From: Evan Hunt Date: Thu, 25 Oct 2018 04:09:06 +0000 (-0700) Subject: convert nsec3_test X-Git-Tag: v9.13.4~21^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=015fda0bb47f1f1137fe879b2a8cd2c505ed6d11;p=thirdparty%2Fbind9.git convert nsec3_test --- diff --git a/lib/dns/tests/Kyuafile b/lib/dns/tests/Kyuafile index 4e11b155401..5f16e4b4e12 100644 --- a/lib/dns/tests/Kyuafile +++ b/lib/dns/tests/Kyuafile @@ -14,7 +14,7 @@ atf_test_program{name='geoip_test'} atf_test_program{name='keytable_test'} atf_test_program{name='master_test'} atf_test_program{name='name_test'} -atf_test_program{name='nsec3_test'} +tap_test_program{name='nsec3_test'} tap_test_program{name='peer_test'} atf_test_program{name='private_test'} atf_test_program{name='rbt_serialize_test', is_exclusive=true} diff --git a/lib/dns/tests/Makefile.in b/lib/dns/tests/Makefile.in index 6445f8e5c63..3093d733a30 100644 --- a/lib/dns/tests/Makefile.in +++ b/lib/dns/tests/Makefile.in @@ -171,9 +171,9 @@ name_test@EXEEXT@: name_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${ISCLIBS} ${LIBS} nsec3_test@EXEEXT@: nsec3_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} - ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ - nsec3_test.@O@ dnstest.@O@ ${DNSLIBS} \ - ${ISCLIBS} ${LIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ + ${LDFLAGS} -o $@ nsec3_test.@O@ dnstest.@O@ \ + ${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} peer_test@EXEEXT@: peer_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ diff --git a/lib/dns/tests/nsec3_test.c b/lib/dns/tests/nsec3_test.c index 0916e79db9e..57576dfa2ec 100644 --- a/lib/dns/tests/nsec3_test.c +++ b/lib/dns/tests/nsec3_test.c @@ -9,23 +9,49 @@ * information regarding copyright ownership. */ - -/*! \file */ - #include -#include +#if HAVE_CMOCKA + +#include +#include +#include +#include +#include #include +#define UNIT_TESTING +#include + +#include +#include + #include #include #include "dnstest.h" -/* - * Helper functions - */ +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 iteration_test(const char *file, unsigned int expected) { @@ -34,12 +60,12 @@ iteration_test(const char *file, unsigned int expected) { unsigned int iterations; result = dns_test_loaddb(&db, dns_dbtype_zone, "test", file); - ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s", file); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_nsec3_maxiterations(db, NULL, mctx, &iterations); - ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s", file); + assert_int_equal(result, ISC_R_SUCCESS); - ATF_CHECK_EQ_MSG(iterations, expected, "%s", file); + assert_int_equal(iterations, expected); dns_db_detach(&db); } @@ -76,20 +102,16 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) { dns_rdatatype_nsec3param, buf, sizeof(buf), params->nsec3param_text); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); result = dns_rdata_tostruct(&rdata, &nsec3param, NULL); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); /* * Check typical use. */ result = dns_nsec3param_salttotext(&nsec3param, salt, sizeof(salt)); - ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, - "\"%s\": expected success, got %s\n", - params->nsec3param_text, isc_result_totext(result)); - ATF_CHECK_EQ_MSG(strcmp(salt, params->expected_salt), 0, - "\"%s\": expected salt \"%s\", got \"%s\"", - params->nsec3param_text, params->expected_salt, salt); + assert_int_equal(result, ISC_R_SUCCESS); + assert_string_equal(salt, params->expected_salt); /* * Ensure available space in the buffer is checked before the salt is @@ -97,61 +119,37 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) { * terminating NULL byte. */ length = strlen(params->expected_salt); - ATF_REQUIRE(length < sizeof(salt) - 1); /* prevent buffer overwrite */ - ATF_REQUIRE(length > 0U); /* prevent length underflow */ + assert_true(length < sizeof(salt) - 1); /* prevent buffer overwrite */ + assert_true(length > 0U); /* prevent length underflow */ result = dns_nsec3param_salttotext(&nsec3param, salt, length - 1); - ATF_CHECK_EQ_MSG(result, ISC_R_NOSPACE, - "\"%s\": expected a %lu-byte target buffer to be " - "rejected, got %s\n", - params->nsec3param_text, (unsigned long)(length - 1), - isc_result_totext(result)); + assert_int_equal(result, ISC_R_NOSPACE); + result = dns_nsec3param_salttotext(&nsec3param, salt, length); - ATF_CHECK_EQ_MSG(result, ISC_R_NOSPACE, - "\"%s\": expected a %lu-byte target buffer to be " - "rejected, got %s\n", - params->nsec3param_text, (unsigned long)length, - isc_result_totext(result)); + assert_int_equal(result, ISC_R_NOSPACE); + result = dns_nsec3param_salttotext(&nsec3param, salt, length + 1); - ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, - "\"%s\": expected a %lu-byte target buffer to be " - "accepted, got %s\n", - params->nsec3param_text, (unsigned long)(length + 1), - isc_result_totext(result)); + assert_int_equal(result, ISC_R_SUCCESS); } /* - * Individual unit tests + * check that appropriate max iterations is returned for different + * key size mixes */ - -ATF_TC(max_iterations); -ATF_TC_HEAD(max_iterations, tc) { - atf_tc_set_md_var(tc, "descr", "check that appropriate max iterations " - " is returned for different key size mixes"); -} -ATF_TC_BODY(max_iterations, tc) { - isc_result_t result; - - UNUSED(tc); - - result = dns_test_begin(NULL, false); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); +static void +max_iterations(void **state) { + UNUSED(state); iteration_test("testdata/nsec3/1024.db", 150); iteration_test("testdata/nsec3/2048.db", 500); iteration_test("testdata/nsec3/4096.db", 2500); iteration_test("testdata/nsec3/min-1024.db", 150); iteration_test("testdata/nsec3/min-2048.db", 500); - - dns_test_end(); } -ATF_TC(nsec3param_salttotext); -ATF_TC_HEAD(nsec3param_salttotext, tc) { - atf_tc_set_md_var(tc, "descr", "check dns_nsec3param_salttotext()"); -} -ATF_TC_BODY(nsec3param_salttotext, tc) { - isc_result_t result; +/* check dns_nsec3param_salttotext() */ +static void +nsec3param_salttotext(void **state) { size_t i; const nsec3param_salttotext_test_params_t tests[] = { @@ -168,25 +166,33 @@ ATF_TC_BODY(nsec3param_salttotext, tc) { { "0 0 0 -", "-" }, }; - UNUSED(tc); - - result = dns_test_begin(NULL, false); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + UNUSED(state); for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { nsec3param_salttotext_test(&tests[i]); } +} - dns_test_end(); +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)); } -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, max_iterations); - ATF_TP_ADD_TC(tp, nsec3param_salttotext); +#else /* HAVE_CMOCKA */ + +#include - return (atf_no_error()); +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (0); } +#endif