sync with HEAD
This commit is contained in:
@@ -14,12 +14,15 @@
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dnstest.c,v 1.2.6.4 2011/09/05 07:19:26 each Exp $ */
|
||||
/* $Id: dnstest.c,v 1.2.6.5 2011/11/04 07:38:23 marka Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/entropy.h>
|
||||
@@ -32,9 +35,12 @@
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/fixedname.h>
|
||||
#include <dns/log.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/result.h>
|
||||
#include <dns/view.h>
|
||||
#include <dns/zone.h>
|
||||
|
||||
#include <dst/dst.h>
|
||||
|
||||
@@ -44,8 +50,11 @@ isc_mem_t *mctx = NULL;
|
||||
isc_entropy_t *ectx = NULL;
|
||||
isc_log_t *lctx = NULL;
|
||||
isc_taskmgr_t *taskmgr = NULL;
|
||||
isc_task_t *maintask = NULL;
|
||||
isc_timermgr_t *timermgr = NULL;
|
||||
isc_socketmgr_t *socketmgr = NULL;
|
||||
dns_zonemgr_t *zonemgr = NULL;
|
||||
isc_boolean_t app_running = ISC_FALSE;
|
||||
int ncpus;
|
||||
|
||||
static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
|
||||
@@ -67,8 +76,12 @@ static isc_logcategory_t categories[] = {
|
||||
|
||||
static void
|
||||
cleanup_managers() {
|
||||
if (app_running)
|
||||
isc_app_finish();
|
||||
if (socketmgr != NULL)
|
||||
isc_socketmgr_destroy(&socketmgr);
|
||||
if (maintask != NULL)
|
||||
isc_task_destroy(&maintask);
|
||||
if (taskmgr != NULL)
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
if (timermgr != NULL)
|
||||
@@ -87,6 +100,7 @@ create_managers() {
|
||||
CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
|
||||
CHECK(isc_timermgr_create(mctx, &timermgr));
|
||||
CHECK(isc_socketmgr_create(mctx, &socketmgr));
|
||||
CHECK(isc_task_create(taskmgr, 0, &maintask));
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
@@ -98,6 +112,8 @@ isc_result_t
|
||||
dns_test_begin(FILE *logfile, isc_boolean_t start_managers) {
|
||||
isc_result_t result;
|
||||
|
||||
if (start_managers)
|
||||
CHECK(isc_app_start());
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
||||
CHECK(isc_mem_create(0, 0, &mctx));
|
||||
CHECK(isc_entropy_create(mctx, &ectx));
|
||||
@@ -134,6 +150,14 @@ dns_test_begin(FILE *logfile, isc_boolean_t 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)
|
||||
CHECK(ISC_R_FAILURE);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
@@ -162,3 +186,114 @@ dns_test_end() {
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a zone with origin 'name', return a pointer to the zone object in
|
||||
* 'zonep'. If 'view' is set, add the zone to that view; otherwise, create
|
||||
* a new view for the purpose.
|
||||
*
|
||||
* If the created view is going to be needed by the caller subsequently,
|
||||
* then 'keepview' should be set to true; this will prevent the view
|
||||
* from being detached. In this case, the caller is responsible for
|
||||
* detaching the view.
|
||||
*/
|
||||
isc_result_t
|
||||
dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
|
||||
isc_boolean_t keepview)
|
||||
{
|
||||
isc_result_t result;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_buffer_t buffer;
|
||||
dns_fixedname_t fixorigin;
|
||||
dns_name_t *origin;
|
||||
|
||||
if (view == NULL)
|
||||
CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view));
|
||||
else if (!keepview)
|
||||
keepview = ISC_TRUE;
|
||||
|
||||
CHECK(dns_zone_create(&zone, mctx));
|
||||
|
||||
isc_buffer_init(&buffer, name, strlen(name));
|
||||
isc_buffer_add(&buffer, strlen(name));
|
||||
dns_fixedname_init(&fixorigin);
|
||||
origin = dns_fixedname_name(&fixorigin);
|
||||
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL));
|
||||
CHECK(dns_zone_setorigin(zone, origin));
|
||||
dns_zone_setview(zone, view);
|
||||
dns_zone_settype(zone, dns_zone_master);
|
||||
dns_zone_setclass(zone, view->rdclass);
|
||||
dns_view_addzone(view, zone);
|
||||
|
||||
if (!keepview)
|
||||
dns_view_detach(&view);
|
||||
|
||||
*zonep = zone;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
if (zone != NULL)
|
||||
dns_zone_detach(&zone);
|
||||
if (view != NULL)
|
||||
dns_view_detach(&view);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_test_setupzonemgr() {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr == NULL);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&zonemgr);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_test_managezone(dns_zone_t *zone) {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr != NULL);
|
||||
|
||||
result = dns_zonemgr_setsize(zonemgr, 1);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
result = dns_zonemgr_managezone(zonemgr, zone);
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
dns_test_releasezone(dns_zone_t *zone) {
|
||||
REQUIRE(zonemgr != NULL);
|
||||
dns_zonemgr_releasezone(zonemgr, zone);
|
||||
}
|
||||
|
||||
void
|
||||
dns_test_closezonemgr() {
|
||||
REQUIRE(zonemgr != NULL);
|
||||
|
||||
dns_zonemgr_shutdown(zonemgr);
|
||||
dns_zonemgr_detach(&zonemgr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sleep for 'usec' microseconds.
|
||||
*/
|
||||
void
|
||||
dns_test_nap(isc_uint32_t usec) {
|
||||
#ifdef HAVE_NANOSLEEP
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = usec / 1000000;
|
||||
ts.tv_nsec = (usec % 1000000) * 1000;
|
||||
nanosleep(&ts, NULL);
|
||||
#elif HAVE_USLEEP
|
||||
usleep(usec);
|
||||
#else
|
||||
/*
|
||||
* No fractional-second sleep function is available, so we
|
||||
* round up to the nearest second and sleep instead
|
||||
*/
|
||||
sleep((usec / 1000000) + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dnstest.h,v 1.2.6.3 2011/09/05 07:19:26 each Exp $ */
|
||||
/* $Id: dnstest.h,v 1.2.6.4 2011/11/04 07:38:23 marka Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/result.h>
|
||||
#include <dns/zone.h>
|
||||
|
||||
#define CHECK(r) \
|
||||
do { \
|
||||
@@ -42,11 +43,13 @@
|
||||
extern isc_mem_t *mctx;
|
||||
extern isc_entropy_t *ectx;
|
||||
extern isc_log_t *lctx;
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
isc_socketmgr_t *socketmgr;
|
||||
int ncpus;
|
||||
|
||||
extern isc_taskmgr_t *taskmgr;
|
||||
extern isc_task_t *maintask;
|
||||
extern isc_timermgr_t *timermgr;
|
||||
extern isc_socketmgr_t *socketmgr;
|
||||
extern dns_zonemgr_t *zonemgr;
|
||||
extern isc_boolean_t app_running;
|
||||
extern int ncpus;
|
||||
|
||||
isc_result_t
|
||||
dns_test_begin(FILE *logfile, isc_boolean_t create_managers);
|
||||
@@ -54,3 +57,21 @@ dns_test_begin(FILE *logfile, isc_boolean_t create_managers);
|
||||
void
|
||||
dns_test_end(void);
|
||||
|
||||
isc_result_t
|
||||
dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
|
||||
isc_boolean_t keepview);
|
||||
|
||||
isc_result_t
|
||||
dns_test_setupzonemgr(void);
|
||||
|
||||
isc_result_t
|
||||
dns_test_managezone(dns_zone_t *zone);
|
||||
|
||||
void
|
||||
dns_test_releasezone(dns_zone_t *zone);
|
||||
|
||||
void
|
||||
dns_test_closezonemgr(void);
|
||||
|
||||
void
|
||||
dns_test_nap(isc_uint32_t usec);
|
||||
|
||||
Reference in New Issue
Block a user