mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-09 01:42:07 -04:00
assert if {isc,dns,ns}_test_begin() is called when a prior test is running
This commit is contained in:
parent
b434b0a4b6
commit
d8766293ab
3 changed files with 107 additions and 50 deletions
|
|
@ -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) {
|
||||
isc_log_destroy(&lctx);
|
||||
}
|
||||
|
||||
if (lctx != NULL)
|
||||
isc_log_destroy(&lctx);
|
||||
|
||||
if (mctx != NULL)
|
||||
if (mctx != NULL) {
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
||||
test_running = false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
isc_log_destroy(&lctx);
|
||||
}
|
||||
|
||||
if (lctx != NULL)
|
||||
isc_log_destroy(&lctx);
|
||||
|
||||
if (mctx != NULL)
|
||||
if (mctx != NULL) {
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
||||
test_running = false;
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
|
|
|
|||
Loading…
Reference in a new issue