mirror of
https://gitee.com/openharmony/developtools_hiperf
synced 2025-03-03 05:26:47 +00:00
添加hiperf stat 用例
Signed-off-by:wenlong12 <wenlong12@huawei.com> Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
parent
17ef04db32
commit
a3338c085a
@ -628,10 +628,10 @@ void SubCommandStat::SetPerfEvent()
|
||||
|
||||
bool SubCommandStat::OnSubCommand(std::vector<std::string> &args)
|
||||
{
|
||||
if (HelpOption()) {
|
||||
return true;
|
||||
CHECK_TRUE(HelpOption(), true, 0, "");
|
||||
if (!CheckRestartOption(appPackage_, targetSystemWide_, restart_, selectPids_)) {
|
||||
return false;
|
||||
}
|
||||
CHECK_TRUE(!CheckRestartOption(appPackage_, targetSystemWide_, restart_, selectPids_), false, 0, "");
|
||||
// check option
|
||||
if (!CheckSelectCpuPidOption()) {
|
||||
return false;
|
||||
@ -640,7 +640,10 @@ bool SubCommandStat::OnSubCommand(std::vector<std::string> &args)
|
||||
HLOGV("CheckOptions() failed");
|
||||
return false;
|
||||
}
|
||||
CHECK_TRUE(!CheckAppIsRunning(selectPids_, appPackage_, checkAppMs_), false, 1, "CheckAppIsRunning() failed");
|
||||
if (!CheckAppIsRunning(selectPids_, appPackage_, checkAppMs_)) {
|
||||
HLOGV("CheckAppIsRunning() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
perfEvents_.SetCpu(selectCpus_);
|
||||
std::vector<pid_t> pids;
|
||||
@ -655,7 +658,10 @@ bool SubCommandStat::OnSubCommand(std::vector<std::string> &args)
|
||||
}
|
||||
pids.insert(pids.end(), selectTids_.begin(), selectTids_.end());
|
||||
perfEvents_.SetPid(pids);
|
||||
CHECK_TRUE(!CheckOptionPidAndApp(pids), false, 1, "CheckOptionPidAndApp() failed");
|
||||
if (!CheckOptionPidAndApp(pids)) {
|
||||
HLOGV("CheckOptionPidAndApp() failed");
|
||||
return false;
|
||||
}
|
||||
SetPerfEvent();
|
||||
if (!PrepairEvents()) {
|
||||
HLOGV("PrepairEvents() failed");
|
||||
|
@ -2199,6 +2199,69 @@ HWTEST_F(SubCommandStatTest, CheckOptionPidAndApp, TestSize.Level1)
|
||||
pids.push_back(700011); // 700011: invalid pid
|
||||
EXPECT_EQ(stat.CheckOptionPidAndApp(pids), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestOnSubCommand_restart_fail
|
||||
* @tc.desc: --restart
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, TestOnSubCommand_restart_fail, TestSize.Level1)
|
||||
{
|
||||
StdoutRecord stdoutRecord;
|
||||
stdoutRecord.Start();
|
||||
const auto startTime = chrono::steady_clock::now();
|
||||
EXPECT_EQ(Command::DispatchCommand("stat --restart"), false);
|
||||
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
chrono::steady_clock::now() - startTime);
|
||||
EXPECT_LE(costMs.count(), defaultRunTimeoutMs);
|
||||
|
||||
std::string stringOut = stdoutRecord.Stop();
|
||||
if (HasFailure()) {
|
||||
printf("output:\n%s", stringOut.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TestOnSubCommand_app_running
|
||||
* @tc.desc: --app
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, TestOnSubCommand_app_running, TestSize.Level1)
|
||||
{
|
||||
StdoutRecord stdoutRecord;
|
||||
stdoutRecord.Start();
|
||||
const auto startTime = chrono::steady_clock::now();
|
||||
EXPECT_EQ(Command::DispatchCommand("stat --app com.app.notrunning -d 2"), false);
|
||||
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
chrono::steady_clock::now() - startTime);
|
||||
EXPECT_LE(costMs.count(), defaultRunTimeoutMs);
|
||||
|
||||
std::string stringOut = stdoutRecord.Stop();
|
||||
if (HasFailure()) {
|
||||
printf("output:\n%s", stringOut.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckPidAndApp
|
||||
* @tc.desc: -p
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, CheckPidAndApp, TestSize.Level1)
|
||||
{
|
||||
StdoutRecord stdoutRecord;
|
||||
stdoutRecord.Start();
|
||||
const auto startTime = chrono::steady_clock::now();
|
||||
EXPECT_EQ(Command::DispatchCommand("stat -p 700001 -d 2"), true);
|
||||
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
chrono::steady_clock::now() - startTime);
|
||||
EXPECT_LE(costMs.count(), defaultRunTimeoutMs);
|
||||
|
||||
std::string stringOut = stdoutRecord.Stop();
|
||||
if (HasFailure()) {
|
||||
printf("output:\n%s", stringOut.c_str());
|
||||
}
|
||||
}
|
||||
} // namespace HiPerf
|
||||
} // namespace Developtools
|
||||
} // namespace OHOS
|
||||
|
Loading…
x
Reference in New Issue
Block a user