diff --git a/tests/dns/rdata_test.c b/tests/dns/rdata_test.c index 60069093ef..0d7fe0304f 100644 --- a/tests/dns/rdata_test.c +++ b/tests/dns/rdata_test.c @@ -42,8 +42,6 @@ #include -static bool debug = false; - /* * An array of these structures is passed to compare_ok(). */ diff --git a/tests/dns/tsig_test.c b/tests/dns/tsig_test.c index 321c9bbcdb..029014ed9b 100644 --- a/tests/dns/tsig_test.c +++ b/tests/dns/tsig_test.c @@ -46,8 +46,6 @@ } \ } -static int debug = 0; - static isc_result_t add_mac(dst_context_t *tsigctx, isc_buffer_t *buf) { dns_rdata_any_tsig_t tsig; diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h index bb4164d8bb..b49b509518 100644 --- a/tests/include/tests/isc.h +++ b/tests/include/tests/isc.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,7 @@ extern isc_loopmgr_t *loopmgr; extern isc_nm_t *netmgr; extern int ncpus; extern unsigned int workers; +extern bool debug; int setup_mctx(void **state); @@ -168,18 +170,86 @@ teardown_managers(void **state); #define ISC_TEST_MAIN ISC_TEST_MAIN_CUSTOM(NULL, NULL) -#define ISC_TEST_MAIN_CUSTOM(setup, teardown) \ - int main(void) { \ - int r; \ - \ - signal(SIGPIPE, SIG_IGN); \ - \ - setup_mctx(NULL); \ - setup_workers(NULL); \ - \ - r = cmocka_run_group_tests(tests, setup, teardown); \ - \ - isc_mem_destroy(&mctx); \ - \ - return (r); \ +#define ISC_TEST_MAIN_CUSTOM(setup, teardown) \ + int main(int argc, char **argv) { \ + int c, r; \ + size_t i, j; \ + struct CMUnitTest selected[ARRAY_SIZE(tests)]; \ + \ + signal(SIGPIPE, SIG_IGN); \ + \ + memset(selected, 0, sizeof(selected)); \ + \ + setup_mctx(NULL); \ + setup_workers(NULL); \ + \ + while ((c = isc_commandline_parse(argc, argv, "dlt:")) != -1) \ + { \ + switch (c) { \ + case 'd': \ + debug = true; \ + break; \ + case 'l': \ + for (i = 0; \ + i < (sizeof(tests) / sizeof(tests[0])); \ + i++) \ + { \ + if (tests[i].name != NULL) { \ + fprintf(stdout, "%s\n", \ + tests[i].name); \ + } \ + } \ + return (0); \ + case 't': \ + for (i = 0; i < ARRAY_SIZE(tests) && \ + tests[i].name != NULL; \ + i++) \ + { \ + if (strcmp(tests[i].name, \ + isc_commandline_argument) != \ + 0) \ + { \ + continue; \ + } \ + for (j = 0; \ + j < ARRAY_SIZE(selected) && \ + selected[j].name != NULL; \ + j++) \ + { \ + if (strcmp(tests[j].name, \ + isc_commandline_argument) == \ + 0) \ + { \ + break; \ + } \ + } \ + if (j < ARRAY_SIZE(selected) && \ + selected[j].name == NULL) \ + { \ + selected[j] = tests[i]; \ + break; \ + } \ + } \ + if (i == ARRAY_SIZE(tests)) { \ + fprintf(stderr, "unknown test '%s'\n", \ + isc_commandline_argument); \ + exit(1); \ + } \ + break; \ + default: \ + fprintf(stderr, "Usage: %s [-dl] [-t test]\n", \ + argv[0]); \ + exit(1); \ + } \ + } \ + \ + if (selected[0].name != NULL) { \ + r = cmocka_run_group_tests(selected, setup, teardown); \ + } else { \ + r = cmocka_run_group_tests(tests, setup, teardown); \ + } \ + \ + isc_mem_destroy(&mctx); \ + \ + return (r); \ } diff --git a/tests/libtest/isc.c b/tests/libtest/isc.c index b155637c4d..7f487f2cda 100644 --- a/tests/libtest/isc.c +++ b/tests/libtest/isc.c @@ -37,6 +37,7 @@ isc_loop_t *mainloop = NULL; isc_loopmgr_t *loopmgr = NULL; isc_nm_t *netmgr = NULL; unsigned int workers = 0; +bool debug = false; static void adjustnofile(void) {