diff --git a/tests/np2_test.c b/tests/np2_test.c index 08783652..3c5ece74 100644 --- a/tests/np2_test.c +++ b/tests/np2_test.c @@ -19,6 +19,7 @@ #include "np2_test.h" +#include #include #include #include @@ -332,6 +333,39 @@ np2_glob_test_setup_server(void **state, const char *test_name, const char **mod return 0; } +int +np2_glob_test_teardown_notif(const char *test_name) +{ + char *path; + DIR *dir; + struct dirent *ent; + + /* open notification dir */ + if (asprintf(&path, "%s/%s/data/notif", NP_SR_REPOS_DIR, test_name) == -1) { + return 1; + } + dir = opendir(path); + free(path); + if (!dir) { + return 1; + } + + /* remove all notif1 notifications */ + while ((ent = readdir(dir))) { + if (!strncmp(ent->d_name, "notif1.notif", 12)) { + if (asprintf(&path, "%s/%s/data/notif/%s", NP_SR_REPOS_DIR, test_name, ent->d_name) == -1) { + closedir(dir); + return 1; + } + unlink(path); + free(path); + } + } + + closedir(dir); + return 0; +} + int np2_glob_test_teardown(void **state, const char **modules) { diff --git a/tests/np2_test.h b/tests/np2_test.h index 50e94705..bea7536c 100644 --- a/tests/np2_test.h +++ b/tests/np2_test.h @@ -285,6 +285,8 @@ int np2_glob_test_setup_env(const char *test_name); int np2_glob_test_setup_server(void **state, const char *test_name, const char **modules); +int np2_glob_test_teardown_notif(const char *test_name); + int np2_glob_test_teardown(void **state, const char **modules); void parse_arg(int argc, char **argv); diff --git a/tests/test_sub_ntf.c b/tests/test_sub_ntf.c index 58e53de3..726dc43f 100644 --- a/tests/test_sub_ntf.c +++ b/tests/test_sub_ntf.c @@ -65,20 +65,9 @@ static int teardown_common(void **state) { struct np2_test *st = *state; - char *cmd; - int ret; - /* Remove the notifications */ - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; } diff --git a/tests/test_sub_ntf_advanced.c b/tests/test_sub_ntf_advanced.c index 45019e3e..60087a2f 100644 --- a/tests/test_sub_ntf_advanced.c +++ b/tests/test_sub_ntf_advanced.c @@ -70,20 +70,9 @@ static int teardown_common(void **state) { struct np2_test *st = *state; - char *cmd; - int ret; - /* Remove the notifications */ - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; } diff --git a/tests/test_sub_ntf_filter.c b/tests/test_sub_ntf_filter.c index 7498d909..b1bb8189 100644 --- a/tests/test_sub_ntf_filter.c +++ b/tests/test_sub_ntf_filter.c @@ -65,20 +65,9 @@ static int teardown_common(void **state) { struct np2_test *st = *state; - char *cmd; - int ret; - /* Remove the notifications */ - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; } diff --git a/tests/test_subscribe_param.c b/tests/test_subscribe_param.c index 86d1e004..6dcad1ce 100644 --- a/tests/test_subscribe_param.c +++ b/tests/test_subscribe_param.c @@ -97,19 +97,9 @@ static int clear_notif(void **state) { struct np2_test *st = *state; - char *cmd; - int ret; - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; } diff --git a/tests/test_yang_push.c b/tests/test_yang_push.c index aa359d4e..647ea40e 100644 --- a/tests/test_yang_push.c +++ b/tests/test_yang_push.c @@ -63,8 +63,6 @@ teardown_common(void **state) { struct np2_test *st = *state; const char *data; - char *cmd; - int ret; /* stop NETCONF session */ nc_session_free(st->nc_sess, NULL); @@ -78,17 +76,8 @@ teardown_common(void **state) SR_EDIT(st, data); FREE_TEST_VARS(st); - /* Remove the notifications */ - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; } diff --git a/tests/test_yang_push_advanced.c b/tests/test_yang_push_advanced.c index 7f906719..3eb54800 100644 --- a/tests/test_yang_push_advanced.c +++ b/tests/test_yang_push_advanced.c @@ -63,20 +63,9 @@ teardown_common(void **state) { struct np2_test *st = *state; const char *data; - char *cmd; - int ret; - /* Remove the notifications */ - if (asprintf(&cmd, "rm -rf %s/%s/data/notif/notif1.notif*", NP_SR_REPOS_DIR, st->test_name) == -1) { - return 1; - } - - ret = system(cmd); - free(cmd); - - if (ret == -1) { - return 1; - } else if (!WIFEXITED(ret) || WEXITSTATUS(ret)) { + /* remove notifications */ + if (np2_glob_test_teardown_notif(st->test_name)) { return 1; }