• 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 #ifndef _CUT_AUTHENTICATE_
17 #ifndef _CUT_ED25519_
18 #include "hks_curve25519_test.h"
19 
20 #include "cmsis_os2.h"
21 #include "hctest.h"
22 #include "iot_watchdog.h"
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  */
HksCurve25519TestSetUp()56 static BOOL HksCurve25519TestSetUp()
57 {
58     LiteTestPrint("setup\n");
59     IoTWatchDogDisable();
60     osThreadId_t id;
61     osThreadAttr_t attr;
62     g_setPriority = osPriorityAboveNormal6;
63     attr.name = "test";
64     attr.attr_bits = 0U;
65     attr.cb_mem = NULL;
66     attr.cb_size = 0U;
67     attr.stack_mem = NULL;
68     attr.stack_size = TEST_TASK_STACK_SIZE;
69     attr.priority = g_setPriority;
70     id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
71     sleep(WAIT_TO_TEST_DONE);
72     LiteTestPrint("HksCurve25519TestSetUp End2!\n");
73     return TRUE;
74 }
75 
76 /**
77  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
78  * @return: true——teardown success
79  */
HksCurve25519TestTearDown()80 static BOOL HksCurve25519TestTearDown()
81 {
82     LiteTestPrint("tearDown\n");
83     IoTWatchDogEnable();
84     return TRUE;
85 }
86 
LocalHksCurve25519Test001(void const * argument)87 static void LocalHksCurve25519Test001(void const *argument)
88 {
89     LiteTestPrint("HksCurve25519Test001 Begin!\n");
90     TEST_ASSERT_TRUE(TestCurve25519All() == 0);
91     LiteTestPrint("HksCurve25519Test001 End!\n");
92     osThreadExit();
93 }
94 
LocalHksCurve25519Test002(void const * argument)95 static void LocalHksCurve25519Test002(void const *argument)
96 {
97     LiteTestPrint("HksCurve25519Test002 Begin!\n");
98     TEST_ASSERT_TRUE(TestEd25519SignTeeVerifyLocal() == 0);
99     LiteTestPrint("HksCurve25519Test002 End!\n");
100     osThreadExit();
101 }
102 
LocalHksCurve25519Test003(void const * argument)103 static void LocalHksCurve25519Test003(void const *argument)
104 {
105     LiteTestPrint("HksCurve25519Test003 Begin!\n");
106     TEST_ASSERT_TRUE(TestCurve25519SignWrong() == 0);
107     LiteTestPrint("HksCurve25519Test003 End!\n");
108     osThreadExit();
109 }
110 
LocalHksCurve25519Test004(void const * argument)111 static void LocalHksCurve25519Test004(void const *argument)
112 {
113     LiteTestPrint("HksCurve25519Test004 Begin!\n");
114     TEST_ASSERT_TRUE(TestCurve25519verifyWrong() == 0);
115     LiteTestPrint("HksCurve25519Test004 End!\n");
116     osThreadExit();
117 }
118 
119 /**
120  * @tc.name: HksCurve25519Test.HksCurve25519Test001
121  * @tc.desc: The static function will return true;
122  * @tc.type: FUNC
123  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test001,Level1)124 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test001, 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)LocalHksCurve25519Test001, NULL, &attr);
137     sleep(WAIT_TO_TEST_DONE);
138     LiteTestPrint("HksCurve25519Test001 End2!\n");
139 }
140 
141 /**
142  * @tc.name: HksCurve25519Test.HksCurve25519Test002
143  * @tc.desc: The static function will return true;
144  * @tc.type: FUNC
145  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test002,Level1)146 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test002, 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)LocalHksCurve25519Test002, NULL, &attr);
159     sleep(WAIT_TO_TEST_DONE);
160     LiteTestPrint("HksCurve25519Test002 End2!\n");
161 }
162 
163 /**
164  * @tc.name: HksCurve25519Test.HksCurve25519Test003
165  * @tc.desc: The static function will return true;
166  * @tc.type: FUNC
167  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test003,Level1)168 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test003, 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)LocalHksCurve25519Test003, NULL, &attr);
181     sleep(WAIT_TO_TEST_DONE);
182     LiteTestPrint("HksCurve25519Test003 End2!\n");
183 }
184 
185 /**
186  * @tc.name: HksCurve25519Test.HksCurve25519Test004
187  * @tc.desc: The static function will return true;
188  * @tc.type: FUNC
189  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test004,Level1)190 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test004, Level1)
191 {
192     osThreadId_t id;
193     osThreadAttr_t attr;
194     g_setPriority = osPriorityAboveNormal6;
195     attr.name = "test";
196     attr.attr_bits = 0U;
197     attr.cb_mem = NULL;
198     attr.cb_size = 0U;
199     attr.stack_mem = NULL;
200     attr.stack_size = TEST_TASK_STACK_SIZE;
201     attr.priority = g_setPriority;
202     id = osThreadNew((osThreadFunc_t)LocalHksCurve25519Test004, NULL, &attr);
203     sleep(WAIT_TO_TEST_DONE);
204     LiteTestPrint("HksCurve25519Test004 End2!\n");
205 }
206 
207 RUN_TEST_SUITE(HksCurve25519Test);
208 #endif
209 #endif /* _CUT_AUTHENTICATE_ */
210 
211