From 6aaaea3e61948d31eecdbeacfa9718a67b516d63 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Tue, 23 Oct 2018 22:52:30 -0700 Subject: [PATCH] convert symtab_test (cherry picked from commit 5f377136be9fb8ccea98856e1c367192d7d98afd) (cherry picked from commit 7b2288483f0777667982fd5bb037b1ed10b049fc) --- lib/isc/tests/Kyuafile | 2 +- lib/isc/tests/Makefile.in | 5 +- lib/isc/tests/symtab_test.c | 103 +++++++++++++++++++++++------------- 3 files changed, 71 insertions(+), 39 deletions(-) diff --git a/lib/isc/tests/Kyuafile b/lib/isc/tests/Kyuafile index f3df6f048d..34249ae932 100644 --- a/lib/isc/tests/Kyuafile +++ b/lib/isc/tests/Kyuafile @@ -25,7 +25,7 @@ tap_test_program{name='result_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'} +tap_test_program{name='symtab_test'} atf_test_program{name='task_test'} atf_test_program{name='taskpool_test'} atf_test_program{name='time_test'} diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 8530bdd0e0..e9772081eb 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -161,8 +161,9 @@ socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS} socket_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS} symtab_test@EXEEXT@: symtab_test.@O@ isctest.@O@ ${ISCDEPLIBS} - ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ - symtab_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ + ${LDFLAGS} -o $@ symtab_test.@O@ isctest.@O@ \ + ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} task_test@EXEEXT@: task_test.@O@ isctest.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ diff --git a/lib/isc/tests/symtab_test.c b/lib/isc/tests/symtab_test.c index a50553b20f..3503952251 100644 --- a/lib/isc/tests/symtab_test.c +++ b/lib/isc/tests/symtab_test.c @@ -9,51 +9,71 @@ * information regarding copyright ownership. */ -/*! \file */ - #include -#include +#if HAVE_CMOCKA +#include +#include +#include + +#include +#include #include +#define UNIT_TESTING +#include + #include #include +#include #include "isctest.h" +static int +_setup(void **state) { + isc_result_t result; + + UNUSED(state); + + result = isc_test_begin(NULL, true, 0); + assert_int_equal(result, ISC_R_SUCCESS); + + return (0); +} + +static int +_teardown(void **state) { + UNUSED(state); + + isc_test_end(); + + return (0); +} + static void undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) { UNUSED(arg); - ATF_REQUIRE_EQ(type, 1); + assert_int_equal(type, 1); isc_mem_free(mctx, key); isc_mem_free(mctx, value.as_pointer); } -/* - * Individual unit tests - */ - -ATF_TC(symtab_grow); -ATF_TC_HEAD(symtab_grow, tc) { - atf_tc_set_md_var(tc, "descr", "symbol table growth"); -} -ATF_TC_BODY(symtab_grow, tc) { +/* test symbol table growth */ +static void +symtab_grow(void **state) { isc_result_t result; isc_symtab_t *st = NULL; isc_symvalue_t value; isc_symexists_t policy = isc_symexists_reject; int i; - UNUSED(tc); - - result = isc_test_begin(NULL, true, 0); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + UNUSED(state); result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st); - ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); - ATF_REQUIRE(st != NULL); + assert_int_equal(result, ISC_R_SUCCESS); + assert_non_null(st); /* Nothing should be in the table yet */ @@ -66,11 +86,11 @@ ATF_TC_BODY(symtab_grow, tc) { snprintf(str, sizeof(str), "%04x", i); key = isc_mem_strdup(mctx, str); - ATF_REQUIRE(key != NULL); + assert_non_null(key); value.as_pointer = isc_mem_strdup(mctx, str); - ATF_REQUIRE(value.as_pointer != NULL); + assert_non_null(value.as_pointer); result = isc_symtab_define(st, key, 1, value, policy); - ATF_CHECK_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); if (result != ISC_R_SUCCESS) undefine(key, 1, value, NULL); } @@ -83,11 +103,11 @@ ATF_TC_BODY(symtab_grow, tc) { snprintf(str, sizeof(str), "%04x", i); key = isc_mem_strdup(mctx, str); - ATF_REQUIRE(key != NULL); + assert_non_null(key); value.as_pointer = isc_mem_strdup(mctx, str); - ATF_REQUIRE(value.as_pointer != NULL); + assert_non_null(value.as_pointer); result = isc_symtab_define(st, key, 1, value, policy); - ATF_CHECK_EQ(result, ISC_R_EXISTS); + assert_int_equal(result, ISC_R_EXISTS); undefine(key, 1, value, NULL); } @@ -99,8 +119,8 @@ ATF_TC_BODY(symtab_grow, tc) { snprintf(str, sizeof(str), "%04x", i); result = isc_symtab_lookup(st, str, 0, &value); - ATF_CHECK_EQ(result, ISC_R_SUCCESS); - ATF_CHECK_STREQ(str, (char *)value.as_pointer); + assert_int_equal(result, ISC_R_SUCCESS); + assert_string_equal(str, (char *)value.as_pointer); } /* @@ -111,7 +131,7 @@ ATF_TC_BODY(symtab_grow, tc) { snprintf(str, sizeof(str), "%04x", i); result = isc_symtab_undefine(st, str, 1); - ATF_CHECK_EQ(result, ISC_R_SUCCESS); + assert_int_equal(result, ISC_R_SUCCESS); } /* @@ -122,19 +142,30 @@ ATF_TC_BODY(symtab_grow, tc) { snprintf(str, sizeof(str), "%04x", i); result = isc_symtab_lookup(st, str, 0, &value); - ATF_CHECK_EQ(result, ISC_R_NOTFOUND); + assert_int_equal(result, ISC_R_NOTFOUND); } isc_symtab_destroy(&st); - isc_test_end(); } -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, symtab_grow); +int +main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(symtab_grow, + _setup, _teardown), + }; - return (atf_no_error()); + 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