[9.18] chg: dev: Restore the ability to select individual unit tests
This adds the command line arguments: `-d` (debug), `-l` (list tests) and `-t test` (run this test) to the unit tests.
e.g.
```
% ./rdata_test -t zonemd
[==========] selected: Running 1 test(s).
[ RUN ] zonemd
[ OK ] zonemd
[==========] selected: 1 test(s) run.
[ PASSED ] 1 test(s).
%
```
Closes #4579
Backport of MR !9384
Merge branch 'backport-4579-restore-the-ability-to-select-individual-unit-tests-9.18' into 'bind-9.18'
See merge request isc-projects/bind9!9386
This commit is contained in:
@@ -40,8 +40,6 @@
|
||||
|
||||
#include <tests/dns.h>
|
||||
|
||||
static bool debug = false;
|
||||
|
||||
/*
|
||||
* An array of these structures is passed to compare_ok().
|
||||
*/
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
static int
|
||||
setup_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <uv.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/hash.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
@@ -48,6 +49,7 @@ extern isc_taskmgr_t *taskmgr;
|
||||
extern isc_timermgr_t *timermgr;
|
||||
extern unsigned int workers;
|
||||
extern isc_task_t *maintask;
|
||||
extern bool debug;
|
||||
|
||||
#define isc_test_nap(ms) uv_sleep(ms)
|
||||
|
||||
@@ -102,18 +104,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); \
|
||||
\
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \
|
||||
isc_mem_create(&mctx); \
|
||||
\
|
||||
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)); \
|
||||
\
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \
|
||||
isc_mem_create(&mctx); \
|
||||
\
|
||||
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); \
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ isc_timermgr_t *timermgr = NULL;
|
||||
isc_nm_t *netmgr = NULL;
|
||||
unsigned int workers = 0;
|
||||
isc_task_t *maintask = NULL;
|
||||
bool debug = false;
|
||||
|
||||
int
|
||||
setup_managers(void **state) {
|
||||
|
||||
Reference in New Issue
Block a user