]> 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 13:05:10 +0000 (23:05 +1000)
(cherry picked from commit 6293682020472e66a92094b57475a6b13ca1fa77)

lib/dns/tests/rdata_test.c

index 3baf31faf1fda62b4d1508afd2b3d5c49cec0284..3cddb6487ead0ac8cd30cf66af814447c79fbe9c 100644 (file)
@@ -24,8 +24,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>
@@ -2757,14 +2758,46 @@ 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, dns_test_init, dns_test_final));
+       if (selected[0].name != NULL) {
+               return (cmocka_run_group_tests(tests, dns_test_init,
+                                              dns_test_final));
+       } else {
+               return (cmocka_run_group_tests(tests, dns_test_init,
+                                              dns_test_final));
+       }
 }
 
 #else /* HAVE_CMOCKA */