1 /*
2 * Copyright (c) 2024 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 "ParamsParseFuzzer.h"
17 #include "common.h"
18 #include "secodeFuzz.h"
19 #include "CommandParser.h"
20
21 using namespace fuzztest;
22
23 const int DEFAULT_LENGTH = 1000;
24
CallParamsParseFunc(const std::vector<std::string> & args)25 void ParamsParse::CallParamsParseFunc(const std::vector<std::string>& args)
26 {
27 CommandParser& parser = CommandParser::GetInstance();
28 parser.ProcessCommand(args);
29 parser.IsCommandValid();
30 }
31
ParamsParseFuzzTest()32 void ParamsParse::ParamsParseFuzzTest()
33 {
34 // 要求单测试用例最低运行3千万次或者8小时以上
35 printf("start ---- ParamsParseFuzzTest\r\n");
36 DT_FUZZ_START(0, TEST_TIMES, (char*)"ParamsParseFuzzTest", 0)
37 {
38 std::vector<std::string> args;
39 SetTestArgs(args);
40 CallParamsParseFunc(args);
41 }
42 DT_FUZZ_END()
43 printf("end ---- ParamsParseFuzzTest\r\n");
44
45 if (DT_GetIsPass() == 0) {
46 printf("ParamsParseFuzzTest is not ok\r\n");
47 } else {
48 printf("ParamsParseFuzzTest is ok\r\n");
49 }
50 }
51
SetTestArgs(std::vector<std::string> & args)52 void ParamsParse::SetTestArgs(std::vector<std::string>& args)
53 {
54 int index = -1;
55 for (const Param& param : paramList) {
56 args.push_back(param.name);
57 for (const std::string& value : param.values) {
58 index++;
59 std::string str = std::string(value);
60 args.push_back(DT_SetGetString(&g_Element[index], str.size() + 1, DEFAULT_LENGTH, (char*)str.c_str()));
61 }
62 }
63 }
64
65 namespace {
TEST_F(ParamsParseFuzzTest,test_params)66 TEST_F(ParamsParseFuzzTest, test_params)
67 {
68 parse.ParamsParseFuzzTest();
69 }
70 }