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