• 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 
32 #define TEST_TASK_STACK_SIZE      0x2000
33 #define WAIT_TO_TEST_DONE         4
34 
35 static osPriority_t g_setPriority;
36 static const struct HksTestKeyExistParams g_testKeyExistParams[] = {
37     /* normal case */
38     { 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
39 };
40 /*
41  * @tc.register: register a test suit named "CalcMultiTest"
42  * @param: test subsystem name
43  * @param: c_example module name
44  * @param: CalcMultiTest test suit name
45  */
46 LITE_TEST_SUIT(security, securityData, HksDeleteTest);
47 
ExecHksInitialize(void const * argument)48 static void ExecHksInitialize(void const *argument)
49 {
50     LiteTestPrint("HksInitialize Begin!\n");
51     TEST_ASSERT_TRUE(HksInitialize() == 0);
52     LiteTestPrint("HksInitialize End!\n");
53     osThreadExit();
54 }
55 
ExecHksDeleteTest001(void const * argument)56 static void ExecHksDeleteTest001(void const *argument)
57 {
58     LiteTestPrint("HksDeleteTest001 Begin!\n");
59     int32_t ret;
60     struct HksBlob *keyAlias = NULL;
61     if (g_testKeyExistParams[0].isGenKey) {
62         HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
63     } else {
64         ret = TestConstuctBlob(&keyAlias,
65                                g_testKeyExistParams[0].keyAliasParams.blobExist,
66                                g_testKeyExistParams[0].keyAliasParams.blobSize,
67                                g_testKeyExistParams[0].keyAliasParams.blobDataExist,
68                                g_testKeyExistParams[0].keyAliasParams.blobDataSize);
69         HKS_TEST_ASSERT(ret == 0);
70     }
71 
72     ret = HksDeleteKeyRun(keyAlias, 1);
73     HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
74 
75     TestFreeBlob(&keyAlias);
76     TEST_ASSERT_TRUE(ret == 0);
77     LiteTestPrint("HksDeleteTest001 End!\n");
78     osThreadExit();
79 }
80 /**
81  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
82  * @return: true——setup success
83  */
HksDeleteTestSetUp()84 static BOOL HksDeleteTestSetUp()
85 {
86     LiteTestPrint("setup\n");
87     osThreadId_t id;
88     osThreadAttr_t attr;
89     g_setPriority = osPriorityAboveNormal6;
90     attr.name = "test";
91     attr.attr_bits = 0U;
92     attr.cb_mem = NULL;
93     attr.cb_size = 0U;
94     attr.stack_mem = NULL;
95     attr.stack_size = TEST_TASK_STACK_SIZE;
96     attr.priority = g_setPriority;
97     id = osThreadNew((osThreadFunc_t)ExecHksInitialize, NULL, &attr);
98     sleep(WAIT_TO_TEST_DONE);
99     LiteTestPrint("HksDeriveTestSetUp End2!\n");
100     return TRUE;
101 }
102 
103 /**
104  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
105  * @return: true——teardown success
106  */
HksDeleteTestTearDown()107 static BOOL HksDeleteTestTearDown()
108 {
109     LiteTestPrint("tearDown\n");
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