diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-12 16:22:35 +0300 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-18 17:44:45 +0300 |
commit | ad23e23c4e5dd93e513f1339cc1cd93a05d089b4 (patch) | |
tree | 80866fa8d5206404d0922f200f935621b500aa48 /tests/fs-tests | |
parent | 261a49daf5846ff6433e4199275115efcc1855fa (diff) |
fs-tests: integck: do not use tests_clear_dir
Do not use shared 'tests_clear_dir()' function which removes a directory
tree recursively, but instead use own implementation. This is because
I'm trying to make integck independend on the shared code because I
need this to do further improvements.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests/fs-tests')
-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) |