]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add the ability select individual tests to rdata_test
authorMark Andrews <marka@isc.org>
Fri, 11 Sep 2020 04:17:36 +0000 (14:17 +1000)
committerMark Andrews <marka@isc.org>
Thu, 1 Oct 2020 08:21:42 +0000 (08:21 +0000)
lib/dns/tests/rdata_test.c

index 0f091214ba7d4fbf58f2f24eb127d461478689e8..e44b2f1cabbc5a88e7f8f4871c2ad9b9b162f023 100644 (file)
@@ -21,8 +21,9 @@
 #include <unistd.h>
 
 #define UNIT_TESTING
-#include <cmocka.h>
 
+#include <isc/cmocka.h>
+#include <isc/commandline.h>
 #include <isc/hex.h>
 #include <isc/lex.h>
 #include <isc/print.h>
@@ -2656,14 +2657,44 @@ main(int argc, char **argv) {
                cmocka_unit_test_setup_teardown(atparent, NULL, NULL),
                cmocka_unit_test_setup_teardown(iszonecutauth, NULL, NULL),
        };
+       struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])];
+       size_t i;
+       int c;
 
-       UNUSED(argv);
+       memset(selected, 0, sizeof(selected));
 
-       if (argc > 1) {
-               debug = true;
+       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':
+                       if (!cmocka_add_test_byname(
+                                   tests, isc_commandline_argument, selected))
+                       {
+                               fprintf(stderr, "unknown test '%s'\n",
+                                       isc_commandline_argument);
+                               exit(1);
+                       }
+                       break;
+               default:
+                       break;
+               }
        }
 
-       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 */