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)/'
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/'
#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 \
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
#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>
#include <dns/view.h>
#include <dns/zone.h>
-#include "dnstest.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;
+#include <dns/test.h>
-static bool dst_active = false;
-static bool test_running = false;
+dns_zonemgr_t *zonemgr = NULL;
/*
- * Logging categories: this needs to match the list in bin/named/log.c.
+ * Create a view.
*/
-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_shutdown(maintask);
- isc_task_destroy(&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));
- return (ISC_R_SUCCESS);
-
-cleanup:
- cleanup_managers();
- return (result);
-}
-
isc_result_t
-dns_test_begin(FILE *logfile, bool start_managers) {
+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;
- 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);
+ result = dns_view_create(mctx, dns_rdataclass_in, name, &view);
+ if (result != ISC_R_SUCCESS) {
+ return (result);
}
- 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 (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);
+ }
- if (dt_mctx != NULL) {
- isc_mem_destroy(&dt_mctx);
+ 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);
}
- test_running = false;
-}
-
-/*
- * Create a view.
- */
-isc_result_t
-dns_test_makeview(const char *name, dns_view_t **viewp) {
- isc_result_t result;
- dns_view_t *view = NULL;
-
- 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
/*
* Create the zone structure.
*/
- result = dns_zone_create(&zone, dt_mctx);
+ result = dns_zone_create(&zone, mctx);
if (result != ISC_R_SUCCESS) {
return (result);
}
* 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;
}
isc_result_t result;
REQUIRE(zonemgr == NULL);
- result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL, &zonemgr);
+ result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr);
return (result);
}
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);
}
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) {
}
}
- *sizep = bp - buf;
-
- result = ISC_R_SUCCESS;
+ if (result == ISC_R_SUCCESS) {
+ *sizep = bp - buf;
+ }
-cleanup:
isc_stdio_close(f);
return (result);
}
/*
* 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);
}
* 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);
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);
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;
}
* 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;
return (result);
}
-#endif /* HAVE_CMOCKA */
$(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 \
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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, ¬none);
+ result = dns_acl_create(mctx, 1, ¬none);
assert_int_equal(result, ISC_R_SUCCESS);
- result = dns_acl_create(dt_mctx, 1, ¬any);
+ result = dns_acl_create(mctx, 1, ¬any);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_merge(notnone, none, false);
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;
de->node_num = dns_acl_node_count(geoip);
geoip->length++;
- result = dns_acl_create(dt_mctx, 1, ¬geoip);
+ result = dns_acl_create(mctx, 1, ¬geoip);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_acl_merge(notgeoip, geoip, false);
#endif /* HAVE_GEOIP2 */
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(dns_acl_isinsecure_test, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(dns_acl_isinsecure)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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)
*/
/* 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);
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);
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;
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);
}
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);
}
/* 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,
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,
}
/* 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;
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),
- };
-
- 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);
-}
+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
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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) {
}
/* 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;
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);
}
/* 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;
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);
}
/* 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;
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);
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),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(diffx_same)
+ISC_TEST_ENTRY(diffx_add)
+ISC_TEST_ENTRY(diffx_remove)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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");
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);
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");
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);
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");
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");
* 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),
- };
-
- 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_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
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
}
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);
}
static int
-_teardown(void **state) {
+teardown_test(void **state) {
UNUSED(state);
if (strcmp(tempname, "dtXXXXXXXX") != 0) {
assert_null(db2);
}
- dns_test_end();
-
return (0);
}
* 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);
* 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);
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
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),
- };
-
- 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_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
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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];
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);
dst_key_free(&key);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(dh_computesecret, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(dh_computesecret, setup_test, teardown_test)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <dns/name.h>
#include <dns/view.h>
-#include "dnstest.h"
+#include <dns/test.h>
uv_sem_t sem;
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);
}
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);
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);
}
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);
}
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);
}
/* create dispatch set */
-static void
-dispatchset_create(void **state) {
+ISC_RUN_TEST_IMPL(dispatchset_create) {
isc_result_t result;
UNUSED(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;
UNUSED(eresult);
UNUSED(cbarg);
- fprintf(stderr, "%s(..., %s, ...)\n", __func__,
- isc_result_totext(eresult));
-
return;
}
UNUSED(region);
UNUSED(arg);
- fprintf(stderr, "%s(..., %s, ...)\n", __func__,
- isc_result_totext(eresult));
-
switch (eresult) {
case ISC_R_EOF:
case ISC_R_CANCELED:
UNUSED(region);
UNUSED(arg);
- fprintf(stderr, "%s(..., %s, ...)\n", __func__,
- isc_result_totext(eresult));
-
atomic_store_relaxed(&testdata.result, eresult);
uv_sem_post(&sem);
UNUSED(eresult);
UNUSED(region);
- fprintf(stderr, "%s(..., %s, ...)\n", __func__,
- isc_result_totext(eresult));
-
dns_dispatch_send(dispentry, r, -1);
}
UNUSED(region);
UNUSED(cbarg);
- fprintf(stderr, "%s(..., %s, ...)\n", __func__,
- isc_result_totext(eresult));
-
return;
}
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 };
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,
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 };
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,
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 };
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,
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 };
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,
}
/* 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;
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,
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+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)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
+#include <dns/test.h>
+
static void
multiple_prefixes(void) {
size_t i, count;
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 {
ISC_R_NOTFOUND },
};
- UNUSED(state);
-
for (i = 0; i < ARRAY_SIZE(tests); i++) {
size_t count = 2;
dns_rdataset_t rdataset;
multiple_prefixes();
}
-int
-main(void) {
- const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(
- dns64_findprefix, NULL, NULL) };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(dns64_findprefix)
+ISC_TEST_LIST_END
-#endif
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#define UNIT_TESTING
#include <cmocka.h>
+#include <fstrm.h>
+
+#include <protobuf-c/protobuf-c.h>
#include <isc/buffer.h>
#include <isc/file.h>
#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"
#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) {
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) {
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) {
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;
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);
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);
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) {
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++;
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;
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);
}
/* 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;
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
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <dst/dst.h>
#include "../dst_internal.h"
-#include "dnstest.h"
-static int
-_setup(void **state) {
- isc_result_t result;
+#include <dns/test.h>
+static int
+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);
}
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;
result = ISC_R_SUCCESS;
err:
- isc_mem_put(dt_mctx, data, size + 1);
+ isc_mem_put(mctx, data, size + 1);
return (result);
}
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;
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);
*/
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);
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);
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);
return;
}
-static void
-sig_test(void **state) {
- UNUSED(state);
-
+ISC_RUN_TEST_IMPL(sig_test) {
struct {
const char *datapath;
const char *sigpath;
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);
/*
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);
/*
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;
}
}
-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),
- };
-
- 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);
-}
+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
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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"
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);
}
static int
-_teardown(void **state) {
+teardown_test(void **state) {
UNUSED(state);
close_geoip();
- dns_test_end();
-
return (0);
}
* 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);
}
/* GeoIP country matching */
-static void
-country(void **state) {
+ISC_RUN_TEST_IMPL(country) {
bool match;
UNUSED(state);
}
/* GeoIP country (ipv6) matching */
-static void
-country_v6(void **state) {
+ISC_RUN_TEST_IMPL(country_v6) {
bool match;
UNUSED(state);
}
/* GeoIP city (ipv4) matching */
-static void
-city(void **state) {
+ISC_RUN_TEST_IMPL(city) {
bool match;
UNUSED(state);
}
/* GeoIP city (ipv6) matching */
-static void
-city_v6(void **state) {
+ISC_RUN_TEST_IMPL(city_v6) {
bool match;
UNUSED(state);
}
/* GeoIP asnum matching */
-static void
-asnum(void **state) {
+ISC_RUN_TEST_IMPL(asnum) {
bool match;
UNUSED(state);
}
/* GeoIP isp matching */
-static void
-isp(void **state) {
+ISC_RUN_TEST_IMPL(isp) {
bool match;
UNUSED(state);
}
/* GeoIP org matching */
-static void
-org(void **state) {
+ISC_RUN_TEST_IMPL(org) {
bool match;
UNUSED(state);
}
/* GeoIP domain matching */
-static void
-domain(void **state) {
+ISC_RUN_TEST_IMPL(domain) {
bool match;
UNUSED(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),
- };
-
- 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_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
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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;
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;
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);
}
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);
}
/* 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];
}
/* 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 */
}
/* 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);
}
/* 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;
}
/* 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",
}
/* 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);
}
/* 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;
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);
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);
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),
- };
-
- return (cmocka_run_group_tests(tests, _setup, _teardown));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+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)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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, ...) {
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);
}
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);
* 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);
* 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);
* 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);
* 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);
* 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);
* 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);
* 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);
* 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);
* Include test:
* dns_master_loadfile() understands $INCLUDE
*/
-static void
-include_test(void **state) {
+ISC_RUN_TEST_IMPL(include) {
isc_result_t result;
UNUSED(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;
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);
}
}
* 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);
* 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);
* 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);
}
/* 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;
* 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);
* 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;
&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);
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,
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,
* 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);
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),
- };
-
- 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_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
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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;
}
/* 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;
/* 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);
/* 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);
/* 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);
/* 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);
/* 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);
/* 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);
}
/* 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;
}
/* dns_nane_init */
-static void
-init_test(void **state) {
+ISC_RUN_TEST_IMPL(init) {
dns_name_t name;
unsigned char offsets[1];
}
/* dns_nane_invalidate */
-static void
-invalidate_test(void **state) {
+ISC_RUN_TEST_IMPL(invalidate) {
dns_name_t name;
unsigned char offsets[1];
}
/* 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;
}
/* dns_nane_isabsolute */
-static void
-isabsolute_test(void **state) {
+ISC_RUN_TEST_IMPL(isabsolute) {
struct {
const char *namestr;
bool expect;
}
/* dns_nane_hash */
-static void
-hash_test(void **state) {
+ISC_RUN_TEST_IMPL(hash) {
struct {
const char *name1;
const char *name2;
}
/* dns_nane_issubdomain */
-static void
-issubdomain_test(void **state) {
+ISC_RUN_TEST_IMPL(issubdomain) {
struct {
const char *name1;
const char *name2;
}
/* dns_nane_countlabels */
-static void
-countlabels_test(void **state) {
+ISC_RUN_TEST_IMPL(countlabels) {
struct {
const char *namestr;
unsigned int expect;
}
/* dns_nane_getlabel */
-static void
-getlabel_test(void **state) {
+ISC_RUN_TEST_IMPL(getlabel) {
struct {
const char *name1;
unsigned int pos1;
}
/* dns_nane_getlabelsequence */
-static void
-getlabelsequence_test(void **state) {
+ISC_RUN_TEST_IMPL(getlabelsequence) {
struct {
const char *name1;
unsigned int pos1;
/* 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',
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;
#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;
-
- 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);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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) {
* 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);
}
/* 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[] = {
}
}
-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),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(max_iterations)
+ISC_TEST_ENTRY(nsec3param_salttotext)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <dns/nsec3.h>
#include "../zone_p.h"
-#include "dnstest.h"
+
+#include <dns/test.h>
#define HASH 1
#define FLAGS 0
#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().
*/
dns_zone_detach(&zone);
}
-static void
-nsec3param_change(void **state) {
+ISC_RUN_TEST_IMPL(nsec3param_change) {
size_t i;
/*
}
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(nsec3param_change, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(nsec3param_change)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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);
/*
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(dscp)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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);
}
}
/* 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;
}
/* 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;
}
}
-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),
- };
-
- 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);
-}
+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
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
#define UNIT_TESTING
#include <cmocka.h>
-#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <dst/dst.h>
-#include "dnstest.h"
+#include <dns/test.h>
typedef struct {
dns_rbt_t *rbt;
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 *
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++) {
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);
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));
}
/*
}
/* 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();
}
/* 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();
}
/* 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";
dns_rbtnode_t *node = NULL;
dns_rbtnodechain_t chain;
- UNUSED(state);
-
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
* 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. */
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;
* 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. */
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;
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();
* 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;
/*
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. */
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;
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 */
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;
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;
* 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;
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);
for (i = 0; i < 1024; i++) {
if (names[i] != NULL) {
- isc_mem_free(dt_mctx, names[i]);
+ isc_mem_free(mctx, names[i]);
}
}
}
/* 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();
}
/* 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;
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();
}
/* 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;
dns_rbtnode_t *node = NULL;
dns_rbtnodechain_t chain;
- UNUSED(state);
-
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
ctx = test_context_setup();
}
/* 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();
}
/* 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;
unsigned int nthreads;
isc_thread_t threads[32];
- UNUSED(state);
-
srandom(time(NULL));
debug_mem_record = false;
/* 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. */
}
#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));
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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] = {
{
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++) {
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 };
assert_true(dns_name_caseequal(name1, name2));
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(ownercase_test),
- cmocka_unit_test(setownercase_test),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(ownercase)
+ISC_TEST_ENTRY(setownercase)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <dns/rdata.h>
-#include "dnstest.h"
+#include <dns/test.h>
static bool debug = false;
};
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().
*/
/*
* 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);
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);
/*
}
}
- isc_mem_free(dt_mctx, rdata_struct);
+ isc_mem_free(mctx, rdata_struct);
}
/*
}
/* APL RDATA manipulations */
-static void
-apl(void **state) {
+ISC_RUN_TEST_IMPL(apl) {
text_ok_t text_ok[] = {
/* empty list */
TEXT_VALID(""),
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t));
}
*
* 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"),
/*
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 */
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));
}
* 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"),
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));
}
* 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.
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_doa, sizeof(dns_rdata_doa_t));
}
* 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.
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_ds, sizeof(dns_rdata_ds_t));
}
* 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.
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_opt, sizeof(dns_rdata_opt_t));
}
* 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"),
*/
WIRE_SENTINEL() };
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t));
}
/*
* 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 "
isc_result_t result;
size_t i;
- UNUSED(state);
-
/*
* Fill the rest of input buffer with compression pointers.
*/
* 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[] = { /*
* "".
*/
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t));
}
/*
* KEY tests.
*/
-static void
-key(void **state) {
+ISC_RUN_TEST_IMPL(key) {
wire_ok_t wire_ok[] = { /*
* RDATA is comprised of:
*
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_key, sizeof(dns_rdata_key_t));
}
/*
* 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"),
TEXT_SENTINEL()
};
- UNUSED(state);
-
check_rdata(text_ok, 0, NULL, false, dns_rdataclass_in,
dns_rdatatype_loc, sizeof(dns_rdata_loc_t));
}
* 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"),
*/
WIRE_SENTINEL() };
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t));
}
* 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),
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));
}
*
* RFC 5155.
*/
-static void
-nsec3(void **state) {
+ISC_RUN_TEST_IMPL(nsec3) {
text_ok_t text_ok[] = { TEXT_INVALID(""),
TEXT_INVALID("."),
TEXT_INVALID(". RRSIG"),
"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),
/*
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.
*/
}
/* 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 */
WIRE_SENTINEL()
};
- UNUSED(state);
-
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_sshfp, sizeof(dns_rdata_sshfp_t));
}
* 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.
*/
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.
{ 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,
*
*/
-static void
-zonemd(void **state) {
+ISC_RUN_TEST_IMPL(zonemd) {
text_ok_t text_ok[] = {
TEXT_INVALID(""),
/* No digest scheme or digest type*/
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);
#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);
#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);
#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(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;
-
- memset(selected, 0, sizeof(selected));
-
- 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;
- }
- }
-
- 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_LIST_START
+
+/* 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)
+
+/* other tests */
+ISC_TEST_ENTRY(edns_client_subnet)
+ISC_TEST_ENTRY(atcname)
+ISC_TEST_ENTRY(atparent)
+ISC_TEST_ENTRY(iszonecutauth)
+ISC_TEST_LIST_END
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
assert_int_equal(sigrdataset.ttl, 0);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(trimttl)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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) {
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. */
* 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),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(active_stale_ancient)
+ISC_TEST_ENTRY(active_ancient)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
isc_result_t result;
isc_sockaddr_t local;
- UNUSED(state);
-
- result = dns_test_begin(NULL, true);
- assert_int_equal(result, ISC_R_SUCCESS);
+ setup_managers(state);
- result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
+ result = dns_dispatchmgr_create(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);
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);
}
}
/* dns_resolver_create */
-static void
-create_test(void **state) {
+ISC_RUN_TEST_IMPL(dns_resolver_create) {
dns_resolver_t *resolver = NULL;
UNUSED(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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+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)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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);
}
};
/* 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;
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);
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);
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);
dst_key_free(&key);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(isc_rsa_verify_test, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(isc_rsa_verify, setup_test, teardown_test)
+ISC_TEST_LIST_END
-#endif /* HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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
* */
} 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'.
* 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));
/*
* 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.
}
/* 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;
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);
dns_zone_detach(&zone);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(updatesigs_next_test, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(updatesigs_next, setup_test, teardown_test)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
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),
- };
-
- 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);
-}
+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
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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;
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);
}
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);
}
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);
} while (result == ISC_R_NOSPACE);
if (buf != NULL) {
- isc_mem_put(dt_mctx, buf, len);
+ isc_mem_put(mctx, buf, len);
}
}
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;
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);
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);
}
* 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;
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);
/*
* 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);
*/
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;
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);
/*
* 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);
/*
* 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;
/*
* 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);
/*
* 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;
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);
}
/* 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));
}
/* 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),
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 */
}
/* Tests the dns__tsig_algallocated function */
-static void
-algallocated_test(void **state) {
+ISC_RUN_TEST_IMPL(algallocated) {
UNUSED(state);
/* test the standard algorithms */
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),
- };
-
- 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);
-}
+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
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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
}
/* simple increment by 1 */
-static void
-increment_test(void **state) {
+ISC_RUN_TEST_IMPL(increment) {
uint32_t old = 50;
uint32_t serial;
}
/* 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;
}
/* past to unixtime */
-static void
-past_to_unix_test(void **state) {
+ISC_RUN_TEST_IMPL(past_to_unix) {
uint32_t old;
uint32_t serial;
}
/* now to unixtime */
-static void
-now_to_unix_test(void **state) {
+ISC_RUN_TEST_IMPL(now_to_unix) {
uint32_t old;
uint32_t serial;
}
/* future to unixtime */
-static void
-future_to_unix_test(void **state) {
+ISC_RUN_TEST_IMPL(future_to_unix) {
uint32_t old;
uint32_t serial;
}
/* 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;
}
/* 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;
}
/* undefined to unixtime */
-static void
-undefined_to_unix_test(void **state) {
+ISC_RUN_TEST_IMPL(undefined_to_unix) {
uint32_t old;
uint32_t serial;
}
/* handle unixtime being zero */
-static void
-unixtime_zero_test(void **state) {
+ISC_RUN_TEST_IMPL(unixtime_zero) {
uint32_t old;
uint32_t serial;
}
/* 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;
}
/* 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;
}
/* 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;
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),
- };
-
- 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_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
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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, NULL,
+ result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
}
/* 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, NULL,
+ result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
}
/* 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, NULL,
+ result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
}
/* 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;
TIME_NOW(&now);
- result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL,
+ result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr,
&myzonemgr);
assert_int_equal(result, ISC_R_SUCCESS);
* - 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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+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)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
}
/* 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;
}
/* 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;
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) {
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();
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();
}
/* 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;
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) {
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+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)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
--- /dev/null
+/*
+ * 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); \
+ }
--- /dev/null
+/*
+ * 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_bound(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);
+}
include $(top_srcdir)/Makefile.top
AM_CPPFLAGS += \
- $(LIBISC_CFLAGS)
+ $(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 = \
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 = \
$(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
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <isc/string.h>
#include <isc/util.h>
+#include <isc/test.h>
+
/*
* Test data from NIST KAT
*/
} 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",
}
/* 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",
aes_testcase_t *testcase = testcases;
- UNUSED(state);
-
while (testcase->key != NULL) {
len = fromhexstr(testcase->key, key);
assert_int_equal(len, ISC_AES192_KEYLENGTH);
}
/* 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",
}
}
-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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY(isc_aes128_test)
+ISC_TEST_ENTRY(isc_aes192_test)
+ISC_TEST_ENTRY(isc_aes256_test)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <fcntl.h>
#include <limits.h>
#include <sched.h> /* IWYU pragma: keep */
#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);
/*
}
/* 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;
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);
}
/* 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;
UNUSED(state);
- isc_buffer_allocate(test_mctx, &b, sizeof(data));
+ isc_buffer_allocate(mctx, &b, sizeof(data));
/*
* Fill originally allocated buffer space.
}
/* 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;
* 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);
/*
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_buffer_reserve)
+ISC_TEST_ENTRY(isc_buffer_dynamic)
+ISC_TEST_ENTRY(isc_buffer_copyregion)
+ISC_TEST_ENTRY(isc_buffer_printf)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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++) {
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_counter)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
/* ! \file */
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <isc/result.h>
#include <isc/util.h>
-#define TEST_INPUT(x) (x), sizeof(x) - 1
+#include <isc/test.h>
-typedef struct hash_testcase {
- const char *input;
- size_t input_len;
- const char *result;
- int repeats;
-} hash_testcase_t;
+#define TEST_INPUT(x) (x), sizeof(x) - 1
-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);
}
}
/* 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);
"81E5EB73C8E7874A", 1);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(isc_crc64_init_test),
- cmocka_unit_test(isc_crc64_test),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_crc64_init)
+ISC_TEST_ENTRY(isc_crc64)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if defined(HAVE_CMOCKA) && defined(HAVE_LIBNGHTTP2)
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include "../netmgr/uv-compat.c"
#include "../netmgr/uv-compat.h"
#include "../netmgr_p.h"
-#include "isctest.h"
+
+#include <isc/test.h>
#define MAX_NM 2
static atomic_bool was_error = false;
-static unsigned int workers = 0;
-
static bool reuse_supported = true;
static bool noanswer = false;
static isc_nm_http_endpoints_t *endpoints = NULL;
+static bool skip_long_tests = false;
+
/* Timeout for soft-timeout tests (0.05 seconds) */
#define T_SOFT 50
#define X(v)
#endif
+#define SKIP_IN_CI \
+ if (skip_long_tests) { \
+ skip(); \
+ return; \
+ }
+
typedef struct csdata {
isc_nm_recv_cb_t reply_cb;
void *cb_arg;
return (fd);
}
-static int
-_setup(void **state) {
- char *p = NULL;
-
- UNUSED(state);
-
- if (workers == 0) {
- workers = isc_os_ncpus();
- }
- p = getenv("ISC_TASK_WORKERS");
- if (p != NULL) {
- workers = atoi(p);
- }
- INSIST(workers != 0);
-
- if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) {
- return (-1);
- }
-
- signal(SIGPIPE, SIG_IGN);
-
- return (0);
-}
-
-static int
-_teardown(void **state) {
- UNUSED(state);
-
- isc_test_end();
-
- return (0);
-}
-
/* Generic */
static void
thread_local size_t tcp_buffer_length = 0;
static int
-nm_setup(void **state) {
- size_t nworkers = ISC_MAX(ISC_MIN(workers, 32), 1);
- int tcp_listen_sock = -1;
+setup_test(void **state) {
+ char *env_workers = getenv("ISC_TASK_WORKERS");
+ size_t nworkers;
+ uv_os_sock_t tcp_listen_sock = -1;
isc_nm_t **nm = NULL;
tcp_listen_addr = (isc_sockaddr_t){ .length = 0 };
close(tcp_listen_sock);
tcp_listen_sock = -1;
+ if (env_workers != NULL) {
+ workers = atoi(env_workers);
+ } else {
+ workers = isc_os_ncpus();
+ }
+ INSIST(workers > 0);
+ nworkers = ISC_MAX(ISC_MIN(workers, 32), 1);
+
+ if (!reuse_supported || getenv("CI") != NULL) {
+ skip_long_tests = true;
+ }
+
atomic_store(&total_sends, NSENDS * NWRITES);
atomic_store(&nsends, atomic_load(&total_sends));
return (-1);
}
- nm = isc_mem_get(test_mctx, MAX_NM * sizeof(nm[0]));
+ nm = isc_mem_get(mctx, MAX_NM * sizeof(nm[0]));
for (size_t i = 0; i < MAX_NM; i++) {
- isc__netmgr_create(test_mctx, nworkers, &nm[i]);
+ isc__netmgr_create(mctx, nworkers, &nm[i]);
assert_non_null(nm[i]);
}
atomic_store(&check_listener_quota, false);
INSIST(endpoints == NULL);
- endpoints = isc_nm_http_endpoints_new(test_mctx);
+ endpoints = isc_nm_http_endpoints_new(mctx);
*state = nm;
}
static int
-nm_teardown(void **state) {
+teardown_test(void **state) {
isc_nm_t **nm = (isc_nm_t **)*state;
for (size_t i = 0; i < MAX_NM; i++) {
isc__netmgr_destroy(&nm[i]);
assert_null(nm[i]);
}
- isc_mem_put(test_mctx, nm, MAX_NM * sizeof(nm[0]));
+ isc_mem_put(mctx, nm, MAX_NM * sizeof(nm[0]));
if (server_tlsctx != NULL) {
isc_tlsctx_free(&server_tlsctx);
}
}
-static void
-mock_doh_uv_tcp_bind(void **state) {
+ISC_RUN_TEST_IMPL(mock_doh_uv_tcp_bind) {
isc_nm_t **nm = (isc_nm_t **)*state;
isc_nm_t *listen_nm = nm[0];
isc_result_t result = ISC_R_SUCCESS;
assert_int_equal(0, atomic_load(&ssends));
}
-static void
-doh_noop_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_noop_POST) {
atomic_store(&POST, true);
doh_noop(state);
}
-static void
-doh_noop_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_noop_GET) {
atomic_store(&POST, false);
doh_noop(state);
}
isc__netmgr_shutdown(connect_nm);
}
-static void
-doh_noresponse_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_noresponse_POST) {
atomic_store(&POST, true);
doh_noresponse(state);
}
-static void
-doh_noresponse_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_noresponse_GET) {
atomic_store(&POST, false);
doh_noresponse(state);
}
if (atomic_load(&ctimeouts) == 5) {
break;
}
- isc_test_nap(1000);
+ isc_test_nap(1);
}
assert_true(atomic_load(&ctimeouts) == 5);
isc__netmgr_shutdown(connect_nm);
}
-static void
-doh_timeout_recovery_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_timeout_recovery_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_timeout_recovery(state);
}
-static void
-doh_timeout_recovery_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_timeout_recovery_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_timeout_recovery(state);
}
*/
int_fast64_t active = atomic_fetch_add(&active_cconnects, 1);
if (atomic_load(&slowdown) || active > workers) {
- isc_test_nap(1000 * (active - workers));
+ isc_test_nap(active - workers);
atomic_store(&slowdown, false);
}
connect_send_request(
assert_int_equal(atomic_load(&ssends), 1);
}
-static void
-doh_recv_one_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_recv_one(state);
}
-static void
-doh_recv_one_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_recv_one(state);
}
-static void
-doh_recv_one_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
doh_recv_one(state);
}
-static void
-doh_recv_one_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
doh_recv_one(state);
}
-static void
-doh_recv_one_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_one(state);
}
-static void
-doh_recv_one_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_recv_one(state);
}
-static void
-doh_recv_one_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_one(state);
}
-static void
-doh_recv_one_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_one_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
assert_int_equal(atomic_load(&ssends), 2);
}
-static void
-doh_recv_two_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_recv_two(state);
}
-static void
-doh_recv_two_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_recv_two(state);
}
-static void
-doh_recv_two_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
doh_recv_two(state);
}
-static void
-doh_recv_two_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
doh_recv_two(state);
}
-static void
-doh_recv_two_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_two(state);
}
-static void
-doh_recv_two_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_recv_two(state);
}
-static void
-doh_recv_two_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_two(state);
}
-static void
-doh_recv_two_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_two_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
if (atomic_load(&was_error)) {
break;
}
- isc_test_nap(100);
+ isc_test_nap(1);
}
for (size_t i = 0; i < nthreads; i++) {
CHECK_RANGE_FULL(ssends);
}
-static void
-doh_recv_send_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_recv_send(state);
}
-static void
-doh_recv_send_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&use_TLS, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&use_TLS, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&use_TLS, true);
atomic_store(&check_listener_quota, true);
doh_recv_send(state);
}
-static void
-doh_recv_send_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_send_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&use_TLS, true);
atomic_store(&check_listener_quota, true);
CHECK_RANGE_HALF(ssends);
}
-static void
-doh_recv_half_send_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_recv_half_send(state);
}
-static void
-doh_recv_half_send_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_recv_half_send_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
CHECK_RANGE_HALF(ssends);
}
-static void
-doh_half_recv_send_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_half_recv_send(state);
}
-static void
-doh_half_recv_send_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_send_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
CHECK_RANGE_HALF(ssends);
}
-static void
-doh_half_recv_half_send_POST(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_GET(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_POST_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_GET_TLS(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_TLS) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_POST_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_GET_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_quota) {
+ SKIP_IN_CI;
+
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_POST_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_POST_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, true);
atomic_store(&check_listener_quota, true);
doh_half_recv_half_send(state);
}
-static void
-doh_half_recv_half_send_GET_TLS_quota(void **state) {
+ISC_RUN_TEST_IMPL(doh_half_recv_half_send_GET_TLS_quota) {
+ SKIP_IN_CI;
+
atomic_store(&use_TLS, true);
atomic_store(&POST, false);
atomic_store(&check_listener_quota, true);
}
/* See: GL #2858, !5319 */
-static void
-doh_bad_connect_uri(void **state) {
+ISC_RUN_TEST_IMPL(doh_bad_connect_uri) {
isc_nm_t **nm = (isc_nm_t **)*state;
isc_nm_t *listen_nm = nm[0];
isc_nm_t *connect_nm = nm[1];
assert_int_equal(atomic_load(&ssends), 0);
}
-static void
-doh_parse_GET_query_string(void **state) {
+ISC_RUN_TEST_IMPL(doh_parse_GET_query_string) {
UNUSED(state);
/* valid */
{
}
}
-static void
-doh_base64url_to_base64(void **state) {
+ISC_RUN_TEST_IMPL(doh_base64url_to_base64) {
UNUSED(state);
char *res;
size_t res_len = 0;
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhc3U";
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "PDw_Pz8-Pg";
char res_test[] = "PDw/Pz8+Pg==";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char test[] = "PDw_Pz8-Pg";
char res_test[] = "PDw/Pz8+Pg==";
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
NULL);
assert_non_null(res);
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* invalid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
res_len = 0;
- res = isc__nm_base64url_to_base64(test_mctx, test, 0, &res_len);
+ res = isc__nm_base64url_to_base64(mctx, test, 0, &res_len);
assert_null(res);
assert_true(res_len == 0);
}
char test[] = "";
res_len = 0;
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
char test[] = "PDw_Pz8-Pg==";
res_len = 0;
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
end */
res_len = 0;
- res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
+ res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
{
res_len = 0;
- res = isc__nm_base64url_to_base64(test_mctx, NULL, 31231,
- &res_len);
+ res = isc__nm_base64url_to_base64(mctx, NULL, 31231, &res_len);
assert_null(res);
assert_true(res_len == 0);
}
}
-static void
-doh_base64_to_base64url(void **state) {
+ISC_RUN_TEST_IMPL(doh_base64_to_base64url) {
char *res;
size_t res_len = 0;
UNUSED(state);
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U";
char test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "PDw_Pz8-Pg";
char test[] = "PDw/Pz8+Pg==";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_non_null(res);
assert_true(res_len == strlen(res_test));
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* valid */
{
char res_test[] = "PDw_Pz8-Pg";
char test[] = "PDw/Pz8+Pg==";
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
NULL);
assert_non_null(res);
assert_true(strcmp(res, res_test) == 0);
- isc_mem_free(test_mctx, res);
+ isc_mem_free(mctx, res);
}
/* invalid */
{
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
res_len = 0;
- res = isc__nm_base64_to_base64url(test_mctx, test, 0, &res_len);
+ res = isc__nm_base64_to_base64url(mctx, test, 0, &res_len);
assert_null(res);
assert_true(res_len == 0);
}
char test[] = "";
res_len = 0;
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
char test[] = "PDw_Pz8-Pg==";
res_len = 0;
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
end */
res_len = 0;
- res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
+ res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
&res_len);
assert_null(res);
assert_true(res_len == 0);
{
res_len = 0;
- res = isc__nm_base64_to_base64url(test_mctx, NULL, 31231,
- &res_len);
+ res = isc__nm_base64_to_base64url(mctx, NULL, 31231, &res_len);
assert_null(res);
assert_true(res_len == 0);
}
}
-static void
-doh_path_validation(void **state) {
+ISC_RUN_TEST_IMPL(doh_path_validation) {
UNUSED(state);
assert_true(isc_nm_http_path_isvalid("/"));
assert_true(isc_nm_http_path_isvalid("/123"));
}
-static void
-doh_connect_makeuri(void **state) {
+ISC_RUN_TEST_IMPL(doh_connect_makeuri) {
struct in_addr localhostv4 = { .s_addr = ntohl(INADDR_LOOPBACK) };
isc_sockaddr_t sa;
char uri[256];
assert_true(strcmp("https://[::1]:44343/dns-query", uri) == 0);
}
-int
-main(void) {
- const struct CMUnitTest tests_short[] = {
- cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_parse_GET_query_string,
- NULL, NULL),
- cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_path_validation, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup,
- nm_teardown),
- };
-
- const struct CMUnitTest tests_long[] = {
- cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_parse_GET_query_string,
- NULL, NULL),
- cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_path_validation, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_timeout_recovery_POST,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_timeout_recovery_GET,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_POST_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_GET_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_POST_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_GET_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_GET, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_POST, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_GET_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_POST_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_GET,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_POST,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_recv_half_send_GET_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_recv_half_send_POST_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_GET,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_POST,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_send_GET_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_send_POST_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_half_send_POST,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET_TLS,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_half_send_POST_TLS, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_half_send_GET_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_half_send_POST_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_half_send_GET_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- doh_half_recv_half_send_POST_TLS_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup,
- nm_teardown),
- };
- int result = 0;
-
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
- UNUSED(tests_long);
- result = (cmocka_run_group_tests(tests_short, _setup, _teardown));
-#else
- if (getenv("CI") != NULL || !reuse_supported) {
- result = (cmocka_run_group_tests(tests_short, _setup,
- _teardown));
- } else {
- result =
- (cmocka_run_group_tests(tests_long, _setup, _teardown));
- }
-#endif
- return result;
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
-#if HAVE_LIBNGHTTP2
- printf("1..0 # Skipped: cmocka not available\n");
-#else
- printf("1..0 # Skipped: libnghttp2 is not available\n");
-#endif
- return (SKIPPED_TEST_EXIT_CODE);
-}
-
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(mock_doh_uv_tcp_bind, setup_test, teardown_test)
+ISC_TEST_ENTRY(doh_parse_GET_query_string)
+ISC_TEST_ENTRY(doh_base64url_to_base64)
+ISC_TEST_ENTRY(doh_base64_to_base64url)
+ISC_TEST_ENTRY(doh_path_validation)
+ISC_TEST_ENTRY(doh_connect_makeuri)
+ISC_TEST_ENTRY_CUSTOM(doh_noop_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_noop_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_noresponse_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_noresponse_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_GET_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_recv_half_send_POST_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_TLS, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_GET_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_send_POST_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_TLS, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_TLS, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_GET_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_half_recv_half_send_POST_TLS_quota, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(doh_bad_connect_uri, setup_test, teardown_test)
+ISC_TEST_LIST_END
+
+ISC_TEST_MAIN
* 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>
#include <isc/result.h>
#include <isc/util.h>
+#include <isc/test.h>
+
typedef struct {
int err;
isc_result_t result;
{ 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;
}
}
-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 */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* 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>
#include <isc/result.h>
#include <isc/util.h>
+#include <isc/test.h>
+
#define NAME "internal"
#define SHA "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f"
#define TRUNC_SHA "3bed2cb3a3acf7b6"
}
/* 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];
}
/* 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];
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_file_sanitize)
+ISC_TEST_ENTRY(isc_file_template)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* 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>
#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;
}
/* 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;
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY(isc_hash_function)
+ISC_TEST_ENTRY(isc_hash_initializer)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
/* ! \file */
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
}
/* 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);
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_heap_delete)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
/* ! \file */
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include "../hmac.c"
+#include <isc/test.h>
+
#define TEST_INPUT(x) (x), sizeof(x) - 1
static int
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();
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();
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),
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);
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);
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));
#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);
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 */
#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 */
"E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1);
}
-static void
-isc_hmac_sha224_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_hmac_sha224) {
isc_hmac_t *hmac = *state;
/* Test 0 */
1);
}
-static void
-isc_hmac_sha256_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_hmac_sha256) {
isc_hmac_t *hmac = *state;
/* Test 0 */
1);
}
-static void
-isc_hmac_sha384_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_hmac_sha384) {
isc_hmac_t *hmac = *state;
/* Test 0 */
1);
}
-static void
-isc_hmac_sha512_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_hmac_sha512) {
isc_hmac_t *hmac = *state;
/* Test 0 */
1);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- /* isc_hmac_new() */
- cmocka_unit_test(isc_hmac_new_test),
-
- /* isc_hmac_init() */
- cmocka_unit_test_setup_teardown(isc_hmac_init_test, _reset,
- _reset),
-
- /* isc_hmac_reset() */
- cmocka_unit_test_setup_teardown(isc_hmac_reset_test, _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),
-
- cmocka_unit_test_setup_teardown(isc_hmac_update_test, _reset,
- _reset),
- cmocka_unit_test_setup_teardown(isc_hmac_final_test, _reset,
- _reset),
-
- cmocka_unit_test(isc_hmac_free_test),
- };
-
- return (cmocka_run_group_tests(tests, _setup, _teardown));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_hmac_new)
+ISC_TEST_ENTRY_CUSTOM(isc_hmac_init, _reset, _reset)
-#include <stdio.h>
+ISC_TEST_ENTRY_CUSTOM(isc_hmac_reset, _reset, _reset)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+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)
+
+ISC_TEST_ENTRY_CUSTOM(isc_hmac_update, _reset, _reset)
+ISC_TEST_ENTRY_CUSTOM(isc_hmac_final, _reset, _reset)
+
+ISC_TEST_ENTRY(isc_hmac_free)
+
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN_CUSTOM(_setup, _teardown)
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <isc/string.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);
+#include <isc/test.h>
- return (0);
-}
-
-static int
-_teardown(void **state) {
- UNUSED(state);
+/* INCLUDE LAST */
- isc_test_end();
-
- return (0);
-}
+#define mctx __mctx
+#include "../ht.c"
+#undef mctx
static void
test_ht_full(int bits, uintptr_t count) {
isc_result_t result;
uintptr_t i;
- isc_ht_init(&ht, test_mctx, bits);
+ isc_ht_init(&ht, mctx, bits);
assert_non_null(ht);
for (i = 1; i < count; i++) {
unsigned char key[16];
size_t tksize;
- isc_ht_init(&ht, test_mctx, 16);
+ isc_ht_init(&ht, mctx, 16);
assert_non_null(ht);
for (i = 1; i <= count; i++) {
/*
}
/* 20 bit, 200K elements test */
-static void
-isc_ht_20(void **state) {
+ISC_RUN_TEST_IMPL(isc_ht_20) {
UNUSED(state);
test_ht_full(20, 200000);
}
/* 8 bit, 20000 elements crowded test */
-static void
-isc_ht_8(void **state) {
+ISC_RUN_TEST_IMPL(isc_ht_8) {
UNUSED(state);
test_ht_full(8, 20000);
}
-/* 8 bit, 100 elements corner case test */
-static void
-isc_ht_1(void **state) {
+ISC_RUN_TEST_IMPL(isc_ht_1) {
UNUSED(state);
test_ht_full(1, 100);
}
/* 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_20),
- cmocka_unit_test(isc_ht_8),
- cmocka_unit_test(isc_ht_1),
- cmocka_unit_test(isc_ht_iterator_test),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(isc_ht_20)
+ISC_TEST_ENTRY(isc_ht_8)
+ISC_TEST_ENTRY(isc_ht_1)
+ISC_TEST_ENTRY(isc_ht_iterator)
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
+++ /dev/null
-/*
- * 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_shutdown(maintask);
- isc_task_destroy(&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_bound(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);
-}
+++ /dev/null
-/*
- * 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);
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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));
}
/* 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";
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));
/*%
* 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;
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,
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) {
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(
/*%
* 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;
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,
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) {
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(
* 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;
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,
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) {
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(
}
}
-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),
- };
-
- UNUSED(argv);
+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)
- 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);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include "../md.c"
+#include <isc/test.h>
+
#define TEST_INPUT(x) (x), sizeof(x) - 1
static int
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 */
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);
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);
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);
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));
#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);
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(""),
"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(""),
"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);
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);
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);
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);
1);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- /* isc_md_new() */
- cmocka_unit_test(isc_md_new_test),
-
- /* isc_md_init() */
- cmocka_unit_test_setup_teardown(isc_md_init_test, _reset,
- _reset),
-
- /* isc_md_reset() */
- cmocka_unit_test_setup_teardown(isc_md_reset_test, _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),
-
- cmocka_unit_test_setup_teardown(isc_md_update_test, _reset,
- _reset),
- cmocka_unit_test_setup_teardown(isc_md_final_test, _reset,
- _reset),
-
- cmocka_unit_test(isc_md_free_test),
- };
-
- return (cmocka_run_group_tests(tests, _setup, _teardown));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_md_new)
-#include <stdio.h>
+ISC_TEST_ENTRY_CUSTOM(isc_md_init, _reset, _reset)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_ENTRY_CUSTOM(isc_md_reset, _reset, _reset)
+
+ISC_TEST_ENTRY(isc_md_md5)
+ISC_TEST_ENTRY(isc_md_sha1)
+
+ISC_TEST_ENTRY(isc_md_sha224)
+ISC_TEST_ENTRY(isc_md_sha256)
+ISC_TEST_ENTRY(isc_md_sha384)
+ISC_TEST_ENTRY(isc_md_sha512)
+
+ISC_TEST_ENTRY_CUSTOM(isc_md_update, _reset, _reset)
+ISC_TEST_ENTRY_CUSTOM(isc_md_final, _reset, _reset)
+
+ISC_TEST_ENTRY(isc_md_free)
+
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN_CUSTOM(_setup, _teardown)
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <fcntl.h>
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#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
#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;
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);
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);
#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;
/* 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);
#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;
/* 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);
}
/* 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;
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++) {
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;
}
/* 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;
}
/* 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;
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)) {
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;
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);
#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));
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#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 {
{ "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);
}
/* 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;
}
/* check multicast addresses are detected properly */
-static void
-netaddr_multicast(void **state) {
+ISC_RUN_TEST_IMPL(netaddr_multicast) {
unsigned int i;
struct {
int family;
}
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(netaddr_isnetzero),
- cmocka_unit_test(netaddr_masktoprefixlen),
- cmocka_unit_test(netaddr_multicast),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY(netaddr_isnetzero)
+ISC_TEST_ENTRY(netaddr_masktoprefixlen)
+ISC_TEST_ENTRY(netaddr_multicast)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <signal.h>
#include "uv_wrap.h"
#define KEEP_BEFORE
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
#include "../netmgr/netmgr-int.h"
#include "../netmgr/udp.c"
#include "../netmgr/uv-compat.c"
#include "../netmgr/uv-compat.h"
#include "../netmgr_p.h"
-#include "isctest.h"
+#pragma GCC diagnostic pop
+
+#include <isc/test.h>
typedef void (*stream_connect_function)(isc_nm_t *nm);
.length = sizeof(stop_magic) };
static atomic_bool do_send = false;
-static unsigned int workers = 0;
static atomic_int_fast64_t nsends;
static int_fast64_t esends; /* expected sends */
#define T_ADVERTISED 120 * 1000
#define T_CONNECT 30 * 1000
-/* Wait for 1 second (1000 * 1000 microseconds) */
+/* Wait for 1 second (1000 milliseconds) */
#define WAIT_REPEATS 1000
-#define T_WAIT 1000 /* In microseconds */
+#define T_WAIT 1 /* 1 millisecond */
#define WAIT_FOR(v, op, val) \
{ \
#define atomic_assert_int_ge(val, exp) assert_true(atomic_load(&val) >= exp)
#define atomic_assert_int_gt(val, exp) assert_true(atomic_load(&val) > exp)
-static int
-_setup(void **state __attribute__((unused))) {
- char *p = NULL;
-
- if (workers == 0) {
- workers = isc_os_ncpus();
- }
- p = getenv("ISC_TASK_WORKERS");
- if (p != NULL) {
- workers = atoi(p);
- }
- INSIST(workers != 0);
-
- if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) {
- return (-1);
- }
-
- signal(SIGPIPE, SIG_IGN);
-
- if (getenv("CI") == NULL || getenv("CI_ENABLE_ALL_TESTS") != NULL) {
- esends = NSENDS * workers;
- } else {
- esends = workers;
- skip_long_tests = true;
- }
-
- if (isc_tlsctx_createserver(NULL, NULL, &tcp_listen_tlsctx) !=
- ISC_R_SUCCESS) {
- return (-1);
- }
- if (isc_tlsctx_createclient(&tcp_connect_tlsctx) != ISC_R_SUCCESS) {
- return (-1);
- }
-
- isc_tlsctx_enable_dot_client_alpn(tcp_connect_tlsctx);
-
- return (0);
-}
-
-static int
-_teardown(void **state __attribute__((unused))) {
- isc_tlsctx_free(&tcp_connect_tlsctx);
- isc_tlsctx_free(&tcp_listen_tlsctx);
-
- isc_test_end();
-
- return (0);
-}
-
static int
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
socklen_t addrlen = sizeof(*addr);
}
static int
-nm_setup(void **state __attribute__((unused))) {
+setup_test(void **state __attribute__((unused))) {
+ char *env_workers = getenv("ISC_TASK_WORKERS");
uv_os_sock_t tcp_listen_sock = -1;
uv_os_sock_t udp_listen_sock = -1;
+ size_t nworkers;
+
+ if (env_workers != NULL) {
+ workers = atoi(env_workers);
+ } else {
+ workers = isc_os_ncpus();
+ }
+ INSIST(workers > 0);
+ nworkers = ISC_MAX(ISC_MIN(workers, 32), 1);
+
+ if (getenv("CI") != NULL && getenv("CI_ENABLE_ALL_TESTS") == NULL) {
+ skip_long_tests = true;
+ esends = nworkers;
+ } else {
+ esends = NSENDS * nworkers;
+ }
udp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0);
return (-1);
}
- isc__netmgr_create(test_mctx, workers, &listen_nm);
+ isc__netmgr_create(mctx, nworkers, &listen_nm);
assert_non_null(listen_nm);
isc_nm_settimeouts(listen_nm, T_INIT, T_IDLE, T_KEEPALIVE,
T_ADVERTISED);
- isc__netmgr_create(test_mctx, workers, &connect_nm);
+ isc__netmgr_create(mctx, nworkers, &connect_nm);
assert_non_null(connect_nm);
isc_nm_settimeouts(connect_nm, T_INIT, T_IDLE, T_KEEPALIVE,
T_ADVERTISED);
connect_readcb = connect_read_cb;
noanswer = false;
+ if (isc_tlsctx_createserver(NULL, NULL, &tcp_listen_tlsctx) !=
+ ISC_R_SUCCESS) {
+ return (-1);
+ }
+ if (isc_tlsctx_createclient(&tcp_connect_tlsctx) != ISC_R_SUCCESS) {
+ return (-1);
+ }
+
+ isc_tlsctx_enable_dot_client_alpn(tcp_connect_tlsctx);
+
return (0);
}
static int
-nm_teardown(void **state __attribute__((unused))) {
+teardown_test(void **state __attribute__((unused))) {
UNUSED(state);
+ isc_tlsctx_free(&tcp_connect_tlsctx);
+ isc_tlsctx_free(&tcp_listen_tlsctx);
+
isc__netmgr_destroy(&connect_nm);
assert_null(connect_nm);
* start slowing down the connections to prevent the
* thundering herd problem.
*/
- isc_test_nap((active - workers) * 1000);
+ isc_test_nap(active - workers);
}
connect(connect_nm);
}
connect_connect_cb, NULL, T_CONNECT, 0);
}
-static void
-mock_listenudp_uv_udp_open(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_open) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
RESET_RETURN;
}
-static void
-mock_listenudp_uv_udp_bind(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_bind) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
RESET_RETURN;
}
-static void
-mock_listenudp_uv_udp_recv_start(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_listenudp_uv_udp_recv_start) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
RESET_RETURN;
}
-static void
-mock_udpconnect_uv_udp_open(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_open) {
WILL_RETURN(uv_udp_open, UV_ENOMEM);
connect_readcb = NULL;
RESET_RETURN;
}
-static void
-mock_udpconnect_uv_udp_bind(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_bind) {
WILL_RETURN(uv_udp_bind, UV_ENOMEM);
connect_readcb = NULL;
}
#if UV_VERSION_HEX >= UV_VERSION(1, 27, 0)
-static void
-mock_udpconnect_uv_udp_connect(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_udpconnect_uv_udp_connect) {
WILL_RETURN(uv_udp_connect, UV_ENOMEM);
connect_readcb = NULL;
}
#endif
-static void
-mock_udpconnect_uv_recv_buffer_size(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_udpconnect_uv_recv_buffer_size) {
WILL_RETURN(uv_recv_buffer_size, UV_ENOMEM);
connect_readcb = NULL;
RESET_RETURN;
}
-static void
-mock_udpconnect_uv_send_buffer_size(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(mock_udpconnect_uv_send_buffer_size) {
WILL_RETURN(uv_send_buffer_size, UV_ENOMEM);
connect_readcb = NULL;
RESET_RETURN;
}
-static void
-udp_noop(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_noop) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-udp_noresponse(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_noresponse) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_nmhandle_detach(&handle);
}
-static void
-udp_timeout_recovery(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_timeout_recovery) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc__netmgr_shutdown(connect_nm);
}
-static void
-udp_recv_one(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_recv_one) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-udp_recv_two(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_recv_two) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 1);
}
-static void
-udp_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_FULL(ssends);
}
-static void
-udp_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_HALF(ssends);
}
-static void
-udp_half_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_half_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
assert_null(listen_sock);
/* Try to send a little while longer */
- isc_test_nap((esends / 2) * 10000);
+ isc_test_nap((esends / 2) * 10);
isc__netmgr_shutdown(connect_nm);
CHECK_RANGE_HALF(ssends);
}
-static void
-udp_half_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(udp_half_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
assert_null(listen_sock);
/* Try to send a little while longer */
- isc_test_nap((esends / 2) * 10000);
+ isc_test_nap((esends / 2) * 10);
isc__netmgr_shutdown(connect_nm);
}
/* TCP */
-static void
-tcp_noop(void **state) {
- stream_noop(state);
-}
+ISC_RUN_TEST_IMPL(tcp_noop) { stream_noop(state); }
-static void
-tcp_noresponse(void **state) {
- stream_noresponse(state);
-}
+ISC_RUN_TEST_IMPL(tcp_noresponse) { stream_noresponse(state); }
-static void
-tcp_timeout_recovery(void **state) {
- stream_timeout_recovery(state);
-}
+ISC_RUN_TEST_IMPL(tcp_timeout_recovery) { stream_timeout_recovery(state); }
-static void
-tcp_recv_one(void **state) {
- stream_recv_one(state);
-}
+ISC_RUN_TEST_IMPL(tcp_recv_one) { stream_recv_one(state); }
-static void
-tcp_recv_two(void **state) {
- stream_recv_two(state);
-}
+ISC_RUN_TEST_IMPL(tcp_recv_two) { stream_recv_two(state); }
-static void
-tcp_recv_send(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_send) {
SKIP_IN_CI;
stream_recv_send(state);
}
-static void
-tcp_recv_half_send(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_half_send) {
SKIP_IN_CI;
stream_recv_half_send(state);
}
-static void
-tcp_half_recv_send(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_send) {
SKIP_IN_CI;
stream_half_recv_send(state);
}
-static void
-tcp_half_recv_half_send(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_half_send) {
SKIP_IN_CI;
stream_half_recv_half_send(state);
}
-static void
-tcp_recv_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_send_sendback) {
SKIP_IN_CI;
stream_recv_send(state);
}
-static void
-tcp_recv_half_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_half_send_sendback) {
SKIP_IN_CI;
stream_recv_half_send(state);
}
-static void
-tcp_half_recv_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_send_sendback) {
SKIP_IN_CI;
stream_half_recv_send(state);
}
-static void
-tcp_half_recv_half_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_sendback) {
SKIP_IN_CI;
stream_half_recv_half_send(state);
}
/* TCP Quota */
-static void
-tcp_recv_one_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_one_quota) {
atomic_store(&check_listener_quota, true);
stream_recv_one(state);
}
-static void
-tcp_recv_two_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_two_quota) {
atomic_store(&check_listener_quota, true);
stream_recv_two(state);
}
-static void
-tcp_recv_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_send_quota) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
stream_recv_send(state);
}
-static void
-tcp_recv_half_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_half_send_quota) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
stream_recv_half_send(state);
}
-static void
-tcp_half_recv_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_send_quota) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
stream_half_recv_send(state);
}
-static void
-tcp_half_recv_half_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_quota) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
stream_half_recv_half_send(state);
}
-static void
-tcp_recv_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_send_quota_sendback) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
allow_send_back = true;
stream_recv_send(state);
}
-static void
-tcp_recv_half_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_recv_half_send_quota_sendback) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
allow_send_back = true;
stream_recv_half_send(state);
}
-static void
-tcp_half_recv_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_send_quota_sendback) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
allow_send_back = true;
stream_half_recv_send(state);
}
-static void
-tcp_half_recv_half_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tcp_half_recv_half_send_quota_sendback) {
SKIP_IN_CI;
atomic_store(&check_listener_quota, true);
allow_send_back = true;
connect_connect_cb, NULL, T_CONNECT, 0);
}
-static void
-tcpdns_noop(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_noop) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-tcpdns_noresponse(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_noresponse) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
&listen_sock);
if (result != ISC_R_SUCCESS) {
isc_refcount_decrement(&active_cconnects);
- isc_test_nap(1000);
+ isc_test_nap(1);
}
assert_int_equal(result, ISC_R_SUCCESS);
atomic_assert_int_eq(ssends, 0);
}
-static void
-tcpdns_timeout_recovery(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_timeout_recovery) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc__netmgr_shutdown(connect_nm);
}
-static void
-tcpdns_recv_one(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_recv_one) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-tcpdns_recv_two(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_recv_two) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 1);
}
-static void
-tcpdns_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_FULL(ssends);
}
-static void
-tcpdns_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_HALF(ssends);
}
-static void
-tcpdns_half_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_half_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
assert_null(listen_sock);
/* Try to send a little while longer */
- isc_test_nap((esends / 2) * 10000);
+ isc_test_nap((esends / 2) * 10);
isc__netmgr_shutdown(connect_nm);
CHECK_RANGE_HALF(ssends);
}
-static void
-tcpdns_half_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tcpdns_half_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
T_CONNECT, 0);
}
-static void
-tls_noop(void **state) {
+ISC_RUN_TEST_IMPL(tls_noop) {
stream_use_TLS = true;
stream_noop(state);
}
-static void
-tls_noresponse(void **state) {
+ISC_RUN_TEST_IMPL(tls_noresponse) {
stream_use_TLS = true;
stream_noresponse(state);
}
-static void
-tls_timeout_recovery(void **state) {
+ISC_RUN_TEST_IMPL(tls_timeout_recovery) {
stream_use_TLS = true;
stream_timeout_recovery(state);
}
-static void
-tls_recv_one(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_one) {
stream_use_TLS = true;
stream_recv_one(state);
}
-static void
-tls_recv_two(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_two) {
stream_use_TLS = true;
stream_recv_two(state);
}
-static void
-tls_recv_send(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_send) {
SKIP_IN_CI;
stream_use_TLS = true;
stream_recv_send(state);
}
-static void
-tls_recv_half_send(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_half_send) {
SKIP_IN_CI;
stream_use_TLS = true;
stream_recv_half_send(state);
}
-static void
-tls_half_recv_send(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_send) {
SKIP_IN_CI;
stream_use_TLS = true;
stream_half_recv_send(state);
}
-static void
-tls_half_recv_half_send(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_half_send) {
SKIP_IN_CI;
stream_use_TLS = true;
stream_half_recv_half_send(state);
}
-static void
-tls_recv_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_send_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_recv_send(state);
}
-static void
-tls_recv_half_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_half_send_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_recv_half_send(state);
}
-static void
-tls_half_recv_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_send_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_half_recv_send(state);
}
-static void
-tls_half_recv_half_send_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_half_send_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
/* TLS quota */
-static void
-tls_recv_one_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_one_quota) {
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_recv_one(state);
}
-static void
-tls_recv_two_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_two_quota) {
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_recv_two(state);
}
-static void
-tls_recv_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_send_quota) {
SKIP_IN_CI;
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_recv_send(state);
}
-static void
-tls_recv_half_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_half_send_quota) {
SKIP_IN_CI;
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_recv_half_send(state);
}
-static void
-tls_half_recv_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_send_quota) {
SKIP_IN_CI;
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_half_recv_send(state);
}
-static void
-tls_half_recv_half_send_quota(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_half_send_quota) {
SKIP_IN_CI;
stream_use_TLS = true;
atomic_store(&check_listener_quota, true);
stream_half_recv_half_send(state);
}
-static void
-tls_recv_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_send_quota_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_recv_send(state);
}
-static void
-tls_recv_half_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_recv_half_send_quota_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_recv_half_send(state);
}
-static void
-tls_half_recv_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_send_quota_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
stream_half_recv_send(state);
}
-static void
-tls_half_recv_half_send_quota_sendback(void **state) {
+ISC_RUN_TEST_IMPL(tls_half_recv_half_send_quota_sendback) {
SKIP_IN_CI;
stream_use_TLS = true;
allow_send_back = true;
tcp_connect_tlsctx);
}
-static void
-tlsdns_noop(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_noop) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-tlsdns_noresponse(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_noresponse) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_sockaddr_t connect_addr;
atomic_assert_int_eq(ssends, 0);
}
-static void
-tlsdns_timeout_recovery(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_timeout_recovery) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_sockaddr_t connect_addr;
isc__netmgr_shutdown(connect_nm);
}
-static void
-tlsdns_recv_one(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_recv_one) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 0);
}
-static void
-tlsdns_recv_two(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_recv_two) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
atomic_assert_int_eq(ssends, 1);
}
-static void
-tlsdns_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_FULL(ssends);
}
-static void
-tlsdns_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
CHECK_RANGE_HALF(ssends);
}
-static void
-tlsdns_half_recv_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_half_recv_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
assert_null(listen_sock);
/* Try to send a little while longer */
- isc_test_nap((esends / 2) * 10000);
+ isc_test_nap((esends / 2) * 10);
isc__netmgr_shutdown(connect_nm);
CHECK_RANGE_HALF(ssends);
}
-static void
-tlsdns_half_recv_half_send(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_half_recv_half_send) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_thread_t threads[workers];
connect_send(handle);
}
-static void
-tlsdns_connect_noalpn(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_connect_noalpn) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_sockaddr_t connect_addr;
return (stream_accept_cb(handle, eresult, cbarg));
}
-static void
-tlsdns_listen_noalpn(void **state __attribute__((unused))) {
+ISC_RUN_TEST_IMPL(tlsdns_listen_noalpn) {
isc_result_t result = ISC_R_SUCCESS;
isc_nmsocket_t *listen_sock = NULL;
isc_sockaddr_t connect_addr;
}
#endif /* HAVE_LIBNGHTTP2 */
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- /* UDP */
- cmocka_unit_test_setup_teardown(mock_listenudp_uv_udp_open,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(mock_listenudp_uv_udp_bind,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- mock_listenudp_uv_udp_recv_start, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_open,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_bind,
- nm_setup, nm_teardown),
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_open, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_bind, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(mock_listenudp_uv_udp_recv_start, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_open, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_bind, setup_test, teardown_test)
#if UV_VERSION_HEX >= UV_VERSION(1, 27, 0)
- cmocka_unit_test_setup_teardown(mock_udpconnect_uv_udp_connect,
- nm_setup, nm_teardown),
+ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_udp_connect, setup_test, teardown_test)
#endif
- cmocka_unit_test_setup_teardown(
- mock_udpconnect_uv_recv_buffer_size, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- mock_udpconnect_uv_send_buffer_size, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_noop, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_noresponse, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_timeout_recovery, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_recv_one, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_recv_two, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_recv_half_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_half_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(udp_half_recv_half_send,
- nm_setup, nm_teardown),
-
- /* TCP */
- cmocka_unit_test_setup_teardown(tcp_noop, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_noresponse, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_timeout_recovery, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_one, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_two, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_half_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_half_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_half_recv_half_send,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_half_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_half_recv_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- tcp_half_recv_half_send_sendback, nm_setup,
- nm_teardown),
-
- /* TCP Quota */
- cmocka_unit_test_setup_teardown(tcp_recv_one_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_two_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_send_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_half_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_half_recv_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_half_recv_half_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcp_recv_send_quota_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- tcp_recv_half_send_quota_sendback, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- tcp_half_recv_send_quota_sendback, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- tcp_half_recv_half_send_quota_sendback, nm_setup,
- nm_teardown),
-
- /* TCPDNS */
- cmocka_unit_test_setup_teardown(tcpdns_recv_one, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_recv_two, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_noop, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_noresponse, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_timeout_recovery,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_recv_half_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_half_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tcpdns_half_recv_half_send,
- nm_setup, nm_teardown),
+ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_recv_buffer_size, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(mock_udpconnect_uv_send_buffer_size, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_noop, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_noresponse, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_timeout_recovery, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_recv_one, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_recv_two, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_half_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(udp_half_recv_half_send, setup_test, teardown_test)
+
+/* TCP */
+ISC_TEST_ENTRY_CUSTOM(tcp_noop, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_noresponse, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_timeout_recovery, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_one, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_two, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_sendback, setup_test,
+ teardown_test)
+
+/* TCP Quota */
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_one_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_two_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_send_quota_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_recv_half_send_quota_sendback, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_send_quota_sendback, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcp_half_recv_half_send_quota_sendback, setup_test,
+ teardown_test)
+
+/* TCPDNS */
+ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_one, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_two, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_noop, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_noresponse, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_timeout_recovery, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_half_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tcpdns_half_recv_half_send, setup_test, teardown_test)
#if HAVE_LIBNGHTTP2
- /* TLS */
- cmocka_unit_test_setup_teardown(tls_noop, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_noresponse, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_timeout_recovery, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_one, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_two, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_half_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_half_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_half_recv_half_send,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_half_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_half_recv_send_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- tls_half_recv_half_send_sendback, nm_setup,
- nm_teardown),
-
- /* TLS quota */
- cmocka_unit_test_setup_teardown(tls_recv_one_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_two_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_send_quota, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_half_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_half_recv_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_half_recv_half_send_quota,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tls_recv_send_quota_sendback,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(
- tls_recv_half_send_quota_sendback, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- tls_half_recv_send_quota_sendback, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(
- tls_half_recv_half_send_quota_sendback, nm_setup,
- nm_teardown),
+/* TLS */
+ISC_TEST_ENTRY_CUSTOM(tls_noop, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_noresponse, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_timeout_recovery, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_one, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_two, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_sendback, setup_test,
+ teardown_test)
+
+/* TLS quota */
+ISC_TEST_ENTRY_CUSTOM(tls_recv_one_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_two_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_quota, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota_sendback, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_recv_half_send_quota_sendback, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_send_quota_sendback, setup_test,
+ teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tls_half_recv_half_send_quota_sendback, setup_test,
+ teardown_test)
#endif
- /* TLSDNS */
- cmocka_unit_test_setup_teardown(tlsdns_recv_one, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_recv_two, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_noop, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_noresponse, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_timeout_recovery,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_recv_half_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_half_recv_send, nm_setup,
- nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_half_recv_half_send,
- nm_setup, nm_teardown),
- cmocka_unit_test_setup_teardown(tlsdns_connect_noalpn, nm_setup,
- nm_teardown),
+/* TLSDNS */
+ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_one, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_two, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_noop, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_noresponse, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_timeout_recovery, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_half_recv_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_half_recv_half_send, setup_test, teardown_test)
+ISC_TEST_ENTRY_CUSTOM(tlsdns_connect_noalpn, setup_test, teardown_test)
#ifdef HAVE_LIBNGHTTP2
- cmocka_unit_test_setup_teardown(tlsdns_listen_noalpn, nm_setup,
- nm_teardown),
+ISC_TEST_ENTRY_CUSTOM(tlsdns_listen_noalpn, setup_test, teardown_test)
#endif
- };
- 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);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
/*! \file */
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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);
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(parse_overflow)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <isc/pool.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 isc_result_t
poolinit(void **target, void *arg) {
}
/* Create a pool */
-static void
-create_pool(void **state) {
+ISC_RUN_TEST_IMPL(create_pool) {
isc_result_t result;
isc_pool_t *pool = NULL;
UNUSED(state);
- result = isc_pool_create(test_mctx, 8, poolfree, poolinit, taskmgr,
- &pool);
+ result = isc_pool_create(mctx, 8, poolfree, poolinit, taskmgr, &pool);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_pool_count(pool), 8);
}
/* Resize a pool */
-static void
-expand_pool(void **state) {
+ISC_RUN_TEST_IMPL(expand_pool) {
isc_result_t result;
isc_pool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
UNUSED(state);
- result = isc_pool_create(test_mctx, 10, poolfree, poolinit, taskmgr,
- &pool1);
+ result = isc_pool_create(mctx, 10, poolfree, poolinit, taskmgr, &pool1);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_pool_count(pool1), 10);
}
/* Get objects */
-static void
-get_objects(void **state) {
+ISC_RUN_TEST_IMPL(get_objects) {
isc_result_t result;
isc_pool_t *pool = NULL;
void *item;
UNUSED(state);
- result = isc_pool_create(test_mctx, 2, poolfree, poolinit, taskmgr,
- &pool);
+ result = isc_pool_create(mctx, 2, poolfree, poolinit, taskmgr, &pool);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_pool_count(pool), 2);
assert_null(pool);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(create_pool, _setup, _teardown),
- cmocka_unit_test_setup_teardown(expand_pool, _setup, _teardown),
- cmocka_unit_test_setup_teardown(get_objects, _setup, _teardown),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY_CUSTOM(create_pool, setup_managers, teardown_managers)
+ISC_TEST_ENTRY_CUSTOM(expand_pool, setup_managers, teardown_managers)
+ISC_TEST_ENTRY_CUSTOM(get_objects, setup_managers, teardown_managers)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <uv.h>
#define UNIT_TESTING
#include <cmocka.h>
#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;
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;
isc_quota_destroy("a);
}
-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;
}
}
-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];
static void *
quota_detach(void *quotap) {
isc_quota_t *quota = (isc_quota_t *)quotap;
- isc_test_nap(10000);
+ uv_sleep(10000);
isc_quota_detach("a);
return ((isc_threadresult_t)0);
}
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;
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
isc_quota_destroy("a);
}
-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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+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)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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");
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));
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_ENTRY(isc_radix_search)
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_LIST_END
+ISC_TEST_MAIN
* 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 */
#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:
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,
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);
ans = pkm1 / qkm1;
do {
+ double yc, pk, qk;
c += 1.0;
y += 1.0;
z += 2.0;
*/
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++;
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 {
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++;
}
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);
/*
/* 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);
* 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;
/* 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));
* 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;
double tau;
uint32_t j;
uint32_t b;
- uint8_t bit_this;
uint8_t bit_prev;
uint32_t v_obs;
double numer;
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);
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++;
* 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;
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);
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);
* 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;
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);
***/
/* 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);
***/
/* 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);
***/
/* 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);
/* 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;
-
- while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
- switch (c) {
- case 'v':
- verbose = true;
- break;
- default:
- break;
- }
- }
-
- 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_LIST_START
+
+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)
+
+ISC_TEST_LIST_END
+
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#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
(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) {
}
}
-int
-main(int argc, char **argv) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(regex_validate),
- };
- int c;
-
- 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 */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY(regex_validate)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#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);
}
/* 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);
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_result_toid)
+ISC_TEST_ENTRY(isc_result_totext)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
/* ! \file */
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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));
}
/* test isc_safe_memwipe() */
-static void
-isc_safe_memwipe_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_safe_memwipe) {
UNUSED(state);
/* These should pass. */
}
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(isc_safe_memequal_test),
- cmocka_unit_test(isc_safe_memwipe_test),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(isc_safe_memequal)
+ISC_TEST_ENTRY(isc_safe_memwipe)
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
+#include <sched.h> /* IWYU pragma: keep */
#include <sched.h>
#include <setjmp.h>
#include <stdarg.h>
#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 },
{ 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];
}
}
-static void
-isc_halfsiphash24_test(void **state) {
+ISC_RUN_TEST_IMPL(isc_halfsiphash24) {
UNUSED(state);
uint8_t in[64], out[4], key[16];
}
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(isc_siphash24_test),
- cmocka_unit_test(isc_halfsiphash24_test),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY(isc_siphash24)
+ISC_TEST_ENTRY(isc_halfsiphash24)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
}
/* 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;
}
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);
* 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;
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(sockaddr_hash)
+ISC_TEST_ENTRY(sockaddr_isnetzero)
+ISC_TEST_ENTRY(sockaddr_eqaddrprefix)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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);
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(isc_stats_basic)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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;
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);
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);
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);
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(symtab_grow)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <uv.h>
#define UNIT_TESTING
#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;
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);
}
}
/* Create a task */
-static void
-create_task(void **state) {
+ISC_RUN_TEST_IMPL(create_task) {
isc_result_t result;
isc_task_t *task = NULL;
}
/* 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;
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);
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);
}
/* Privileged events */
-static void
-privileged_events(void **state) {
+ISC_RUN_TEST_IMPL(privileged_events) {
isc_result_t result;
isc_task_t *task1 = NULL, *task2 = NULL;
isc_event_t *event = NULL;
assert_false(isc_task_getprivilege(task2));
/* First event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST, set,
- &a, sizeof(isc_event_t));
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &a,
+ sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&a), -1);
isc_task_send(task1, &event);
/* Second event: not privileged */
- event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST, set,
- &b, sizeof(isc_event_t));
+ event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST, set, &b,
+ sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&b), -1);
isc_task_send(task2, &event);
/* Third event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST, set,
- &c, sizeof(isc_event_t));
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &c,
+ sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&c), -1);
isc_task_send(task1, &event);
/* Fourth event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST, set,
- &d, sizeof(isc_event_t));
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &d,
+ sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&d), -1);
isc_task_send(task1, &event);
/* Fifth event: not privileged */
- event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST, set,
- &e, sizeof(isc_event_t));
+ event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST, set, &e,
+ sizeof(isc_event_t));
assert_non_null(event);
assert_int_equal(atomic_load(&e), -1);
* Edge case: this tests that the task manager behaves as expected when
* we explicitly set it into normal mode *while* running privileged.
*/
-static void
-privilege_drop(void **state) {
+ISC_RUN_TEST_IMPL(privilege_drop) {
isc_result_t result;
isc_task_t *task1 = NULL, *task2 = NULL;
isc_event_t *event = NULL;
assert_false(isc_task_getprivilege(task2));
/* First event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
set_and_drop, &a, sizeof(isc_event_t));
assert_non_null(event);
isc_task_send(task1, &event);
/* Second event: not privileged */
- event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
+ event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
set_and_drop, &b, sizeof(isc_event_t));
assert_non_null(event);
isc_task_send(task2, &event);
/* Third event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
set_and_drop, &c, sizeof(isc_event_t));
assert_non_null(event);
isc_task_send(task1, &event);
/* Fourth event: privileged */
- event = isc_event_allocate(test_mctx, task1, ISC_TASKEVENT_TEST,
+ event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
set_and_drop, &d, sizeof(isc_event_t));
assert_non_null(event);
isc_task_send(task1, &event);
/* Fifth event: not privileged */
- event = isc_event_allocate(test_mctx, task2, ISC_TASKEVENT_TEST,
+ event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
set_and_drop, &e, sizeof(isc_event_t));
assert_non_null(event);
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;
* 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);
}
}
-static void
-task_exclusive(void **state) {
+ISC_RUN_TEST_IMPL(task_exclusive) {
isc_task_t *tasks[10];
isc_result_t result;
int i;
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);
}
while (atomic_load(&counter) > 0) {
- isc_test_nap(1000);
+ uv_sleep(1000);
}
}
}
}
-static void
-manytasks(void **state) {
- isc_mem_t *mctx = NULL;
+ISC_RUN_TEST_IMPL(manytasks) {
isc_event_t *event = NULL;
uintptr_t ntasks = 10000;
(unsigned long)ntasks);
}
- isc_mutex_init(&lock);
- isc_condition_init(&cv);
-
- isc_mem_debugging = ISC_MEM_DEBUGRECORD;
- isc_mem_create(&mctx);
-
- isc_managers_create(mctx, 4, 0, &netmgr, &taskmgr, NULL);
-
atomic_init(&done, false);
event = isc_event_allocate(mctx, (void *)1, 1, maxtask_cb,
WAIT(&cv, &lock);
}
UNLOCK(&lock);
-
- isc_managers_destroy(&netmgr, &taskmgr, NULL);
-
- isc_mem_destroy(&mctx);
- isc_condition_destroy(&cv);
- isc_mutex_destroy(&lock);
}
/*
isc_event_free(&event);
}
-static void
-task_shutdown(void **state) {
+ISC_RUN_TEST_IMPL(task_shutdown) {
isc_result_t result;
isc_eventtype_t event_type;
isc_event_t *event = NULL;
/*
* This event causes the task to wait on cv.
*/
- event = isc_event_allocate(test_mctx, &senders[1], event_type,
- sd_event1, NULL, sizeof(*event));
+ event = isc_event_allocate(mctx, &senders[1], event_type, sd_event1,
+ NULL, sizeof(*event));
assert_non_null(event);
isc_task_send(task, &event);
* Now we fill up the task's event queue with some events.
*/
for (i = 0; i < 256; ++i) {
- event = isc_event_allocate(test_mctx, &senders[1], event_type,
+ event = isc_event_allocate(mctx, &senders[1], event_type,
sd_event2, NULL, sizeof(*event));
assert_non_null(event);
isc_task_send(task, &event);
isc_event_free(&event);
}
-static void
-post_shutdown(void **state) {
+ISC_RUN_TEST_IMPL(post_shutdown) {
isc_result_t result;
isc_eventtype_t event_type;
isc_event_t *event;
/*
* This event causes the task to wait on cv.
*/
- event = isc_event_allocate(test_mctx, &senders[1], event_type,
- psd_event1, NULL, sizeof(*event));
+ event = isc_event_allocate(mctx, &senders[1], event_type, psd_event1,
+ NULL, sizeof(*event));
assert_non_null(event);
isc_task_send(task, &event);
/*
* Block the task on cv.
*/
- event = isc_event_allocate(test_mctx, (void *)1, 9999, pg_event1, NULL,
+ event = isc_event_allocate(mctx, (void *)1, 9999, pg_event1, NULL,
sizeof(*event));
assert_non_null(event);
for (type_cnt = 0; type_cnt < TYPECNT; ++type_cnt) {
for (tag_cnt = 0; tag_cnt < TAGCNT; ++tag_cnt) {
eventtab[event_cnt] = isc_event_allocate(
- test_mctx,
- &senders[sender + sender_cnt],
+ mctx, &senders[sender + sender_cnt],
(isc_eventtype_t)(type + type_cnt),
pg_event2, NULL, sizeof(*event));
* type 'type' and with tag 'tag' not marked as unpurgeable from sender
* from the task's " queue and returns the number of events purged.
*/
-static void
-purge(void **state) {
+ISC_RUN_TEST_IMPL(purge) {
UNUSED(state);
/* Try purging on a specific sender. */
* returns the number of tasks purged.
*/
-static void
-purgerange(void **state) {
+ISC_RUN_TEST_IMPL(purgerange) {
UNUSED(state);
/* Now let's try some ranges. */
/*
* 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);
WAITUNTIL(&cv, &lock, &now);
}
-
UNLOCK(&lock);
isc_task_detach(&task);
* task's queue and returns true.
*/
-static void
-purgeevent(void **state) {
+ISC_RUN_TEST_IMPL(purgeevent) {
UNUSED(state);
try_purgeevent(true);
* 'event' from the task's queue and returns false.
*/
-static void
-purgeevent_notpurge(void **state) {
+ISC_RUN_TEST_IMPL(purgeevent_notpurge) {
UNUSED(state);
try_purgeevent(false);
}
-int
-main(int argc, char **argv) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(manytasks),
- 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(post_shutdown, _setup2,
- _teardown),
- cmocka_unit_test_setup_teardown(privilege_drop, _setup,
- _teardown),
- cmocka_unit_test_setup_teardown(privileged_events, _setup,
- _teardown),
- cmocka_unit_test_setup_teardown(purge, _setup2, _teardown),
- cmocka_unit_test_setup_teardown(purgeevent, _setup2, _teardown),
- cmocka_unit_test_setup_teardown(purgeevent_notpurge, _setup,
- _teardown),
- cmocka_unit_test_setup_teardown(purgerange, _setup, _teardown),
- cmocka_unit_test_setup_teardown(task_shutdown, _setup4,
- _teardown),
- cmocka_unit_test_setup_teardown(task_exclusive, _setup4,
- _teardown),
- };
- struct CMUnitTest selected[sizeof(tests) / sizeof(tests[0])];
- size_t i;
- int c;
-
- memset(selected, 0, sizeof(selected));
-
- 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_START
- if (selected[0].name != NULL) {
- return (cmocka_run_group_tests(selected, NULL, NULL));
- } else {
- return (cmocka_run_group_tests(tests, NULL, NULL));
- }
-}
+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(post_shutdown, _setup2, _teardown)
+ISC_TEST_ENTRY_CUSTOM(privilege_drop, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(privileged_events, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(purge, _setup2, _teardown)
+ISC_TEST_ENTRY_CUSTOM(purgeevent, _setup2, _teardown)
+ISC_TEST_ENTRY_CUSTOM(purgeevent_notpurge, _setup2, _teardown)
+ISC_TEST_ENTRY_CUSTOM(task_shutdown, _setup4, _teardown)
+ISC_TEST_ENTRY_CUSTOM(task_exclusive, _setup4, _teardown)
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <isc/taskpool.h>
#include <isc/util.h>
-#include "isctest.h"
+#include <isc/test.h>
#define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K')
#define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC)
-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);
-}
-
/* Create a taskpool */
-static void
-create_pool(void **state) {
+ISC_RUN_TEST_IMPL(create_pool) {
isc_result_t result;
isc_taskpool_t *pool = NULL;
UNUSED(state);
- result = isc_taskpool_create(taskmgr, test_mctx, 8, 2, false, &pool);
+ result = isc_taskpool_create(taskmgr, mctx, 8, 2, false, &pool);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_taskpool_size(pool), 8);
}
/* Resize a taskpool */
-static void
-expand_pool(void **state) {
+ISC_RUN_TEST_IMPL(expand_pool) {
isc_result_t result;
isc_taskpool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
UNUSED(state);
- result = isc_taskpool_create(taskmgr, test_mctx, 10, 2, false, &pool1);
+ result = isc_taskpool_create(taskmgr, mctx, 10, 2, false, &pool1);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_taskpool_size(pool1), 10);
}
/* Get tasks */
-static void
-get_tasks(void **state) {
+ISC_RUN_TEST_IMPL(get_tasks) {
isc_result_t result;
isc_taskpool_t *pool = NULL;
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
UNUSED(state);
- result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, false, &pool);
+ result = isc_taskpool_create(taskmgr, mctx, 2, 2, false, &pool);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_taskpool_size(pool), 2);
}
/* Set privileges */
-static void
-set_privilege(void **state) {
+ISC_RUN_TEST_IMPL(set_privilege) {
isc_result_t result;
isc_taskpool_t *pool = NULL;
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
UNUSED(state);
- result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, true, &pool);
+ result = isc_taskpool_create(taskmgr, mctx, 2, 2, true, &pool);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_taskpool_size(pool), 2);
assert_null(pool);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(create_pool, _setup, _teardown),
- cmocka_unit_test_setup_teardown(expand_pool, _setup, _teardown),
- cmocka_unit_test_setup_teardown(get_tasks, _setup, _teardown),
- cmocka_unit_test_setup_teardown(set_privilege, _setup,
- _teardown),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY_CUSTOM(create_pool, setup_managers, teardown_managers)
+ISC_TEST_ENTRY_CUSTOM(expand_pool, setup_managers, teardown_managers)
+ISC_TEST_ENTRY_CUSTOM(get_tasks, setup_managers, teardown_managers)
+ISC_TEST_ENTRY_CUSTOM(set_privilege, setup_managers, teardown_managers)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include "../time.c"
+#include <isc/test.h>
+
#define NS_PER_S 1000000000 /*%< Nanoseconds per second. */
#define MAX_NS (NS_PER_S - 1)
{ { 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++) {
&(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++) {
}
/* 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];
}
/* 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];
}
/* 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];
}
/* 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];
}
/* 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];
}
/* 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];
}
/* 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];
}
/* 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];
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),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+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)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <uv.h>
#define UNIT_TESTING
#include <cmocka.h>
#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;
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);
}
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);
}
}
*/
/* timer type ticker */
-static void
-ticker(void **state) {
+ISC_RUN_TEST_IMPL(ticker) {
isc_time_t expires;
isc_interval_t interval;
}
/* timer type once reaches lifetime */
-static void
-once_life(void **state) {
+ISC_RUN_TEST_IMPL(once_life) {
isc_result_t result;
isc_time_t expires;
isc_interval_t interval;
}
/* timer type once idles out */
-static void
-once_idle(void **state) {
+ISC_RUN_TEST_IMPL(once_idle) {
isc_result_t result;
isc_time_t expires;
isc_interval_t interval;
isc_event_free(&event);
}
-static void
-reset(void **state) {
+ISC_RUN_TEST_IMPL(reset) {
isc_time_t expires;
isc_interval_t interval;
}
/* timer events purged */
-static void
-purge(void **state) {
+ISC_RUN_TEST_IMPL(purge) {
isc_result_t result;
isc_time_t expires;
isc_interval_t interval;
* 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);
isc_task_destroy(&task2);
}
-int
-main(int argc, char **argv) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(ticker), cmocka_unit_test(once_life),
- cmocka_unit_test(once_idle), cmocka_unit_test(reset),
- cmocka_unit_test(purge),
- };
- int c;
-
- while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
- switch (c) {
- case 'v':
- verbose = true;
- break;
- default:
- break;
- }
- }
-
- return (cmocka_run_group_tests(tests, _setup, _teardown));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY_CUSTOM(ticker, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(once_life, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(once_idle, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(reset, _setup, _teardown)
+ISC_TEST_ENTRY_CUSTOM(purge, _setup, _teardown)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
$(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
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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 },
{ "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;
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);
+
+ if (result != ISC_R_SUCCESS) {
+ return (-1);
+ }
+
+ return (0);
+}
- return (ISC_R_SUCCESS);
+ISC_TEARDOWN_TEST_IMPL(group) {
+ if (lctx == NULL) {
+ return (-1);
+ }
+
+ isc_log_setcontext(NULL);
+ isc_log_destroy(&lctx);
-cleanup:
- cleanup();
- return (result);
+ return (0);
}
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 },
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;
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));
-}
-
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(cfg_obj_asduration)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#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 },
{ "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;
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);
}
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;
};
char buf[1024];
- UNUSED(state);
-
/* Parse with default line numbering */
result = cfg_parser_create(mctx, lctx, &p);
assert_int_equal(result, ISC_R_SUCCESS);
}
/* 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);
}
/* 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);
}
/* 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);
} 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),
- };
-
- return (cmocka_run_group_tests(tests, _setup, _teardown));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY(addzoneconf)
+ISC_TEST_ENTRY(parse_buffer)
+ISC_TEST_ENTRY(cfg_map_firstclause)
+ISC_TEST_ENTRY(cfg_map_nextclause)
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN_CUSTOM(setup_test_group, teardown_test_group)
#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) \
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 int ncpus;
-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
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);
* 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;
/*%
*/
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().
#include <time.h>
#include <unistd.h>
-#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/hash.h>
#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;
-int ncpus;
bool debug_mem_record = true;
-static atomic_bool run_managers = false;
-
-static bool dst_active = false;
-static bool test_running = false;
-
-static dns_zone_t *served_zone = NULL;
-
-/*
- * We don't want to use netmgr-based client accounting, we need to emulate it.
- */
-atomic_uint_fast32_t client_refs[32];
-atomic_uintptr_t client_addrs[32];
-
-void
-isc__nmhandle_attach(isc_nmhandle_t *source, isc_nmhandle_t **targetp FLARG) {
- ns_client_t *client = (ns_client_t *)source;
- int i;
-
- for (i = 0; i < 32; i++) {
- if (atomic_load(&client_addrs[i]) == (uintptr_t)client) {
- break;
- }
- }
- INSIST(i < 32);
- INSIST(atomic_load(&client_refs[i]) > 0);
-
- atomic_fetch_add(&client_refs[i], 1);
-
- *targetp = source;
- return;
-}
-
-void
-isc__nmhandle_detach(isc_nmhandle_t **handlep FLARG) {
- isc_nmhandle_t *handle = *handlep;
- ns_client_t *client = (ns_client_t *)handle;
- int i;
-
- *handlep = NULL;
-
- for (i = 0; i < 32; i++) {
- if (atomic_load(&client_addrs[i]) == (uintptr_t)client) {
- break;
- }
- }
- INSIST(i < 32);
-
- if (atomic_fetch_sub(&client_refs[i], 1) == 1) {
- dns_view_detach(&client->view);
- client->state = 4;
- ns__client_reset_cb(client);
- ns__client_put_cb(client);
- isc_mem_put(mctx, client, sizeof(ns_client_t));
- atomic_store(&client_addrs[i], (uintptr_t)NULL);
- }
-
- 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,
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);
-
- 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);
-
- isc_event_free(&event);
-}
+int
+setup_server(void **state) {
+ isc_result_t result;
+ ns_listenlist_t *listenon = NULL;
+ in_port_t port = 5300 + isc_random8();
-static void
-cleanup_managers(void) {
- atomic_store(&shutdown_done, false);
+ setup_managers(state);
- if (maintask != NULL) {
- isc_task_shutdown(maintask);
- isc_task_destroy(&maintask);
- }
+ ns_server_create(mctx, matchview, &sctx);
- 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);
+ result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr);
+ if (result != ISC_R_SUCCESS) {
+ return (-1);
}
- if (sctx != NULL) {
- ns_server_detach(&sctx);
- }
- if (interfacemgr != NULL) {
- ns_interfacemgr_detach(&interfacemgr);
+ result = ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, netmgr,
+ dispatchmgr, maintask, NULL, workers,
+ false, &interfacemgr);
+ if (result != ISC_R_SUCCESS) {
+ return (-1);
}
- isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
- taskmgr == NULL ? NULL : &taskmgr,
- timermgr == NULL ? NULL : &timermgr);
-
- if (app_running) {
- isc_app_finish();
+ result = ns_listenlist_default(mctx, port, -1, true, AF_INET,
+ &listenon);
+ if (result != ISC_R_SUCCESS) {
+ return (-1);
}
-}
-
-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;
- ncpus = isc_os_ncpus();
-
- isc_managers_create(mctx, ncpus, 0, &netmgr, &taskmgr, &timermgr);
- CHECK(isc_task_create_bound(taskmgr, 0, &maintask, 0));
- isc_taskmgr_setexcltask(taskmgr, maintask);
- CHECK(isc_task_onshutdown(maintask, shutdown_managers, NULL));
-
- 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, ncpus, 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);
+ return (0);
}
-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);
+int
+teardown_server(void **state) {
+ if (interfacemgr != NULL) {
+ ns_interfacemgr_shutdown(interfacemgr);
+ ns_interfacemgr_detach(&interfacemgr);
}
- 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 (dispatchmgr != NULL) {
+ dns_dispatchmgr_detach(&dispatchmgr);
}
- if (mctx != NULL) {
- isc_mem_destroy(&mctx);
+ if (sctx != NULL) {
+ ns_server_detach(&sctx);
}
- test_running = false;
+ teardown_managers(state);
+ return (0);
}
-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);
-}
+static dns_zone_t *served_zone = NULL;
/*
- * 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.
+ * We don't want to use netmgr-based client accounting, we need to emulate it.
*/
-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));
- }
+atomic_uint_fast32_t client_refs[32];
+atomic_uintptr_t client_addrs[32];
- 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);
+void
+isc__nmhandle_attach(isc_nmhandle_t *source, isc_nmhandle_t **targetp FLARG) {
+ ns_client_t *client = (ns_client_t *)source;
+ int i;
- if (!keepview) {
- dns_view_detach(&view);
+ for (i = 0; i < 32; i++) {
+ if (atomic_load(&client_addrs[i]) == (uintptr_t)client) {
+ break;
+ }
}
+ INSIST(i < 32);
+ INSIST(atomic_load(&client_refs[i]) > 0);
- *zonep = zone;
-
- return (ISC_R_SUCCESS);
+ atomic_fetch_add(&client_refs[i], 1);
-cleanup:
- if (zone != NULL) {
- dns_zone_detach(&zone);
- }
- if (view != NULL) {
- dns_view_detach(&view);
- }
- return (result);
+ *targetp = source;
+ return;
}
-isc_result_t
-ns_test_setupzonemgr(void) {
- isc_result_t result;
- REQUIRE(zonemgr == NULL);
-
- result = dns_zonemgr_create(mctx, taskmgr, timermgr, NULL, &zonemgr);
- return (result);
-}
+void
+isc__nmhandle_detach(isc_nmhandle_t **handlep FLARG) {
+ isc_nmhandle_t *handle = *handlep;
+ ns_client_t *client = (ns_client_t *)handle;
+ int i;
-isc_result_t
-ns_test_managezone(dns_zone_t *zone) {
- isc_result_t result;
- REQUIRE(zonemgr != NULL);
+ *handlep = NULL;
- result = dns_zonemgr_setsize(zonemgr, 1);
- if (result != ISC_R_SUCCESS) {
- return (result);
+ for (i = 0; i < 32; i++) {
+ if (atomic_load(&client_addrs[i]) == (uintptr_t)client) {
+ break;
+ }
}
+ INSIST(i < 32);
- 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);
+ if (atomic_fetch_sub(&client_refs[i], 1) == 1) {
+ dns_view_detach(&client->view);
+ client->state = 4;
+ ns__client_reset_cb(client);
+ ns__client_put_cb(client);
+ isc_mem_put(mctx, client, sizeof(ns_client_t));
+ atomic_store(&client_addrs[i], (uintptr_t)NULL);
+ }
- dns_zonemgr_shutdown(zonemgr);
- dns_zonemgr_detach(&zonemgr);
+ return;
}
isc_result_t
/*
* 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);
}
/*
* Start zone manager.
*/
- result = ns_test_setupzonemgr();
+ result = dns_test_setupzonemgr();
if (result != ISC_R_SUCCESS) {
goto free_zone;
}
/*
* 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;
}
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);
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);
}
/*
* 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;
}
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) {
$(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 \
* information regarding copyright ownership.
*/
-#include <isc/util.h>
-
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
+#include <isc/util.h>
+
#define UNIT_TESTING
#include <cmocka.h>
#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;
ns_listenlist_detach(&list);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(ns_listenlist_default_test,
- _setup, _teardown),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
+ISC_TEST_LIST_START
-#else /* HAVE_CMOCKA */
+ISC_TEST_ENTRY_CUSTOM(ns_listenlist_default, _setup, _teardown)
-#include <stdio.h>
-
-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
* information regarding copyright ownership.
*/
-#include <isc/util.h>
-
-#if HAVE_CMOCKA
-
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
+#include <isc/util.h>
+
#define UNIT_TESTING
#include <cmocka.h>
#include <ns/client.h>
#include <ns/notify.h>
-#include "nstest.h"
+#include <dns/test.h>
-static int
-_setup(void **state) {
- isc_result_t result;
-
- UNUSED(state);
+#include <ns/test.h>
+static int
+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
}
/* 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;
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",
isc_nmhandle_detach(&handle);
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(notify_start, _setup,
- _teardown),
- };
-
- 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);
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY_CUSTOM(ns_notify_start, setup_test, teardown_test)
+ISC_TEST_LIST_END
-#endif /* HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#if HAVE_CMOCKA
-
#include <limits.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#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().
}
/* 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[] = {
}
}
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(ns_plugin_expandpath_test,
- _setup, _teardown),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-#else /* HAVE_CMOCKA */
+ISC_TEST_LIST_START
-#include <stdio.h>
+ISC_TEST_ENTRY_CUSTOM(ns_plugin_expandpath, setup_managers, teardown_managers)
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (SKIPPED_TEST_EXIT_CODE);
-}
+ISC_TEST_LIST_END
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
* information regarding copyright ownership.
*/
-#include <isc/util.h>
-
-#if HAVE_CMOCKA
-
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
+#include <isc/util.h>
+
#define UNIT_TESTING
#include <cmocka.h>
#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);
}
}
/* 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[] = {
/*
* 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);
}
/* 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[] = {
}
}
-static void
-ns__query_hookasync_test(void **state) {
+ISC_RUN_TEST_IMPL(ns_query_hookasync) {
size_t i;
UNUSED(state);
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[] = {
}
}
-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));
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
-
- return (SKIPPED_TEST_EXIT_CODE);
-}
+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)
-#endif /* HAVE_CMOCKA */
+ISC_TEST_LIST_END
+ISC_TEST_MAIN