2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

convert safe_test

This commit is contained in:
Evan Hunt 2018-10-23 22:26:42 -07:00
parent 718ca3166c
commit c1c8d8846f
3 changed files with 51 additions and 35 deletions

View File

@ -20,7 +20,7 @@ atf_test_program{name='queue_test'}
tap_test_program{name='radix_test'} tap_test_program{name='radix_test'}
atf_test_program{name='regex_test'} atf_test_program{name='regex_test'}
tap_test_program{name='result_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='sockaddr_test'}
atf_test_program{name='socket_test'} atf_test_program{name='socket_test'}
atf_test_program{name='symtab_test'} atf_test_program{name='symtab_test'}

View File

@ -145,8 +145,9 @@ result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS}
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS} safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
safe_test.@O@ ${ISCLIBS} ${LIBS} ${LDFLAGS} -o $@ safe_test.@O@ \
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS} socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \

View File

@ -9,42 +9,44 @@
* information regarding copyright ownership. * information regarding copyright ownership.
*/ */
/* ! \file */ /* ! \file */
#include <config.h> #include <config.h>
#include <atf-c.h> #if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/safe.h> #include <isc/safe.h>
#include <isc/util.h> #include <isc/util.h>
ATF_TC(isc_safe_memequal); /* test isc_safe_memequal() */
ATF_TC_HEAD(isc_safe_memequal, tc) { static void
atf_tc_set_md_var(tc, "descr", "safe memequal()"); isc_safe_memequal_test(void **state) {
} UNUSED(state);
ATF_TC_BODY(isc_safe_memequal, tc) {
UNUSED(tc);
ATF_CHECK(isc_safe_memequal("test", "test", 4)); assert_true(isc_safe_memequal("test", "test", 4));
ATF_CHECK(!isc_safe_memequal("test", "tesc", 4)); assert_true(!isc_safe_memequal("test", "tesc", 4));
ATF_CHECK(isc_safe_memequal("\x00\x00\x00\x00", assert_true(isc_safe_memequal("\x00\x00\x00\x00",
"\x00\x00\x00\x00", 4)); "\x00\x00\x00\x00", 4));
ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x00", assert_true(!isc_safe_memequal("\x00\x00\x00\x00",
"\x00\x00\x00\x01", 4)); "\x00\x00\x00\x01", 4));
ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x02", assert_true(!isc_safe_memequal("\x00\x00\x00\x02",
"\x00\x00\x00\x00", 4)); "\x00\x00\x00\x00", 4));
} }
ATF_TC(isc_safe_memwipe); /* test isc_safe_memwipe() */
ATF_TC_HEAD(isc_safe_memwipe, tc) { static void
atf_tc_set_md_var(tc, "descr", "isc_safe_memwipe()"); isc_safe_memwipe_test(void **state) {
} UNUSED(state);
ATF_TC_BODY(isc_safe_memwipe, tc) {
UNUSED(tc);
/* These should pass. */ /* These should pass. */
isc_safe_memwipe(NULL, 0); isc_safe_memwipe(NULL, 0);
@ -61,7 +63,7 @@ ATF_TC_BODY(isc_safe_memwipe, tc) {
isc_safe_memwipe(buf1, sizeof(buf1)); isc_safe_memwipe(buf1, sizeof(buf1));
memset(buf2, 0, sizeof(buf2)); 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); isc_safe_memwipe(buf1, 3);
memset(buf2, 0, 3); memset(buf2, 0, 3);
ATF_CHECK(memcmp(buf1, buf2, sizeof(buf1)) == 0); assert_int_equal(memcmp(buf1, buf2, sizeof(buf1)), 0);
} }
} }
/* int
* Main main(void) {
*/ const struct CMUnitTest tests[] = {
ATF_TP_ADD_TCS(tp) { cmocka_unit_test(isc_safe_memequal_test),
ATF_TP_ADD_TC(tp, isc_safe_memequal); cmocka_unit_test(isc_safe_memwipe_test),
ATF_TP_ADD_TC(tp, isc_safe_memwipe); };
return (atf_no_error());
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 (0);
}
#endif