]> 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>
Thu, 22 Aug 2024 06:04:59 +0000 (06:04 +0000)
ISC_TEST_MAIN now supports turning on/off debugging and
running individual tests.

(cherry picked from commit d8a6ff5c3e3c196a840d0c6b73d0213331d758fd)

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

index 0d7c23d6aafea64ca8e798ec0e1ab91e30452236..67a5c67294af189473f1fa73b9ce25b8870a4d65 100644 (file)
@@ -40,8 +40,6 @@
 
 #include <tests/dns.h>
 
-static bool debug = false;
-
 /*
  * An array of these structures is passed to compare_ok().
  */
index 2cc26c7158c3d19391467c6d463c8832bc5781fa..628921f6c0f2ead1646ddf9ab2e636ba4b4b945c 100644 (file)
@@ -37,8 +37,6 @@
 
 #define TEST_ORIGIN "test"
 
-static int debug = 0;
-
 static int
 setup_test(void **state) {
        isc_result_t result;
index 6131c2018529007ab03d10621c3ce60008d632f8..eaee11768f4f29052cf05d3046d0c233d462b15b 100644 (file)
@@ -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);                                                             \
        }
index 970a4b10f313f511d64a2aa04482987e18690418..5ea8e34e3ff77b19e14b5925828bfaab6db4d882 100644 (file)
@@ -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) {