Commit 795df666 authored by Mark Andrews's avatar Mark Andrews
Browse files

Set working directory in unit tests

so that sanitiser results are in expected locations.
parent f036e0bc
Pipeline #49870 failed with stages
in 32 minutes and 30 seconds
......@@ -133,6 +133,15 @@ dns_acl_isinsecure_test(void **state) {
#endif /* HAVE_GEOIP2 */
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -140,7 +149,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -395,6 +395,15 @@ version_test(void **state) {
dns_db_detach(&db);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -407,7 +416,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -158,6 +158,15 @@ diffx_remove(void **state) {
dns_db_detach(&olddb);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -167,7 +176,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -354,6 +354,15 @@ seek_nx_nsec3(void **state) {
* dns_dbiterator_origin
* dns_dbiterator_setcleanmode
*/
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -376,7 +385,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -459,6 +459,15 @@ resigned(void **state) {
dns_rdataset_disassociate(&added);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -481,7 +490,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -89,6 +89,17 @@ dh_computesecret(void **state) {
}
#endif /* USE_OPENSSL */
#if USE_OPENSSL
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
#endif
int
main(void) {
#if USE_OPENSSL
......@@ -97,7 +108,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
#else /* if USE_OPENSSL */
print_message("1..0 # Skipped: dh test broken with PKCS11");
#endif /* if USE_OPENSSL */
......
......@@ -331,6 +331,15 @@ dispatch_getnext(void **state) {
dns_dispatchmgr_destroy(&dispatchmgr);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -342,7 +351,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -364,6 +364,15 @@ totext_test(void **state) {
}
cleanup();
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
#endif /* HAVE_DNSTAP */
int
......@@ -378,7 +387,7 @@ main(void) {
/* make sure text conversion gets the right local time */
setenv("TZ", "PST8", 1);
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
#else /* if HAVE_DNSTAP */
print_message("1..0 # Skip dnstap not enabled\n");
#endif /* HAVE_DNSTAP */
......
......@@ -286,13 +286,22 @@ sig_test(void **state) {
}
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(sig_test, _setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -52,6 +52,8 @@ _setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
......
......@@ -48,6 +48,8 @@ _setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
......
......@@ -745,6 +745,15 @@ benchmark_test(void **state) {
#endif /* DNS_BENCHMARK_TESTS */
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
......@@ -778,7 +787,7 @@ main(int argc, char **argv) {
}
}
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -170,6 +170,15 @@ nsec3param_salttotext(void **state) {
}
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -179,7 +188,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -151,13 +151,22 @@ dscp(void **state) {
dns_peer_detach(&peer);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dscp, _setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -213,6 +213,15 @@ private_nsec3_totext_test(void **state) {
}
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -222,7 +231,7 @@ main(void) {
_setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -450,6 +450,15 @@ serialize_align_test(void **state) {
assert_true(dns_rbt_serialize_align(0x301) == 0x308);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
......@@ -471,7 +480,7 @@ main(int argc, char **argv) {
}
}
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -1342,6 +1342,15 @@ benchmark(void **state) {
}
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -1372,7 +1381,7 @@ main(void) {
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -2562,6 +2562,15 @@ iszonecutauth(void **state) {
#undef UNR
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
......@@ -2598,7 +2607,7 @@ main(int argc, char **argv) {
debug = true;
}
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -122,13 +122,22 @@ trimttl(void **state) {
assert_int_equal(sigrdataset.ttl, 0);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -284,6 +284,15 @@ test_rdatasetstats_active_ancient(void **state) {
rdatasetstats(state, false);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -294,7 +303,7 @@ main(void) {
test_rdatasetstats_active_ancient, _setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -194,6 +194,15 @@ settimeout_overmax_test(void **state) {
destroy_resolver(&resolver);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -210,7 +219,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -16,6 +16,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define UNIT_TESTING
#include <cmocka.h>
......@@ -109,13 +110,22 @@ ids(void **state) {
assert_string_equal(str, "(result code text not available)");
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(ids),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -214,6 +214,15 @@ isc_rsa_verify_test(void **state) {
dst_key_free(&key);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -221,7 +230,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -437,6 +437,15 @@ updatesigs_next_test(void **state) {
dns_zone_detach(&zone);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -444,7 +453,7 @@ main(void) {
_teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, run_group_setup, NULL));
}
#else /* HAVE_CMOCKA */
......
......@@ -184,6 +184,15 @@ some_ago_test(void **state) {
assert_int_equal(when, test_time);
}
static int
run_group_setup(void **state) {
UNUSED(state);
assert_return_code(chdir(TESTS_DIR), 0);
return (0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
......@@ -200,7 +209,7 @@ main(void) {
_teardown),
};