From 4cb4927a034e0bd14ae5254f4c44aaf35496db1f Mon Sep 17 00:00:00 2001 From: jiangwei Date: Thu, 28 Nov 2024 10:13:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=201.=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=A6=86=E7=9B=96=E7=8E=87;=202.?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=94=A8=E4=BE=8B=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangwei --- bundle.json | 1 + test/BUILD.gn | 5 + test/scripts/testModule/test_hitrace_cmd.py | 21 ++ test/systemtest/BUILD.gn | 24 +++ test/systemtest/hitrace_systemtest.cpp | 78 +++++++ .../hitrace_dump/hitrace_dump_test.cpp | 150 +++++++++++++- .../hitrace_meter/hitrace_ndk_test.cpp | 190 +++++------------- 7 files changed, 322 insertions(+), 147 deletions(-) create mode 100644 test/systemtest/BUILD.gn create mode 100644 test/systemtest/hitrace_systemtest.cpp diff --git a/bundle.json b/bundle.json index 38e289f..fa66476 100644 --- a/bundle.json +++ b/bundle.json @@ -106,6 +106,7 @@ } ], "test": [ + "//base/hiviewdfx/hitrace/test:hitrace_systemtest", "//base/hiviewdfx/hitrace/test:hitrace_unittest", "//base/hiviewdfx/hitrace/test:hitrace_fuzztest" ] diff --git a/test/BUILD.gn b/test/BUILD.gn index b2be1fd..a35827c 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -15,6 +15,11 @@ import("//base/hiviewdfx/hitrace/hitrace.gni") import("//build/ohos.gni") import("//build/test.gni") +group("hitrace_systemtest") { + testonly = true + deps = [ "systemtest:HitraceSystemTest" ] +} + group("hitrace_unittest") { testonly = true deps = [ diff --git a/test/scripts/testModule/test_hitrace_cmd.py b/test/scripts/testModule/test_hitrace_cmd.py index e260a43..afa0ba9 100644 --- a/test/scripts/testModule/test_hitrace_cmd.py +++ b/test/scripts/testModule/test_hitrace_cmd.py @@ -381,4 +381,25 @@ class TestHitraceCmd: for word_cmd in word_cmds3: get_shell_result(word_cmd, word_cmds3.get(word_cmd)) + @pytest.mark.L0 + def test_capture_cpu_idle(self): + word_cmds1 = { + 'hdc shell hitrace -t 5 idle': 'cpu_idle', + } + + for word_cmd in word_cmds1: + get_shell_result(word_cmd, word_cmds1.get(word_cmd)) + + @pytest.mark.L0 + def test_max_parameters_cmd(self): + hitrace_cmd = 'hdc shell hitrace -t 5' + for i in range(1, 256): + hitrace_cmd += ' app' + word_cmds1 = { + hitrace_cmd: 'error: the number of input arguments exceeds the upper limit', + } + + for word_cmd in word_cmds1: + get_shell_result(word_cmd, word_cmds1.get(word_cmd)) + diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn new file mode 100644 index 0000000..2d708ef --- /dev/null +++ b/test/systemtest/BUILD.gn @@ -0,0 +1,24 @@ +# 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. + +import("//base/hiviewdfx/hitrace/hitrace.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "hitrace/hitrace" + +ohos_systemtest("HitraceSystemTest") { + module_out_path = module_output_path + sources = [ "hitrace_systemtest.cpp" ] + external_deps = [ "googletest:gtest_main" ] +} diff --git a/test/systemtest/hitrace_systemtest.cpp b/test/systemtest/hitrace_systemtest.cpp new file mode 100644 index 0000000..befac08 --- /dev/null +++ b/test/systemtest/hitrace_systemtest.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2023 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 +#include +#include +#include + +using namespace testing::ext; +using namespace std; + +const int TIME_COUNT = 10000; +const std::string TRACING_ON_DIR = "/sys/kernel/tracing/tracing_on"; + +namespace OHOS { +namespace HiviewDFX { +class HitraceSystemTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() {} + void TearDown() {} +}; + +static bool RunCmd(const string& cmdstr) +{ + FILE *fp = popen(cmdstr.c_str(), "r"); + if (fp == nullptr) { + return false; + } + pclose(fp); + return true; +} + +static bool IsTracingOn() +{ + std::ifstream tracingOnFile(TRACING_ON_DIR); + if (!tracingOnFile.is_open()) { + std::cout << "Failed to open /sys/kernel/tracing/tracing_on." << std::endl; + return false; + } + std::string content; + getline(tracingOnFile, content); + tracingOnFile.close(); + return content == "1"; +} + +/** + * @tc.name: HitraceSystemTest_001 + * @tc.desc: when excute hitrace record function, check tracing_on switcher status + * @tc.type: FUNC + */ +HWTEST_F(HitraceSystemTest, HitraceSystemTest_001, TestSize.Level2) +{ + ASSERT_TRUE(RunCmd("hitrace --trace_finish_nodump")); + ASSERT_TRUE(RunCmd("hitrace --trace_begin ace")); + int testCnt = TIME_COUNT; + while (testCnt > 0) { + ASSERT_TRUE(IsTracingOn()) << "tracing_on switcher status is not 1"; + usleep(10); + testCnt--; + } + ASSERT_TRUE(RunCmd("hitrace --trace_finish_nodump")); +} +} // namespace HiviewDFX +} // namespace OHOS diff --git a/test/unittest/hitrace_dump/hitrace_dump_test.cpp b/test/unittest/hitrace_dump/hitrace_dump_test.cpp index 00bae37..4aa87d6 100644 --- a/test/unittest/hitrace_dump/hitrace_dump_test.cpp +++ b/test/unittest/hitrace_dump/hitrace_dump_test.cpp @@ -15,6 +15,9 @@ #include "hitrace_dump.h" #include "common_utils.h" +#include "securec.h" +#include "hilog/log.h" +#include "parameters.h" #include #include @@ -26,10 +29,12 @@ #include #include #include -#include "securec.h" - -#include "hilog/log.h" -#include "parameters.h" +#include +#include +#include +#include +#include +#include #include using namespace OHOS::HiviewDFX::Hitrace; @@ -47,7 +52,10 @@ namespace { const std::string TAG_PROP = "debug.hitrace.tags.enableflags"; const std::string DEFAULT_OUTPUT_DIR = "/data/log/hitrace/"; const std::string LOG_DIR = "/data/log/"; +const std::string TRACE_SNAPSHOT_PREFIX = "trace_"; +const std::string SAVED_EVENTS_FORMAT_PATH = DEFAULT_OUTPUT_DIR + "saved_events_format"; const int SLEEP_TIME = 10; // sleep 10ms +const int BUFFER_SIZE = 255; std::string g_traceRootPath; @@ -101,6 +109,62 @@ bool RunCmd(const string& cmdstr) return true; } +bool CountSnapShotTraceFile(int& fileCount) +{ + if (access(DEFAULT_OUTPUT_DIR.c_str(), F_OK) != 0) { + return false; + } + DIR* dirPtr = opendir(DEFAULT_OUTPUT_DIR.c_str()); + if (dirPtr == nullptr) { + HILOG_ERROR(LOG_CORE, "Failed to opendir %{public}s.", DEFAULT_OUTPUT_DIR.c_str()); + return false; + } + struct dirent* ptr = nullptr; + while ((ptr = readdir(dirPtr)) != nullptr) { + if (ptr->d_type == DT_REG) { + std::string name = std::string(ptr->d_name); + if (name.compare(0, TRACE_SNAPSHOT_PREFIX.size(), TRACE_SNAPSHOT_PREFIX) != 0) { + continue; + } + } + } + closedir(dirPtr); + return true; +} + +int HasProcessWithName(const std::string& name) +{ + std::array buffer; + std::unique_ptr pipe(popen("ps -ef", "r"), pclose); + if (!pipe) { + HILOG_ERROR(LOG_CORE, "Error: run command failed."); + return -1; + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + std::string line(buffer.data()); + size_t found = line.rfind(name); + if (found != std::string::npos && (found == line.length() - name.length() || + line[found + name.length()] == ' ')) { + return 1; + } + } + return 0; +} + +struct stat GetFileCreationTime(const std::string& filePath) +{ + struct stat fileStat; + if (stat(filePath.c_str(), &fileStat) != 0) { + HILOG_ERROR(LOG_CORE, "Error getting file status: %{public}d.", errno); + } + return fileStat; +} + +bool IsRootVersion() +{ + return OHOS::system::GetBoolParameter("const.debuggable", false); +} + class HitraceDumpTest : public testing::Test { public: static void SetUpTestCase(void); @@ -353,6 +417,25 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_007, TestSize.Level0) ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); } +/** + * @tc.name: DumpTraceTest_008 + * @tc.desc: Test Test DumpTrace(int maxDuration) for check process is recycled. + * @tc.type: FUNC + */ +HWTEST_F(HitraceDumpTest, DumpTraceTest_008, TestSize.Level0) +{ + const std::vector tagGroups = {"default"}; + ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS); + for (int i = 0; i < 10; i++) { + int maxDuration = 1; + TraceRetInfo ret = DumpTrace(maxDuration); + ASSERT_TRUE(ret.errorCode == TraceErrorCode::SUCCESS); + sleep(1); + ASSERT_TRUE(HasProcessWithName("HitraceDump") == 0); + } + ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); +} + /** * @tc.name: DumpForServiceMode_001 * @tc.desc: The correct usage of grasping trace in SERVICE_MODE. @@ -485,6 +568,45 @@ HWTEST_F(HitraceDumpTest, DumpForServiceMode_006, TestSize.Level0) ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); } +/** + * @tc.name: DumpForServiceMode_007 + * @tc.desc: File aging and deletion function in SERVICE_MODE with commerical version. + * @tc.type: FUNC + */ +HWTEST_F(HitraceDumpTest, DumpForServiceMode_007, TestSize.Level0) +{ + const std::vector tagGroups = {"default"}; + ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS); + int fileCount = 0; + for (int i = 0; i < 25; i++) { + TraceRetInfo ret = DumpTrace(); + ASSERT_TRUE(ret.errorCode == TraceErrorCode::SUCCESS); + sleep(1); + } + if (!IsRootVersion()) { + ASSERT_TRUE(CountSnapShotTraceFile(fileCount)); + ASSERT_TRUE(fileCount > 0 && fileCount <= 20); + } + ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); +} + +/** + * @tc.name: DumpForServiceMode_008 + * @tc.desc: Test TRACE_IS_OCCUPIED. + * @tc.type: FUNC + */ +HWTEST_F(HitraceDumpTest, DumpForServiceMode_008, TestSize.Level0) +{ + const std::vector tagGroups = {"scene_performance"}; + ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS); + + SetSysInitParamTags(123); + OHOS::system::SetParameter("debug.hitrace.tags.enableflags", std::to_string(0)); + ASSERT_TRUE(DumpTrace().errorCode == TraceErrorCode::TRACE_IS_OCCUPIED); + + ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); +} + /** * @tc.name: DumpForCmdMode_001 * @tc.desc: The correct usage of grasping trace in CMD_MODE. @@ -738,6 +860,26 @@ HWTEST_F(HitraceDumpTest, DumpForCmdMode_011, TestSize.Level0) ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); } +/** + * @tc.name: DumpForCmdMode_012 + * @tc.desc: Test saved_events_format regenerate. + * @tc.type: FUNC + */ +HWTEST_F(HitraceDumpTest, DumpForCmdMode_012, TestSize.Level0) +{ + std::string args = "tags: sched clockType: boot bufferSize:1024 overwrite: 1"; + struct stat beforeStat = GetFileCreationTime(SAVED_EVENTS_FORMAT_PATH); + ASSERT_TRUE(OpenTrace(args) == TraceErrorCode::SUCCESS); + ASSERT_TRUE(DumpTraceOn() == TraceErrorCode::SUCCESS); + sleep(1); + TraceRetInfo ret = DumpTraceOff(); + ASSERT_TRUE(ret.errorCode == TraceErrorCode::SUCCESS); + ASSERT_TRUE(ret.outputFiles.size() > 0); + struct stat afterStat = GetFileCreationTime(SAVED_EVENTS_FORMAT_PATH); + ASSERT_TRUE(afterStat.st_ctime != beforeStat.st_ctime); + ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS); +} + /** * @tc.name: ParammeterCheck_001 * @tc.desc: Check parameter after interface call. diff --git a/test/unittest/hitrace_meter/hitrace_ndk_test.cpp b/test/unittest/hitrace_meter/hitrace_ndk_test.cpp index f648cdf..50cf1b4 100644 --- a/test/unittest/hitrace_meter/hitrace_ndk_test.cpp +++ b/test/unittest/hitrace_meter/hitrace_ndk_test.cpp @@ -357,26 +357,6 @@ bool RunCmd(const string& cmdstr) return true; } -/** - * @tc.name: HiTraceNDKTest_StartTrace_001 - * @tc.desc: tracing_mark_write file node normal output start tracing and end tracing. - * @tc.type: FUNC - */ -HWTEST_F(HitraceNDKTest, StartTrace_001, TestSize.Level0) -{ - std::string traceName = "HitraceStartTrace001"; - ASSERT_TRUE(CleanTrace()); - ASSERT_TRUE(SetFtrace(TRACING_ON, true)) << "Hitrace Setting tracing_on failed."; - StartTrace(TAG, traceName); - FinishTrace(TAG); - ASSERT_TRUE(SetFtrace(TRACING_ON, false)) << "Hitrace Setting tracing_on failed."; - vector list = ReadTrace(); - bool isStartSuc = GetTraceResult('B', traceName, nullptr, 0, list); - ASSERT_TRUE(isStartSuc) << "Hitrace Can't find \"B|pid|" + traceName + "\" from trace."; - bool isFinishSuc = GetTraceResult('E', traceName, nullptr, 0, list); - ASSERT_TRUE(isFinishSuc) << "Hitrace Can't find \"E|\" from trace."; -} - /** * @tc.name: HiTraceNDKTest_AddHitraceMeterMarker_001 * @tc.desc: Testing AddHitraceMeterMarker function @@ -768,6 +748,26 @@ HWTEST_F(HitraceNDKTest, StartAsyncHiTraceIdTest_001, TestSize.Level0) ASSERT_TRUE(isFinishSuc) << "Hitrace Can't find \"F|pid|\" from trace."; } +/** + * @tc.name: HiTraceNDKTest_StartTrace_001 + * @tc.desc: tracing_mark_write file node normal output start tracing and end tracing. + * @tc.type: FUNC + */ +HWTEST_F(HitraceNDKTest, StartTrace_001, TestSize.Level0) +{ + std::string traceName = "HitraceStartTrace001"; + ASSERT_TRUE(CleanTrace()); + ASSERT_TRUE(SetFtrace(TRACING_ON, true)) << "Hitrace Setting tracing_on failed."; + StartTrace(TAG, traceName); + FinishTrace(TAG); + ASSERT_TRUE(SetFtrace(TRACING_ON, false)) << "Hitrace Setting tracing_on failed."; + vector list = ReadTrace(); + bool isStartSuc = GetTraceResult('B', traceName, nullptr, 0, list); + ASSERT_TRUE(isStartSuc) << "Hitrace Can't find \"B|pid|" + traceName + "\" from trace."; + bool isFinishSuc = GetTraceResult('E', traceName, nullptr, 0, list); + ASSERT_TRUE(isFinishSuc) << "Hitrace Can't find \"E|\" from trace."; +} + /** * @tc.name: HiTraceNDKTest_StartTrace_002 * @tc.desc: tracing_mark_write file node has no output. @@ -1131,26 +1131,6 @@ HWTEST_F(HitraceNDKTest, StartTrace_020, TestSize.Level1) SetTraceDisabled(false); } -/** - * @tc.name: HiTraceNDKTest_StartTraceWrapper_001 - * @tc.desc: Testing StartTraceWrapper function - * @tc.type: FUNC - */ -HWTEST_F(HitraceNDKTest, StartTraceWrapper_001, TestSize.Level0) -{ - string traceName = "StartTraceWrapper001"; - ASSERT_TRUE(CleanTrace()); - ASSERT_TRUE(SetFtrace(TRACING_ON, true)) << "Setting tracing_on failed."; - StartTraceWrapper(TAG, traceName.c_str()); - FinishTrace(TAG); - ASSERT_TRUE(SetFtrace(TRACING_ON, false)) << "Setting tracing_on failed."; - vector list = ReadTrace(); - bool isStartSuc = GetTraceResult('B', traceName, nullptr, 0, list); - ASSERT_TRUE(isStartSuc) << "Hitrace Can't find \"B|pid|" + traceName + "\" from trace."; - bool isFinishSuc = GetTraceResult('E', traceName, nullptr, 0, list); - ASSERT_TRUE(isFinishSuc) << "Hitrace Can't find \"E|\" from trace."; -} - /** * @tc.name: HiTraceNDKTest_StartAsyncTraceWrapper * @tc.desc: Testing StartAsyncTraceWrapper function @@ -1172,6 +1152,26 @@ HWTEST_F(HitraceNDKTest, StartAsyncTraceWrapper_001, TestSize.Level1) EXPECT_FALSE(isFinishSuc) << "Hitrace Can't find \"F|pid|" + traceName + "\" from trace."; } +/** + * @tc.name: HiTraceNDKTest_StartTraceWrapper_001 + * @tc.desc: Testing StartTraceWrapper function + * @tc.type: FUNC + */ +HWTEST_F(HitraceNDKTest, StartTraceWrapper_001, TestSize.Level0) +{ + string traceName = "StartTraceWrapper001"; + ASSERT_TRUE(CleanTrace()); + ASSERT_TRUE(SetFtrace(TRACING_ON, true)) << "Setting tracing_on failed."; + StartTraceWrapper(TAG, traceName.c_str()); + FinishTrace(TAG); + ASSERT_TRUE(SetFtrace(TRACING_ON, false)) << "Setting tracing_on failed."; + vector list = ReadTrace(); + bool isStartSuc = GetTraceResult('B', traceName, nullptr, 0, list); + ASSERT_TRUE(isStartSuc) << "Hitrace Can't find \"B|pid|" + traceName + "\" from trace."; + bool isFinishSuc = GetTraceResult('E', traceName, nullptr, 0, list); + ASSERT_TRUE(isFinishSuc) << "Hitrace Can't find \"E|\" from trace."; +} + /** * @tc.name: HiTraceNDKTest_CountTraceWrapper_001 * @tc.desc: Testing CountTraceWrapper function @@ -1234,106 +1234,10 @@ HWTEST_F(HitraceNDKTest, StartTrace_023, TestSize.Level1) /** * @tc.name: HiTraceNDKTest_StartTrace_024 - * @tc.desc: Testing trace cmd function - * @tc.type: FUNC - */ -HWTEST_F(HitraceNDKTest, StartTrace_024, TestSize.Level1) -{ - ASSERT_TRUE(CleanTrace()); - ASSERT_TRUE(RunCmd("hitrace -h > /data/local/tmp/test1.txt")); - ASSERT_TRUE(RunCmd("hitrace -l > /data/local/tmp/test2.txt")); - ASSERT_TRUE(RunCmd("hitrace --list_categories > /data/local/tmp/test3.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_begin > /data/local/tmp/test4.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_dump > /data/local/tmp/test5.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_finish > /data/local/tmp/test6.txt")); - ASSERT_TRUE(RunCmd("hitrace --hlep > /data/local/tmp/test7.txt")); - ASSERT_TRUE(RunCmd("hitrace -a > /data/local/tmp/test8.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_clock > /data/local/tmp/test9.txt")); - ASSERT_TRUE(RunCmd("hitrace -t a > /data/local/tmp/test10.txt")); - ASSERT_TRUE(RunCmd("hitrace -t -1 > /data/local/tmp/test11.txt")); - ASSERT_TRUE(RunCmd("hitrace --time a > /data/local/tmp/test12.txt")); - ASSERT_TRUE(RunCmd("hitrace --time -1 > /data/local/tmp/test13.txt")); - ASSERT_TRUE(RunCmd("hitrace -b a > /data/local/tmp/test14.txt")); - ASSERT_TRUE(RunCmd("hitrace -b -1 > /data/local/tmp/test15.txt")); - ASSERT_TRUE(RunCmd("hitrace --buffer_size a > /data/local/tmp/test16.txt")); - ASSERT_TRUE(RunCmd("hitrace --buffer_size -1 > /data/local/tmp/test17.txt")); - ASSERT_TRUE(RunCmd("hitrace -z --time 1 --buffer_size 10240 --trace_clock clock ohos > /data/local/tmp/trace01")); - ASSERT_TRUE(RunCmd("hitrace -z -t 1 -b 10240 --trace_clock clock --overwrite ohos > /data/local/tmp/trace02")); - ASSERT_TRUE(RunCmd("hitrace -t 1 --trace_clock boot ohos > /data/local/tmp/trace03")); - ASSERT_TRUE(RunCmd("hitrace -t 1 --trace_clock global ohos > /data/local/tmp/trace04")); - ASSERT_TRUE(RunCmd("hitrace -t 1 --trace_clock mono ohos > /data/local/tmp/trace05")); - ASSERT_TRUE(RunCmd("hitrace -t 1 --trace_clock uptime ohos > /data/local/tmp/trace06")); - ASSERT_TRUE(RunCmd("hitrace -t 1 --trace_clock perf ohos > /data/local/tmp/trace07")); - ASSERT_TRUE(RunCmd("hitrace -b 2048 -t 10 -o /data/local/tmp/test20.txt sched")); - ASSERT_TRUE(RunCmd("hitrace -b 2048 -t 10 -o /data/local/tmp/test21 load")); - ASSERT_TRUE(RunCmd("hitrace --trace_begin --record app > /data/local/tmp/test22.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_finish --record > /data/local/tmp/test23.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_begin --record app --file_size 10240 > /data/local/tmp/test24.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_begin --record app --file_size 102400 > /data/local/tmp/test25.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_finish --record > /data/local/tmp/test26.txt")); - ASSERT_TRUE(RunCmd("hitrace --start_bgsrv > /data/local/tmp/test27.txt")); - ASSERT_TRUE(RunCmd("hitrace --dump_bgsrv > /data/local/tmp/test28.txt")); - ASSERT_TRUE(RunCmd("hitrace --stop_bgsrv > /data/local/tmp/test29.txt")); - ASSERT_TRUE(RunCmd("hitrace -t 3 -b 10240 --text app --output /data/local/tmp/trace.txt")); - ASSERT_TRUE(RunCmd("hitrace -t 3 -b 10240 --raw app > /data/local/tmp/test30.txt")); - ASSERT_TRUE(RunCmd("hitrace -t 3 -b 10240 --raw app --file_size 102400 > /data/local/tmp/test31.txt")); - ASSERT_TRUE(RunCmd("hitrace --trace_finish_nodump > /data/local/tmp/test3.txt")); -} - -/** - * @tc.name: HiTraceNDKTest_StartTrace_025 - * @tc.desc: Testing bytrace cmd function - * @tc.type: FUNC - */ -HWTEST_F(HitraceNDKTest, StartTrace_025, TestSize.Level1) -{ - ASSERT_TRUE(CleanTrace()); - ASSERT_TRUE(RunCmd("bytrace -h > /data/local/tmp/test1.txt")); - ASSERT_TRUE(RunCmd("bytrace -l > /data/local/tmp/test2.txt")); - ASSERT_TRUE(RunCmd("bytrace --list_categories > /data/local/tmp/test3.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_begin > /data/local/tmp/test4.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_dump > /data/local/tmp/test5.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_finish > /data/local/tmp/test6.txt")); - ASSERT_TRUE(RunCmd("bytrace --hlep > /data/local/tmp/test7.txt")); - ASSERT_TRUE(RunCmd("bytrace -a > /data/local/tmp/test8.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_clock > /data/local/tmp/test9.txt")); - ASSERT_TRUE(RunCmd("bytrace -t a > /data/local/tmp/test10.txt")); - ASSERT_TRUE(RunCmd("bytrace -t -1 > /data/local/tmp/test11.txt")); - ASSERT_TRUE(RunCmd("bytrace --time a > /data/local/tmp/test12.txt")); - ASSERT_TRUE(RunCmd("bytrace --time -1 > /data/local/tmp/test13.txt")); - ASSERT_TRUE(RunCmd("bytrace -b a > /data/local/tmp/test14.txt")); - ASSERT_TRUE(RunCmd("bytrace -b -1 > /data/local/tmp/test15.txt")); - ASSERT_TRUE(RunCmd("bytrace --buffer_size a > /data/local/tmp/test16.txt")); - ASSERT_TRUE(RunCmd("bytrace --buffer_size -1 > /data/local/tmp/test17.txt")); - ASSERT_TRUE(RunCmd("bytrace -z --time 1 --buffer_size 10240 --trace_clock clock ohos > /data/local/tmp/trace01")); - ASSERT_TRUE(RunCmd("bytrace -z -t 1 -b 10240 --trace_clock clock --overwrite ohos > /data/local/tmp/trace02")); - ASSERT_TRUE(RunCmd("bytrace -t 1 --trace_clock boot ohos > /data/local/tmp/trace03")); - ASSERT_TRUE(RunCmd("bytrace -t 1 --trace_clock global ohos > /data/local/tmp/trace04")); - ASSERT_TRUE(RunCmd("bytrace -t 1 --trace_clock mono ohos > /data/local/tmp/trace05")); - ASSERT_TRUE(RunCmd("bytrace -t 1 --trace_clock uptime ohos > /data/local/tmp/trace06")); - ASSERT_TRUE(RunCmd("bytrace -t 1 --trace_clock perf ohos > /data/local/tmp/trace07")); - ASSERT_TRUE(RunCmd("bytrace -b 2048 -t 10 -o /data/local/tmp/test20.txt sched")); - ASSERT_TRUE(RunCmd("bytrace -b 2048 -t 10 -o /data/local/tmp/test21 load")); - ASSERT_TRUE(RunCmd("bytrace --trace_begin --record app > /data/local/tmp/test22.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_finish --record > /data/local/tmp/test23.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_begin --record app --file_size 10240 > /data/local/tmp/test24.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_begin --record app --file_size 102400 > /data/local/tmp/test25.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_finish --record > /data/local/tmp/test26.txt")); - ASSERT_TRUE(RunCmd("bytrace --start_bgsrv > /data/local/tmp/test27.txt")); - ASSERT_TRUE(RunCmd("bytrace --dump_bgsrv > /data/local/tmp/test28.txt")); - ASSERT_TRUE(RunCmd("bytrace --stop_bgsrv > /data/local/tmp/test29.txt")); - ASSERT_TRUE(RunCmd("bytrace -t 3 -b 10240 --text app --output /data/local/tmp/trace.txt")); - ASSERT_TRUE(RunCmd("bytrace -t 3 -b 10240 --raw app > /data/local/tmp/test30.txt")); - ASSERT_TRUE(RunCmd("bytrace -t 3 -b 10240 --raw app --file_size 102400 > /data/local/tmp/test31.txt")); - ASSERT_TRUE(RunCmd("bytrace --trace_finish_nodump > /data/local/tmp/test3.txt")); -} - -/** - * @tc.name: HiTraceNDKTest_StartTrace_026 * @tc.desc: Testing IsTagEnabled * @tc.type: FUNC */ -HWTEST_F(HitraceNDKTest, StartTrace_026, TestSize.Level1) +HWTEST_F(HitraceNDKTest, StartTrace_024, TestSize.Level1) { const std::string keyTraceTag = "debug.hitrace.tags.enableflags"; ASSERT_TRUE(SetProperty(keyTraceTag, std::to_string(HITRACE_TAG_USB | HITRACE_TAG_HDF))); @@ -1345,11 +1249,11 @@ HWTEST_F(HitraceNDKTest, StartTrace_026, TestSize.Level1) } /** - * @tc.name: HiTraceNDKTest_StartTrace_027 + * @tc.name: HiTraceNDKTest_StartTrace_025 * @tc.desc: Testing IsTagEnabled with multiple tags * @tc.type: FUNC */ -HWTEST_F(HitraceNDKTest, StartTrace_027, TestSize.Level1) +HWTEST_F(HitraceNDKTest, StartTrace_025, TestSize.Level1) { const std::string keyTraceTag = "debug.hitrace.tags.enableflags"; ASSERT_TRUE(SetProperty(keyTraceTag, std::to_string(HITRACE_TAG_ZIMAGE | HITRACE_TAG_HDF | HITRACE_TAG_ZAUDIO))); @@ -1361,11 +1265,11 @@ HWTEST_F(HitraceNDKTest, StartTrace_027, TestSize.Level1) } /** - * @tc.name: HiTraceNDKTest_StartTrace_028 + * @tc.name: HiTraceNDKTest_StartTrace_026 * @tc.desc: tracing_mark_write file node general output start and end tracing for debugging. * @tc.type: FUNC */ -HWTEST_F(HitraceNDKTest, StartTrace_028, TestSize.Level1) +HWTEST_F(HitraceNDKTest, StartTrace_026, TestSize.Level1) { ASSERT_TRUE(CleanTrace()); ASSERT_TRUE(SetFtrace(TRACING_ON, true)) << "Setting tracing_on failed."; @@ -1374,11 +1278,11 @@ HWTEST_F(HitraceNDKTest, StartTrace_028, TestSize.Level1) } /** - * @tc.name: HiTraceNDKTest_StartTrace_029 + * @tc.name: HiTraceNDKTest_StartTrace_027 * @tc.desc: tracing_mark_write file node normal output start trace and end trace async with args * @tc.type: FUNC */ -HWTEST_F(HitraceNDKTest, StartTrace_029, TestSize.Level1) +HWTEST_F(HitraceNDKTest, StartTrace_027, TestSize.Level1) { string traceName = "asyncTraceTest029-%d"; int taskId = 123; -- Gitee