• 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 #include "hctest.h"
17 #include "iot_watchdog.h"
18 #include "hks_api.h"
19 #include "hks_param.h"
20 #include "securec.h"
21 #include "cmsis_os2.h"
22 #include "ohos_types.h"
23 
24 #define TEST_TASK_STACK_SIZE      0x2000
25 #define WAIT_TO_TEST_DONE         4
26 
27 static osPriority_t g_setPriority;
28 
29 /*
30  * @tc.register: register a test suit named "CalcMultiTest"
31  * @param: test subsystem name
32  * @param: c_example module name
33  * @param: CalcMultiTest test suit name
34  */
35 LITE_TEST_SUIT(security, securityData, HksAesTest);
36 
ExecHksInitialize(void const * argument)37 static void ExecHksInitialize(void const *argument)
38 {
39     LiteTestPrint("HksInitialize Begin!\n");
40     TEST_ASSERT_TRUE(HksInitialize() == 0);
41     LiteTestPrint("HksInitialize End!\n");
42     osThreadExit();
43 }
44 /**
45  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
46  * @return: true——setup success
47  */
HksAesTestSetUp()48 static BOOL HksAesTestSetUp()
49 {
50     LiteTestPrint("setup\n");
51     IoTWatchDogDisable();
52     osThreadId_t id;
53     osThreadAttr_t attr;
54     g_setPriority = osPriorityAboveNormal6;
55     attr.name = "test";
56     attr.attr_bits = 0U;
57     attr.cb_mem = NULL;
58     attr.cb_size = 0U;
59     attr.stack_mem = NULL;
60     attr.stack_size = TEST_TASK_STACK_SIZE;
61     attr.priority = g_setPriority;
62     id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
63     sleep(WAIT_TO_TEST_DONE);
64     LiteTestPrint("HksAgreementTestSetUp End2!\n");
65     return TRUE;
66 }
67 
68 /**
69  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
70  * @return: true——teardown success
71  */
HksAesTestTearDown()72 static BOOL HksAesTestTearDown()
73 {
74     LiteTestPrint("tearDown\n");
75     IoTWatchDogEnable();
76     return TRUE;
77 }
78 
79 #define TEST_TASK_STACK_SIZE      0x2000
80 #define WAIT_TO_TEST_DONE         4
81 
82 static osPriority_t g_setPriority;
83 
ExecHksAesTest001(void const * argument)84 static void ExecHksAesTest001(void const *argument)
85 {
86     LiteTestPrint("HksAesTest001 Begin!\n");
87     TEST_ASSERT_TRUE(TestAes256ByAgree() == 0);
88     LiteTestPrint("HksAesTest001 End!\n");
89     osThreadExit();
90 }
91 
ExecHksAesTest002(void const * argument)92 static void ExecHksAesTest002(void const *argument)
93 {
94     LiteTestPrint("HksAesTest002 Begin!\n");
95     TEST_ASSERT_TRUE(TestAes256ByAgree1() == 0);
96     LiteTestPrint("HksAesTest002 End!\n");
97     osThreadExit();
98 }
99 
ExecHksAesTest003(void const * argument)100 static void ExecHksAesTest003(void const *argument)
101 {
102     LiteTestPrint("HksAesTest003 Begin!\n");
103     TEST_ASSERT_TRUE(TestAes256ByAgree2() == 0);
104     LiteTestPrint("HksAesTest003 End!\n");
105     osThreadExit();
106 }
107 
ExecHksAesTest004(void const * argument)108 static void ExecHksAesTest004(void const *argument)
109 {
110     LiteTestPrint("HksAesTest004 Begin!\n");
111     TEST_ASSERT_EQUAL(TestAes256ByLocal(), 0);
112     LiteTestPrint("HksAesTest004 End!\n");
113     osThreadExit();
114 }
115 
116 #ifndef _CUT_AUTHENTICATE_
117 #ifndef _CUT_ED25519_
118 /**
119  * @tc.name: HksCipherTest.HksCipherTest001
120  * @tc.desc: The static function will return true;
121  * @tc.type: FUNC
122  */
LITE_TEST_CASE(HksAesTest,HksAesTest001,Level1)123 LITE_TEST_CASE(HksAesTest, HksAesTest001, Level1)
124 {
125     osThreadId_t id;
126     osThreadAttr_t attr;
127     g_setPriority = osPriorityAboveNormal6;
128     attr.name = "test";
129     attr.attr_bits = 0U;
130     attr.cb_mem = NULL;
131     attr.cb_size = 0U;
132     attr.stack_mem = NULL;
133     attr.stack_size = TEST_TASK_STACK_SIZE;
134     attr.priority = g_setPriority;
135     id = osThreadNew((osThreadFunc_t)ExecHksAesTest001, NULL, &attr);
136     sleep(WAIT_TO_TEST_DONE);
137     LiteTestPrint("HksAesTest001 End2!\n");
138 }
139 
140 /**
141  * @tc.name: HksCipherTest.HksCipherTest002
142  * @tc.desc: The static function will return true;
143  * @tc.type: FUNC
144  */
LITE_TEST_CASE(HksAesTest,HksAesTest002,Level1)145 LITE_TEST_CASE(HksAesTest, HksAesTest002, Level1)
146 {
147     osThreadId_t id;
148     osThreadAttr_t attr;
149     g_setPriority = osPriorityAboveNormal6;
150     attr.name = "test";
151     attr.attr_bits = 0U;
152     attr.cb_mem = NULL;
153     attr.cb_size = 0U;
154     attr.stack_mem = NULL;
155     attr.stack_size = TEST_TASK_STACK_SIZE;
156     attr.priority = g_setPriority;
157     id = osThreadNew((osThreadFunc_t)ExecHksAesTest002, NULL, &attr);
158     sleep(WAIT_TO_TEST_DONE);
159     LiteTestPrint("HksAesTest002 End2!\n");
160 }
161 
162 /**
163  * @tc.name: HksCipherTest.HksCipherTest003
164  * @tc.desc: The static function will return true;
165  * @tc.type: FUNC
166  */
LITE_TEST_CASE(HksAesTest,HksAesTest003,Level1)167 LITE_TEST_CASE(HksAesTest, HksAesTest003, Level1)
168 {
169     osThreadId_t id;
170     osThreadAttr_t attr;
171     g_setPriority = osPriorityAboveNormal6;
172     attr.name = "test";
173     attr.attr_bits = 0U;
174     attr.cb_mem = NULL;
175     attr.cb_size = 0U;
176     attr.stack_mem = NULL;
177     attr.stack_size = TEST_TASK_STACK_SIZE;
178     attr.priority = g_setPriority;
179     id = osThreadNew((osThreadFunc_t)ExecHksAesTest003, NULL, &attr);
180     sleep(WAIT_TO_TEST_DONE);
181     LiteTestPrint("HksAesTest003 End2!\n");
182 
183 }
184 #endif
185 #endif /* _CUT_AUTHENTICATE_ */
186 
187 /**
188  * @tc.name: HksCipherTest.HksCipherTest004
189  * @tc.desc: The static function will return true;
190  * @tc.type: FUNC
191  */
LITE_TEST_CASE(HksAesTest,HksAesTest004,Level1)192 LITE_TEST_CASE(HksAesTest, HksAesTest004, Level1)
193 {
194     osThreadId_t id;
195     osThreadAttr_t attr;
196     g_setPriority = osPriorityAboveNormal6;
197     attr.name = "test";
198     attr.attr_bits = 0U;
199     attr.cb_mem = NULL;
200     attr.cb_size = 0U;
201     attr.stack_mem = NULL;
202     attr.stack_size = TEST_TASK_STACK_SIZE;
203     attr.priority = g_setPriority;
204     id = osThreadNew((osThreadFunc_t)ExecHksAesTest004, NULL, &attr);
205     sleep(WAIT_TO_TEST_DONE);
206     LiteTestPrint("HksAesTest004 End2!\n");
207 }
208 
209 RUN_TEST_SUITE(HksAesTest);
210