]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extend ISC_TEST_MAIN for debugging
authorMark Andrews <marka@isc.org>
Fri, 7 Oct 2022 05:13:32 +0000 (16:13 +1100)
committerMark Andrews <marka@isc.org>
Wed, 21 Aug 2024 23:54:39 +0000 (09:54 +1000)
ISC_TEST_MAIN now supports turning on/off debugging and
running individual tests.

tests/dns/rdata_test.c
tests/dns/tsig_test.c
tests/include/tests/isc.h
tests/libtest/isc.c

index 60069093ef65bcafa91ea2404dab60a3edca8953..0d7fe0304f6b634fe4db322b1dcb8e580d722d6c 100644 (file)
@@ -42,8 +42,6 @@
 
 #include <tests/dns.h>
 
-static bool debug = false;
-
 /*
  * An array of these structures is passed to compare_ok().
  */
index 321c9bbcdb120ba0a651d35d120e13261898e5d1..029014ed9b4969343a6f080ba59ccee641cabfd6 100644 (file)
@@ -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;
index bb4164d8bb1b7ad53825c9b722a0f657c3dd5e3b..b49b50951838ddb81e399449afcd3474432c9287 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdbool.h>
 
 #include <isc/buffer.h>
+#include <isc/commandline.h>
 #include <isc/hash.h>
 #include <isc/log.h>
 #include <isc/mem.h>
@@ -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);                                                             \
        }
index b155637c4dd3459979cde7f7af002a546ec29d49..7f487f2cda955cbac5db196b97eb9311eae00b36 100644 (file)
@@ -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) {