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'}
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'}

View File

@ -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 $@ \

View File

@ -9,42 +9,44 @@
* information regarding copyright ownership.
*/
/* ! \file */
#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 <stdlib.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/safe.h>
#include <isc/util.h>
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",
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));
ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x00",
assert_true(!isc_safe_memequal("\x00\x00\x00\x00",
"\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));
}
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 <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif