• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _CUT_AUTHENTICATE_
17 
18 #include "hks_others_test.h"
19 
20 #include <hctest.h>
21 #include "iot_watchdog.h"
22 #include "hks_api.h"
23 #include "hks_param.h"
24 #include "hks_type.h"
25 
26 #include "cmsis_os2.h"
27 #include "ohos_types.h"
28 
29 #define TEST_TASK_STACK_SIZE      0x2000
30 #define WAIT_TO_TEST_DONE         4
31 
32 static osPriority_t g_setPriority;
33 
34 /*
35  * @tc.register: register a test suit named "CalcMultiTest"
36  * @param: test subsystem name
37  * @param: c_example module name
38  * @param: CalcMultiTest test suit name
39  */
40 LITE_TEST_SUIT(security, securityData, HksOthersTest);
41 
ExecHksInitialize(void const * argument)42 static void ExecHksInitialize(void const *argument)
43 {
44     LiteTestPrint("HksInitialize Begin!\n");
45     TEST_ASSERT_TRUE(HksInitialize() == 0);
46     LiteTestPrint("HksInitialize End!\n");
47     osThreadExit();
48 }
49 /**
50  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
51  * @return: true——setup success
52  */
HksOthersTestSetUp()53 static BOOL HksOthersTestSetUp()
54 {
55     LiteTestPrint("setup\n");
56     IoTWatchDogDisable();
57     osThreadId_t id;
58     osThreadAttr_t attr;
59     g_setPriority = osPriorityAboveNormal6;
60     attr.name = "test";
61     attr.attr_bits = 0U;
62     attr.cb_mem = NULL;
63     attr.cb_size = 0U;
64     attr.stack_mem = NULL;
65     attr.stack_size = TEST_TASK_STACK_SIZE;
66     attr.priority = g_setPriority;
67     id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
68     sleep(WAIT_TO_TEST_DONE);
69     LiteTestPrint("HksOthersTestSetUp End2!\n");
70     return TRUE;
71 }
72 
73 /**
74  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
75  * @return: true——teardown success
76  */
HksOthersTestTearDown()77 static BOOL HksOthersTestTearDown()
78 {
79     LiteTestPrint("tearDown\n");
80     IoTWatchDogEnable();
81     return TRUE;
82 }
83 
ExcHksOthersTest001(void const * argument)84 static void ExcHksOthersTest001(void const *argument)
85 {
86     LiteTestPrint("HksOthersTest001 Begin!\n");
87     int32_t ret = HksGetKeyParamSet(NULL, NULL, NULL);
88     TEST_ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
89     LiteTestPrint("HksOthersTest001 End!\n");
90     osThreadExit();
91 }
92 
ExcHksOthersTest002(void const * argument)93 static void ExcHksOthersTest002(void const *argument)
94 {
95     LiteTestPrint("HksOthersTest002 Begin!\n");
96     int32_t ret = HksGetKeyInfoList(NULL, NULL, NULL);
97     TEST_ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
98     LiteTestPrint("HksOthersTest002 End!\n");
99     osThreadExit();
100 }
101 
ExcHksOthersTest003(void const * argument)102 static void ExcHksOthersTest003(void const *argument)
103 {
104     LiteTestPrint("HksOthersTest003 Begin!\n");
105     int32_t ret = HksAttestKey(NULL, NULL, NULL);
106     TEST_ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
107     LiteTestPrint("HksOthersTest003 End!\n");
108     osThreadExit();
109 }
110 
ExcHksOthersTest004(void const * argument)111 static void ExcHksOthersTest004(void const *argument)
112 {
113     LiteTestPrint("HksOthersTest004 Begin!\n");
114     int32_t ret = HksGetCertificateChain(NULL, NULL, NULL);
115     TEST_ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
116     LiteTestPrint("HksOthersTest004 End!\n");
117     osThreadExit();
118 }
119 
ExcHksOthersTest005(void const * argument)120 static void ExcHksOthersTest005(void const *argument)
121 {
122     LiteTestPrint("HksOthersTest005 Begin!\n");
123     int32_t ret = HksGetCertificateChain(NULL, NULL, NULL);
124     TEST_ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
125     LiteTestPrint("HksOthersTest005 End!\n");
126     osThreadExit();
127 }
128 
ExcHksOthersTest006(void const * argument)129 static void ExcHksOthersTest006(void const *argument)
130 {
131     LiteTestPrint("HksOthersTest006 Begin!\n");
132     int32_t ret = HksUnwrapKey(NULL, NULL, NULL, NULL);
133     TEST_ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
134     LiteTestPrint("HksOthersTest006 End!\n");
135     osThreadExit();
136 }
137 
ExcHksOthersTest007(void const * argument)138 static void ExcHksOthersTest007(void const *argument)
139 {
140     LiteTestPrint("HksOthersTest007 Begin!\n");
141     int32_t ret = HksGetSdkVersion(NULL);
142     TEST_ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
143     LiteTestPrint("HksOthersTest007 End!\n");
144     osThreadExit();
145 }
146 
ExcHksOthersTest008(void const * argument)147 static void ExcHksOthersTest008(void const *argument)
148 {
149     LiteTestPrint("HksOthersTest008 Begin!\n");
150     int32_t ret = HksInitialize();
151     TEST_ASSERT_TRUE(ret == HKS_SUCCESS);
152     LiteTestPrint("HksOthersTest008 End!\n");
153     osThreadExit();
154 }
155 
156 /**
157  * @tc.name: HksOthersTest.HksOthersTest001
158  * @tc.desc: The static function will return true;
159  * @tc.type: FUNC
160  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest001,Level1)161 LITE_TEST_CASE(HksOthersTest, HksOthersTest001, Level1)
162 {
163     osThreadId_t id;
164     osThreadAttr_t attr;
165     g_setPriority = osPriorityAboveNormal6;
166     attr.name = "test";
167     attr.attr_bits = 0U;
168     attr.cb_mem = NULL;
169     attr.cb_size = 0U;
170     attr.stack_mem = NULL;
171     attr.stack_size = TEST_TASK_STACK_SIZE;
172     attr.priority = g_setPriority;
173     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest001, NULL, &attr);
174     sleep(WAIT_TO_TEST_DONE);
175     LiteTestPrint("HksOthersTest001 End2!\n");
176 }
177 
178 /**
179  * @tc.name: HksOthersTest.HksOthersTest002
180  * @tc.desc: The static function will return true;
181  * @tc.type: FUNC
182  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest002,Level1)183 LITE_TEST_CASE(HksOthersTest, HksOthersTest002, Level1)
184 {
185     osThreadId_t id;
186     osThreadAttr_t attr;
187     g_setPriority = osPriorityAboveNormal6;
188     attr.name = "test";
189     attr.attr_bits = 0U;
190     attr.cb_mem = NULL;
191     attr.cb_size = 0U;
192     attr.stack_mem = NULL;
193     attr.stack_size = TEST_TASK_STACK_SIZE;
194     attr.priority = g_setPriority;
195     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest002, NULL, &attr);
196     sleep(WAIT_TO_TEST_DONE);
197     LiteTestPrint("HksOthersTest002 End2!\n");
198 }
199 
200 /**
201  * @tc.name: HksOthersTest.HksOthersTest003
202  * @tc.desc: The static function will return true;
203  * @tc.type: FUNC
204  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest003,Level1)205 LITE_TEST_CASE(HksOthersTest, HksOthersTest003, Level1)
206 {
207     osThreadId_t id;
208     osThreadAttr_t attr;
209     g_setPriority = osPriorityAboveNormal6;
210     attr.name = "test";
211     attr.attr_bits = 0U;
212     attr.cb_mem = NULL;
213     attr.cb_size = 0U;
214     attr.stack_mem = NULL;
215     attr.stack_size = TEST_TASK_STACK_SIZE;
216     attr.priority = g_setPriority;
217     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest003, NULL, &attr);
218     sleep(WAIT_TO_TEST_DONE);
219     LiteTestPrint("HksOthersTest003 End2!\n");
220 }
221 
222 /**
223  * @tc.name: HksOthersTest.HksOthersTest004
224  * @tc.desc: The static function will return true;
225  * @tc.type: FUNC
226  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest004,Level1)227 LITE_TEST_CASE(HksOthersTest, HksOthersTest004, 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)ExcHksOthersTest004, NULL, &attr);
240     sleep(WAIT_TO_TEST_DONE);
241     LiteTestPrint("HksOthersTest004 End2!\n");
242 }
243 
244 /**
245  * @tc.name: HksOthersTest.HksOthersTest005
246  * @tc.desc: The static function will return true;
247  * @tc.type: FUNC
248  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest005,Level1)249 LITE_TEST_CASE(HksOthersTest, HksOthersTest005, Level1)
250 {
251     osThreadId_t id;
252     osThreadAttr_t attr;
253     g_setPriority = osPriorityAboveNormal6;
254     attr.name = "test";
255     attr.attr_bits = 0U;
256     attr.cb_mem = NULL;
257     attr.cb_size = 0U;
258     attr.stack_mem = NULL;
259     attr.stack_size = TEST_TASK_STACK_SIZE;
260     attr.priority = g_setPriority;
261     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest005, NULL, &attr);
262     sleep(WAIT_TO_TEST_DONE);
263     LiteTestPrint("HksOthersTest005 End2!\n");
264 }
265 
266 /**
267  * @tc.name: HksOthersTest.HksOthersTest006
268  * @tc.desc: The static function will return true;
269  * @tc.type: FUNC
270  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest006,Level1)271 LITE_TEST_CASE(HksOthersTest, HksOthersTest006, Level1)
272 {
273     osThreadId_t id;
274     osThreadAttr_t attr;
275     g_setPriority = osPriorityAboveNormal6;
276     attr.name = "test";
277     attr.attr_bits = 0U;
278     attr.cb_mem = NULL;
279     attr.cb_size = 0U;
280     attr.stack_mem = NULL;
281     attr.stack_size = TEST_TASK_STACK_SIZE;
282     attr.priority = g_setPriority;
283     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest006, NULL, &attr);
284     sleep(WAIT_TO_TEST_DONE);
285     LiteTestPrint("HksOthersTest006 End2!\n");
286 }
287 
288 /**
289  * @tc.name: HksOthersTest.HksOthersTest006
290  * @tc.desc: The static function will return true;
291  * @tc.type: FUNC
292  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest007,Level1)293 LITE_TEST_CASE(HksOthersTest, HksOthersTest007, Level1)
294 {
295     osThreadId_t id;
296     osThreadAttr_t attr;
297     g_setPriority = osPriorityAboveNormal6;
298     attr.name = "test";
299     attr.attr_bits = 0U;
300     attr.cb_mem = NULL;
301     attr.cb_size = 0U;
302     attr.stack_mem = NULL;
303     attr.stack_size = TEST_TASK_STACK_SIZE;
304     attr.priority = g_setPriority;
305     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest007, NULL, &attr);
306     sleep(WAIT_TO_TEST_DONE);
307     LiteTestPrint("HksOthersTest007 End2!\n");
308 }
309 
310 /**
311  * @tc.name: HksOthersTest.HksOthersTest008
312  * @tc.desc: The static function will return true;
313  * @tc.type: FUNC
314  */
LITE_TEST_CASE(HksOthersTest,HksOthersTest008,Level1)315 LITE_TEST_CASE(HksOthersTest, HksOthersTest008, Level1)
316 {
317     osThreadId_t id;
318     osThreadAttr_t attr;
319     g_setPriority = osPriorityAboveNormal6;
320     attr.name = "test";
321     attr.attr_bits = 0U;
322     attr.cb_mem = NULL;
323     attr.cb_size = 0U;
324     attr.stack_mem = NULL;
325     attr.stack_size = TEST_TASK_STACK_SIZE;
326     attr.priority = g_setPriority;
327     id = osThreadNew((osThreadFunc_t)ExcHksOthersTest008, NULL, &attr);
328     sleep(WAIT_TO_TEST_DONE);
329     LiteTestPrint("HksOthersTest008 End2!\n");
330 }
331 RUN_TEST_SUITE(HksOthersTest);
332 
333 #endif /* _CUT_AUTHENTICATE_ */
334