1 /*
2  * Copyright (c) 2001-2021, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /* system includes */
8 #include <stdlib.h>
9 
10 
11 /* cerberus pal */
12 #include "cc_pal_types.h"
13 #include "cc_pal_types_plat.h"
14 #include "cc_pal_mem.h"
15 #include "cc_pal_perf.h"
16 #include "cc_regs.h"
17 #include "cc_otp_defs.h"
18 #include "cc_lib.h"
19 #include "cc_rnd_common.h"
20 #include "mbedtls_cc_mng.h"
21 
22 /* tests pal and hal */
23 #include "board_configs.h"
24 #include "test_pal_mem.h"
25 #include "test_pal_mem_s.h"
26 #include "test_pal_thread.h"
27 #include "test_pal_log.h"
28 #include "test_proj_otp.h"
29 
30 /* mbedtls */
31 #include "mbedtls/memory_buffer_alloc.h"
32 #include "mbedtls/entropy.h"
33 #include "mbedtls/ctr_drbg.h"
34 
35 /* internal files */
36 #include "run_integration_test.h"
37 #include "run_integration_test_api.h"
38 #include "run_integration_helper.h"
39 #include "run_integration_pal_log.h"
40 #include "run_integration_pal_otp.h"
41 #include "run_integration_pal_reg.h"
42 #include "run_integration_profiler.h"
43 #include "run_integration_flash.h"
44 #include "run_integration_otp.h"
45 
46 /************************************************************
47  *
48  * defines
49  *
50  ************************************************************/
51 #define RUNIT_FLASH_SIZE                        0x10000
52 #define RUNIT_TEST_NAME_LENGTH                  50
53 #define RUNIT_PTHREAD_STACK_MIN                 16384
54 #define RUNIT_MBEDTLS_HEAP_MIN                  1024*512
55 
56 #ifndef RUNIT_TEST_ITER_MAX
57 #define RUNIT_TEST_ITER_MAX 1
58 #endif
59 
60 /************************************************************
61  *
62  * macros
63  *
64  ************************************************************/
65 typedef struct ImpCong_t
66 {
67     uint8_t md2_process;
68     uint8_t md4_process;
69     uint8_t md5_process;
70     uint8_t ripemd160_process;
71     uint8_t sha1_process;
72     uint8_t sha256_process;
73     uint8_t sha512_process;
74     uint8_t des_setkey;
75     uint8_t des_crypt;
76     uint8_t des3_crypt;
77     uint8_t aes_setkey;
78     uint8_t aes_setkey_dec;
79     uint8_t aes_encrypt;
80     uint8_t aes_decrypt;
81     uint8_t aes;
82     uint8_t ccm;
83     uint8_t gcm;
84     uint8_t sha1;
85     uint8_t sha256;
86     uint8_t sha512;
87     uint8_t rsa;
88     uint8_t dhm;
89     uint8_t ecc;
90     uint8_t ecp;
91     uint8_t entropy_hardware;
92     uint8_t pk_rsa_alt;
93     uint8_t cmac;
94     uint8_t mbedtls_ecdh_gen_public_alt;
95     uint8_t mbedtls_ecdh_compute_shared_alt;
96     uint8_t mbedtls_ecdsa_verify_alt;
97     uint8_t mbedtls_ecdsa_sign_alt;
98     uint8_t mbedtls_ecdsa_genkey_alt;
99 } ImpCong_t;
100 
101 /************************************************************
102  *
103  * static function prototypes
104  *
105  ************************************************************/
106 static void runIt_finish(void);
107 static RunItError_t runIt_init(void);
108 static void* runIt_executer(void *params);
109 
110 /************************************************************
111  *
112  * variables
113  *
114  ************************************************************/
115 /* pass result between executer and main thread */
116 RunItError_t g_runIt_executerRc = RUNIT_ERROR__FAIL;
117 
118 /* ptr to the heap managed by the mbedtls library. to be freed at a later point */
119 uint8_t* gRunIt_mbedtlsHeap_ptr = NULL;
120 
121 /* RndContext and RndState to be used by the tests */
122 CCRndContext_t* gpRndContext = NULL;
123 mbedtls_ctr_drbg_context* gpRndState = NULL;
124 
125 /* RunItPtr to be freed at a later point */
126 RunItPtr gRunIt_rndContext_ptr;
127 RunItPtr gRunIt_rndWorkBuff_ptr;
128 RunItPtr gRunIt_rndState_ptr;
129 RunItPtr gRunIt_entropy_ptr;
130 
131 /* for debugging */
132 uint32_t gRunItStackSize = 0;
133 uint8_t gRunItPrintEnable = 1;
134 ImpCong_t gCompConf = { 0 };
135 /************************************************************
136  *
137  * static functions
138  *
139  ************************************************************/
runIt_finish(void)140 static void runIt_finish(void)
141 {
142     runIt_perfFin();
143 
144     CC_LibFini((CCRndContext_t *)GET_PTR(gRunIt_rndContext_ptr));
145 
146     FREE_IF_NOT_NULL(gRunIt_rndContext_ptr);
147     FREE_IF_NOT_NULL(gRunIt_rndWorkBuff_ptr);
148     FREE_IF_NOT_NULL(gRunIt_rndState_ptr);
149     FREE_IF_NOT_NULL(gRunIt_entropy_ptr);
150 
151     RUNIT_TEST_PAL_FREE(gRunIt_mbedtlsHeap_ptr);
152 }
153 
runIt_init(void)154 static RunItError_t runIt_init(void)
155 {
156     RunItError_t rc = RUNIT_ERROR__OK;
157 
158     uint32_t* mbedtlsHeapAligned = NULL;
159 
160     RunItPtr rndContext;
161     RunItPtr rndWorkBuff;
162     RunItPtr rndState;
163     RunItPtr mbedtlsEntropy;
164 
165     CCRndContext_t* pRndContex = NULL;
166     CCRndWorkBuff_t* pRndWorkBuff = NULL;
167     mbedtls_ctr_drbg_context* pRndState = NULL;
168     mbedtls_entropy_context* pMbedtlsEntropy = NULL;
169 
170     /* initilaise mbedtls heap manager */
171     ALLOC_BUFF_ALIGN32(gRunIt_mbedtlsHeap_ptr, mbedtlsHeapAligned, RUNIT_MBEDTLS_HEAP_MIN);
172     mbedtls_memory_buffer_alloc_init((uint8_t*)mbedtlsHeapAligned, RUNIT_MBEDTLS_HEAP_MIN);
173 
174     /* use global ptr to be able to free them on exit */
175     ALLOC_STRUCT(CCRndContext_t, rndContext, pRndContex);
176     ALLOC_STRUCT(CCRndWorkBuff_t, rndWorkBuff, pRndWorkBuff);
177     ALLOC_STRUCT(mbedtls_ctr_drbg_context, rndState, pRndState);
178     ALLOC_STRUCT(mbedtls_entropy_context, mbedtlsEntropy, pMbedtlsEntropy);
179 
180     /* init Rnd context's inner member */
181     pRndContex->rndState = pRndState;
182     pRndContex->entropyCtx = pMbedtlsEntropy;
183 
184     /* save pointers staticaly to free them at a  later point */
185     gRunIt_rndContext_ptr = rndContext;
186     gRunIt_rndWorkBuff_ptr = rndWorkBuff;
187     gRunIt_rndState_ptr = rndState;
188     gRunIt_entropy_ptr = mbedtlsEntropy;
189 
190     /* set global vars */
191     gpRndContext = pRndContex;
192     gpRndState = pRndState;
193 
194 
195     /* initialise CC library */
196     RUNIT_ASSERT(CC_LibInit(pRndContex, pRndWorkBuff) == CC_LIB_RET_OK);
197 
198     return RUNIT_ERROR__OK;
199 
200 bail:
201     runIt_finish();
202 
203     return rc;
204 
205 }
206 
runIt_printMbedtlsAltConfig(void)207 static void runIt_printMbedtlsAltConfig(void)
208 {
209     static const char* SOFTWARE = "software";
210     static const char* HARDWARE = "hardware";
211     static const char* MBEDTLS_CONFIG_FORMAT = "%-40.40s %-10.10s\n";
212     static const char* DASH = "----------------------------------------------------------------------------------";
213 
214     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "define", "state");
215     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, DASH, DASH);
216 
217     (void)HARDWARE;
218     (void)SOFTWARE;
219 
220 #if defined(MBEDTLS_MD2_PROCESS_ALT)
221     gCompConf.md2_process = 1;
222     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD2_PROCESS_ALT", HARDWARE);
223 #else
224     gCompConf.md2_process = 0;
225     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD2_PROCESS_ALT", SOFTWARE);
226 #endif
227 
228 #if defined(MBEDTLS_MD4_PROCESS_ALT)
229     gCompConf.md4_process = 1;
230     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD4_PROCESS_ALT", HARDWARE);
231 #else
232     gCompConf.md4_process = 0;
233     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD4_PROCESS_ALT", SOFTWARE);
234 #endif
235 
236 #if defined(MBEDTLS_MD5_PROCESS_ALT)
237     gCompConf.md5_process = 1;
238     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD5_PROCESS_ALT", HARDWARE);
239 #else
240     gCompConf.md5_process = 0;
241     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_MD5_PROCESS_ALT", SOFTWARE);
242 #endif
243 
244 #if defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
245     gCompConf.ripemd160_process = 1;
246     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_RIPEMD160_PROCESS_ALT", HARDWARE);
247 #else
248     gCompConf.ripemd160_process = 0;
249     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_RIPEMD160_PROCESS_ALT", SOFTWARE);
250 #endif
251 
252 #if defined(MBEDTLS_SHA1_PROCESS_ALT)
253     gCompConf.sha1_process = 1;
254     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA1_PROCESS_ALT", HARDWARE);
255 #else
256     gCompConf.sha1_process = 0;
257     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA1_PROCESS_ALT", SOFTWARE);
258 #endif
259 
260 #if defined(MBEDTLS_SHA256_PROCESS_ALT)
261     gCompConf.sha256_process = 1;
262     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA256_PROCESS_ALT", HARDWARE);
263 #else
264     gCompConf.sha256_process = 0;
265     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA256_PROCESS_ALT", SOFTWARE);
266 #endif
267 
268 #if defined(MBEDTLS_SHA512_PROCESS_ALT)
269     gCompConf.sha512_process = 1;
270     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA512_PROCESS_ALT", HARDWARE);
271 #else
272     gCompConf.sha512_process = 0;
273     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA512_PROCESS_ALT", SOFTWARE);
274 #endif
275 
276 #if defined(MBEDTLS_DES_SETKEY_ALT)
277     gCompConf.des_setkey = 1;
278     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES_SETKEY_ALT", HARDWARE);
279 #else
280     gCompConf.des_setkey = 0;
281     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES_SETKEY_ALT", SOFTWARE);
282 #endif
283 
284 #if defined(MBEDTLS_DES_CRYPT_ECB_ALT)
285     gCompConf.des_crypt = 1;
286     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES_CRYPT_ECB_ALT", HARDWARE);
287 #else
288     gCompConf.des_crypt = 0;
289     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES_CRYPT_ECB_ALT", SOFTWARE);
290 #endif
291 
292 #if defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
293     gCompConf.des3_crypt = 1;
294     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES3_CRYPT_ECB_ALT", HARDWARE);
295 #else
296     gCompConf.des3_crypt = 0;
297     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DES3_CRYPT_ECB_ALT", SOFTWARE);
298 #endif
299 
300 #if defined(MBEDTLS_AES_SETKEY_ENC_ALT)
301     gCompConf.des_setkey = 1;
302     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_SETKEY_ENC_ALT", HARDWARE);
303 #else
304     gCompConf.des_setkey = 0;
305     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_SETKEY_ENC_ALT", SOFTWARE);
306 #endif
307 
308 #if defined(MBEDTLS_AES_SETKEY_DEC_ALT)
309     gCompConf.aes_setkey = 1;
310     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_SETKEY_DEC_ALT", HARDWARE);
311 #else
312     gCompConf.aes_setkey = 0;
313     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_SETKEY_DEC_ALT", SOFTWARE);
314 #endif
315 
316 
317 #if defined(MBEDTLS_AES_ENCRYPT_ALT)
318     gCompConf.aes_encrypt = 1;
319     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_ENCRYPT_ALT", HARDWARE);
320 #else
321     gCompConf.aes_encrypt = 0;
322     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_ENCRYPT_ALT", SOFTWARE);
323 #endif
324 
325 #if defined(MBEDTLS_AES_DECRYPT_ALT)
326     gCompConf.aes_decrypt = 1;
327     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_DECRYPT_ALT", HARDWARE);
328 #else
329     gCompConf.aes_decrypt = 0;
330     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_DECRYPT_ALT", SOFTWARE);
331 #endif
332 
333 #if defined(MBEDTLS_AES_ALT)
334     gCompConf.aes = 1;
335     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_ALT", HARDWARE);
336 #else
337     gCompConf.aes = 0;
338     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_AES_ALT", SOFTWARE);
339 #endif
340 
341 #if defined(MBEDTLS_CCM_ALT)
342     gCompConf.ccm = 1;
343     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_CCM_ALT", HARDWARE);
344 #else
345     gCompConf.ccm = 0;
346     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_CCM_ALT", SOFTWARE);
347 #endif
348 
349 #if defined(MBEDTLS_GCM_ALT)
350     gCompConf.gcm = 1;
351     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_GCM_ALT", HARDWARE);
352 #else
353     gCompConf.gcm = 0;
354     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_GCM_ALT", SOFTWARE);
355 #endif
356 
357 #if defined(MBEDTLS_SHA1_ALT)
358     gCompConf.sha1 = 1;
359     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA1_ALT", HARDWARE);
360 #else
361     gCompConf.sha1 = 0;
362     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA1_ALT", SOFTWARE);
363 #endif
364 
365 #if defined(MBEDTLS_SHA256_ALT)
366     gCompConf.sha256 = 1;
367     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA256_ALT", HARDWARE);
368 #else
369     gCompConf.sha256 = 0;
370     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA256_ALT", SOFTWARE);
371 #endif
372 
373 #if defined(MBEDTLS_SHA512_ALT)
374     gCompConf.sha512 = 1;
375     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA512_ALT", HARDWARE);
376 #else
377     gCompConf.sha512 = 0;
378     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_SHA512_ALT", SOFTWARE);
379 #endif
380 
381 #if defined(MBEDTLS_RSA_ALT)
382     gCompConf.rsa = 1;
383     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_RSA_ALT", HARDWARE);
384 #else
385     gCompConf.rsa = 0;
386     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_RSA_ALT", SOFTWARE);
387 #endif
388 
389 #if defined(MBEDTLS_DHM_ALT)
390     gCompConf.dhm = 1;
391     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DHM_ALT", HARDWARE);
392 #else
393     gCompConf.dhm = 0;
394     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_DHM_ALT", SOFTWARE);
395 #endif
396 
397 #if defined(MBEDTLS_ECC_ALT)
398     gCompConf.ecc = 1;
399     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECC_ALT", HARDWARE);
400 #else
401     gCompConf.ecc = 0;
402     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECC_ALT", SOFTWARE);
403 #endif
404 
405 #if defined(MBEDTLS_ECP_ALT)
406     gCompConf.ecp = 1;
407     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECP_ALT", HARDWARE);
408 #else
409     gCompConf.ecp = 0;
410     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECP_ALT", SOFTWARE);
411 #endif
412 
413 #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
414     gCompConf.entropy_hardware = 1;
415     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ENTROPY_HARDWARE_ALT", HARDWARE);
416 #else
417     gCompConf.entropy_hardware = 0;
418     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ENTROPY_HARDWARE_ALT", SOFTWARE);
419 #endif
420 
421 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
422     gCompConf.pk_rsa_alt = 1;
423     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_PK_RSA_ALT_SUPPORT", HARDWARE);
424 #else
425     gCompConf.pk_rsa_alt = 0;
426     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_PK_RSA_ALT_SUPPORT", SOFTWARE);
427 #endif
428 
429 #if defined(MBEDTLS_CMAC_ALT)
430     gCompConf.cmac = 1;
431     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_CMAC_ALT", HARDWARE);
432 #else
433     gCompConf.cmac = 0;
434     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_CMAC_ALT", SOFTWARE);
435 #endif
436 
437 #if defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT)
438     gCompConf.mbedtls_ecdh_gen_public_alt = 1;
439     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDH_GEN_PUBLIC_ALT", HARDWARE);
440 #else
441     gCompConf.mbedtls_ecdh_gen_public_alt = 0;
442     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDH_GEN_PUBLIC_ALT", SOFTWARE);
443 #endif
444 
445 #if defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT)
446     gCompConf.mbedtls_ecdh_compute_shared_alt = 1;
447     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDH_COMPUTE_SHARED_ALT", HARDWARE);
448 #else
449     gCompConf.mbedtls_ecdh_compute_shared_alt = 0;
450     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDH_COMPUTE_SHARED_ALT", SOFTWARE);
451 #endif
452 
453 #if defined(MBEDTLS_ECDSA_VERIFY_ALT)
454     gCompConf.mbedtls_ecdsa_verify_alt = 1;
455     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_VERIFY_ALT", HARDWARE);
456 #else
457     gCompConf.mbedtls_ecdsa_verify_alt = 0;
458     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_VERIFY_ALT", SOFTWARE);
459 #endif
460 
461 #if defined(MBEDTLS_ECDSA_SIGN_ALT)
462     gCompConf.mbedtls_ecdsa_sign_alt = 1;
463     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_SIGN_ALT", HARDWARE);
464 #else
465     gCompConf.mbedtls_ecdsa_sign_alt = 0;
466     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_SIGN_ALT", SOFTWARE);
467 #endif
468 
469 #if defined(MBEDTLS_ECDSA_GENKEY_ALT)
470     gCompConf.mbedtls_ecdsa_genkey_alt = 1;
471     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_GENKEY_ALT", HARDWARE);
472 #else
473     gCompConf.mbedtls_ecdsa_genkey_alt = 0;
474     RUNIT_PRINT(MBEDTLS_CONFIG_FORMAT, "MBEDTLS_ECDSA_GENKEY_ALT", SOFTWARE);
475 #endif
476 
477 }
478 
runIt_regApi(void)479 static void runIt_regApi(void)
480 {
481     RUNIT_PERF_REG_API(mbedtls_aes_crypt_cbc                              , gCompConf.aes);
482     RUNIT_PERF_REG_API(mbedtls_aes_crypt_cfb128                           , gCompConf.aes);
483     RUNIT_PERF_REG_API(mbedtls_aes_crypt_cfb8                             , gCompConf.aes);
484     RUNIT_PERF_REG_API(mbedtls_aes_crypt_ctr                              , gCompConf.aes);
485     RUNIT_PERF_REG_API_W_PARAM(mbedtls_aes_crypt_ctr, "16B"               , gCompConf.aes);
486     RUNIT_PERF_REG_API_W_PARAM(mbedtls_aes_crypt_ctr, "128B"              , gCompConf.aes);
487     RUNIT_PERF_REG_API_W_PARAM(mbedtls_aes_crypt_ctr, "1024B"             , gCompConf.aes);
488     RUNIT_PERF_REG_API_W_PARAM(mbedtls_aes_crypt_ctr, "8192B"             , gCompConf.aes);
489     RUNIT_PERF_REG_API_W_PARAM(mbedtls_aes_crypt_ctr, "65535B"            , gCompConf.aes);
490     RUNIT_PERF_REG_API(mbedtls_aes_crypt_ecb                              , gCompConf.aes);
491     RUNIT_PERF_REG_API(mbedtls_aes_crypt_ofb                              , gCompConf.aes);
492     RUNIT_PERF_REG_API(mbedtls_aes_ext_dma_init                           , gCompConf.aes);
493     RUNIT_PERF_REG_API(mbedtls_aes_ext_dma_set_key                        , gCompConf.aes);
494     RUNIT_PERF_REG_API(mbedtls_aes_ext_dma_set_iv                         , gCompConf.aes);
495     RUNIT_PERF_REG_API(mbedtls_aes_ext_dma_finish                         , gCompConf.aes);
496     RUNIT_PERF_REG_API(mbedtls_aes_free                                   , gCompConf.aes);
497     RUNIT_PERF_REG_API(mbedtls_aes_init                                   , gCompConf.aes);
498     RUNIT_PERF_REG_API(mbedtls_aes_key_wrap                               , gCompConf.aes);
499     RUNIT_PERF_REG_API(mbedtls_aes_key_unwrap                             , gCompConf.aes);
500     RUNIT_PERF_REG_API(mbedtls_aes_setkey_dec                             , gCompConf.aes);
501     RUNIT_PERF_REG_API(mbedtls_aes_setkey_enc                             , gCompConf.aes);
502     RUNIT_PERF_REG_API(mbedtls_ccm_init                                   , gCompConf.ccm);
503     RUNIT_PERF_REG_API(mbedtls_ccm_setkey                                 , gCompConf.ccm);
504     RUNIT_PERF_REG_API(mbedtls_ccm_encrypt_and_tag                        , gCompConf.ccm);
505     RUNIT_PERF_REG_API(mbedtls_ccm_auth_decrypt                           , gCompConf.ccm);
506     RUNIT_PERF_REG_API(mbedtls_ccm_free                                   , gCompConf.ccm);
507     RUNIT_PERF_REG_API(mbedtls_ccm_star_nonce_generate                    , 1);
508     RUNIT_PERF_REG_API(mbedtls_ccm_star_encrypt_and_tag                   , 1);
509     RUNIT_PERF_REG_API(mbedtls_ccm_star_auth_decrypt                      , 1);
510     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chacha, "encrypt"                  , 1);
511     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chacha, "decrypt"                  , 1);
512     RUNIT_PERF_REG_API(mbedtls_chacha_init                                , 1);
513     RUNIT_PERF_REG_API(mbedtls_chacha_finish                              , 1);
514     RUNIT_PERF_REG_API(mbedtls_chacha_free                                , 1);
515     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chacha_poly, "encrypt"             , 1);
516     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chacha_poly, "decrypt"             , 1);
517     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chacha20_crypt, "encrypt"          , 1);
518     RUNIT_PERF_REG_API(mbedtls_chacha20_init                              , 1);
519     RUNIT_PERF_REG_API(mbedtls_chacha20_free                              , 1);
520     RUNIT_PERF_REG_API(mbedtls_chacha20_setkey                            , 1);
521     RUNIT_PERF_REG_API(mbedtls_chacha20_starts                            , 1);
522     RUNIT_PERF_REG_API(mbedtls_chacha20_update                            , 1);
523     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chachapoly_auth_decrypt, "decrypt" , 1);
524     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chachapoly_encrypt_and_tag, "encrypt" , 1);
525     RUNIT_PERF_REG_API_W_PARAM(mbedtls_chachapoly_encrypt_and_tag, "decrypt" , 1);
526     RUNIT_PERF_REG_API(mbedtls_chachapoly_init                            , 1);
527     RUNIT_PERF_REG_API(mbedtls_chachapoly_free                            , 1);
528     RUNIT_PERF_REG_API(mbedtls_chachapoly_setkey                          , 1);
529     RUNIT_PERF_REG_API(mbedtls_cipher_cmac_finish                         , gCompConf.cmac);
530     RUNIT_PERF_REG_API(mbedtls_cipher_cmac_starts                         , gCompConf.cmac);
531     RUNIT_PERF_REG_API(mbedtls_cipher_cmac_update                         , gCompConf.cmac);
532     RUNIT_PERF_REG_API_W_PARAM(mbedtls_cipher_cmac_update, "16B"          , gCompConf.cmac);
533     RUNIT_PERF_REG_API_W_PARAM(mbedtls_cipher_cmac_update, "128B"         , gCompConf.cmac);
534     RUNIT_PERF_REG_API_W_PARAM(mbedtls_cipher_cmac_update, "1024B"        , gCompConf.cmac);
535     RUNIT_PERF_REG_API_W_PARAM(mbedtls_cipher_cmac_update, "8192B"        , gCompConf.cmac);
536     RUNIT_PERF_REG_API_W_PARAM(mbedtls_cipher_cmac_update, "65535B"       , gCompConf.cmac);
537     RUNIT_PERF_REG_API(mbedtls_cipher_cmac_reset                          , gCompConf.cmac);
538     RUNIT_PERF_REG_API(mbedtls_cipher_cmac                                , gCompConf.cmac);
539     RUNIT_PERF_REG_API(mbedtls_cipher_free                                , 0);
540     RUNIT_PERF_REG_API(mbedtls_cipher_info_from_type                      , 0);
541     RUNIT_PERF_REG_API(mbedtls_cipher_init                                , 0);
542     RUNIT_PERF_REG_API(mbedtls_cipher_setup                               , 0);
543     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_free                              , 1);
544     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_init                              , 1);
545     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_random                            , 1);
546     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_random_with_add                   , 1);
547     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_reseed                            , 1);
548     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_seed                              , 1);
549     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_seed_entropy_len                  , 1);
550     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_set_entropy_len                   , 1);
551     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_set_prediction_resistance         , 1);
552     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_set_reseed_interval               , 1);
553     RUNIT_PERF_REG_API(mbedtls_ctr_drbg_update                            , 1);
554     RUNIT_PERF_REG_API(mbedtls_dhm_calc_secret                            , gCompConf.dhm);
555     RUNIT_PERF_REG_API(mbedtls_dhm_free                                   , gCompConf.dhm);
556     RUNIT_PERF_REG_API(mbedtls_dhm_init                                   , gCompConf.dhm);
557     RUNIT_PERF_REG_API(mbedtls_dhm_make_params                            , gCompConf.dhm);
558     RUNIT_PERF_REG_API(mbedtls_dhm_make_public                            , gCompConf.dhm);
559     RUNIT_PERF_REG_API(mbedtls_dhm_read_params                            , gCompConf.dhm);
560     RUNIT_PERF_REG_API(mbedtls_dhm_read_public                            , gCompConf.dhm);
561     RUNIT_PERF_REG_API(mbedtls_ecdh_calc_secret                           , gCompConf.ecc);
562     RUNIT_PERF_REG_API(mbedtls_ecdh_compute_shared                        , gCompConf.ecc);
563     RUNIT_PERF_REG_API(mbedtls_ecdh_free                                  , gCompConf.ecc);
564     RUNIT_PERF_REG_API(mbedtls_ecdh_gen_public                            , gCompConf.ecc);
565     RUNIT_PERF_REG_API(mbedtls_ecdh_init                                  , gCompConf.ecc);
566     RUNIT_PERF_REG_API(mbedtls_ecdh_make_params                           , gCompConf.ecc);
567     RUNIT_PERF_REG_API(mbedtls_ecdh_make_public                           , gCompConf.ecc);
568     RUNIT_PERF_REG_API(mbedtls_ecdh_read_params                           , gCompConf.ecc);
569     RUNIT_PERF_REG_API(mbedtls_ecdh_read_public                           , gCompConf.ecc);
570     RUNIT_PERF_REG_API(mbedtls_ecdh_read_params_edwards                   , gCompConf.ecc);
571     RUNIT_PERF_REG_API(mbedtls_ecdh_make_params_edwards                   , gCompConf.ecc);
572     RUNIT_PERF_REG_API(mbedtls_ecdsa_free                                 , gCompConf.ecc);
573     RUNIT_PERF_REG_API(mbedtls_ecdsa_genkey                               , gCompConf.ecc);
574     RUNIT_PERF_REG_API(mbedtls_ecdsa_genkey_edwards                       , gCompConf.ecc);
575     RUNIT_PERF_REG_API(mbedtls_ecdsa_init                                 , gCompConf.ecc);
576     RUNIT_PERF_REG_API(mbedtls_ecdsa_read_signature                       , gCompConf.ecc);
577     RUNIT_PERF_REG_API(mbedtls_ecdsa_sign                                 , gCompConf.ecc);
578     RUNIT_PERF_REG_API(mbedtls_ecdsa_sign_det                             , gCompConf.ecc);
579     RUNIT_PERF_REG_API(mbedtls_ecdsa_sign_edwards                         , gCompConf.ecc);
580     RUNIT_PERF_REG_API(mbedtls_ecdsa_verify                               , gCompConf.ecc);
581     RUNIT_PERF_REG_API(mbedtls_ecdsa_verify_edwards                       , gCompConf.ecc);
582     RUNIT_PERF_REG_API(mbedtls_ecdsa_write_signature                      , gCompConf.ecc);
583     RUNIT_PERF_REG_API(mbedtls_ecies_kem_encrypt                          , gCompConf.ecc);
584     RUNIT_PERF_REG_API(mbedtls_ecies_kem_encrypt_full                     , gCompConf.ecc);
585     RUNIT_PERF_REG_API(mbedtls_ecies_kem_decrypt                          , gCompConf.ecc);
586     RUNIT_PERF_REG_API(mbedtls_entropy_init                               , 0);
587     RUNIT_PERF_REG_API(mbedtls_gcm_auth_decrypt                           , gCompConf.gcm);
588     RUNIT_PERF_REG_API(mbedtls_gcm_crypt_and_tag                          , gCompConf.gcm);
589     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "encrypt"       , gCompConf.gcm);
590     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "decrypt"       , gCompConf.gcm);
591     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "16B"           , gCompConf.gcm);
592     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "128B"          , gCompConf.gcm);
593     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "1024B"         , gCompConf.gcm);
594     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "8192B"         , gCompConf.gcm);
595     RUNIT_PERF_REG_API_W_PARAM(mbedtls_gcm_crypt_and_tag, "65534B"        , gCompConf.gcm);
596     RUNIT_PERF_REG_API(mbedtls_gcm_free                                   , gCompConf.gcm);
597     RUNIT_PERF_REG_API(mbedtls_gcm_init                                   , gCompConf.gcm);
598     RUNIT_PERF_REG_API(mbedtls_gcm_setkey                                 , gCompConf.gcm);
599     RUNIT_PERF_REG_API(mbedtls_hkdf                                       , 1);
600     RUNIT_PERF_REG_API(mbedtls_hkdf_key_derivation                        , 1);
601     RUNIT_PERF_REG_API(mbedtls_md                                         , 0);
602     RUNIT_PERF_REG_API(mbedtls_md_hmac                                    , 0);
603     RUNIT_PERF_REG_API(mbedtls_md_hmac_finish                             , 0);
604     RUNIT_PERF_REG_API(mbedtls_md_hmac_starts                             , 0);
605     RUNIT_PERF_REG_API(mbedtls_md_hmac_update                             , 0);
606     RUNIT_PERF_REG_API(mbedtls_md_info_from_string                        , 0);
607     RUNIT_PERF_REG_API(mbedtls_md_init                                    , 0);
608     RUNIT_PERF_REG_API(mbedtls_md_setup                                   , 0);
609     RUNIT_PERF_REG_API(mbedtls_poly                                       , 1);
610     RUNIT_PERF_REG_API(mbedtls_poly1305_mac                               , 1);
611     RUNIT_PERF_REG_API(mbedtls_rsa_check_privkey                          , gCompConf.rsa);
612     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_privkey, "2048"          , gCompConf.rsa);
613     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_privkey, "3072"          , gCompConf.rsa);
614     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_privkey, "4096"          , gCompConf.rsa);
615     RUNIT_PERF_REG_API(mbedtls_rsa_check_pubkey                           , gCompConf.rsa);
616     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_pubkey, "2048"           , gCompConf.rsa);
617     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_pubkey, "3072"           , gCompConf.rsa);
618     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_check_pubkey, "4096"           , gCompConf.rsa);
619     RUNIT_PERF_REG_API(mbedtls_rsa_check_pub_priv                         , gCompConf.rsa);
620     RUNIT_PERF_REG_API(mbedtls_rsa_complete                               , gCompConf.rsa);
621     RUNIT_PERF_REG_API(mbedtls_rsa_copy                                   , gCompConf.rsa);
622     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_copy, "2048"                   , gCompConf.rsa);
623     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_copy, "3072"                   , gCompConf.rsa);
624     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_copy, "4096"                   , gCompConf.rsa);
625     RUNIT_PERF_REG_API(mbedtls_rsa_free                                   , gCompConf.rsa);
626     RUNIT_PERF_REG_API(mbedtls_rsa_gen_key                                , gCompConf.rsa);
627     RUNIT_PERF_REG_API(mbedtls_rsa_init                                   , gCompConf.rsa);
628     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_decrypt, "2048"          , gCompConf.rsa);
629     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_decrypt, "3072"          , gCompConf.rsa);
630     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_decrypt, "4096"          , gCompConf.rsa);
631     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_encrypt, "2048"          , gCompConf.rsa);
632     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_encrypt, "3072"          , gCompConf.rsa);
633     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_encrypt, "4096"          , gCompConf.rsa);
634     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_sign, "2048"             , gCompConf.rsa);
635     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_sign, "3072"             , gCompConf.rsa);
636     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_sign, "4096"             , gCompConf.rsa);
637     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_verify, "2048"           , gCompConf.rsa);
638     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_verify, "3072"           , gCompConf.rsa);
639     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_pkcs1_verify, "4096"           , gCompConf.rsa);
640     RUNIT_PERF_REG_API(mbedtls_rsa_private                                , gCompConf.rsa);
641     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_private, "2048"                , gCompConf.rsa);
642     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_private, "3072"                , gCompConf.rsa);
643     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_private, "4096"                , gCompConf.rsa);
644     RUNIT_PERF_REG_API(mbedtls_rsa_public                                 , gCompConf.rsa);
645     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_public, "2048"                 , gCompConf.rsa);
646     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_public, "3072"                 , gCompConf.rsa);
647     RUNIT_PERF_REG_API_W_PARAM(mbedtls_rsa_public, "4096"                 , gCompConf.rsa);
648     RUNIT_PERF_REG_API(mbedtls_sb_cert_chain_cerification_init            , 1);
649     RUNIT_PERF_REG_API(mbedtls_sb_cert_verify_single                      , 1);
650     RUNIT_PERF_REG_API(mbedtls_sb_sw_image_store_address_change           , 1);
651     RUNIT_PERF_REG_API(mbedtls_sha1                                       , gCompConf.sha1);
652     RUNIT_PERF_REG_API(mbedtls_sha1_clone                                 , gCompConf.sha1);
653     RUNIT_PERF_REG_API(mbedtls_sha1_finish_ret                            , gCompConf.sha1);
654     RUNIT_PERF_REG_API(mbedtls_sha1_free                                  , gCompConf.sha1);
655     RUNIT_PERF_REG_API(mbedtls_sha1_init                                  , gCompConf.sha1);
656     RUNIT_PERF_REG_API(mbedtls_sha1_starts_ret                            , gCompConf.sha1);
657     RUNIT_PERF_REG_API(mbedtls_sha1_update_ret                            , gCompConf.sha1);
658     RUNIT_PERF_REG_API(mbedtls_sha256                                     , gCompConf.sha256);
659     RUNIT_PERF_REG_API(mbedtls_sha256_clone                               , gCompConf.sha256);
660     RUNIT_PERF_REG_API(mbedtls_sha256_finish                              , gCompConf.sha256);
661     RUNIT_PERF_REG_API(mbedtls_sha256_free                                , gCompConf.sha256);
662     RUNIT_PERF_REG_API(mbedtls_sha256_init                                , gCompConf.sha256);
663     RUNIT_PERF_REG_API(mbedtls_sha256_starts                              , gCompConf.sha256);
664     RUNIT_PERF_REG_API(mbedtls_sha256_update                              , gCompConf.sha256);
665     RUNIT_PERF_REG_API(mbedtls_sha512                                     , gCompConf.sha512);
666     RUNIT_PERF_REG_API(mbedtls_sha512_clone                               , gCompConf.sha512);
667     RUNIT_PERF_REG_API(mbedtls_sha512_finish                              , gCompConf.sha512);
668     RUNIT_PERF_REG_API(mbedtls_sha512_free                                , gCompConf.sha512);
669     RUNIT_PERF_REG_API(mbedtls_sha512_init                                , gCompConf.sha512);
670     RUNIT_PERF_REG_API(mbedtls_sha512_starts                              , gCompConf.sha512);
671     RUNIT_PERF_REG_API(mbedtls_sha512_update                              , gCompConf.sha512);
672     RUNIT_PERF_REG_API(mbedtls_srp_init                                   , 1);
673     RUNIT_PERF_REG_API(mbedtls_srp_pwd_ver_create                         , 1);
674     RUNIT_PERF_REG_API(mbedtls_srp_host_pub_key_create                    , 1);
675     RUNIT_PERF_REG_API(mbedtls_srp_user_proof_calc                        , 1);
676     RUNIT_PERF_REG_API(mbedtls_srp_user_pub_key_create                    , 1);
677     RUNIT_PERF_REG_API(mbedtls_srp_host_proof_verify_and_calc             , 1);
678     RUNIT_PERF_REG_API(mbedtls_srp_user_proof_verify                      , 1);
679     RUNIT_PERF_REG_API(mbedtls_util_asset_pkg_unpack                      , 1);
680     RUNIT_PERF_REG_API(mbedtls_util_key_derivation_cmac                   , 1);
681     RUNIT_PERF_REG_API(mbedtls_util_key_derivation_hmac                   , 1);
682 }
683 /**
684  * @brief               Executor function. Called from a side thread to perform the sequence of tests.
685  * @note                This is a workaround the issue that CC API requires DMA-able stack.
686  *                      When using Test_PalThreadCreate we are able to ensure that the stack is DMA-able.
687  * @param params        Not used
688  */
runIt_executer(void * params)689 static void* runIt_executer(void *params)
690 {
691     RunItError_t rc = RUNIT_ERROR__OK;
692     const char* TEST_NAME = "All Tests";
693     uint32_t testIter = 0;
694 
695     CC_UNUSED_PARAM(params);
696 
697     RUNIT_PRINT("cc312 runtime integration test\n");
698     RUNIT_PRINT("---------------------------------------------------------------\n");
699 
700     /* Initialise runtime integration perf engine */
701     runIt_perfInit();
702 
703     runIt_printMbedtlsAltConfig();
704 
705     RUNIT_PRINT_HEADER();
706 
707     gRunItPrintEnable = 1;
708 
709     runIt_regApi();
710 
711     for (testIter = 1; testIter <= RUNIT_TEST_ITER_MAX; ++testIter)
712     {
713 
714         RUNIT_TEST_START(TEST_NAME);
715 
716         /* Init libraries */
717         RUNIT_ASSERT(runIt_init() == RUNIT_ERROR__OK);
718 
719 #if !defined(RUNIT_PIE_ENABLED)
720         rc += runIt_aesTest();
721         rc += runIt_srpTest();
722         rc += runIt_shaTest();
723         rc += runIt_ccmTest();
724         rc += runIt_gcmTest();
725         rc += runIt_rsaTest();
726         rc += runIt_ecdsaTest();
727         rc += runIt_ecdhTest();
728         rc += runIt_eciesTest();
729         rc += runIt_ctrDrbgTest();
730         rc += runIt_ChachaTest();
731         rc += runIt_macTest();
732         rc += runIt_dhmTest();
733         rc += runIt_extDmaTest();
734 #endif /* RUNIT_PIE_ENABLED */
735 
736         rc += runIt_keyDerivationTest();
737         rc += runIt_assetProvTest();
738         rc += runIt_secureBootTest();
739 
740         g_runIt_executerRc = rc;
741 
742         RUNIT_TEST_RESULT(TEST_NAME);
743 
744         /* continue to next test only if all passed */
745         RUNIT_ASSERT(rc == RUNIT_ERROR__OK);
746 
747         /* disable printing of next tests */
748         gRunItPrintEnable = 0;
749 
750         /* indicate progress */
751         RUNIT_PRINT("Test %u/%u completed\n", (unsigned int)testIter, RUNIT_TEST_ITER_MAX);
752 
753         runIt_finish();
754     }
755 
756 bail:
757     runIt_perfDump();
758     CC_PAL_PERF_DUMP();
759 
760     return NULL;
761 }
762 
763 /************************************************************
764  *
765  * public functions
766  *
767  ************************************************************/
runIt_all(void)768 RunItError_t runIt_all(void)
769 {
770     RunItError_t rc = RUNIT_ERROR__OK;
771     ThreadHandle threadHandle = NULL;
772     const char* TASK_NAME = "runIt_executer";
773     uint32_t priotity = Test_PalGetDefaultPriority();
774 
775     /* init platform and map memory */
776     RUNIT_ASSERT(Test_ProjInit() == 0);
777 
778     RUNIT_PRINT("FPGA version: 0x%08"PRIx32"\n", TEST_READ_TEE_ENV_REG(DX_ENV_VERSION_REG_OFFSET));
779 
780     gRunItStackSize = RUNIT_PTHREAD_STACK_MIN;
781 
782     /* Create a task that will allocate a DMA -able stack */
783     threadHandle = Test_PalThreadCreate(RUNIT_PTHREAD_STACK_MIN,
784                                         runIt_executer,
785                                         priotity,
786                                         NULL,
787                                         (char*) TASK_NAME,
788                                         sizeof(TASK_NAME),
789                                         true);
790 
791     /* Verify task was created successfully */
792     RUNIT_ASSERT(threadHandle != NULL);
793 
794     /* Wait for task to complete */
795     Test_PalThreadJoin(threadHandle, NULL);
796 
797     /* Finalize task's resources */
798     Test_PalThreadDestroy(threadHandle);
799 
800     /* Read result code */
801     rc = g_runIt_executerRc;
802 
803 bail:
804     /* Free platform */
805     Test_ProjFree();
806 
807     return rc;
808 }
809 
810 #if defined(DX_PLAT_ZYNQ7000)
main(int argc,char ** argv)811 int main(int argc, char** argv)
812 {
813     ((void)argc);
814     ((void)argv);
815 
816     runIt_all();
817 
818     return 0;
819 }
820 #endif
821