]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
convert aes_test
authorEvan Hunt <each@isc.org>
Wed, 24 Oct 2018 07:02:43 +0000 (00:02 -0700)
committerEvan Hunt <each@isc.org>
Thu, 15 Nov 2018 04:17:04 +0000 (20:17 -0800)
lib/isc/tests/Kyuafile
lib/isc/tests/Makefile.in
lib/isc/tests/aes_test.c

index c4c45545bdf34a6770410d258c204166e940ea43..52375be0ebaf3ad50df4d43f3d71d136e5e50842 100644 (file)
@@ -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'}
index b91b6f994615b7b22e61a1bb8a7529e90622c585..f23097e1391281907014705686968bbe72ca39d1 100644 (file)
@@ -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 $@ \
index 0f6801311ff4a6aa570ca8445f3998926ee64476..629819308327e0c9f9d4b04a1a0ac14382c64721 100644 (file)
@@ -9,16 +9,20 @@
  * 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>
 
+#define UNIT_TESTING
+#include <cmocka.h>
+
 #include <isc/aes.h>
 #include <isc/buffer.h>
 #include <isc/hex.h>
@@ -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 <stdio.h>
+
+int
+main(void) {
+       printf("1..0 # Skipped: cmocka not available\n");
+       return (0);
 }
 
+#endif