From 6c91acfb4bb4013ca0f9fb3311393bfb6c418243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E6=98=8C=E6=99=B6?= Date: Wed, 18 Dec 2024 15:35:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86=20Signed-o?= =?UTF-8?q?ff-by:leiguangyu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 冷昌晶 --- demo/cpp/hiperf_example_cmd.cpp | 46 +++++++++---------- .../main/js/MainAbility/pages/index/index.js | 2 +- src/perf_event_record.cpp | 6 ++- src/spe_decoder.cpp | 18 ++++---- src/symbols_file.cpp | 2 +- src/virtual_runtime.cpp | 4 +- src/virtual_thread.cpp | 3 ++ .../common/native/debug_logger_test.cpp | 4 +- test/unittest/common/native/hashlist_test.cpp | 8 ++-- .../common/native/perf_events_test.cpp | 36 +++++++-------- .../common/native/ring_buffer_test.cpp | 32 ++++++------- .../common/native/symbols_file_test.cpp | 10 ++-- 12 files changed, 89 insertions(+), 82 deletions(-) diff --git a/demo/cpp/hiperf_example_cmd.cpp b/demo/cpp/hiperf_example_cmd.cpp index 09c68d1..dbee741 100644 --- a/demo/cpp/hiperf_example_cmd.cpp +++ b/demo/cpp/hiperf_example_cmd.cpp @@ -31,8 +31,8 @@ using namespace std::chrono_literals; namespace { #define USED_FUNCTION __attribute__((__used__)) __attribute__((optnone)) -constexpr milliseconds eachStackFunRunTime = 100ms; -constexpr milliseconds msDuartion = 1000ms; +constexpr milliseconds EACH_STACK_FUN_RUN_TIME = 100ms; +constexpr milliseconds MS_DUARTION = 1000ms; const ssize_t ERRINFOLEN = 512; extern USED_FUNCTION void LoopBranch0(std::default_random_engine &rnd, int level); @@ -195,7 +195,7 @@ inline void Loop(milliseconds timeOutMS, const Option &option) USED_FUNCTION void CallStack10(int currentStack, const Option &option) { if (option.stack > 0) { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -203,11 +203,11 @@ USED_FUNCTION void CallStack9(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack10(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -215,11 +215,11 @@ USED_FUNCTION void CallStack8(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack9(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -227,11 +227,11 @@ USED_FUNCTION void CallStack7(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack8(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -239,11 +239,11 @@ USED_FUNCTION void CallStack6(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack7(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -251,11 +251,11 @@ USED_FUNCTION void CallStack5(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack6(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -263,11 +263,11 @@ USED_FUNCTION void CallStack4(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack5(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -275,11 +275,11 @@ USED_FUNCTION void CallStack3(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack4(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -287,11 +287,11 @@ USED_FUNCTION void CallStack2(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack3(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -299,11 +299,11 @@ USED_FUNCTION void CallStack1(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack2(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } @@ -311,11 +311,11 @@ USED_FUNCTION void CallStack0(int currentStack, const Option &option) { if (option.stack > 0) { if (option.dynamicStack) { - Loop(eachStackFunRunTime, option); // loop 100 ms + Loop(EACH_STACK_FUN_RUN_TIME, option); // loop 100 ms } CallStack1(currentStack - 1, option); } else { - Loop(option.second * msDuartion, option); + Loop(option.second * MS_DUARTION, option); } } diff --git a/demo/js/entry/src/main/js/MainAbility/pages/index/index.js b/demo/js/entry/src/main/js/MainAbility/pages/index/index.js index 4c8cbd2..afdf188 100644 --- a/demo/js/entry/src/main/js/MainAbility/pages/index/index.js +++ b/demo/js/entry/src/main/js/MainAbility/pages/index/index.js @@ -172,4 +172,4 @@ export default { console.info('onclick testOnclick' + this.clickTimes); this.output = this.clickTimes; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/perf_event_record.cpp b/src/perf_event_record.cpp index 5d0ed8c..e1cc68d 100644 --- a/src/perf_event_record.cpp +++ b/src/perf_event_record.cpp @@ -114,7 +114,7 @@ inline void PopFromBinary2(bool condition, uint8_t*& p, T1& v1, T2& v2, u64& siz inline void SetPointerOffset(uint8_t*& p, u64 offset, u64& size) { - HIPERF_ASSERT(offset <= size, "SetPointerOffset error\n"); + HIPERF_ASSERT(offset <= size && offset <= RECORD_SIZE_LIMIT, "SetPointerOffset error\n"); size -= offset; p += offset; } @@ -184,6 +184,10 @@ std::vector PerfRecordSample::serverPidMap_ = {}; void PerfRecordAuxtrace::Init(uint8_t* data, const perf_event_attr& attr) { + if (data == nullptr || header_.size > sizeof(perf_event_header)) { + HLOGE("Init failed"); + return; + } PerfEventRecordTemplate::Init(data); rawData_ = data + header_.size; } diff --git a/src/spe_decoder.cpp b/src/spe_decoder.cpp index c334708..01007f1 100644 --- a/src/spe_decoder.cpp +++ b/src/spe_decoder.cpp @@ -31,9 +31,9 @@ namespace Developtools { namespace HiPerf { constexpr const int UN_PRMT = -1; -const char *SpePktName(enum SpePktType type) +const std::string SpePktName(enum SpePktType type) { - const char* spePacketName; + std::string spePacketName = ""; switch (type) { case PERF_SPE_PAD: spePacketName = "PAD"; break; case PERF_SPE_END: spePacketName = "END"; break; @@ -495,10 +495,10 @@ static int SpePktDesCont(const struct SpePkt *packet, { CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); u64 payload = packet->payload; - const char *name = SpePktName(packet->type); + const std::string name = SpePktName(packet->type); int err = 0; - SpePktOutString(&err, &buf, &bufLen, "%s %d ", name, + SpePktOutString(&err, &buf, &bufLen, "%s %d ", name.c_str(), (unsigned short)payload); switch (packet->index) { @@ -524,7 +524,7 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); int idx = packet->index; unsigned long long payload = packet->payload; - const char *name = SpePktName(packet->type); + const std::string name = SpePktName(packet->type); char *bufOrig = buf; size_t blen = bufLen; int err = 0; @@ -533,7 +533,7 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, case PERF_SPE_BAD: case PERF_SPE_PAD: case PERF_SPE_END: - SpePktOutString(&err, &buf, &blen, "%s", name); + SpePktOutString(&err, &buf, &blen, "%s", name.c_str()); break; case PERF_SPE_EVENTS: err = SpePktDescEvent(packet, buf, bufLen); @@ -543,14 +543,14 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, break; case PERF_SPE_DATA_SOURCE: case PERF_SPE_TIMESTAMP: - SpePktOutString(&err, &buf, &blen, "%s %lld", name, payload); + SpePktOutString(&err, &buf, &blen, "%s %lld", name.c_str(), payload); break; case PERF_SPE_ADDRESS: err = SpePktDescAddr(packet, buf, bufLen); break; case PERF_SPE_CONTEXT: SpePktOutString(&err, &buf, &blen, "%s 0x%lx el%d", - name, (unsigned long)payload, idx + 1); + name.c_str(), (unsigned long)payload, idx + 1); break; case PERF_SPE_COUNTER: err = SpePktDesCont(packet, buf, bufLen); @@ -565,7 +565,7 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, if (err) { err = 0; SpePktOutString(&err, &bufOrig, &bufLen, "%s 0x%llx (%d)", - name, payload, packet->index); + name.c_str(), payload, packet->index); } return err; diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 3796ed9..5a7d429 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -284,7 +284,7 @@ private: uint64_t ehFrameHDRFdeCount_ {0}; uint64_t ehFrameHDRFdeTableItemSize_ {0}; uint64_t ehFrameHDRFdeTableElfOffset_ {0}; - std::shared_ptr elfFile_; + std::shared_ptr elfFile_ = nullptr; std::unordered_map info_; bool GetSectionInfo(const std::string &name, uint64_t §ionVaddr, uint64_t §ionSize, diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index 0ab5a3d..0bd910c 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -87,9 +87,9 @@ std::string VirtualRuntime::ReadThreadName(pid_t tid, bool isThread) } else if (tid == devhostPid_) { comm = DEVHOST_FILE_NAME; } else if (isThread) { - comm = ReadFileToString(StringPrintf("/proc/%d/comm", tid)).c_str(); + comm = ReadFileToString(StringPrintf("/proc/%d/comm", tid)); } else { - comm = ReadFileToString(StringPrintf("/proc/%d/cmdline", tid)).c_str(); + comm = ReadFileToString(StringPrintf("/proc/%d/cmdline", tid)); } if (comm == EMPTY_STRING) { comm = ReadFromSavedCmdLines(tid); diff --git a/src/virtual_thread.cpp b/src/virtual_thread.cpp index e9054dc..f08b765 100644 --- a/src/virtual_thread.cpp +++ b/src/virtual_thread.cpp @@ -37,6 +37,9 @@ static constexpr int MAP_PROT_EXEC_INDEX = 2; bool VirtualThread::IsSorted() const { + if (memMapsIndexs_.empty()) { + return true; + } for (std::size_t index = 1; index < memMaps_.size(); ++index) { if (memMaps_[memMapsIndexs_[index - 1]]->end > memMaps_[memMapsIndexs_[index]]->begin) { std::cout << "memMaps_ order error:\n" diff --git a/test/unittest/common/native/debug_logger_test.cpp b/test/unittest/common/native/debug_logger_test.cpp index c65cd08..4c961bc 100644 --- a/test/unittest/common/native/debug_logger_test.cpp +++ b/test/unittest/common/native/debug_logger_test.cpp @@ -218,7 +218,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"; + const std::string logTags = "DebugTest:T,DebugTest:V"; DebugLogger::GetInstance()->SetLogTags("DebugTest"); @@ -241,7 +241,7 @@ 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); + DebugLogger::GetInstance()->SetLogTags(logTags); EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_MUCH, "DebugTest"), false); EXPECT_EQ(DebugLogger::GetInstance()->ShouldLog(LEVEL_VERBOSE, "DebugTest"), true); diff --git a/test/unittest/common/native/hashlist_test.cpp b/test/unittest/common/native/hashlist_test.cpp index f126349..b660831 100644 --- a/test/unittest/common/native/hashlist_test.cpp +++ b/test/unittest/common/native/hashlist_test.cpp @@ -239,8 +239,8 @@ HWTEST_F(HashListTest, find, TestSize.Level1) HWTEST_F(HashListTest, push_front, TestSize.Level1) { HashList hashList {size_}; - constexpr std::size_t size_ {20}; - for (std::size_t curSize = 0; curSize < size_; ++curSize) { + constexpr std::size_t size {20}; + for (std::size_t curSize = 0; curSize < size; ++curSize) { hashList.push_front(curSize, curSize); std::size_t tmp = hashList.front(); EXPECT_EQ(tmp, curSize); @@ -250,8 +250,8 @@ HWTEST_F(HashListTest, push_front, TestSize.Level1) HWTEST_F(HashListTest, push_back, TestSize.Level1) { HashList hashList {size_}; - constexpr std::size_t size_ {20}; - for (std::size_t curSize = 0; curSize < size_; ++curSize) { + constexpr std::size_t size {20}; + for (std::size_t curSize = 0; curSize < size; ++curSize) { hashList.push_back(curSize, curSize); std::size_t tmp = hashList.back(); EXPECT_EQ(tmp, curSize); diff --git a/test/unittest/common/native/perf_events_test.cpp b/test/unittest/common/native/perf_events_test.cpp index 3bd8e93..a4bd939 100644 --- a/test/unittest/common/native/perf_events_test.cpp +++ b/test/unittest/common/native/perf_events_test.cpp @@ -55,8 +55,8 @@ public: static constexpr auto DEFAULT_STAT_REPORT_TIME = 500; static constexpr auto DEFAULT_SAMPLE_MMAPAGE = 256; - static uint64_t g_recordCount; - static uint64_t g_statCount; + static uint64_t gRecordCount; + static uint64_t gStatCount; }; void PerfEventsTest::SetUpTestCase() {} @@ -67,19 +67,19 @@ void PerfEventsTest::SetUp() {} void PerfEventsTest::TearDown() {} -uint64_t PerfEventsTest::g_recordCount = 0; -uint64_t PerfEventsTest::g_statCount = 0; +uint64_t PerfEventsTest::gRecordCount = 0; +uint64_t PerfEventsTest::gStatCount = 0; bool PerfEventsTest::RecordCount(PerfEventRecord& record) { - g_recordCount++; + gRecordCount++; return true; } void PerfEventsTest::StatCount( const std::map> &countEvents) { - g_statCount++; + gStatCount++; } void PerfEventsTest::TestCodeThread() @@ -193,7 +193,7 @@ HWTEST_F(PerfEventsTest, RecordNormal, TestSize.Level1) PerfEvents event; // prepare - g_recordCount = 0; + gRecordCount = 0; event.SetMmapPages(DEFAULT_SAMPLE_MMAPAGE); event.SetRecordCallBack(RecordCount); @@ -219,9 +219,9 @@ HWTEST_F(PerfEventsTest, RecordNormal, TestSize.Level1) std::this_thread::sleep_for(TEST_TIME); EXPECT_EQ(event.PauseTracking(), true); std::this_thread::sleep_for(TEST_TIME); // wait for clearing mmap buffer - uint64_t recordCount = g_recordCount; + uint64_t recordCount = gRecordCount; std::this_thread::sleep_for(TEST_TIME); - EXPECT_EQ(recordCount, g_recordCount) << "now should have no record"; + EXPECT_EQ(recordCount, gRecordCount) << "now should have no record"; EXPECT_EQ(event.ResumeTracking(), true); TestCodeThread(); std::this_thread::sleep_for(TEST_TIME); @@ -230,7 +230,7 @@ HWTEST_F(PerfEventsTest, RecordNormal, TestSize.Level1) for (std::thread &t : testThreads) { t.join(); } - ASSERT_GT(g_recordCount, recordCount) << "should have more records"; + ASSERT_GT(gRecordCount, recordCount) << "should have more records"; size_t lostSamples = 0; size_t lostNonSamples = 0; @@ -247,7 +247,7 @@ HWTEST_F(PerfEventsTest, RecordSetAll, TestSize.Level1) PerfEvents event; // prepare - g_recordCount = 0; + gRecordCount = 0; event.SetMmapPages(DEFAULT_SAMPLE_MMAPAGE); event.SetRecordCallBack(RecordCount); SetAllConfig(event); @@ -259,9 +259,9 @@ HWTEST_F(PerfEventsTest, RecordSetAll, TestSize.Level1) std::this_thread::sleep_for(TEST_TIME); EXPECT_EQ(event.PauseTracking(), true); std::this_thread::sleep_for(TEST_TIME); // wait for clearing mmap buffer - uint64_t recordCount = g_recordCount; + uint64_t recordCount = gRecordCount; std::this_thread::sleep_for(TEST_TIME); - EXPECT_EQ(recordCount, g_recordCount) << "now should have no record"; + EXPECT_EQ(recordCount, gRecordCount) << "now should have no record"; EXPECT_EQ(event.ResumeTracking(), true); TestCodeThread(); std::this_thread::sleep_for(TEST_TIME); @@ -270,7 +270,7 @@ HWTEST_F(PerfEventsTest, RecordSetAll, TestSize.Level1) for (std::thread &t : testThreads) { t.join(); } - ASSERT_GT(g_recordCount, recordCount) << "should have more records"; + ASSERT_GT(gRecordCount, recordCount) << "should have more records"; std::string stringOut = stdoutRecord.Stop(); } @@ -283,7 +283,7 @@ HWTEST_F(PerfEventsTest, StatNormal, TestSize.Level1) PerfEvents event; // prepare - g_statCount = 0; + gStatCount = 0; std::vector selectCpus_; event.SetCpu(selectCpus_); std::vector pids; @@ -305,8 +305,8 @@ HWTEST_F(PerfEventsTest, StatNormal, TestSize.Level1) std::this_thread::sleep_for(TEST_TIME); EXPECT_EQ(event.PauseTracking(), true); - EXPECT_GT(g_statCount, 0u) << "should have stats"; - uint64_t statCount = g_statCount; + EXPECT_GT(gStatCount, 0u) << "should have stats"; + uint64_t statCount = gStatCount; std::this_thread::sleep_for(TEST_TIME); EXPECT_EQ(event.ResumeTracking(), true); std::this_thread::sleep_for(TEST_TIME); @@ -315,7 +315,7 @@ HWTEST_F(PerfEventsTest, StatNormal, TestSize.Level1) for (std::thread &t : testThreads) { t.join(); } - EXPECT_GT(g_statCount, statCount) << "should have more stats"; + EXPECT_GT(gStatCount, statCount) << "should have more stats"; std::string stringOut = stdoutRecord.Stop(); } diff --git a/test/unittest/common/native/ring_buffer_test.cpp b/test/unittest/common/native/ring_buffer_test.cpp index 364c8af..9e25f66 100644 --- a/test/unittest/common/native/ring_buffer_test.cpp +++ b/test/unittest/common/native/ring_buffer_test.cpp @@ -29,10 +29,10 @@ namespace Developtools { namespace HiPerf { class RingBufferTest : public testing::Test { public: - static constexpr size_t MEGA = 1024 * 1024; - static constexpr size_t CAP = 16 * MEGA; - static constexpr size_t U8MASK = 0xFF; - static constexpr size_t MAX_TESTSIZE = 1024; + static constexpr size_t mega = 1024 * 1024; + static constexpr size_t cap = 16 * mega; + static constexpr size_t u8Mask = 0xFF; + static constexpr size_t maxTestSize = 1024; static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -61,13 +61,13 @@ void RingBufferTest::ReadBufferAndCheck(RingBuffer &buf) ASSERT_EQ(checkSize, readData.size) \ << " read data size " << readData.size << " expect data size " << checkSize; p += sizeof(perf_event_header); - uint8_t data = static_cast(checkSize & U8MASK); + uint8_t data = static_cast(checkSize & u8Mask); for (size_t i = 0; i < (checkSize - sizeof(perf_event_header)); i++) { ASSERT_EQ(*p, data) << "checkSize = " << std::hex << checkSize; p++; } checkSize++; - checkSize %= MAX_TESTSIZE; + checkSize %= maxTestSize; if (checkSize < sizeof(perf_event_header)) { checkSize = sizeof(perf_event_header); } @@ -82,14 +82,14 @@ void RingBufferTest::WriteBuffer(RingBuffer &buf) while ((p = buf.AllocForWrite(writeData.size)) != nullptr) { ASSERT_EQ(memcpy_s(p, writeData.size, &writeData, sizeof(perf_event_header)), 0); p += sizeof(perf_event_header); - uint8_t data = static_cast(writeData.size & U8MASK); + uint8_t data = static_cast(writeData.size & u8Mask); for (size_t i = 0; i < (writeData.size - sizeof(perf_event_header)); i++) { *p = data; p++; } buf.EndWrite(); writeData.size++; - writeData.size %= MAX_TESTSIZE; + writeData.size %= maxTestSize; if (writeData.size < sizeof(perf_event_header)) { writeData.size = sizeof(perf_event_header); } @@ -103,18 +103,18 @@ void RingBufferTest::WriteBuffer(RingBuffer &buf) */ HWTEST_F(RingBufferTest, Basic, TestSize.Level1) { - RingBuffer rb {CAP}; - ASSERT_TRUE(rb.GetFreeSize() == CAP) << "the buffer should be empty now"; + RingBuffer rb {cap}; + ASSERT_TRUE(rb.GetFreeSize() == cap) << "the buffer should be empty now"; WriteBuffer(rb); - ASSERT_LE(rb.GetFreeSize(), CAP); + ASSERT_LE(rb.GetFreeSize(), cap); ReadBufferAndCheck(rb); - ASSERT_TRUE(rb.GetFreeSize() == CAP) << "the buffer should be empty now"; + ASSERT_TRUE(rb.GetFreeSize() == cap) << "the buffer should be empty now"; } HWTEST_F(RingBufferTest, Wrap, TestSize.Level1) { - RingBuffer rb {CAP}; + RingBuffer rb {cap}; const __u16 maxWriteSize = 65535; perf_event_header writeData = {PERF_RECORD_MMAP, 0, maxWriteSize}; size_t half = 0; @@ -127,12 +127,12 @@ HWTEST_F(RingBufferTest, Wrap, TestSize.Level1) break; } } - ASSERT_LE(rb.GetFreeSize(), CAP); + ASSERT_LE(rb.GetFreeSize(), cap); while (rb.GetReadData() != nullptr) { rb.EndRead(); } - ASSERT_EQ(rb.GetFreeSize(), CAP); + ASSERT_EQ(rb.GetFreeSize(), cap); WriteBuffer(rb); // write_head has turned round uint8_t *tail = rb.AllocForWrite(sizeof(perf_event_header)); @@ -142,7 +142,7 @@ HWTEST_F(RingBufferTest, Wrap, TestSize.Level1) ASSERT_GE(p, tail); // reading has been ahead of writing ReadBufferAndCheck(rb); - ASSERT_TRUE(rb.GetFreeSize() == CAP) << "the buffer should be empty now"; + ASSERT_TRUE(rb.GetFreeSize() == cap) << "the buffer should be empty now"; } } // namespace HiPerf } // namespace Developtools diff --git a/test/unittest/common/native/symbols_file_test.cpp b/test/unittest/common/native/symbols_file_test.cpp index 3f56f03..b7fb119 100644 --- a/test/unittest/common/native/symbols_file_test.cpp +++ b/test/unittest/common/native/symbols_file_test.cpp @@ -646,7 +646,7 @@ HWTEST_F(SymbolsFileTest, GetBuildId, TestSize.Level1) EXPECT_EQ(symbolsFile->GetBuildId().empty(), false); } -struct sectionInfo { +struct SectionInfo { const std::string name; uint64_t addr; uint64_t size; @@ -704,7 +704,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1) 000000000000012c 0000000000000000 0 0 1 */ #ifdef __arm__ - const std::vector sectionCheckList = { + const std::vector sectionCheckList = { {".note.gnu.build-id", 0x000001c8, 0x000024, 0x0001c8}, {".text", 0x00001320, 0x000818, 0x001320}, {".eh_frame_hdr", 0x00002034, 0x0000dc, 0x002034}, @@ -713,7 +713,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1) {".strtab", 0x00000000, 0x000c3d, 0x003744}, }; #else - const std::vector sectionCheckList = { + const std::vector sectionCheckList = { {".note.gnu.build-id", 0x0000000000000358, 0x0000000000000024, 0x00000358}, {".text", 0x00000000000022f0, 0x00000000000007b5, 0x000022f0}, {".eh_frame_hdr", 0x0000000000003034, 0x00000000000000bc, 0x00003034}, @@ -722,7 +722,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1) {".strtab", 0x00000000, 0x0000000000000bbb, 0x00004a30}, }; #endif - for (sectionInfo info : sectionCheckList) { + for (SectionInfo info : sectionCheckList) { uint64_t addr; uint64_t size; uint64_t offset; @@ -731,7 +731,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1) EXPECT_EQ(size, info.size); EXPECT_EQ(offset, info.offset); if (HasFailure()) { - printf("sectionInfo check failed at '%s', %" PRIx64 ",%" PRIx64 ",%" PRIx64 "\n", + printf("SectionInfo check failed at '%s', %" PRIx64 ",%" PRIx64 ",%" PRIx64 "\n", info.name.c_str(), info.addr, info.size, info.offset); } } -- Gitee