mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 05:28:00 +00:00
3131. [func] Improve scalability by allocating one zone task
per 100 zones at startup time, rather than using a fixed-size task table. [RT #24406]
This commit is contained in:
parent
b5b6bddcd9
commit
c46ce2d79b
9
bin/tests/startperf/README
Normal file
9
bin/tests/startperf/README
Normal file
@ -0,0 +1,9 @@
|
||||
These scripts generate a named.conf file with an arbitrary number of
|
||||
small zones, for testing startup performance.
|
||||
|
||||
To generate a test server with 1000 zones, run:
|
||||
|
||||
$ sh setup.sh 1000 > named.conf
|
||||
|
||||
Zones are generated with random names, and all of them load from the same
|
||||
file: smallzone.db.
|
32
bin/tests/startperf/makenames.pl
Normal file
32
bin/tests/startperf/makenames.pl
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
# PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: makenames.pl,v 1.2 2011/07/06 05:05:51 each Exp $
|
||||
use strict;
|
||||
|
||||
die "Usage: makenames.pl <num>" if (@ARGV == 0);
|
||||
|
||||
my @chars = split("", "abcdefghijklmnopqrstuvwxyz123456789");
|
||||
|
||||
srand;
|
||||
for (my $i = 0; $i < @ARGV[0]; $i++) {
|
||||
my $name = "";
|
||||
for (my $j = 0; $j < 10; $j++) {
|
||||
my $r = rand 35;
|
||||
$name .= $chars[$r];
|
||||
}
|
||||
print "$name" . ".example\n";
|
||||
}
|
48
bin/tests/startperf/setup.sh
Normal file
48
bin/tests/startperf/setup.sh
Normal file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <number of zones>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
. ../system/conf.sh
|
||||
|
||||
cat << EOF
|
||||
options {
|
||||
directory "`pwd`";
|
||||
listen-on { localhost; };
|
||||
listen-on-v6 { localhost; };
|
||||
port 5300;
|
||||
allow-query { any; };
|
||||
allow-transfer { localhost; };
|
||||
allow-recursion { none; };
|
||||
recursion no;
|
||||
};
|
||||
|
||||
key rndc_key {
|
||||
secret "1234abcd8765";
|
||||
algorithm hmac-md5;
|
||||
};
|
||||
|
||||
controls {
|
||||
inet 127.0.0.1 port 9953 allow { any; } keys { rndc_key; };
|
||||
};
|
||||
|
||||
logging {
|
||||
channel basic {
|
||||
file "`pwd`/named.log" versions 3 size 100m;
|
||||
severity info;
|
||||
print-time yes;
|
||||
print-severity no;
|
||||
print-category no;
|
||||
};
|
||||
category default {
|
||||
basic;
|
||||
};
|
||||
};
|
||||
|
||||
EOF
|
||||
|
||||
$PERL makenames.pl $1 | while read zonename; do
|
||||
echo "zone $zonename { type master; file \"smallzone.db\"; };"
|
||||
done
|
17
bin/tests/startperf/smallzone.db
Normal file
17
bin/tests/startperf/smallzone.db
Normal file
@ -0,0 +1,17 @@
|
||||
$TTL 300 ; 5 minutes
|
||||
@ IN SOA mname1. . (
|
||||
2000042407 ; serial
|
||||
20 ; refresh (20 seconds)
|
||||
20 ; retry (20 seconds)
|
||||
1814400 ; expire (3 weeks)
|
||||
3600 ; minimum (1 hour)
|
||||
)
|
||||
NS ns
|
||||
ns A 10.53.0.3
|
||||
|
||||
a A 10.0.0.1
|
||||
b A 10.0.0.2
|
||||
d A 10.0.0.4
|
||||
z A 10.0.0.26
|
||||
a.a.a.a A 10.0.0.3
|
||||
*.e A 10.0.0.6
|
177
lib/dns/tests/zonemgr_test.c
Normal file
177
lib/dns/tests/zonemgr_test.c
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: zonemgr_test.c,v 1.2 2011/07/06 05:05:51 each Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
|
||||
#include <dns/name.h>
|
||||
#include <dns/view.h>
|
||||
#include <dns/zone.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
static isc_result_t
|
||||
make_zone(const char *name, dns_zone_t **zonep) {
|
||||
isc_result_t result;
|
||||
dns_view_t *view = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_buffer_t buffer;
|
||||
dns_fixedname_t fixorigin;
|
||||
dns_name_t *origin;
|
||||
|
||||
CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view));
|
||||
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_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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(zonemgr_create);
|
||||
ATF_TC_HEAD(zonemgr_create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create zone manager");
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_create, tc) {
|
||||
dns_zonemgr_t *zonemgr = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, ISC_TRUE);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&zonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_zonemgr_shutdown(zonemgr);
|
||||
dns_zonemgr_detach(&zonemgr);
|
||||
ATF_REQUIRE_EQ(zonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
|
||||
ATF_TC(zonemgr_managezone);
|
||||
ATF_TC_HEAD(zonemgr_managezone, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_managezone, tc) {
|
||||
dns_zonemgr_t *zonemgr = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, ISC_TRUE);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&zonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = make_zone("foo", &zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
||||
result = dns_zonemgr_managezone(zonemgr, zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(zonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
|
||||
result = dns_zonemgr_setsize(zonemgr, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Now it should succeed */
|
||||
result = dns_zonemgr_managezone(zonemgr, zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(zonemgr, DNS_ZONESTATE_ANY), 1);
|
||||
|
||||
dns_zonemgr_releasezone(zonemgr, zone);
|
||||
dns_zone_detach(&zone);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(zonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
|
||||
dns_zonemgr_shutdown(zonemgr);
|
||||
dns_zonemgr_detach(&zonemgr);
|
||||
ATF_REQUIRE_EQ(zonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, zonemgr_create);
|
||||
ATF_TP_ADD_TC(tp, zonemgr_managezone);
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX:
|
||||
* dns_zonemgr API calls that are not yet part of this unit test:
|
||||
*
|
||||
* - dns_zonemgr_attach
|
||||
* - dns_zonemgr_forcemaint
|
||||
* - dns_zonemgr_resumexfrs
|
||||
* - dns_zonemgr_shutdown
|
||||
* - dns_zonemgr_setsize
|
||||
* - dns_zonemgr_settransfersin
|
||||
* - dns_zonemgr_getttransfersin
|
||||
* - dns_zonemgr_settransfersperns
|
||||
* - dns_zonemgr_getttransfersperns
|
||||
* - dns_zonemgr_setiolimit
|
||||
* - dns_zonemgr_getiolimit
|
||||
* - dns_zonemgr_dbdestroyed
|
||||
* - dns_zonemgr_setserialqueryrate
|
||||
* - dns_zonemgr_getserialqueryrate
|
||||
* - dns_zonemgr_unreachable
|
||||
* - dns_zonemgr_unreachableadd
|
||||
*/
|
5
lib/isc/Atffile
Normal file
5
lib/isc/Atffile
Normal file
@ -0,0 +1,5 @@
|
||||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
5
lib/isc/tests/Atffile
Normal file
5
lib/isc/tests/Atffile
Normal file
@ -0,0 +1,5 @@
|
||||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp-glob: *_test
|
50
lib/isc/tests/Makefile.in
Normal file
50
lib/isc/tests/Makefile.in
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
# PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.2 2011/07/06 05:05:51 each Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
|
||||
@BIND9_VERSION@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
||||
CINCLUDES = -I. -Iinclude ${ISC_INCLUDES}
|
||||
CDEFINES = -DTESTS="\"${top_builddir}/lib/isc/tests/\""
|
||||
|
||||
ISCLIBS = ../libisc.@A@
|
||||
ISCDEPLIBS = ../libisc.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
|
||||
OBJS = isctest.@O@
|
||||
SRCS = isctest.c taskpool_test.c
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS = taskpool_test@EXEEXT@
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
taskpool_test@EXEEXT@: taskpool_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
taskpool_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
clean distclean::
|
||||
rm -f ${TARGETS}
|
117
lib/isc/tests/isctest.c
Normal file
117
lib/isc/tests/isctest.c
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: isctest.c,v 1.2 2011/07/06 05:05:52 each Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/hash.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/os.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_entropy_t *ectx = NULL;
|
||||
isc_log_t *lctx = NULL;
|
||||
isc_taskmgr_t *taskmgr = NULL;
|
||||
int ncpus;
|
||||
|
||||
static isc_boolean_t hash_active = ISC_FALSE;
|
||||
|
||||
/*
|
||||
* Logging categories: this needs to match the list in bin/named/log.c.
|
||||
*/
|
||||
static isc_logcategory_t categories[] = {
|
||||
{ "", 0 },
|
||||
{ "client", 0 },
|
||||
{ "network", 0 },
|
||||
{ "update", 0 },
|
||||
{ "queries", 0 },
|
||||
{ "unmatched", 0 },
|
||||
{ "update-security", 0 },
|
||||
{ "query-errors", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
isc_result_t
|
||||
isc_test_begin(FILE *logfile) {
|
||||
isc_result_t result;
|
||||
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
||||
CHECK(isc_mem_create(0, 0, &mctx));
|
||||
CHECK(isc_entropy_create(mctx, &ectx));
|
||||
|
||||
CHECK(isc_hash_create(mctx, ectx, 255));
|
||||
hash_active = ISC_TRUE;
|
||||
|
||||
if (logfile != NULL) {
|
||||
isc_logdestination_t destination;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
|
||||
CHECK(isc_log_create(mctx, &lctx, &logconfig));
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_setcontext(lctx);
|
||||
|
||||
destination.file.stream = logfile;
|
||||
destination.file.name = NULL;
|
||||
destination.file.versions = ISC_LOG_ROLLNEVER;
|
||||
destination.file.maximum_size = 0;
|
||||
CHECK(isc_log_createchannel(logconfig, "stderr",
|
||||
ISC_LOG_TOFILEDESC,
|
||||
ISC_LOG_DYNAMIC,
|
||||
&destination, 0));
|
||||
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
|
||||
}
|
||||
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
ncpus = isc_os_ncpus();
|
||||
#else
|
||||
ncpus = 1;
|
||||
#endif
|
||||
|
||||
CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
isc_test_end();
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
isc_test_end() {
|
||||
if (taskmgr != NULL)
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
if (lctx != NULL)
|
||||
isc_log_destroy(&lctx);
|
||||
if (hash_active) {
|
||||
isc_hash_destroy();
|
||||
hash_active = ISC_FALSE;
|
||||
}
|
||||
if (ectx != NULL)
|
||||
isc_entropy_detach(&ectx);
|
||||
if (mctx != NULL)
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
52
lib/isc/tests/isctest.h
Normal file
52
lib/isc/tests/isctest.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: isctest.h,v 1.2 2011/07/06 05:05:52 each Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/hash.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#define CHECK(r) \
|
||||
do { \
|
||||
result = (r); \
|
||||
if (result != ISC_R_SUCCESS) \
|
||||
goto cleanup; \
|
||||
} while (0)
|
||||
|
||||
extern isc_mem_t *mctx;
|
||||
extern isc_entropy_t *ectx;
|
||||
extern isc_log_t *lctx;
|
||||
extern isc_taskmgr_t *taskmgr;
|
||||
extern int ncpus;
|
||||
|
||||
isc_result_t
|
||||
isc_test_begin(FILE *logfile);
|
||||
|
||||
void
|
||||
isc_test_end(void);
|
||||
|
161
lib/isc/tests/taskpool_test.c
Normal file
161
lib/isc/tests/taskpool_test.c
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
||||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: taskpool_test.c,v 1.2 2011/07/06 05:05:52 each Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/task.h>
|
||||
#include <isc/taskpool.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* Create a taskpool */
|
||||
ATF_TC(create_pool);
|
||||
ATF_TC_HEAD(create_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(create_pool, tc) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 8, 2, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool), 8);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/* Resize a taskpool */
|
||||
ATF_TC(expand_pool);
|
||||
ATF_TC_HEAD(expand_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "expand a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(expand_pool, tc) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 10, 2, &pool1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool1), 10);
|
||||
|
||||
/* resizing to a smaller size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 5, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to the same size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 10, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to larger size should make a new pool */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 20, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 20);
|
||||
ATF_REQUIRE(pool2 != hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
|
||||
isc_taskpool_destroy(&pool2);
|
||||
ATF_REQUIRE_EQ(pool2, NULL);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/* Get tasks */
|
||||
ATF_TC(get_tasks);
|
||||
ATF_TC_HEAD(get_tasks, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(get_tasks, tc) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool), 2);
|
||||
|
||||
/* two tasks in pool; make sure we can access them more than twice */
|
||||
isc_taskpool_gettask(pool, &task1);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task1));
|
||||
|
||||
isc_taskpool_gettask(pool, &task2);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task2));
|
||||
|
||||
isc_taskpool_gettask(pool, &task3);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task3));
|
||||
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
isc_task_destroy(&task3);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, create_pool);
|
||||
ATF_TP_ADD_TC(tp, expand_pool);
|
||||
ATF_TP_ADD_TC(tp, get_tasks);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user