From 1b48e710d526a21601549eb1f6951fba73b7300a Mon Sep 17 00:00:00 2001 From: Joey Date: Wed, 14 Nov 2018 20:19:50 +0800 Subject: [PATCH] convert name_test --- lib/dns/tests/name_test.c | 352 ++++++++++++++++++++------------------ 1 file changed, 187 insertions(+), 165 deletions(-) diff --git a/lib/dns/tests/name_test.c b/lib/dns/tests/name_test.c index 68d1acc1ad..20fcec8b0e 100644 --- a/lib/dns/tests/name_test.c +++ b/lib/dns/tests/name_test.c @@ -9,17 +9,22 @@ * information regarding copyright ownership. */ -/*! \file */ - #include +#if HAVE_CMOCKA + +#include +#include +#include + #include #include #include #include #include -#include +#define UNIT_TESTING +#include #include #include @@ -35,15 +40,30 @@ #include "dnstest.h" -/* - * Individual unit tests - */ +static int +_setup(void **state) { + isc_result_t result; -ATF_TC(fullcompare); -ATF_TC_HEAD(fullcompare, tc) { - atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test"); + UNUSED(state); + + result = dns_test_begin(NULL, false); + assert_int_equal(result, ISC_R_SUCCESS); + + return (0); } -ATF_TC_BODY(fullcompare, tc) { + +static int +_teardown(void **state) { + UNUSED(state); + + dns_test_end(); + + return (0); +} + +/* dns_name_fullcompare test */ +static void +fullcompare_test(void **state) { dns_fixedname_t fixed1; dns_fixedname_t fixed2; dns_name_t *name1; @@ -84,7 +104,7 @@ ATF_TC_BODY(fullcompare, tc) { { NULL, NULL, dns_namereln_none, 0, 0 } }; - UNUSED(tc); + UNUSED(state); name1 = dns_fixedname_initname(&fixed1); name2 = dns_fixedname_initname(&fixed2); @@ -97,28 +117,28 @@ ATF_TC_BODY(fullcompare, tc) { } else { result = dns_name_fromstring2(name1, data[i].name1, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); } if (data[i].name2[0] == 0) { dns_fixedname_init(&fixed2); } else { result = dns_name_fromstring2(name2, data[i].name2, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); } relation = dns_name_fullcompare(name1, name1, &order, &nlabels); - ATF_REQUIRE_EQ(relation, dns_namereln_equal); - ATF_REQUIRE_EQ(order, 0); - ATF_REQUIRE_EQ(nlabels, name1->labels); + assert_int_equal(relation, dns_namereln_equal); + assert_int_equal(order, 0); + assert_int_equal(nlabels, name1->labels); /* Some random initializer */ order = 3001; nlabels = 3001; relation = dns_name_fullcompare(name1, name2, &order, &nlabels); - ATF_REQUIRE_EQ(relation, data[i].relation); - ATF_REQUIRE_EQ(order, data[i].order); - ATF_REQUIRE_EQ(nlabels, data[i].nlabels); + assert_int_equal(relation, data[i].relation); + assert_int_equal(order, data[i].order); + assert_int_equal(nlabels, data[i].nlabels); } } @@ -136,11 +156,11 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, isc_buffer_init(&source, buf1, sizeof(buf1)); isc_buffer_init(&target, buf2, sizeof(buf2)); - ATF_REQUIRE_EQ(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS); + assert_int_equal(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS); - ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - ATF_CHECK_EQ(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS); + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); + assert_int_equal(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS); isc_buffer_setactive(&source, source.used); @@ -155,15 +175,13 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, &target) == ISC_R_SUCCESS); dns_decompress_invalidate(dctx); - ATF_CHECK_EQ(target.used, length); - ATF_CHECK(memcmp(target.base, expected, target.used) == 0); + assert_int_equal(target.used, length); + assert_true(memcmp(target.base, expected, target.used) == 0); } -ATF_TC(compression); -ATF_TC_HEAD(compression, tc) { - atf_tc_set_md_var(tc, "descr", "name compression test"); -} -ATF_TC_BODY(compression, tc) { +/* name compression test */ +static void +compression_test(void **state) { unsigned int allowed; dns_compress_t cctx; dns_decompress_t dctx; @@ -177,7 +195,7 @@ ATF_TC_BODY(compression, tc) { unsigned char plain[] = "\003yyy\003foo\0\003bar\003yyy\003foo\0\003" "bar\003yyy\003foo\0\003xxx\003bar\003foo"; - ATF_REQUIRE_EQ(dns_test_begin(NULL, false), ISC_R_SUCCESS);; + UNUSED(state); dns_name_init(&name1, NULL); r.base = plain1; @@ -196,7 +214,7 @@ ATF_TC_BODY(compression, tc) { /* Test 1: NONE */ allowed = DNS_COMPRESS_NONE; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -209,7 +227,7 @@ ATF_TC_BODY(compression, tc) { /* Test2: GLOBAL14 */ allowed = DNS_COMPRESS_GLOBAL14; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -222,7 +240,7 @@ ATF_TC_BODY(compression, tc) { /* Test3: ALL */ allowed = DNS_COMPRESS_ALL; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -235,7 +253,7 @@ ATF_TC_BODY(compression, tc) { /* Test4: NONE disabled */ allowed = DNS_COMPRESS_NONE; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -249,7 +267,7 @@ ATF_TC_BODY(compression, tc) { /* Test5: GLOBAL14 disabled */ allowed = DNS_COMPRESS_GLOBAL14; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -263,7 +281,7 @@ ATF_TC_BODY(compression, tc) { /* Test6: ALL disabled */ allowed = DNS_COMPRESS_ALL; - ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, 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); @@ -274,15 +292,11 @@ ATF_TC_BODY(compression, tc) { dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); - - dns_test_end(); } -ATF_TC(istat); -ATF_TC_HEAD(istat, tc) { - atf_tc_set_md_var(tc, "descr", "is trust-anchor-telemetry test"); -} -ATF_TC_BODY(istat, tc) { +/* is trust-anchor-telemetry test */ +static void +istat_test(void **state) { dns_fixedname_t fixed; dns_name_t *name; isc_result_t result; @@ -315,74 +329,73 @@ ATF_TC_BODY(istat, tc) { { "_ta-1234-abcf-EcD89.example", false } }; + UNUSED(state); + name = dns_fixedname_initname(&fixed); - for (i = 0; i < sizeof(data)/sizeof(data[0]); i++) { + for (i = 0; i < (sizeof(data) / sizeof(data[0])); i++) { result = dns_name_fromstring(name, data[i].name, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); - ATF_CHECK_EQ_MSG(dns_name_istat(name), data[i].istat, - "testing %s - expected %u", data[i].name, data[i].istat); + assert_int_equal(result, ISC_R_SUCCESS); + assert_int_equal(dns_name_istat(name), data[i].istat); } } -ATF_TC(init); -ATF_TC_HEAD(init, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_init"); -} -ATF_TC_BODY(init, tc) { +/* dns_nane_init */ +static void +init_test(void **state) { dns_name_t name; unsigned char offsets[1]; + UNUSED(state); + dns_name_init(&name, offsets); - ATF_CHECK_EQ(name.ndata, NULL); - ATF_CHECK_EQ(name.length, 0); - ATF_CHECK_EQ(name.labels, 0); - ATF_CHECK_EQ(name.attributes, 0); - ATF_CHECK_EQ(name.offsets, offsets); - ATF_CHECK_EQ(name.buffer, NULL); + assert_null(name.ndata); + assert_int_equal(name.length, 0); + assert_int_equal(name.labels, 0); + assert_int_equal(name.attributes, 0); + assert_int_equal(name.offsets, offsets); + assert_null(name.buffer); } -ATF_TC(invalidate); -ATF_TC_HEAD(invalidate, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_invalidate"); -} -ATF_TC_BODY(invalidate, tc) { +/* dns_nane_invalidate */ +static void +invalidate_test(void **state) { dns_name_t name; unsigned char offsets[1]; + UNUSED(state); + dns_name_init(&name, offsets); dns_name_invalidate(&name); - ATF_CHECK_EQ(name.ndata, NULL); - ATF_CHECK_EQ(name.length, 0); - ATF_CHECK_EQ(name.labels, 0); - ATF_CHECK_EQ(name.attributes, 0); - ATF_CHECK_EQ(name.offsets, NULL); - ATF_CHECK_EQ(name.buffer, NULL); + assert_null(name.ndata); + assert_int_equal(name.length, 0); + assert_int_equal(name.labels, 0); + assert_int_equal(name.attributes, 0); + assert_null(name.offsets); + assert_null(name.buffer); } -ATF_TC(buffer); -ATF_TC_HEAD(buffer, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_setbuffer/hasbuffer"); -} -ATF_TC_BODY(buffer, tc) { +/* dns_nane_setbuffer/hasbuffer */ +static void +buffer_test(void **state) { dns_name_t name; unsigned char buf[BUFSIZ]; isc_buffer_t b; + UNUSED(state); + isc_buffer_init(&b, buf, BUFSIZ); dns_name_init(&name, NULL); dns_name_setbuffer(&name, &b); - ATF_CHECK_EQ(name.buffer, &b); - ATF_CHECK(dns_name_hasbuffer(&name)); + assert_int_equal(name.buffer, &b); + assert_true(dns_name_hasbuffer(&name)); } -ATF_TC(isabsolute); -ATF_TC_HEAD(isabsolute, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_isabsolute"); -} -ATF_TC_BODY(isabsolute, tc) { +/* dns_nane_isabsolute */ +static void +isabsolute_test(void **state) { struct { const char *namestr; bool expect; @@ -393,7 +406,9 @@ ATF_TC_BODY(isabsolute, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_name_t name; unsigned char data[BUFSIZ]; @@ -408,17 +423,16 @@ ATF_TC_BODY(isabsolute, tc) { isc_buffer_init(&nb, data, BUFSIZ); dns_name_setbuffer(&name, &nb); result = dns_name_fromtext(&name, &b, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); - ATF_CHECK_EQ(dns_name_isabsolute(&name), testcases[i].expect); + assert_int_equal(dns_name_isabsolute(&name), + testcases[i].expect); } } -ATF_TC(hash); -ATF_TC_HEAD(hash, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_hash"); -} -ATF_TC_BODY(hash, tc) { +/* dns_nane_hash */ +static void +hash_test(void **state) { struct { const char *name1; const char *name2; @@ -434,7 +448,9 @@ ATF_TC_BODY(hash, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_fixedname_t f1, f2; dns_name_t *n1, *n2; @@ -445,10 +461,10 @@ ATF_TC_BODY(hash, tc) { result = dns_name_fromstring2(n1, testcases[i].name1, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_name_fromstring2(n2, testcases[i].name2, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); /* Check case-insensitive hashing first */ h1 = dns_name_hash(n1, false); @@ -457,7 +473,7 @@ ATF_TC_BODY(hash, tc) { printf("%s hashes to %u, %s to %u, case insensitive\n", testcases[i].name1, h1, testcases[i].name2, h2); - ATF_REQUIRE_EQ((h1 == h2), testcases[i].expect); + assert_int_equal((h1 == h2), testcases[i].expect); /* Now case-sensitive */ h1 = dns_name_hash(n1, false); @@ -466,15 +482,13 @@ ATF_TC_BODY(hash, tc) { printf("%s hashes to %u, %s to %u, case sensitive\n", testcases[i].name1, h1, testcases[i].name2, h2); - ATF_REQUIRE_EQ((h1 == h2), testcases[i].expect); + assert_int_equal((h1 == h2), testcases[i].expect); } } -ATF_TC(issubdomain); -ATF_TC_HEAD(issubdomain, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_issubdomain"); -} -ATF_TC_BODY(issubdomain, tc) { +/* dns_nane_issubdomain */ +static void +issubdomain_test(void **state) { struct { const char *name1; const char *name2; @@ -490,7 +504,9 @@ ATF_TC_BODY(issubdomain, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_fixedname_t f1, f2; dns_name_t *n1, *n2; @@ -500,26 +516,24 @@ ATF_TC_BODY(issubdomain, tc) { result = dns_name_fromstring2(n1, testcases[i].name1, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_name_fromstring2(n2, testcases[i].name2, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); printf("check: %s %s a subdomain of %s\n", testcases[i].name1, testcases[i].expect ? "is" : "is not", testcases[i].name2); - ATF_CHECK_EQ(dns_name_issubdomain(n1, n2), + assert_int_equal(dns_name_issubdomain(n1, n2), testcases[i].expect); } } -ATF_TC(countlabels); -ATF_TC_HEAD(countlabels, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_countlabels"); -} -ATF_TC_BODY(countlabels, tc) { +/* dns_nane_countlabels */ +static void +countlabels_test(void **state) { struct { const char *namestr; unsigned int expect; @@ -533,7 +547,9 @@ ATF_TC_BODY(countlabels, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_fixedname_t fname; dns_name_t *name; @@ -542,21 +558,19 @@ ATF_TC_BODY(countlabels, tc) { result = dns_name_fromstring2(name, testcases[i].namestr, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); printf("%s: expect %u labels\n", testcases[i].namestr, testcases[i].expect); - ATF_REQUIRE_EQ(dns_name_countlabels(name), + assert_int_equal(dns_name_countlabels(name), testcases[i].expect); } } -ATF_TC(getlabel); -ATF_TC_HEAD(getlabel, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_getlabel"); -} -ATF_TC_BODY(getlabel, tc) { +/* dns_nane_getlabel */ +static void +getlabel_test(void **state) { struct { const char *name1; unsigned int pos1; @@ -569,7 +583,9 @@ ATF_TC_BODY(getlabel, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_fixedname_t f1, f2; dns_name_t *n1, *n2; @@ -582,28 +598,26 @@ ATF_TC_BODY(getlabel, tc) { result = dns_name_fromstring2(n1, testcases[i].name1, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_name_fromstring2(n2, testcases[i].name2, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); dns_name_getlabel(n1, testcases[i].pos1, &l1); dns_name_getlabel(n2, testcases[i].pos2, &l2); - ATF_CHECK_EQ(l1.length, l2.length); + assert_int_equal(l1.length, l2.length); p1 = l1.base; p2 = l2.base; for (j = 0; j < l1.length; j++) { - ATF_REQUIRE_EQ(*p1++, *p2++); + assert_int_equal(*p1++, *p2++); } } } -ATF_TC(getlabelsequence); -ATF_TC_HEAD(getlabelsequence, tc) { - atf_tc_set_md_var(tc, "descr", "dns_nane_getlabelsequence"); -} -ATF_TC_BODY(getlabelsequence, tc) { +/* dns_nane_getlabelsequence */ +static void +getlabelsequence_test(void **state) { struct { const char *name1; unsigned int pos1; @@ -618,7 +632,9 @@ ATF_TC_BODY(getlabelsequence, tc) { }; unsigned int i; - for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) { + UNUSED(state); + + for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) { isc_result_t result; dns_name_t t1, t2; dns_fixedname_t f1, f2; @@ -634,17 +650,17 @@ ATF_TC_BODY(getlabelsequence, tc) { result = dns_name_fromstring2(n1, testcases[i].name1, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_name_fromstring2(n2, testcases[i].name2, NULL, 0, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); dns_name_getlabelsequence(n1, testcases[i].pos1, testcases[i].range, &t1); dns_name_getlabelsequence(n2, testcases[i].pos2, testcases[i].range, &t2); - ATF_REQUIRE(dns_name_equal(&t1, &t2)); + assert_true(dns_name_equal(&t1, &t2)); } } @@ -655,11 +671,7 @@ ATF_TC_BODY(getlabelsequence, tc) { * name parser, but we don't require it as part of the unit test runs. */ -ATF_TC(benchmark); -ATF_TC_HEAD(benchmark, tc) { - atf_tc_set_md_var(tc, "descr", - "Benchmark dns_name_fromwire() implementation"); -} +/* Benchmark dns_name_fromwire() implementation */ static void * fromwire_thread(void *arg) { @@ -700,7 +712,8 @@ fromwire_thread(void *arg) { return (NULL); } -ATF_TC_BODY(benchmark, tc) { +static void +benchmark_test(void **state) { isc_result_t result; unsigned int i; isc_time_t ts1, ts2; @@ -708,61 +721,70 @@ ATF_TC_BODY(benchmark, tc) { unsigned int nthreads; isc_thread_t threads[32]; - UNUSED(tc); + UNUSED(state); debug_mem_record = false; - result = dns_test_begin(NULL, true); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); - result = isc_time_now(&ts1); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); nthreads = ISC_MIN(isc_os_ncpus(), 32); nthreads = ISC_MAX(nthreads, 1); for (i = 0; i < nthreads; i++) { result = isc_thread_create(fromwire_thread, NULL, &threads[i]); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); } for (i = 0; i < nthreads; i++) { result = isc_thread_join(threads[i], NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); } result = isc_time_now(&ts2); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); t = isc_time_microdiff(&ts2, &ts1); printf("%u dns_name_fromwire() calls, %f seconds, %f calls/second\n", nthreads * 32000000, t / 1000000.0, (nthreads * 32000000) / (t / 1000000.0)); - - dns_test_end(); } #endif /* DNS_BENCHMARK_TESTS */ -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, fullcompare); - ATF_TP_ADD_TC(tp, compression); - ATF_TP_ADD_TC(tp, istat); - ATF_TP_ADD_TC(tp, init); - ATF_TP_ADD_TC(tp, invalidate); - ATF_TP_ADD_TC(tp, buffer); - ATF_TP_ADD_TC(tp, isabsolute); - ATF_TP_ADD_TC(tp, hash); - ATF_TP_ADD_TC(tp, issubdomain); - ATF_TP_ADD_TC(tp, countlabels); - ATF_TP_ADD_TC(tp, getlabel); - ATF_TP_ADD_TC(tp, getlabelsequence); +int +main(void) { + 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), #ifdef DNS_BENCHMARK_TESTS - ATF_TP_ADD_TC(tp, benchmark); + cmocka_unit_test_setup_teardown(benchmark_test, + _setup, _teardown), #endif /* DNS_BENCHMARK_TESTS */ + }; - return (atf_no_error()); + return (cmocka_run_group_tests(tests, NULL, NULL)); } + +#else /* HAVE_CMOCKA */ + +#include + +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (0); +} + +#endif