diff --git a/device/cmds/src/main.cpp b/device/cmds/src/main.cpp index b2cc8438e49d870f8c9656a5e66ef28cd2088a73..6a4e8840d305285e1bbd27828799778e4aa4aa01 100644 --- a/device/cmds/src/main.cpp +++ b/device/cmds/src/main.cpp @@ -472,7 +472,11 @@ int main(int argc, char* argv[]) if (option == -1) { break; // CONFIG. } - + std::string optionStr("qtohlskc"); + if (optionStr.find(option) == std::string::npos) { + printf("invalid param\n"); + return -1; + } if (option == 'c' && strcmp(optarg, "-") == 0) { std::string content; std::istreambuf_iterator begin(std::cin); diff --git a/device/cmds/test/unittest/hiprofiler_cmd_test.cpp b/device/cmds/test/unittest/hiprofiler_cmd_test.cpp index f1f545d5305c36851e40ace1be5434e5f3717cec..e899b6eaff7c29d7e51889b7c69de08ed548af76 100644 --- a/device/cmds/test/unittest/hiprofiler_cmd_test.cpp +++ b/device/cmds/test/unittest/hiprofiler_cmd_test.cpp @@ -819,3 +819,31 @@ HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0240, Function | MediumTest | Lev cmd = "rm " + DEFAULT_PATH + outFileName + "*.htrace"; system(cmd.c_str()); } + +/** + * @tc.name: hiprofiler_cmd + * @tc.desc: Test hiprofiler_cmd with test -s -c. + * @tc.type: FUNC + */ +HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0250, Function | MediumTest | Level1) +{ + StopProcessStub(DEFAULT_HIPROFILERD_PATH); + sleep(1); + StopProcessStub(DEFAULT_HIPROFILER_PLUGINS_PATH); + sleep(1); + + std::string cmd = DEFAULT_HIPROFILER_CMD_PATH + " test -c "; + std::string content = ""; + EXPECT_TRUE(RunCommand(cmd, content)); + std::string destStr = "invalid param"; + EXPECT_TRUE(content.find(destStr) != std::string::npos); + cmd = DEFAULT_HIPROFILER_CMD_PATH + " XXX%$ --config "; + content = ""; + EXPECT_TRUE(RunCommand(cmd, content)); + EXPECT_TRUE(content.find(destStr) != std::string::npos); + cmd = DEFAULT_HIPROFILER_CMD_PATH + " @X8&C -s "; + content = ""; + EXPECT_TRUE(RunCommand(cmd, content)); + destStr = "unknown param"; + EXPECT_TRUE(content.find(destStr) != std::string::npos); +} \ No newline at end of file