2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

Give the unit tests a big overhaul

The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.

This commit does several things:

1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
   conditionals.

2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
   implementations, test lists, and the main test routine, so we don't
   have to repeat this all over again.  The macros were modeled after
   libuv test suite but adapted to cmocka as the test driver.

   A simple example of a unit test would be:

    ISC_RUN_TEST_IMPL(test1) { assert_true(true); }

    ISC_TEST_LIST_START
    ISC_TEST_ENTRY(test1)
    ISC_TEST_LIST_END

    ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)

   For more complicated examples including group setup and teardown
   functions, and per-test setup and teardown functions.

3. The macros prefix the test functions and cmocka entries, so the name
   of the test can now match the tested function name, and we don't have
   to append `_test` because `run_test_` is automatically prepended to
   the main test function, and `setup_test_` and `teardown_test_` is
   prepended to setup and teardown function.

4. Update all the unit tests to use the new syntax and fix a few bits
   here and there.

5. In the future, we can separate the test declarations and test
   implementations which are going to greatly help with uncluttering the
   bigger unit tests like doh_test and netmgr_test, because the test
   implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
   and `ISC_RUN_TEST_IMPL` for more details.

NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros.  There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
This commit is contained in:
Ondřej Surý 2022-05-02 10:56:42 +02:00 committed by Evan Hunt
parent 3b757aa749
commit 63fe9312ff
81 changed files with 2288 additions and 5718 deletions

View File

@ -34,6 +34,12 @@ PointerAlignment: Right
PointerBindsToType: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<isc/test.h>$'
Priority: 100
- Regex: '^<dns/test.h>$'
Priority: 101
- Regex: '^<ns/test.h>$'
Priority: 102
- Regex: '^<isc/'
Priority: 5
- Regex: '^<(pk11|pkcs11)/'

View File

@ -34,6 +34,12 @@ PointerAlignment: Right
PointerBindsToType: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<isc/test.h>$'
Priority: 100
- Regex: '^<dns/test.h>$'
Priority: 101
- Regex: '^<ns/test.h>$'
Priority: 102
- Regex: '^<isc/'
Priority: 2
- Regex: '^<dns/'

View File

@ -28,15 +28,20 @@
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/cache.h>
#include <dns/diff.h>
#include <dns/zone.h>
#include <isc/test.h>
extern dns_zonemgr_t *zonemgr;
typedef struct {
dns_diffop_t op;
const char *owner;
dns_ttl_t ttl;
const char *type;
const char *rdata;
const char *owner;
dns_ttl_t ttl;
const char *type;
const char *rdata;
} zonechange_t;
#define ZONECHANGE_SENTINEL \
@ -44,25 +49,8 @@ typedef struct {
0, NULL, 0, NULL, NULL \
}
extern isc_mem_t *dt_mctx;
extern isc_log_t *lctx;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *maintask;
extern isc_timermgr_t *timermgr;
extern isc_nm_t *netmgr;
extern dns_zonemgr_t *zonemgr;
extern bool app_running;
extern int ncpus;
extern bool debug_mem_record;
isc_result_t
dns_test_begin(FILE *logfile, bool create_managers);
void
dns_test_end(void);
isc_result_t
dns_test_makeview(const char *name, dns_view_t **viewp);
dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp);
/*%
* Create a zone with origin 'name', return a pointer to the zone object in

View File

@ -24,11 +24,9 @@
#include <time.h>
#include <unistd.h>
#if HAVE_CMOCKA
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
@ -55,172 +53,45 @@
#include <dns/view.h>
#include <dns/zone.h>
#include "dnstest.h"
#include <dns/test.h>
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) { \
goto cleanup; \
} \
} while (0)
isc_mem_t *dt_mctx = NULL;
isc_log_t *lctx = NULL;
isc_nm_t *netmgr = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_task_t *maintask = NULL;
isc_timermgr_t *timermgr = NULL;
dns_zonemgr_t *zonemgr = NULL;
bool app_running = false;
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.
*/
static isc_logcategory_t categories[] = { { "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 } };
static void
cleanup_managers(void) {
if (maintask != NULL) {
isc_task_detach(&maintask);
}
isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
taskmgr == NULL ? NULL : &taskmgr,
timermgr == NULL ? NULL : &timermgr);
if (app_running) {
isc_app_finish();
}
}
static isc_result_t
create_managers(void) {
isc_result_t result;
ncpus = isc_os_ncpus();
isc_managers_create(dt_mctx, ncpus, 0, &netmgr, &taskmgr, &timermgr);
CHECK(isc_task_create(taskmgr, 0, &maintask, 0));
return (ISC_R_SUCCESS);
cleanup:
cleanup_managers();
return (result);
}
isc_result_t
dns_test_begin(FILE *logfile, bool start_managers) {
isc_result_t result;
INSIST(!test_running);
test_running = true;
if (start_managers) {
CHECK(isc_app_start());
}
if (debug_mem_record) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
}
INSIST(dt_mctx == NULL);
isc_mem_create(&dt_mctx);
/* Don't check the memory leaks as they hide the assertions */
isc_mem_setdestroycheck(dt_mctx, false);
INSIST(!dst_active);
CHECK(dst_lib_init(dt_mctx, NULL));
dst_active = true;
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
INSIST(lctx == NULL);
isc_log_create(dt_mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
destination.file.stream = logfile;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
}
if (start_managers) {
CHECK(create_managers());
}
/*
* The caller might run from another directory, so tests
* that access test data files must first chdir to the proper
* location.
*/
if (chdir(TESTS_DIR) == -1) {
CHECK(ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
cleanup:
dns_test_end();
return (result);
}
void
dns_test_end(void) {
cleanup_managers();
dst_lib_destroy();
dst_active = false;
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
if (dt_mctx != NULL) {
isc_mem_destroy(&dt_mctx);
}
test_running = false;
}
/*
* Create a view.
*/
isc_result_t
dns_test_makeview(const char *name, dns_view_t **viewp) {
dns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) {
isc_result_t result;
dns_view_t *view = NULL;
dns_cache_t *cache = NULL;
result = dns_view_create(mctx, dns_rdataclass_in, name, &view);
if (result != ISC_R_SUCCESS) {
return (result);
}
if (with_cache) {
result = dns_cache_create(mctx, mctx, taskmgr, timermgr,
dns_rdataclass_in, "", "rbt", 0, NULL,
&cache);
if (result != ISC_R_SUCCESS) {
dns_view_detach(&view);
return (result);
}
dns_view_setcache(view, cache, false);
/*
* Reference count for "cache" is now at 2, so decrement it in
* order for the cache to be automatically freed when "view"
* gets freed.
*/
dns_cache_detach(&cache);
}
CHECK(dns_view_create(dt_mctx, dns_rdataclass_in, name, &view));
*viewp = view;
return (ISC_R_SUCCESS);
cleanup:
if (view != NULL) {
dns_view_detach(&view);
}
return (result);
}
isc_result_t
@ -236,7 +107,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
/*
* Create the zone structure.
*/
result = dns_zone_create(&zone, dt_mctx, 0);
result = dns_zone_create(&zone, mctx, 0);
if (result != ISC_R_SUCCESS) {
return (result);
}
@ -259,7 +130,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
* If requested, create a view.
*/
if (createview) {
result = dns_test_makeview("view", &view);
result = dns_test_makeview("view", false, &view);
if (result != ISC_R_SUCCESS) {
goto detach_zone;
}
@ -292,8 +163,7 @@ dns_test_setupzonemgr(void) {
isc_result_t result;
REQUIRE(zonemgr == NULL);
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
&zonemgr);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr);
return (result);
}
@ -346,8 +216,8 @@ dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
return (result);
}
result = dns_db_create(dt_mctx, "rbt", name, dbtype, dns_rdataclass_in,
0, NULL, db);
result = dns_db_create(mctx, "rbt", name, dbtype, dns_rdataclass_in, 0,
NULL, db);
if (result != ISC_R_SUCCESS) {
return (result);
}
@ -426,10 +296,12 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
continue;
}
if (len % 2 != 0U) {
CHECK(ISC_R_UNEXPECTEDEND);
result = ISC_R_UNEXPECTEDEND;
break;
}
if (len > bufsiz * 2) {
CHECK(ISC_R_NOSPACE);
result = ISC_R_NOSPACE;
break;
}
rp = s;
for (i = 0; i < len; i += 2) {
@ -440,11 +312,10 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
}
}
*sizep = bp - buf;
if (result == ISC_R_SUCCESS) {
*sizep = bp - buf;
}
result = ISC_R_SUCCESS;
cleanup:
isc_stdio_close(f);
return (result);
}
@ -481,7 +352,7 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
/*
* Create a lexer as one is required by dns_rdata_fromtext().
*/
result = isc_lex_create(dt_mctx, 64, &lex);
result = isc_lex_create(mctx, 64, &lex);
if (result != ISC_R_SUCCESS) {
return (result);
}
@ -527,7 +398,7 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
* Parse input string, determining result.
*/
result = dns_rdata_fromtext(rdata, rdclass, rdtype, lex, dns_rootname,
0, dt_mctx, &target, &callbacks);
0, mctx, &target, &callbacks);
destroy_lexer:
isc_lex_destroy(&lex);
@ -546,7 +417,7 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
name = dns_fixedname_initname(fname);
isc_buffer_allocate(dt_mctx, &b, length);
isc_buffer_allocate(mctx, &b, length);
isc_buffer_putmem(b, (const unsigned char *)namestr, length);
result = dns_name_fromtext(name, b, dns_rootname, 0, NULL);
@ -571,15 +442,14 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
REQUIRE(diff != NULL);
REQUIRE(changes != NULL);
dns_diff_init(dt_mctx, diff);
dns_diff_init(mctx, diff);
for (i = 0; changes[i].owner != NULL; i++) {
/*
* Parse owner name.
*/
name = dns_fixedname_initname(&fixedname);
result = dns_name_fromstring(name, changes[i].owner, 0,
dt_mctx);
result = dns_name_fromstring(name, changes[i].owner, 0, mctx);
if (result != ISC_R_SUCCESS) {
break;
}
@ -610,7 +480,7 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
* Create a diff tuple for the parsed change and append it to
* the diff.
*/
result = dns_difftuple_create(dt_mctx, changes[i].op, name,
result = dns_difftuple_create(mctx, changes[i].op, name,
changes[i].ttl, &rdata, &tuple);
if (result != ISC_R_SUCCESS) {
break;
@ -624,4 +494,3 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
return (result);
}
#endif /* HAVE_CMOCKA */

View File

@ -15,7 +15,11 @@ LDADD += \
$(LIBDNS_LIBS)
check_LTLIBRARIES = libdnstest.la
libdnstest_la_SOURCES = dnstest.c dnstest.h
libdnstest_la_SOURCES = \
../../isc/test.c \
../../isc/include/isc/test.h \
../../dns/test.c \
../../dns/include/dns/test.h
check_PROGRAMS = \
acl_test \

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -31,36 +29,14 @@
#include <dns/acl.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
#define BUFLEN 255
#define BIGBUFLEN (70 * 1024)
#define TEST_ORIGIN "test"
/* test that dns_acl_isinsecure works */
static void
dns_acl_isinsecure_test(void **state) {
ISC_RUN_TEST_IMPL(dns_acl_isinsecure) {
isc_result_t result;
dns_acl_t *any = NULL;
dns_acl_t *none = NULL;
@ -74,16 +50,16 @@ dns_acl_isinsecure_test(void **state) {
UNUSED(state);
result = dns_acl_any(dt_mctx, &any);
result = dns_acl_any(mctx, &any);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_none(dt_mctx, &none);
result = dns_acl_none(mctx, &none);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_create(dt_mctx, 1, &notnone);
result = dns_acl_create(mctx, 1, &notnone);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_create(dt_mctx, 1, &notany);
result = dns_acl_create(mctx, 1, &notany);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_merge(notnone, none, false);
@ -93,7 +69,7 @@ dns_acl_isinsecure_test(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
#if defined(HAVE_GEOIP2)
result = dns_acl_create(dt_mctx, 1, &geoip);
result = dns_acl_create(mctx, 1, &geoip);
assert_int_equal(result, ISC_R_SUCCESS);
de = geoip->elements;
@ -108,7 +84,7 @@ dns_acl_isinsecure_test(void **state) {
de->node_num = dns_acl_node_count(geoip);
geoip->length++;
result = dns_acl_create(dt_mctx, 1, &notgeoip);
result = dns_acl_create(mctx, 1, &notgeoip);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_merge(notgeoip, geoip, false);
@ -135,24 +111,8 @@ dns_acl_isinsecure_test(void **state) {
#endif /* HAVE_GEOIP2 */
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dns_acl_isinsecure_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(dns_acl_isinsecure)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,28 +27,7 @@
#include <dns/name.h>
#include <dns/rdatalist.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
@ -61,17 +38,13 @@ _teardown(void **state) {
*/
/* test multiple calls to dns_db_getoriginnode */
static void
getoriginnode_test(void **state) {
ISC_RUN_TEST_IMPL(getoriginnode) {
dns_db_t *db = NULL;
dns_dbnode_t *node = NULL;
isc_mem_t *mctx = NULL;
isc_result_t result;
UNUSED(state);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
@ -85,21 +58,16 @@ getoriginnode_test(void **state) {
dns_db_detachnode(db, &node);
dns_db_detach(&db);
isc_mem_detach(&mctx);
}
/* test getservestalettl and setservestalettl */
static void
getsetservestalettl_test(void **state) {
ISC_RUN_TEST_IMPL(getsetservestalettl) {
dns_db_t *db = NULL;
isc_mem_t *mctx = NULL;
isc_result_t result;
dns_ttl_t ttl;
UNUSED(state);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
@ -119,12 +87,10 @@ getsetservestalettl_test(void **state) {
assert_int_equal(ttl, 6 * 3600);
dns_db_detach(&db);
isc_mem_detach(&mctx);
}
/* check DNS_DBFIND_STALEOK works */
static void
dns_dbfind_staleok_test(void **state) {
ISC_RUN_TEST_IMPL(dns_dbfind_staleok) {
dns_db_t *db = NULL;
dns_dbnode_t *node = NULL;
dns_fixedname_t example_fixed;
@ -135,14 +101,11 @@ dns_dbfind_staleok_test(void **state) {
dns_rdataset_t rdataset;
int count;
int pass;
isc_mem_t *mctx = NULL;
isc_result_t result;
unsigned char data[] = { 0x0a, 0x00, 0x00, 0x01 };
UNUSED(state);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
@ -277,18 +240,16 @@ dns_dbfind_staleok_test(void **state) {
}
dns_db_detach(&db);
isc_mem_detach(&mctx);
}
/* database class */
static void
class_test(void **state) {
ISC_RUN_TEST_IMPL(class) {
isc_result_t result;
dns_db_t *db = NULL;
UNUSED(state);
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
@ -302,15 +263,14 @@ class_test(void **state) {
}
/* database type */
static void
dbtype_test(void **state) {
ISC_RUN_TEST_IMPL(dbtype) {
isc_result_t result;
dns_db_t *db = NULL;
UNUSED(state);
/* DB has zone semantics */
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text,
@ -321,7 +281,7 @@ dbtype_test(void **state) {
dns_db_detach(&db);
/* DB has cache semantics */
result = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_cache,
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_db_load(db, "testdata/db/data.db", dns_masterformat_text,
@ -333,8 +293,7 @@ dbtype_test(void **state) {
}
/* database versions */
static void
version_test(void **state) {
ISC_RUN_TEST_IMPL(version) {
isc_result_t result;
dns_fixedname_t fname, ffound;
dns_name_t *name, *foundname;
@ -400,29 +359,13 @@ version_test(void **state) {
dns_db_detach(&db);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(getoriginnode_test),
cmocka_unit_test(getsetservestalettl_test),
cmocka_unit_test(dns_dbfind_staleok_test),
cmocka_unit_test_setup_teardown(class_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(dbtype_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(version_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(getoriginnode)
ISC_TEST_ENTRY(getsetservestalettl)
ISC_TEST_ENTRY(dns_dbfind_staleok)
ISC_TEST_ENTRY(class)
ISC_TEST_ENTRY(dbtype)
ISC_TEST_ENTRY(version)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -31,33 +29,12 @@
#include <dns/journal.h>
#include <dns/name.h>
#include "dnstest.h"
#include <dns/test.h>
#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
#define TEST_ORIGIN "test"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
static void
test_create(const char *oldfile, dns_db_t **old, const char *newfile,
dns_db_t **newdb) {
@ -71,8 +48,7 @@ test_create(const char *oldfile, dns_db_t **old, const char *newfile,
}
/* dns_db_diffx of identical content */
static void
diffx_same(void **state) {
ISC_RUN_TEST_IMPL(diffx_same) {
dns_db_t *newdb = NULL, *olddb = NULL;
isc_result_t result;
dns_diff_t diff;
@ -82,7 +58,7 @@ diffx_same(void **state) {
test_create("testdata/diff/zone1.data", &olddb,
"testdata/diff/zone1.data", &newdb);
dns_diff_init(dt_mctx, &diff);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
@ -95,8 +71,7 @@ diffx_same(void **state) {
}
/* dns_db_diffx of zone with record added */
static void
diffx_add(void **state) {
ISC_RUN_TEST_IMPL(diffx_add) {
dns_db_t *newdb = NULL, *olddb = NULL;
dns_difftuple_t *tuple;
isc_result_t result;
@ -108,7 +83,7 @@ diffx_add(void **state) {
test_create("testdata/diff/zone1.data", &olddb,
"testdata/diff/zone2.data", &newdb);
dns_diff_init(dt_mctx, &diff);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
@ -128,8 +103,7 @@ diffx_add(void **state) {
}
/* dns_db_diffx of zone with record removed */
static void
diffx_remove(void **state) {
ISC_RUN_TEST_IMPL(diffx_remove) {
dns_db_t *newdb = NULL, *olddb = NULL;
dns_difftuple_t *tuple;
isc_result_t result;
@ -141,7 +115,7 @@ diffx_remove(void **state) {
test_create("testdata/diff/zone1.data", &olddb,
"testdata/diff/zone3.data", &newdb);
dns_diff_init(dt_mctx, &diff);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
@ -160,26 +134,10 @@ diffx_remove(void **state) {
dns_db_detach(&olddb);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(diffx_same, _setup, _teardown),
cmocka_unit_test_setup_teardown(diffx_add, _setup, _teardown),
cmocka_unit_test_setup_teardown(diffx_remove, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(diffx_same)
ISC_TEST_ENTRY(diffx_add)
ISC_TEST_ENTRY(diffx_remove)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -30,33 +28,12 @@
#include <dns/dbiterator.h>
#include <dns/name.h>
#include "dnstest.h"
#include <dns/test.h>
#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
#define TEST_ORIGIN "test"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
static isc_result_t
make_name(const char *src, dns_name_t *name) {
isc_buffer_t b;
@ -82,15 +59,13 @@ test_create(const char *filename) {
dns_db_detach(&db);
}
static void
create(void **state) {
ISC_RUN_TEST_IMPL(create) {
UNUSED(state);
test_create("testdata/dbiterator/zone1.data");
}
static void
create_nsec3(void **state) {
ISC_RUN_TEST_IMPL(create_nsec3) {
UNUSED(state);
test_create("testdata/dbiterator/zone2.data");
@ -133,15 +108,13 @@ test_walk(const char *filename, int nodes) {
dns_db_detach(&db);
}
static void
walk(void **state) {
ISC_RUN_TEST_IMPL(walk) {
UNUSED(state);
test_walk("testdata/dbiterator/zone1.data", 12);
}
static void
walk_nsec3(void **state) {
ISC_RUN_TEST_IMPL(walk_nsec3) {
UNUSED(state);
test_walk("testdata/dbiterator/zone2.data", 33);
@ -184,15 +157,13 @@ test_reverse(const char *filename) {
dns_db_detach(&db);
}
static void
reverse(void **state) {
ISC_RUN_TEST_IMPL(reverse) {
UNUSED(state);
test_reverse("testdata/dbiterator/zone1.data");
}
static void
reverse_nsec3(void **state) {
ISC_RUN_TEST_IMPL(reverse_nsec3) {
UNUSED(state);
test_reverse("testdata/dbiterator/zone2.data");
@ -241,15 +212,13 @@ test_seek_node(const char *filename, int nodes) {
dns_db_detach(&db);
}
static void
seek_node(void **state) {
ISC_RUN_TEST_IMPL(seek_node) {
UNUSED(state);
test_seek_node("testdata/dbiterator/zone1.data", 9);
}
static void
seek_node_nsec3(void **state) {
ISC_RUN_TEST_IMPL(seek_node_nsec3) {
UNUSED(state);
test_seek_node("testdata/dbiterator/zone2.data", 30);
@ -285,15 +254,13 @@ test_seek_empty(const char *filename) {
dns_db_detach(&db);
}
static void
seek_empty(void **state) {
ISC_RUN_TEST_IMPL(seek_empty) {
UNUSED(state);
test_seek_empty("testdata/dbiterator/zone1.data");
}
static void
seek_empty_nsec3(void **state) {
ISC_RUN_TEST_IMPL(seek_empty_nsec3) {
UNUSED(state);
test_seek_empty("testdata/dbiterator/zone2.data");
@ -334,15 +301,13 @@ test_seek_nx(const char *filename) {
dns_db_detach(&db);
}
static void
seek_nx(void **state) {
ISC_RUN_TEST_IMPL(seek_nx) {
UNUSED(state);
test_seek_nx("testdata/dbiterator/zone1.data");
}
static void
seek_nx_nsec3(void **state) {
ISC_RUN_TEST_IMPL(seek_nx_nsec3) {
UNUSED(state);
test_seek_nx("testdata/dbiterator/zone2.data");
@ -356,39 +321,19 @@ seek_nx_nsec3(void **state) {
* dns_dbiterator_origin
* dns_dbiterator_setcleanmode
*/
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(create, _setup, _teardown),
cmocka_unit_test_setup_teardown(create_nsec3, _setup,
_teardown),
cmocka_unit_test_setup_teardown(walk, _setup, _teardown),
cmocka_unit_test_setup_teardown(walk_nsec3, _setup, _teardown),
cmocka_unit_test_setup_teardown(reverse, _setup, _teardown),
cmocka_unit_test_setup_teardown(reverse_nsec3, _setup,
_teardown),
cmocka_unit_test_setup_teardown(seek_node, _setup, _teardown),
cmocka_unit_test_setup_teardown(seek_node_nsec3, _setup,
_teardown),
cmocka_unit_test_setup_teardown(seek_empty, _setup, _teardown),
cmocka_unit_test_setup_teardown(seek_empty_nsec3, _setup,
_teardown),
cmocka_unit_test_setup_teardown(seek_nx, _setup, _teardown),
cmocka_unit_test_setup_teardown(seek_nx_nsec3, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(create)
ISC_TEST_ENTRY(create_nsec3)
ISC_TEST_ENTRY(walk)
ISC_TEST_ENTRY(walk_nsec3)
ISC_TEST_ENTRY(reverse)
ISC_TEST_ENTRY(reverse_nsec3)
ISC_TEST_ENTRY(seek_node)
ISC_TEST_ENTRY(seek_node_nsec3)
ISC_TEST_ENTRY(seek_empty)
ISC_TEST_ENTRY(seek_empty_nsec3)
ISC_TEST_ENTRY(seek_nx)
ISC_TEST_ENTRY(seek_nx_nsec3)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -37,7 +35,7 @@
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include "dnstest.h"
#include <dns/test.h>
static char tempname[11] = "dtXXXXXXXX";
static dns_db_t *db1 = NULL, *db2 = NULL;
@ -72,23 +70,20 @@ local_callback(const char *file, int line, isc_assertiontype_t type,
}
static int
_setup(void **state) {
setup_test(void **state) {
isc_result_t res;
UNUSED(state);
isc_assertion_setcallback(local_callback);
res = dns_test_begin(NULL, false);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
res = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db1);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_newversion(db1, &v1);
assert_non_null(v1);
res = dns_db_create(dt_mctx, "rbt", dns_rootname, dns_dbtype_zone,
res = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db2);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_newversion(db2, &v2);
@ -98,7 +93,7 @@ _setup(void **state) {
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
if (strcmp(tempname, "dtXXXXXXXX") != 0) {
@ -123,8 +118,6 @@ _teardown(void **state) {
assert_null(db2);
}
dns_test_end();
return (0);
}
@ -132,8 +125,7 @@ _teardown(void **state) {
* Check dns_db_attachversion() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
attachversion(void **state) {
ISC_RUN_TEST_IMPL(attachversion) {
dns_dbversion_t *v = NULL;
UNUSED(state);
@ -150,8 +142,7 @@ attachversion(void **state) {
* Check dns_db_closeversion() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
closeversion(void **state) {
ISC_RUN_TEST_IMPL(closeversion) {
UNUSED(state);
assert_non_null(v1);
@ -165,8 +156,7 @@ closeversion(void **state) {
* Check dns_db_find() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
find(void **state) {
ISC_RUN_TEST_IMPL(find) {
isc_result_t res;
dns_rdataset_t rdataset;
dns_fixedname_t fixed;
@ -195,8 +185,7 @@ find(void **state) {
* Check dns_db_allrdatasets() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
allrdatasets(void **state) {
ISC_RUN_TEST_IMPL(allrdatasets) {
isc_result_t res;
dns_dbnode_t *node = NULL;
dns_rdatasetiter_t *iterator = NULL;
@ -222,8 +211,7 @@ allrdatasets(void **state) {
* Check dns_db_findrdataset() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
findrdataset(void **state) {
ISC_RUN_TEST_IMPL(findrdataset) {
isc_result_t res;
dns_rdataset_t rdataset;
dns_dbnode_t *node = NULL;
@ -254,8 +242,7 @@ findrdataset(void **state) {
* Check dns_db_deleterdataset() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
deleterdataset(void **state) {
ISC_RUN_TEST_IMPL(deleterdataset) {
isc_result_t res;
dns_dbnode_t *node = NULL;
@ -277,8 +264,7 @@ deleterdataset(void **state) {
* Check dns_db_subtractrdataset() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
subtract(void **state) {
ISC_RUN_TEST_IMPL(subtract) {
isc_result_t res;
dns_rdataset_t rdataset;
dns_rdatalist_t rdatalist;
@ -319,8 +305,7 @@ subtract(void **state) {
* Check dns_db_dump() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
dump(void **state) {
ISC_RUN_TEST_IMPL(dump) {
isc_result_t res;
FILE *f = NULL;
@ -340,8 +325,7 @@ dump(void **state) {
* Check dns_db_addrdataset() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
addrdataset(void **state) {
ISC_RUN_TEST_IMPL(addrdataset) {
isc_result_t res;
dns_rdataset_t rdataset;
dns_dbnode_t *node = NULL;
@ -374,8 +358,7 @@ addrdataset(void **state) {
* Check dns_db_getnsec3parameters() passes with matching db and version,
* and asserts with mis-matching db and version.
*/
static void
getnsec3parameters(void **state) {
ISC_RUN_TEST_IMPL(getnsec3parameters) {
isc_result_t res;
dns_hash_t hash;
uint8_t flags;
@ -397,8 +380,7 @@ getnsec3parameters(void **state) {
* Check dns_db_resigned() passes with matching db and version, and
* asserts with mis-matching db and version.
*/
static void
resigned(void **state) {
ISC_RUN_TEST_IMPL(resigned) {
isc_result_t res;
dns_rdataset_t rdataset, added;
dns_dbnode_t *node = NULL;
@ -461,39 +443,18 @@ resigned(void **state) {
dns_rdataset_disassociate(&added);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dump, _setup, _teardown),
cmocka_unit_test_setup_teardown(find, _setup, _teardown),
cmocka_unit_test_setup_teardown(allrdatasets, _setup,
_teardown),
cmocka_unit_test_setup_teardown(findrdataset, _setup,
_teardown),
cmocka_unit_test_setup_teardown(deleterdataset, _setup,
_teardown),
cmocka_unit_test_setup_teardown(subtract, _setup, _teardown),
cmocka_unit_test_setup_teardown(addrdataset, _setup, _teardown),
cmocka_unit_test_setup_teardown(getnsec3parameters, _setup,
_teardown),
cmocka_unit_test_setup_teardown(resigned, _setup, _teardown),
cmocka_unit_test_setup_teardown(attachversion, _setup,
_teardown),
cmocka_unit_test_setup_teardown(closeversion, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(dump, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(allrdatasets, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(findrdataset, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(deleterdataset, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(subtract, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(addrdataset, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(getnsec3parameters, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(resigned, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(attachversion, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(closeversion, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -31,32 +29,35 @@
#include <dns/name.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include <dns/test.h>
static int
_setup(void **state) {
setup_test(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS) {
return (1);
}
return (0);
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
dns_test_end();
dst_lib_destroy();
return (0);
}
/* OpenSSL DH_compute_key() failure */
static void
dh_computesecret(void **state) {
ISC_RUN_TEST_IMPL(dh_computesecret) {
dst_key_t *key = NULL;
isc_buffer_t buf;
unsigned char array[1024];
@ -73,7 +74,7 @@ dh_computesecret(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_key_fromfile(name, 18602, DST_ALG_DH,
DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", dt_mctx,
DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", mctx,
&key);
assert_int_equal(result, ISC_R_SUCCESS);
@ -86,24 +87,8 @@ dh_computesecret(void **state) {
dst_key_free(&key);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dh_computesecret, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(dh_computesecret, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -37,7 +35,7 @@
#include <dns/name.h>
#include <dns/view.h>
#include "dnstest.h"
#include <dns/test.h>
uv_sem_t sem;
@ -114,15 +112,9 @@ reset_testdata(void);
static int
_setup(void **state) {
isc_result_t result;
uv_os_sock_t sock = -1;
int r;
UNUSED(state);
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
udp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0);
@ -143,8 +135,10 @@ _setup(void **state) {
}
close(sock);
setup_managers(state);
/* Create a secondary network manager */
isc_managers_create(dt_mctx, ncpus, 0, &connect_nm, NULL, NULL);
isc_managers_create(mctx, workers, 0, &connect_nm, NULL, NULL);
isc_nm_settimeouts(netmgr, T_SERVER_INIT, T_SERVER_IDLE,
T_SERVER_KEEPALIVE, T_SERVER_ADVERTISED);
@ -166,14 +160,12 @@ _setup(void **state) {
static int
_teardown(void **state) {
UNUSED(state);
uv_sem_destroy(&sem);
isc_managers_destroy(&connect_nm, NULL, NULL);
assert_null(connect_nm);
dns_test_end();
teardown_managers(state);
return (0);
}
@ -184,7 +176,7 @@ make_dispatchset(unsigned int ndisps) {
isc_sockaddr_t any;
dns_dispatch_t *disp = NULL;
result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr);
if (result != ISC_R_SUCCESS) {
return (result);
}
@ -195,7 +187,7 @@ make_dispatchset(unsigned int ndisps) {
return (result);
}
result = dns_dispatchset_create(dt_mctx, disp, &dset, ndisps);
result = dns_dispatchset_create(mctx, disp, &dset, ndisps);
dns_dispatch_detach(&disp);
return (result);
@ -212,8 +204,7 @@ reset(void) {
}
/* create dispatch set */
static void
dispatchset_create(void **state) {
ISC_RUN_TEST_IMPL(dispatchset_create) {
isc_result_t result;
UNUSED(state);
@ -228,8 +219,7 @@ dispatchset_create(void **state) {
}
/* test dispatch set round-robin */
static void
dispatchset_get(void **state) {
ISC_RUN_TEST_IMPL(dispatchset_get) {
isc_result_t result;
dns_dispatch_t *d1, *d2, *d3, *d4, *d5;
@ -290,9 +280,6 @@ server_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
UNUSED(eresult);
UNUSED(cbarg);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
return;
}
@ -366,9 +353,6 @@ response(isc_result_t eresult, isc_region_t *region, void *arg) {
UNUSED(region);
UNUSED(arg);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
switch (eresult) {
case ISC_R_EOF:
case ISC_R_CANCELED:
@ -387,9 +371,6 @@ response_timeout(isc_result_t eresult, isc_region_t *region, void *arg) {
UNUSED(region);
UNUSED(arg);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
atomic_store_relaxed(&testdata.result, eresult);
uv_sem_post(&sem);
@ -402,9 +383,6 @@ connected(isc_result_t eresult, isc_region_t *region, void *cbarg) {
UNUSED(eresult);
UNUSED(region);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
dns_dispatch_send(dispentry, r, -1);
}
@ -414,9 +392,6 @@ client_senddone(isc_result_t eresult, isc_region_t *region, void *cbarg) {
UNUSED(region);
UNUSED(cbarg);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
return;
}
@ -425,16 +400,12 @@ timeout_connected(isc_result_t eresult, isc_region_t *region, void *cbarg) {
UNUSED(region);
UNUSED(cbarg);
fprintf(stderr, "%s(..., %s, ...)\n", __func__,
isc_result_totext(eresult));
atomic_store_relaxed(&testdata.result, eresult);
uv_sem_post(&sem);
}
static void
dispatch_timeout_tcp_connect(void **state) {
ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_connect) {
isc_result_t result;
isc_region_t region;
unsigned char rbuf[12] = { 0 };
@ -446,7 +417,7 @@ dispatch_timeout_tcp_connect(void **state) {
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_blackhole, 0);
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
@ -489,8 +460,7 @@ dispatch_timeout_tcp_connect(void **state) {
assert_int_equal(result, ISC_R_TIMEDOUT);
}
static void
dispatch_timeout_tcp_response(void **state __attribute__((unused))) {
ISC_RUN_TEST_IMPL(dispatch_timeout_tcp_response) {
isc_result_t result;
isc_region_t region;
unsigned char rbuf[12] = { 0 };
@ -503,7 +473,7 @@ dispatch_timeout_tcp_response(void **state __attribute__((unused))) {
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
@ -546,8 +516,7 @@ dispatch_timeout_tcp_response(void **state __attribute__((unused))) {
dns_dispatchmgr_detach(&dispatchmgr);
}
static void
dispatch_tcp_response(void **state __attribute__((unused))) {
ISC_RUN_TEST_IMPL(dispatch_tcp_response) {
isc_result_t result;
isc_region_t region;
unsigned char rbuf[12] = { 0 };
@ -560,7 +529,7 @@ dispatch_tcp_response(void **state __attribute__((unused))) {
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatch_createtcp(dispatchmgr, &tcp_connect_addr,
@ -606,8 +575,7 @@ dispatch_tcp_response(void **state __attribute__((unused))) {
dns_dispatchmgr_detach(&dispatchmgr);
}
static void
dispatch_timeout_udp_response(void **state __attribute__((unused))) {
ISC_RUN_TEST_IMPL(dispatch_timeout_udp_response) {
isc_result_t result;
isc_region_t region;
unsigned char rbuf[12] = { 0 };
@ -620,7 +588,7 @@ dispatch_timeout_udp_response(void **state __attribute__((unused))) {
udp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0);
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatch_createudp(dispatchmgr, &tcp_connect_addr,
@ -663,8 +631,7 @@ dispatch_timeout_udp_response(void **state __attribute__((unused))) {
}
/* test dispatch getnext */
static void
dispatch_getnext(void **state) {
ISC_RUN_TEST_IMPL(dispatch_getnext) {
isc_result_t result;
isc_region_t region;
isc_nmsocket_t *sock = NULL;
@ -674,7 +641,7 @@ dispatch_getnext(void **state) {
UNUSED(state);
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatch_createudp(dispatchmgr, &udp_connect_addr,
@ -718,36 +685,16 @@ dispatch_getnext(void **state) {
dns_dispatchmgr_detach(&dispatchmgr);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dispatch_timeout_tcp_connect,
_setup, _teardown),
cmocka_unit_test_setup_teardown(dispatch_timeout_tcp_response,
_setup, _teardown),
cmocka_unit_test_setup_teardown(dispatch_tcp_response, _setup,
_teardown),
cmocka_unit_test_setup_teardown(dispatch_timeout_udp_response,
_setup, _teardown),
cmocka_unit_test_setup_teardown(dispatchset_create, _setup,
_teardown),
cmocka_unit_test_setup_teardown(dispatchset_get, _setup,
_teardown),
cmocka_unit_test_setup_teardown(dispatch_getnext, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_tcp_connect, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_tcp_response, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatch_tcp_response, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatch_timeout_udp_response, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatchset_create, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatchset_get, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dispatch_getnext, _setup, _teardown)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -34,6 +32,8 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/test.h>
static void
multiple_prefixes(void) {
size_t i, count;
@ -121,8 +121,7 @@ multiple_prefixes(void) {
assert_true(have_p1 != have_p2);
}
static void
dns64_findprefix(void **state) {
ISC_RUN_TEST_IMPL(dns64_findprefix) {
unsigned int i, j, o;
isc_result_t result;
struct {
@ -165,8 +164,6 @@ dns64_findprefix(void **state) {
ISC_R_NOTFOUND },
};
UNUSED(state);
for (i = 0; i < ARRAY_SIZE(tests); i++) {
size_t count = 2;
dns_rdataset_t rdataset;
@ -231,22 +228,8 @@ dns64_findprefix(void **state) {
multiple_prefixes();
}
int
main(void) {
const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(
dns64_findprefix, NULL, NULL) };
ISC_TEST_LIST_START
ISC_TEST_ENTRY(dns64_findprefix)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -24,6 +22,9 @@
#define UNIT_TESTING
#include <cmocka.h>
#include <fstrm.h>
#include <protobuf-c/protobuf-c.h>
#include <isc/buffer.h>
#include <isc/file.h>
@ -35,13 +36,7 @@
#include <dns/dnstap.h>
#include <dns/view.h>
#include "dnstest.h"
#ifdef HAVE_DNSTAP
#include <fstrm.h>
#include <protobuf-c/protobuf-c.h>
#include <dns/test.h>
#define TAPFILE "testdata/dnstap/dnstap.file"
#define TAPSOCK "testdata/dnstap/dnstap.sock"
@ -50,48 +45,39 @@
#define TAPTEXT "testdata/dnstap/dnstap.text"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
cleanup(void **state __attribute__((__unused__))) {
(void)isc_file_remove(TAPFILE);
(void)isc_file_remove(TAPSOCK);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
setup(void **state) {
/*
* Make sure files are cleaned up before the test runs.
*/
cleanup(state);
/*
* Make sure text conversions match the time zone in which
* the testdata was originally generated.
*/
setenv("TZ", "PDT8", 1);
return (0);
}
static void
cleanup(void) {
(void)isc_file_remove(TAPFILE);
(void)isc_file_remove(TAPSOCK);
}
/* set up dnstap environment */
static void
create_test(void **state) {
ISC_RUN_TEST_IMPL(dns_dt_create) {
isc_result_t result;
dns_dtenv_t *dtenv = NULL;
struct fstrm_iothr_options *fopt;
UNUSED(state);
cleanup();
fopt = fstrm_iothr_options_init();
assert_non_null(fopt);
fstrm_iothr_options_set_num_input_queues(fopt, 1);
result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
&dtenv);
assert_int_equal(result, ISC_R_SUCCESS);
if (dtenv != NULL) {
@ -107,7 +93,7 @@ create_test(void **state) {
assert_non_null(fopt);
fstrm_iothr_options_set_num_input_queues(fopt, 1);
result = dns_dt_create(dt_mctx, dns_dtmode_unix, TAPSOCK, &fopt, NULL,
result = dns_dt_create(mctx, dns_dtmode_unix, TAPSOCK, &fopt, NULL,
&dtenv);
assert_int_equal(result, ISC_R_SUCCESS);
if (dtenv != NULL) {
@ -124,7 +110,7 @@ create_test(void **state) {
assert_non_null(fopt);
fstrm_iothr_options_set_num_input_queues(fopt, 1);
result = dns_dt_create(dt_mctx, 33, TAPSOCK, &fopt, NULL, &dtenv);
result = dns_dt_create(mctx, 33, TAPSOCK, &fopt, NULL, &dtenv);
assert_int_equal(result, ISC_R_FAILURE);
assert_null(dtenv);
if (dtenv != NULL) {
@ -133,13 +119,10 @@ create_test(void **state) {
if (fopt != NULL) {
fstrm_iothr_options_destroy(&fopt);
}
cleanup();
}
/* send dnstap messages */
static void
send_test(void **state) {
ISC_RUN_TEST_IMPL(dns_dt_send) {
isc_result_t result;
dns_dtenv_t *dtenv = NULL;
dns_dthandle_t *handle = NULL;
@ -163,18 +146,14 @@ send_test(void **state) {
isc_time_t p, f;
struct fstrm_iothr_options *fopt;
UNUSED(state);
cleanup();
result = dns_test_makeview("test", &view);
result = dns_test_makeview("test", false, &view);
assert_int_equal(result, ISC_R_SUCCESS);
fopt = fstrm_iothr_options_init();
assert_non_null(fopt);
fstrm_iothr_options_set_num_input_queues(fopt, 1);
result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
&dtenv);
assert_int_equal(result, ISC_R_SUCCESS);
@ -192,7 +171,7 @@ send_test(void **state) {
memset(&zr, 0, sizeof(zr));
isc_buffer_init(&zb, zone, sizeof(zone));
result = dns_compress_init(&cctx, -1, dt_mctx);
result = dns_compress_init(&cctx, -1, mctx);
assert_int_equal(result, ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE);
result = dns_name_towire(zname, &cctx, &zb);
@ -266,7 +245,7 @@ send_test(void **state) {
dns_dt_detach(&dtenv);
dns_view_detach(&view);
result = dns_dt_open(TAPFILE, dns_dtmode_file, dt_mctx, &handle);
result = dns_dt_open(TAPFILE, dns_dtmode_file, mctx, &handle);
assert_int_equal(result, ISC_R_SUCCESS);
while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) {
@ -278,7 +257,7 @@ send_test(void **state) {
r.base = data;
r.length = dsize;
result = dns_dt_parse(dt_mctx, &r, &dtdata);
result = dns_dt_parse(mctx, &r, &dtdata);
assert_int_equal(result, ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS) {
n++;
@ -299,12 +278,10 @@ send_test(void **state) {
if (handle != NULL) {
dns_dt_close(&handle);
}
cleanup();
}
/* dnstap message to text */
static void
totext_test(void **state) {
ISC_RUN_TEST_IMPL(dns_dt_totext) {
isc_result_t result;
dns_dthandle_t *handle = NULL;
uint8_t *data;
@ -313,7 +290,7 @@ totext_test(void **state) {
UNUSED(state);
result = dns_dt_open(TAPSAVED, dns_dtmode_file, dt_mctx, &handle);
result = dns_dt_open(TAPSAVED, dns_dtmode_file, mctx, &handle);
assert_int_equal(result, ISC_R_SUCCESS);
result = isc_stdio_open(TAPTEXT, "r", &fp);
@ -341,13 +318,13 @@ totext_test(void **state) {
}
/* parse dnstap frame */
result = dns_dt_parse(dt_mctx, &r, &dtdata);
result = dns_dt_parse(mctx, &r, &dtdata);
assert_int_equal(result, ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS) {
continue;
}
isc_buffer_allocate(dt_mctx, &b, 2048);
isc_buffer_allocate(mctx, &b, 2048);
assert_non_null(b);
if (b == NULL) {
break;
@ -366,37 +343,14 @@ totext_test(void **state) {
if (handle != NULL) {
dns_dt_close(&handle);
}
cleanup();
}
#endif /* HAVE_DNSTAP */
int
main(void) {
#if HAVE_DNSTAP
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(create_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(send_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown),
};
/* make sure text conversion gets the right local time */
setenv("TZ", "PST8", 1);
return (cmocka_run_group_tests(tests, NULL, NULL));
#else /* if HAVE_DNSTAP */
print_message("1..0 # Skipped: dnstap not enabled\n");
return (SKIPPED_TEST_EXIT_CODE);
#endif /* HAVE_DNSTAP */
}
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_START
#include <stdio.h>
ISC_TEST_ENTRY_CUSTOM(dns_dt_create, setup, cleanup)
ISC_TEST_ENTRY_CUSTOM(dns_dt_send, setup, cleanup)
ISC_TEST_ENTRY_CUSTOM(dns_dt_totext, setup, cleanup)
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
ISC_TEST_LIST_END
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -34,25 +32,23 @@
#include <dst/dst.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include <dns/test.h>
static int
_setup(void **state) {
isc_result_t result;
setup_test(void **state) {
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
dst_lib_init(mctx, NULL);
return (0);
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
dns_test_end();
dst_lib_destroy();
return (0);
}
@ -73,7 +69,7 @@ sig_fromfile(const char *path, isc_buffer_t *buf) {
result = isc_file_getsizefd(fileno(fp), &size);
assert_int_equal(result, ISC_R_SUCCESS);
data = isc_mem_get(dt_mctx, (size + 1));
data = isc_mem_get(mctx, (size + 1));
assert_non_null(data);
len = (size_t)size;
@ -123,7 +119,7 @@ sig_fromfile(const char *path, isc_buffer_t *buf) {
result = ISC_R_SUCCESS;
err:
isc_mem_put(dt_mctx, data, size + 1);
isc_mem_put(mctx, data, size + 1);
return (result);
}
@ -154,7 +150,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
result = isc_file_getsizefd(fileno(fp), &size);
assert_int_equal(result, ISC_R_SUCCESS);
data = isc_mem_get(dt_mctx, (size + 1));
data = isc_mem_get(mctx, (size + 1));
assert_non_null(data);
p = data;
@ -175,7 +171,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
isc_buffer_add(&b, strlen(keyname));
result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_key_fromfile(name, id, alg, type, "testdata/dst", dt_mctx,
result = dst_key_fromfile(name, id, alg, type, "testdata/dst", mctx,
&key);
assert_int_equal(result, ISC_R_SUCCESS);
@ -197,8 +193,8 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
*/
isc_buffer_remainingregion(&sigbuf, &sigreg);
result = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_GENERAL,
false, 0, &ctx);
result = dst_context_create(key, mctx, DNS_LOGCATEGORY_GENERAL, false,
0, &ctx);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_context_adddata(ctx, &datareg);
@ -215,8 +211,8 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
isc_result_t result2;
dst_context_destroy(&ctx);
result2 = dst_context_create(
key, dt_mctx, DNS_LOGCATEGORY_GENERAL, false, 0, &ctx);
result2 = dst_context_create(key, mctx, DNS_LOGCATEGORY_GENERAL,
false, 0, &ctx);
assert_int_equal(result2, ISC_R_SUCCESS);
result2 = dst_context_adddata(ctx, &datareg);
@ -241,7 +237,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
fprintf(stderr, "# %s:\n# %s\n", sigpath, hexbuf);
}
isc_mem_put(dt_mctx, data, size + 1);
isc_mem_put(mctx, data, size + 1);
dst_context_destroy(&ctx);
dst_key_free(&key);
@ -251,10 +247,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
return;
}
static void
sig_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(sig_test) {
struct {
const char *datapath;
const char *sigpath;
@ -310,7 +303,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name,
result = dns_name_fromtext(name1, &b1, dns_rootname, 0, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_key_fromfile(name1, key1_id, alg, type, "comparekeys",
dt_mctx, &key1);
mctx, &key1);
assert_int_equal(result, ISC_R_SUCCESS);
/*
@ -322,7 +315,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name,
result = dns_name_fromtext(name2, &b2, dns_rootname, 0, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_key_fromfile(name2, key2_id, alg, type, "comparekeys",
dt_mctx, &key2);
mctx, &key2);
assert_int_equal(result, ISC_R_SUCCESS);
/*
@ -346,10 +339,7 @@ check_cmp(const char *key1_name, dns_keytag_t key1_id, const char *key2_name,
return;
}
static void
cmp_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(cmp_test) {
struct {
const char *key1_name;
dns_keytag_t key1_id;
@ -477,24 +467,9 @@ cmp_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(sig_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(cmp_test, _setup, _teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(sig_test, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(cmp_test, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -35,7 +33,8 @@
#include <dns/geoip.h>
#include "../geoip2.c"
#include "dnstest.h"
#include <dns/test.h>
/* Use GeoIP2 databases from the 'geoip2' system test */
#define TEST_GEOIP_DATA "../../../bin/tests/system/geoip2/data"
@ -50,14 +49,9 @@ static void
close_geoip(void);
static int
_setup(void **state) {
isc_result_t result;
setup_test(void **state) {
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
@ -65,13 +59,11 @@ _setup(void **state) {
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
close_geoip();
dns_test_end();
return (0);
}
@ -135,8 +127,7 @@ entry_exists(dns_geoip_subtype_t subtype, const char *addr) {
* present in all databases, 192.0.2.128 should only be present in the country
* database, ::1 should be absent from all databases).
*/
static void
baseline(void **state) {
ISC_RUN_TEST_IMPL(baseline) {
dns_geoip_subtype_t subtype;
UNUSED(state);
@ -214,8 +205,7 @@ do_lookup_string_v6(const char *addr, dns_geoip_subtype_t subtype,
}
/* GeoIP country matching */
static void
country(void **state) {
ISC_RUN_TEST_IMPL(country) {
bool match;
UNUSED(state);
@ -240,8 +230,7 @@ country(void **state) {
}
/* GeoIP country (ipv6) matching */
static void
country_v6(void **state) {
ISC_RUN_TEST_IMPL(country_v6) {
bool match;
UNUSED(state);
@ -260,8 +249,7 @@ country_v6(void **state) {
}
/* GeoIP city (ipv4) matching */
static void
city(void **state) {
ISC_RUN_TEST_IMPL(city) {
bool match;
UNUSED(state);
@ -298,8 +286,7 @@ city(void **state) {
}
/* GeoIP city (ipv6) matching */
static void
city_v6(void **state) {
ISC_RUN_TEST_IMPL(city_v6) {
bool match;
UNUSED(state);
@ -339,8 +326,7 @@ city_v6(void **state) {
}
/* GeoIP asnum matching */
static void
asnum(void **state) {
ISC_RUN_TEST_IMPL(asnum) {
bool match;
UNUSED(state);
@ -354,8 +340,7 @@ asnum(void **state) {
}
/* GeoIP isp matching */
static void
isp(void **state) {
ISC_RUN_TEST_IMPL(isp) {
bool match;
UNUSED(state);
@ -370,8 +355,7 @@ isp(void **state) {
}
/* GeoIP org matching */
static void
org(void **state) {
ISC_RUN_TEST_IMPL(org) {
bool match;
UNUSED(state);
@ -386,8 +370,7 @@ org(void **state) {
}
/* GeoIP domain matching */
static void
domain(void **state) {
ISC_RUN_TEST_IMPL(domain) {
bool match;
UNUSED(state);
@ -400,27 +383,16 @@ domain(void **state) {
assert_true(match);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(baseline), cmocka_unit_test(country),
cmocka_unit_test(country_v6), cmocka_unit_test(city),
cmocka_unit_test(city_v6), cmocka_unit_test(asnum),
cmocka_unit_test(isp), cmocka_unit_test(org),
cmocka_unit_test(domain),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(baseline, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(country, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(country_v6, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(city, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(city_v6, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(asnum, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(isp, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(org, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(domain, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -42,28 +40,7 @@
#include <dst/dst.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
dns_keytable_t *keytable = NULL;
dns_ntatable_t *ntatable = NULL;
@ -123,7 +100,7 @@ create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr,
keystruct->common.rdclass = rdclass;
keystruct->common.rdtype = dns_rdatatype_dnskey;
keystruct->mctx = dt_mctx;
keystruct->mctx = mctx;
ISC_LINK_INIT(&keystruct->common, link);
keystruct->flags = flags;
keystruct->protocol = proto;
@ -134,7 +111,7 @@ create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr,
ISC_R_SUCCESS);
isc_buffer_usedregion(&keydatabuf, &r);
keystruct->datalen = r.length;
keystruct->data = isc_mem_allocate(dt_mctx, r.length);
keystruct->data = isc_mem_allocate(mctx, r.length);
memmove(keystruct->data, r.base, r.length);
}
@ -182,11 +159,10 @@ create_tables(void) {
dns_name_t *keyname = dns_fixedname_name(&fn);
isc_stdtime_t now;
result = dns_test_makeview("view", &view);
result = dns_test_makeview("view", false, &view);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(dns_keytable_create(dt_mctx, &keytable),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_create(mctx, &keytable), ISC_R_SUCCESS);
assert_int_equal(
dns_ntatable_create(view, taskmgr, timermgr, &ntatable),
ISC_R_SUCCESS);
@ -229,8 +205,7 @@ destroy_tables(void) {
}
/* add keys to the keytable */
static void
add_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_add) {
dns_keynode_t *keynode = NULL;
dns_keynode_t *null_keynode = NULL;
unsigned char digest[ISC_MAX_MD_SIZE];
@ -380,10 +355,7 @@ add_test(void **state) {
}
/* delete keys from the keytable */
static void
delete_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(dns_keytable_delete) {
create_tables();
/* dns_keytable_delete requires exact match */
@ -409,8 +381,7 @@ delete_test(void **state) {
}
/* delete key nodes from the keytable */
static void
deletekey_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_deletekey) {
dns_rdata_dnskey_t dnskey;
dns_fixedname_t fn;
dns_name_t *keyname = dns_fixedname_name(&fn);
@ -475,8 +446,7 @@ deletekey_test(void **state) {
}
/* check find-variant operations */
static void
find_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_find) {
dns_keynode_t *keynode = NULL;
dns_fixedname_t fname;
dns_name_t *name;
@ -530,8 +500,7 @@ find_test(void **state) {
}
/* check issecuredomain() */
static void
issecuredomain_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_issecuredomain) {
bool issecure;
const char **n;
const char *names[] = { "example.com", "sub.example.com",
@ -568,8 +537,7 @@ issecuredomain_test(void **state) {
}
/* check dns_keytable_dump() */
static void
dump_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_dump) {
FILE *f = fopen("/dev/null", "w");
UNUSED(state);
@ -587,8 +555,7 @@ dump_test(void **state) {
}
/* check negative trust anchors */
static void
nta_test(void **state) {
ISC_RUN_TEST_IMPL(dns_keytable_nta) {
isc_result_t result;
bool issecure, covered;
dns_fixedname_t fn;
@ -600,13 +567,13 @@ nta_test(void **state) {
UNUSED(state);
result = dns_test_makeview("view", &myview);
result = dns_test_makeview("view", false, &myview);
assert_int_equal(result, ISC_R_SUCCESS);
result = isc_task_create(taskmgr, 0, &myview->task, 0);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_view_initsecroots(myview, dt_mctx);
result = dns_view_initsecroots(myview, mctx);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_view_getsecroots(myview, &keytable);
assert_int_equal(result, ISC_R_SUCCESS);
@ -692,29 +659,17 @@ nta_test(void **state) {
dns_view_detach(&myview);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(add_test),
cmocka_unit_test(delete_test),
cmocka_unit_test(deletekey_test),
cmocka_unit_test(find_test),
cmocka_unit_test(issecuredomain_test),
cmocka_unit_test(dump_test),
cmocka_unit_test(nta_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_ENTRY_CUSTOM(dns_keytable_add, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_delete, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_deletekey, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_find, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_issecuredomain, setup_managers,
teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_dump, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_keytable_nta, setup_managers, teardown_managers)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -40,28 +38,7 @@
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
static void
nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {
@ -174,7 +151,7 @@ test_master(const char *workdir, const char *testfile,
result = dns_master_loadfile(testfile, &dns_origin, &dns_origin,
dns_rdataclass_in, true, 0, &callbacks,
NULL, NULL, dt_mctx, format, 0);
NULL, NULL, mctx, format, 0);
return (result);
}
@ -182,15 +159,14 @@ test_master(const char *workdir, const char *testfile,
static void
include_callback(const char *filename, void *arg) {
char **argp = (char **)arg;
*argp = isc_mem_strdup(dt_mctx, filename);
*argp = isc_mem_strdup(mctx, filename);
}
/*
* Successful load test:
* dns_master_loadfile() loads a valid master file and returns success
*/
static void
load_test(void **state) {
ISC_RUN_TEST_IMPL(load) {
isc_result_t result;
UNUSED(state);
@ -204,8 +180,7 @@ load_test(void **state) {
* Unexpected end of file test:
* dns_master_loadfile() returns DNS_R_UNEXPECTED when file ends too soon
*/
static void
unexpected_test(void **state) {
ISC_RUN_TEST_IMPL(unexpected) {
isc_result_t result;
UNUSED(state);
@ -220,8 +195,7 @@ unexpected_test(void **state) {
* dns_master_loadfile() accepts broken zones with no TTL for first record
* if it is an SOA
*/
static void
noowner_test(void **state) {
ISC_RUN_TEST_IMPL(noowner) {
isc_result_t result;
UNUSED(state);
@ -236,8 +210,7 @@ noowner_test(void **state) {
* dns_master_loadfile() returns DNS_R_NOOWNER when no owner name is
* specified
*/
static void
nottl_test(void **state) {
ISC_RUN_TEST_IMPL(nottl) {
isc_result_t result;
UNUSED(state);
@ -252,8 +225,7 @@ nottl_test(void **state) {
* dns_master_loadfile() returns DNS_R_BADCLASS when record class doesn't
* match zone class
*/
static void
badclass_test(void **state) {
ISC_RUN_TEST_IMPL(badclass) {
isc_result_t result;
UNUSED(state);
@ -267,8 +239,7 @@ badclass_test(void **state) {
* Too big rdata test:
* dns_master_loadfile() returns ISC_R_NOSPACE when record is too big
*/
static void
toobig_test(void **state) {
ISC_RUN_TEST_IMPL(toobig) {
isc_result_t result;
UNUSED(state);
@ -282,8 +253,7 @@ toobig_test(void **state) {
* Maximum rdata test:
* dns_master_loadfile() returns ISC_R_SUCCESS when record is maximum size
*/
static void
maxrdata_test(void **state) {
ISC_RUN_TEST_IMPL(maxrdata) {
isc_result_t result;
UNUSED(state);
@ -297,8 +267,7 @@ maxrdata_test(void **state) {
* DNSKEY test:
* dns_master_loadfile() understands DNSKEY with key material
*/
static void
dnskey_test(void **state) {
ISC_RUN_TEST_IMPL(dnskey) {
isc_result_t result;
UNUSED(state);
@ -315,8 +284,7 @@ dnskey_test(void **state) {
* RFC 4034 removed the ability to signal NOKEY, so empty key material should
* be rejected.
*/
static void
dnsnokey_test(void **state) {
ISC_RUN_TEST_IMPL(dnsnokey) {
isc_result_t result;
UNUSED(state);
@ -330,8 +298,7 @@ dnsnokey_test(void **state) {
* Include test:
* dns_master_loadfile() understands $INCLUDE
*/
static void
include_test(void **state) {
ISC_RUN_TEST_IMPL(include) {
isc_result_t result;
UNUSED(state);
@ -345,8 +312,7 @@ include_test(void **state) {
* Include file list test:
* dns_master_loadfile4() returns names of included file
*/
static void
master_includelist_test(void **state) {
ISC_RUN_TEST_IMPL(master_includelist) {
isc_result_t result;
char *filename = NULL;
@ -361,12 +327,12 @@ master_includelist_test(void **state) {
result = dns_master_loadfile(
"testdata/master/master8.data", &dns_origin, &dns_origin,
dns_rdataclass_in, 0, true, &callbacks, include_callback,
&filename, dt_mctx, dns_masterformat_text, 0);
&filename, mctx, dns_masterformat_text, 0);
assert_int_equal(result, DNS_R_SEENINCLUDE);
assert_non_null(filename);
if (filename != NULL) {
assert_string_equal(filename, "testdata/master/master6.data");
isc_mem_free(dt_mctx, filename);
isc_mem_free(mctx, filename);
}
}
@ -374,8 +340,7 @@ master_includelist_test(void **state) {
* Include failure test:
* dns_master_loadfile() understands $INCLUDE failures
*/
static void
includefail_test(void **state) {
ISC_RUN_TEST_IMPL(includefail) {
isc_result_t result;
UNUSED(state);
@ -389,8 +354,7 @@ includefail_test(void **state) {
* Non-empty blank lines test:
* dns_master_loadfile() handles non-empty blank lines
*/
static void
blanklines_test(void **state) {
ISC_RUN_TEST_IMPL(blanklines) {
isc_result_t result;
UNUSED(state);
@ -405,8 +369,7 @@ blanklines_test(void **state) {
* dns_master_loadfile() allows leading zeroes in SOA
*/
static void
leadingzero_test(void **state) {
ISC_RUN_TEST_IMPL(leadingzero) {
isc_result_t result;
UNUSED(state);
@ -417,8 +380,7 @@ leadingzero_test(void **state) {
}
/* masterfile totext tests */
static void
totext_test(void **state) {
ISC_RUN_TEST_IMPL(totext) {
isc_result_t result;
dns_rdataset_t rdataset;
dns_rdatalist_t rdatalist;
@ -455,8 +417,7 @@ totext_test(void **state) {
* Raw load test:
* dns_master_loadfile() loads a valid raw file and returns success
*/
static void
loadraw_test(void **state) {
ISC_RUN_TEST_IMPL(loadraw) {
isc_result_t result;
UNUSED(state);
@ -488,8 +449,7 @@ loadraw_test(void **state) {
* Raw dump test:
* dns_master_dump*() functions dump valid raw files
*/
static void
dumpraw_test(void **state) {
ISC_RUN_TEST_IMPL(dumpraw) {
isc_result_t result;
dns_db_t *db = NULL;
dns_dbversion_t *version = NULL;
@ -512,7 +472,7 @@ dumpraw_test(void **state) {
&target);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_db_create(dt_mctx, "rbt", &dnsorigin, dns_dbtype_zone,
result = dns_db_create(mctx, "rbt", &dnsorigin, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
assert_int_equal(result, ISC_R_SUCCESS);
@ -528,9 +488,8 @@ dumpraw_test(void **state) {
dns_db_currentversion(db, &version);
result = dns_master_dump(dt_mctx, db, version,
&dns_master_style_default, "test.dump",
dns_masterformat_raw, NULL);
result = dns_master_dump(mctx, db, version, &dns_master_style_default,
"test.dump", dns_masterformat_raw, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
result = test_master(NULL, "test.dump", dns_masterformat_raw, nullmsg,
@ -544,9 +503,8 @@ dumpraw_test(void **state) {
header.flags |= DNS_MASTERRAW_SOURCESERIALSET;
unlink("test.dump");
result = dns_master_dump(dt_mctx, db, version,
&dns_master_style_default, "test.dump",
dns_masterformat_raw, &header);
result = dns_master_dump(mctx, db, version, &dns_master_style_default,
"test.dump", dns_masterformat_raw, &header);
assert_int_equal(result, ISC_R_SUCCESS);
result = test_master(NULL, "test.dump", dns_masterformat_raw, nullmsg,
@ -587,8 +545,7 @@ warn_expect(struct dns_rdatacallbacks *mycallbacks, const char *fmt, ...) {
* Origin change test:
* dns_master_loadfile() rejects zones with inherited name following $ORIGIN
*/
static void
neworigin_test(void **state) {
ISC_RUN_TEST_IMPL(neworigin) {
isc_result_t result;
UNUSED(state);
@ -600,53 +557,25 @@ neworigin_test(void **state) {
assert_true(warn_expect_result);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(load_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(unexpected_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(noowner_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(nottl_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(badclass_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(dnskey_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(dnsnokey_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(include_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(master_includelist_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(includefail_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(blanklines_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(leadingzero_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(loadraw_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(dumpraw_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(toobig_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(maxrdata_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(neworigin_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(load)
ISC_TEST_ENTRY(unexpected)
ISC_TEST_ENTRY(noowner)
ISC_TEST_ENTRY(nottl)
ISC_TEST_ENTRY(badclass)
ISC_TEST_ENTRY(dnskey)
ISC_TEST_ENTRY(dnsnokey)
ISC_TEST_ENTRY(include)
ISC_TEST_ENTRY(master_includelist)
ISC_TEST_ENTRY(includefail)
ISC_TEST_ENTRY(blanklines)
ISC_TEST_ENTRY(leadingzero)
ISC_TEST_ENTRY(totext)
ISC_TEST_ENTRY(loadraw)
ISC_TEST_ENTRY(dumpraw)
ISC_TEST_ENTRY(toobig)
ISC_TEST_ENTRY(maxrdata)
ISC_TEST_ENTRY(neworigin)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -38,35 +36,13 @@
#include <dns/fixedname.h>
#include <dns/name.h>
#include "dnstest.h"
#include <dns/test.h>
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
/* dns_name_fullcompare test */
static void
fullcompare_test(void **state) {
ISC_RUN_TEST_IMPL(fullcompare) {
dns_fixedname_t fixed1;
dns_fixedname_t fixed2;
dns_name_t *name1;
@ -182,8 +158,7 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3,
}
/* name compression test */
static void
compression_test(void **state) {
ISC_RUN_TEST_IMPL(compression) {
unsigned int allowed;
dns_compress_t cctx;
dns_decompress_t dctx;
@ -216,7 +191,7 @@ compression_test(void **state) {
/* Test 1: NONE */
allowed = DNS_COMPRESS_NONE;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
dns_decompress_setmethods(&dctx, allowed);
@ -229,7 +204,7 @@ compression_test(void **state) {
/* Test2: GLOBAL14 */
allowed = DNS_COMPRESS_GLOBAL14;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
dns_decompress_setmethods(&dctx, allowed);
@ -242,7 +217,7 @@ compression_test(void **state) {
/* Test3: ALL */
allowed = DNS_COMPRESS_ALL;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
dns_decompress_setmethods(&dctx, allowed);
@ -255,7 +230,7 @@ compression_test(void **state) {
/* Test4: NONE disabled */
allowed = DNS_COMPRESS_NONE;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_compress_disable(&cctx);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
@ -269,7 +244,7 @@ compression_test(void **state) {
/* Test5: GLOBAL14 disabled */
allowed = DNS_COMPRESS_GLOBAL14;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_compress_disable(&cctx);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
@ -283,7 +258,7 @@ compression_test(void **state) {
/* Test6: ALL disabled */
allowed = DNS_COMPRESS_ALL;
assert_int_equal(dns_compress_init(&cctx, -1, dt_mctx), ISC_R_SUCCESS);
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
dns_compress_setmethods(&cctx, allowed);
dns_compress_disable(&cctx);
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
@ -297,8 +272,7 @@ compression_test(void **state) {
}
/* is trust-anchor-telemetry test */
static void
istat_test(void **state) {
ISC_RUN_TEST_IMPL(istat) {
dns_fixedname_t fixed;
dns_name_t *name;
isc_result_t result;
@ -341,8 +315,7 @@ istat_test(void **state) {
}
/* dns_nane_init */
static void
init_test(void **state) {
ISC_RUN_TEST_IMPL(init) {
dns_name_t name;
unsigned char offsets[1];
@ -359,8 +332,7 @@ init_test(void **state) {
}
/* dns_nane_invalidate */
static void
invalidate_test(void **state) {
ISC_RUN_TEST_IMPL(invalidate) {
dns_name_t name;
unsigned char offsets[1];
@ -378,8 +350,7 @@ invalidate_test(void **state) {
}
/* dns_nane_setbuffer/hasbuffer */
static void
buffer_test(void **state) {
ISC_RUN_TEST_IMPL(buffer) {
dns_name_t name;
unsigned char buf[BUFSIZ];
isc_buffer_t b;
@ -394,8 +365,7 @@ buffer_test(void **state) {
}
/* dns_nane_isabsolute */
static void
isabsolute_test(void **state) {
ISC_RUN_TEST_IMPL(isabsolute) {
struct {
const char *namestr;
bool expect;
@ -429,8 +399,7 @@ isabsolute_test(void **state) {
}
/* dns_nane_hash */
static void
hash_test(void **state) {
ISC_RUN_TEST_IMPL(hash) {
struct {
const char *name1;
const char *name2;
@ -493,8 +462,7 @@ hash_test(void **state) {
}
/* dns_nane_issubdomain */
static void
issubdomain_test(void **state) {
ISC_RUN_TEST_IMPL(issubdomain) {
struct {
const char *name1;
const char *name2;
@ -537,8 +505,7 @@ issubdomain_test(void **state) {
}
/* dns_nane_countlabels */
static void
countlabels_test(void **state) {
ISC_RUN_TEST_IMPL(countlabels) {
struct {
const char *namestr;
unsigned int expect;
@ -573,8 +540,7 @@ countlabels_test(void **state) {
}
/* dns_nane_getlabel */
static void
getlabel_test(void **state) {
ISC_RUN_TEST_IMPL(getlabel) {
struct {
const char *name1;
unsigned int pos1;
@ -617,8 +583,7 @@ getlabel_test(void **state) {
}
/* dns_nane_getlabelsequence */
static void
getlabelsequence_test(void **state) {
ISC_RUN_TEST_IMPL(getlabelsequence) {
struct {
const char *name1;
unsigned int pos1;
@ -673,8 +638,7 @@ getlabelsequence_test(void **state) {
/* Benchmark dns_name_fromwire() implementation */
static void *
fromwire_thread(void *arg) {
ISC_RUN_TEST_IMPL(fromwire_thread(void *arg) {
unsigned int maxval = 32000000;
uint8_t data[] = { 3, 'w', 'w', 'w', 7, 'e', 'x',
'a', 'm', 'p', 'l', 'e', 7, 'i',
@ -709,8 +673,7 @@ fromwire_thread(void *arg) {
return (NULL);
}
static void
benchmark_test(void **state) {
ISC_RUN_TEST_IMPL(benchmark) {
isc_result_t result;
unsigned int i;
isc_time_t ts1, ts2;
@ -747,50 +710,22 @@ benchmark_test(void **state) {
#endif /* DNS_BENCHMARK_TESTS */
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(fullcompare_test),
cmocka_unit_test_setup_teardown(compression_test, _setup,
_teardown),
cmocka_unit_test(istat_test),
cmocka_unit_test(init_test),
cmocka_unit_test(invalidate_test),
cmocka_unit_test(buffer_test),
cmocka_unit_test(isabsolute_test),
cmocka_unit_test(hash_test),
cmocka_unit_test(issubdomain_test),
cmocka_unit_test(countlabels_test),
cmocka_unit_test(getlabel_test),
cmocka_unit_test(getlabelsequence_test),
ISC_TEST_LIST_START
ISC_TEST_ENTRY(fullcompare)
ISC_TEST_ENTRY(compression)
ISC_TEST_ENTRY(istat)
ISC_TEST_ENTRY(init)
ISC_TEST_ENTRY(invalidate)
ISC_TEST_ENTRY(buffer)
ISC_TEST_ENTRY(isabsolute)
ISC_TEST_ENTRY(hash)
ISC_TEST_ENTRY(issubdomain)
ISC_TEST_ENTRY(countlabels)
ISC_TEST_ENTRY(getlabel)
ISC_TEST_ENTRY(getlabelsequence)
#ifdef DNS_BENCHMARK_TESTS
cmocka_unit_test_setup_teardown(benchmark_test, _setup,
_teardown),
ISC_TEST_ENTRY(benchmark)
#endif /* DNS_BENCHMARK_TESTS */
};
int c;
ISC_TEST_LIST_END
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
verbose = true;
break;
default:
break;
}
}
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -30,28 +28,7 @@
#include <dns/db.h>
#include <dns/nsec3.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
static void
iteration_test(const char *file, unsigned int expected) {
@ -134,8 +111,7 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) {
* check that appropriate max iterations is returned for different
* key size mixes
*/
static void
max_iterations(void **state) {
ISC_RUN_TEST_IMPL(max_iterations) {
UNUSED(state);
iteration_test("testdata/nsec3/1024.db", 150);
@ -146,8 +122,7 @@ max_iterations(void **state) {
}
/* check dns_nsec3param_salttotext() */
static void
nsec3param_salttotext(void **state) {
ISC_RUN_TEST_IMPL(nsec3param_salttotext) {
size_t i;
const nsec3param_salttotext_test_params_t tests[] = {
@ -171,26 +146,9 @@ nsec3param_salttotext(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(max_iterations, _setup,
_teardown),
cmocka_unit_test_setup_teardown(nsec3param_salttotext, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(max_iterations)
ISC_TEST_ENTRY(nsec3param_salttotext)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -33,7 +31,8 @@
#include <dns/nsec3.h>
#include "../zone_p.h"
#include "dnstest.h"
#include <dns/test.h>
#define HASH 1
#define FLAGS 0
@ -41,27 +40,6 @@
#define SALTLEN 4
#define SALT "FEDCBA98"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
/*%
* Structures containing parameters for nsec3param_salttotext_test().
*/
@ -184,8 +162,7 @@ nsec3param_change_test(const nsec3param_change_test_params_t *test) {
dns_zone_detach(&zone);
}
static void
nsec3param_change(void **state) {
ISC_RUN_TEST_IMPL(nsec3param_change) {
size_t i;
/*
@ -281,24 +258,8 @@ nsec3param_change(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(nsec3param_change, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(nsec3param_change)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -28,46 +26,22 @@
#include <dns/peer.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
/* Test DSCP set/get functions */
static void
dscp(void **state) {
ISC_RUN_TEST_IMPL(dscp) {
isc_result_t result;
isc_netaddr_t netaddr;
struct in_addr ina;
dns_peer_t *peer = NULL;
isc_dscp_t dscp;
UNUSED(state);
/*
* Create peer structure for the loopback address.
*/
ina.s_addr = INADDR_LOOPBACK;
isc_netaddr_fromin(&netaddr, &ina);
result = dns_peer_new(dt_mctx, &netaddr, &peer);
result = dns_peer_new(mctx, &netaddr, &peer);
assert_int_equal(result, ISC_R_SUCCESS);
/*
@ -153,23 +127,10 @@ dscp(void **state) {
dns_peer_detach(&peer);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(dscp, _setup, _teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(dscp)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -35,27 +33,30 @@
#include <dst/dst.h>
#include "dnstest.h"
#include <dns/test.h>
static dns_rdatatype_t privatetype = 65534;
static int
_setup(void **state) {
setup_test(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS) {
return (1);
}
return (0);
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
dns_test_end();
dst_lib_destroy();
return (0);
}
@ -147,8 +148,7 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private,
}
/* convert private signing records to text */
static void
private_signing_totext_test(void **state) {
ISC_RUN_TEST_IMPL(private_signing_totext) {
dns_rdata_t private;
int i;
@ -180,8 +180,7 @@ private_signing_totext_test(void **state) {
}
/* convert private chain records to text */
static void
private_nsec3_totext_test(void **state) {
ISC_RUN_TEST_IMPL(private_nsec3_totext) {
dns_rdata_t private;
int i;
@ -215,26 +214,9 @@ private_nsec3_totext_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(private_signing_totext_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(private_nsec3_totext_test,
_setup, _teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(private_signing_totext, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(private_nsec3_totext, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
@ -29,7 +27,6 @@
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
@ -54,7 +51,7 @@
#include <dst/dst.h>
#include "dnstest.h"
#include <dns/test.h>
typedef struct {
dns_rbt_t *rbt;
@ -127,31 +124,11 @@ static const char *const ordered_names[] = {
static const size_t ordered_names_count =
(sizeof(ordered_names) / sizeof(*ordered_names));
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
static void
delete_data(void *data, void *arg) {
UNUSED(arg);
isc_mem_put(dt_mctx, data, sizeof(size_t));
isc_mem_put(mctx, data, sizeof(size_t));
}
static test_context_t *
@ -160,16 +137,15 @@ test_context_setup(void) {
isc_result_t result;
size_t i;
ctx = isc_mem_get(dt_mctx, sizeof(*ctx));
ctx = isc_mem_get(mctx, sizeof(*ctx));
assert_non_null(ctx);
ctx->rbt = NULL;
result = dns_rbt_create(dt_mctx, delete_data, NULL, &ctx->rbt);
result = dns_rbt_create(mctx, delete_data, NULL, &ctx->rbt);
assert_int_equal(result, ISC_R_SUCCESS);
ctx->rbt_distances = NULL;
result = dns_rbt_create(dt_mctx, delete_data, NULL,
&ctx->rbt_distances);
result = dns_rbt_create(mctx, delete_data, NULL, &ctx->rbt_distances);
assert_int_equal(result, ISC_R_SUCCESS);
for (i = 0; i < domain_names_count; i++) {
@ -181,13 +157,13 @@ test_context_setup(void) {
name = dns_fixedname_name(&fname);
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = i + 1;
result = dns_rbt_addname(ctx->rbt, name, n);
assert_int_equal(result, ISC_R_SUCCESS);
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = node_distances[i];
result = dns_rbt_addname(ctx->rbt_distances, name, n);
@ -202,7 +178,7 @@ test_context_teardown(test_context_t *ctx) {
dns_rbt_destroy(&ctx->rbt);
dns_rbt_destroy(&ctx->rbt_distances);
isc_mem_put(dt_mctx, ctx, sizeof(*ctx));
isc_mem_put(mctx, ctx, sizeof(*ctx));
}
/*
@ -233,13 +209,10 @@ check_test_data(dns_rbt_t *rbt) {
}
/* Test the creation of an rbt */
static void
rbt_create(void **state) {
ISC_RUN_TEST_IMPL(rbt_create) {
test_context_t *ctx;
bool tree_ok;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -253,12 +226,9 @@ rbt_create(void **state) {
}
/* Test dns_rbt_nodecount() on a tree */
static void
rbt_nodecount(void **state) {
ISC_RUN_TEST_IMPL(rbt_nodecount) {
test_context_t *ctx;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -269,8 +239,7 @@ rbt_nodecount(void **state) {
}
/* Test dns_rbtnode_get_distance() on a tree */
static void
rbtnode_get_distance(void **state) {
ISC_RUN_TEST_IMPL(rbtnode_get_distance) {
isc_result_t result;
test_context_t *ctx;
const char *name_str = "a";
@ -279,8 +248,6 @@ rbtnode_get_distance(void **state) {
dns_rbtnode_t *node = NULL;
dns_rbtnodechain_t chain;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -322,19 +289,16 @@ rbtnode_get_distance(void **state) {
* path from a sub-tree's root to a node is no more than
* 2log(n). This check verifies that the tree is balanced.
*/
static void
rbt_check_distance_random(void **state) {
ISC_RUN_TEST_IMPL(rbt_check_distance_random) {
dns_rbt_t *mytree = NULL;
const unsigned int log_num_nodes = 16;
isc_result_t result;
bool tree_ok;
int i;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree);
result = dns_rbt_create(mctx, delete_data, NULL, &mytree);
assert_int_equal(result, ISC_R_SUCCESS);
/* Names are inserted in random order. */
@ -351,7 +315,7 @@ rbt_check_distance_random(void **state) {
size_t *n;
char namebuf[34];
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = i + 1;
@ -400,19 +364,16 @@ rbt_check_distance_random(void **state) {
* path from a sub-tree's root to a node is no more than
* 2log(n). This check verifies that the tree is balanced.
*/
static void
rbt_check_distance_ordered(void **state) {
ISC_RUN_TEST_IMPL(rbt_check_distance_ordered) {
dns_rbt_t *mytree = NULL;
const unsigned int log_num_nodes = 16;
isc_result_t result;
bool tree_ok;
int i;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree);
result = dns_rbt_create(mctx, delete_data, NULL, &mytree);
assert_int_equal(result, ISC_R_SUCCESS);
/* Names are inserted in sorted order. */
@ -431,7 +392,7 @@ rbt_check_distance_ordered(void **state) {
dns_fixedname_t fname;
dns_name_t *name;
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = i + 1;
@ -479,25 +440,22 @@ compare_labelsequences(dns_rbtnode_t *node, const char *labelstr) {
dns_name_init(&name, NULL);
dns_rbt_namefromnode(node, &name);
result = dns_name_tostring(&name, &nodestr, dt_mctx);
result = dns_name_tostring(&name, &nodestr, mctx);
assert_int_equal(result, ISC_R_SUCCESS);
is_equal = strcmp(labelstr, nodestr) == 0 ? true : false;
isc_mem_free(dt_mctx, nodestr);
isc_mem_free(mctx, nodestr);
return (is_equal);
}
/* Test insertion into a tree */
static void
rbt_insert(void **state) {
ISC_RUN_TEST_IMPL(rbt_insert) {
isc_result_t result;
test_context_t *ctx;
dns_rbtnode_t *node;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -653,13 +611,10 @@ rbt_insert(void **state) {
* as a red-black tree. This test checks node deletion when upper nodes
* have data.
*/
static void
rbt_remove(void **state) {
ISC_RUN_TEST_IMPL(rbt_remove) {
isc_result_t result;
size_t j;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
/*
@ -675,7 +630,7 @@ rbt_remove(void **state) {
size_t start_node;
/* Create a tree. */
result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree);
result = dns_rbt_create(mctx, delete_data, NULL, &mytree);
assert_int_equal(result, ISC_R_SUCCESS);
/* Insert test data into the tree. */
@ -703,7 +658,7 @@ rbt_remove(void **state) {
assert_non_null(node);
assert_null(node->data);
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = i;
@ -843,7 +798,7 @@ insert_nodes(dns_rbt_t *mytree, char **names, size_t *names_count,
size_t *n;
char namebuf[34];
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = i; /* Unused value */
@ -868,7 +823,7 @@ insert_nodes(dns_rbt_t *mytree, char **names, size_t *names_count,
result = dns_rbt_addnode(mytree, name, &node);
if (result == ISC_R_SUCCESS) {
node->data = n;
names[*names_count] = isc_mem_strdup(dt_mctx,
names[*names_count] = isc_mem_strdup(mctx,
namebuf);
assert_non_null(names[*names_count]);
*names_count += 1;
@ -899,7 +854,7 @@ remove_nodes(dns_rbt_t *mytree, char **names, size_t *names_count,
result = dns_rbt_deletename(mytree, name, false);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_free(dt_mctx, names[node]);
isc_mem_free(mctx, names[node]);
if (*names_count > 0) {
names[node] = names[*names_count - 1];
names[*names_count - 1] = NULL;
@ -944,8 +899,7 @@ check_tree(dns_rbt_t *mytree, char **names, size_t names_count) {
* forest. The number of nodes in the tree level doesn't grow
* over 1024.
*/
static void
rbt_insert_and_remove(void **state) {
ISC_RUN_TEST_IMPL(rbt_insert_and_remove) {
isc_result_t result;
dns_rbt_t *mytree = NULL;
size_t *n;
@ -953,14 +907,12 @@ rbt_insert_and_remove(void **state) {
size_t names_count;
int i;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree);
result = dns_rbt_create(mctx, delete_data, NULL, &mytree);
assert_int_equal(result, ISC_R_SUCCESS);
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
result = dns_rbt_addname(mytree, dns_rootname, n);
assert_int_equal(result, ISC_R_SUCCESS);
@ -999,7 +951,7 @@ rbt_insert_and_remove(void **state) {
for (i = 0; i < 1024; i++) {
if (names[i] != NULL) {
isc_mem_free(dt_mctx, names[i]);
isc_mem_free(mctx, names[i]);
}
}
@ -1011,16 +963,13 @@ rbt_insert_and_remove(void **state) {
}
/* Test findname return values */
static void
rbt_findname(void **state) {
ISC_RUN_TEST_IMPL(rbt_findname) {
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname, found;
dns_name_t *name = NULL, *foundname = NULL;
size_t *n = NULL;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -1059,21 +1008,18 @@ rbt_findname(void **state) {
}
/* Test addname return values */
static void
rbt_addname(void **state) {
ISC_RUN_TEST_IMPL(rbt_addname) {
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname;
dns_name_t *name = NULL;
size_t *n;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = 1;
@ -1085,26 +1031,23 @@ rbt_addname(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
/* Now add again, should get ISC_R_EXISTS */
n = isc_mem_get(dt_mctx, sizeof(size_t));
n = isc_mem_get(mctx, sizeof(size_t));
assert_non_null(n);
*n = 2;
result = dns_rbt_addname(ctx->rbt, name, n);
assert_int_equal(result, ISC_R_EXISTS);
isc_mem_put(dt_mctx, n, sizeof(size_t));
isc_mem_put(mctx, n, sizeof(size_t));
test_context_teardown(ctx);
}
/* Test deletename return values */
static void
rbt_deletename(void **state) {
ISC_RUN_TEST_IMPL(rbt_deletename) {
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname;
dns_name_t *name = NULL;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -1125,8 +1068,7 @@ rbt_deletename(void **state) {
}
/* Test nodechain */
static void
rbt_nodechain(void **state) {
ISC_RUN_TEST_IMPL(rbt_nodechain) {
isc_result_t result;
test_context_t *ctx;
dns_fixedname_t fname, found, expect;
@ -1134,8 +1076,6 @@ rbt_nodechain(void **state) {
dns_rbtnode_t *node = NULL;
dns_rbtnodechain_t chain;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -1186,15 +1126,12 @@ rbt_nodechain(void **state) {
}
/* Test addname return values */
static void
rbtnode_namelen(void **state) {
ISC_RUN_TEST_IMPL(rbtnode_namelen) {
isc_result_t result;
test_context_t *ctx = NULL;
dns_rbtnode_t *node;
unsigned int len;
UNUSED(state);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
@ -1267,8 +1204,7 @@ find_thread(void *arg) {
}
/* Benchmark RBT implementation */
static void
benchmark(void **state) {
ISC_RUN_TEST_IMPL(benchmark) {
isc_result_t result;
char namestr[sizeof("name18446744073709551616.example.org.")];
unsigned int r;
@ -1281,8 +1217,6 @@ benchmark(void **state) {
unsigned int nthreads;
isc_thread_t threads[32];
UNUSED(state);
srandom(time(NULL));
debug_mem_record = false;
@ -1301,7 +1235,7 @@ benchmark(void **state) {
/* Create a tree. */
mytree = NULL;
result = dns_rbt_create(dt_mctx, NULL, NULL, &mytree);
result = dns_rbt_create(mctx, NULL, NULL, &mytree);
assert_int_equal(result, ISC_R_SUCCESS);
/* Insert test data into the tree. */
@ -1343,47 +1277,24 @@ benchmark(void **state) {
}
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(rbt_create, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_nodecount, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbtnode_get_distance, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_check_distance_random,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_check_distance_ordered,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_insert, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_remove, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_insert_and_remove, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_findname, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_addname, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_deletename, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_nodechain, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbtnode_namelen, _setup,
_teardown),
ISC_TEST_LIST_START
ISC_TEST_ENTRY(rbt_create)
ISC_TEST_ENTRY(rbt_nodecount)
ISC_TEST_ENTRY(rbtnode_get_distance)
ISC_TEST_ENTRY(rbt_check_distance_random)
ISC_TEST_ENTRY(rbt_check_distance_ordered)
ISC_TEST_ENTRY(rbt_insert)
ISC_TEST_ENTRY(rbt_remove)
ISC_TEST_ENTRY(rbt_insert_and_remove)
ISC_TEST_ENTRY(rbt_findname)
ISC_TEST_ENTRY(rbt_addname)
ISC_TEST_ENTRY(rbt_deletename)
ISC_TEST_ENTRY(rbt_nodechain)
ISC_TEST_ENTRY(rbtnode_namelen)
#if defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__)
cmocka_unit_test_setup_teardown(benchmark, _setup, _teardown),
ISC_TEST_ENTRY(benchmark)
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -30,32 +28,15 @@
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include "dnstest.h"
#include <dns/test.h>
/* Include the main file */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#undef CHECK
#include "../rbtdb.c"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#pragma GCC diagnostic pop
const char *ownercase_vectors[12][2] = {
{
@ -157,8 +138,7 @@ ownercase_test_one(const char *str1, const char *str2) {
return (dns_name_caseequal(name1, name2));
}
static void
ownercase_test(void **state) {
ISC_RUN_TEST_IMPL(ownercase) {
UNUSED(state);
for (size_t n = 0; n < ARRAY_SIZE(ownercase_vectors); n++) {
@ -172,8 +152,7 @@ ownercase_test(void **state) {
assert_false(ownercase_test_one("\\216", "\\246"));
}
static void
setownercase_test(void **state) {
ISC_RUN_TEST_IMPL(setownercase) {
isc_result_t result;
rbtdb_nodelock_t node_locks[1];
dns_rbtdb_t rbtdb = { .node_locks = node_locks };
@ -222,24 +201,9 @@ setownercase_test(void **state) {
assert_true(dns_name_caseequal(name1, name2));
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(ownercase_test),
cmocka_unit_test(setownercase_test),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(ownercase)
ISC_TEST_ENTRY(setownercase)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -35,7 +33,7 @@
#include <dns/rdata.h>
#include "dnstest.h"
#include <dns/test.h>
static bool debug = false;
@ -56,27 +54,6 @@ struct textvsunknown {
};
typedef struct textvsunknown textvsunknown_t;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
/*
* An array of these structures is passed to check_text_ok().
*/
@ -199,7 +176,7 @@ rdata_towire(dns_rdata_t *rdata, unsigned char *dst, size_t dstlen,
/*
* Try converting input data into uncompressed wire form.
*/
dns_compress_init(&cctx, -1, dt_mctx);
dns_compress_init(&cctx, -1, mctx);
result = dns_rdata_towire(rdata, &cctx, &target);
dns_compress_invalidate(&cctx);
@ -285,7 +262,7 @@ check_struct_conversions(dns_rdata_t *rdata, size_t structsize,
char buf[1024];
unsigned int count = 0;
rdata_struct = isc_mem_allocate(dt_mctx, structsize);
rdata_struct = isc_mem_allocate(mctx, structsize);
assert_non_null(rdata_struct);
/*
@ -365,7 +342,7 @@ check_struct_conversions(dns_rdata_t *rdata, size_t structsize,
}
}
isc_mem_free(dt_mctx, rdata_struct);
isc_mem_free(mctx, rdata_struct);
}
/*
@ -892,8 +869,7 @@ key_required(void **state, dns_rdatatype_t type, size_t size) {
}
/* APL RDATA manipulations */
static void
apl(void **state) {
ISC_RUN_TEST_IMPL(apl) {
text_ok_t text_ok[] = {
/* empty list */
TEXT_VALID(""),
@ -934,8 +910,6 @@ apl(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t));
}
@ -977,8 +951,7 @@ apl(void **state) {
*
* ATMA RRs cause no additional section processing.
*/
static void
atma(void **state) {
ISC_RUN_TEST_IMPL(atma) {
text_ok_t text_ok[] = { TEXT_VALID("00"),
TEXT_VALID_CHANGED("0.0", "00"),
/*
@ -1041,15 +1014,12 @@ atma(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t));
}
/* AMTRELAY RDATA manipulations */
static void
amtrelay(void **state) {
ISC_RUN_TEST_IMPL(amtrelay) {
text_ok_t text_ok[] = {
TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_INVALID("0 0"),
/* gateway type 0 */
@ -1121,14 +1091,11 @@ amtrelay(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_amtrelay, sizeof(dns_rdata_amtrelay_t));
}
static void
cdnskey(void **state) {
ISC_RUN_TEST_IMPL(cdnskey) {
key_required(state, dns_rdatatype_cdnskey, sizeof(dns_rdata_cdnskey_t));
}
@ -1196,8 +1163,7 @@ cdnskey(void **state) {
* must understand the semantics associated with a bit in the Type Bit
* Map field that has been set to 1.
*/
static void
csync(void **state) {
ISC_RUN_TEST_IMPL(csync) {
text_ok_t text_ok[] = { TEXT_INVALID(""),
TEXT_INVALID("0"),
TEXT_VALID("0 0"),
@ -1252,14 +1218,11 @@ csync(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_csync, sizeof(dns_rdata_csync_t));
}
static void
dnskey(void **state) {
ISC_RUN_TEST_IMPL(dnskey) {
key_required(state, dns_rdatatype_dnskey, sizeof(dns_rdata_dnskey_t));
}
@ -1323,8 +1286,7 @@ dnskey(void **state) {
* character ("-", ASCII 45). White space is permitted within Base64
* data.
*/
static void
doa(void **state) {
ISC_RUN_TEST_IMPL(doa) {
text_ok_t text_ok[] = {
/*
* Valid, non-empty DOA-DATA.
@ -1471,8 +1433,6 @@ doa(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_doa, sizeof(dns_rdata_doa_t));
}
@ -1539,8 +1499,7 @@ doa(void **state) {
* DNSKEY RR size. As of the time of this writing, the only defined
* digest algorithm is SHA-1, which produces a 20 octet digest.
*/
static void
ds(void **state) {
ISC_RUN_TEST_IMPL(ds) {
text_ok_t text_ok[] = {
/*
* Invalid, empty record.
@ -1742,8 +1701,6 @@ ds(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_ds, sizeof(dns_rdata_ds_t));
}
@ -1808,8 +1765,7 @@ ds(void **state) {
* All fields are in network byte order ("big-endian", per [RFC1700],
* Data Notation).
*/
static void
edns_client_subnet(void **state) {
ISC_RUN_TEST_IMPL(edns_client_subnet) {
wire_ok_t wire_ok[] = {
/*
* Option code with no content.
@ -1883,8 +1839,6 @@ edns_client_subnet(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_opt, sizeof(dns_rdata_opt_t));
}
@ -1898,8 +1852,7 @@ edns_client_subnet(void **state) {
* significant. For readability, whitespace may be included in the value
* field and should be ignored when reading a master file.
*/
static void
eid(void **state) {
ISC_RUN_TEST_IMPL(eid) {
text_ok_t text_ok[] = { TEXT_VALID("AABBCC"),
TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
TEXT_INVALID("aab"),
@ -1913,8 +1866,6 @@ eid(void **state) {
*/
WIRE_SENTINEL() };
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t));
}
@ -1922,8 +1873,7 @@ eid(void **state) {
/*
* test that an oversized HIP record will be rejected
*/
static void
hip(void **state) {
ISC_RUN_TEST_IMPL(hip) {
text_ok_t text_ok[] = {
/* RFC 8005 examples. */
TEXT_VALID_LOOP(0, "2 200100107B1A74DF365639CC39F1D578 "
@ -1959,8 +1909,6 @@ hip(void **state) {
isc_result_t result;
size_t i;
UNUSED(state);
/*
* Fill the rest of input buffer with compression pointers.
*/
@ -2037,8 +1985,7 @@ hip(void **state) {
* as one or two <character-string>s, i.e., count followed by
* characters.
*/
static void
isdn(void **state) {
ISC_RUN_TEST_IMPL(isdn) {
wire_ok_t wire_ok[] = { /*
* "".
*/
@ -2061,8 +2008,6 @@ isdn(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t));
}
@ -2070,8 +2015,7 @@ isdn(void **state) {
/*
* KEY tests.
*/
static void
key(void **state) {
ISC_RUN_TEST_IMPL(key) {
wire_ok_t wire_ok[] = {
/*
* RDATA is comprised of:
@ -2144,8 +2088,6 @@ key(void **state) {
TEXT_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_key, sizeof(dns_rdata_key_t));
}
@ -2153,8 +2095,7 @@ key(void **state) {
/*
* LOC tests.
*/
static void
loc(void **state) {
ISC_RUN_TEST_IMPL(loc) {
text_ok_t text_ok[] = {
TEXT_VALID_CHANGED("0 N 0 E 0", "0 0 0.000 N 0 0 0.000 E 0.00m "
"1m 10000m 10m"),
@ -2209,8 +2150,6 @@ loc(void **state) {
TEXT_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, 0, NULL, false, dns_rdataclass_in,
dns_rdatatype_loc, sizeof(dns_rdata_loc_t));
}
@ -2224,8 +2163,7 @@ loc(void **state) {
* significant. For readability, whitespace may be included in the value
* field and should be ignored when reading a master file.
*/
static void
nimloc(void **state) {
ISC_RUN_TEST_IMPL(nimloc) {
text_ok_t text_ok[] = { TEXT_VALID("AABBCC"),
TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
TEXT_INVALID("aab"),
@ -2239,8 +2177,6 @@ nimloc(void **state) {
*/
WIRE_SENTINEL() };
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t));
}
@ -2311,8 +2247,7 @@ nimloc(void **state) {
* Bits representing pseudo-types MUST be clear, as they do not appear
* in zone data. If encountered, they MUST be ignored upon being read.
*/
static void
nsec(void **state) {
ISC_RUN_TEST_IMPL(nsec) {
text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("."),
TEXT_VALID(". RRSIG"), TEXT_SENTINEL() };
wire_ok_t wire_ok[] = { WIRE_INVALID(0x00), WIRE_INVALID(0x00, 0x00),
@ -2320,8 +2255,6 @@ nsec(void **state) {
WIRE_VALID(0x00, 0x00, 0x01, 0x02),
WIRE_SENTINEL() };
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t));
}
@ -2331,8 +2264,7 @@ nsec(void **state) {
*
* RFC 5155.
*/
static void
nsec3(void **state) {
ISC_RUN_TEST_IMPL(nsec3) {
text_ok_t text_ok[] = { TEXT_INVALID(""),
TEXT_INVALID("."),
TEXT_INVALID(". RRSIG"),
@ -2352,15 +2284,12 @@ nsec3(void **state) {
"AJHVGTICN6K0VDA53GCHFMT219SRRQLM"),
TEXT_SENTINEL() };
UNUSED(state);
check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in,
dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t));
}
/* NXT RDATA manipulations */
static void
nxt(void **state) {
ISC_RUN_TEST_IMPL(nxt) {
compare_ok_t compare_ok[] = {
COMPARE("a. A SIG", "a. A SIG", 0),
/*
@ -2379,14 +2308,11 @@ nxt(void **state) {
COMPARE("b. A SIG AAAA", "b. A AAAA SIG", 0), COMPARE_SENTINEL()
};
UNUSED(state);
check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in,
dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t));
}
static void
rkey(void **state) {
ISC_RUN_TEST_IMPL(rkey) {
text_ok_t text_ok[] = { /*
* Valid, flags set to 0 and a key is present.
*/
@ -2420,108 +2346,8 @@ rkey(void **state) {
dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t));
}
/*
* rrsig (sig) tests.
*/
static void
sig_rrsig(void **state) {
wire_ok_t wire_ok[] = {
/*
* RDATA is comprised of:
*
* type covered: 2
* algorithm: 1
* labels: 1
* original ttl: 4
* signature expiration: 4
* time signed: 4
* key footprint: 2
* signer: variable
* signature: variable
* - if algorithm is PRIVATEDNS the algorithm name is embedded
* at the start of the signature
* - if algorithm is PRIVATEOID the algorithm OID is embedded
* at the start of the signature
*/
/* PRIVATEDNS example. */
WIRE_INVALID(0x00, 0x01, 253, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r',
0x00, 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e',
0x00),
/* PRIVATEDNS example. + sigdata */
WIRE_VALID(0x00, 0x01, 253, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 's', 'i', 'g', 'n', 'e', 'r', 0x00, 0x07, 'e',
'x', 'a', 'm', 'p', 'l', 'e', 0x00, 0x00),
/* PRIVATEDNS compression pointer. */
WIRE_INVALID(0x00, 0x00, 0x00, 253, 0xc0, 0x00, 0x00),
/* PRIVATEOID */
WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r',
0x00, 0x00),
/* PRIVATEOID 1.3.6.1.4.1.2495 */
WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r',
0x00, 0x06, 0x07, 0x2b, 0x06, 0x01, 0x04, 0x01,
0x93, 0x3f),
/* PRIVATEOID 1.3.6.1.4.1.2495 + sigdata */
WIRE_VALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 's', 'i', 'g', 'n', 'e', 'r', 0x00, 0x06, 0x07,
0x2b, 0x06, 0x01, 0x04, 0x01, 0x93, 0x3f, 0x00),
/* PRIVATEOID malformed OID - high-bit set on last octet */
WIRE_INVALID(0x00, 0x01, 254, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 's', 'i', 'g', 'n', 'e', 'r',
0x00, 0x06, 0x07, 0x2b, 0x06, 0x01, 0x04, 0x01,
0x93, 0xbf, 0x00),
WIRE_SENTINEL()
};
text_ok_t text_ok[] = {
/* PRIVATEDNS example. */
TEXT_INVALID("A 253 1 0 19700101000001 19700101000000 0 "
"signer. B2V4YW1wbGUA"),
/* PRIVATEDNS example. + sigdata */
TEXT_VALID("A 253 1 0 19700101000001 19700101000000 0 signer. "
"B2V4YW1wbGUAAA=="),
/* PRIVATEDNS compression pointer. */
TEXT_INVALID("A 253 1 0 19700101000001 19700101000000 0 "
"signer. wAAA"),
/* PRIVATEOID */
TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 "
"signer. AA=="),
/* PRIVATEOID 1.3.6.1.4.1.2495 */
TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 "
"signer. BgcrBgEEAZM/"),
/* PRIVATEOID 1.3.6.1.4.1.2495 + sigdata */
TEXT_VALID("A 254 1 0 19700101000001 19700101000000 0 signer. "
"BgcrBgEEAZM/AA=="),
/* PRIVATEOID malformed OID - high-bit set on last octet */
TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 "
"signer. BgcrBgEEAZO/AA=="),
/* PRIVATEOID malformed OID - wrong tag */
TEXT_INVALID("A 254 1 0 19700101000001 19700101000000 0 "
"signer. BwcrBgEEAZM/AA=="),
/*
* Sentinel.
*/
TEXT_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_sig, sizeof(dns_rdata_sig_t));
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_rrsig, sizeof(dns_rdata_rrsig_t));
}
/* SSHFP RDATA manipulations */
static void
sshfp(void **state) {
ISC_RUN_TEST_IMPL(sshfp) {
text_ok_t text_ok[] = { TEXT_INVALID(""), /* too short */
TEXT_INVALID("0"), /* reserved, too short */
TEXT_VALID("0 0"), /* no finger print */
@ -2598,8 +2424,6 @@ sshfp(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_sshfp, sizeof(dns_rdata_sshfp_t));
}
@ -2643,8 +2467,7 @@ sshfp(void **state) {
* port 25; if zero, SMTP service is not supported on the specified
* address.
*/
static void
wks(void **state) {
ISC_RUN_TEST_IMPL(wks) {
text_ok_t text_ok[] = { /*
* Valid, IPv4 address in dotted-quad form.
*/
@ -2681,14 +2504,11 @@ wks(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t));
}
static void
https_svcb(void **state) {
ISC_RUN_TEST_IMPL(https_svcb) {
/*
* Known keys: mandatory, apln, no-default-alpn, port,
* ipv4hint, port, ipv6hint.
@ -2932,8 +2752,6 @@ https_svcb(void **state) {
{ NULL, NULL }
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_svcb, sizeof(dns_rdata_in_svcb_t));
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
@ -3030,8 +2848,7 @@ https_svcb(void **state) {
*
*/
static void
zonemd(void **state) {
ISC_RUN_TEST_IMPL(zonemd) {
text_ok_t text_ok[] = {
TEXT_INVALID(""),
/* No digest scheme or digest type*/
@ -3198,16 +3015,13 @@ zonemd(void **state) {
WIRE_SENTINEL()
};
UNUSED(state);
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_zonemd, sizeof(dns_rdata_zonemd_t));
}
static void
atcname(void **state) {
ISC_RUN_TEST_IMPL(atcname) {
unsigned int i;
UNUSED(state);
#define UNR "# Unexpected result from dns_rdatatype_atcname for type %u\n"
for (i = 0; i < 0xffffU; i++) {
bool tf = dns_rdatatype_atcname((dns_rdatatype_t)i);
@ -3231,10 +3045,9 @@ atcname(void **state) {
#undef UNR
}
static void
atparent(void **state) {
ISC_RUN_TEST_IMPL(atparent) {
unsigned int i;
UNUSED(state);
#define UNR "# Unexpected result from dns_rdatatype_atparent for type %u\n"
for (i = 0; i < 0xffffU; i++) {
bool tf = dns_rdatatype_atparent((dns_rdatatype_t)i);
@ -3256,10 +3069,8 @@ atparent(void **state) {
#undef UNR
}
static void
iszonecutauth(void **state) {
ISC_RUN_TEST_IMPL(iszonecutauth) {
unsigned int i;
UNUSED(state);
#define UNR "# Unexpected result from dns_rdatatype_iszonecutauth for type %u\n"
for (i = 0; i < 0xffffU; i++) {
bool tf = dns_rdatatype_iszonecutauth((dns_rdatatype_t)i);
@ -3285,88 +3096,37 @@ iszonecutauth(void **state) {
#undef UNR
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
/* types */
cmocka_unit_test_setup_teardown(amtrelay, _setup, _teardown),
cmocka_unit_test_setup_teardown(apl, _setup, _teardown),
cmocka_unit_test_setup_teardown(atma, _setup, _teardown),
cmocka_unit_test_setup_teardown(cdnskey, _setup, _teardown),
cmocka_unit_test_setup_teardown(csync, _setup, _teardown),
cmocka_unit_test_setup_teardown(dnskey, _setup, _teardown),
cmocka_unit_test_setup_teardown(doa, _setup, _teardown),
cmocka_unit_test_setup_teardown(ds, _setup, _teardown),
cmocka_unit_test_setup_teardown(eid, _setup, _teardown),
cmocka_unit_test_setup_teardown(hip, _setup, _teardown),
cmocka_unit_test_setup_teardown(https_svcb, _setup, _teardown),
cmocka_unit_test_setup_teardown(isdn, _setup, _teardown),
cmocka_unit_test_setup_teardown(key, _setup, _teardown),
cmocka_unit_test_setup_teardown(loc, _setup, _teardown),
cmocka_unit_test_setup_teardown(nimloc, _setup, _teardown),
cmocka_unit_test_setup_teardown(nsec, _setup, _teardown),
cmocka_unit_test_setup_teardown(nsec3, _setup, _teardown),
cmocka_unit_test_setup_teardown(nxt, _setup, _teardown),
cmocka_unit_test_setup_teardown(rkey, _setup, _teardown),
cmocka_unit_test_setup_teardown(sig_rrsig, _setup, _teardown),
cmocka_unit_test_setup_teardown(sshfp, _setup, _teardown),
cmocka_unit_test_setup_teardown(wks, _setup, _teardown),
cmocka_unit_test_setup_teardown(zonemd, _setup, _teardown),
/* other tests */
cmocka_unit_test_setup_teardown(edns_client_subnet, _setup,
_teardown),
cmocka_unit_test_setup_teardown(atcname, NULL, NULL),
cmocka_unit_test_setup_teardown(atparent, NULL, NULL),
cmocka_unit_test_setup_teardown(iszonecutauth, NULL, NULL),
};
struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])];
size_t i;
int c;
ISC_TEST_LIST_START
memset(selected, 0, sizeof(selected));
/* types */
ISC_TEST_ENTRY(amtrelay)
ISC_TEST_ENTRY(apl)
ISC_TEST_ENTRY(atma)
ISC_TEST_ENTRY(cdnskey)
ISC_TEST_ENTRY(csync)
ISC_TEST_ENTRY(dnskey)
ISC_TEST_ENTRY(doa)
ISC_TEST_ENTRY(ds)
ISC_TEST_ENTRY(eid)
ISC_TEST_ENTRY(hip)
ISC_TEST_ENTRY(https_svcb)
ISC_TEST_ENTRY(isdn)
ISC_TEST_ENTRY(key)
ISC_TEST_ENTRY(loc)
ISC_TEST_ENTRY(nimloc)
ISC_TEST_ENTRY(nsec)
ISC_TEST_ENTRY(nsec3)
ISC_TEST_ENTRY(nxt)
ISC_TEST_ENTRY(rkey)
ISC_TEST_ENTRY(sshfp)
ISC_TEST_ENTRY(wks)
ISC_TEST_ENTRY(zonemd)
while ((c = isc_commandline_parse(argc, argv, "dlt:")) != -1) {
switch (c) {
case 'd':
debug = true;
break;
case 'l':
for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++)
{
if (tests[i].name != NULL) {
fprintf(stdout, "%s\n", tests[i].name);
}
}
return (0);
case 't':
if (!cmocka_add_test_byname(
tests, isc_commandline_argument, selected))
{
fprintf(stderr, "unknown test '%s'\n",
isc_commandline_argument);
exit(1);
}
break;
default:
break;
}
}
/* other tests */
ISC_TEST_ENTRY(edns_client_subnet)
ISC_TEST_ENTRY(atcname)
ISC_TEST_ENTRY(atparent)
ISC_TEST_ENTRY(iszonecutauth)
ISC_TEST_LIST_END
if (selected[0].name != NULL) {
return (cmocka_run_group_tests(selected, NULL, NULL));
} else {
return (cmocka_run_group_tests(tests, NULL, NULL));
}
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,32 +27,10 @@
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
/* test trimming of rdataset TTLs */
static void
trimttl(void **state) {
ISC_RUN_TEST_IMPL(trimttl) {
dns_rdataset_t rdataset, sigrdataset;
dns_rdata_rrsig_t rrsig;
isc_stdtime_t ttltimenow, ttltimeexpire;
@ -124,23 +100,8 @@ trimttl(void **state) {
assert_int_equal(sigrdataset.ttl, 0);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(trimttl)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -31,28 +29,7 @@
#include <dns/stats.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
static void
set_typestats(dns_stats_t *stats, dns_rdatatype_t type) {
@ -220,7 +197,7 @@ rdatasetstats(void **state, bool servestale) {
UNUSED(state);
result = dns_rdatasetstats_create(dt_mctx, &stats);
result = dns_rdatasetstats_create(mctx, &stats);
assert_int_equal(result, ISC_R_SUCCESS);
/* First 255 types. */
@ -272,41 +249,17 @@ rdatasetstats(void **state, bool servestale) {
* Test that rdatasetstats counters are properly set when moving from
* active -> stale -> ancient.
*/
static void
test_rdatasetstats_active_stale_ancient(void **state) {
rdatasetstats(state, true);
}
ISC_RUN_TEST_IMPL(active_stale_ancient) { rdatasetstats(state, true); }
/*
* Test that rdatasetstats counters are properly set when moving from
* active -> ancient.
*/
static void
test_rdatasetstats_active_ancient(void **state) {
rdatasetstats(state, false);
}
ISC_RUN_TEST_IMPL(active_ancient) { rdatasetstats(state, false); }
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(
test_rdatasetstats_active_stale_ancient, _setup,
_teardown),
cmocka_unit_test_setup_teardown(
test_rdatasetstats_active_ancient, _setup, _teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(active_stale_ancient)
ISC_TEST_ENTRY(active_ancient)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -36,7 +34,7 @@
#include <dns/resolver.h>
#include <dns/view.h>
#include "dnstest.h"
#include <dns/test.h>
static dns_dispatchmgr_t *dispatchmgr = NULL;
static dns_dispatch_t *dispatch = NULL;
@ -47,15 +45,12 @@ _setup(void **state) {
isc_result_t result;
isc_sockaddr_t local;
UNUSED(state);
setup_managers(state);
result = dns_test_begin(NULL, true);
result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_test_makeview("view", &view);
result = dns_test_makeview("view", true, &view);
assert_int_equal(result, ISC_R_SUCCESS);
isc_sockaddr_any(&local);
@ -67,12 +62,11 @@ _setup(void **state) {
static int
_teardown(void **state) {
UNUSED(state);
dns_dispatch_detach(&dispatch);
dns_view_detach(&view);
dns_dispatchmgr_detach(&dispatchmgr);
dns_test_end();
teardown_managers(state);
return (0);
}
@ -93,8 +87,7 @@ destroy_resolver(dns_resolver_t **resolverp) {
}
/* dns_resolver_create */
static void
create_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_create) {
dns_resolver_t *resolver = NULL;
UNUSED(state);
@ -104,8 +97,7 @@ create_test(void **state) {
}
/* dns_resolver_gettimeout */
static void
gettimeout_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_gettimeout) {
dns_resolver_t *resolver = NULL;
unsigned int timeout;
@ -120,8 +112,7 @@ gettimeout_test(void **state) {
}
/* dns_resolver_settimeout */
static void
settimeout_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_settimeout) {
dns_resolver_t *resolver = NULL;
unsigned int default_timeout, timeout;
@ -138,8 +129,7 @@ settimeout_test(void **state) {
}
/* dns_resolver_settimeout */
static void
settimeout_default_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_settimeout_default) {
dns_resolver_t *resolver = NULL;
unsigned int default_timeout, timeout;
@ -161,8 +151,7 @@ settimeout_default_test(void **state) {
}
/* dns_resolver_settimeout below minimum */
static void
settimeout_belowmin_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_settimeout_belowmin) {
dns_resolver_t *resolver = NULL;
unsigned int default_timeout, timeout;
@ -180,8 +169,7 @@ settimeout_belowmin_test(void **state) {
}
/* dns_resolver_settimeout over maximum */
static void
settimeout_overmax_test(void **state) {
ISC_RUN_TEST_IMPL(dns_resolver_settimeout_overmax) {
dns_resolver_t *resolver = NULL;
unsigned int timeout;
@ -195,33 +183,15 @@ settimeout_overmax_test(void **state) {
destroy_resolver(&resolver);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(create_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(gettimeout_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(settimeout_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(settimeout_default_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(settimeout_belowmin_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(settimeout_overmax_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(dns_resolver_create, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_resolver_gettimeout, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_default, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_belowmin, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_resolver_settimeout_overmax, _setup, _teardown)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,25 +27,29 @@
#include <isc/util.h>
#include "../dst_internal.h"
#include "dnstest.h"
#include <dns/test.h>
static int
_setup(void **state) {
setup_test(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS) {
return (1);
}
return (0);
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
dns_test_end();
dst_lib_destroy();
return (0);
}
@ -131,8 +133,7 @@ static unsigned char sigsha512[512] = {
};
/* RSA verify */
static void
isc_rsa_verify_test(void **state) {
ISC_RUN_TEST_IMPL(isc_rsa_verify) {
isc_result_t ret;
dns_fixedname_t fname;
isc_buffer_t buf;
@ -150,12 +151,12 @@ isc_rsa_verify_test(void **state) {
assert_int_equal(ret, ISC_R_SUCCESS);
ret = dst_key_fromfile(name, 29235, DST_ALG_RSASHA1, DST_TYPE_PUBLIC,
"./", dt_mctx, &key);
"./", mctx, &key);
assert_int_equal(ret, ISC_R_SUCCESS);
/* RSASHA1 */
ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
&ctx);
assert_int_equal(ret, ISC_R_SUCCESS);
@ -175,7 +176,7 @@ isc_rsa_verify_test(void **state) {
key->key_alg = DST_ALG_RSASHA256;
ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
&ctx);
assert_int_equal(ret, ISC_R_SUCCESS);
@ -195,7 +196,7 @@ isc_rsa_verify_test(void **state) {
key->key_alg = DST_ALG_RSASHA512;
ret = dst_context_create(key, dt_mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0,
&ctx);
assert_int_equal(ret, ISC_R_SUCCESS);
@ -214,24 +215,8 @@ isc_rsa_verify_test(void **state) {
dst_key_free(&key);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_rsa_verify_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(isc_rsa_verify, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -46,28 +44,8 @@
#include <dst/dst.h>
#include "../zone_p.h"
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
/*%
* Structure characterizing a single diff tuple in the dns_diff_t structure
@ -95,6 +73,30 @@ typedef struct {
* */
} updatesigs_test_params_t;
static int
setup_test(void **state) {
isc_result_t result;
UNUSED(state);
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS) {
return (1);
}
return (0);
}
static int
teardown_test(void **state) {
UNUSED(state);
dst_lib_destroy();
return (0);
}
/*%
* Check whether the 'found' tuple matches the 'expected' tuple. 'found' is
* the 'index'th tuple output by dns__zone_updatesigs() in test 'test'.
@ -126,8 +128,7 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
* Check owner name.
*/
expected_name = dns_fixedname_initname(&expected_fname);
result = dns_name_fromstring(expected_name, expected->owner, 0,
dt_mctx);
result = dns_name_fromstring(expected_name, expected->owner, 0, mctx);
assert_int_equal(result, ISC_R_SUCCESS);
dns_name_format(&found->name, found_name, sizeof(found_name));
assert_true(dns_name_equal(expected_name, &found->name));
@ -235,7 +236,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
/*
* Initialize the structure dns__zone_updatesigs() will modify.
*/
dns_diff_init(dt_mctx, &zone_diff);
dns_diff_init(mctx, &zone_diff);
/*
* Check whether dns__zone_updatesigs() behaves as expected.
@ -287,8 +288,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
}
/* dns__zone_updatesigs() tests */
static void
updatesigs_next_test(void **state) {
ISC_RUN_TEST_IMPL(updatesigs_next) {
dst_key_t *zone_keys[DNS_MAXZONEKEYS];
dns_zone_t *zone = NULL;
dns_db_t *db = NULL;
@ -314,8 +314,8 @@ updatesigs_next_test(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
isc_stdtime_get(&now);
result = dns__zone_findkeys(zone, db, NULL, now, dt_mctx,
DNS_MAXZONEKEYS, zone_keys, &nkeys);
result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS,
zone_keys, &nkeys);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(nkeys, 2);
@ -438,24 +438,8 @@ updatesigs_next_test(void **state) {
dns_zone_detach(&zone);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(updatesigs_next_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(updatesigs_next, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -29,34 +27,12 @@
#include <dns/time.h>
#include "dnstest.h"
#include <dns/test.h>
#define TEST_ORIGIN "test"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
/* value = 0xfffffffff <-> 19691231235959 */
static void
epoch_minus_one_test(void **state) {
ISC_RUN_TEST_IMPL(epoch_minus_one) {
const char *test_text = "19691231235959";
const uint32_t test_time = 0xffffffff;
isc_result_t result;
@ -77,8 +53,7 @@ epoch_minus_one_test(void **state) {
}
/* value = 0x000000000 <-> 19700101000000*/
static void
epoch_test(void **state) {
ISC_RUN_TEST_IMPL(epoch) {
const char *test_text = "19700101000000";
const uint32_t test_time = 0x00000000;
isc_result_t result;
@ -99,8 +74,7 @@ epoch_test(void **state) {
}
/* value = 0x7fffffff <-> 20380119031407 */
static void
half_maxint_test(void **state) {
ISC_RUN_TEST_IMPL(half_maxint) {
const char *test_text = "20380119031407";
const uint32_t test_time = 0x7fffffff;
isc_result_t result;
@ -121,8 +95,7 @@ half_maxint_test(void **state) {
}
/* value = 0x80000000 <-> 20380119031408 */
static void
half_plus_one_test(void **state) {
ISC_RUN_TEST_IMPL(half_plus_one) {
const char *test_text = "20380119031408";
const uint32_t test_time = 0x80000000;
isc_result_t result;
@ -143,8 +116,7 @@ half_plus_one_test(void **state) {
}
/* value = 0xef68f5d0 <-> 19610307130000 */
static void
fifty_before_test(void **state) {
ISC_RUN_TEST_IMPL(fifty_before) {
isc_result_t result;
const char *test_text = "19610307130000";
const uint32_t test_time = 0xef68f5d0;
@ -165,8 +137,7 @@ fifty_before_test(void **state) {
}
/* value = 0x4d74d6d0 <-> 20110307130000 */
static void
some_ago_test(void **state) {
ISC_RUN_TEST_IMPL(some_ago) {
const char *test_text = "20110307130000";
const uint32_t test_time = 0x4d74d6d0;
isc_result_t result;
@ -186,33 +157,13 @@ some_ago_test(void **state) {
assert_int_equal(when, test_time);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(epoch_minus_one_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(epoch_test, _setup, _teardown),
cmocka_unit_test_setup_teardown(half_maxint_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(half_plus_one_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(fifty_before_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(some_ago_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(epoch_minus_one)
ISC_TEST_ENTRY(epoch)
ISC_TEST_ENTRY(half_maxint)
ISC_TEST_ENTRY(half_plus_one)
ISC_TEST_ENTRY(fifty_before)
ISC_TEST_ENTRY(some_ago)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -33,41 +31,37 @@
#include <dns/tsig.h>
#include "../tsig_p.h"
#include "dnstest.h"
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) { \
goto cleanup; \
} \
} while (0)
#include <dns/test.h>
#define TEST_ORIGIN "test"
static int debug = 0;
static int
_setup(void **state) {
setup_test(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS) {
return (1);
}
return (0);
}
static int
_teardown(void **state) {
teardown_test(void **state) {
UNUSED(state);
dns_test_end();
dst_lib_destroy();
return (0);
}
static int debug = 0;
static isc_result_t
add_mac(dst_context_t *tsigctx, isc_buffer_t *buf) {
dns_rdata_any_tsig_t tsig;
@ -111,7 +105,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
memset(&tsig, 0, sizeof(tsig));
CHECK(dns_compress_init(&cctx, -1, dt_mctx));
CHECK(dns_compress_init(&cctx, -1, mctx));
invalidate_ctx = true;
tsig.common.rdclass = dns_rdataclass_any;
@ -135,13 +129,13 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
CHECK(dst_context_adddata(tsigctx, &r));
CHECK(dst_key_sigsize(key->key, &sigsize));
tsig.signature = isc_mem_get(dt_mctx, sigsize);
tsig.signature = isc_mem_get(mctx, sigsize);
isc_buffer_init(&sigbuf, tsig.signature, sigsize);
CHECK(dst_context_sign(tsigctx, &sigbuf));
tsig.siglen = isc_buffer_usedlength(&sigbuf);
assert_int_equal(sigsize, tsig.siglen);
isc_buffer_allocate(dt_mctx, &dynbuf, 512);
isc_buffer_allocate(mctx, &dynbuf, 512);
CHECK(dns_rdata_fromstruct(&rdata, dns_rdataclass_any,
dns_rdatatype_tsig, &tsig, dynbuf));
dns_rdatalist_init(&rdatalist);
@ -162,7 +156,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
}
cleanup:
if (tsig.signature != NULL) {
isc_mem_put(dt_mctx, tsig.signature, sigsize);
isc_mem_put(mctx, tsig.signature, sigsize);
}
if (dynbuf != NULL) {
isc_buffer_free(&dynbuf);
@ -186,13 +180,13 @@ printmessage(dns_message_t *msg) {
}
do {
buf = isc_mem_get(dt_mctx, len);
buf = isc_mem_get(mctx, len);
isc_buffer_init(&b, buf, len);
result = dns_message_totext(msg, &dns_master_style_debug, 0,
&b);
if (result == ISC_R_NOSPACE) {
isc_mem_put(dt_mctx, buf, len);
isc_mem_put(mctx, buf, len);
len *= 2;
} else if (result == ISC_R_SUCCESS) {
printf("%.*s\n", (int)isc_buffer_usedlength(&b), buf);
@ -200,7 +194,7 @@ printmessage(dns_message_t *msg) {
} while (result == ISC_R_NOSPACE);
if (buf != NULL) {
isc_mem_put(dt_mctx, buf, len);
isc_mem_put(mctx, buf, len);
}
}
@ -211,7 +205,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
dns_compress_t cctx;
isc_result_t result;
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTRENDER, &msg);
dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg);
assert_non_null(msg);
msg->id = 50;
@ -238,7 +232,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
assert_int_equal(result, ISC_R_SUCCESS);
}
result = dns_compress_init(&cctx, -1, dt_mctx);
result = dns_compress_init(&cctx, -1, mctx);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_message_renderbegin(msg, &cctx, buf);
@ -258,7 +252,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
isc_buffer_free(tsigin);
}
result = dns_message_getquerytsig(msg, dt_mctx, tsigout);
result = dns_message_getquerytsig(msg, mctx, tsigout);
assert_int_equal(result, ISC_R_SUCCESS);
}
@ -272,8 +266,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
* and last messages contain TSIGs but the intermediate message doesn't
* correctly verifies.
*/
static void
tsig_tcp_test(void **state) {
ISC_RUN_TEST_IMPL(tsig_tcp) {
const dns_name_t *tsigowner = NULL;
dns_fixedname_t fkeyname;
dns_message_t *msg = NULL;
@ -297,11 +290,11 @@ tsig_tcp_test(void **state) {
result = dns_name_fromstring(keyname, "test", 0, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_tsigkeyring_create(dt_mctx, &ring);
result = dns_tsigkeyring_create(mctx, &ring);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_tsigkey_create(keyname, dns_tsig_hmacsha256_name, secret,
sizeof(secret), false, NULL, 0, 0, dt_mctx,
sizeof(secret), false, NULL, 0, 0, mctx,
ring, &key);
assert_int_equal(result, ISC_R_SUCCESS);
assert_non_null(key);
@ -309,21 +302,21 @@ tsig_tcp_test(void **state) {
/*
* Create request.
*/
isc_buffer_allocate(dt_mctx, &buf, 65535);
isc_buffer_allocate(mctx, &buf, 65535);
render(buf, 0, key, &tsigout, &querytsig, NULL);
isc_buffer_free(&buf);
/*
* Create response message 1.
*/
isc_buffer_allocate(dt_mctx, &buf, 65535);
isc_buffer_allocate(mctx, &buf, 65535);
render(buf, DNS_MESSAGEFLAG_QR, key, &querytsig, &tsigout, NULL);
assert_non_null(tsigout);
/*
* Process response message 1.
*/
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
result = dns_message_settsigkey(msg, key);
@ -347,7 +340,7 @@ tsig_tcp_test(void **state) {
*/
assert_non_null(dns_message_gettsig(msg, &tsigowner));
result = dns_message_getquerytsig(msg, dt_mctx, &tsigin);
result = dns_message_getquerytsig(msg, mctx, &tsigin);
assert_int_equal(result, ISC_R_SUCCESS);
tsigctx = msg->tsigctx;
@ -355,7 +348,7 @@ tsig_tcp_test(void **state) {
isc_buffer_free(&buf);
dns_message_detach(&msg);
result = dst_context_create(key->key, dt_mctx, DNS_LOGCATEGORY_DNSSEC,
result = dst_context_create(key->key, mctx, DNS_LOGCATEGORY_DNSSEC,
false, 0, &outctx);
assert_int_equal(result, ISC_R_SUCCESS);
assert_non_null(outctx);
@ -369,7 +362,7 @@ tsig_tcp_test(void **state) {
/*
* Create response message 2.
*/
isc_buffer_allocate(dt_mctx, &buf, 65535);
isc_buffer_allocate(mctx, &buf, 65535);
assert_int_equal(result, ISC_R_SUCCESS);
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
@ -377,7 +370,7 @@ tsig_tcp_test(void **state) {
/*
* Process response message 2.
*/
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
msg->tcp_continuation = 1;
@ -414,7 +407,7 @@ tsig_tcp_test(void **state) {
/*
* Create response message 3.
*/
isc_buffer_allocate(dt_mctx, &buf, 65535);
isc_buffer_allocate(mctx, &buf, 65535);
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
result = add_tsig(outctx, key, buf);
@ -423,7 +416,7 @@ tsig_tcp_test(void **state) {
/*
* Process response message 3.
*/
dns_message_create(dt_mctx, DNS_MESSAGE_INTENTPARSE, &msg);
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
assert_non_null(msg);
msg->tcp_continuation = 1;
@ -455,7 +448,7 @@ tsig_tcp_test(void **state) {
isc_buffer_free(&tsigin);
}
result = dns_message_getquerytsig(msg, dt_mctx, &tsigin);
result = dns_message_getquerytsig(msg, mctx, &tsigin);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_free(&buf);
@ -480,8 +473,7 @@ tsig_tcp_test(void **state) {
}
/* Tests the dns__tsig_algvalid function */
static void
algvalid_test(void **state) {
ISC_RUN_TEST_IMPL(algvalid) {
UNUSED(state);
assert_true(dns__tsig_algvalid(DST_ALG_HMACMD5));
@ -496,8 +488,7 @@ algvalid_test(void **state) {
}
/* Tests the dns__tsig_algfromname function */
static void
algfromname_test(void **state) {
ISC_RUN_TEST_IMPL(algfromname) {
UNUSED(state);
assert_int_equal(dns__tsig_algfromname(DNS_TSIG_HMACMD5_NAME),
@ -532,14 +523,13 @@ static void
test_name(const char *name_string, const dns_name_t *expected) {
dns_name_t name;
dns_name_init(&name, NULL);
assert_int_equal(dns_name_fromstring(&name, name_string, 0, dt_mctx),
assert_int_equal(dns_name_fromstring(&name, name_string, 0, mctx),
ISC_R_SUCCESS);
assert_ptr_equal(dns__tsig_algnamefromname(&name), expected);
dns_name_free(&name, dt_mctx);
dns_name_free(&name, mctx);
}
static void
algnamefromname_test(void **state) {
ISC_RUN_TEST_IMPL(algnamefromname) {
UNUSED(state);
/* test the standard algorithms */
@ -558,8 +548,7 @@ algnamefromname_test(void **state) {
}
/* Tests the dns__tsig_algallocated function */
static void
algallocated_test(void **state) {
ISC_RUN_TEST_IMPL(algallocated) {
UNUSED(state);
/* test the standard algorithms */
@ -577,29 +566,12 @@ algallocated_test(void **state) {
assert_true(dns__tsig_algallocated(dns_rootname));
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(tsig_tcp_test, _setup,
_teardown),
cmocka_unit_test(algvalid_test),
cmocka_unit_test(algfromname_test),
cmocka_unit_test_setup_teardown(algnamefromname_test, _setup,
_teardown),
cmocka_unit_test(algallocated_test),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(tsig_tcp, setup_test, teardown_test)
ISC_TEST_ENTRY(algvalid)
ISC_TEST_ENTRY(algfromname)
ISC_TEST_ENTRY_CUSTOM(algnamefromname, setup_test, teardown_test)
ISC_TEST_ENTRY(algallocated)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -32,38 +30,28 @@
#include <dns/update.h>
#include "dnstest.h"
#include <dns/test.h>
/*
* Fix the linking order problem for overridden isc_stdtime_get() by making
* everything local. This also allows static functions from update.c to be
* tested.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#undef CHECK
#include "../update.c"
#pragma GCC diagnostic pop
static int
_setup(void **state) {
isc_result_t result;
setup_test(void **state) {
UNUSED(state);
result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
setenv("TZ", "", 1);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
static uint32_t mystdtime;
static void
@ -83,8 +71,7 @@ isc_stdtime_get(isc_stdtime_t *now) {
}
/* simple increment by 1 */
static void
increment_test(void **state) {
ISC_RUN_TEST_IMPL(increment) {
uint32_t old = 50;
uint32_t serial;
@ -97,8 +84,7 @@ increment_test(void **state) {
}
/* increment past zero, 0xfffffffff -> 1 */
static void
increment_past_zero_test(void **state) {
ISC_RUN_TEST_IMPL(increment_past_zero) {
uint32_t old = 0xffffffffu;
uint32_t serial;
@ -111,8 +97,7 @@ increment_past_zero_test(void **state) {
}
/* past to unixtime */
static void
past_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(past_to_unix) {
uint32_t old;
uint32_t serial;
@ -128,8 +113,7 @@ past_to_unix_test(void **state) {
}
/* now to unixtime */
static void
now_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(now_to_unix) {
uint32_t old;
uint32_t serial;
@ -145,8 +129,7 @@ now_to_unix_test(void **state) {
}
/* future to unixtime */
static void
future_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(future_to_unix) {
uint32_t old;
uint32_t serial;
@ -162,8 +145,7 @@ future_to_unix_test(void **state) {
}
/* undefined plus 1 to unixtime */
static void
undefined_plus1_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(undefined_plus1_to_unix) {
uint32_t old;
uint32_t serial;
@ -180,8 +162,7 @@ undefined_plus1_to_unix_test(void **state) {
}
/* undefined minus 1 to unixtime */
static void
undefined_minus1_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(undefined_minus1_to_unix) {
uint32_t old;
uint32_t serial;
@ -198,8 +179,7 @@ undefined_minus1_to_unix_test(void **state) {
}
/* undefined to unixtime */
static void
undefined_to_unix_test(void **state) {
ISC_RUN_TEST_IMPL(undefined_to_unix) {
uint32_t old;
uint32_t serial;
@ -215,8 +195,7 @@ undefined_to_unix_test(void **state) {
}
/* handle unixtime being zero */
static void
unixtime_zero_test(void **state) {
ISC_RUN_TEST_IMPL(unixtime_zero) {
uint32_t old;
uint32_t serial;
@ -232,8 +211,7 @@ unixtime_zero_test(void **state) {
}
/* past to date */
static void
past_to_date_test(void **state) {
ISC_RUN_TEST_IMPL(past_to_date) {
uint32_t old, serial;
dns_updatemethod_t used = dns_updatemethod_none;
@ -251,8 +229,7 @@ past_to_date_test(void **state) {
}
/* now to date */
static void
now_to_date_test(void **state) {
ISC_RUN_TEST_IMPL(now_to_date) {
uint32_t old;
uint32_t serial;
dns_updatemethod_t used = dns_updatemethod_none;
@ -287,8 +264,7 @@ now_to_date_test(void **state) {
}
/* future to date */
static void
future_to_date_test(void **state) {
ISC_RUN_TEST_IMPL(future_to_date) {
uint32_t old;
uint32_t serial;
dns_updatemethod_t used = dns_updatemethod_none;
@ -313,46 +289,19 @@ future_to_date_test(void **state) {
assert_int_equal(dns_updatemethod_increment, used);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(increment_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(increment_past_zero_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(past_to_unix_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(now_to_unix_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(future_to_unix_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(undefined_to_unix_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(undefined_plus1_to_unix_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(undefined_minus1_to_unix_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(unixtime_zero_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(past_to_date_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(now_to_date_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(future_to_date_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(increment, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(increment_past_zero, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(past_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(now_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(future_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(undefined_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(undefined_plus1_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(undefined_minus1_to_unix, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(unixtime_zero, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(past_to_date, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(now_to_date, setup_test, NULL)
ISC_TEST_ENTRY_CUSTOM(future_to_date, setup_test, NULL)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -33,38 +31,16 @@
#include <dns/view.h>
#include <dns/zone.h>
#include "dnstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
return (0);
}
#include <dns/test.h>
/* create zone manager */
static void
zonemgr_create(void **state) {
ISC_RUN_TEST_IMPL(dns_zonemgr_create) {
dns_zonemgr_t *myzonemgr = NULL;
isc_result_t result;
UNUSED(state);
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
@ -74,15 +50,14 @@ zonemgr_create(void **state) {
}
/* manage and release a zone */
static void
zonemgr_managezone(void **state) {
ISC_RUN_TEST_IMPL(dns_zonemgr_managezone) {
dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL;
isc_result_t result;
UNUSED(state);
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
@ -108,15 +83,14 @@ zonemgr_managezone(void **state) {
}
/* create and release a zone */
static void
zonemgr_createzone(void **state) {
ISC_RUN_TEST_IMPL(dns_zonemgr_createzone) {
dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL;
isc_result_t result;
UNUSED(state);
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
@ -134,8 +108,7 @@ zonemgr_createzone(void **state) {
}
/* manage and release a zone */
static void
zonemgr_unreachable(void **state) {
ISC_RUN_TEST_IMPL(dns_zonemgr_unreachable) {
dns_zonemgr_t *myzonemgr = NULL;
dns_zone_t *zone = NULL;
isc_sockaddr_t addr1, addr2;
@ -147,7 +120,7 @@ zonemgr_unreachable(void **state) {
TIME_NOW(&now);
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
@ -217,30 +190,14 @@ zonemgr_unreachable(void **state) {
* - dns_zonemgr_getserialqueryrate
*/
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(zonemgr_create, _setup,
_teardown),
cmocka_unit_test_setup_teardown(zonemgr_managezone, _setup,
_teardown),
cmocka_unit_test_setup_teardown(zonemgr_createzone, _setup,
_teardown),
cmocka_unit_test_setup_teardown(zonemgr_unreachable, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_create, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_managezone, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_createzone, setup_managers, teardown_managers)
ISC_TEST_ENTRY_CUSTOM(dns_zonemgr_unreachable, setup_managers,
teardown_managers)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -39,35 +37,30 @@
#include <dns/zone.h>
#include <dns/zt.h>
#include "dnstest.h"
struct args {
void *arg1;
void *arg2;
bool arg3;
};
#include <dns/test.h>
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = dns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
isc_app_start();
setup_managers(state);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
dns_test_end();
teardown_managers(state);
isc_app_finish();
return (0);
}
struct args {
void *arg1;
void *arg2;
bool arg3;
};
static isc_result_t
count_zone(dns_zone_t *zone, void *uap) {
int *nzones = (int *)uap;
@ -122,8 +115,7 @@ start_zone_asyncload(isc_task_t *task, isc_event_t *event) {
}
/* apply a function to a zone table */
static void
apply(void **state) {
ISC_RUN_TEST_IMPL(dns_zt_apply) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_view_t *view = NULL;
@ -157,8 +149,7 @@ apply(void **state) {
}
/* asynchronous zone load */
static void
asyncload_zone(void **state) {
ISC_RUN_TEST_IMPL(dns_zt_asyncload_zone) {
isc_result_t result;
int n;
dns_zone_t *zone = NULL;
@ -202,7 +193,7 @@ asyncload_zone(void **state) {
args.arg1 = zone;
args.arg2 = &done;
args.arg3 = false;
isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args);
isc_app_onrun(mctx, maintask, start_zone_asyncload, &args);
isc_app_run();
while (dns__zone_loadpending(zone) && i++ < 5000) {
@ -224,7 +215,7 @@ asyncload_zone(void **state) {
args.arg1 = zone;
args.arg2 = &done;
args.arg3 = true;
isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args);
isc_app_onrun(mctx, maintask, start_zone_asyncload, &args);
isc_app_run();
@ -241,7 +232,7 @@ asyncload_zone(void **state) {
args.arg1 = zone;
args.arg2 = &done;
args.arg3 = false;
isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args);
isc_app_onrun(mctx, maintask, start_zone_asyncload, &args);
isc_app_run();
@ -266,8 +257,7 @@ asyncload_zone(void **state) {
}
/* asynchronous zone table load */
static void
asyncload_zt(void **state) {
ISC_RUN_TEST_IMPL(dns_zt_asyncload_zt) {
isc_result_t result;
dns_zone_t *zone1 = NULL, *zone2 = NULL, *zone3 = NULL;
dns_view_t *view;
@ -316,7 +306,7 @@ asyncload_zt(void **state) {
args.arg1 = zt;
args.arg2 = &done;
isc_app_onrun(dt_mctx, maintask, start_zt_asyncload, &args);
isc_app_onrun(mctx, maintask, start_zt_asyncload, &args);
isc_app_run();
while (!atomic_load(&done) && i++ < 5000) {
@ -350,27 +340,12 @@ asyncload_zt(void **state) {
dns_view_detach(&view);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(apply, _setup, _teardown),
cmocka_unit_test_setup_teardown(asyncload_zone, _setup,
_teardown),
cmocka_unit_test_setup_teardown(asyncload_zt, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(dns_zt_apply, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_zt_asyncload_zone, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(dns_zt_asyncload_zt, _setup, _teardown)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

119
lib/isc/include/isc/test.h Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*! \file */
#include <inttypes.h>
#include <stdbool.h>
#include <uv.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netmgr.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include "../netmgr_p.h"
#include "../task_p.h"
#include "../timer_p.h"
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
extern isc_mem_t *mctx;
extern isc_nm_t *netmgr;
extern isc_taskmgr_t *taskmgr;
extern isc_timermgr_t *timermgr;
extern unsigned int workers;
extern isc_task_t *maintask;
#define isc_test_nap(ms) uv_sleep(ms)
int
setup_managers(void **state);
int
teardown_managers(void **state);
#ifndef TESTS_DIR
#define TESTS_DIR "./"
#endif
/* clang-format off */
/* Copied from cmocka */
#define ISC_TEST_ENTRY(name) \
{ #name, run_test_##name, NULL, NULL, NULL },
#define ISC_TEST_ENTRY_SETUP(name) \
{ #name, run_test_##name, setup_test_##name, NULL, NULL },
#define ISC_TEST_ENTRY_TEARDOWN(name) \
{ #name, run_test_##name, NULL, teardown_test_##name, NULL },
#define ISC_TEST_ENTRY_SETUP_TEARDOWN(name) \
{ #name, run_test_##name, setup_test_##name, teardown_test_##name, NULL },
#define ISC_TEST_ENTRY_CUSTOM(name, setup, teardown) \
{ #name, run_test_##name, setup, teardown, NULL },
/* clang-format on */
#define ISC_SETUP_TEST_DECLARE(name) \
int setup_test_##name(void **state __attribute__((unused)));
#define ISC_RUN_TEST_DECLARE(name) \
void run_test_##name(void **state __attribute__((unused)));
#define ISC_TEARDOWN_TEST_DECLARE(name) \
int teardown_test_##name(void **state __attribute__((unused)))
#define ISC_SETUP_TEST_IMPL(name) \
int setup_test_##name(void **state __attribute__((unused))); \
int setup_test_##name(void **state __attribute__((unused)))
#define ISC_RUN_TEST_IMPL(name) \
void run_test_##name(void **state __attribute__((unused))); \
void run_test_##name(void **state __attribute__((unused)))
#define ISC_TEARDOWN_TEST_IMPL(name) \
int teardown_test_##name(void **state __attribute__((unused))); \
int teardown_test_##name(void **state __attribute__((unused)))
#define ISC_TEST_LIST_START const struct CMUnitTest tests[] = {
#define ISC_TEST_LIST_END \
} \
;
#define ISC_TEST_MAIN ISC_TEST_MAIN_CUSTOM(NULL, NULL)
#define ISC_TEST_MAIN_CUSTOM(setup, teardown) \
int main(void) { \
int r; \
\
signal(SIGPIPE, SIG_IGN); \
\
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \
isc_mem_create(&mctx); \
\
r = cmocka_run_group_tests(tests, setup, teardown); \
\
isc_mem_destroy(&mctx); \
\
return (r); \
}

87
lib/isc/test.c Normal file
View File

@ -0,0 +1,87 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <inttypes.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/managers.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include "../netmgr_p.h"
#include "../task_p.h"
#include "../timer_p.h"
#include <isc/test.h>
isc_mem_t *mctx = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_timermgr_t *timermgr = NULL;
isc_nm_t *netmgr = NULL;
unsigned int workers = 0;
isc_task_t *maintask = NULL;
int
setup_managers(void **state) {
isc_result_t result;
UNUSED(state);
REQUIRE(mctx != NULL);
if (workers == 0) {
char *env_workers = getenv("ISC_TASK_WORKERS");
if (env_workers != NULL) {
workers = atoi(env_workers);
} else {
workers = isc_os_ncpus();
}
INSIST(workers > 0);
}
result = isc_managers_create(mctx, workers, 0, &netmgr, &taskmgr,
&timermgr);
if (result != ISC_R_SUCCESS) {
return (-1);
}
result = isc_task_create(taskmgr, 0, &maintask, 0);
if (result != ISC_R_SUCCESS) {
return (-1);
}
isc_taskmgr_setexcltask(taskmgr, maintask);
return (0);
}
int
teardown_managers(void **state) {
UNUSED(state);
isc_task_detach(&maintask);
isc_managers_destroy(&netmgr, &taskmgr, &timermgr);
return (0);
}

View File

@ -2,16 +2,18 @@ include $(top_srcdir)/Makefile.top
AM_CPPFLAGS += \
$(LIBISC_CFLAGS) \
$(LIBUV_CFLAGS) \
-I..
LDADD += \
libisctest.la \
$(LIBISC_LIBS)
$(LIBISC_LIBS) \
$(LIBUV_LIBS)
check_LTLIBRARIES = libisctest.la
libisctest_la_SOURCES = \
isctest.c \
isctest.h \
libisctest_la_SOURCES = \
../../isc/test.c \
../../isc/include/isc/test.h \
uv_wrap.h
check_PROGRAMS = \
@ -51,14 +53,12 @@ check_PROGRAMS += \
doh_test_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(LIBUV_CFLAGS) \
$(LIBNGHTTP2_CFLAGS) \
$(OPENSSL_CFLAGS)
doh_test_LDADD = \
$(LDADD) \
$(LIBNGHTTP2_LIBS) \
$(LIBUV_LIBS)
$(LIBNGHTTP2_LIBS)
endif HAVE_LIBNGHTTP2
hmac_test_CPPFLAGS = \
@ -81,14 +81,22 @@ random_test_LDADD = \
$(LDADD) \
-lm
netmgr_test_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(LIBUV_CFLAGS) \
$(OPENSSL_CFLAGS)
task_test_CPPFLAGS = \
$(AM_CPPFLAGS)
task_test_LDADD = \
$(LDADD)
if HAVE_LIBXML2
task_test_CPPFLAGS += $(LIBXML2_CFLAGS)
task_test_LDADD += $(LIBXML2_LIBS)
endif HAVE_LIBXML2
if HAVE_JSON_C
task_test_CPPFLAGS += $(JSON_C_CFLAGS)
task_test_LDADD += $(JSON_C_LIBS)
endif HAVE_JSON_C
netmgr_test_LDADD = \
$(LDADD) \
$(LIBUV_LIBS)
EXTRA_DIST = testdata

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -30,6 +29,8 @@
#include <isc/string.h>
#include <isc/util.h>
#include <isc/test.h>
/*
* Test data from NIST KAT
*/
@ -77,8 +78,7 @@ typedef struct aes_testcase {
} aes_testcase_t;
/* AES 128 test vectors */
static void
isc_aes128_test(void **state) {
ISC_RUN_TEST_IMPL(isc_aes128_test) {
aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt128 #3) */
{ "00000000000000000000000000000000",
"F0000000000000000000000000000000",
@ -124,8 +124,7 @@ isc_aes128_test(void **state) {
}
/* AES 192 test vectors */
static void
isc_aes192_test(void **state) {
ISC_RUN_TEST_IMPL(isc_aes192_test) {
aes_testcase_t testcases[] = {
/* Test 1 (KAT ECBVarTxt192 #3) */
{ "000000000000000000000000000000000000000000000000",
@ -156,8 +155,6 @@ isc_aes192_test(void **state) {
aes_testcase_t *testcase = testcases;
UNUSED(state);
while (testcase->key != NULL) {
len = fromhexstr(testcase->key, key);
assert_int_equal(len, ISC_AES192_KEYLENGTH);
@ -172,8 +169,7 @@ isc_aes192_test(void **state) {
}
/* AES 256 test vectors */
static void
isc_aes256_test(void **state) {
ISC_RUN_TEST_IMPL(isc_aes256_test) {
aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt256 #3) */
{ "00000000000000000000000000000000"
"00000000000000000000000000000000",
@ -224,25 +220,12 @@ isc_aes256_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_aes128_test),
cmocka_unit_test(isc_aes192_test),
cmocka_unit_test(isc_aes256_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_aes128_test)
ISC_TEST_ENTRY(isc_aes192_test)
ISC_TEST_ENTRY(isc_aes256_test)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <fcntl.h>
#include <limits.h>
#include <sched.h> /* IWYU pragma: keep */
@ -34,39 +32,17 @@
#include <isc/types.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* reserve space in dynamic buffers */
static void
isc_buffer_reserve_test(void **state) {
ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
isc_result_t result;
isc_buffer_t *b;
UNUSED(state);
b = NULL;
isc_buffer_allocate(test_mctx, &b, 1024);
isc_buffer_allocate(mctx, &b, 1024);
assert_int_equal(b->length, 1024);
/*
@ -125,8 +101,7 @@ isc_buffer_reserve_test(void **state) {
}
/* dynamic buffer automatic reallocation */
static void
isc_buffer_dynamic_test(void **state) {
ISC_RUN_TEST_IMPL(isc_buffer_dynamic) {
isc_buffer_t *b;
size_t last_length = 10;
int i;
@ -134,7 +109,7 @@ isc_buffer_dynamic_test(void **state) {
UNUSED(state);
b = NULL;
isc_buffer_allocate(test_mctx, &b, last_length);
isc_buffer_allocate(mctx, &b, last_length);
assert_non_null(b);
assert_int_equal(b->length, last_length);
@ -178,8 +153,7 @@ isc_buffer_dynamic_test(void **state) {
}
/* copy a region into a buffer */
static void
isc_buffer_copyregion_test(void **state) {
ISC_RUN_TEST_IMPL(isc_buffer_copyregion) {
unsigned char data[] = { 0x11, 0x22, 0x33, 0x44 };
isc_buffer_t *b = NULL;
isc_result_t result;
@ -191,7 +165,7 @@ isc_buffer_copyregion_test(void **state) {
UNUSED(state);
isc_buffer_allocate(test_mctx, &b, sizeof(data));
isc_buffer_allocate(mctx, &b, sizeof(data));
/*
* Fill originally allocated buffer space.
@ -216,8 +190,7 @@ isc_buffer_copyregion_test(void **state) {
}
/* sprintf() into a buffer */
static void
isc_buffer_printf_test(void **state) {
ISC_RUN_TEST_IMPL(isc_buffer_printf) {
unsigned int used, prev_used;
const char *empty_fmt;
isc_result_t result;
@ -230,7 +203,7 @@ isc_buffer_printf_test(void **state) {
* Prepare a buffer with auto-reallocation enabled.
*/
b = NULL;
isc_buffer_allocate(test_mctx, &b, 0);
isc_buffer_allocate(mctx, &b, 0);
isc_buffer_setautorealloc(b, true);
/*
@ -322,30 +295,13 @@ isc_buffer_printf_test(void **state) {
assert_int_equal(used, 7);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_buffer_reserve_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_buffer_dynamic_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_buffer_copyregion_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(isc_buffer_printf_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_buffer_reserve)
ISC_TEST_ENTRY(isc_buffer_dynamic)
ISC_TEST_ENTRY(isc_buffer_copyregion)
ISC_TEST_ENTRY(isc_buffer_printf)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -27,39 +25,17 @@
#include <isc/result.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* test isc_counter object */
static void
isc_counter_test(void **state) {
ISC_RUN_TEST_IMPL(isc_counter) {
isc_result_t result;
isc_counter_t *counter = NULL;
int i;
UNUSED(state);
result = isc_counter_create(test_mctx, 0, &counter);
result = isc_counter_create(mctx, 0, &counter);
assert_int_equal(result, ISC_R_SUCCESS);
for (i = 0; i < 10; i++) {
@ -82,24 +58,10 @@ isc_counter_test(void **state) {
isc_counter_detach(&counter);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_counter_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_counter)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -13,8 +13,7 @@
/* ! \file */
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -29,21 +28,13 @@
#include <isc/result.h>
#include <isc/util.h>
#include <isc/test.h>
#define TEST_INPUT(x) (x), sizeof(x) - 1
typedef struct hash_testcase {
const char *input;
size_t input_len;
const char *result;
int repeats;
} hash_testcase_t;
static void
isc_crc64_init_test(void **state) {
ISC_RUN_TEST_IMPL(isc_crc64_init) {
uint64_t crc;
UNUSED(state);
isc_crc64_init(&crc);
assert_int_equal(crc, 0xffffffffffffffffUL);
}
@ -68,10 +59,7 @@ _crc64(const char *buf, size_t buflen, const char *result, const int repeats) {
}
/* 64-bit cyclic redundancy check */
static void
isc_crc64_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(isc_crc64) {
_crc64(TEST_INPUT(""), "0000000000000000", 1);
_crc64(TEST_INPUT("a"), "CE73F427ACC0A99A", 1);
_crc64(TEST_INPUT("abc"), "048B813AF9F49702", 1);
@ -85,24 +73,11 @@ isc_crc64_test(void **state) {
"81E5EB73C8E7874A", 1);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_crc64_init_test),
cmocka_unit_test(isc_crc64_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_crc64_init)
ISC_TEST_ENTRY(isc_crc64)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,8 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <errno.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -27,6 +26,8 @@
#include <isc/result.h>
#include <isc/util.h>
#include <isc/test.h>
typedef struct {
int err;
isc_result_t result;
@ -87,13 +88,10 @@ testpair_t testpair[] = { { EPERM, ISC_R_NOPERM },
{ 0, ISC_R_UNEXPECTED } };
/* convert errno to ISC result */
static void
isc_errno_toresult_test(void **state) {
ISC_RUN_TEST_IMPL(isc_errno_toresult) {
isc_result_t result, expect;
size_t i;
UNUSED(state);
for (i = 0; i < sizeof(testpair) / sizeof(testpair[0]); i++) {
result = isc_errno_toresult(testpair[i].err);
expect = testpair[i].result;
@ -101,23 +99,10 @@ isc_errno_toresult_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_errno_toresult_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_errno_toresult)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,9 +11,8 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <fcntl.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -28,6 +27,8 @@
#include <isc/result.h>
#include <isc/util.h>
#include <isc/test.h>
#define NAME "internal"
#define SHA "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f"
#define TRUNC_SHA "3bed2cb3a3acf7b6"
@ -52,8 +53,7 @@ touch(const char *filename) {
}
/* test sanitized filenames */
static void
isc_file_sanitize_test(void **state) {
ISC_RUN_TEST_IMPL(isc_file_sanitize) {
isc_result_t result;
char buf[1024];
@ -88,8 +88,7 @@ isc_file_sanitize_test(void **state) {
}
/* test filename templates */
static void
isc_file_template_test(void **state) {
ISC_RUN_TEST_IMPL(isc_file_template) {
isc_result_t result;
char buf[1024];
@ -131,24 +130,11 @@ isc_file_template_test(void **state) {
assert_string_equal(buf, "file-XXXXXXXX");
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_file_sanitize_test),
cmocka_unit_test(isc_file_template_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_file_sanitize)
ISC_TEST_ENTRY(isc_file_template)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,9 +11,8 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -33,11 +32,10 @@
#include <isc/string.h>
#include <isc/util.h>
#define TEST_INPUT(x) (x), sizeof(x) - 1
#include <isc/test.h>
/*Hash function test */
static void
isc_hash_function_test(void **state) {
/* Hash function test */
ISC_RUN_TEST_IMPL(isc_hash_function) {
unsigned int h1;
unsigned int h2;
@ -69,8 +67,7 @@ isc_hash_function_test(void **state) {
}
/* Hash function initializer test */
static void
isc_hash_initializer_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hash_initializer) {
unsigned int h1;
unsigned int h2;
@ -89,24 +86,11 @@ isc_hash_initializer_test(void **state) {
assert_int_equal(h1, h2);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_hash_function_test),
cmocka_unit_test(isc_hash_initializer_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_hash_function)
ISC_TEST_ENTRY(isc_hash_initializer)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -13,8 +13,6 @@
/* ! \file */
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,28 +27,7 @@
#include <isc/mem.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
struct e {
unsigned int value;
@ -73,14 +50,13 @@ idx(void *p, unsigned int i) {
}
/* test isc_heap_delete() */
static void
isc_heap_delete_test(void **state) {
ISC_RUN_TEST_IMPL(isc_heap_delete) {
isc_heap_t *heap = NULL;
struct e e1 = { 100, 0 };
UNUSED(state);
isc_heap_create(test_mctx, compare, idx, 0, &heap);
isc_heap_create(mctx, compare, idx, 0, &heap);
assert_non_null(heap);
isc_heap_insert(heap, &e1);
@ -93,23 +69,10 @@ isc_heap_delete_test(void **state) {
assert_null(heap);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_heap_delete_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_ENTRY(isc_heap_delete)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -13,8 +13,6 @@
/* ! \file */
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -33,6 +31,8 @@
#include "../hmac.c"
#include <isc/test.h>
#define TEST_INPUT(x) (x), sizeof(x) - 1
static int
@ -65,8 +65,7 @@ _reset(void **state) {
return (0);
}
static void
isc_hmac_new_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_new) {
UNUSED(state);
isc_hmac_t *hmac = isc_hmac_new();
@ -74,8 +73,7 @@ isc_hmac_new_test(void **state) {
isc_hmac_free(hmac); /* Cleanup */
}
static void
isc_hmac_free_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_free) {
UNUSED(state);
isc_hmac_t *hmac = isc_hmac_new();
@ -87,13 +85,13 @@ isc_hmac_free_test(void **state) {
static void
isc_hmac_test(isc_hmac_t *hmac, const void *key, size_t keylen,
const isc_md_type_t *type, const char *buf, size_t buflen,
const char *result, const int repeats) {
const char *result, const size_t repeats) {
isc_result_t res;
assert_non_null(hmac);
assert_int_equal(isc_hmac_init(hmac, key, keylen, type), ISC_R_SUCCESS);
int i;
for (i = 0; i < repeats; i++) {
for (size_t i = 0; i < repeats; i++) {
assert_int_equal(isc_hmac_update(hmac,
(const unsigned char *)buf,
buflen),
@ -110,14 +108,15 @@ isc_hmac_test(isc_hmac_t *hmac, const void *key, size_t keylen,
isc_buffer_t b;
isc_buffer_init(&b, hexdigest, sizeof(hexdigest));
assert_return_code(isc_hex_totext(&r, 0, "", &b), ISC_R_SUCCESS);
res = isc_hex_totext(&r, 0, "", &b);
assert_return_code(res, ISC_R_SUCCESS);
assert_memory_equal(hexdigest, result, (result ? strlen(result) : 0));
assert_int_equal(isc_hmac_reset(hmac), ISC_R_SUCCESS);
}
static void
isc_hmac_init_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_init) {
isc_hmac_t *hmac = *state;
assert_non_null(hmac);
@ -152,8 +151,7 @@ isc_hmac_init_test(void **state) {
assert_int_equal(isc_hmac_reset(hmac), ISC_R_SUCCESS);
}
static void
isc_hmac_update_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_update) {
isc_hmac_t *hmac = *state;
assert_non_null(hmac);
@ -165,8 +163,7 @@ isc_hmac_update_test(void **state) {
ISC_R_SUCCESS);
}
static void
isc_hmac_reset_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_reset) {
isc_hmac_t *hmac = *state;
#if 0
unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused));
@ -194,8 +191,7 @@ isc_hmac_reset_test(void **state) {
#endif /* if 0 */
}
static void
isc_hmac_final_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_final) {
isc_hmac_t *hmac = *state;
assert_non_null(hmac);
@ -213,8 +209,7 @@ isc_hmac_final_test(void **state) {
expect_assert_failure(isc_hmac_final(hmac, digest, NULL));
}
static void
isc_hmac_md5_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_md5) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -311,8 +306,7 @@ isc_hmac_md5_test(void **state) {
#endif /* if 0 */
}
static void
isc_hmac_sha1_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_sha1) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -395,8 +389,7 @@ isc_hmac_sha1_test(void **state) {
"E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1);
}
static void
isc_hmac_sha224_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_sha224) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -519,8 +512,7 @@ isc_hmac_sha224_test(void **state) {
1);
}
static void
isc_hmac_sha256_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_sha256) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -643,8 +635,7 @@ isc_hmac_sha256_test(void **state) {
1);
}
static void
isc_hmac_sha384_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_sha384) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -773,8 +764,7 @@ isc_hmac_sha384_test(void **state) {
1);
}
static void
isc_hmac_sha512_test(void **state) {
ISC_RUN_TEST_IMPL(isc_hmac_sha512) {
isc_hmac_t *hmac = *state;
/* Test 0 */
@ -904,47 +894,25 @@ isc_hmac_sha512_test(void **state) {
1);
}
int
main(void) {
const struct CMUnitTest tests[] = {
/* isc_hmac_new() */
cmocka_unit_test(isc_hmac_new_test),
ISC_TEST_LIST_START
/* isc_hmac_init() */
cmocka_unit_test_setup_teardown(isc_hmac_init_test, _reset,
_reset),
ISC_TEST_ENTRY(isc_hmac_new)
ISC_TEST_ENTRY_CUSTOM(isc_hmac_init, _reset, _reset)
/* isc_hmac_reset() */
cmocka_unit_test_setup_teardown(isc_hmac_reset_test, _reset,
_reset),
ISC_TEST_ENTRY_CUSTOM(isc_hmac_reset, _reset, _reset)
/* isc_hmac_init() -> isc_hmac_update() -> isc_hmac_final() */
cmocka_unit_test(isc_hmac_md5_test),
cmocka_unit_test(isc_hmac_sha1_test),
cmocka_unit_test(isc_hmac_sha224_test),
cmocka_unit_test(isc_hmac_sha256_test),
cmocka_unit_test(isc_hmac_sha384_test),
cmocka_unit_test(isc_hmac_sha512_test),
ISC_TEST_ENTRY(isc_hmac_md5)
ISC_TEST_ENTRY(isc_hmac_sha1)
ISC_TEST_ENTRY(isc_hmac_sha224)
ISC_TEST_ENTRY(isc_hmac_sha256)
ISC_TEST_ENTRY(isc_hmac_sha384)
ISC_TEST_ENTRY(isc_hmac_sha512)
cmocka_unit_test_setup_teardown(isc_hmac_update_test, _reset,
_reset),
cmocka_unit_test_setup_teardown(isc_hmac_final_test, _reset,
_reset),
ISC_TEST_ENTRY_CUSTOM(isc_hmac_update, _reset, _reset)
ISC_TEST_ENTRY_CUSTOM(isc_hmac_final, _reset, _reset)
cmocka_unit_test(isc_hmac_free_test),
};
ISC_TEST_ENTRY(isc_hmac_free)
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN_CUSTOM(_setup, _teardown)

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -32,32 +30,13 @@
#include <isc/string.h>
#include <isc/util.h>
#include "isctest.h"
#include <isc/test.h>
/* INCLUDE LAST */
#define mctx __mctx
#include "../ht.c"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#undef mctx
static void
test_ht_full(uint8_t init_bits, uint8_t finish_bits, uintptr_t count) {
@ -65,7 +44,7 @@ test_ht_full(uint8_t init_bits, uint8_t finish_bits, uintptr_t count) {
isc_result_t result;
uintptr_t i;
isc_ht_init(&ht, test_mctx, init_bits, ISC_HT_CASE_SENSITIVE);
isc_ht_init(&ht, mctx, init_bits, ISC_HT_CASE_SENSITIVE);
assert_non_null(ht);
for (i = 1; i < count; i++) {
@ -212,7 +191,7 @@ test_ht_iterator(void) {
unsigned char key[16];
size_t tksize;
isc_ht_init(&ht, test_mctx, HT_MIN_BITS, ISC_HT_CASE_SENSITIVE);
isc_ht_init(&ht, mctx, HT_MIN_BITS, ISC_HT_CASE_SENSITIVE);
assert_non_null(ht);
for (i = 1; i <= count; i++) {
/*
@ -318,53 +297,35 @@ test_ht_iterator(void) {
}
/* 24 bit, 200K elements test, no rehashing */
static void
isc_ht_24(void **state) {
ISC_RUN_TEST_IMPL(isc_ht_24) {
UNUSED(state);
test_ht_full(24, 24, 200000);
}
/* 15 bit, 45K elements test, full rehashing */
static void
isc_ht_15(void **state) {
ISC_RUN_TEST_IMPL(isc_ht_15) {
UNUSED(state);
test_ht_full(1, 15, 48000);
}
/* 8 bit, 20k elements test, partial rehashing */
static void
isc_ht_8(void **state) {
ISC_RUN_TEST_IMPL(isc_ht_8) {
UNUSED(state);
test_ht_full(8, 14, 20000);
}
/* test hashtable iterator */
static void
isc_ht_iterator_test(void **state) {
ISC_RUN_TEST_IMPL(isc_ht_iterator) {
UNUSED(state);
test_ht_iterator();
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_ht_24),
cmocka_unit_test(isc_ht_15),
cmocka_unit_test(isc_ht_8),
cmocka_unit_test(isc_ht_iterator_test),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(isc_ht_24)
ISC_TEST_ENTRY(isc_ht_15)
ISC_TEST_ENTRY(isc_ht_8)
ISC_TEST_ENTRY(isc_ht_iterator)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -1,163 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include "isctest.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/managers.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
isc_mem_t *test_mctx = NULL;
isc_log_t *test_lctx = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_timermgr_t *timermgr = NULL;
isc_nm_t *netmgr = 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.
*/
static isc_logcategory_t categories[] = { { "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 } };
static void
cleanup_managers(void) {
if (maintask != NULL) {
isc_task_detach(&maintask);
}
isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
taskmgr == NULL ? NULL : &taskmgr,
timermgr == NULL ? NULL : &timermgr);
}
static isc_result_t
create_managers(unsigned int workers) {
isc_result_t result;
char *p;
if (workers == 0) {
workers = isc_os_ncpus();
}
p = getenv("ISC_TASK_WORKERS");
if (p != NULL) {
workers = atoi(p);
}
INSIST(workers != 0);
isc_managers_create(test_mctx, workers, 0, &netmgr, &taskmgr,
&timermgr);
CHECK(isc_task_create(taskmgr, 0, &maintask, 0));
isc_taskmgr_setexcltask(taskmgr, maintask);
return (ISC_R_SUCCESS);
cleanup:
cleanup_managers();
return (result);
}
isc_result_t
isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers) {
isc_result_t result;
INSIST(!test_running);
test_running = true;
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
INSIST(test_mctx == NULL);
isc_mem_create(&test_mctx);
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
INSIST(test_lctx == NULL);
isc_log_create(test_mctx, &test_lctx, &logconfig);
isc_log_registercategories(test_lctx, categories);
isc_log_setcontext(test_lctx);
destination.file.stream = logfile;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
}
ncpus = isc_os_ncpus();
if (start_managers) {
CHECK(create_managers(workers));
}
return (ISC_R_SUCCESS);
cleanup:
isc_test_end();
return (result);
}
void
isc_test_end(void) {
if (maintask != NULL) {
isc_task_detach(&maintask);
}
cleanup_managers();
if (test_lctx != NULL) {
isc_log_destroy(&test_lctx);
}
if (test_mctx != NULL) {
isc_mem_destroy(&test_mctx);
}
test_running = false;
}
/*
* Sleep for 'usec' microseconds.
*/
void
isc_test_nap(uint32_t usec) {
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
}

View File

@ -1,64 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*! \file */
#include <inttypes.h>
#include <stdbool.h>
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netmgr.h>
#include <isc/print.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 *test_mctx;
extern isc_log_t *test_lctx;
extern isc_taskmgr_t *taskmgr;
extern isc_timermgr_t *timermgr;
extern isc_nm_t *netmgr;
extern int ncpus;
isc_result_t
isc_test_begin(FILE *logfile, bool start_managers, unsigned int workers);
/*%<
* Begin test, logging to 'logfile' or default if not specified.
*
* If 'start_managers' is set, start a task manager, timer manager,
* and socket manager.
*
* If 'workers' is zero, use the number of CPUs on the system as a default;
* otherwise, set up the task manager with the specified number of worker
* threads. The environment variable ISC_TASK_WORKERS overrides this value.
*/
void
isc_test_end(void);
void
isc_test_nap(uint32_t usec);

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,36 +27,12 @@
#include <isc/mem.h>
#include <isc/util.h>
#include "isctest.h"
#include <isc/test.h>
#define AS_STR(x) (x).value.as_textregion.base
static bool debug = false;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
/* check handling of 0xff */
static void
lex_0xff(void **state) {
ISC_RUN_TEST_IMPL(lex_0xff) {
isc_result_t result;
isc_lex_t *lex = NULL;
isc_buffer_t death_buf;
@ -68,7 +42,7 @@ lex_0xff(void **state) {
UNUSED(state);
result = isc_lex_create(test_mctx, 1024, &lex);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_init(&death_buf, &death[0], sizeof(death));
@ -84,8 +58,7 @@ lex_0xff(void **state) {
}
/* check setting of source line */
static void
lex_setline(void **state) {
ISC_RUN_TEST_IMPL(lex_setline) {
isc_result_t result;
isc_lex_t *lex = NULL;
unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer";
@ -96,7 +69,7 @@ lex_setline(void **state) {
UNUSED(state);
result = isc_lex_create(test_mctx, 1024, &lex);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_init(&buf, &text[0], sizeof(text));
@ -209,8 +182,7 @@ static struct {
/*%
* string
*/
static void
lex_string(void **state) {
ISC_RUN_TEST_IMPL(lex_string) {
isc_buffer_t buf;
isc_lex_t *lex = NULL;
isc_result_t result;
@ -220,7 +192,7 @@ lex_string(void **state) {
UNUSED(state);
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
result = isc_lex_create(test_mctx, 1024, &lex);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_constinit(&buf, parse_tests[i].text,
@ -236,12 +208,6 @@ lex_string(void **state) {
memset(&token, 0, sizeof(token));
result = isc_lex_getmastertoken(lex, &token,
isc_tokentype_string, true);
if (debug) {
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
parse_tests[i].text, isc_result_toid(result),
isc_result_toid(parse_tests[i].string_result),
token.type, parse_tests[i].string_type);
}
assert_int_equal(result, parse_tests[i].string_result);
if (result == ISC_R_SUCCESS) {
@ -250,10 +216,6 @@ lex_string(void **state) {
case isc_tokentype_qstring:
case isc_tokentype_vpair:
case isc_tokentype_qvpair:
if (debug) {
fprintf(stdout, "# value='%s'\n",
AS_STR(token));
}
assert_int_equal(token.type,
parse_tests[i].string_type);
assert_string_equal(
@ -274,8 +236,7 @@ lex_string(void **state) {
/*%
* qstring
*/
static void
lex_qstring(void **state) {
ISC_RUN_TEST_IMPL(lex_qstring) {
isc_buffer_t buf;
isc_lex_t *lex = NULL;
isc_result_t result;
@ -285,7 +246,7 @@ lex_qstring(void **state) {
UNUSED(state);
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
result = isc_lex_create(test_mctx, 1024, &lex);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_constinit(&buf, parse_tests[i].text,
@ -301,12 +262,6 @@ lex_qstring(void **state) {
memset(&token, 0, sizeof(token));
result = isc_lex_getmastertoken(lex, &token,
isc_tokentype_qstring, true);
if (debug) {
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
parse_tests[i].text, isc_result_toid(result),
isc_result_toid(parse_tests[i].qstring_result),
token.type, parse_tests[i].qstring_type);
}
assert_int_equal(result, parse_tests[i].qstring_result);
if (result == ISC_R_SUCCESS) {
@ -315,10 +270,6 @@ lex_qstring(void **state) {
case isc_tokentype_qstring:
case isc_tokentype_vpair:
case isc_tokentype_qvpair:
if (debug) {
fprintf(stdout, "# value='%s'\n",
AS_STR(token));
}
assert_int_equal(token.type,
parse_tests[i].qstring_type);
assert_string_equal(
@ -340,8 +291,7 @@ lex_qstring(void **state) {
* keypair is <string>=<qstring>. This has implications double quotes
* in key names.
*/
static void
lex_keypair(void **state) {
ISC_RUN_TEST_IMPL(lex_keypair) {
isc_buffer_t buf;
isc_lex_t *lex = NULL;
isc_result_t result;
@ -351,7 +301,7 @@ lex_keypair(void **state) {
UNUSED(state);
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
result = isc_lex_create(test_mctx, 1024, &lex);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_constinit(&buf, parse_tests[i].text,
@ -367,12 +317,6 @@ lex_keypair(void **state) {
memset(&token, 0, sizeof(token));
result = isc_lex_getmastertoken(lex, &token,
isc_tokentype_qvpair, true);
if (debug) {
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
parse_tests[i].text, isc_result_toid(result),
isc_result_toid(parse_tests[i].qvpair_result),
token.type, parse_tests[i].qvpair_type);
}
assert_int_equal(result, parse_tests[i].qvpair_result);
if (result == ISC_R_SUCCESS) {
@ -381,10 +325,6 @@ lex_keypair(void **state) {
case isc_tokentype_qstring:
case isc_tokentype_vpair:
case isc_tokentype_qvpair:
if (debug) {
fprintf(stdout, "# value='%s'\n",
AS_STR(token));
}
assert_int_equal(token.type,
parse_tests[i].qvpair_type);
assert_string_equal(
@ -402,31 +342,13 @@ lex_keypair(void **state) {
}
}
int
main(int argc, char *argv[]) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(lex_0xff), cmocka_unit_test(lex_keypair),
cmocka_unit_test(lex_setline), cmocka_unit_test(lex_string),
cmocka_unit_test(lex_qstring),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(lex_0xff)
ISC_TEST_ENTRY(lex_keypair)
ISC_TEST_ENTRY(lex_setline)
ISC_TEST_ENTRY(lex_string)
ISC_TEST_ENTRY(lex_qstring)
UNUSED(argv);
ISC_TEST_LIST_END
if (argc > 1) {
debug = true;
}
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -32,6 +31,8 @@
#include "../md.c"
#include <isc/test.h>
#define TEST_INPUT(x) (x), sizeof(x) - 1
static int
@ -64,19 +65,13 @@ _reset(void **state) {
return (0);
}
static void
isc_md_new_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(isc_md_new) {
isc_md_t *md = isc_md_new();
assert_non_null(md);
isc_md_free(md); /* Cleanup */
}
static void
isc_md_free_test(void **state) {
UNUSED(state);
ISC_RUN_TEST_IMPL(isc_md_free) {
isc_md_t *md = isc_md_new();
assert_non_null(md);
isc_md_free(md); /* Test freeing valid message digest context */
@ -85,13 +80,13 @@ isc_md_free_test(void **state) {
static void
isc_md_test(isc_md_t *md, const isc_md_type_t *type, const char *buf,
size_t buflen, const char *result, const int repeats) {
size_t buflen, const char *result, const size_t repeats) {
isc_result_t res;
assert_non_null(md);
assert_int_equal(isc_md_init(md, type), ISC_R_SUCCESS);
int i;
for (i = 0; i < repeats; i++) {
for (size_t i = 0; i < repeats; i++) {
assert_int_equal(
isc_md_update(md, (const unsigned char *)buf, buflen),
ISC_R_SUCCESS);
@ -106,14 +101,15 @@ isc_md_test(isc_md_t *md, const isc_md_type_t *type, const char *buf,
isc_buffer_t b;
isc_buffer_init(&b, hexdigest, sizeof(hexdigest));
assert_return_code(isc_hex_totext(&r, 0, "", &b), ISC_R_SUCCESS);
res = isc_hex_totext(&r, 0, "", &b);
assert_return_code(res, ISC_R_SUCCESS);
assert_memory_equal(hexdigest, result, (result ? strlen(result) : 0));
assert_int_equal(isc_md_reset(md), ISC_R_SUCCESS);
}
static void
isc_md_init_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_init) {
isc_md_t *md = *state;
assert_non_null(md);
@ -140,8 +136,7 @@ isc_md_init_test(void **state) {
assert_int_equal(isc_md_reset(md), ISC_R_SUCCESS);
}
static void
isc_md_update_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_update) {
isc_md_t *md = *state;
assert_non_null(md);
@ -153,8 +148,7 @@ isc_md_update_test(void **state) {
ISC_R_SUCCESS);
}
static void
isc_md_reset_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_reset) {
isc_md_t *md = *state;
#if 0
unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused));
@ -181,8 +175,7 @@ isc_md_reset_test(void **state) {
#endif /* if 0 */
}
static void
isc_md_final_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_final) {
isc_md_t *md = *state;
assert_non_null(md);
@ -198,8 +191,7 @@ isc_md_final_test(void **state) {
assert_int_equal(isc_md_final(md, digest, NULL), ISC_R_SUCCESS);
}
static void
isc_md_md5_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_md5) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_MD5, NULL, 0, NULL, 0);
isc_md_test(md, ISC_MD_MD5, TEST_INPUT(""),
@ -222,8 +214,7 @@ isc_md_md5_test(void **state) {
"57EDF4A22BE3C955AC49DA2E2107B67A", 1);
}
static void
isc_md_sha1_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_sha1) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_SHA1, NULL, 0, NULL, 0);
isc_md_test(md, ISC_MD_SHA1, TEST_INPUT(""),
@ -266,8 +257,7 @@ isc_md_sha1_test(void **state) {
"CB0082C8F197D260991BA6A460E76E202BAD27B3", 1);
}
static void
isc_md_sha224_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_sha224) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_SHA224, NULL, 0, NULL, 0);
@ -326,8 +316,7 @@ isc_md_sha224_test(void **state) {
1);
}
static void
isc_md_sha256_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_sha256) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_SHA256, NULL, 0, NULL, 0);
@ -388,8 +377,7 @@ isc_md_sha256_test(void **state) {
1);
}
static void
isc_md_sha384_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_sha384) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_SHA384, NULL, 0, NULL, 0);
@ -465,8 +453,7 @@ isc_md_sha384_test(void **state) {
1);
}
static void
isc_md_sha512_test(void **state) {
ISC_RUN_TEST_IMPL(isc_md_sha512) {
isc_md_t *md = *state;
isc_md_test(md, ISC_MD_SHA512, NULL, 0, NULL, 0);
@ -541,47 +528,27 @@ isc_md_sha512_test(void **state) {
1);
}
int
main(void) {
const struct CMUnitTest tests[] = {
/* isc_md_new() */
cmocka_unit_test(isc_md_new_test),
ISC_TEST_LIST_START
/* isc_md_init() */
cmocka_unit_test_setup_teardown(isc_md_init_test, _reset,
_reset),
ISC_TEST_ENTRY(isc_md_new)
/* isc_md_reset() */
cmocka_unit_test_setup_teardown(isc_md_reset_test, _reset,
_reset),
ISC_TEST_ENTRY_CUSTOM(isc_md_init, _reset, _reset)
/* isc_md_init() -> isc_md_update() -> isc_md_final() */
cmocka_unit_test(isc_md_md5_test),
cmocka_unit_test(isc_md_sha1_test),
cmocka_unit_test(isc_md_sha224_test),
cmocka_unit_test(isc_md_sha256_test),
cmocka_unit_test(isc_md_sha384_test),
cmocka_unit_test(isc_md_sha512_test),
ISC_TEST_ENTRY_CUSTOM(isc_md_reset, _reset, _reset)
cmocka_unit_test_setup_teardown(isc_md_update_test, _reset,
_reset),
cmocka_unit_test_setup_teardown(isc_md_final_test, _reset,
_reset),
ISC_TEST_ENTRY(isc_md_md5)
ISC_TEST_ENTRY(isc_md_sha1)
cmocka_unit_test(isc_md_free_test),
};
ISC_TEST_ENTRY(isc_md_sha224)
ISC_TEST_ENTRY(isc_md_sha256)
ISC_TEST_ENTRY(isc_md_sha384)
ISC_TEST_ENTRY(isc_md_sha512)
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_ENTRY_CUSTOM(isc_md_update, _reset, _reset)
ISC_TEST_ENTRY_CUSTOM(isc_md_final, _reset, _reset)
#else /* HAVE_CMOCKA */
ISC_TEST_ENTRY(isc_md_free)
#include <stdio.h>
ISC_TEST_LIST_END
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN_CUSTOM(_setup, _teardown)

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <fcntl.h>
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
@ -38,28 +36,8 @@
#include <isc/util.h>
#include "../mem_p.h"
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
#define MP1_FREEMAX 10
#define MP1_FILLCNT 10
@ -69,8 +47,7 @@ _teardown(void **state) {
#define MP2_FILLCNT 25
/* general memory system tests */
static void
isc_mem_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem) {
void *items1[50];
void *items2[50];
void *tmp;
@ -80,8 +57,8 @@ isc_mem_test(void **state) {
UNUSED(state);
isc_mempool_create(test_mctx, 24, &mp1);
isc_mempool_create(test_mctx, 31, &mp2);
isc_mempool_create(mctx, 24, &mp1);
isc_mempool_create(mctx, 31, &mp2);
isc_mempool_setfreemax(mp1, MP1_FREEMAX);
isc_mempool_setfillcount(mp1, MP1_FILLCNT);
@ -141,7 +118,7 @@ isc_mem_test(void **state) {
isc_mempool_destroy(&mp1);
isc_mempool_destroy(&mp2);
isc_mempool_create(test_mctx, 2, &mp1);
isc_mempool_create(mctx, 2, &mp1);
tmp = isc_mempool_get(mp1);
assert_non_null(tmp);
@ -153,8 +130,7 @@ isc_mem_test(void **state) {
#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
/* aligned memory system tests */
static void
isc_mem_aligned_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_aligned) {
isc_mem_t *mctx2 = NULL;
void *ptr;
size_t alignment;
@ -165,22 +141,21 @@ isc_mem_aligned_test(void **state) {
/* Check different alignment sizes up to the page size */
for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) {
size_t size = alignment / 2 - 1;
ptr = isc_mem_get_aligned(test_mctx, size, alignment);
ptr = isc_mem_get_aligned(mctx, size, alignment);
/* Check if the pointer is properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
/* Check if we can resize to <alignment, 2*alignment> range */
ptr = isc_mem_reget_aligned(test_mctx, ptr, size,
ptr = isc_mem_reget_aligned(mctx, ptr, size,
size * 2 + alignment, alignment);
/* Check if the pointer is still properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
isc_mem_put_aligned(test_mctx, ptr, size * 2 + alignment,
alignment);
isc_mem_put_aligned(mctx, ptr, size * 2 + alignment, alignment);
/* Check whether isc_mem_putanddetach_detach() also works */
isc_mem_create(&mctx2);
@ -191,8 +166,7 @@ isc_mem_aligned_test(void **state) {
#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
/* test TotalUse calculation */
static void
isc_mem_total_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_total) {
isc_mem_t *mctx2 = NULL;
size_t before, after;
ssize_t diff;
@ -220,16 +194,16 @@ isc_mem_total_test(void **state) {
/* ISC_MEMFLAG_INTERNAL */
before = isc_mem_total(test_mctx);
before = isc_mem_total(mctx);
for (i = 0; i < 100000; i++) {
void *ptr;
ptr = isc_mem_get(test_mctx, 2048);
isc_mem_put(test_mctx, ptr, 2048);
ptr = isc_mem_get(mctx, 2048);
isc_mem_put(mctx, ptr, 2048);
}
after = isc_mem_total(test_mctx);
after = isc_mem_total(mctx);
diff = after - before;
assert_int_equal(diff, (2048) * 100000);
@ -238,8 +212,7 @@ isc_mem_total_test(void **state) {
}
/* test InUse calculation */
static void
isc_mem_inuse_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_inuse) {
isc_mem_t *mctx2 = NULL;
size_t before, after;
ssize_t diff;
@ -262,43 +235,41 @@ isc_mem_inuse_test(void **state) {
isc_mem_destroy(&mctx2);
}
static void
isc_mem_zeroget_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_zeroget) {
uint8_t *data = NULL;
UNUSED(state);
data = isc_mem_get(test_mctx, 0);
data = isc_mem_get(mctx, 0);
assert_non_null(data);
isc_mem_put(test_mctx, data, 0);
isc_mem_put(mctx, data, 0);
}
#define REGET_INIT_SIZE 1024
#define REGET_GROW_SIZE 2048
#define REGET_SHRINK_SIZE 512
static void
isc_mem_reget_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_reget) {
uint8_t *data = NULL;
UNUSED(state);
/* test that we can reget NULL */
data = isc_mem_reget(test_mctx, NULL, 0, REGET_INIT_SIZE);
data = isc_mem_reget(mctx, NULL, 0, REGET_INIT_SIZE);
assert_non_null(data);
isc_mem_put(test_mctx, data, REGET_INIT_SIZE);
isc_mem_put(mctx, data, REGET_INIT_SIZE);
/* test that we can re-get a zero-length allocation */
data = isc_mem_get(test_mctx, 0);
data = isc_mem_get(mctx, 0);
assert_non_null(data);
data = isc_mem_reget(test_mctx, data, 0, REGET_INIT_SIZE);
data = isc_mem_reget(mctx, data, 0, REGET_INIT_SIZE);
assert_non_null(data);
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
data[i] = i % UINT8_MAX;
}
data = isc_mem_reget(test_mctx, data, REGET_INIT_SIZE, REGET_GROW_SIZE);
data = isc_mem_reget(mctx, data, REGET_INIT_SIZE, REGET_GROW_SIZE);
assert_non_null(data);
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
@ -309,22 +280,20 @@ isc_mem_reget_test(void **state) {
data[i - 1] = i % UINT8_MAX;
}
data = isc_mem_reget(test_mctx, data, REGET_GROW_SIZE,
REGET_SHRINK_SIZE);
data = isc_mem_reget(mctx, data, REGET_GROW_SIZE, REGET_SHRINK_SIZE);
assert_non_null(data);
for (size_t i = REGET_SHRINK_SIZE; i > 0; i--) {
assert_int_equal(data[i - 1], i % UINT8_MAX);
}
isc_mem_put(test_mctx, data, REGET_SHRINK_SIZE);
isc_mem_put(mctx, data, REGET_SHRINK_SIZE);
}
#if ISC_MEM_TRACKLINES
/* test mem with no flags */
static void
isc_mem_noflags_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_noflags) {
isc_result_t result;
isc_mem_t *mctx2 = NULL;
char buf[4096], *p, *q;
@ -368,8 +337,7 @@ isc_mem_noflags_test(void **state) {
}
/* test mem with record flag */
static void
isc_mem_recordflag_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_recordflag) {
isc_result_t result;
isc_mem_t *mctx2 = NULL;
char buf[4096], *p;
@ -409,8 +377,7 @@ isc_mem_recordflag_test(void **state) {
}
/* test mem with trace flag */
static void
isc_mem_traceflag_test(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_traceflag) {
isc_result_t result;
isc_mem_t *mctx2 = NULL;
char buf[4096], *p;
@ -470,7 +437,7 @@ static atomic_size_t mem_size;
static isc_threadresult_t
mem_thread(isc_threadarg_t arg) {
isc_mem_t *mctx = (isc_mem_t *)arg;
isc_mem_t *mctx2 = (isc_mem_t *)arg;
void *items[NUM_ITEMS];
size_t size = atomic_load(&mem_size);
while (!atomic_compare_exchange_weak(&mem_size, &size, size / 2)) {
@ -479,18 +446,17 @@ mem_thread(isc_threadarg_t arg) {
for (int i = 0; i < ITERS; i++) {
for (int j = 0; j < NUM_ITEMS; j++) {
items[j] = isc_mem_get(mctx, size);
items[j] = isc_mem_get(mctx2, size);
}
for (int j = 0; j < NUM_ITEMS; j++) {
isc_mem_put(mctx, items[j], size);
isc_mem_put(mctx2, items[j], size);
}
}
return ((isc_threadresult_t)0);
}
static void
isc_mem_benchmark(void **state) {
ISC_RUN_TEST_IMPL(isc_mem_benchmark) {
int nthreads = ISC_MAX(ISC_MIN(isc_os_ncpus(), 32), 1);
isc_thread_t threads[32];
isc_time_t ts1, ts2;
@ -505,7 +471,7 @@ isc_mem_benchmark(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
for (int i = 0; i < nthreads; i++) {
isc_thread_create(mem_thread, test_mctx, &threads[i]);
isc_thread_create(mem_thread, mctx, &threads[i]);
}
for (int i = 0; i < nthreads; i++) {
isc_thread_join(threads[i], NULL);
@ -525,58 +491,31 @@ isc_mem_benchmark(void **state) {
#endif /* __SANITIZE_THREAD */
/*
* Main
*/
ISC_TEST_LIST_START
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_mem_test, _setup,
_teardown),
ISC_TEST_ENTRY(isc_mem)
#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
cmocka_unit_test_setup_teardown(isc_mem_aligned_test, _setup,
_teardown),
ISC_TEST_ENTRY(isc_mem_aligned)
#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
cmocka_unit_test_setup_teardown(isc_mem_total_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_mem_inuse_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_mem_zeroget_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_mem_reget_test, _setup,
_teardown),
ISC_TEST_ENTRY(isc_mem_total)
ISC_TEST_ENTRY(isc_mem_inuse)
ISC_TEST_ENTRY(isc_mem_zeroget)
ISC_TEST_ENTRY(isc_mem_reget)
#if !defined(__SANITIZE_THREAD__)
cmocka_unit_test_setup_teardown(isc_mem_benchmark, _setup,
_teardown),
ISC_TEST_ENTRY(isc_mem_benchmark)
#endif /* __SANITIZE_THREAD__ */
#if ISC_MEM_TRACKLINES
cmocka_unit_test_setup_teardown(isc_mem_noflags_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(isc_mem_recordflag_test, _setup,
_teardown),
/*
* traceflag_test closes stderr, which causes weird
* side effects for any next test trying to use libuv.
* This test has to be the last one to avoid problems.
*/
cmocka_unit_test_setup_teardown(isc_mem_traceflag_test, _setup,
_teardown),
ISC_TEST_ENTRY(isc_mem_noflags)
ISC_TEST_ENTRY(isc_mem_recordflag)
/*
* traceflag_test closes stderr, which causes weird
* side effects for any next test trying to use libuv.
* This test has to be the last one to avoid problems.
*/
ISC_TEST_ENTRY(isc_mem_traceflag)
#endif /* if ISC_MEM_TRACKLINES */
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
@ -28,9 +27,10 @@
#include <isc/sockaddr.h>
#include <isc/util.h>
#include <isc/test.h>
/* test isc_netaddr_isnetzero() */
static void
netaddr_isnetzero(void **state) {
ISC_RUN_TEST_IMPL(netaddr_isnetzero) {
unsigned int i;
struct in_addr ina;
struct {
@ -41,12 +41,12 @@ netaddr_isnetzero(void **state) {
{ "10.0.0.0", false }, { "10.9.0.0", false },
{ "10.9.8.0", false }, { "10.9.8.7", false },
{ "127.0.0.0", false }, { "127.0.0.1", false } };
bool result;
isc_netaddr_t netaddr;
UNUSED(state);
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
bool result;
ina.s_addr = inet_addr(tests[i].address);
isc_netaddr_fromin(&netaddr, &ina);
result = isc_netaddr_isnetzero(&netaddr);
@ -55,8 +55,7 @@ netaddr_isnetzero(void **state) {
}
/* test isc_netaddr_masktoprefixlen() calculates correct prefix lengths */
static void
netaddr_masktoprefixlen(void **state) {
ISC_RUN_TEST_IMPL(netaddr_masktoprefixlen) {
struct in_addr na_a;
struct in_addr na_b;
struct in_addr na_c;
@ -97,8 +96,7 @@ netaddr_masktoprefixlen(void **state) {
}
/* check multicast addresses are detected properly */
static void
netaddr_multicast(void **state) {
ISC_RUN_TEST_IMPL(netaddr_multicast) {
unsigned int i;
struct {
int family;
@ -135,25 +133,12 @@ netaddr_multicast(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(netaddr_isnetzero),
cmocka_unit_test(netaddr_masktoprefixlen),
cmocka_unit_test(netaddr_multicast),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(netaddr_isnetzero)
ISC_TEST_ENTRY(netaddr_masktoprefixlen)
ISC_TEST_ENTRY(netaddr_multicast)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,6 @@
/*! \file */
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -31,37 +29,13 @@
#include <isc/parseint.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
static void
parse_overflow(void **state) {
ISC_RUN_TEST_IMPL(parse_overflow) {
isc_result_t result;
uint32_t output;
UNUSED(state);
result = isc_parse_uint32(&output, "1234567890", 10);
assert_int_equal(ISC_R_SUCCESS, result);
assert_int_equal(1234567890, output);
@ -73,24 +47,10 @@ parse_overflow(void **state) {
assert_int_equal(ISC_R_RANGE, result);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(parse_overflow, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(parse_overflow)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -21,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <uv.h>
#define UNIT_TESTING
#include <cmocka.h>
@ -30,10 +29,9 @@
#include <isc/thread.h>
#include <isc/util.h>
#include "isctest.h"
#include <isc/test.h>
static void
isc_quota_get_set_test(void **state) {
ISC_RUN_TEST_IMPL(isc_quota_get_set) {
UNUSED(state);
isc_quota_t quota;
isc_quota_t *quota2 = NULL;
@ -79,8 +77,7 @@ add_quota(isc_quota_t *source, isc_quota_t **target,
assert_int_equal(isc_quota_getused(source), expected_used);
}
static void
isc_quota_hard_test(void **state) {
ISC_RUN_TEST_IMPL(isc_quota_hard) {
isc_quota_t quota;
isc_quota_t *quotas[110];
int i;
@ -111,8 +108,7 @@ isc_quota_hard_test(void **state) {
isc_quota_destroy(&quota);
}
static void
isc_quota_soft_test(void **state) {
ISC_RUN_TEST_IMPL(isc_quota_soft) {
isc_quota_t quota;
isc_quota_t *quotas[110];
int i;
@ -165,8 +161,7 @@ callback(isc_quota_t *quota, void *data) {
}
}
static void
isc_quota_callback_test(void **state) {
ISC_RUN_TEST_IMPL(isc_quota_callback) {
isc_result_t result;
isc_quota_t quota;
isc_quota_t *quotas[30];
@ -260,7 +255,7 @@ isc_thread_t g_threads[10 * 100];
static void *
quota_detach(void *quotap) {
isc_quota_t *quota = (isc_quota_t *)quotap;
isc_test_nap(10000);
uv_sleep(10000);
isc_quota_detach(&quota);
return ((isc_threadresult_t)0);
}
@ -291,8 +286,7 @@ quota_thread(void *qtip) {
return ((isc_threadresult_t)0);
}
static void
isc_quota_callback_mt_test(void **state) {
ISC_RUN_TEST_IMPL(isc_quota_callback_mt) {
UNUSED(state);
isc_quota_t quota;
int i;
@ -313,14 +307,14 @@ isc_quota_callback_mt_test(void **state) {
for (i = 0; i < (int)atomic_load(&g_tnum); i++) {
isc_thread_join(g_threads[i], NULL);
}
int direct = 0, callback = 0;
int direct = 0, ncallback = 0;
for (i = 0; i < 10; i++) {
direct += atomic_load(&qtis[i].direct);
callback += atomic_load(&qtis[i].callback);
ncallback += atomic_load(&qtis[i].callback);
}
/* Total quota gained must be 10 threads * 100 tries */
assert_int_equal(direct + callback, 10 * 100);
assert_int_equal(direct + ncallback, 10 * 100);
/*
* At least 100 must be direct, the rest is virtually random:
* - in a regular run I'm constantly getting 100:900 ratio
@ -332,27 +326,14 @@ isc_quota_callback_mt_test(void **state) {
isc_quota_destroy(&quota);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_quota_get_set_test),
cmocka_unit_test(isc_quota_hard_test),
cmocka_unit_test(isc_quota_soft_test),
cmocka_unit_test(isc_quota_callback_test),
cmocka_unit_test(isc_quota_callback_mt_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_quota_get_set)
ISC_TEST_ENTRY(isc_quota_hard)
ISC_TEST_ENTRY(isc_quota_soft)
ISC_TEST_ENTRY(isc_quota_callback)
ISC_TEST_ENTRY(isc_quota_callback_mt)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -29,32 +27,10 @@
#include <isc/result.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* test radix searching */
static void
isc_radix_search_test(void **state) {
ISC_RUN_TEST_IMPL(isc_radix_search) {
isc_radix_tree_t *radix = NULL;
isc_radix_node_t *node;
isc_prefix_t prefix;
@ -64,7 +40,7 @@ isc_radix_search_test(void **state) {
UNUSED(state);
result = isc_radix_create(test_mctx, &radix, 32);
result = isc_radix_create(mctx, &radix, 32);
assert_int_equal(result, ISC_R_SUCCESS);
in_addr.s_addr = inet_addr("3.3.3.0");
@ -101,24 +77,9 @@ isc_radix_search_test(void **state) {
isc_radix_destroy(radix, NULL);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_radix_search_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_radix_search)
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_LIST_END
ISC_TEST_MAIN

View File

@ -18,8 +18,6 @@
* random. The test is expected to fail on occasion by random happenstance.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <math.h>
#include <sched.h> /* IWYU pragma: keep */
@ -40,11 +38,11 @@
#include <isc/result.h>
#include <isc/util.h>
#include "isctest.h"
#include <isc/test.h>
#define REPS 25000
typedef double(pvalue_func_t)(isc_mem_t *mctx, uint16_t *values, size_t length);
typedef double(pvalue_func_t)(uint16_t *values, size_t length);
/* igamc(), igam(), etc. were adapted (and cleaned up) from the Cephes
* math library:
@ -66,9 +64,6 @@ igamc(double a, double x);
static double
igam(double a, double x);
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
typedef enum {
ISC_RANDOM8,
ISC_RANDOM16,
@ -78,31 +73,10 @@ typedef enum {
ISC_NONCE_BYTES
} isc_random_func;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
static double
igamc(double a, double x) {
double ans, ax, c, yc, r, t, y, z;
double pk, pkm1, pkm2, qk, qkm1, qkm2;
double ans, ax, c, r, t, y, z;
double pkm1, pkm2, qkm1, qkm2;
if ((x <= 0) || (a <= 0)) {
return (1.0);
@ -130,6 +104,7 @@ igamc(double a, double x) {
ans = pkm1 / qkm1;
do {
double yc, pk, qk;
c += 1.0;
y += 1.0;
z += 2.0;
@ -258,13 +233,12 @@ tables_init(void) {
*/
static uint32_t
matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
size_t i, j, k;
unsigned int rt = 0;
uint32_t rank = 0;
uint32_t tmp;
for (k = 0; k < rows; k++) {
i = k;
for (size_t k = 0; k < rows; k++) {
size_t i = k;
while (rt >= cols || ((bits[i] >> rt) & 1) == 0) {
i++;
@ -289,7 +263,7 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
bits[k] = tmp;
}
for (j = i + 1; j < rows; j++) {
for (size_t j = i + 1; j < rows; j++) {
if (((bits[j] >> rt) & 1) == 0) {
continue;
} else {
@ -363,7 +337,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
break;
}
p_value = (*func)(test_mctx, (uint16_t *)values, REPS * 2);
p_value = (*func)((uint16_t *)values, REPS * 2);
if (p_value >= 0.01) {
passed++;
}
@ -384,13 +358,6 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
lower_confidence = p_hat - (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m));
higher_confidence = p_hat + (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m));
if (verbose) {
print_message("# passed=%u/1000\n", passed);
print_message("# higher_confidence=%f, lower_confidence=%f, "
"proportion=%f\n",
higher_confidence, lower_confidence, proportion);
}
assert_in_range(proportion, lower_confidence, higher_confidence);
/*
@ -407,29 +374,17 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
/* Pre-requisite that at least 55 sequences are processed. */
assert_true(m >= 55);
if (verbose) {
print_message("# ");
}
chi_square = 0.0;
for (j = 0; j < 10; j++) {
double numer;
double denom;
if (verbose) {
print_message("hist%u=%u ", j, histogram[j]);
}
numer = (histogram[j] - (m / 10.0)) *
(histogram[j] - (m / 10.0));
denom = m / 10.0;
chi_square += numer / denom;
}
if (verbose) {
print_message("\n");
}
p_value_t = igamc(9 / 2.0, chi_square / 2.0);
assert_true(p_value_t >= 0.0001);
@ -440,7 +395,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
* RANDOM test suite.
*/
static double
monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
monobit(uint16_t *values, size_t length) {
size_t i;
int32_t scount;
uint32_t numbits;
@ -459,10 +414,6 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
/* Preconditions (section 2.1.7 in NIST SP 800-22) */
assert_true(numbits >= 100);
if (verbose) {
print_message("# numbits=%u, scount=%d\n", numbits, scount);
}
s_obs = abs(scount) / sqrt(numbits);
p_value = erfc(s_obs / sqrt(2.0));
@ -473,7 +424,7 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
* This is the runs test taken from the NIST SP 800-22 RNG test suite.
*/
static double
runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
runs(uint16_t *values, size_t length) {
size_t i;
uint32_t bcount;
uint32_t numbits;
@ -481,7 +432,6 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
double tau;
uint32_t j;
uint32_t b;
uint8_t bit_this;
uint8_t bit_prev;
uint32_t v_obs;
double numer;
@ -497,10 +447,6 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
bcount += bitcounts_table[values[i]];
}
if (verbose) {
print_message("# numbits=%u, bcount=%u\n", numbits, bcount);
}
pi = (double)bcount / (double)numbits;
tau = 2.0 / sqrt(numbits);
@ -524,7 +470,7 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
v_obs = 0;
for (i = 1; i < numbits; i++) {
bit_this = (values[j] & (1U << b)) == 0 ? 0 : 1;
uint8_t bit_this = (values[j] & (1U << b)) == 0 ? 0 : 1;
if (b == 0) {
b = 15;
j++;
@ -552,7 +498,7 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
* test suite.
*/
static double
blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
blockfrequency(uint16_t *values, size_t length) {
uint32_t i;
uint32_t numbits;
uint32_t mbits;
@ -567,10 +513,6 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
mwords = mbits / 16;
numblocks = numbits / mbits;
if (verbose) {
print_message("# numblocks=%u\n", numblocks);
}
/* Preconditions (section 2.2.7 in NIST SP 800-22) */
assert_true(numbits >= 100);
assert_true(mbits >= 20);
@ -603,10 +545,6 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
isc_mem_put(mctx, pi, numblocks * sizeof(double));
if (verbose) {
print_message("# chi_square=%f\n", chi_square);
}
p_value = igamc(numblocks * 0.5, chi_square * 0.5);
return (p_value);
@ -617,7 +555,7 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
* test suite.
*/
static double
binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
binarymatrixrank(uint16_t *values, size_t length) {
uint32_t i;
size_t matrix_m;
size_t matrix_q;
@ -693,11 +631,6 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
chi_square = term1 + term2 + term3;
if (verbose) {
print_message("# fm_0=%u, fm_1=%u, fm_rest=%u, chi_square=%f\n",
fm_0, fm_1, fm_rest, chi_square);
}
p_value = exp(-chi_square * 0.5);
return (p_value);
@ -708,32 +641,28 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
***/
/* Monobit test for the RANDOM */
static void
isc_random32_monobit(void **state) {
ISC_RUN_TEST_IMPL(isc_random32_monobit) {
UNUSED(state);
random_test(monobit, ISC_RANDOM32);
}
/* Runs test for the RANDOM */
static void
isc_random32_runs(void **state) {
ISC_RUN_TEST_IMPL(isc_random32_runs) {
UNUSED(state);
random_test(runs, ISC_RANDOM32);
}
/* Block frequency test for the RANDOM */
static void
isc_random32_blockfrequency(void **state) {
ISC_RUN_TEST_IMPL(isc_random32_blockfrequency) {
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM32);
}
/* Binary matrix rank test for the RANDOM */
static void
isc_random32_binarymatrixrank(void **state) {
ISC_RUN_TEST_IMPL(isc_random32_binarymatrixrank) {
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM32);
@ -744,32 +673,28 @@ isc_random32_binarymatrixrank(void **state) {
***/
/* Monobit test for the RANDOM */
static void
isc_random_bytes_monobit(void **state) {
ISC_RUN_TEST_IMPL(isc_random_bytes_monobit) {
UNUSED(state);
random_test(monobit, ISC_RANDOM_BYTES);
}
/* Runs test for the RANDOM */
static void
isc_random_bytes_runs(void **state) {
ISC_RUN_TEST_IMPL(isc_random_bytes_runs) {
UNUSED(state);
random_test(runs, ISC_RANDOM_BYTES);
}
/* Block frequency test for the RANDOM */
static void
isc_random_bytes_blockfrequency(void **state) {
ISC_RUN_TEST_IMPL(isc_random_bytes_blockfrequency) {
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM_BYTES);
}
/* Binary matrix rank test for the RANDOM */
static void
isc_random_bytes_binarymatrixrank(void **state) {
ISC_RUN_TEST_IMPL(isc_random_bytes_binarymatrixrank) {
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM_BYTES);
@ -780,32 +705,28 @@ isc_random_bytes_binarymatrixrank(void **state) {
***/
/* Monobit test for the RANDOM */
static void
isc_random_uniform_monobit(void **state) {
ISC_RUN_TEST_IMPL(isc_random_uniform_monobit) {
UNUSED(state);
random_test(monobit, ISC_RANDOM_UNIFORM);
}
/* Runs test for the RANDOM */
static void
isc_random_uniform_runs(void **state) {
ISC_RUN_TEST_IMPL(isc_random_uniform_runs) {
UNUSED(state);
random_test(runs, ISC_RANDOM_UNIFORM);
}
/* Block frequency test for the RANDOM */
static void
isc_random_uniform_blockfrequency(void **state) {
ISC_RUN_TEST_IMPL(isc_random_uniform_blockfrequency) {
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM_UNIFORM);
}
/* Binary matrix rank test for the RANDOM */
static void
isc_random_uniform_binarymatrixrank(void **state) {
ISC_RUN_TEST_IMPL(isc_random_uniform_binarymatrixrank) {
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM_UNIFORM);
@ -814,80 +735,52 @@ isc_random_uniform_binarymatrixrank(void **state) {
/* Tests for isc_nonce_bytes() function */
/* Monobit test for the RANDOM */
static void
isc_nonce_bytes_monobit(void **state) {
ISC_RUN_TEST_IMPL(isc_nonce_bytes_monobit) {
UNUSED(state);
random_test(monobit, ISC_NONCE_BYTES);
}
/* Runs test for the RANDOM */
static void
isc_nonce_bytes_runs(void **state) {
ISC_RUN_TEST_IMPL(isc_nonce_bytes_runs) {
UNUSED(state);
random_test(runs, ISC_NONCE_BYTES);
}
/* Block frequency test for the RANDOM */
static void
isc_nonce_bytes_blockfrequency(void **state) {
ISC_RUN_TEST_IMPL(isc_nonce_bytes_blockfrequency) {
UNUSED(state);
random_test(blockfrequency, ISC_NONCE_BYTES);
}
/* Binary matrix rank test for the RANDOM */
static void
isc_nonce_bytes_binarymatrixrank(void **state) {
ISC_RUN_TEST_IMPL(isc_nonce_bytes_binarymatrixrank) {
UNUSED(state);
random_test(binarymatrixrank, ISC_NONCE_BYTES);
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_random32_monobit),
cmocka_unit_test(isc_random32_runs),
cmocka_unit_test(isc_random32_blockfrequency),
cmocka_unit_test(isc_random32_binarymatrixrank),
cmocka_unit_test(isc_random_bytes_monobit),
cmocka_unit_test(isc_random_bytes_runs),
cmocka_unit_test(isc_random_bytes_blockfrequency),
cmocka_unit_test(isc_random_bytes_binarymatrixrank),
cmocka_unit_test(isc_random_uniform_monobit),
cmocka_unit_test(isc_random_uniform_runs),
cmocka_unit_test(isc_random_uniform_blockfrequency),
cmocka_unit_test(isc_random_uniform_binarymatrixrank),
cmocka_unit_test(isc_nonce_bytes_monobit),
cmocka_unit_test(isc_nonce_bytes_runs),
cmocka_unit_test(isc_nonce_bytes_blockfrequency),
cmocka_unit_test(isc_nonce_bytes_binarymatrixrank),
};
int c;
ISC_TEST_LIST_START
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
verbose = true;
break;
default:
break;
}
}
ISC_TEST_ENTRY(isc_random32_monobit)
ISC_TEST_ENTRY(isc_random32_runs)
ISC_TEST_ENTRY(isc_random32_blockfrequency)
ISC_TEST_ENTRY(isc_random32_binarymatrixrank)
ISC_TEST_ENTRY(isc_random_bytes_monobit)
ISC_TEST_ENTRY(isc_random_bytes_runs)
ISC_TEST_ENTRY(isc_random_bytes_blockfrequency)
ISC_TEST_ENTRY(isc_random_bytes_binarymatrixrank)
ISC_TEST_ENTRY(isc_random_uniform_monobit)
ISC_TEST_ENTRY(isc_random_uniform_runs)
ISC_TEST_ENTRY(isc_random_uniform_blockfrequency)
ISC_TEST_ENTRY(isc_random_uniform_binarymatrixrank)
ISC_TEST_ENTRY(isc_nonce_bytes_monobit)
ISC_TEST_ENTRY(isc_nonce_bytes_runs)
ISC_TEST_ENTRY(isc_nonce_bytes_blockfrequency)
ISC_TEST_ENTRY(isc_nonce_bytes_binarymatrixrank)
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -33,12 +32,10 @@
#include <isc/regex.h>
#include <isc/util.h>
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
#include <isc/test.h>
/* test isc_regex_validate() */
static void
regex_validate(void **state) {
ISC_RUN_TEST_IMPL(regex_validate) {
/*
* test regex were generated using http://code.google.com/p/regfuzz/
* modified to use only printable characters
@ -2303,23 +2300,10 @@ regex_validate(void **state) {
(r == 0 && tests[i].expect == -1)) &&
!tests[i].exception)
{
if (verbose) {
print_error("regcomp(%s) -> %s expected %s\n",
tests[i].expression,
r != 0 ? "bad" : "good",
tests[i].expect == -1 ? "bad"
: "good");
}
} else if (r == 0 &&
preg.re_nsub != (unsigned int)tests[i].expect &&
!tests[i].exception)
{
if (verbose) {
print_error("%s preg.re_nsub %lu expected %d\n",
tests[i].expression,
(unsigned long)preg.re_nsub,
tests[i].expect);
}
tests[i].expect = preg.re_nsub;
}
if (r == 0) {
@ -2341,34 +2325,10 @@ regex_validate(void **state) {
}
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(regex_validate),
};
int c;
ISC_TEST_LIST_START
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
verbose = true;
break;
default:
break;
}
}
ISC_TEST_ENTRY(regex_validate)
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
@ -26,9 +25,10 @@
#include <isc/result.h>
#include <isc/util.h>
#include <isc/test.h>
/* convert result to identifier string */
static void
isc_result_toid_test(void **state) {
ISC_RUN_TEST_IMPL(isc_result_toid) {
const char *id;
UNUSED(state);
@ -41,8 +41,7 @@ isc_result_toid_test(void **state) {
}
/* convert result to description string */
static void
isc_result_totext_test(void **state) {
ISC_RUN_TEST_IMPL(isc_result_totext) {
const char *str;
UNUSED(state);
@ -54,24 +53,11 @@ isc_result_totext_test(void **state) {
assert_string_equal("failure", str);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_result_toid_test),
cmocka_unit_test(isc_result_totext_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_result_toid)
ISC_TEST_ENTRY(isc_result_totext)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -13,8 +13,6 @@
/* ! \file */
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -28,9 +26,10 @@
#include <isc/safe.h>
#include <isc/util.h>
#include <isc/test.h>
/* test isc_safe_memequal() */
static void
isc_safe_memequal_test(void **state) {
ISC_RUN_TEST_IMPL(isc_safe_memequal) {
UNUSED(state);
assert_true(isc_safe_memequal("test", "test", 4));
@ -44,8 +43,7 @@ isc_safe_memequal_test(void **state) {
}
/* test isc_safe_memwipe() */
static void
isc_safe_memwipe_test(void **state) {
ISC_RUN_TEST_IMPL(isc_safe_memwipe) {
UNUSED(state);
/* These should pass. */
@ -84,24 +82,10 @@ isc_safe_memwipe_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_safe_memequal_test),
cmocka_unit_test(isc_safe_memwipe_test),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY(isc_safe_memequal)
ISC_TEST_ENTRY(isc_safe_memwipe)
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,7 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <sched.h>
#include <setjmp.h>
#include <stdarg.h>
@ -26,6 +25,8 @@
#include "../siphash.c"
#include <isc/test.h>
const uint8_t vectors_sip64[64][8] = {
{ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72 },
{ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74 },
@ -128,8 +129,7 @@ const uint8_t vectors_hsip32[64][4] = {
{ 0xbd, 0x83, 0x99, 0x7a }, { 0x59, 0xea, 0x4a, 0x74 }
};
static void
isc_siphash24_test(void **state) {
ISC_RUN_TEST_IMPL(isc_siphash24) {
UNUSED(state);
uint8_t in[64], out[8], key[16];
@ -144,8 +144,7 @@ isc_siphash24_test(void **state) {
}
}
static void
isc_halfsiphash24_test(void **state) {
ISC_RUN_TEST_IMPL(isc_halfsiphash24) {
UNUSED(state);
uint8_t in[64], out[4], key[16];
@ -160,24 +159,11 @@ isc_halfsiphash24_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_siphash24_test),
cmocka_unit_test(isc_halfsiphash24_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_siphash24)
ISC_TEST_ENTRY(isc_halfsiphash24)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -30,32 +28,10 @@
#include <isc/sockaddr.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* test sockaddr hash */
static void
sockaddr_hash(void **state) {
ISC_RUN_TEST_IMPL(sockaddr_hash) {
isc_sockaddr_t addr;
struct in_addr in;
struct in6_addr in6;
@ -80,13 +56,12 @@ sockaddr_hash(void **state) {
}
/* test isc_sockaddr_isnetzero() */
static void
sockaddr_isnetzero(void **state) {
ISC_RUN_TEST_IMPL(sockaddr_isnetzero) {
isc_sockaddr_t addr;
struct in_addr in;
struct in6_addr in6;
bool r;
int ret;
size_t i;
struct {
const char *string;
@ -123,7 +98,7 @@ sockaddr_isnetzero(void **state) {
}
for (i = 0; i < sizeof(data6) / sizeof(data6[0]); i++) {
ret = inet_pton(AF_INET6, data6[i].string, &in6);
int ret = inet_pton(AF_INET6, data6[i].string, &in6);
assert_int_equal(ret, 1);
isc_sockaddr_fromin6(&addr, &in6, 1);
r = isc_sockaddr_isnetzero(&addr);
@ -135,8 +110,7 @@ sockaddr_isnetzero(void **state) {
* test that isc_sockaddr_eqaddrprefix() returns true when prefixes of a
* and b are equal, and false when they are not equal
*/
static void
sockaddr_eqaddrprefix(void **state) {
ISC_RUN_TEST_IMPL(sockaddr_eqaddrprefix) {
struct in_addr ina_a;
struct in_addr ina_b;
struct in_addr ina_c;
@ -163,26 +137,12 @@ sockaddr_eqaddrprefix(void **state) {
assert_false(isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 16));
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(sockaddr_hash, _setup,
_teardown),
cmocka_unit_test(sockaddr_isnetzero),
cmocka_unit_test(sockaddr_eqaddrprefix),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(sockaddr_hash)
ISC_TEST_ENTRY(sockaddr_isnetzero)
ISC_TEST_ENTRY(sockaddr_eqaddrprefix)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -28,38 +26,16 @@
#include <isc/stats.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
/* test stats */
static void
isc_stats_basic_test(void **state) {
ISC_RUN_TEST_IMPL(isc_stats_basic) {
isc_stats_t *stats = NULL;
isc_result_t result;
UNUSED(state);
result = isc_stats_create(test_mctx, &stats, 4);
result = isc_stats_create(mctx, &stats, 4);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_stats_ncounters(stats), 4);
@ -118,24 +94,10 @@ isc_stats_basic_test(void **state) {
isc_stats_detach(&stats);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(isc_stats_basic_test, _setup,
_teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_stats_basic)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -28,41 +26,19 @@
#include <isc/symtab.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
#include <isc/test.h>
static void
undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) {
UNUSED(arg);
assert_int_equal(type, 1);
isc_mem_free(test_mctx, key);
isc_mem_free(test_mctx, value.as_pointer);
isc_mem_free(mctx, key);
isc_mem_free(mctx, value.as_pointer);
}
/* test symbol table growth */
static void
symtab_grow(void **state) {
ISC_RUN_TEST_IMPL(symtab_grow) {
isc_result_t result;
isc_symtab_t *st = NULL;
isc_symvalue_t value;
@ -71,7 +47,7 @@ symtab_grow(void **state) {
UNUSED(state);
result = isc_symtab_create(test_mctx, 3, undefine, NULL, false, &st);
result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st);
assert_int_equal(result, ISC_R_SUCCESS);
assert_non_null(st);
@ -85,9 +61,9 @@ symtab_grow(void **state) {
char str[16], *key;
snprintf(str, sizeof(str), "%04x", i);
key = isc_mem_strdup(test_mctx, str);
key = isc_mem_strdup(mctx, str);
assert_non_null(key);
value.as_pointer = isc_mem_strdup(test_mctx, str);
value.as_pointer = isc_mem_strdup(mctx, str);
assert_non_null(value.as_pointer);
result = isc_symtab_define(st, key, 1, value, policy);
assert_int_equal(result, ISC_R_SUCCESS);
@ -103,9 +79,9 @@ symtab_grow(void **state) {
char str[16], *key;
snprintf(str, sizeof(str), "%04x", i);
key = isc_mem_strdup(test_mctx, str);
key = isc_mem_strdup(mctx, str);
assert_non_null(key);
value.as_pointer = isc_mem_strdup(test_mctx, str);
value.as_pointer = isc_mem_strdup(mctx, str);
assert_non_null(value.as_pointer);
result = isc_symtab_define(st, key, 1, value, policy);
assert_int_equal(result, ISC_R_EXISTS);
@ -149,23 +125,10 @@ symtab_grow(void **state) {
isc_symtab_destroy(&st);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(symtab_grow, _setup, _teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(symtab_grow)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -22,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <uv.h>
#define UNIT_TESTING
@ -39,7 +38,7 @@
#include <isc/timer.h>
#include <isc/util.h>
#include "isctest.h"
#include <isc/test.h>
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
@ -53,60 +52,45 @@ static atomic_bool done;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
isc_mutex_init(&lock);
isc_condition_init(&cv);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
workers = 0;
setup_managers(state);
return (0);
}
static int
_setup2(void **state) {
isc_result_t result;
UNUSED(state);
isc_mutex_init(&lock);
isc_condition_init(&cv);
/* Two worker threads */
result = isc_test_begin(NULL, true, 2);
assert_int_equal(result, ISC_R_SUCCESS);
workers = 2;
setup_managers(state);
return (0);
}
static int
_setup4(void **state) {
isc_result_t result;
UNUSED(state);
isc_mutex_init(&lock);
isc_condition_init(&cv);
/* Four worker threads */
result = isc_test_begin(NULL, true, 4);
assert_int_equal(result, ISC_R_SUCCESS);
workers = 4;
setup_managers(state);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
teardown_managers(state);
isc_test_end();
isc_condition_destroy(&cv);
isc_mutex_destroy(&lock);
return (0);
}
@ -124,8 +108,7 @@ set(isc_task_t *task, isc_event_t *event) {
#include <isc/thread.h>
/* Create a task */
static void
create_task(void **state) {
ISC_RUN_TEST_IMPL(create_task) {
isc_result_t result;
isc_task_t *task = NULL;
@ -139,8 +122,7 @@ create_task(void **state) {
}
/* Process events */
static void
all_events(void **state) {
ISC_RUN_TEST_IMPL(all_events) {
isc_result_t result;
isc_task_t *task = NULL;
isc_event_t *event = NULL;
@ -157,14 +139,14 @@ all_events(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
/* First event */
event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST, set, &a,
event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &a,
sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&a), 0);
isc_task_send(task, &event);
event = isc_event_allocate(test_mctx, task, ISC_TASKEVENT_TEST, set, &b,
event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &b,
sizeof(isc_event_t));
assert_non_null(event);
@ -172,7 +154,7 @@ all_events(void **state) {
isc_task_send(task, &event);
while ((atomic_load(&a) == 0 || atomic_load(&b) == 0) && i++ < 5000) {
isc_test_nap(1000);
uv_sleep(1000);
}
assert_int_not_equal(atomic_load(&a), 0);
@ -223,8 +205,7 @@ static char four[] = "4";
static char tick[] = "tick";
static char tock[] = "tock";
static void
basic(void **state) {
ISC_RUN_TEST_IMPL(basic) {
isc_result_t result;
isc_task_t *task1 = NULL;
isc_task_t *task2 = NULL;
@ -272,7 +253,7 @@ basic(void **state) {
* structure (socket, timer, task, etc) but this is just a
* test program.
*/
event = isc_event_allocate(test_mctx, (void *)1, 1, basic_cb,
event = isc_event_allocate(mctx, (void *)1, 1, basic_cb,
testarray[i], sizeof(*event));
assert_non_null(event);
isc_task_send(task1, &event);
@ -347,8 +328,7 @@ exclusive_cb(isc_task_t *task, isc_event_t *event) {
}
}
static void
task_exclusive(void **state) {
ISC_RUN_TEST_IMPL(task_exclusive) {
isc_task_t *tasks[10];
isc_result_t result;
int i;
@ -374,12 +354,12 @@ task_exclusive(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
}
v = isc_mem_get(test_mctx, sizeof *v);
v = isc_mem_get(mctx, sizeof *v);
assert_non_null(v);
*v = i;
event = isc_event_allocate(test_mctx, NULL, 1, exclusive_cb, v,
event = isc_event_allocate(mctx, NULL, 1, exclusive_cb, v,
sizeof(*event));
assert_non_null(event);
@ -392,7 +372,7 @@ task_exclusive(void **state) {
}
while (atomic_load(&counter) > 0) {
isc_test_nap(1000);
uv_sleep(1000);
}
}
@ -429,8 +409,7 @@ maxtask_cb(isc_task_t *task, isc_event_t *event) {
}
}
static void
manytasks(void **state) {
ISC_RUN_TEST_IMPL(manytasks) {
isc_event_t *event = NULL;
uintptr_t ntasks = 2; /* 0000; */
@ -443,8 +422,8 @@ manytasks(void **state) {
atomic_init(&done, false);
event = isc_event_allocate(test_mctx, NULL, 1, maxtask_cb,
(void *)ntasks, sizeof(*event));
event = isc_event_allocate(mctx, NULL, 1, maxtask_cb, (void *)ntasks,
sizeof(*event));
assert_non_null(event);
LOCK(&lock);
@ -518,12 +497,12 @@ try_purgeevent(void) {
/*
* Block the task on cv.
*/
event1 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1,
event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
pge_event1, NULL, sizeof(*event1));
assert_non_null(event1);
isc_task_send(task, &event1);
event2 = isc_event_allocate(test_mctx, (void *)1, (isc_eventtype_t)1,
event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
pge_event2, NULL, sizeof(*event2));
assert_non_null(event2);
@ -553,7 +532,6 @@ try_purgeevent(void) {
WAITUNTIL(&cv, &lock, &now);
}
UNLOCK(&lock);
isc_task_detach(&task);
@ -566,72 +544,21 @@ try_purgeevent(void) {
* task's queue and returns true.
*/
static void
purgeevent(void **state) {
ISC_RUN_TEST_IMPL(purgeevent) {
UNUSED(state);
try_purgeevent();
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(manytasks, _setup, _teardown),
cmocka_unit_test_setup_teardown(all_events, _setup, _teardown),
cmocka_unit_test_setup_teardown(basic, _setup2, _teardown),
cmocka_unit_test_setup_teardown(create_task, _setup, _teardown),
cmocka_unit_test_setup_teardown(purgeevent, _setup2, _teardown),
cmocka_unit_test_setup_teardown(task_exclusive, _setup4,
_teardown),
};
struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])];
size_t i;
int c;
ISC_TEST_LIST_START
memset(selected, 0, sizeof(selected));
ISC_TEST_ENTRY_CUSTOM(manytasks, _setup4, _teardown)
ISC_TEST_ENTRY_CUSTOM(all_events, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(basic, _setup2, _teardown)
ISC_TEST_ENTRY_CUSTOM(create_task, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(purgeevent, _setup2, _teardown)
ISC_TEST_ENTRY_CUSTOM(task_exclusive, _setup4, _teardown)
while ((c = isc_commandline_parse(argc, argv, "lt:v")) != -1) {
switch (c) {
case 'l':
for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++)
{
if (tests[i].name != NULL) {
fprintf(stdout, "%s\n", tests[i].name);
}
}
return (0);
case 't':
if (!cmocka_add_test_byname(
tests, isc_commandline_argument, selected))
{
fprintf(stderr, "unknown test '%s'\n",
isc_commandline_argument);
exit(1);
}
break;
case 'v':
verbose = true;
break;
default:
break;
}
}
ISC_TEST_LIST_END
if (selected[0].name != NULL) {
return (cmocka_run_group_tests(selected, NULL, NULL));
} else {
return (cmocka_run_group_tests(tests, NULL, NULL));
}
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -30,6 +28,8 @@
#include "../time.c"
#include <isc/test.h>
#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
#define MAX_NS (NS_PER_S - 1)
@ -66,8 +66,7 @@ const struct time_vectors vectors_sub[7] = {
{ { 0, 0 }, { 0, MAX_NS }, { 0, 0 }, ISC_R_RANGE },
};
static void
isc_time_add_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_add_test) {
UNUSED(state);
for (size_t i = 0; i < ARRAY_SIZE(vectors_add); i++) {
@ -100,8 +99,7 @@ isc_time_add_test(void **state) {
&(isc_time_t){ 0, 0 }, &(isc_interval_t){ 0, 0 }, NULL));
}
static void
isc_time_sub_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_sub_test) {
UNUSED(state);
for (size_t i = 0; i < ARRAY_SIZE(vectors_sub); i++) {
@ -134,8 +132,8 @@ isc_time_sub_test(void **state) {
}
/* parse http time stamp */
static void
isc_time_parsehttptimestamp_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_parsehttptimestamp_test) {
isc_result_t result;
isc_time_t t, x;
char buf[ISC_FORMATHTTPTIMESTAMP_SIZE];
@ -153,8 +151,8 @@ isc_time_parsehttptimestamp_test(void **state) {
}
/* print UTC in ISO8601 */
static void
isc_time_formatISO8601_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -189,8 +187,8 @@ isc_time_formatISO8601_test(void **state) {
}
/* print UTC in ISO8601 with milliseconds */
static void
isc_time_formatISO8601ms_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601ms_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -226,8 +224,8 @@ isc_time_formatISO8601ms_test(void **state) {
}
/* print UTC in ISO8601 with microseconds */
static void
isc_time_formatISO8601us_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601us_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -263,8 +261,8 @@ isc_time_formatISO8601us_test(void **state) {
}
/* print local time in ISO8601 */
static void
isc_time_formatISO8601L_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601L_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -298,8 +296,8 @@ isc_time_formatISO8601L_test(void **state) {
}
/* print local time in ISO8601 with milliseconds */
static void
isc_time_formatISO8601Lms_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lms_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -334,8 +332,8 @@ isc_time_formatISO8601Lms_test(void **state) {
}
/* print local time in ISO8601 with microseconds */
static void
isc_time_formatISO8601Lus_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lus_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -370,8 +368,8 @@ isc_time_formatISO8601Lus_test(void **state) {
}
/* print UTC time as yyyymmddhhmmsssss */
static void
isc_time_formatshorttimestamp_test(void **state) {
ISC_RUN_TEST_IMPL(isc_time_formatshorttimestamp_test) {
isc_result_t result;
isc_time_t t;
char buf[64];
@ -399,32 +397,19 @@ isc_time_formatshorttimestamp_test(void **state) {
assert_string_equal(buf, "20151213094640123");
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_time_add_test),
cmocka_unit_test(isc_time_sub_test),
cmocka_unit_test(isc_time_parsehttptimestamp_test),
cmocka_unit_test(isc_time_formatISO8601_test),
cmocka_unit_test(isc_time_formatISO8601ms_test),
cmocka_unit_test(isc_time_formatISO8601us_test),
cmocka_unit_test(isc_time_formatISO8601L_test),
cmocka_unit_test(isc_time_formatISO8601Lms_test),
cmocka_unit_test(isc_time_formatISO8601Lus_test),
cmocka_unit_test(isc_time_formatshorttimestamp_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(isc_time_add_test)
ISC_TEST_ENTRY(isc_time_sub_test)
ISC_TEST_ENTRY(isc_time_parsehttptimestamp_test)
ISC_TEST_ENTRY(isc_time_formatISO8601_test)
ISC_TEST_ENTRY(isc_time_formatISO8601ms_test)
ISC_TEST_ENTRY(isc_time_formatISO8601us_test)
ISC_TEST_ENTRY(isc_time_formatISO8601L_test)
ISC_TEST_ENTRY(isc_time_formatISO8601Lms_test)
ISC_TEST_ENTRY(isc_time_formatISO8601Lus_test)
ISC_TEST_ENTRY(isc_time_formatshorttimestamp_test)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -21,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <uv.h>
#define UNIT_TESTING
#include <cmocka.h>
@ -36,7 +35,8 @@
#include <isc/util.h>
#include "../timer.c"
#include "isctest.h"
#include <isc/test.h>
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
@ -58,24 +58,16 @@ static int nevents;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
/* Timer tests require two worker threads */
result = isc_test_begin(NULL, true, 2);
assert_int_equal(result, ISC_R_SUCCESS);
atomic_init(&errcnt, ISC_R_SUCCESS);
setup_managers(state);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
teardown_managers(state);
return (0);
}
@ -176,7 +168,8 @@ subthread_assert_result_equal(isc_result_t result, isc_result_t expected,
const char *file, unsigned int line) {
if (result != expected) {
printf("# %s:%u subthread_assert_result_equal(%u != %u)\n",
file, line, result, expected);
file, line, (unsigned int)result,
(unsigned int)expected);
set_global_error(result);
}
}
@ -251,8 +244,7 @@ ticktock(isc_task_t *task, isc_event_t *event) {
*/
/* timer type ticker */
static void
ticker(void **state) {
ISC_RUN_TEST_IMPL(ticker) {
isc_interval_t interval;
UNUSED(state);
@ -316,8 +308,7 @@ test_idle(isc_task_t *task, isc_event_t *event) {
}
/* timer type once idles out */
static void
once_idle(void **state) {
ISC_RUN_TEST_IMPL(once_idle) {
isc_interval_t interval;
UNUSED(state);
@ -398,8 +389,7 @@ test_reset(isc_task_t *task, isc_event_t *event) {
}
}
static void
reset(void **state) {
ISC_RUN_TEST_IMPL(reset) {
isc_interval_t interval;
UNUSED(state);
@ -480,8 +470,7 @@ once_event(isc_task_t *task, isc_event_t *event) {
}
/* timer events purged */
static void
purge(void **state) {
ISC_RUN_TEST_IMPL(purge) {
isc_result_t result;
isc_interval_t interval;
@ -520,7 +509,7 @@ purge(void **state) {
* Wait for shutdown processing to complete.
*/
while (!atomic_load(&shutdownflag)) {
isc_test_nap(1000);
uv_sleep(1000);
}
assert_int_equal(atomic_load(&errcnt), ISC_R_SUCCESS);
@ -533,37 +522,12 @@ purge(void **state) {
isc_task_detach(&task2);
}
int
main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(ticker),
cmocka_unit_test(once_idle),
cmocka_unit_test(reset),
cmocka_unit_test(purge),
};
int c;
ISC_TEST_LIST_START
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
verbose = true;
break;
default:
break;
}
}
ISC_TEST_ENTRY_CUSTOM(once_idle, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(reset, _setup, _teardown)
ISC_TEST_ENTRY_CUSTOM(purge, _setup, _teardown)
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_LIST_END
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -6,10 +6,16 @@ AM_CPPFLAGS += \
$(LIBISCCFG_CFLAGS)
LDADD += \
libisccfgtest.la \
$(LIBISC_LIBS) \
$(LIBDNS_LIBS) \
$(LIBISCCFG_LIBS)
check_LTLIBRARIES = libisccfgtest.la
libisccfgtest_la_SOURCES = \
../../isc/test.c \
../../isc/include/isc/test.h
check_PROGRAMS = \
duration_test \
parser_test

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -36,14 +34,8 @@
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
#include <isc/test.h>
isc_mem_t *mctx = NULL;
isc_log_t *lctx = NULL;
static isc_logcategory_t categories[] = { { "", 0 },
{ "client", 0 },
@ -55,23 +47,8 @@ static isc_logcategory_t categories[] = { { "", 0 },
{ "query-errors", 0 },
{ NULL, 0 } };
static void
cleanup(void) {
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
}
static isc_result_t
setup(void) {
ISC_SETUP_TEST_IMPL(group) {
isc_result_t result;
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
isc_mem_create(&mctx);
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
@ -85,13 +62,24 @@ setup(void) {
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
result = isc_log_usechannel(logconfig, "stderr", NULL, NULL);
return (ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS) {
return (-1);
}
cleanup:
cleanup();
return (result);
return (0);
}
ISC_TEARDOWN_TEST_IMPL(group) {
if (lctx == NULL) {
return (-1);
}
isc_log_setcontext(NULL);
isc_log_destroy(&lctx);
return (0);
}
struct duration_conf {
@ -101,8 +89,7 @@ struct duration_conf {
typedef struct duration_conf duration_conf_t;
/* test cfg_obj_asduration() */
static void
cfg_obj_asduration_test(void **state) {
ISC_RUN_TEST_IMPL(cfg_obj_asduration) {
isc_result_t result;
duration_conf_t durations[] = {
{ .string = "PT0S", .time = 0 },
@ -133,10 +120,6 @@ cfg_obj_asduration_test(void **state) {
cfg_parser_t *p1 = NULL;
cfg_obj_t *c1 = NULL;
UNUSED(state);
setup();
for (int i = 0; i < num; i++) {
const cfg_listelt_t *element;
const cfg_obj_t *kasps = NULL;
@ -177,27 +160,12 @@ cfg_obj_asduration_test(void **state) {
cfg_obj_destroy(p1, &c1);
cfg_parser_destroy(&p1);
}
cleanup();
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(cfg_obj_asduration_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY(cfg_obj_asduration)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -38,14 +36,8 @@
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
#include <isc/test.h>
isc_mem_t *mctx = NULL;
isc_log_t *lctx = NULL;
static isc_logcategory_t categories[] = { { "", 0 },
{ "client", 0 },
@ -57,24 +49,8 @@ static isc_logcategory_t categories[] = { { "", 0 },
{ "query-errors", 0 },
{ NULL, 0 } };
static void
cleanup(void) {
if (lctx != NULL) {
isc_log_setcontext(NULL);
isc_log_destroy(&lctx);
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
}
static isc_result_t
setup(void) {
ISC_SETUP_TEST_IMPL(group) {
isc_result_t result;
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
isc_mem_create(&mctx);
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
@ -88,32 +64,22 @@ setup(void) {
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
result = isc_log_usechannel(logconfig, "stderr", NULL, NULL);
return (ISC_R_SUCCESS);
cleanup:
cleanup();
return (result);
}
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = setup();
assert_int_equal(result, ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS) {
return (-1);
}
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
ISC_TEARDOWN_TEST_IMPL(group) {
if (lctx == NULL) {
return (-1);
}
cleanup();
isc_log_setcontext(NULL);
isc_log_destroy(&lctx);
return (0);
}
@ -126,8 +92,7 @@ append(void *arg, const char *str, int len) {
snprintf(buf + l, 1024 - l, "%.*s", len, str);
}
static void
addzoneconf(void **state) {
ISC_RUN_TEST_IMPL(addzoneconf) {
isc_result_t result;
isc_buffer_t b;
cfg_parser_t *p = NULL;
@ -142,8 +107,6 @@ addzoneconf(void **state) {
};
char buf[1024];
UNUSED(state);
/* Parse with default line numbering */
result = cfg_parser_create(mctx, lctx, &p);
assert_int_equal(result, ISC_R_SUCCESS);
@ -182,16 +145,13 @@ addzoneconf(void **state) {
}
/* test cfg_parse_buffer() */
static void
parse_buffer_test(void **state) {
ISC_RUN_TEST_IMPL(parse_buffer) {
isc_result_t result;
unsigned char text[] = "options\n{\nrecursion yes;\n};\n";
isc_buffer_t buf1, buf2;
cfg_parser_t *p1 = NULL, *p2 = NULL;
cfg_obj_t *c1 = NULL, *c2 = NULL;
UNUSED(state);
isc_buffer_init(&buf1, &text[0], sizeof(text) - 1);
isc_buffer_add(&buf1, sizeof(text) - 1);
@ -224,14 +184,11 @@ parse_buffer_test(void **state) {
}
/* test cfg_map_firstclause() */
static void
cfg_map_firstclause_test(void **state) {
ISC_RUN_TEST_IMPL(cfg_map_firstclause) {
const char *name = NULL;
const void *clauses = NULL;
unsigned int idx;
UNUSED(state);
name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx);
assert_non_null(name);
assert_non_null(clauses);
@ -239,14 +196,11 @@ cfg_map_firstclause_test(void **state) {
}
/* test cfg_map_nextclause() */
static void
cfg_map_nextclause_test(void **state) {
ISC_RUN_TEST_IMPL(cfg_map_nextclause) {
const char *name = NULL;
const void *clauses = NULL;
unsigned int idx;
UNUSED(state);
name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx);
assert_non_null(name);
assert_non_null(clauses);
@ -263,26 +217,13 @@ cfg_map_nextclause_test(void **state) {
} while (name != NULL);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(addzoneconf),
cmocka_unit_test(parse_buffer_test),
cmocka_unit_test(cfg_map_firstclause_test),
cmocka_unit_test(cfg_map_nextclause_test),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
ISC_TEST_ENTRY(addzoneconf)
ISC_TEST_ENTRY(parse_buffer)
ISC_TEST_ENTRY(cfg_map_firstclause)
ISC_TEST_ENTRY(cfg_map_nextclause)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)

View File

@ -34,9 +34,11 @@
#include <ns/hooks.h>
#include <ns/interfacemgr.h>
#include <dns/test.h>
typedef struct ns_test_id {
const char *description;
int lineno;
int lineno;
} ns_test_id_t;
#define NS_TEST_ID(desc) \
@ -51,56 +53,24 @@ typedef struct ns_test_id {
goto cleanup; \
} while (0)
extern isc_mem_t *mctx;
extern isc_log_t *lctx;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *maintask;
extern isc_timermgr_t *timermgr;
extern dns_zonemgr_t *zonemgr;
extern dns_dispatchmgr_t *dispatchmgr;
extern ns_clientmgr_t *clientmgr;
extern ns_clientmgr_t *clientmgr;
extern ns_interfacemgr_t *interfacemgr;
extern ns_server_t *sctx;
extern bool app_running;
extern bool debug_mem_record;
extern ns_server_t *sctx;
#ifdef NETMGR_TRACE
#define FLARG \
, const char *file __attribute__((unused)), \
, const char *file __attribute__((unused)), \
unsigned int line __attribute__((unused)), \
const char *func __attribute__((unused))
const char *func __attribute__((unused))
#else
#define FLARG
#endif
isc_result_t
ns_test_begin(FILE *logfile, bool create_managers);
void
ns_test_end(void);
/*%
* Create a view. If "with_cache" is set to true, a cache database will
* also be created and attached to the created view.
*/
isc_result_t
ns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp);
isc_result_t
ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
bool keepview);
isc_result_t
ns_test_setupzonemgr(void);
isc_result_t
ns_test_managezone(dns_zone_t *zone);
void
ns_test_releasezone(dns_zone_t *zone);
void
ns_test_closezonemgr(void);
int
setup_server(void **state);
int
teardown_server(void **state);
/*%
* Load data for zone "zonename" from file "filename" and start serving it to
@ -117,9 +87,6 @@ ns_test_serve_zone(const char *zonename, const char *filename,
void
ns_test_cleanup_zone(void);
void
ns_test_nap(uint32_t usec);
isc_result_t
ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile);
@ -135,10 +102,10 @@ ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp);
* Structure containing parameters for ns_test_qctx_create().
*/
typedef struct ns_test_qctx_create_params {
const char *qname;
const char *qname;
dns_rdatatype_t qtype;
unsigned int qflags;
bool with_cache;
unsigned int qflags;
bool with_cache;
} ns_test_qctx_create_params_t;
/*%
@ -150,7 +117,7 @@ typedef struct ns_test_qctx_create_params {
*/
isc_result_t
ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
query_ctx_t **qctxp);
query_ctx_t **qctxp);
/*%
* Destroy a query context created by ns_test_qctx_create().

View File

@ -19,7 +19,6 @@
#include <time.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
@ -51,25 +50,82 @@
#include <ns/interfacemgr.h>
#include <ns/server.h>
#include "nstest.h"
#include <ns/test.h>
isc_mem_t *mctx = NULL;
isc_log_t *lctx = NULL;
isc_nm_t *netmgr = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_task_t *maintask = NULL;
isc_timermgr_t *timermgr = NULL;
dns_zonemgr_t *zonemgr = NULL;
dns_dispatchmgr_t *dispatchmgr = NULL;
ns_clientmgr_t *clientmgr = NULL;
ns_interfacemgr_t *interfacemgr = NULL;
ns_server_t *sctx = NULL;
bool app_running = false;
bool debug_mem_record = true;
static atomic_bool run_managers = false;
static bool dst_active = false;
static bool test_running = false;
static isc_result_t
matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
dns_message_t *message, dns_aclenv_t *env, isc_result_t *sigresultp,
dns_view_t **viewp) {
UNUSED(srcaddr);
UNUSED(destaddr);
UNUSED(message);
UNUSED(env);
UNUSED(sigresultp);
UNUSED(viewp);
return (ISC_R_NOTIMPLEMENTED);
}
int
setup_server(void **state) {
isc_result_t result;
ns_listenlist_t *listenon = NULL;
in_port_t port = 5300 + isc_random8();
setup_managers(state);
ns_server_create(mctx, matchview, &sctx);
result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr);
if (result != ISC_R_SUCCESS) {
return (-1);
}
result = ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, netmgr,
dispatchmgr, maintask, NULL, false,
&interfacemgr);
if (result != ISC_R_SUCCESS) {
return (-1);
}
result = ns_listenlist_default(mctx, port, -1, true, AF_INET,
&listenon);
if (result != ISC_R_SUCCESS) {
return (-1);
}
ns_interfacemgr_setlistenon4(interfacemgr, listenon);
ns_listenlist_detach(&listenon);
clientmgr = ns_interfacemgr_getclientmgr(interfacemgr);
return (0);
}
int
teardown_server(void **state) {
if (interfacemgr != NULL) {
ns_interfacemgr_shutdown(interfacemgr);
ns_interfacemgr_detach(&interfacemgr);
}
if (dispatchmgr != NULL) {
dns_dispatchmgr_detach(&dispatchmgr);
}
if (sctx != NULL) {
ns_server_detach(&sctx);
}
teardown_managers(state);
return (0);
}
static dns_zone_t *served_zone = NULL;
@ -124,359 +180,6 @@ isc__nmhandle_detach(isc_nmhandle_t **handlep FLARG) {
return;
}
/*
* Logging categories: this needs to match the list in lib/ns/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 } };
static isc_result_t
matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
dns_message_t *message, dns_aclenv_t *env, isc_result_t *sigresultp,
dns_view_t **viewp) {
UNUSED(srcaddr);
UNUSED(destaddr);
UNUSED(message);
UNUSED(env);
UNUSED(sigresultp);
UNUSED(viewp);
return (ISC_R_NOTIMPLEMENTED);
}
/*
* These need to be shut down from a running task.
*/
static atomic_bool shutdown_done = false;
static void
shutdown_managers(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
isc_event_free(&event);
if (interfacemgr != NULL) {
ns_interfacemgr_shutdown(interfacemgr);
ns_interfacemgr_detach(&interfacemgr);
}
if (dispatchmgr != NULL) {
dns_dispatchmgr_detach(&dispatchmgr);
}
atomic_store(&shutdown_done, true);
atomic_store(&run_managers, false);
}
static void
cleanup_managers(void) {
atomic_store(&shutdown_done, false);
if (maintask != NULL) {
isc_event_t *event = isc_event_allocate(
mctx, NULL, ISC_TASKEVENT_TEST, shutdown_managers, NULL,
sizeof(*event));
isc_task_send(maintask, &event);
isc_task_detach(&maintask);
}
while (atomic_load(&run_managers) && !atomic_load(&shutdown_done)) {
/*
* There's no straightforward way to determine
* whether all the clients have shut down, so
* we'll just sleep for a bit and hope.
*/
ns_test_nap(500000);
}
if (sctx != NULL) {
ns_server_detach(&sctx);
}
if (interfacemgr != NULL) {
ns_interfacemgr_detach(&interfacemgr);
}
isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
taskmgr == NULL ? NULL : &taskmgr,
timermgr == NULL ? NULL : &timermgr);
if (app_running) {
isc_app_finish();
}
}
static void
scan_interfaces(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
ns_interfacemgr_scan(interfacemgr, true, false);
isc_event_free(&event);
}
static isc_result_t
create_managers(void) {
isc_result_t result;
in_port_t port = 5300 + isc_random8();
ns_listenlist_t *listenon = NULL;
isc_event_t *event = NULL;
int ncpus = isc_os_ncpus();
isc_managers_create(mctx, ncpus, 0, &netmgr, &taskmgr, &timermgr);
CHECK(isc_task_create(taskmgr, 0, &maintask, 0));
isc_taskmgr_setexcltask(taskmgr, maintask);
CHECK(ns_server_create(mctx, matchview, &sctx));
CHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, netmgr,
dispatchmgr, maintask, NULL, false,
&interfacemgr));
CHECK(ns_listenlist_default(mctx, port, -1, true, AF_INET, &listenon));
ns_interfacemgr_setlistenon4(interfacemgr, listenon);
ns_listenlist_detach(&listenon);
event = isc_event_allocate(mctx, maintask, ISC_TASKEVENT_TEST,
scan_interfaces, NULL, sizeof(isc_event_t));
isc_task_send(maintask, &event);
clientmgr = ns_interfacemgr_getclientmgr(interfacemgr);
atomic_store(&run_managers, true);
return (ISC_R_SUCCESS);
cleanup:
cleanup_managers();
return (result);
}
isc_result_t
ns_test_begin(FILE *logfile, bool start_managers) {
isc_result_t result;
INSIST(!test_running);
test_running = true;
if (start_managers) {
isc_resourcevalue_t files;
/*
* The 'listenlist_test', 'notify_test', and 'query_test'
* tests need more than 256 descriptors with 8 cpus.
* Bump up to at least 1024.
*/
result = isc_resource_getcurlimit(isc_resource_openfiles,
&files);
if (result == ISC_R_SUCCESS) {
if (files < 1024) {
files = 1024;
(void)isc_resource_setlimit(
isc_resource_openfiles, files);
}
}
CHECK(isc_app_start());
}
if (debug_mem_record) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
}
INSIST(mctx == NULL);
isc_mem_create(&mctx);
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);
isc_log_create(mctx, &lctx, &logconfig);
isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
destination.file.stream = logfile;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination, 0);
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
}
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_DIR) == -1) {
CHECK(ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
cleanup:
ns_test_end();
return (result);
}
void
ns_test_end(void) {
cleanup_managers();
dst_lib_destroy();
dst_active = false;
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
test_running = false;
}
isc_result_t
ns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) {
dns_cache_t *cache = NULL;
dns_view_t *view = NULL;
isc_result_t result;
CHECK(dns_view_create(mctx, dns_rdataclass_in, name, &view));
if (with_cache) {
CHECK(dns_cache_create(mctx, mctx, taskmgr, timermgr,
dns_rdataclass_in, "", "rbt", 0, NULL,
&cache));
dns_view_setcache(view, cache, false);
/*
* Reference count for "cache" is now at 2, so decrement it in
* order for the cache to be automatically freed when "view"
* gets freed.
*/
dns_cache_detach(&cache);
}
*viewp = view;
return (ISC_R_SUCCESS);
cleanup:
if (view != NULL) {
dns_view_detach(&view);
}
return (result);
}
/*
* 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
ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
bool 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 = true;
}
zone = *zonep;
if (zone == NULL) {
CHECK(dns_zone_create(&zone, mctx, 0));
}
isc_buffer_constinit(&buffer, name, strlen(name));
isc_buffer_add(&buffer, strlen(name));
origin = dns_fixedname_initname(&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_primary);
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
ns_test_setupzonemgr(void) {
isc_result_t result;
REQUIRE(zonemgr == NULL);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr);
return (result);
}
isc_result_t
ns_test_managezone(dns_zone_t *zone) {
isc_result_t result;
REQUIRE(zonemgr != NULL);
result = dns_zonemgr_managezone(zonemgr, zone);
return (result);
}
void
ns_test_releasezone(dns_zone_t *zone) {
REQUIRE(zonemgr != NULL);
dns_zonemgr_releasezone(zonemgr, zone);
}
void
ns_test_closezonemgr(void) {
REQUIRE(zonemgr != NULL);
dns_zonemgr_shutdown(zonemgr);
dns_zonemgr_detach(&zonemgr);
}
isc_result_t
ns_test_serve_zone(const char *zonename, const char *filename,
dns_view_t *view) {
@ -486,7 +189,7 @@ ns_test_serve_zone(const char *zonename, const char *filename,
/*
* Prepare zone structure for further processing.
*/
result = ns_test_makezone(zonename, &served_zone, view, true);
result = dns_test_makezone(zonename, &served_zone, view, false);
if (result != ISC_R_SUCCESS) {
return (result);
}
@ -494,7 +197,7 @@ ns_test_serve_zone(const char *zonename, const char *filename,
/*
* Start zone manager.
*/
result = ns_test_setupzonemgr();
result = dns_test_setupzonemgr();
if (result != ISC_R_SUCCESS) {
goto free_zone;
}
@ -502,7 +205,7 @@ ns_test_serve_zone(const char *zonename, const char *filename,
/*
* Add the zone to the zone manager.
*/
result = ns_test_managezone(served_zone);
result = dns_test_managezone(served_zone);
if (result != ISC_R_SUCCESS) {
goto close_zonemgr;
}
@ -533,9 +236,9 @@ ns_test_serve_zone(const char *zonename, const char *filename,
return (ISC_R_SUCCESS);
release_zone:
ns_test_releasezone(served_zone);
dns_test_releasezone(served_zone);
close_zonemgr:
ns_test_closezonemgr();
dns_test_closezonemgr();
free_zone:
dns_zone_detach(&served_zone);
@ -544,8 +247,8 @@ free_zone:
void
ns_test_cleanup_zone(void) {
ns_test_releasezone(served_zone);
ns_test_closezonemgr();
dns_test_releasezone(served_zone);
dns_test_closezonemgr();
dns_zone_detach(&served_zone);
}
@ -776,7 +479,7 @@ ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
/*
* Every client needs to belong to a view.
*/
result = ns_test_makeview("view", params->with_cache, &client->view);
result = dns_test_makeview("view", params->with_cache, &client->view);
if (result != ISC_R_SUCCESS) {
goto detach_client;
}
@ -860,18 +563,6 @@ ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp) {
return (NS_HOOK_RETURN);
}
/*
* Sleep for 'usec' microseconds.
*/
void
ns_test_nap(uint32_t usec) {
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
}
isc_result_t
ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile) {

View File

@ -12,9 +12,13 @@ LDADD += \
$(LIBNS_LIBS)
check_LTLIBRARIES = libnstest.la
libnstest_la_SOURCES = \
nstest.c \
nstest.h
libnstest_la_SOURCES = \
../../isc/test.c \
../../isc/include/isc/test.h \
../../dns/test.c \
../../dns/include/dns/test.h \
../../ns/test.c \
../../ns/include/ns/test.h
check_PROGRAMS = \
listenlist_test \

View File

@ -11,10 +11,6 @@
* information regarding copyright ownership.
*/
#include <isc/util.h>
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -24,6 +20,8 @@
#include <string.h>
#include <unistd.h>
#include <isc/util.h>
#define UNIT_TESTING
#include <cmocka.h>
@ -35,36 +33,28 @@
#include <ns/listenlist.h>
#include "nstest.h"
#include <ns/test.h>
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
isc__nm_force_tid(0);
result = ns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
setup_managers(state);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc__nm_force_tid(-1);
ns_test_end();
teardown_managers(state);
return (0);
}
/* test that ns_listenlist_default() works */
static void
ns_listenlist_default_test(void **state) {
ISC_RUN_TEST_IMPL(ns_listenlist_default) {
isc_result_t result;
in_port_t port = 5300 + isc_random8();
ns_listenlist_t *list = NULL;
@ -120,25 +110,10 @@ ns_listenlist_default_test(void **state) {
ns_listenlist_detach(&list);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(ns_listenlist_default_test,
_setup, _teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(ns_listenlist_default, _setup, _teardown)
#else /* HAVE_CMOCKA */
ISC_TEST_LIST_END
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,10 +11,6 @@
* information regarding copyright ownership.
*/
#include <isc/util.h>
#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
@ -24,6 +20,8 @@
#include <string.h>
#include <unistd.h>
#include <isc/util.h>
#define UNIT_TESTING
#include <cmocka.h>
@ -39,31 +37,20 @@
#include <ns/client.h>
#include <ns/notify.h>
#include "nstest.h"
#include <dns/test.h>
#include <ns/test.h>
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
setup_test(void **state) {
isc__nm_force_tid(0);
result = ns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
return (setup_server(state));
}
static int
_teardown(void **state) {
UNUSED(state);
teardown_test(void **state) {
isc__nm_force_tid(-1);
ns_test_end();
return (0);
return (teardown_server(state));
}
static void
@ -88,8 +75,7 @@ check_response(isc_buffer_t *buf) {
}
/* test ns_notify_start() */
static void
notify_start(void **state) {
ISC_RUN_TEST_IMPL(ns_notify_start) {
isc_result_t result;
ns_client_t *client = NULL;
isc_nmhandle_t *handle = NULL;
@ -103,7 +89,7 @@ notify_start(void **state) {
result = ns_test_getclient(NULL, false, &client);
assert_int_equal(result, ISC_R_SUCCESS);
result = ns_test_makeview("view", false, &client->view);
result = dns_test_makeview("view", false, &client->view);
assert_int_equal(result, ISC_R_SUCCESS);
result = ns_test_serve_zone("example.com", "testdata/notify/zone1.db",
@ -148,24 +134,8 @@ notify_start(void **state) {
isc_nmhandle_detach(&handle);
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(notify_start, _setup,
_teardown),
};
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(ns_notify_start, setup_test, teardown_test)
ISC_TEST_LIST_END
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,8 +11,6 @@
* information regarding copyright ownership.
*/
#if HAVE_CMOCKA
#include <limits.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -37,30 +35,7 @@ _fail(const char *const file, const int line);
#include <ns/hooks.h>
#include "nstest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = ns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
if (*state != NULL) {
isc_mem_free(mctx, *state);
}
ns_test_end();
return (0);
}
#include <ns/test.h>
/*%
* Structure containing parameters for run_full_path_test().
@ -125,8 +100,7 @@ run_full_path_test(const ns_plugin_expandpath_test_params_t *test,
}
/* test ns_plugin_expandpath() */
static void
ns_plugin_expandpath_test(void **state) {
ISC_RUN_TEST_IMPL(ns_plugin_expandpath) {
size_t i;
const ns_plugin_expandpath_test_params_t tests[] = {
@ -182,23 +156,10 @@ ns_plugin_expandpath_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(ns_plugin_expandpath_test,
_setup, _teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
ISC_TEST_ENTRY_CUSTOM(ns_plugin_expandpath, setup_managers, teardown_managers)
#include <stdio.h>
ISC_TEST_LIST_END
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* if HAVE_CMOCKA */
ISC_TEST_MAIN

View File

@ -11,10 +11,6 @@
* information regarding copyright ownership.
*/
#include <isc/util.h>
#if HAVE_CMOCKA
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
@ -24,6 +20,8 @@
#include <stdlib.h>
#include <string.h>
#include <isc/util.h>
#define UNIT_TESTING
#include <cmocka.h>
@ -40,30 +38,19 @@
#include <ns/server.h>
#include <ns/stats.h>
#include "nstest.h"
#include <ns/test.h>
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
setup_test(void **state) {
isc__nm_force_tid(0);
result = ns_test_begin(NULL, true);
assert_int_equal(result, ISC_R_SUCCESS);
setup_server(state);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
teardown_test(void **state) {
isc__nm_force_tid(-1);
ns_test_end();
teardown_server(state);
return (0);
}
@ -183,8 +170,7 @@ run_sfcache_test(const ns__query_sfcache_test_params_t *test) {
}
/* test ns__query_sfcache() */
static void
ns__query_sfcache_test(void **state) {
ISC_RUN_TEST_IMPL(ns_query_sfcache) {
size_t i;
const ns__query_sfcache_test_params_t tests[] = {
@ -326,6 +312,7 @@ run_start_test(const ns__query_start_test_params_t *test) {
/*
* Interrupt execution if query_lookup() or ns_query_done() is called.
*/
ns_hooktable_create(mctx, &query_hooks);
ns_hook_add(query_hooks, mctx, NS_QUERY_LOOKUP_BEGIN, &hook);
ns_hook_add(query_hooks, mctx, NS_QUERY_DONE_BEGIN, &hook);
@ -447,8 +434,7 @@ run_start_test(const ns__query_start_test_params_t *test) {
}
/* test ns__query_start() */
static void
ns__query_start_test(void **state) {
ISC_RUN_TEST_IMPL(ns_query_start) {
size_t i;
const ns__query_start_test_params_t tests[] = {
@ -1027,8 +1013,7 @@ run_hookasync_test(const ns__query_hookasync_test_params_t *test) {
}
}
static void
ns__query_hookasync_test(void **state) {
ISC_RUN_TEST_IMPL(ns_query_hookasync) {
size_t i;
UNUSED(state);
@ -1461,8 +1446,7 @@ run_hookasync_e2e_test(const ns__query_hookasync_e2e_test_params_t *test) {
ns_hooktable_free(mctx, (void **)&ns__hook_table);
}
static void
ns__query_hookasync_e2e_test(void **state) {
ISC_RUN_TEST_IMPL(ns_query_hookasync_e2e) {
UNUSED(state);
const ns__query_hookasync_e2e_test_params_t tests[] = {
@ -1505,31 +1489,12 @@ ns__query_hookasync_e2e_test(void **state) {
}
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(ns__query_sfcache_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(ns__query_start_test, _setup,
_teardown),
cmocka_unit_test_setup_teardown(ns__query_hookasync_test,
_setup, _teardown),
cmocka_unit_test_setup_teardown(ns__query_hookasync_e2e_test,
_setup, _teardown),
};
ISC_TEST_LIST_START
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ISC_TEST_ENTRY_CUSTOM(ns_query_sfcache, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(ns_query_start, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(ns_query_hookasync, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(ns_query_hookasync_e2e, setup_test, teardown_test)
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (SKIPPED_TEST_EXIT_CODE);
}
#endif /* HAVE_CMOCKA */
ISC_TEST_LIST_END
ISC_TEST_MAIN