Commit 0a2706b2 authored by Evan Hunt's avatar Evan Hunt Committed by Mark Andrews
Browse files

convert result tests to use CMocka instead of ATF

(cherry picked from commit 47111093)
parent 3bc66aa7
Pipeline #6433 passed with stages
in 8 minutes and 57 seconds
......@@ -25,6 +25,7 @@ atf_test_program{name='rdata_test'}
atf_test_program{name='rdataset_test'}
atf_test_program{name='rdatasetstats_test'}
atf_test_program{name='resolver_test'}
tap_test_program{name='result_test'}
atf_test_program{name='rsa_test'}
atf_test_program{name='sigs_test'}
atf_test_program{name='time_test'}
......
......@@ -229,11 +229,10 @@ resolver_test@EXEEXT@: resolver_test.@O@ dnstest.@O@ \
resolver_test.@O@ dnstest.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
result_test@EXEEXT@: result_test.@O@ \
${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
result_test.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
${LDFLAGS} -o $@ result_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
rsa_test@EXEEXT@: rsa_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
......
......@@ -9,12 +9,19 @@
* 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 <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
......@@ -22,103 +29,106 @@
#include <dns/result.h>
#include <dst/result.h>
ATF_TC(ids);
ATF_TC_HEAD(ids, tc) {
atf_tc_set_md_var(tc, "descr", "check ids array is populated");
}
ATF_TC_BODY(ids, tc) {
/*
* Check ids array is populated.
*/
static void
ids(void **state) {
const char *str;
isc_result_t result;
UNUSED(tc);
UNUSED(state);
dns_result_register();
dst_result_register();
for (result = ISC_RESULTCLASS_DNS;
result < (ISC_RESULTCLASS_DNS + DNS_R_NRESULTS);
result++) {
result++)
{
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
for (result = ISC_RESULTCLASS_DST;
result < (ISC_RESULTCLASS_DST + DST_R_NRESULTS);
result++) {
result++)
{
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
for (result = ISC_RESULTCLASS_DNSRCODE;
result < (ISC_RESULTCLASS_DNSRCODE + DNS_R_NRCODERESULTS);
result++) {
result++)
{
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, ids);
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(ids),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
return (atf_no_error());
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif
......@@ -21,7 +21,7 @@ atf_test_program{name='queue_test'}
atf_test_program{name='radix_test'}
atf_test_program{name='random_test'}
atf_test_program{name='regex_test'}
atf_test_program{name='result_test'}
tap_test_program{name='result_test'}
atf_test_program{name='safe_test'}
atf_test_program{name='sockaddr_test'}
atf_test_program{name='socket_test'}
......
......@@ -137,8 +137,9 @@ regex_test@EXEEXT@: regex_test.@O@ ${ISCDEPLIBS}
regex_test.@O@ ${ISCLIBS} ${LIBS}
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
result_test.@O@ ${ISCLIBS} ${LIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
${LDFLAGS} -o $@ result_test.@O@ \
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
......
......@@ -11,51 +11,83 @@
#include <config.h>
#include <atf-c.h>
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
#ifdef PKCS11CRYPTO
#include <pk11/result.h>
#endif
ATF_TC(tables);
ATF_TC_HEAD(tables, tc) {
atf_tc_set_md_var(tc, "descr", "check tables are populated");
/* convert result to identifier string */
static void
isc_result_toid_test(void **state) {
const char *id;
UNUSED(state);
id = isc_result_toid(ISC_R_SUCCESS);
assert_string_equal("ISC_R_SUCCESS", id);
id = isc_result_toid(ISC_R_FAILURE);
assert_string_equal("ISC_R_FAILURE", id);
}
/* convert result to description string */
static void
isc_result_totext_test(void **state) {
const char *str;
UNUSED(state);
str = isc_result_totext(ISC_R_SUCCESS);
assert_string_equal("success", str);
str = isc_result_totext(ISC_R_FAILURE);
assert_string_equal("failure", str);
}
ATF_TC_BODY(tables, tc) {
/* check tables are populated */
static void
tables(void **state) {
const char *str;
isc_result_t result;
UNUSED(state);
#ifdef PKCS11CRYPTO
pk11_result_register();
#endif
for (result = 0; result < ISC_R_NRESULTS; result++) {
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
#ifdef PKCS11CRYPTO
for (result = ISC_RESULTCLASS_PK11;
......@@ -63,65 +95,45 @@ ATF_TC_BODY(tables, tc) {
result++)
{
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
#endif
}
ATF_TC(isc_result_toid);
ATF_TC_HEAD(isc_result_toid, tc) {
atf_tc_set_md_var(tc, "descr", "convert result to identifier string");
}
ATF_TC_BODY(isc_result_toid, tc) {
const char *id;
id = isc_result_toid(ISC_R_SUCCESS);
ATF_REQUIRE_STREQ("ISC_R_SUCCESS", id);
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_result_toid_test),
cmocka_unit_test(isc_result_totext_test),
cmocka_unit_test(tables),
};
id = isc_result_toid(ISC_R_FAILURE);
ATF_REQUIRE_STREQ("ISC_R_FAILURE", id);
return (cmocka_run_group_tests(tests, NULL, NULL));
}
ATF_TC(isc_result_totext);
ATF_TC_HEAD(isc_result_totext, tc) {
atf_tc_set_md_var(tc, "descr", "convert result to description string");
}
ATF_TC_BODY(isc_result_totext, tc) {
const char *str;
#else /* HAVE_CMOCKA */
str = isc_result_totext(ISC_R_SUCCESS);
ATF_REQUIRE_STREQ("success", str);
#include <stdio.h>
str = isc_result_totext(ISC_R_FAILURE);
ATF_REQUIRE_STREQ("failure", str);
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_result_toid);
ATF_TP_ADD_TC(tp, isc_result_totext);
ATF_TP_ADD_TC(tp, tables);
return (atf_no_error());
}
#endif
syntax(2)
test_suite('bind9')
tap_test_program{name='result_test'}
......@@ -39,11 +39,10 @@ TARGETS = result_test@EXEEXT@
@BIND9_MAKE_RULES@
result_test@EXEEXT@: result_test.@O@ \
${ISCDEPLIBS} ${ISCCCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
result_test.@O@ ${ISCCCLIBS} \
${ISCLIBS} ${LIBS}
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${ISCCCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_FLAGS} \
${LDFLAGS} -o $@ result_test.@O@ \
${ISCCCLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
unit::
sh ${top_builddir}/unit/unittest.sh
......
......@@ -9,62 +9,78 @@
* 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 <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
#include <isccc/lib.h>
#include <isccc/result.h>
ATF_TC(tables);
ATF_TC_HEAD(tables, tc) {
atf_tc_set_md_var(tc, "descr", "check tables are populated");
}
ATF_TC_BODY(tables, tc) {
/*
* Check tables are populated.
*/
static void
tables(void **state) {
const char *str;
isc_result_t result;
UNUSED(tc);
UNUSED(state);
isccc_result_register();
for (result = ISC_RESULTCLASS_ISCCC;
result < (ISC_RESULTCLASS_ISCCC + ISCCC_R_NRESULTS);
result++) {
result++)
{
str = isc_result_toid(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_toid(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_toid(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE_MSG(str != NULL,
"isc_result_totext(%u) returned NULL", result);
ATF_CHECK_MSG(strcmp(str,
"(result code text not available)") != 0,
"isc_result_totext(%u) returned %s", result, str);
assert_non_null(str);
assert_string_not_equal(str,
"(result code text not available)");
}
str = isc_result_toid(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
str = isc_result_totext(result);
ATF_REQUIRE(str != NULL);
ATF_CHECK_STREQ(str, "(result code text not available)");
assert_non_null(str);
assert_string_equal(str, "(result code text not available)");
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, tables);
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(tables),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
return (atf_no_error());
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif
......@@ -4048,6 +4048,7 @@
./lib/isccc/result.c C.NOM 2001,2003,2004,2005,2007,2015,2016,2018
./lib/isccc/sexpr.c C.NOM 2001,2004,2005,2007,2014,2015,2016,2018
./lib/isccc/symtab.c C.NOM 2001,2004,2005,2007,2016,2018
./lib/isccc/tests/Kyuafile X 2018
./lib/isccc/tests/Makefile.in MAKE 2018
./lib/isccc/tests/result_test.c C 2018
./lib/isccc/version.c C 1998,1999,2000,2001,2004,2005,2007,2016,2018
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment