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