diff --git a/lib/isc/tests/Kyuafile b/lib/isc/tests/Kyuafile index 1148f76f5c..8adf7ed51c 100644 --- a/lib/isc/tests/Kyuafile +++ b/lib/isc/tests/Kyuafile @@ -20,7 +20,7 @@ atf_test_program{name='queue_test'} tap_test_program{name='radix_test'} atf_test_program{name='regex_test'} tap_test_program{name='result_test'} -atf_test_program{name='safe_test'} +tap_test_program{name='safe_test'} atf_test_program{name='sockaddr_test'} atf_test_program{name='socket_test'} atf_test_program{name='symtab_test'} diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index e3fd51825a..0fb8eb8ba7 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -145,8 +145,9 @@ result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS} - ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ - safe_test.@O@ ${ISCLIBS} ${LIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ + ${LDFLAGS} -o $@ safe_test.@O@ \ + ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ diff --git a/lib/isc/tests/safe_test.c b/lib/isc/tests/safe_test.c index ea3e61f98d..af1d377c70 100644 --- a/lib/isc/tests/safe_test.c +++ b/lib/isc/tests/safe_test.c @@ -9,42 +9,44 @@ * information regarding copyright ownership. */ - /* ! \file */ #include -#include +#if HAVE_CMOCKA + +#include +#include +#include -#include #include +#include + +#define UNIT_TESTING +#include #include #include -ATF_TC(isc_safe_memequal); -ATF_TC_HEAD(isc_safe_memequal, tc) { - atf_tc_set_md_var(tc, "descr", "safe memequal()"); -} -ATF_TC_BODY(isc_safe_memequal, tc) { - UNUSED(tc); +/* test isc_safe_memequal() */ +static void +isc_safe_memequal_test(void **state) { + UNUSED(state); - ATF_CHECK(isc_safe_memequal("test", "test", 4)); - ATF_CHECK(!isc_safe_memequal("test", "tesc", 4)); - ATF_CHECK(isc_safe_memequal("\x00\x00\x00\x00", - "\x00\x00\x00\x00", 4)); - ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x00", - "\x00\x00\x00\x01", 4)); - ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x02", - "\x00\x00\x00\x00", 4)); + assert_true(isc_safe_memequal("test", "test", 4)); + assert_true(!isc_safe_memequal("test", "tesc", 4)); + assert_true(isc_safe_memequal("\x00\x00\x00\x00", + "\x00\x00\x00\x00", 4)); + assert_true(!isc_safe_memequal("\x00\x00\x00\x00", + "\x00\x00\x00\x01", 4)); + assert_true(!isc_safe_memequal("\x00\x00\x00\x02", + "\x00\x00\x00\x00", 4)); } -ATF_TC(isc_safe_memwipe); -ATF_TC_HEAD(isc_safe_memwipe, tc) { - atf_tc_set_md_var(tc, "descr", "isc_safe_memwipe()"); -} -ATF_TC_BODY(isc_safe_memwipe, tc) { - UNUSED(tc); +/* test isc_safe_memwipe() */ +static void +isc_safe_memwipe_test(void **state) { + UNUSED(state); /* These should pass. */ isc_safe_memwipe(NULL, 0); @@ -61,7 +63,7 @@ ATF_TC_BODY(isc_safe_memwipe, tc) { isc_safe_memwipe(buf1, sizeof(buf1)); memset(buf2, 0, sizeof(buf2)); - ATF_CHECK(memcmp(buf1, buf2, sizeof(buf1)) == 0); + assert_int_equal(memcmp(buf1, buf2, sizeof(buf1)), 0); } /* @@ -78,15 +80,28 @@ ATF_TC_BODY(isc_safe_memwipe, tc) { isc_safe_memwipe(buf1, 3); memset(buf2, 0, 3); - ATF_CHECK(memcmp(buf1, buf2, sizeof(buf1)) == 0); + assert_int_equal(memcmp(buf1, buf2, sizeof(buf1)), 0); } } -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, isc_safe_memequal); - ATF_TP_ADD_TC(tp, isc_safe_memwipe); - return (atf_no_error()); +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)); } + +#else /* HAVE_CMOCKA */ + +#include + +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (0); +} + +#endif