!528 补充用例

Merge pull request !528 from wenlong_12/master
This commit is contained in:
openharmony_ci 2024-07-29 09:08:20 +00:00 committed by Gitee
commit 27564f7e32
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 218 additions and 5 deletions

View File

@ -56,7 +56,7 @@ Note:If the text contains special characters, please escape them according to th
<configuration>
<oatconfig>
<filefilterlist>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility, license header policies">
<filteritem type="filepath" name="test/unittest/resource/testdata/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/dwarf/.*" desc="test resource file, no license header"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/report/.*" desc="test resource file, no license header"/>
@ -119,6 +119,8 @@ Note:If the text contains special characters, please escape them according to th
<filteritem type="filepath" name="test/unittest/resource/testdata/dwarf.uncompress.data" desc="the binary file for test, the file is self-developed"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/fp.compress.data" desc="the binary file for test, the file is self-developed"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/fp.uncompress.data" desc="the binary file for test, the file is self-developed"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/invalid_perf.data.tar.gz" desc="the binary file for test, the file is self-developed"/>
<filteritem type="filepath" name="test/unittest/resource/testdata/invalid_gzip_perf.data.tar.gz" desc="the binary file for test, the file is self-developed"/>
<filteritem type="filepath" name="demo/js/entry/src/main/resources/base/media/icon.png" desc="the binary file, the file is self-picture"/>
<filteritem type="filepath" name="figures/hiperf_architecture.png" desc="the binary file, the file is self-picture"/>
<filteritem type="filepath" name="figures/hiperf_architecture_zh.png" desc="the binary file, the file is self-picture"/>

View File

@ -220,6 +220,7 @@ HWTEST_F(DebugLoggerTest, SetLogTags, TestSize.Level1)
const std::string errorLogTag = "errtag";
const std::string errorLogTags = "errtag,errtag,errtag";
const std::string mixLogTags = "errtag,errtag,DebugTest,errtag";
const std::string LogTags = "DebugTest:T,DebugTest:V";
DebugLogger::GetInstance()->SetLogTags("DebugTest");
@ -242,6 +243,11 @@ HWTEST_F(DebugLoggerTest, SetLogTags, TestSize.Level1)
EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_MUCH, "DebugTest"), true);
EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_DEBUG, "DebugTest"), true);
DebugLogger::GetInstance()->SetLogTags(LogTags);
EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_MUCH, "DebugTest"), false);
EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_VERBOSE, "DebugTest"), true);
// back to default
DebugLogger::GetInstance()->SetLogTags("");
}

View File

@ -35,7 +35,7 @@ public:
void SetUp();
void TearDown();
const std::string TEST_LOG_MESSAGE = "<HELLO_TEST_LOG_MESSAGE>";
void LogLevelTest(std::vector<std::string> args, DebugLevel level);
void LogLevelTest(std::vector<std::string> args, DebugLevel level, bool result = true);
default_random_engine rnd_;
};
@ -63,11 +63,14 @@ void OptionDebugTest::TearDown()
Option::ClearMainOptions();
}
void OptionDebugTest::LogLevelTest(std::vector<std::string> args, const DebugLevel testlevel)
void OptionDebugTest::LogLevelTest(std::vector<std::string> args, const DebugLevel testlevel, bool result)
{
// backup
DebugLevel oldLevel = DebugLogger::GetInstance()->GetLogLevel();
EXPECT_EQ(Command::DispatchCommands(args), true);
EXPECT_EQ(Command::DispatchCommands(args), result);
if (!result) {
return;
}
const std::string logMessage =
TEST_LOG_MESSAGE + std::to_string(rnd_()) + "_" + std::to_string(testlevel);
@ -139,6 +142,36 @@ HWTEST_F(OptionDebugTest, much, TestSize.Level1)
LogLevelTest({"--much", TEST_CMD_NOTHING}, LEVEL_MUCH);
}
/**
* @tc.name: undebug
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, undebug, TestSize.Level1)
{
LogLevelTest({"--debug"}, LEVEL_DEBUG, false);
}
/**
* @tc.name: unverbose
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, unverbose, TestSize.Level1)
{
LogLevelTest({"--verbose"}, LEVEL_VERBOSE, false);
}
/**
* @tc.name: unmuch
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, unmuch, TestSize.Level1)
{
LogLevelTest({"--much"}, LEVEL_MUCH, false);
}
/**
* @tc.name: mixlog
* @tc.desc:
@ -170,6 +203,16 @@ HWTEST_F(OptionDebugTest, logpath, TestSize.Level1)
EXPECT_EQ(Command::DispatchCommands({"--logpath", DEFAULT_LOG_PATH, TEST_CMD_NOTHING}), true);
}
/**
* @tc.name: unlogpath
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, unlogpath, TestSize.Level1)
{
EXPECT_EQ(Command::DispatchCommands({"--logpath"}), false);
}
/**
* @tc.name: logtag
* @tc.desc:
@ -181,6 +224,16 @@ HWTEST_F(OptionDebugTest, logtag, TestSize.Level1)
LogLevelTest({"--logtag", "123", TEST_CMD_NOTHING}, DebugLogger::GetInstance()->GetLogLevel());
}
/**
* @tc.name: unlogtag
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, unlogtag, TestSize.Level1)
{
LogLevelTest({"--logtag"}, LEVEL_MUCH, false);
}
/**
* @tc.name: logDisabled
* @tc.desc:
@ -193,6 +246,18 @@ HWTEST_F(OptionDebugTest, logDisabled, TestSize.Level1)
DebugLogger::GetInstance()->Disable(false);
}
/**
* @tc.name: unlogDisabled
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(OptionDebugTest, unlogDisabled, TestSize.Level1)
{
// no log will save in log file.
LogLevelTest({"--nodebug"}, LEVEL_FATAL, false);
DebugLogger::GetInstance()->Disable(false);
}
/**
* @tc.name: hilog
* @tc.desc:

View File

@ -169,6 +169,25 @@ HWTEST_F(RegisterTest, RegisterGetName, TestSize.Level1)
EXPECT_EQ(RegisterGetName(i).empty(), false);
}
}
/**
* @tc.name: GetArchName
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(RegisterTest, GetArchName, TestSize.Level1)
{
RegisterGetSP(ArchType::ARCH_ARM);
EXPECT_STREQ(GetArchName(ArchType::ARCH_ARM).c_str(), "ARM");
RegisterGetSP(ArchType::ARCH_ARM64);
EXPECT_STREQ(GetArchName(ArchType::ARCH_ARM64).c_str(), "ARM64");
RegisterGetSP(ArchType::ARCH_X86);
EXPECT_STREQ(GetArchName(ArchType::ARCH_X86).c_str(), "X86_32");
RegisterGetSP(ArchType::ARCH_X86_64);
EXPECT_STREQ(GetArchName(ArchType::ARCH_X86_64).c_str(), "X86_64");
RegisterGetSP(ArchType::ARCH_UNKNOWN);
EXPECT_STREQ(GetArchName(ArchType::ARCH_UNKNOWN).c_str(), "Unsupport");
}
} // namespace HiPerf
} // namespace Developtools
} // namespace OHOS

View File

@ -83,7 +83,7 @@ std::unique_ptr<ReportJsonFile> ReportJsonFileTest::PrepairReportJson(
json->AddNewFunction(0, "funca1");
json->AddNewFunction(0, "funca2");
json->AddNewFunction(1, "funcb1");
json->AddNewFunction(2, "funcc1");
json->AddNewFunction(2, "funcc1"); // 2: num two
// id , pid , tid , event count
uint64_t id = 1;
uint64_t eventCount = 10;

View File

@ -205,6 +205,48 @@ HWTEST_F(SubCommandReportTest, TestOnSubCommand_i, TestSize.Level1)
EXPECT_EQ(FileCompare(stringOut, targetFile), true);
}
/**
* @tc.name: TestOnSubCommand_gzip_fail
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(SubCommandReportTest, TestOnSubCommand_gzip_fail, TestSize.Level1)
{
StdoutRecord stdoutRecord;
stdoutRecord.Start();
const auto startTime = chrono::steady_clock::now();
EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "invalid_perf.data.tar.gz"), false);
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
chrono::steady_clock::now() - startTime);
EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
std::string stringOut = stdoutRecord.Stop();
if (HasFailure()) {
printf("output:\n%s", stringOut.c_str());
}
}
/**
* @tc.name: TestOnSubCommand_gzip_fail1
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(SubCommandReportTest, TestOnSubCommand_gzip_fail1, TestSize.Level1)
{
StdoutRecord stdoutRecord;
stdoutRecord.Start();
const auto startTime = chrono::steady_clock::now();
EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "invalid_gzip_perf.data.tar.gz"), false);
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
chrono::steady_clock::now() - startTime);
EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
std::string stringOut = stdoutRecord.Stop();
if (HasFailure()) {
printf("output:\n%s", stringOut.c_str());
}
}
/**
* @tc.name: TestOnSubCommand_i1
* @tc.desc:

View File

@ -951,6 +951,83 @@ HWTEST_F(SubCommandStatTest, TestOnSubCommand_d4, TestSize.Level1)
t1.join();
}
/**
* @tc.name: TestOnSubCommand_d5
* @tc.desc: -d
* @tc.type: FUNC
*/
HWTEST_F(SubCommandStatTest, TestOnSubCommand_d5, TestSize.Level1)
{
int tid1 = 0;
std::thread t1(SubCommandStatTest::TestCodeThread, std::ref(tid1));
while (tid1 == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // 10: sleep 10ms
}
std::string cmdstr = "stat -p ";
cmdstr += std::to_string(tid1);
cmdstr += " -c 0 -d 3 --dumpoptions --per-core";
StdoutRecord stdoutRecord;
stdoutRecord.Start();
const auto startTime = chrono::steady_clock::now();
g_wait = true;
EXPECT_EQ(Command::DispatchCommand(cmdstr), true);
g_wait = false;
{
std::unique_lock<std::mutex> lock(mtx);
cv.notify_all();
}
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());
}
t1.join();
}
/**
* @tc.name: TestOnSubCommand_d6
* @tc.desc: -d
* @tc.type: FUNC
*/
HWTEST_F(SubCommandStatTest, TestOnSubCommand_d6, TestSize.Level1)
{
int tid1 = 0;
std::thread t1(SubCommandStatTest::TestCodeThread, std::ref(tid1));
while (tid1 == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // 10: sleep 10ms
}
std::string cmdstr = "stat -p ";
cmdstr += std::to_string(tid1);
cmdstr += " -c 0 -d 3 --dumpoptions --per-thread";
StdoutRecord stdoutRecord;
stdoutRecord.Start();
const auto startTime = chrono::steady_clock::now();
g_wait = true;
EXPECT_EQ(Command::DispatchCommand(cmdstr), true);
g_wait = false;
{
std::unique_lock<std::mutex> lock(mtx);
cv.notify_all();
}
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());
}
t1.join();
}
/**
* @tc.name: TestOnSubCommand_i
* @tc.desc: -i

View File

@ -79,6 +79,8 @@
<option name="push" value="testdata/perfnew.data -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/report_test.data -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/invalid_gzip_perf.data.tar.gz -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/invalid_perf.data.tar.gz -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/report_test_i.txt -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/report_test_diff.txt -> /data/test/resource/testdata/" src="res"/>
<option name="push" value="testdata/report_test_sort1.txt -> /data/test/resource/testdata/" src="res"/>

Binary file not shown.

Binary file not shown.