From 9fb59763bce293c2490e0b9f8e97bb1f74ba0910 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Fri, 26 Feb 2010 09:04:11 -0500 Subject: Add --with-test-dir option to configure All 'make check' tests will chdir() into this directory before running the suite. This provides the option of having temporary files generated in a tmpfs or ramdisk --- src/tests/auth-tests.c | 3 +++ src/tests/check_and_open-tests.c | 4 ++++ src/tests/common.c | 18 +++++++++++++++++- src/tests/common.h | 2 ++ src/tests/fail_over-tests.c | 2 ++ src/tests/files-tests.c | 3 +++ src/tests/find_uid-tests.c | 4 ++++ src/tests/ipa_ldap_opt-tests.c | 4 ++++ src/tests/ipa_timerules-tests.c | 2 ++ src/tests/krb5_utils-tests.c | 4 ++++ src/tests/refcount-tests.c | 2 ++ src/tests/resolv-tests.c | 2 ++ src/tests/stress-tests.c | 3 +++ src/tests/strtonum-tests.c | 3 +++ src/tests/sysdb-tests.c | 3 +++ 15 files changed, 58 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/auth-tests.c b/src/tests/auth-tests.c index 71215bcd2..64864090b 100644 --- a/src/tests/auth-tests.c +++ b/src/tests/auth-tests.c @@ -37,6 +37,7 @@ #include "util/util.h" #include "confdb/confdb.h" #include "db/sysdb.h" +#include "tests/common.h" #define TESTS_PATH "tests_auth" #define TEST_CONF_FILE "tests_conf.ldb" @@ -319,6 +320,8 @@ int main(int argc, const char *argv[]) } poptFreeContext(pc); + tests_set_cwd(); + ret = clean_db_dir(); if (ret != EOK) { fprintf(stderr, "Could not delete the db directory (%d) (%s)\n", diff --git a/src/tests/check_and_open-tests.c b/src/tests/check_and_open-tests.c index 32cf09f33..7ec8f3bc3 100644 --- a/src/tests/check_and_open-tests.c +++ b/src/tests/check_and_open-tests.c @@ -29,6 +29,7 @@ #include #include "util/util.h" +#include "tests/common.h" #define SUFFIX ".symlink" @@ -208,6 +209,9 @@ Suite *check_and_open_suite (void) int main(void) { int number_failed; + + tests_set_cwd(); + Suite *s = check_and_open_suite (); SRunner *sr = srunner_create (s); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/common.c b/src/tests/common.c index 50dc61b16..4ae1f490b 100644 --- a/src/tests/common.c +++ b/src/tests/common.c @@ -27,9 +27,9 @@ #include "tests/common.h" #include "util/dlinklist.h" -#include "util/util.h" TALLOC_CTX *global_talloc_context = NULL; +#include "util/util.h" struct size_snapshot { struct size_snapshot *prev; @@ -107,3 +107,19 @@ leak_check_teardown(void) } check_leaks(global_talloc_context, 0); } + +void +tests_set_cwd(void) +{ + int ret; + + ret = chdir(TEST_DIR); + if (ret == -1) { + if (strlen(TEST_DIR)) { + fprintf(stderr, + "Could not chdir to [%s].\n" + "Attempting to continue with current dir\n", + TEST_DIR); + } + } +} diff --git a/src/tests/common.h b/src/tests/common.h index 5d4b0867e..576d705ba 100644 --- a/src/tests/common.h +++ b/src/tests/common.h @@ -42,4 +42,6 @@ void _check_leaks_pop(TALLOC_CTX *ctx, const char *location); void leak_check_setup(void); void leak_check_teardown(void); +void tests_set_cwd(void); + #endif /* !__TESTS_COMMON_H__ */ diff --git a/src/tests/fail_over-tests.c b/src/tests/fail_over-tests.c index 4e97a1e2b..1864a09be 100644 --- a/src/tests/fail_over-tests.c +++ b/src/tests/fail_over-tests.c @@ -300,6 +300,8 @@ main(int argc, const char *argv[]) poptFreeContext(pc); debug_level = debug; + tests_set_cwd(); + suite = create_suite(); sr = srunner_create(suite); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/files-tests.c b/src/tests/files-tests.c index 2ebe659da..2267a6034 100644 --- a/src/tests/files-tests.c +++ b/src/tests/files-tests.c @@ -34,6 +34,7 @@ #include "config.h" #include "tools/tools_util.h" #include "util/util.h" +#include "tests/common.h" static char tpl_dir[] = "file-tests-dir-XXXXXX"; static char *dir_path; @@ -312,6 +313,8 @@ int main(int argc, char *argv[]) poptFreeContext(pc); debug_level = debug; + tests_set_cwd(); + Suite *s = files_suite(); SRunner *sr = srunner_create(s); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/find_uid-tests.c b/src/tests/find_uid-tests.c index 9eafadd45..8d1362f7f 100644 --- a/src/tests/find_uid-tests.c +++ b/src/tests/find_uid-tests.c @@ -29,6 +29,7 @@ #include #include "util/find_uid.h" +#include "tests/common.h" START_TEST(test_check_if_uid_is_active_success) @@ -115,6 +116,9 @@ int main(void) { debug_level = 255; int number_failed; + + tests_set_cwd(); + Suite *s = find_uid_suite (); SRunner *sr = srunner_create (s); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/ipa_ldap_opt-tests.c b/src/tests/ipa_ldap_opt-tests.c index 215f94a4d..4b4667a47 100644 --- a/src/tests/ipa_ldap_opt-tests.c +++ b/src/tests/ipa_ldap_opt-tests.c @@ -27,6 +27,7 @@ #include "providers/ipa/ipa_common.h" #include "providers/ldap/sdap.h" +#include "tests/common.h" START_TEST(test_check_num_opts) { @@ -49,6 +50,9 @@ Suite *ipa_ldap_opt_suite (void) int main(void) { int number_failed; + + tests_set_cwd(); + Suite *s = ipa_ldap_opt_suite (); SRunner *sr = srunner_create (s); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/ipa_timerules-tests.c b/src/tests/ipa_timerules-tests.c index 0a7be90be..29fc7e4ac 100644 --- a/src/tests/ipa_timerules-tests.c +++ b/src/tests/ipa_timerules-tests.c @@ -569,6 +569,8 @@ int main(int argc, const char *argv[]) } debug_level = debug; + tests_set_cwd(); + timelib_suite = create_timelib_suite(); sr = srunner_create(timelib_suite); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/krb5_utils-tests.c b/src/tests/krb5_utils-tests.c index 362daf475..64cf9c3d3 100644 --- a/src/tests/krb5_utils-tests.c +++ b/src/tests/krb5_utils-tests.c @@ -27,6 +27,7 @@ #include "providers/krb5/krb5_utils.h" #include "providers/krb5/krb5_auth.h" +#include "tests/common.h" #define BASE "/abc/def" @@ -296,6 +297,9 @@ Suite *krb5_utils_suite (void) int main(void) { int number_failed; + + tests_set_cwd(); + Suite *s = krb5_utils_suite (); SRunner *sr = srunner_create (s); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/refcount-tests.c b/src/tests/refcount-tests.c index db2a256ee..5e85b6f84 100644 --- a/src/tests/refcount-tests.c +++ b/src/tests/refcount-tests.c @@ -220,6 +220,8 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); debug_level = debug; + tests_set_cwd(); + suite = create_suite(); sr = srunner_create(suite); srunner_set_fork_status(sr, CK_FORK); diff --git a/src/tests/resolv-tests.c b/src/tests/resolv-tests.c index e93d0f196..c0133b923 100644 --- a/src/tests/resolv-tests.c +++ b/src/tests/resolv-tests.c @@ -595,6 +595,8 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); debug_level = debug; + tests_set_cwd(); + resolv_suite = create_resolv_suite(); sr = srunner_create(resolv_suite); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/stress-tests.c b/src/tests/stress-tests.c index 945053185..3b5373579 100644 --- a/src/tests/stress-tests.c +++ b/src/tests/stress-tests.c @@ -30,6 +30,7 @@ #include #include "util/util.h" +#include "tests/common.h" #define DEFAULT_START 10 #define DEFAULT_STOP 20 @@ -247,6 +248,8 @@ int main(int argc, const char *argv[]) } poptFreeContext(pc); + tests_set_cwd(); + verbose = pc_verbosity; if (pc_prefix) { diff --git a/src/tests/strtonum-tests.c b/src/tests/strtonum-tests.c index 7b9cf522c..a7131c1b5 100644 --- a/src/tests/strtonum-tests.c +++ b/src/tests/strtonum-tests.c @@ -25,6 +25,7 @@ #include #include "util/util.h" #include "util/strtonum.h" +#include "tests/common.h" /******************** * Utility routines * @@ -445,6 +446,8 @@ int main(int argc, const char *argv[]) { } poptFreeContext(pc); + tests_set_cwd(); + strtonum_suite = create_strtonum_suite(); sr = srunner_create(strtonum_suite); /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 8b486b691..c6661aef6 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -29,6 +29,7 @@ #include "util/util.h" #include "confdb/confdb_setup.h" #include "db/sysdb_private.h" +#include "tests/common.h" #define TESTS_PATH "tests_sysdb" #define TEST_CONF_FILE "tests_conf.ldb" @@ -3297,6 +3298,8 @@ int main(int argc, const char *argv[]) { } poptFreeContext(pc); + tests_set_cwd(); + ret = unlink(TESTS_PATH"/"LOCAL_SYSDB_FILE); if (ret != EOK && errno != ENOENT) { fprintf(stderr, "Could not delete the test ldb file (%d) (%s)\n", -- cgit