Skip to content

Commit 66da4c2

Browse files
enjiamainashif
authored andcommitted
tests: crypto: move the tinycrypt test to new ztest API
Migrate the testsuite tests/crypto/tinycrypt to the new ztest API. Signed-off-by: Enjia Mai <enjia.mai@intel.com>
1 parent 64f096d commit 66da4c2

File tree

11 files changed

+43
-132
lines changed

11 files changed

+43
-132
lines changed

tests/crypto/tinycrypt/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ CONFIG_TINYCRYPT_ECC_DH=y
1313
CONFIG_TINYCRYPT_ECC_DSA=y
1414
CONFIG_ZTEST_STACK_SIZE=5120
1515
CONFIG_ZTEST=y
16+
CONFIG_ZTEST_NEW_API=y

tests/crypto/tinycrypt/src/aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ uint32_t var_text_test(uint32_t r, const uint8_t *in, const uint8_t *out,
167167
/*
168168
* All NIST tests with fixed key and variable text.
169169
*/
170-
void test_aes_fixed_key_variable_text(void)
170+
ZTEST(tinycrypt, test_aes_fixed_key_variable_text)
171171
{
172172
uint32_t result = TC_PASS;
173173
const uint8_t key[NUM_OF_NIST_KEYS] = {
@@ -1113,7 +1113,7 @@ uint32_t var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
11131113
/*
11141114
* All NIST tests with variable key and fixed text.
11151115
*/
1116-
void test_aes_variable_key_fixed_text(void)
1116+
ZTEST(tinycrypt, test_aes_variable_key_fixed_text)
11171117
{
11181118
uint32_t result = TC_PASS;
11191119
const struct kat_table kat_tbl[NUM_OF_FIXED_KEYS] = {

tests/crypto/tinycrypt/src/cbc_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const uint8_t ciphertext[80] = {
101101
/*
102102
* NIST SP 800-38a CBC Test for encryption and decryption.
103103
*/
104-
void test_cbc_sp_800_38a_encrypt_decrypt(void)
104+
ZTEST(tinycrypt, test_cbc_sp_800_38a_encrypt_decrypt)
105105
{
106106

107107
TC_START("Performing AES128 tests:");

tests/crypto/tinycrypt/src/ccm_mode.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ uint32_t do_test(const uint8_t *key,
120120
return result;
121121
}
122122

123-
void test_ccm_vector_1(void)
123+
ZTEST(tinycrypt, test_ccm_vector_1)
124124
{
125125
uint32_t result = TC_PASS;
126126
/* RFC 3610 test vector #1 */
@@ -158,7 +158,7 @@ void test_ccm_vector_1(void)
158158
zassert_false(result, "CCM test #1 (RFC 3610 test vector #1) failed.");
159159
}
160160

161-
void test_ccm_vector_2(void)
161+
ZTEST(tinycrypt, test_ccm_vector_2)
162162
{
163163
uint32_t result = TC_PASS;
164164
/* RFC 3610 test vector #2 */
@@ -196,7 +196,7 @@ void test_ccm_vector_2(void)
196196
zassert_false(result, "CCM test #2 failed.");
197197
}
198198

199-
void test_ccm_vector_3(void)
199+
ZTEST(tinycrypt, test_ccm_vector_3)
200200
{
201201
uint32_t result = TC_PASS;
202202
/* RFC 3610 test vector #3 */
@@ -236,7 +236,7 @@ void test_ccm_vector_3(void)
236236
zassert_false(result, "CCM test #3 failed.");
237237
}
238238

239-
void test_ccm_vector_4(void)
239+
ZTEST(tinycrypt, test_ccm_vector_4)
240240
{
241241
uint32_t result = TC_PASS;
242242
/* RFC 3610 test vector #7 */
@@ -275,7 +275,7 @@ void test_ccm_vector_4(void)
275275
zassert_false(result, "CCM test #4 failed.");
276276
}
277277

278-
void test_ccm_vector_5(void)
278+
ZTEST(tinycrypt, test_ccm_vector_5)
279279
{
280280
uint32_t result = TC_PASS;
281281
/* RFC 3610 test vector #8 */
@@ -314,7 +314,7 @@ void test_ccm_vector_5(void)
314314
zassert_false(result, "CCM test #5 failed.");
315315
}
316316

317-
void test_ccm_vector_6(void)
317+
ZTEST(tinycrypt, test_ccm_vector_6)
318318
{
319319
uint32_t result = TC_PASS;
320320
/* RFC 3610 test vector #9 */
@@ -354,7 +354,7 @@ void test_ccm_vector_6(void)
354354
zassert_false(result, "CCM test #6 failed.");
355355
}
356356

357-
void test_ccm_vector_7(void)
357+
ZTEST(tinycrypt, test_ccm_vector_7)
358358
{
359359
uint32_t result = TC_PASS;
360360
/* Test based on RFC 3610 test vector #9 but with no associated data */
@@ -415,7 +415,7 @@ void test_ccm_vector_7(void)
415415

416416
}
417417

418-
void test_ccm_vector_8(void)
418+
ZTEST(tinycrypt, test_ccm_vector_8)
419419
{
420420
uint32_t result = TC_PASS;
421421
/* Test based on RFC 3610 test vector #9 but with no payload data */

tests/crypto/tinycrypt/src/cmac_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s)
251251
* Main task to test CMAC
252252
*/
253253

254-
void test_cmac_mode(void)
254+
ZTEST(tinycrypt, test_cmac_mode)
255255
{
256256

257257
uint32_t result = TC_PASS;

tests/crypto/tinycrypt/src/ctr_prng.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int test_prng_vector(struct prng_vector *v)
343343
return rc;
344344
}
345345

346-
void test_ctr_prng_reseed(void)
346+
ZTEST(tinycrypt, test_ctr_prng_reseed)
347347
{
348348
uint8_t expectedV1[] = {0x7E, 0xE3, 0xA0, 0xCB, 0x6D, 0x5C, 0x4B, 0xC2,
349349
0x4B, 0x7E, 0x3C, 0x48, 0x88, 0xC3, 0x69, 0x70};
@@ -427,7 +427,7 @@ void test_ctr_prng_reseed(void)
427427
TC_PRINT("CTR PRNG reseed test succeeded\n");
428428
}
429429

430-
void test_ctr_prng_uninstantiate(void)
430+
ZTEST(tinycrypt, test_ctr_prng_uninstantiate)
431431
{
432432
uint8_t entropy[32] = {0}; /* value not important */
433433
TCCtrPrng_t ctx;
@@ -462,7 +462,7 @@ void test_ctr_prng_uninstantiate(void)
462462
TC_PRINT("CTR PRNG uninstantiate test succeeded\n");
463463
}
464464

465-
void test_ctr_prng_robustness(void)
465+
ZTEST(tinycrypt, test_ctr_prng_robustness)
466466
{
467467
uint8_t entropy[32] = {0}; /* value not important */
468468
uint8_t output[32];
@@ -538,7 +538,7 @@ void test_ctr_prng_robustness(void)
538538
/*
539539
* Main task to test CTR PRNG
540540
*/
541-
void test_ctr_prng_vector(void)
541+
ZTEST(tinycrypt, test_ctr_prng_vector)
542542
{
543543
int elements;
544544
int rc;

tests/crypto/tinycrypt/src/ecc_dh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ int montecarlo_ecdh(int num_tests, bool verbose)
446446
return TC_PASS;
447447
}
448448

449-
void test_ecc_dh(void)
449+
ZTEST(tinycrypt, test_ecc_dh)
450450
{
451451
unsigned int result = TC_PASS;
452452

tests/crypto/tinycrypt/src/ecc_dsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ int default_CSPRNG(uint8_t *dest, unsigned int size)
628628
return 1;
629629
}
630630

631-
void test_ecc_dsa(void)
631+
ZTEST(tinycrypt, test_ecc_dsa)
632632
{
633633
unsigned int result = TC_PASS;
634634

tests/crypto/tinycrypt/src/hmac.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <zephyr/test_utils.h>
4343
#include <zephyr/ztest.h>
4444

45-
uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
45+
static uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
4646
size_t datalen, const uint8_t *expected,
4747
size_t expectedlen)
4848
{
@@ -60,7 +60,7 @@ uint32_t do_hmac_test(TCHmacState_t h, uint32_t testnum, const uint8_t *data,
6060
/*
6161
* NIST test vectors for encryption.
6262
*/
63-
void test_hmac_1(void)
63+
ZTEST(tinycrypt, test_hmac_1)
6464
{
6565
uint32_t result = TC_PASS;
6666

@@ -94,7 +94,7 @@ void test_hmac_1(void)
9494
zassert_false(result, "HMAC test #7 failed");
9595
}
9696

97-
void test_hmac_2(void)
97+
ZTEST(tinycrypt, test_hmac_2)
9898
{
9999
uint32_t result = TC_PASS;
100100

@@ -128,7 +128,7 @@ void test_hmac_2(void)
128128
zassert_false(result, "HMAC test #7 failed");
129129
}
130130

131-
void test_hmac_3(void)
131+
ZTEST(tinycrypt, test_hmac_3)
132132
{
133133
uint32_t result = TC_PASS;
134134

@@ -168,7 +168,7 @@ void test_hmac_3(void)
168168
zassert_false(result, "HMAC test #3 failed");
169169
}
170170

171-
void test_hmac_4(void)
171+
ZTEST(tinycrypt, test_hmac_4)
172172
{
173173
uint32_t result = TC_PASS;
174174

@@ -210,7 +210,7 @@ void test_hmac_4(void)
210210
zassert_false(result, "HMAC test #4 failed");
211211
}
212212

213-
void test_hmac_5(void)
213+
ZTEST(tinycrypt, test_hmac_5)
214214
{
215215
uint32_t result = TC_PASS;
216216

@@ -244,7 +244,7 @@ void test_hmac_5(void)
244244
zassert_false(result, "HMAC test #5 failed");
245245
}
246246

247-
void test_hmac_6(void)
247+
ZTEST(tinycrypt, test_hmac_6)
248248
{
249249
uint32_t result = TC_PASS;
250250

@@ -302,7 +302,7 @@ void test_hmac_6(void)
302302
zassert_false(result, "HMAC test #6 failed");
303303
}
304304

305-
void test_hmac_7(void)
305+
ZTEST(tinycrypt, test_hmac_7)
306306
{
307307
uint32_t result = TC_PASS;
308308

tests/crypto/tinycrypt/src/main.c

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,4 @@
66

77
#include <zephyr/ztest.h>
88

9-
extern void test_ccm_vector_1(void);
10-
extern void test_ccm_vector_2(void);
11-
extern void test_ccm_vector_3(void);
12-
extern void test_ccm_vector_4(void);
13-
extern void test_ccm_vector_5(void);
14-
extern void test_ccm_vector_6(void);
15-
extern void test_ccm_vector_7(void);
16-
extern void test_ccm_vector_8(void);
17-
extern void test_ctr_sp_800_38a_encrypt_decrypt(void);
18-
extern void test_cbc_sp_800_38a_encrypt_decrypt(void);
19-
extern void test_cmac_mode(void);
20-
extern void test_ctr_prng_vector(void);
21-
extern void test_ctr_prng_reseed(void);
22-
extern void test_ctr_prng_uninstantiate(void);
23-
extern void test_ctr_prng_robustness(void);
24-
extern void test_ecc_dh(void);
25-
extern void test_ecc_dsa(void);
26-
extern void test_hmac_1(void);
27-
extern void test_hmac_2(void);
28-
extern void test_hmac_3(void);
29-
extern void test_hmac_4(void);
30-
extern void test_hmac_5(void);
31-
extern void test_hmac_6(void);
32-
extern void test_hmac_7(void);
33-
extern void test_sha256_1(void);
34-
extern void test_sha256_2(void);
35-
extern void test_sha256_3(void);
36-
extern void test_sha256_4(void);
37-
extern void test_sha256_5(void);
38-
extern void test_sha256_6(void);
39-
extern void test_sha256_7(void);
40-
extern void test_sha256_8(void);
41-
extern void test_sha256_9(void);
42-
extern void test_sha256_10(void);
43-
extern void test_sha256_11(void);
44-
extern void test_sha256_12(void);
45-
extern void test_sha256_13_and_14(void);
46-
extern void test_aes_key_chain(void);
47-
extern void test_aes_vectors(void);
48-
extern void test_aes_fixed_key_variable_text(void);
49-
extern void test_aes_variable_key_fixed_text(void);
50-
51-
52-
/**test case main entry*/
53-
void test_main(void)
54-
{
55-
ztest_test_suite(test_tinycrypt,
56-
ztest_unit_test(test_aes_key_chain),
57-
ztest_unit_test(test_aes_vectors),
58-
ztest_unit_test(test_aes_fixed_key_variable_text),
59-
ztest_unit_test(test_aes_variable_key_fixed_text),
60-
ztest_unit_test(test_sha256_1),
61-
ztest_unit_test(test_sha256_2),
62-
ztest_unit_test(test_sha256_3),
63-
ztest_unit_test(test_sha256_4),
64-
ztest_unit_test(test_sha256_5),
65-
ztest_unit_test(test_sha256_6),
66-
ztest_unit_test(test_sha256_7),
67-
ztest_unit_test(test_sha256_8),
68-
ztest_unit_test(test_sha256_9),
69-
ztest_unit_test(test_sha256_10),
70-
ztest_unit_test(test_sha256_11),
71-
ztest_unit_test(test_sha256_12),
72-
ztest_unit_test(test_sha256_13_and_14),
73-
ztest_unit_test(test_hmac_1),
74-
ztest_unit_test(test_hmac_2),
75-
ztest_unit_test(test_hmac_3),
76-
ztest_unit_test(test_hmac_4),
77-
ztest_unit_test(test_hmac_5),
78-
ztest_unit_test(test_hmac_6),
79-
ztest_unit_test(test_hmac_7),
80-
ztest_unit_test(test_ccm_vector_1),
81-
ztest_unit_test(test_ccm_vector_2),
82-
ztest_unit_test(test_ccm_vector_3),
83-
ztest_unit_test(test_ccm_vector_4),
84-
ztest_unit_test(test_ccm_vector_5),
85-
ztest_unit_test(test_ccm_vector_6),
86-
ztest_unit_test(test_ccm_vector_7),
87-
ztest_unit_test(test_ccm_vector_8),
88-
ztest_unit_test(test_ecc_dh),
89-
ztest_unit_test(test_ecc_dsa),
90-
ztest_unit_test(test_cmac_mode),
91-
ztest_unit_test(test_ctr_prng_vector),
92-
ztest_unit_test(test_ctr_prng_reseed),
93-
ztest_unit_test(test_ctr_prng_uninstantiate),
94-
ztest_unit_test(test_ctr_prng_robustness),
95-
ztest_unit_test(test_ctr_sp_800_38a_encrypt_decrypt),
96-
ztest_unit_test(test_cbc_sp_800_38a_encrypt_decrypt)
97-
);
98-
ztest_run_test_suite(test_tinycrypt);
99-
}
9+
ZTEST_SUITE(tinycrypt, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)