diff --git a/CMakeLists.txt b/CMakeLists.txt index 834b7a5..0f00889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ set(SOURCES src/fcntl/open.c # unistd src/unistd/files.c - + # sys/stat + src/sysstat/stat.c ) # fx-9860G-only assets and fx-CG-50-only assets set(ASSETS_fx diff --git a/include/ft/all-tests.h b/include/ft/all-tests.h index 6735014..b21aee3 100644 --- a/include/ft/all-tests.h +++ b/include/ft/all-tests.h @@ -68,4 +68,7 @@ extern ft_test ft_unistd_simple_read; extern ft_test ft_unistd_seek_patterns; extern ft_test ft_unistd_folders; +/* sys/stat */ +extern ft_test ft_sysstat_stat; + #endif /* _FT_ALL_TESTS_H_ */ diff --git a/src/main.c b/src/main.c index c4ec792..d44188f 100644 --- a/src/main.c +++ b/src/main.c @@ -97,6 +97,10 @@ ft_list headers_posix[] = { &ft_unistd_folders, NULL, }}, + { "", (ft_test*[]){ + &ft_sysstat_stat, + NULL, + }}, { NULL } }; diff --git a/src/sysstat/stat.c b/src/sysstat/stat.c new file mode 100644 index 0000000..8320dee --- /dev/null +++ b/src/sysstat/stat.c @@ -0,0 +1,33 @@ +#include +#include +#include + +#include +#include +#include + +static void _ft_sysstat_stat_switch(ft_test *t) +{ + struct stat st; + int rc; + + DO_E(rc, stat("@MainMem", &st), t, "%d"); + ft_assert(t, rc == 0 && S_ISDIR(st.st_mode)); + +#ifdef FX9860G + DO_E(rc, stat("FxLibcT.g1a", &st), t, "%d"); +#else + DO_E(rc, stat("FxLibcT.g3a", &st), t, "%d"); +#endif + ft_assert(t, rc == 0 && S_ISREG(st.st_mode)); +} + +static void _ft_sysstat_stat(ft_test *t) +{ + gint_world_switch(GINT_CALL(_ft_sysstat_stat_switch, (void *)t)); +} + +ft_test ft_sysstat_stat = { + .name = "stat() function", + .function = _ft_sysstat_stat, +}; diff --git a/src/unistd/files.c b/src/unistd/files.c index d93c251..d7e4aaa 100644 --- a/src/unistd/files.c +++ b/src/unistd/files.c @@ -308,17 +308,9 @@ static void _ft_unistd_folders_switch(ft_test *t) { int rc, fd, type, size; - /* Create a directory (don't fail if we already ran the test before) */ + /* Create a directory */ DO_E(rc, mkdir("ft_test", 0755), t, "%d"); - ft_assert(t, rc == 0 || (rc == -1 && errno == EEXIST)); - ft_log(t, "note: this folder might already exist\n"); - - /* Remove that directory */ - DO_E(rc, rmdir("ft_test"), t, "%d"); ft_assert(t, rc == 0); - - /* Create it anew (and empty) */ - DO_E(rc, mkdir("ft_test", 0755), t, "%d"); ft_assert(t, rc == 0); DO_E(rc, mkdir("ft_test", 0755), t, "%d"); ft_assert(t, rc == -1 && errno == EEXIST); @@ -352,6 +344,20 @@ static void _ft_unistd_folders_switch(ft_test *t) &type, &size); ft_log(t, "BFile_Ext_Stat()=%d (type=%d, size=%d)\n", rc, type, size); ft_assert(t, rc == 0 && type == BFile_Type_File && size == 28); + + /* Clean up everything */ + DO_E(rc, rmdir("ft_test/subfolder"), t, "%d"); + ft_assert(t, rc == -1 && errno == ENOTEMPTY); + DO_E(rc, unlink("ft_test/subfolder"), t, "%d"); + ft_assert(t, rc == -1 && errno == ENOTDIR); + DO_E(rc, unlink("ft_test/subfolder/file.txt"), t, "%d"); + ft_assert(t, rc == 0); + DO_E(rc, rmdir("ft_test/subfolder"), t, "%d"); + ft_assert(t, rc == 0); + DO_E(rc, unlink("ft_test/file.txt"), t, "%d"); + ft_assert(t, rc == 0); + DO_E(rc, rmdir("ft_test"), t, "%d"); + ft_assert(t, rc == 0); } static void _ft_unistd_folders(ft_test *t)