tests: cmac_mode: convert to ztest

- replaced test points with ztest APIs wherever possible
- split the main file into two files:
    - main.c has ztest entry and runs separate functions for ztest
    - cmac_mode.c has the original routines

JIRA: ZEP-2449

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
This commit is contained in:
Niranjhana N
2017-08-02 13:23:25 +05:30
committed by Anas Nashif
parent 98f69e1de5
commit c47d5fcee1
4 changed files with 40 additions and 26 deletions

View File

@@ -1,3 +1,4 @@
CONFIG_TINYCRYPT=y
CONFIG_TINYCRYPT_AES=y
CONFIG_TINYCRYPT_AES_CMAC=y
CONFIG_ZTEST=y

View File

@@ -1,3 +1,4 @@
include ${ZEPHYR_BASE}/tests/Makefile.test
ccflags-y += -I$(ZEPHYR_BASE)/tests/include
obj-y = test_cmac_mode.o
obj-y = main.o cmac_mode.o

View File

@@ -48,6 +48,7 @@
#include <stdio.h>
#include <string.h>
#include <ztest.h>
#define BUF_LEN 16
@@ -250,7 +251,7 @@ static u32_t verify_cmac_512_bit_msg(TCCmacState_t s)
* Main task to test CMAC
*/
void main(void)
void test_cmac_mode(void)
{
u32_t result = TC_PASS;
@@ -268,38 +269,33 @@ void main(void)
(void) tc_cmac_setup(&state, key, &sched);
result = verify_gf_2_128_double(K1, K2, state);
if (result == TC_FAIL) { /* terminate test */
TC_ERROR("CMAC test #1 (128 double) failed.\n");
goto exitTest;
}
/**TESTPOINT: Check result - test 1*/
zassert_false(result, "CMAC test #1 (128 double) failed");
(void) tc_cmac_setup(&state, key, &sched);
result = verify_cmac_null_msg(&state);
if (result == TC_FAIL) { /* terminate test */
TC_ERROR("CMAC test #2 (null msg) failed.\n");
goto exitTest;
}
/**TESTPOINT: Check result - test 2*/
zassert_false(result, "CMAC test #2 (null msg) failed");
(void) tc_cmac_setup(&state, key, &sched);
result = verify_cmac_1_block_msg(&state);
if (result == TC_FAIL) { /* terminate test */
TC_ERROR("CMAC test #3 (1 block msg)failed.\n");
goto exitTest;
}
/**TESTPOINT: Check result - test 3*/
zassert_false(result, "CMAC test #1 (1 block msg) failed");
(void) tc_cmac_setup(&state, key, &sched);
result = verify_cmac_320_bit_msg(&state);
if (result == TC_FAIL) { /* terminate test */
TC_ERROR("CMAC test #4 (320 bit msg) failed.\n");
goto exitTest;
}
/**TESTPOINT: Check result - test 4*/
zassert_false(result, "CMAC test #1 (320 bit msg) failed");
(void) tc_cmac_setup(&state, key, &sched);
result = verify_cmac_512_bit_msg(&state);
if (result == TC_FAIL) { /* terminate test */
TC_ERROR("CMAC test #5 (512 bit msg)failed.\n");
goto exitTest;
}
/**TESTPOINT: Check result - test 5*/
zassert_false(result, "CMAC test #1 (512 bit msg) failed");
TC_PRINT("All CMAC tests succeeded!\n");
exitTest:
TC_END_RESULT(result);
TC_END_REPORT(result);
}

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
extern void test_cmac_mode(void);
/**test case main entry*/
void test_main(void *p1, void *p2, void *p3)
{
ztest_test_suite(test_cmac_fn,
ztest_unit_test(test_cmac_mode));
ztest_run_test_suite(test_cmac_fn);
}