1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hks_cipher_test.h"
17
18 #include "hctest.h"
19
20 #include "hks_api.h"
21 #include "hks_param.h"
22 #include "hks_test_cipher.h"
23 #include "securec.h"
24 #include "cmsis_os2.h"
25 #include "ohos_types.h"
26
27 #include <unistd.h>
28
29 #define TEST_INDEX_0 0
30 #define TEST_INDEX_1 1
31 #define TEST_INDEX_2 2
32 #define TEST_INDEX_3 3
33 #define TEST_INDEX_4 4
34 #define TEST_TASK_STACK_SIZE 0x2000
35 #define WAIT_TO_TEST_DONE 4
36
37 static osPriority_t g_setPriority;
38
39 /*
40 * @tc.register: register a test suit named "CalcMultiTest"
41 * @param: test subsystem name
42 * @param: c_example module name
43 * @param: CalcMultiTest test suit name
44 */
45 LITE_TEST_SUIT(security, securityData, HksCipherTest);
46
ExecHksInitialize(void const *argument)47 static void ExecHksInitialize(void const *argument)
48 {
49 LiteTestPrint("HksInitialize Begin!\n");
50 TEST_ASSERT_TRUE(HksInitialize() == 0);
51 LiteTestPrint("HksInitialize End!\n");
52 osThreadExit();
53 }
54
55 /**
56 * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
57 * @return: true——setup success
58 */
HksCipherTestSetUpnull59 static BOOL HksCipherTestSetUp()
60 {
61 LiteTestPrint("setup\n");
62 osThreadId_t id;
63 osThreadAttr_t attr;
64 g_setPriority = osPriorityAboveNormal6;
65 attr.name = "test";
66 attr.attr_bits = 0U;
67 attr.cb_mem = NULL;
68 attr.cb_size = 0U;
69 attr.stack_mem = NULL;
70 attr.stack_size = TEST_TASK_STACK_SIZE;
71 attr.priority = g_setPriority;
72 id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
73 sleep(WAIT_TO_TEST_DONE);
74 LiteTestPrint("HksCipherTestSetUp End2!\n");
75 return TRUE;
76 }
77
78 /**
79 * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
80 * @return: true——teardown success
81 */
HksCipherTestTearDownnull82 static BOOL HksCipherTestTearDown()
83 {
84 LiteTestPrint("tearDown\n");
85 return TRUE;
86 }
87
ExecHksCipherTest001(void const *argument)88 static void ExecHksCipherTest001(void const *argument)
89 {
90 LiteTestPrint("HksCipherTest001 Begin!\n");
91 TEST_ASSERT_TRUE(BaseTestCipher(1, TEST_INDEX_0, 1) == 0);
92 LiteTestPrint("HksCipherTest001 End!\n");
93 osThreadExit();
94 }
95
ExecHksCipherTest002(void const *argument)96 static void ExecHksCipherTest002(void const *argument)
97 {
98 LiteTestPrint("HksCipherTest002 Begin!\n");
99 TEST_ASSERT_TRUE(BaseTestCipher(1, TEST_INDEX_0, 1) == 0);
100 LiteTestPrint("HksCipherTest002 End!\n");
101 osThreadExit();
102 }
103
ExecHksCipherTest003(void const *argument)104 static void ExecHksCipherTest003(void const *argument)
105 {
106 LiteTestPrint("HksCipherTest003 Begin!\n");
107 TEST_ASSERT_TRUE(BaseTestEncrypt(1, TEST_INDEX_0, 1) == 0);
108 LiteTestPrint("HksCipherTest003 End!\n");
109 osThreadExit();
110 }
111
ExecHksCipherTest004(void const *argument)112 static void ExecHksCipherTest004(void const *argument)
113 {
114 LiteTestPrint("HksCipherTest004 Begin!\n");
115 TEST_ASSERT_TRUE(BaseTestEncrypt(1, TEST_INDEX_1, 1) == 0);
116 LiteTestPrint("HksCipherTest004 End!\n");
117 osThreadExit();
118 }
119
ExecHksCipherTest005(void const *argument)120 static void ExecHksCipherTest005(void const *argument)
121 {
122 LiteTestPrint("HksCipherTest005 Begin!\n");
123 TEST_ASSERT_TRUE(BaseTestEncrypt(1, TEST_INDEX_2, 1) == 0);
124 LiteTestPrint("HksCipherTest005 End!\n");
125 osThreadExit();
126 }
127
ExecHksCipherTest006(void const *argument)128 static void ExecHksCipherTest006(void const *argument)
129 {
130 LiteTestPrint("HksCipherTest006 Begin!\n");
131 TEST_ASSERT_TRUE(BaseTestEncrypt(1, TEST_INDEX_3, 1) == 0);
132 LiteTestPrint("HksCipherTest006 End!\n");
133 osThreadExit();
134 }
135
ExecHksCipherTest007(void const *argument)136 static void ExecHksCipherTest007(void const *argument)
137 {
138 LiteTestPrint("HksCipherTest007 Begin!\n");
139 TEST_ASSERT_TRUE(BaseTestEncrypt(1, TEST_INDEX_4, 1) == 0);
140 LiteTestPrint("HksCipherTest007 End!\n");
141 osThreadExit();
142 }
143
ExecHksCipherTest008(void const *argument)144 static void ExecHksCipherTest008(void const *argument)
145 {
146 LiteTestPrint("HksCipherTest008 Begin!\n");
147 TEST_ASSERT_TRUE(BaseTestDecrypt(1, TEST_INDEX_0, 1) == 0);
148 LiteTestPrint("HksCipherTest008 End!\n");
149 osThreadExit();
150 }
151
ExecHksCipherTest009(void const *argument)152 static void ExecHksCipherTest009(void const *argument)
153 {
154 LiteTestPrint("HksCipherTest009 Begin!\n");
155 TEST_ASSERT_TRUE(BaseTestDecrypt(1, TEST_INDEX_1, 1) == 0);
156 LiteTestPrint("HksCipherTest009 End!\n");
157 osThreadExit();
158 }
159
ExecHksCipherTest010(void const *argument)160 static void ExecHksCipherTest010(void const *argument)
161 {
162 LiteTestPrint("HksCipherTest010 Begin!\n");
163 TEST_ASSERT_TRUE(BaseTestCipher(1, TEST_INDEX_2, 1) == 0);
164 LiteTestPrint("HksCipherTest010 End!\n");
165 osThreadExit();
166 }
167
ExecHksCipherTest011(void const *argument)168 static void ExecHksCipherTest011(void const *argument)
169 {
170 LiteTestPrint("HksCipherTest011 Begin!\n");
171 TEST_ASSERT_TRUE(BaseTestDecrypt(1, TEST_INDEX_3, 1) == 0);
172 LiteTestPrint("HksCipherTest011 End!\n");
173 osThreadExit();
174 }
175
ExecHksCipherTest012(void const *argument)176 static void ExecHksCipherTest012(void const *argument)
177 {
178 LiteTestPrint("HksCipherTest012 Begin!\n");
179 TEST_ASSERT_TRUE(BaseTestDecrypt(1, TEST_INDEX_4, 1) == 0);
180 LiteTestPrint("HksCipherTest012 End!\n");
181 osThreadExit();
182 }
183
184
185 /**
186 * @tc.name: HksCipherTest.HksCipherTest001
187 * @tc.desc: The static function will return true;
188 * @tc.type: FUNC
189 */
LITE_TEST_CASEnull190 LITE_TEST_CASE(HksCipherTest, HksCipherTest001, Level1)
191 {
192 osThreadId_t id;
193 osThreadAttr_t attr;
194 g_setPriority = osPriorityAboveNormal6;
195 attr.name = "test";
196 attr.attr_bits = 0U;
197 attr.cb_mem = NULL;
198 attr.cb_size = 0U;
199 attr.stack_mem = NULL;
200 attr.stack_size = TEST_TASK_STACK_SIZE;
201 attr.priority = g_setPriority;
202 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest001, NULL, &attr);
203 sleep(WAIT_TO_TEST_DONE);
204 LiteTestPrint("HksCipherTest001 End2!\n");
205 }
206
207 #ifndef _CUT_AUTHENTICATE_
208
LITE_TEST_CASEnull209 LITE_TEST_CASE(HksCipherTest, HksCipherTest002, Level1)
210 {
211 osThreadId_t id;
212 osThreadAttr_t attr;
213 g_setPriority = osPriorityAboveNormal6;
214 attr.name = "test";
215 attr.attr_bits = 0U;
216 attr.cb_mem = NULL;
217 attr.cb_size = 0U;
218 attr.stack_mem = NULL;
219 attr.stack_size = TEST_TASK_STACK_SIZE;
220 attr.priority = g_setPriority;
221 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest002, NULL, &attr);
222 sleep(WAIT_TO_TEST_DONE);
223 LiteTestPrint("HksCipherTest002 End2!\n");
224
225 }
226
LITE_TEST_CASEnull227 LITE_TEST_CASE(HksCipherTest, HksCipherTest003, Level1)
228 {
229 osThreadId_t id;
230 osThreadAttr_t attr;
231 g_setPriority = osPriorityAboveNormal6;
232 attr.name = "test";
233 attr.attr_bits = 0U;
234 attr.cb_mem = NULL;
235 attr.cb_size = 0U;
236 attr.stack_mem = NULL;
237 attr.stack_size = TEST_TASK_STACK_SIZE;
238 attr.priority = g_setPriority;
239 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest003, NULL, &attr);
240 sleep(WAIT_TO_TEST_DONE);
241 LiteTestPrint("HksCipherTest003 End2!\n");
242 }
243
LITE_TEST_CASEnull244 LITE_TEST_CASE(HksCipherTest, HksCipherTest004, Level1)
245 {
246 osThreadId_t id;
247 osThreadAttr_t attr;
248 g_setPriority = osPriorityAboveNormal6;
249 attr.name = "test";
250 attr.attr_bits = 0U;
251 attr.cb_mem = NULL;
252 attr.cb_size = 0U;
253 attr.stack_mem = NULL;
254 attr.stack_size = TEST_TASK_STACK_SIZE;
255 attr.priority = g_setPriority;
256 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest004, NULL, &attr);
257 sleep(WAIT_TO_TEST_DONE);
258 LiteTestPrint("HksCipherTest004 End2!\n");
259 }
260
LITE_TEST_CASEnull261 LITE_TEST_CASE(HksCipherTest, HksCipherTest005, Level1)
262 {
263 osThreadId_t id;
264 osThreadAttr_t attr;
265 g_setPriority = osPriorityAboveNormal6;
266 attr.name = "test";
267 attr.attr_bits = 0U;
268 attr.cb_mem = NULL;
269 attr.cb_size = 0U;
270 attr.stack_mem = NULL;
271 attr.stack_size = TEST_TASK_STACK_SIZE;
272 attr.priority = g_setPriority;
273 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest005, NULL, &attr);
274 sleep(WAIT_TO_TEST_DONE);
275 LiteTestPrint("HksCipherTest005 End2!\n");
276 }
277
LITE_TEST_CASEnull278 LITE_TEST_CASE(HksCipherTest, HksCipherTest006, Level1)
279 {
280 osThreadId_t id;
281 osThreadAttr_t attr;
282 g_setPriority = osPriorityAboveNormal6;
283 attr.name = "test";
284 attr.attr_bits = 0U;
285 attr.cb_mem = NULL;
286 attr.cb_size = 0U;
287 attr.stack_mem = NULL;
288 attr.stack_size = TEST_TASK_STACK_SIZE;
289 attr.priority = g_setPriority;
290 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest006, NULL, &attr);
291 sleep(WAIT_TO_TEST_DONE);
292 LiteTestPrint("HksCipherTest006 End2!\n");
293 }
294
LITE_TEST_CASEnull295 LITE_TEST_CASE(HksCipherTest, HksCipherTest007, Level1)
296 {
297 osThreadId_t id;
298 osThreadAttr_t attr;
299 g_setPriority = osPriorityAboveNormal6;
300 attr.name = "test";
301 attr.attr_bits = 0U;
302 attr.cb_mem = NULL;
303 attr.cb_size = 0U;
304 attr.stack_mem = NULL;
305 attr.stack_size = TEST_TASK_STACK_SIZE;
306 attr.priority = g_setPriority;
307 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest007, NULL, &attr);
308 sleep(WAIT_TO_TEST_DONE);
309 LiteTestPrint("HksCipherTest007 End2!\n");
310 }
311
LITE_TEST_CASEnull312 LITE_TEST_CASE(HksCipherTest, HksCipherTest008, Level1)
313 {
314 osThreadId_t id;
315 osThreadAttr_t attr;
316 g_setPriority = osPriorityAboveNormal6;
317 attr.name = "test";
318 attr.attr_bits = 0U;
319 attr.cb_mem = NULL;
320 attr.cb_size = 0U;
321 attr.stack_mem = NULL;
322 attr.stack_size = TEST_TASK_STACK_SIZE;
323 attr.priority = g_setPriority;
324 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest008, NULL, &attr);
325 sleep(WAIT_TO_TEST_DONE);
326 LiteTestPrint("HksCipherTest008 End2!\n");
327 }
328
LITE_TEST_CASEnull329 LITE_TEST_CASE(HksCipherTest, HksCipherTest009, Level1)
330 {
331 osThreadId_t id;
332 osThreadAttr_t attr;
333 g_setPriority = osPriorityAboveNormal6;
334 attr.name = "test";
335 attr.attr_bits = 0U;
336 attr.cb_mem = NULL;
337 attr.cb_size = 0U;
338 attr.stack_mem = NULL;
339 attr.stack_size = TEST_TASK_STACK_SIZE;
340 attr.priority = g_setPriority;
341 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest009, NULL, &attr);
342 sleep(WAIT_TO_TEST_DONE);
343 LiteTestPrint("HksCipherTest009 End2!\n");
344 }
345
LITE_TEST_CASEnull346 LITE_TEST_CASE(HksCipherTest, HksCipherTest010, Level1)
347 {
348 osThreadId_t id;
349 osThreadAttr_t attr;
350 g_setPriority = osPriorityAboveNormal6;
351 attr.name = "test";
352 attr.attr_bits = 0U;
353 attr.cb_mem = NULL;
354 attr.cb_size = 0U;
355 attr.stack_mem = NULL;
356 attr.stack_size = TEST_TASK_STACK_SIZE;
357 attr.priority = g_setPriority;
358 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest010, NULL, &attr);
359 sleep(WAIT_TO_TEST_DONE);
360 LiteTestPrint("HksCipherTest010 End2!\n");
361 }
362
LITE_TEST_CASEnull363 LITE_TEST_CASE(HksCipherTest, HksCipherTest011, Level1)
364 {
365 osThreadId_t id;
366 osThreadAttr_t attr;
367 g_setPriority = osPriorityAboveNormal6;
368 attr.name = "test";
369 attr.attr_bits = 0U;
370 attr.cb_mem = NULL;
371 attr.cb_size = 0U;
372 attr.stack_mem = NULL;
373 attr.stack_size = TEST_TASK_STACK_SIZE;
374 attr.priority = g_setPriority;
375 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest011, NULL, &attr);
376 sleep(WAIT_TO_TEST_DONE);
377 LiteTestPrint("HksCipherTest011 End2!\n");
378 }
379
LITE_TEST_CASEnull380 LITE_TEST_CASE(HksCipherTest, HksCipherTest012, Level1)
381 {
382 osThreadId_t id;
383 osThreadAttr_t attr;
384 g_setPriority = osPriorityAboveNormal6;
385 attr.name = "test";
386 attr.attr_bits = 0U;
387 attr.cb_mem = NULL;
388 attr.cb_size = 0U;
389 attr.stack_mem = NULL;
390 attr.stack_size = TEST_TASK_STACK_SIZE;
391 attr.priority = g_setPriority;
392 id = osThreadNew((osThreadFunc_t)ExecHksCipherTest012, NULL, &attr);
393 sleep(WAIT_TO_TEST_DONE);
394 LiteTestPrint("HksCipherTest012 End2!\n");
395 }
396 #endif /* _CUT_AUTHENTICATE_ */
397
398 RUN_TEST_SUITE(HksCipherTest);
399