From b38492152d3bf7e6fa2d30dec79f8c765125a7c0 Mon Sep 17 00:00:00 2001 From: buzhenwang Date: Fri, 1 Aug 2025 17:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0GetConfigName=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20Signed-off-by:leiguangyu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: buzhenwang --- include/report.h | 6 ++++++ test/unittest/common/native/report_test.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/report.h b/include/report.h index 780bcaf..ae7f0e0 100644 --- a/include/report.h +++ b/include/report.h @@ -503,6 +503,12 @@ public: virtual ~Report() {} std::map configIdIndexMaps_; // index of configNames_ + std::string GetConfigName(uint64_t id) + { + size_t index = GetConfigIndex(id); + HIPERF_ASSERT(index < configs_.size(), "unable found config index %zu\n", index); + return configs_[index].eventName_; + } size_t GetConfigIndex(uint64_t id) { diff --git a/test/unittest/common/native/report_test.cpp b/test/unittest/common/native/report_test.cpp index 33f4a43..6475bd0 100644 --- a/test/unittest/common/native/report_test.cpp +++ b/test/unittest/common/native/report_test.cpp @@ -829,6 +829,20 @@ HWTEST_F(ReportTest, PrepareConsole, TestSize.Level1) EXPECT_EQ(report_->consoleWidth_, report_->ConsoleDefaultWidth); } } + +HWTEST_F(ReportTest, OverConfigIndex, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_NE(pid, -1); + + if (pid == 0) { + report_->configIdIndexMaps_.emplace(1000u, 1000u); + report_->GetConfigName(1000); + _exit(-2); + } else { + printf("exit.\n"); + } +} } // namespace HiPerf } // namespace Developtools } // namespace OHOS -- Gitee