diff options
Diffstat (limited to 'tests/fs-tests/integrity')
-rw-r--r-- | tests/fs-tests/integrity/integck.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c index ed02b56..4806acd 100644 --- a/tests/fs-tests/integrity/integck.c +++ b/tests/fs-tests/integrity/integck.c @@ -1942,6 +1942,42 @@ static void create_test_data(void) do_an_operation(); } +/* + * Recursively remove a directory, just like "rm -rf" shell command. + */ +void rm_minus_rf_dir(const char *dir_name) +{ + DIR *dir; + struct dirent *entry; + char buf[PATH_MAX]; + + dir = opendir(dir_name); + CHECK(dir != NULL); + CHECK(getcwd(buf, PATH_MAX) != NULL); + CHECK(chdir(dir_name) == 0); + + for (;;) { + errno = 0; + entry = readdir(dir); + if (!entry) { + CHECK(errno == 0); + break; + } + + if (strcmp(entry->d_name, ".") && + strcmp(entry->d_name, "..")) { + if (entry->d_type == DT_DIR) + rm_minus_rf_dir(entry->d_name); + else + CHECK(unlink(entry->d_name) == 0); + } + } + + CHECK(chdir(buf) == 0); + CHECK(closedir(dir) == 0); + CHECK(rmdir(dir_name) == 0); +} + static void update_test_data(void) { uint64_t i, n; @@ -1977,19 +2013,17 @@ static int integck(void) { int64_t rpt; - /* Make our top directory */ - if (chdir(fsinfo.test_dir) != -1) { + /* Create our top directory */ + if (chdir(fsinfo.test_dir) == 0) { /* Remove it if it is already there */ - tests_clear_dir("."); - CHECK(chdir("..") != -1); - CHECK(rmdir(fsinfo.test_dir) != -1); + CHECK(chdir("..") == 0); + rm_minus_rf_dir(fsinfo.test_dir); } - top_dir = dir_new(NULL, fsinfo.test_dir); + top_dir = dir_new(NULL, fsinfo.test_dir); if (!top_dir) return -1; - srand(getpid()); create_test_data(); if (!tests_fs_is_rootfs()) { @@ -2018,8 +2052,7 @@ static int integck(void) /* Tidy up by removing everything */ close_open_files(); - tests_clear_dir(fsinfo.test_dir); - CHECK(rmdir(fsinfo.test_dir) != -1); + rm_minus_rf_dir(fsinfo.test_dir); return 0; } @@ -2186,6 +2219,9 @@ int main(int argc, char *argv[]) tests_file_system_mount_dir = (void *)fsinfo.mount_point; tests_file_system_type = (void *)fsinfo.fstype; + /* Seed the random generator with out PID */ + srand(getpid()); + /* Do the actual test */ ret = integck(); if (ret) |