diff --git a/lib/isc/tests/Kyuafile b/lib/isc/tests/Kyuafile index c4c45545bd..52375be0eb 100644 --- a/lib/isc/tests/Kyuafile +++ b/lib/isc/tests/Kyuafile @@ -1,7 +1,7 @@ syntax(2) test_suite('bind9') -atf_test_program{name='aes_test'} +tap_test_program{name='aes_test'} atf_test_program{name='buffer_test'} atf_test_program{name='counter_test'} atf_test_program{name='errno_test'} diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index b91b6f9946..f23097e139 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -54,8 +54,9 @@ TARGETS = aes_test@EXEEXT@ buffer_test@EXEEXT@ \ @BIND9_MAKE_RULES@ aes_test@EXEEXT@: aes_test.@O@ ${ISCDEPLIBS} - ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ - aes_test.@O@ ${ISCLIBS} ${LIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \ + ${LDFLAGS} -o $@ aes_test.@O@ \ + ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS} buffer_test@EXEEXT@: buffer_test.@O@ isctest.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ diff --git a/lib/isc/tests/aes_test.c b/lib/isc/tests/aes_test.c index 0f6801311f..6298193083 100644 --- a/lib/isc/tests/aes_test.c +++ b/lib/isc/tests/aes_test.c @@ -9,16 +9,20 @@ * information regarding copyright ownership. */ - -/* ! \file */ - #include -#include +#if HAVE_CMOCKA + +#include +#include +#include #include #include +#define UNIT_TESTING +#include + #include #include #include @@ -55,15 +59,15 @@ tohexstr(unsigned char *d, char *out) { } size_t -fromhexstr(const char *in, unsigned char *d) -{ +fromhexstr(const char *in, unsigned char *d) { isc_buffer_t b; isc_result_t ret; isc_buffer_init(&b, d, ISC_AES256_KEYLENGTH + 1); ret = isc_hex_decodestring(in, &b); - if (ret != ISC_R_SUCCESS) - return 0; + if (ret != ISC_R_SUCCESS) { + return (0); + } return isc_buffer_usedlength(&b); } @@ -73,14 +77,9 @@ typedef struct aes_testcase { const char *result; } aes_testcase_t; - -ATF_TC(isc_aes128); -ATF_TC_HEAD(isc_aes128, tc) { - atf_tc_set_md_var(tc, "descr", "AES 128 test vectors"); -} -ATF_TC_BODY(isc_aes128, tc) { - UNUSED(tc); - +/* AES 128 test vectors */ +static void +isc_aes128_test(void **state) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt128 #3) */ { @@ -123,26 +122,24 @@ ATF_TC_BODY(isc_aes128, tc) { aes_testcase_t *testcase = testcases; + UNUSED(state); + while (testcase->key != NULL) { len = fromhexstr(testcase->key, key); - ATF_CHECK_EQ(len, ISC_AES128_KEYLENGTH); + assert_int_equal(len, ISC_AES128_KEYLENGTH); len = fromhexstr(testcase->input, plaintext); - ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH); + assert_int_equal(len, ISC_AES_BLOCK_LENGTH); isc_aes128_crypt(key, plaintext, ciphertext); - ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS); - ATF_CHECK_STREQ(str, testcase->result); + assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS); + assert_string_equal(str, testcase->result); testcase++; } } -ATF_TC(isc_aes192); -ATF_TC_HEAD(isc_aes192, tc) { - atf_tc_set_md_var(tc, "descr", "AES 192 test vectors"); -} -ATF_TC_BODY(isc_aes192, tc) { - UNUSED(tc); - +/* AES 192 test vectors */ +static void +isc_aes192_test(void **state) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt192 #3) */ { @@ -185,26 +182,24 @@ ATF_TC_BODY(isc_aes192, tc) { aes_testcase_t *testcase = testcases; + UNUSED(state); + while (testcase->key != NULL) { len = fromhexstr(testcase->key, key); - ATF_CHECK_EQ(len, ISC_AES192_KEYLENGTH); + assert_int_equal(len, ISC_AES192_KEYLENGTH); len = fromhexstr(testcase->input, plaintext); - ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH); + assert_int_equal(len, ISC_AES_BLOCK_LENGTH); isc_aes192_crypt(key, plaintext, ciphertext); - ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS); - ATF_CHECK_STREQ(str, testcase->result); + assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS); + assert_string_equal(str, testcase->result); testcase++; } } -ATF_TC(isc_aes256); -ATF_TC_HEAD(isc_aes256, tc) { - atf_tc_set_md_var(tc, "descr", "AES 256 test vectors"); -} -ATF_TC_BODY(isc_aes256, tc) { - UNUSED(tc); - +/* AES 256 test vectors */ +static void +isc_aes256_test(void **state) { aes_testcase_t testcases[] = { /* Test 1 (KAT ECBVarTxt256 #3) */ { @@ -253,26 +248,40 @@ ATF_TC_BODY(isc_aes256, tc) { aes_testcase_t *testcase = testcases; + UNUSED(state); + while (testcase->key != NULL) { len = fromhexstr(testcase->key, key); - ATF_CHECK_EQ(len, ISC_AES256_KEYLENGTH); + assert_int_equal(len, ISC_AES256_KEYLENGTH); len = fromhexstr(testcase->input, plaintext); - ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH); + assert_int_equal(len, ISC_AES_BLOCK_LENGTH); isc_aes256_crypt(key, plaintext, ciphertext); - ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS); - ATF_CHECK_STREQ(str, testcase->result); + assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS); + assert_string_equal(str, testcase->result); testcase++; } } -/* - * Main - */ -ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, isc_aes128); - ATF_TP_ADD_TC(tp, isc_aes192); - ATF_TP_ADD_TC(tp, isc_aes256); - return (atf_no_error()); +int +main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(isc_aes128_test), + cmocka_unit_test(isc_aes192_test), + cmocka_unit_test(isc_aes256_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