]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
assert if {isc,dns,ns}_test_begin() is called when a prior test is running
authorEvan Hunt <each@isc.org>
Fri, 26 Oct 2018 00:02:46 +0000 (17:02 -0700)
committerEvan Hunt <each@isc.org>
Thu, 15 Nov 2018 04:17:04 +0000 (20:17 -0800)
lib/dns/tests/dnstest.c
lib/isc/tests/isctest.c
lib/ns/tests/nstest.c

index 51f425e3a4c110d7cb002fd8311895a636d58507..ad348f3addaa762abb52e4d3103dd9cfbadcd86f 100644 (file)
@@ -59,6 +59,7 @@ int ncpus;
 bool debug_mem_record = true;
 
 static bool dst_active = false;
+static bool test_running = false;
 
 /*
  * Logging categories: this needs to match the list in bin/named/log.c.
@@ -77,16 +78,22 @@ static isc_logcategory_t categories[] = {
 
 static void
 cleanup_managers(void) {
-       if (app_running)
-               isc_app_finish();
-       if (socketmgr != NULL)
-               isc_socketmgr_destroy(&socketmgr);
-       if (maintask != NULL)
+       if (maintask != NULL) {
+               isc_task_shutdown(maintask);
                isc_task_destroy(&maintask);
-       if (taskmgr != NULL)
+       }
+       if (socketmgr != NULL) {
+               isc_socketmgr_destroy(&socketmgr);
+       }
+       if (taskmgr != NULL) {
                isc_taskmgr_destroy(&taskmgr);
-       if (timermgr != NULL)
+       }
+       if (timermgr != NULL) {
                isc_timermgr_destroy(&timermgr);
+       }
+       if (app_running) {
+               isc_app_finish();
+       }
 }
 
 static isc_result_t
@@ -109,22 +116,30 @@ isc_result_t
 dns_test_begin(FILE *logfile, bool start_managers) {
        isc_result_t result;
 
-       if (start_managers)
+       INSIST(!test_running);
+       test_running = true;
+
+       if (start_managers) {
                CHECK(isc_app_start());
-       if (debug_mem_record)
+       }
+       if (debug_mem_record) {
                isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+       }
+
+       INSIST(mctx == NULL);
        CHECK(isc_mem_create(0, 0, &mctx));
 
-       if (!dst_active) {
-               CHECK(dst_lib_init(mctx, NULL));
-               dst_active = true;
-       }
+       INSIST(!dst_active);
+       CHECK(dst_lib_init(mctx, NULL));
+       dst_active = true;
 
        if (logfile != NULL) {
                isc_logdestination_t destination;
                isc_logconfig_t *logconfig = NULL;
 
+               INSIST(lctx == NULL);
                CHECK(isc_log_create(mctx, &lctx, &logconfig));
+
                isc_log_registercategories(lctx, categories);
                isc_log_setcontext(lctx);
                dns_log_init(lctx);
@@ -143,8 +158,9 @@ dns_test_begin(FILE *logfile, bool start_managers) {
 
        dns_result_register();
 
-       if (start_managers)
+       if (start_managers) {
                CHECK(create_managers());
+       }
 
        /*
         * The caller might run from another directory, so tests
@@ -166,17 +182,18 @@ void
 dns_test_end(void) {
        cleanup_managers();
 
-       if (dst_active) {
-               dst_lib_destroy();
-               dst_active = false;
-       }
+       dst_lib_destroy();
+       dst_active = false;
 
-       if (lctx != NULL)
+       if (lctx != NULL) {
                isc_log_destroy(&lctx);
+       }
 
-       if (mctx != NULL)
+       if (mctx != NULL) {
                isc_mem_destroy(&mctx);
+       }
 
+       test_running = false;
 }
 
 /*
index fae6995bde2622021cbe44a1b8327d3e06563c72..66ca877e03eb6b7d6c8d00685fd7b347162e2f8a 100644 (file)
@@ -18,7 +18,6 @@
 #include <stdlib.h>
 #include <time.h>
 
-#include <isc/app.h>
 #include <isc/buffer.h>
 #include <isc/hash.h>
 #include <isc/mem.h>
@@ -39,6 +38,8 @@ isc_socketmgr_t *socketmgr = NULL;
 isc_task_t *maintask = NULL;
 int ncpus;
 
+static bool test_running = false;
+
 /*
  * Logging categories: this needs to match the list in bin/named/log.c.
  */
@@ -56,14 +57,19 @@ static isc_logcategory_t categories[] = {
 
 static void
 cleanup_managers(void) {
-       if (maintask != NULL)
+       if (maintask != NULL) {
+               isc_task_shutdown(maintask);
                isc_task_destroy(&maintask);
-       if (socketmgr != NULL)
+       }
+       if (socketmgr != NULL) {
                isc_socketmgr_destroy(&socketmgr);
-       if (taskmgr != NULL)
+       }
+       if (taskmgr != NULL) {
                isc_taskmgr_destroy(&taskmgr);
-       if (timermgr != NULL)
+       }
+       if (timermgr != NULL) {
                isc_timermgr_destroy(&timermgr);
+       }
 }
 
 static isc_result_t
@@ -99,14 +105,21 @@ isc_test_begin(FILE *logfile, bool start_managers,
 {
        isc_result_t result;
 
+       INSIST(!test_running);
+       test_running = true;
+
        isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+
+       INSIST(mctx == NULL);
        CHECK(isc_mem_create(0, 0, &mctx));
 
        if (logfile != NULL) {
                isc_logdestination_t destination;
                isc_logconfig_t *logconfig = NULL;
 
+               INSIST(lctx == NULL);
                CHECK(isc_log_create(mctx, &lctx, &logconfig));
+
                isc_log_registercategories(lctx, categories);
                isc_log_setcontext(lctx);
 
@@ -136,17 +149,23 @@ isc_test_begin(FILE *logfile, bool start_managers,
 
 void
 isc_test_end(void) {
-       if (maintask != NULL)
+       if (maintask != NULL) {
                isc_task_detach(&maintask);
-       if (taskmgr != NULL)
+       }
+       if (taskmgr != NULL) {
                isc_taskmgr_destroy(&taskmgr);
+       }
 
        cleanup_managers();
 
-       if (lctx != NULL)
+       if (lctx != NULL) {
                isc_log_destroy(&lctx);
-       if (mctx != NULL)
+       }
+       if (mctx != NULL) {
                isc_mem_destroy(&mctx);
+       }
+
+       test_running = false;
 }
 
 /*
index d71dbd68760e725c5ec331c779b432673c72dfaf..2e6a97d437671e8dbb99d42a18a0870dab69cb17 100644 (file)
@@ -69,6 +69,7 @@ bool debug_mem_record = true;
 bool run_managers = false;
 
 static bool dst_active = false;
+static bool test_running = false;
 
 static dns_zone_t *served_zone = NULL;
 
@@ -131,9 +132,6 @@ shutdown_managers(isc_task_t *task, isc_event_t *event) {
 
 static void
 cleanup_managers(void) {
-       if (app_running)
-               isc_app_finish();
-
        shutdown_done = false;
 
        if (maintask != NULL) {
@@ -150,14 +148,21 @@ cleanup_managers(void) {
                ns_test_nap(500000);
        }
 
-       if (sctx != NULL)
+       if (sctx != NULL) {
                ns_server_detach(&sctx);
-       if (socketmgr != NULL)
+       }
+       if (socketmgr != NULL) {
                isc_socketmgr_destroy(&socketmgr);
-       if (taskmgr != NULL)
+       }
+       if (taskmgr != NULL) {
                isc_taskmgr_destroy(&taskmgr);
-       if (timermgr != NULL)
+       }
+       if (timermgr != NULL) {
                isc_timermgr_destroy(&timermgr);
+       }
+       if (app_running) {
+               isc_app_finish();
+       }
 }
 
 static void
@@ -203,6 +208,7 @@ create_managers(void) {
                                   scan_interfaces, NULL,
                                   sizeof (isc_event_t));
        isc_task_send(maintask, &event);
+
        /*
         * There's no straightforward way to determine
         * whether the interfaces have been scanned,
@@ -223,20 +229,31 @@ isc_result_t
 ns_test_begin(FILE *logfile, bool start_managers) {
        isc_result_t result;
 
-       if (start_managers)
+       INSIST(!test_running);
+       test_running = true;
+
+       if (start_managers) {
                CHECK(isc_app_start());
-       if (debug_mem_record)
+       }
+       if (debug_mem_record) {
                isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+       }
+
+       INSIST(mctx == NULL);
        CHECK(isc_mem_create(0, 0, &mctx));
 
-       CHECK(dst_lib_init(mctx, NULL));
-       dst_active = true;
+       if (!dst_active) {
+               CHECK(dst_lib_init(mctx, NULL));
+               dst_active = true;
+       }
 
        if (logfile != NULL) {
                isc_logdestination_t destination;
                isc_logconfig_t *logconfig = NULL;
 
+               INSIST(lctx == NULL);
                CHECK(isc_log_create(mctx, &lctx, &logconfig));
+
                isc_log_registercategories(lctx, categories);
                isc_log_setcontext(lctx);
                dns_log_init(lctx);
@@ -255,16 +272,18 @@ ns_test_begin(FILE *logfile, bool start_managers) {
 
        dns_result_register();
 
-       if (start_managers)
+       if (start_managers) {
                CHECK(create_managers());
+       }
 
        /*
         * atf-run changes us to a /tmp directory, so tests
         * that access test data files must first chdir to the proper
         * location.
         */
-       if (chdir(TESTS) == -1)
+       if (chdir(TESTS) == -1) {
                CHECK(ISC_R_FAILURE);
+       }
 
        ns__hook_table = NULL;
 
@@ -279,16 +298,18 @@ void
 ns_test_end(void) {
        cleanup_managers();
 
-       if (dst_active) {
-               dst_lib_destroy();
-               dst_active = false;
-       }
+       dst_lib_destroy();
+       dst_active = false;
 
-       if (lctx != NULL)
+       if (lctx != NULL) {
                isc_log_destroy(&lctx);
+       }
 
-       if (mctx != NULL)
+       if (mctx != NULL) {
                isc_mem_destroy(&mctx);
+       }
+
+       test_running = false;
 }
 
 isc_result_t