!593 去掉测试用例采集进程32,64位宏判断

Merge pull request !593 from wenlong_12/master
This commit is contained in:
openharmony_ci 2024-09-14 01:53:58 +00:00 committed by Gitee
commit 293c5fa1a6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 96 additions and 17 deletions

View File

@ -44,6 +44,7 @@ sources_base = [
"unittest/common/native/report_json_file_test.cpp",
"unittest/common/native/unique_stack_table_test.cpp",
"unittest/common/native/spe_decoder_test.cpp",
"unittest/common/native/test_utilities.cpp",
]
if (hiperf_debug) {

View File

@ -14,7 +14,7 @@
*/
#include "cpu_usage_test.h"
#include "utilities_test.h"
#include "test_utilities.h"
using namespace std;
using namespace testing::ext;
using namespace std::chrono;
@ -43,13 +43,20 @@ public:
float GetAverageCpuUsage(pid_t pid, uint64_t timeOut);
void TestCpuUsage(const std::string &option, unsigned int expect, bool fixPid);
std::string testProcesses = "com.ohos.sceneboard";
};
void CpuUsageTest::SetUpTestCase() {}
void CpuUsageTest::TearDownTestCase() {}
void CpuUsageTest::SetUp() {}
void CpuUsageTest::SetUp()
{
if (!HiPerf::CheckTestApp()) {
testProcesses = "com.ohos.launcher";
}
}
void CpuUsageTest::TearDown() {}
@ -216,7 +223,7 @@ void CpuUsageTest::TestCpuUsage(const std::string &option, unsigned int expect,
std::string cmd = "hiperf record ";
if (fixPid) {
cmd += "--app ";
cmd += " " + TEST_PROCESSES;
cmd += " " + testProcesses;
}
cmd += " " + option;

View File

@ -20,8 +20,8 @@
#include <cinttypes>
#include <thread>
#include "test_utilities.h"
#include "utilities.h"
#include "utilities_test.h"
using namespace testing::ext;
using namespace std;
@ -426,7 +426,11 @@ HWTEST_F(HiperfClientTest, SetDataLimit, TestSize.Level1)
HWTEST_F(HiperfClientTest, SetAppPackage, TestSize.Level1)
{
HiperfClient::RecordOption opt;
opt.SetAppPackage(TEST_PROCESSES);
std::string testProcesses = "com.ohos.sceneboard";
if (!CheckTestApp()) {
testProcesses = "com.ohos.launcher";
}
opt.SetAppPackage(testProcesses);
TestCaseOption(opt);
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HIPERF_TEST_UTILITIES_H_
#define HIPERF_TEST_UTILITIES_H_
namespace OHOS {
namespace Developtools {
namespace HiPerf {
bool CheckTestApp();
} // namespace HiPerf
} // namespace Developtools
} // namespace OHOS
#endif // HIPERF_TEST_UTILITIES_H_

View File

@ -20,10 +20,4 @@
#include <gtest/gtest.h>
#include <hilog/log.h>
#if defined(__aarch64__)
const std::string TEST_PROCESSES = "com.ohos.sceneboard";
#else
const std::string TEST_PROCESSES = "com.ohos.launcher";
#endif
#endif // HIPERF_UTILITIES_TEST_H

View File

@ -17,7 +17,7 @@
#include "command.h"
#include "subcommand_dump.h"
#include "subcommand_record.h"
#include "utilities_test.h"
#include "test_utilities.h"
using namespace testing::ext;
using namespace std;
@ -95,9 +95,12 @@ HWTEST_F(SpeDecoderTest, TestGetSpeEventNameByType, TestSize.Level1)
HWTEST_F(SpeDecoderTest, TestRecord, TestSize.Level1)
{
StdoutRecord stdoutRecord;
std::string testProcesses = "com.ohos.sceneboard";
if (!CheckTestApp()) {
testProcesses = "com.ohos.launcher";
}
std::string cmdString = "record -e arm_spe_0/load_filter=1,min_latency=100/ -d 10 --app ";
cmdString += " " + TEST_PROCESSES;
cmdString += " " + testProcesses;
printf("command : %s\n", cmdString.c_str());
// it need load some symbols and much more log

View File

@ -28,8 +28,8 @@
#include "command.h"
#include "debug_logger.h"
#include "test_utilities.h"
#include "utilities.h"
#include "utilities_test.h"
using namespace std::literals::chrono_literals;
using namespace testing::ext;
@ -81,14 +81,21 @@ public:
static void TestRecordCommand(const std::string &option, bool expect = true, bool fixPid = true);
size_t GetFileSize(const char* fileName);
static std::string testProcesses;
};
std::string SubCommandRecordTest::testProcesses = "com.ohos.sceneboard";
void SubCommandRecordTest::SetUpTestCase() {}
void SubCommandRecordTest::TearDownTestCase() {}
void SubCommandRecordTest::SetUp()
{
if (!CheckTestApp()) {
SubCommandRecordTest::testProcesses = "com.ohos.launcher";
}
SubCommand::ClearSubCommands(); // clear the subCommands left from other UT
ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
SubCommandRecord::RegisterSubCommandRecord();
@ -127,7 +134,7 @@ void SubCommandRecordTest::TestRecordCommand(const std::string &option, bool exp
std::string cmdString = "record ";
if (fixPid) {
cmdString += "--app ";
cmdString += " " + TEST_PROCESSES;
cmdString += " " + testProcesses;
}
cmdString += " " + option;
printf("command : %s\n", cmdString.c_str());
@ -556,7 +563,7 @@ HWTEST_F(SubCommandRecordTest, SelectPidInputErr, TestSize.Level1)
TestRecordCommand("-d 2 -p abc ", false, false);
}
HWTEST_F(SubCommandRecordTest, SelectPidInputConfict, TestSize.Level1)
HWTEST_F(SubCommandRecordTest, SelectPidInputConflict, TestSize.Level1)
{
ForkAndRunTest("-d 2 -a -p 1 ", false, false);
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdio>
#include <iostream>
#include "test_utilities.h"
namespace OHOS {
namespace Developtools {
namespace HiPerf {
bool CheckTestApp()
{
FILE *fp = nullptr;
char buf[100];
std::string cmd = "pidof com.ohos.sceneboard";
if ((fp = popen(cmd.c_str(), "r")) != nullptr) {
if (fgets(buf, sizeof(buf), fp) == nullptr) {
pclose(fp);
return false;
}
pclose(fp);
}
return true;
}
} // namespace HiPerf
} // namespace Developtools
} // namespace OHOS