diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index 6e6e8d081408a52d24b4e683c6d351589ccaf818..04921821bb82a4c83d2fead2cea69372ca2716c4 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -188,41 +188,6 @@ const std::unordered_map COMMAND_MAP = { { std::string("-HCI"), CommandType::CT_HCI }, }; -const std::unordered_map COMMAND_MAP_REVERSE = { - { CommandType::CT_N, std::string("-N") }, - { CommandType::CT_PKG, std::string("-PKG") }, - { CommandType::CT_PID, std::string("-PID") }, - { CommandType::CT_OUT, std::string("-OUT") }, - { CommandType::CT_C, std::string("-c") }, - { CommandType::CT_G, std::string("-g") }, - { CommandType::CT_F, std::string("-f") }, - { CommandType::CT_FDS, std::string("-fds") }, - { CommandType::CT_T, std::string("-t") }, - { CommandType::CT_P, std::string("-p") }, - { CommandType::CT_PRINT, std::string("-print") }, - { CommandType::CT_R, std::string("-r") }, - { CommandType::CT_TRACE, std::string("-TRACE") }, - { CommandType::CT_THREADS, std::string("-threads") }, - { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, - { CommandType::CT_D, std::string("-d") }, - { CommandType::CT_INTERVAL, std::string("-INTERVAL") }, - { CommandType::CT_SESSIONID, std::string("-SESSIONID") }, - { CommandType::CT_NET, std::string("-net") }, - { CommandType::CT_VIEW, std::string("-VIEW") }, - { CommandType::CT_FL, std::string("-fl") }, - { CommandType::CT_FTL, std::string("-ftl") }, - { CommandType::CT_GC, std::string("-GPU_COUNTER") }, - { CommandType::CT_NAV, std::string("-nav") }, - { CommandType::CT_O, std::string("-o") }, - { CommandType::CT_LF, std::string("-lockfreq") }, - { CommandType::CT_AS, std::string("-aischedule") }, - { CommandType::CT_GE, std::string("-ge") }, - { CommandType::CT_CI, std::string("-ci") }, - { CommandType::CT_FC, std::string("-fc") }, - { CommandType::CT_HCI, std::string("-HCI") }, -}; - - const std::unordered_map COMMAND_HELP_MAP = { { CommandHelp::HELP, std::string("--help") }, { CommandHelp::VERSION, std::string("--version") }, diff --git a/host/smartperf/client/client_command/include/smartperf_command.h b/host/smartperf/client/client_command/include/smartperf_command.h index 6e0f0685035c1cde64669ce96082c101c12474da..8d94539ac17afd334a89ca1ed8e359dbc95ac8ac 100644 --- a/host/smartperf/client/client_command/include/smartperf_command.h +++ b/host/smartperf/client/client_command/include/smartperf_command.h @@ -38,8 +38,6 @@ public: " -PID set process pid, must add, for example: -PID 3568 \n" " -threads get threads, must add -PID or -PKG for example: \n" "\t\t -threads -PID 3568 or -threads -PKG ohos.samples.ecg \n" - " -fds get file descriptor, must add -PID or -PKG for example: \n" - "\t\t -fds -PID 3568 or -fds -PKG ohos.samples.ecg \n" " -c get device CPU frequency and CPU usage, process CPU usage and CPU load .. \n" " -ci get cpu instructions and cycles \n" " -g get device GPU frequency and GPU load \n" @@ -62,7 +60,6 @@ public: " -server start a process to listen to the socket message of the start and stop commands \n" " -clear clear the process ID \n" " -ohtestfps used by the vilidator to obtain the fps, the collection times can be set \n" - " -editorServer start a process to listen to the socket message of the editor \n" " -recordcapacity get the battery level difference \n" " --version get version \n" " --help get help \n" @@ -81,7 +78,6 @@ public: "SP_daemon -server \n" "SP_daemon -clear \n" "SP_daemon -ohtestfps 10 \n" - "SP_daemon -editorServer \n" "SP_daemon -recordcapacity \n" "example3: These parameters need to be used separately \n" "SP_daemon -editor responseTime ohos.samples.ecg app name \n" diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 3e3a571728d18e9d6a2b883278bef013b01390be..8d759d5693a53d1c8db8a684ac7baf5dfb982485 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -148,6 +148,9 @@ bool VeriyKey(std::set& keys, std::map& m bool VerifyValueStr(std::map& mapInfo, std::string& errorInfo); bool IntegerValueVerification(std::set &keys, std::map &mapInfo, std::string &errorInfo); +bool RemSpaceAndTraPara(std::vector& outParam, std::map& mapInfo, + std::string &errorInfo); +bool IsInvalidInputfromComParam(const std::string& param, std::string &errorInfo); bool IsHmKernel(); std::string GetCpuNum(); void GetCurrentTime(int prevTime); diff --git a/host/smartperf/client/client_command/smartperf_main.cpp b/host/smartperf/client/client_command/smartperf_main.cpp index f2ccb73da140ce580512bccca9dcef988616d211..beaeeab3a96a93bd8f21af46ca0d860b0c194db2 100644 --- a/host/smartperf/client/client_command/smartperf_main.cpp +++ b/host/smartperf/client/client_command/smartperf_main.cpp @@ -95,7 +95,7 @@ static bool g_checkCmdParam(std::vector &argv, std::string &errorIn ) { keys.insert(argv[1].substr(1).c_str()); } - for (auto& a : OHOS::SmartPerf::COMMAND_MAP) { + for (auto& a : OHOS::SmartPerf::COMMAND_SHELL_MAP) { keys.insert(a.first.substr(1)); // No prefix required '-' } @@ -104,6 +104,8 @@ static bool g_checkCmdParam(std::vector &argv, std::string &errorIn keys.erase("f2"); keys.erase("fl"); keys.erase("ftl"); + keys.erase("editorServer"); + keys.erase("deviceServer"); return OHOS::SmartPerf::SPUtils::VeriyParameter(keys, str, errorInfo); } diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index b1fe62e4c0aac6f7e33f87d513f0f9d7aae95f26..5e4e3dd064e7ff061db300a35c46cc8bd033851d 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -517,12 +517,39 @@ bool SPUtils::IntegerVerification(const std::string& str, std::string& errorInfo bool SPUtils::VeriyParameter(std::set &keys, const std::string& param, std::string &errorInfo) { - std::string keyParam; - std::string valueParm; std::vector out; - std::vector subOut; std::map mapInfo; + if (!IsInvalidInputfromComParam(param, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + SPUtils::StrSplit(param, "-", out); + if (!RemSpaceAndTraPara(out, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!VeriyKey(keys, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!VerifyValueStr(mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!IntegerValueVerification(keys, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + return true; +} + +bool SPUtils::IsInvalidInputfromComParam(const std::string& param, std::string &errorInfo) +{ if (param.empty()) { errorInfo = "The parameter cannot be empty"; return false; @@ -532,9 +559,30 @@ bool SPUtils::VeriyParameter(std::set &keys, const std::string& par LOGE("-PKG and -PID cannot be used together with"); return false; } - SPUtils::StrSplit(param, "-", out); + const size_t paramLength = 1; + if (param.length() == paramLength && param[0] == '-') { + errorInfo = "invalid parameter -- '" + param + "'"; + return false; + } + std::string commandShell; + for (const auto& a : COMMAND_SHELL_MAP) { + commandShell = a.first.substr(1); + } + if (param.find("--") != std::string::npos && param.find(commandShell)) { + errorInfo = "invalid parameter -- '" + param + "'"; + return false; + } + return true; +} - for (auto it = out.begin(); it != out.end(); ++it) { // Parsing keys and values +bool SPUtils::RemSpaceAndTraPara(std::vector& outParam, std::map& mapInfo, + std::string &errorInfo) +{ + std::string keyParam; + std::string valueParm; + std::vector subOut; + + for (auto it = outParam.begin(); it != outParam.end(); ++it) { // Parsing keys and values subOut.clear(); SPUtils::StrSplit(*it, " ", subOut); if (mapInfo.end() != mapInfo.find(subOut[0])) { @@ -554,21 +602,6 @@ bool SPUtils::VeriyParameter(std::set &keys, const std::string& par mapInfo[keyParam] = ""; } } - - if (!VeriyKey(keys, mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } - - if (!VerifyValueStr(mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } - - if (!IntegerValueVerification(keys, mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } return true; }