1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <string.h>
8 
9 #include "cc_lib.h"
10 #include "test_pal_thread.h"
11 #include "test_pal_log.h"
12 
13 #define  THREAD_STACK_SIZE              (128*1024)
14 
15 typedef struct LibInitArgs {
16     void* p_rng;
17     void* p_entropy;
18     CCRndWorkBuff_t * rndWorkBuff_ptr;
19 } LibInitArgs;
20 
21 uint32_t threadErr = 0;
22 static CCRndContext_t gRndContext_ptr;
23 
Test_LibInit(void * params)24 static void* Test_LibInit(void *params ){
25     uint32_t rc;
26     LibInitArgs* threadArgs = (LibInitArgs*)params;
27     gRndContext_ptr.rndState = threadArgs->p_rng;
28     gRndContext_ptr.entropyCtx = threadArgs->p_entropy;
29 
30     rc = CC_LibInit(&gRndContext_ptr, threadArgs->rndWorkBuff_ptr);
31     threadErr = rc;
32     return((void *)threadErr);
33 
34 }
35 
Test_Proj_CC_LibInit_Wrap(void * p_rng,void * p_entropy,CCRndWorkBuff_t * rndWorkBuff_ptr)36 int Test_Proj_CC_LibInit_Wrap(void* p_rng, void* p_entropy, CCRndWorkBuff_t * rndWorkBuff_ptr){
37     uint32_t rc = 0;
38     uint32_t priority = Test_PalGetDefaultPriority();
39     int threadRc;
40     ThreadHandle threadHandle;
41     LibInitArgs params;
42 
43     params.p_rng = p_rng;
44     params.p_entropy = p_entropy;
45     params.rndWorkBuff_ptr = rndWorkBuff_ptr;
46 
47     threadHandle = Test_PalThreadCreate(THREAD_STACK_SIZE, Test_LibInit,
48                     priority, &params, NULL, 0, true);
49 
50     if (threadHandle == NULL) {
51         TEST_PRINTF_ERROR("Test_PalThreadCreate failed\n");
52         return -1;
53     }
54 
55     /* Wait till thread is complete before main continues */
56     threadRc = Test_PalThreadJoin(threadHandle, (void *)&rc);
57     if (threadRc != 0) {
58         TEST_PRINTF_ERROR("Test_PalThreadJoin failed\n");
59         return -1;
60     }
61 
62     threadRc = Test_PalThreadDestroy(threadHandle);
63     if (threadRc != 0) {
64         TEST_PRINTF_ERROR("Test_PalThreadDestroy failed\n");
65     }
66 
67     return rc;
68 }
69