• 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 
18 #include "hks_api.h"
19 #include "hks_param.h"
20 #include "hks_test_aes.h"
21 #include "securec.h"
22 #include "cmsis_os2.h"
23 #include "ohos_types.h"
24 #include <unistd.h>
25 
26 #define TEST_TASK_STACK_SIZE      0x2000
27 #define WAIT_TO_TEST_DONE         4
28 
29 static osPriority_t g_setPriority;
30 
31 /*
32  * @tc.register: register a test suit named "CalcMultiTest"
33  * @param: test subsystem name
34  * @param: c_example module name
35  * @param: CalcMultiTest test suit name
36  */
37 LITE_TEST_SUIT(security, securityData, HksAesTest);
38 
ExecHksInitialize(void const * argument)39 static void ExecHksInitialize(void const *argument)
40 {
41     LiteTestPrint("HksInitialize Begin!\n");
42     TEST_ASSERT_TRUE(HksInitialize() == 0);
43     LiteTestPrint("HksInitialize End!\n");
44     osThreadExit();
45 }
46 /**
47  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
48  * @return: true——setup success
49  */
HksAesTestSetUp()50 static BOOL HksAesTestSetUp()
51 {
52     LiteTestPrint("setup\n");
53     osThreadId_t id;
54     osThreadAttr_t attr;
55     g_setPriority = osPriorityAboveNormal6;
56     attr.name = "test";
57     attr.attr_bits = 0U;
58     attr.cb_mem = NULL;
59     attr.cb_size = 0U;
60     attr.stack_mem = NULL;
61     attr.stack_size = TEST_TASK_STACK_SIZE;
62     attr.priority = g_setPriority;
63     id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
64     sleep(WAIT_TO_TEST_DONE);
65     LiteTestPrint("HksAgreementTestSetUp End2!\n");
66     return TRUE;
67 }
68 
69 /**
70  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
71  * @return: true——teardown success
72  */
HksAesTestTearDown()73 static BOOL HksAesTestTearDown()
74 {
75     LiteTestPrint("tearDown\n");
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