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
18 #include "hctest.h"
19 #include "iot_watchdog.h"
20 #include "hks_delete_test.h"
21 #include "hks_api.h"
22 #include "hks_param.h"
23 #include "hks_test_api_performance.h"
24 #include "hks_test_common.h"
25 #include "hks_test_log.h"
26 #include "hks_type.h"
27 #include "cmsis_os2.h"
28 #include "ohos_types.h"
29
30 #define TEST_TASK_STACK_SIZE 0x2000
31 #define WAIT_TO_TEST_DONE 4
32
33 static osPriority_t g_setPriority;
34 static const struct HksTestKeyExistParams g_testKeyExistParams[] = {
35 /* normal case */
36 { 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
37 };
38 /*
39 * @tc.register: register a test suit named "CalcMultiTest"
40 * @param: test subsystem name
41 * @param: c_example module name
42 * @param: CalcMultiTest test suit name
43 */
44 LITE_TEST_SUIT(security, securityData, HksDeleteTest);
45
ExecHksInitialize(void const * argument)46 static void ExecHksInitialize(void const *argument)
47 {
48 LiteTestPrint("HksInitialize Begin!\n");
49 TEST_ASSERT_TRUE(HksInitialize() == 0);
50 LiteTestPrint("HksInitialize End!\n");
51 osThreadExit();
52 }
53
ExecHksDeleteTest001(void const * argument)54 static void ExecHksDeleteTest001(void const *argument)
55 {
56 LiteTestPrint("HksDeleteTest001 Begin!\n");
57 int32_t ret;
58 struct HksBlob *keyAlias = NULL;
59 if (g_testKeyExistParams[0].isGenKey) {
60 HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
61 } else {
62 ret = TestConstuctBlob(&keyAlias,
63 g_testKeyExistParams[0].keyAliasParams.blobExist,
64 g_testKeyExistParams[0].keyAliasParams.blobSize,
65 g_testKeyExistParams[0].keyAliasParams.blobDataExist,
66 g_testKeyExistParams[0].keyAliasParams.blobDataSize);
67 HKS_TEST_ASSERT(ret == 0);
68 }
69
70 ret = HksDeleteKeyRun(keyAlias, 1);
71 HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
72
73 TestFreeBlob(&keyAlias);
74 TEST_ASSERT_TRUE(ret == 0);
75 LiteTestPrint("HksDeleteTest001 End!\n");
76 osThreadExit();
77 }
78 /**
79 * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
80 * @return: true——setup success
81 */
HksDeleteTestSetUp()82 static BOOL HksDeleteTestSetUp()
83 {
84 LiteTestPrint("setup\n");
85 IoTWatchDogDisable();
86 osThreadId_t id;
87 osThreadAttr_t attr;
88 g_setPriority = osPriorityAboveNormal6;
89 attr.name = "test";
90 attr.attr_bits = 0U;
91 attr.cb_mem = NULL;
92 attr.cb_size = 0U;
93 attr.stack_mem = NULL;
94 attr.stack_size = TEST_TASK_STACK_SIZE;
95 attr.priority = g_setPriority;
96 id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
97 sleep(WAIT_TO_TEST_DONE);
98 LiteTestPrint("HksDeriveTestSetUp End2!\n");
99 return TRUE;
100 }
101
102 /**
103 * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
104 * @return: true——teardown success
105 */
HksDeleteTestTearDown()106 static BOOL HksDeleteTestTearDown()
107 {
108 LiteTestPrint("tearDown\n");
109 IoTWatchDogEnable();
110 return TRUE;
111 }
112
113 /**
114 * @tc.name: HksDeleteTest.HksDeleteTest001
115 * @tc.desc: The static function will return true;
116 * @tc.type: FUNC
117 */
LITE_TEST_CASE(HksDeleteTest,HksDeleteTest001,Level1)118 LITE_TEST_CASE(HksDeleteTest, HksDeleteTest001, Level1)
119 {
120 osThreadId_t id;
121 osThreadAttr_t attr;
122 g_setPriority = osPriorityAboveNormal6;
123 attr.name = "test";
124 attr.attr_bits = 0U;
125 attr.cb_mem = NULL;
126 attr.cb_size = 0U;
127 attr.stack_mem = NULL;
128 attr.stack_size = TEST_TASK_STACK_SIZE;
129 attr.priority = g_setPriority;
130 id = osThreadNew((osThreadFunc_t)ExecHksDeleteTest001, NULL, &attr);
131 sleep(WAIT_TO_TEST_DONE);
132 LiteTestPrint("HksDeleteTest001 End2!\n");
133 }
134
135 RUN_TEST_SUITE(HksDeleteTest);
136 #endif /* _CUT_AUTHENTICATE_ */
137
138