From: Evan Hunt Date: Wed, 24 Oct 2018 16:22:15 +0000 (-0700) Subject: convert resconf_test; remove ATF from lib/irs/tests X-Git-Tag: v9.13.4~21^2~62 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cec8c52cbe8ace343034bf464d30c3a54642b805;p=thirdparty%2Fbind9.git convert resconf_test; remove ATF from lib/irs/tests --- diff --git a/lib/irs/tests/Kyuafile b/lib/irs/tests/Kyuafile index 4ef71369e96..466f1bff628 100644 --- a/lib/irs/tests/Kyuafile +++ b/lib/irs/tests/Kyuafile @@ -1,4 +1,4 @@ syntax(2) test_suite('bind9') -atf_test_program{name='resconf_test'} +tap_test_program{name='resconf_test'} diff --git a/lib/irs/tests/Makefile.in b/lib/irs/tests/Makefile.in index 021fee6fd20..bdf5f623311 100644 --- a/lib/irs/tests/Makefile.in +++ b/lib/irs/tests/Makefile.in @@ -27,10 +27,8 @@ ISCDEPLIBS = ../../isc/libisc.@A@ IRSLIBS = ../libirs.@A@ IRSDEPLIBS = ../libirs.@A@ -LIBS = ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @ATFLIBS@ - -CMOCKA_CFLAGS = @CMOCKA_CFLAGS@ -CMOCKA_LIBS = @CMOCKA_LIBS@ +CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@ +LIBS = ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @CMOCKA_LIBS@ OBJS = SRCS = resconf_test.c @@ -41,8 +39,8 @@ TARGETS = resconf_test@EXEEXT@ @BIND9_MAKE_RULES@ resconf_test@EXEEXT@: resconf_test.@O@ ${CFGDEPLIBS} ${DNSDEPLIBS} ${IRSDEPLIBS} ${ISCDEPLIBS} - ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ - resconf_test.@O@ ${LIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \ + ${LDFLAGS} -o $@ resconf_test.@O@ ${LIBS} unit:: sh ${top_builddir}/unit/unittest.sh diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c index 23938d2e412..3afa82d2678 100644 --- a/lib/irs/tests/resconf_test.c +++ b/lib/irs/tests/resconf_test.c @@ -11,13 +11,20 @@ #include -#include +#if HAVE_CMOCKA + +#include +#include +#include #include #include #include #include +#define UNIT_TESTING +#include + #include #include @@ -31,21 +38,19 @@ setup_test() { isc_result_t result; result = isc_mem_create(0, 0, &mctx); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); /* - * atf-run changes us to a /tmp directory, so tests + * the caller might run from another directory, but tests * that access test data files must first chdir to the proper * location. */ - ATF_REQUIRE(chdir(TESTS) != -1); + assert_return_code(chdir(TESTS), 0); } -ATF_TC(irs_resconf_load); -ATF_TC_HEAD(irs_resconf_load, tc) { - atf_tc_set_md_var(tc, "descr", "irs_resconf_load"); -} -ATF_TC_BODY(irs_resconf_load, tc) { +/* test irs_resconf_load() */ +static void +irs_resconf_load_test(void **state) { isc_result_t result; irs_resconf_t *resconf = NULL; unsigned int i; @@ -110,33 +115,58 @@ ATF_TC_BODY(irs_resconf_load, tc) { }; - UNUSED(tc); + UNUSED(state); setup_test(); for (i = 0; i < sizeof(tests)/sizeof(tests[1]); i++) { result = irs_resconf_load(mctx, tests[i].file, &resconf); - ATF_CHECK_EQ_MSG(result, tests[i].loadres, "%s", tests[i].file); - if (result == ISC_R_SUCCESS) - ATF_CHECK_MSG(resconf != NULL, "%s", tests[i].file); - else - ATF_CHECK_MSG(resconf == NULL, "%s", tests[i].file); + if (result != tests[i].loadres) { + fail_msg("# unexpected result %s loading %s", + isc_result_totext(result), tests[i].file); + } + + if (result == ISC_R_SUCCESS && resconf == NULL) { + fail_msg("# NULL on success loading %s", + tests[i].file); + } else if (result != ISC_R_SUCCESS && resconf != NULL) { + fail_msg("# non-NULL on failure loading %s", + tests[i].file); + } + if (resconf != NULL && tests[i].check != NULL) { result = (tests[i].check)(resconf); - ATF_CHECK_EQ_MSG(result, tests[i].checkres, "%s", + if (result != tests[i].checkres) { + fail_msg("# unexpected result %s loading %s", + isc_result_totext(result), tests[i].file); + } } - if (resconf != NULL) + if (resconf != NULL) { irs_resconf_destroy(&resconf); + } } isc_mem_detach(&mctx); } -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, irs_resconf_load); - return (atf_no_error()); +int +main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(irs_resconf_load_test), + }; + + 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