]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add the ability to select tests to run
authorMark Andrews <marka@isc.org>
Wed, 2 Sep 2020 08:22:21 +0000 (18:22 +1000)
committerMark Andrews <marka@isc.org>
Thu, 1 Oct 2020 13:03:01 +0000 (23:03 +1000)
task_test [-t <test_name>]

(cherry picked from commit 76837484e7d6f9a70c8217f9bd7f5aa1784fe353)

lib/isc/include/isc/Makefile.in
lib/isc/include/isc/cmocka.h [new file with mode: 0644]
lib/isc/tests/task_test.c
util/copyrights

index 958e825595f7512d6ffdd20f514745fe2ea0a2ac..3f4d39c3e62695a1a82db755f9365a970121beca 100644 (file)
@@ -19,7 +19,7 @@ VERSION=@BIND9_VERSION@
 # install target below.
 #
 HEADERS =      aes.h app.h assertions.h boolean.h backtrace.h base32.h base64.h \
-               bind9.h buffer.h bufferlist.h commandline.h \
+               bind9.h buffer.h bufferlist.h cmocka.h commandline.h \
                counter.h crc64.h deprecated.h entropy.h errno.h \
                endian.h error.h event.h eventclass.h file.h formatcheck.h \
                fsaccess.h hash.h heap.h hex.h hmacmd5.h hmacsha.h \
diff --git a/lib/isc/include/isc/cmocka.h b/lib/isc/include/isc/cmocka.h
new file mode 100644 (file)
index 0000000..aadfcad
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+/*! \file isc/cmocka.h */
+
+#pragma once
+
+#include <cmocka.h>
+
+#include <isc/lang.h>
+
+ISC_LANG_BEGINDECLS
+
+/*
+ * Copy the test identified by 'name' from 'tests' to 'selected'.
+ */
+#define cmocka_add_test_byname(tests, name, selected)                          \
+       _cmocka_add_test_byname(tests, sizeof(tests) / sizeof(tests[0]), name, \
+                               selected,                                      \
+                               sizeof(selected) / sizeof(selected[0]))
+
+static inline bool
+_cmocka_add_test_byname(const struct CMUnitTest *tests, size_t ntests,
+                       const char *name, struct CMUnitTest *selected,
+                       size_t nselected) {
+       size_t i, j;
+
+       for (i = 0; i < ntests && tests[i].name != NULL; i++) {
+               if (strcmp(tests[i].name, name) != 0) {
+                       continue;
+               }
+               for (j = 0; j < nselected && selected[j].name != NULL; j++) {
+                       if (strcmp(tests[j].name, name) == 0) {
+                               break;
+                       }
+               }
+               if (j < nselected && selected[j].name == NULL) {
+                       selected[j] = tests[i];
+               }
+               return (true);
+       }
+       return (false);
+}
+
+ISC_LANG_ENDDECLS
index 7490e98d964cdccc8f3edb889fe2b3c2d1c7318a..24a325c05ccc822f7477482955bd0dc997da4125 100644 (file)
@@ -25,8 +25,8 @@
 #include <unistd.h>
 
 #define UNIT_TESTING
-#include <cmocka.h>
 
+#include <isc/cmocka.h>
 #include <isc/commandline.h>
 #include <isc/condition.h>
 #include <isc/mem.h>
@@ -1571,10 +1571,22 @@ main(int argc, char **argv) {
                                                _setup, _teardown),
 #endif
        };
+       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;
@@ -1583,8 +1595,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 */
index 4dfed39ba48d2a213bed41ab694286f808a50082..788b703b4e60d2b51ab6b9f61f0a574e7e29d5f9 100644 (file)
 ./lib/isc/include/isc/boolean.h                        C       2018,2019,2020
 ./lib/isc/include/isc/buffer.h                 C       1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2010,2012,2014,2016,2017,2018,2019,2020
 ./lib/isc/include/isc/bufferlist.h             C       1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020
+./lib/isc/include/isc/cmocka.h                 C       2020
 ./lib/isc/include/isc/commandline.h            C       1999,2000,2001,2004,2005,2006,2007,2015,2016,2018,2019,2020
 ./lib/isc/include/isc/counter.h                        C       2014,2016,2018,2019,2020
 ./lib/isc/include/isc/crc64.h                  C       2013,2016,2018,2019,2020