2 * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
26 #include <isc/buffer.h>
27 #include <isc/entropy.h>
31 #include <isc/socket.h>
32 #include <isc/string.h>
34 #include <isc/timer.h>
39 isc_mem_t *mctx = NULL;
40 isc_entropy_t *ectx = NULL;
41 isc_log_t *lctx = NULL;
42 isc_taskmgr_t *taskmgr = NULL;
43 isc_timermgr_t *timermgr = NULL;
44 isc_socketmgr_t *socketmgr = NULL;
47 static isc_boolean_t hash_active = ISC_FALSE;
50 * Logging categories: this needs to match the list in bin/named/log.c.
52 static isc_logcategory_t categories[] = {
59 { "update-security", 0 },
60 { "query-errors", 0 },
66 if (socketmgr != NULL)
67 isc_socketmgr_destroy(&socketmgr);
69 isc_taskmgr_destroy(&taskmgr);
71 isc_timermgr_destroy(&timermgr);
77 #ifdef ISC_PLATFORM_USETHREADS
78 ncpus = isc_os_ncpus();
83 CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
84 CHECK(isc_timermgr_create(mctx, &timermgr));
85 CHECK(isc_socketmgr_create(mctx, &socketmgr));
86 return (ISC_R_SUCCESS);
94 isc_test_begin(FILE *logfile, isc_boolean_t start_managers) {
97 isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
98 CHECK(isc_mem_create(0, 0, &mctx));
99 CHECK(isc_entropy_create(mctx, &ectx));
101 CHECK(isc_hash_create(mctx, ectx, 255));
102 hash_active = ISC_TRUE;
104 if (logfile != NULL) {
105 isc_logdestination_t destination;
106 isc_logconfig_t *logconfig = NULL;
108 CHECK(isc_log_create(mctx, &lctx, &logconfig));
109 isc_log_registercategories(lctx, categories);
110 isc_log_setcontext(lctx);
112 destination.file.stream = logfile;
113 destination.file.name = NULL;
114 destination.file.versions = ISC_LOG_ROLLNEVER;
115 destination.file.maximum_size = 0;
116 CHECK(isc_log_createchannel(logconfig, "stderr",
120 CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
123 #ifdef ISC_PLATFORM_USETHREADS
124 ncpus = isc_os_ncpus();
130 CHECK(create_managers());
132 return (ISC_R_SUCCESS);
142 isc_taskmgr_destroy(&taskmgr);
144 isc_log_destroy(&lctx);
147 hash_active = ISC_FALSE;
150 isc_entropy_detach(&ectx);
155 isc_mem_destroy(&mctx);
159 * Sleep for 'usec' microseconds.
162 isc_test_nap(isc_uint32_t usec) {
163 #ifdef HAVE_NANOSLEEP
166 ts.tv_sec = usec / 1000000;
167 ts.tv_nsec = (usec % 1000000) * 1000;
168 nanosleep(&ts, NULL);
173 * No fractional-second sleep function is available, so we
174 * round up to the nearest second and sleep instead
176 sleep((usec / 1000000) + 1);