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 #include "hks_generate_random_test.h"
17 
18 #include "hctest.h"
19 #include "hi_watchdog.h"
20 #include "hks_api.h"
21 #include "hks_param.h"
22 #include "hks_test_api_performance.h"
23 #include "hks_test_common.h"
24 #include "hks_test_log.h"
25 #include "hks_type.h"
26 
27 /*
28  * @tc.register: register a test suit named "CalcMultiTest"
29  * @param: test subsystem name
30  * @param: c_example module name
31  * @param: CalcMultiTest test suit name
32  */
33 LITE_TEST_SUIT(husk, huks_lite, HksGenerateRandomTest);
34 
35 /**
36  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
37  * @return: true——setup success
38  */
HksGenerateRandomTestSetUp()39 static BOOL HksGenerateRandomTestSetUp()
40 {
41     LiteTestPrint("setup\n");
42     hi_watchdog_disable();
43     TEST_ASSERT_TRUE(HksInitialize() == 0);
44     return TRUE;
45 }
46 
47 /**
48  * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
49  * @return: true——teardown success
50  */
HksGenerateRandomTestTearDown()51 static BOOL HksGenerateRandomTestTearDown()
52 {
53     LiteTestPrint("tearDown\n");
54     hi_watchdog_enable();
55     return TRUE;
56 }
57 
58 static const struct HksTestGenRandomParams g_testGenRandomParams[] = {
59     /* normal case */
60     { 0, HKS_SUCCESS, { true, HKS_MAX_RANDOM_LEN, true, HKS_MAX_RANDOM_LEN } },
61 };
62 /**
63  * @tc.name: HksGenerateRandomTest.HksGenerateRandomTest001
64  * @tc.desc: The static function will return true;
65  * @tc.type: FUNC
66  */
LITE_TEST_CASE(HksGenerateRandomTest,HksGenerateRandomTest001,Level1)67 LITE_TEST_CASE(HksGenerateRandomTest, HksGenerateRandomTest001, Level1)
68 {
69     int32_t ret;
70     struct HksBlob *random = NULL;
71 
72     ret = TestConstructBlobOut(&random,
73         g_testGenRandomParams[0].randomParams.blobExist,
74         g_testGenRandomParams[0].randomParams.blobSize,
75         g_testGenRandomParams[0].randomParams.blobDataExist,
76         g_testGenRandomParams[0].randomParams.blobDataSize);
77     TEST_ASSERT_TRUE(ret == 0);
78 
79     ret = HksGenerateRandomRun(random, 1);
80     if (ret != g_testGenRandomParams[0].expectResult) {
81         HKS_TEST_LOG_I("HksGenerateRandomRun failed, ret[%u] = %d", g_testGenRandomParams[0].testId, ret);
82     }
83     TEST_ASSERT_TRUE(ret == g_testGenRandomParams[0].expectResult);
84 
85     TestFreeBlob(&random);
86     TEST_ASSERT_TRUE(ret == 0);
87 }
88 
89 RUN_TEST_SUITE(HksGenerateRandomTest);
90