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