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