Add the ability to select tests to run

task_test [-t <test_name>]

(cherry picked from commit 76837484e7)
This commit is contained in:
Mark Andrews
2020-09-02 18:22:21 +10:00
parent 8746e496c7
commit 6583a9437f
4 changed files with 74 additions and 4 deletions

View File

@@ -22,9 +22,9 @@
#include <unistd.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/atomic.h>
#include <isc/cmocka.h>
#include <isc/commandline.h>
#include <isc/condition.h>
#include <isc/mem.h>
@@ -1549,10 +1549,22 @@ main(int argc, char **argv) {
cmocka_unit_test_setup_teardown(task_exclusive, _setup4,
_teardown),
};
struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])];
int c;
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
memset(selected, 0, sizeof(selected));
while ((c = isc_commandline_parse(argc, argv, "t:v")) != -1) {
switch (c) {
case 't':
if (!cmocka_add_test_byname(
tests, isc_commandline_argument, selected))
{
fprintf(stderr, "unknown test '%s'\n",
isc_commandline_argument);
exit(1);
}
break;
case 'v':
verbose = true;
break;
@@ -1561,7 +1573,11 @@ main(int argc, char **argv) {
}
}
return (cmocka_run_group_tests(tests, NULL, NULL));
if (selected[0].name != NULL) {
return (cmocka_run_group_tests(selected, NULL, NULL));
} else {
return (cmocka_run_group_tests(tests, NULL, NULL));
}
}
#else /* HAVE_CMOCKA */