Add file system tests
This commit is contained in:
parent
3253619eaf
commit
de19f22cbe
@ -12,4 +12,5 @@ module /armv8/sbin/mallocator
|
||||
module /armv8/sbin/stackoverflow
|
||||
module /armv8/sbin/echoserver
|
||||
module /armv8/sbin/shelly
|
||||
module /armv8/sbin/filereader
|
||||
module /armv8/sbin/block_driver_server
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
let
|
||||
-- Default list of modules to build/install
|
||||
modules_common = [ "/sbin/" ++ f | f <- [ "init", "hello", "mallocator", "stackoverflow", "echoserver", "enet", "shelly", "block_driver_server"
|
||||
modules_common = [ "/sbin/" ++ f | f <- [ "init", "hello", "mallocator", "stackoverflow", "echoserver", "enet", "shelly", "filereader", "block_driver_server"
|
||||
] ]
|
||||
in
|
||||
[
|
||||
|
||||
@ -31,12 +31,15 @@ static uint64_t systime_to_ms(systime_t time){
|
||||
#define MOUNTPOINT "/sdcard"
|
||||
#define SUBDIR "/parent"
|
||||
#define SUBDIR_LONG "/parent-directory"
|
||||
#define SUBDIR_INVALID "/parent.txtt"
|
||||
#define DIR_NOT_EXIST "/not-exist"
|
||||
#define FILENAME "/myfile2.txt"
|
||||
#define LONGFILENAME "/mylongfilenamefile.txt"
|
||||
#define LONGFILENAME2 "/mylongfilenamefilesecond.txt"
|
||||
#define FILE_NOT_EXIST "/not-exist.txt"
|
||||
|
||||
char *long_text = "Hello World! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||
|
||||
#define TEST_PREAMBLE(arg) \
|
||||
printf("\n-------------------------------\n"); \
|
||||
printf("%s(%s)\n", __FUNCTION__, arg);
|
||||
@ -80,8 +83,26 @@ static uint64_t systime_to_ms(systime_t time){
|
||||
TEST_END \
|
||||
} while(0); \
|
||||
|
||||
static errval_t test_make_dir(char *dir)
|
||||
{
|
||||
TEST_PREAMBLE(dir)
|
||||
|
||||
return mkdir(dir);
|
||||
}
|
||||
|
||||
static errval_t test_rm_dir(char *dir)
|
||||
{
|
||||
TEST_PREAMBLE(dir)
|
||||
|
||||
return rmdir(dir);
|
||||
}
|
||||
|
||||
static errval_t test_rm_file(char *dir)
|
||||
{
|
||||
TEST_PREAMBLE(dir)
|
||||
|
||||
return rm(dir);
|
||||
}
|
||||
|
||||
static errval_t test_read_dir(char *dir)
|
||||
{
|
||||
@ -113,6 +134,82 @@ static errval_t test_read_dir(char *dir)
|
||||
return err;
|
||||
}
|
||||
|
||||
static errval_t test_fread_big(char *file)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
TEST_PREAMBLE(file)
|
||||
|
||||
FILE *f = fopen(file, "r");
|
||||
if (f == NULL) {
|
||||
return FS_ERR_OPEN;
|
||||
}
|
||||
|
||||
/* obtain the file size */
|
||||
res = fseek (f , 0 , SEEK_END);
|
||||
if (res) {
|
||||
return FS_ERR_INVALID_FH;
|
||||
}
|
||||
|
||||
size_t filesize = ftell (f);
|
||||
rewind (f);
|
||||
|
||||
printf("File size is %zu\n", filesize);
|
||||
if(filesize != strlen(long_text)) {
|
||||
return FS_ERR_READ;
|
||||
}
|
||||
|
||||
char *buf = calloc(filesize + 2, sizeof(char));
|
||||
if (buf == NULL) {
|
||||
return LIB_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
size_t read = fread(buf, 1, filesize, f);
|
||||
|
||||
if (read != filesize) {
|
||||
return FS_ERR_READ;
|
||||
}
|
||||
|
||||
if(memcmp(buf, long_text, strlen(long_text))) {
|
||||
return FS_ERR_READ;
|
||||
}
|
||||
|
||||
// printf("read: %s\n", buf);
|
||||
|
||||
res = fclose(f);
|
||||
if (res) {
|
||||
return FS_ERR_CLOSE;
|
||||
}
|
||||
|
||||
return SYS_ERR_OK;
|
||||
}
|
||||
|
||||
static errval_t test_fwrite_big(char *file)
|
||||
{
|
||||
int res = 0;
|
||||
TEST_PREAMBLE(file)
|
||||
|
||||
FILE *f = fopen(file, "w");
|
||||
if (f == NULL) {
|
||||
return FS_ERR_OPEN;
|
||||
}
|
||||
|
||||
printf("file opened\n");
|
||||
|
||||
// write in splits
|
||||
for (size_t i = 0; i < strlen(long_text); ++i) {
|
||||
size_t written = fwrite(long_text + i, 1, 1, f);
|
||||
if (written != 1) return FS_ERR_WRITE;
|
||||
}
|
||||
|
||||
res = fclose(f);
|
||||
if (res) {
|
||||
return FS_ERR_CLOSE;
|
||||
}
|
||||
|
||||
return SYS_ERR_OK;
|
||||
}
|
||||
|
||||
static errval_t test_fread(char *file)
|
||||
{
|
||||
int res = 0;
|
||||
@ -180,6 +277,8 @@ static errval_t test_fwrite(char *file)
|
||||
return FS_ERR_OPEN;
|
||||
}
|
||||
|
||||
printf("file opened\n");
|
||||
|
||||
const char *inspirational_quote = "I love deadlines. I like the whooshing "
|
||||
"sound they make as they fly by.";
|
||||
|
||||
@ -219,5 +318,51 @@ int main(int argc, char *argv[])
|
||||
|
||||
run_test(test_fread, MOUNTPOINT FILENAME);
|
||||
|
||||
// NOTE rueegges: part added by me
|
||||
|
||||
// MKDIR
|
||||
|
||||
// create a new directory
|
||||
run_test(test_make_dir, MOUNTPOINT SUBDIR);
|
||||
// create subdirectory
|
||||
run_test(test_make_dir, MOUNTPOINT SUBDIR SUBDIR);
|
||||
|
||||
// try to create existing directory
|
||||
run_test_fail(test_make_dir, MOUNTPOINT SUBDIR);
|
||||
// too long dirname
|
||||
run_test_fail(test_make_dir, MOUNTPOINT SUBDIR_LONG);
|
||||
// too long name extension
|
||||
run_test_fail(test_make_dir, MOUNTPOINT SUBDIR_INVALID);
|
||||
|
||||
// RMDIR
|
||||
|
||||
// try to delete non-empty directory
|
||||
run_test_fail(test_rm_dir, MOUNTPOINT SUBDIR);
|
||||
// delete subdirectory
|
||||
run_test(test_rm_dir, MOUNTPOINT SUBDIR SUBDIR);
|
||||
// try to delete again after deleting subdir
|
||||
run_test(test_rm_dir, MOUNTPOINT SUBDIR);
|
||||
|
||||
// non-existent directory
|
||||
run_test_fail(test_rm_dir, MOUNTPOINT DIR_NOT_EXIST);
|
||||
// dry to delete file using rmdir
|
||||
run_test_fail(test_rm_dir, MOUNTPOINT FILENAME);
|
||||
|
||||
// RM
|
||||
|
||||
// delete a valid file
|
||||
run_test(test_rm_file, MOUNTPOINT FILENAME)
|
||||
// delete non-existent file
|
||||
run_test_fail(test_rm_file, MOUNTPOINT FILENAME)
|
||||
|
||||
// FILE OPERATIONS (more extensive than what was already present, exploring cluster/sector bounds)
|
||||
run_test(test_make_dir, MOUNTPOINT SUBDIR);
|
||||
run_test(test_fwrite_big, MOUNTPOINT SUBDIR FILENAME);
|
||||
run_test(test_fread_big, MOUNTPOINT SUBDIR FILENAME);
|
||||
run_test(test_rm_file, MOUNTPOINT SUBDIR FILENAME);
|
||||
run_test(test_rm_dir, MOUNTPOINT SUBDIR);
|
||||
|
||||
// TODO rueegges: delete open file and directory
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user