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 "hi_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 
30 /*
31  * @tc.register: register a test suit named "CalcMultiTest"
32  * @param: test subsystem name
33  * @param: c_example module name
34  * @param: CalcMultiTest test suit name
35  */
36 LITE_TEST_SUIT(husk, huks_lite, HksCurve25519Test);
37 
38 /**
39  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
40  * @return: true——setup success
41  */
HksCurve25519TestSetUp()42 static BOOL HksCurve25519TestSetUp()
43 {
44     LiteTestPrint("setup\n");
45     hi_watchdog_disable();
46     TEST_ASSERT_TRUE(HksInitialize() == 0);
47     return TRUE;
48 }
49 
50 /**
51  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
52  * @return: true——teardown success
53  */
HksCurve25519TestTearDown()54 static BOOL HksCurve25519TestTearDown()
55 {
56     LiteTestPrint("tearDown\n");
57     hi_watchdog_enable();
58     return TRUE;
59 }
60 
61 
62 /**
63  * @tc.name: HksCurve25519Test.HksCurve25519Test001
64  * @tc.desc: The static function will return true;
65  * @tc.type: FUNC
66  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test001,Level1)67 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test001, Level1)
68 {
69     LiteTestPrint("HksCurve25519Test001 Begin!\n");
70     TEST_ASSERT_TRUE(TestCurve25519All() == 0);
71     LiteTestPrint("HksCurve25519Test001 End!\n");
72 }
73 
74 #define TEST_TASK_STACK_SIZE      0x2000
75 #define WAIT_TO_TEST_DONE         4
76 
77 static osPriority_t g_setPriority;
78 
LocalHksCurve25519Test002(void const * argument)79 static void LocalHksCurve25519Test002(void const *argument)
80 {
81     LiteTestPrint("HksCurve25519Test002 Begin!\n");
82     TEST_ASSERT_TRUE(TestEd25519SignTeeVerifyLocal() == 0);
83     LiteTestPrint("HksCurve25519Test002 End!\n");
84 
85     osThreadExit();
86 }
87 
88 /**
89  * @tc.name: HksCurve25519Test.HksCurve25519Test002
90  * @tc.desc: The static function will return true;
91  * @tc.type: FUNC
92  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test002,Level1)93 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test002, Level1)
94 {
95     osThreadId_t id;
96     osThreadAttr_t attr;
97     g_setPriority = osPriorityAboveNormal6;
98     attr.name = "test";
99     attr.attr_bits = 0U;
100     attr.cb_mem = NULL;
101     attr.cb_size = 0U;
102     attr.stack_mem = NULL;
103     attr.stack_size = TEST_TASK_STACK_SIZE;
104     attr.priority = g_setPriority;
105     id = osThreadNew((osThreadFunc_t)LocalHksCurve25519Test002, NULL, &attr);
106 
107     (void)id;
108     sleep(WAIT_TO_TEST_DONE);
109 
110     LiteTestPrint("HksCurve25519Test002 End2!\n");
111 }
112 
113 /**
114  * @tc.name: HksCurve25519Test.HksCurve25519Test003
115  * @tc.desc: The static function will return true;
116  * @tc.type: FUNC
117  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test003,Level1)118 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test003, Level1)
119 {
120     TEST_ASSERT_TRUE(TestCurve25519SignWrong() == 0);
121 }
122 
123 /**
124  * @tc.name: HksCurve25519Test.HksCurve25519Test004
125  * @tc.desc: The static function will return true;
126  * @tc.type: FUNC
127  */
LITE_TEST_CASE(HksCurve25519Test,HksCurve25519Test004,Level1)128 LITE_TEST_CASE(HksCurve25519Test, HksCurve25519Test004, Level1)
129 {
130     TEST_ASSERT_TRUE(TestCurve25519verifyWrong() == 0);
131 }
132 
133 RUN_TEST_SUITE(HksCurve25519Test);
134 #endif
135 #endif /* _CUT_AUTHENTICATE_ */
136 
137