• 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 
18 #include "hctest.h"
19 
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 #include <unistd.h>
31 #define TEST_TASK_STACK_SIZE      0x2000
32 #define WAIT_TO_TEST_DONE         4
33 
34 static osPriority_t g_setPriority;
35 static const struct HksTestKeyExistParams g_testKeyExistParams[] = {
36     /* normal case */
37     { 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
38 };
39 /*
40  * @tc.register: register a test suit named "CalcMultiTest"
41  * @param: test subsystem name
42  * @param: c_example module name
43  * @param: CalcMultiTest test suit name
44  */
45 LITE_TEST_SUIT(security, securityData, HksDeleteTest);
46 
ExecHksInitialize(void const * argument)47 static void ExecHksInitialize(void const *argument)
48 {
49     LiteTestPrint("HksInitialize Begin!\n");
50     TEST_ASSERT_TRUE(HksInitialize() == 0);
51     LiteTestPrint("HksInitialize End!\n");
52     osThreadExit();
53 }
54 
ExecHksDeleteTest001(void const * argument)55 static void ExecHksDeleteTest001(void const *argument)
56 {
57     LiteTestPrint("HksDeleteTest001 Begin!\n");
58     int32_t ret;
59     struct HksBlob *keyAlias = NULL;
60     if (g_testKeyExistParams[0].isGenKey) {
61         HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
62     } else {
63         ret = TestConstuctBlob(&keyAlias,
64                                g_testKeyExistParams[0].keyAliasParams.blobExist,
65                                g_testKeyExistParams[0].keyAliasParams.blobSize,
66                                g_testKeyExistParams[0].keyAliasParams.blobDataExist,
67                                g_testKeyExistParams[0].keyAliasParams.blobDataSize);
68         HKS_TEST_ASSERT(ret == 0);
69     }
70 
71     ret = HksDeleteKeyRun(keyAlias, 1);
72     HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
73 
74     TestFreeBlob(&keyAlias);
75     TEST_ASSERT_TRUE(ret == 0);
76     LiteTestPrint("HksDeleteTest001 End!\n");
77     osThreadExit();
78 }
79 /**
80  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
81  * @return: true——setup success
82  */
HksDeleteTestSetUp()83 static BOOL HksDeleteTestSetUp()
84 {
85     LiteTestPrint("setup\n");
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     return TRUE;
110 }
111 
112 /**
113  * @tc.name: HksDeleteTest.HksDeleteTest001
114  * @tc.desc: The static function will return true;
115  * @tc.type: FUNC
116  */
LITE_TEST_CASE(HksDeleteTest,HksDeleteTest001,Level1)117 LITE_TEST_CASE(HksDeleteTest, HksDeleteTest001, Level1)
118 {
119     osThreadId_t id;
120     osThreadAttr_t attr;
121     g_setPriority = osPriorityAboveNormal6;
122     attr.name = "test";
123     attr.attr_bits = 0U;
124     attr.cb_mem = NULL;
125     attr.cb_size = 0U;
126     attr.stack_mem = NULL;
127     attr.stack_size = TEST_TASK_STACK_SIZE;
128     attr.priority = g_setPriority;
129     id = osThreadNew((osThreadFunc_t)ExecHksDeleteTest001, NULL, &attr);
130     sleep(WAIT_TO_TEST_DONE);
131     LiteTestPrint("HksDeleteTest001 End2!\n");
132 }
133 
134 RUN_TEST_SUITE(HksDeleteTest);
135 #endif /* _CUT_AUTHENTICATE_ */
136 
137