diff options
Diffstat (limited to 'compiler-rt/lib/memprof/tests/rawprofile.cpp')
| -rw-r--r-- | compiler-rt/lib/memprof/tests/rawprofile.cpp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/compiler-rt/lib/memprof/tests/rawprofile.cpp b/compiler-rt/lib/memprof/tests/rawprofile.cpp index 829e18370737..6181d80fadf6 100644 --- a/compiler-rt/lib/memprof/tests/rawprofile.cpp +++ b/compiler-rt/lib/memprof/tests/rawprofile.cpp @@ -3,7 +3,6 @@ #include <cstdint> #include <memory> -#include "memprof/memprof_meminfoblock.h" #include "profile/MemProfData.inc" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_procmaps.h" @@ -14,13 +13,13 @@ namespace { -using ::__memprof::MemInfoBlock; using ::__memprof::MIBMapTy; using ::__memprof::SerializeToRawProfile; using ::__sanitizer::MemoryMappedSegment; using ::__sanitizer::MemoryMappingLayoutBase; using ::__sanitizer::StackDepotPut; using ::__sanitizer::StackTrace; +using ::llvm::memprof::MemInfoBlock; using ::testing::_; using ::testing::Action; using ::testing::DoAll; @@ -33,21 +32,21 @@ public: MOCK_METHOD(void, Reset, (), (override)); }; -u64 PopulateFakeMap(const MemInfoBlock &FakeMIB, uptr StackPCBegin, - MIBMapTy &FakeMap) { +uint64_t PopulateFakeMap(const MemInfoBlock &FakeMIB, uint64_t StackPCBegin, + MIBMapTy &FakeMap) { constexpr int kSize = 5; - uptr array[kSize]; + uint64_t array[kSize]; for (int i = 0; i < kSize; i++) { array[i] = StackPCBegin + i; } StackTrace St(array, kSize); - u32 Id = StackDepotPut(St); + uint32_t Id = StackDepotPut(St); InsertOrMerge(Id, FakeMIB, FakeMap); return Id; } -template <class T = u64> T Read(char *&Buffer) { +template <class T = uint64_t> T Read(char *&Buffer) { static_assert(std::is_pod<T>::value, "Must be a POD type."); assert(reinterpret_cast<size_t>(Buffer) % sizeof(T) == 0 && "Unaligned read!"); @@ -86,12 +85,12 @@ TEST(MemProf, Basic) { FakeMIB.alloc_count = 0x1; FakeMIB.total_access_count = 0x2; - u64 FakeIds[2]; + uint64_t FakeIds[2]; FakeIds[0] = PopulateFakeMap(FakeMIB, /*StackPCBegin=*/2, FakeMap); FakeIds[1] = PopulateFakeMap(FakeMIB, /*StackPCBegin=*/3, FakeMap); char *Ptr = nullptr; - u64 NumBytes = SerializeToRawProfile(FakeMap, Layout, Ptr); + uint64_t NumBytes = SerializeToRawProfile(FakeMap, Layout, Ptr); const char *Buffer = Ptr; ASSERT_GT(NumBytes, 0ULL); @@ -100,10 +99,10 @@ TEST(MemProf, Basic) { // Check the header. EXPECT_THAT(Read(Ptr), MEMPROF_RAW_MAGIC_64); EXPECT_THAT(Read(Ptr), MEMPROF_RAW_VERSION); - const u64 TotalSize = Read(Ptr); - const u64 SegmentOffset = Read(Ptr); - const u64 MIBOffset = Read(Ptr); - const u64 StackOffset = Read(Ptr); + const uint64_t TotalSize = Read(Ptr); + const uint64_t SegmentOffset = Read(Ptr); + const uint64_t MIBOffset = Read(Ptr); + const uint64_t StackOffset = Read(Ptr); // ============= Check sizes and padding. EXPECT_EQ(TotalSize, NumBytes); @@ -117,7 +116,7 @@ TEST(MemProf, Basic) { EXPECT_EQ(MIBOffset - SegmentOffset, 64ULL); EXPECT_EQ(MIBOffset, 112ULL); - // We expect 2 mib entry, 8b for the count and sizeof(u64) + + // We expect 2 mib entry, 8b for the count and sizeof(uint64_t) + // sizeof(MemInfoBlock) contains stack id + MeminfoBlock. EXPECT_EQ(StackOffset - MIBOffset, 8 + 2 * (8 + sizeof(MemInfoBlock))); @@ -129,19 +128,22 @@ TEST(MemProf, Basic) { EXPECT_GE(TotalSize - StackOffset, 8ULL + 2 * (8 + 8 + 5 * 8)); // ============= Check contents. + // The Uuid field is not yet populated on Linux-Elf by the sanitizer procmaps + // library, so we expect it to be filled with 0 for now. unsigned char ExpectedSegmentBytes[64] = { - 0x01, 0, 0, 0, 0, 0, 0, 0, // Number of entries - 0x10, 0, 0, 0, 0, 0, 0, 0, // Start - 0x20, 0, 0, 0, 0, 0, 0, 0, // End - 0x10, 0, 0, 0, 0, 0, 0, 0, // Offset - 0x0C, 0x0, 0xF, 0xF, 0xE, 0xE, // Uuid + 0x01, 0, 0, 0, 0, 0, 0, 0, // Number of entries + 0x10, 0, 0, 0, 0, 0, 0, 0, // Start + 0x20, 0, 0, 0, 0, 0, 0, 0, // End + 0x10, 0, 0, 0, 0, 0, 0, 0, // Offset + 0x0, // Uuid }; EXPECT_EQ(memcmp(Buffer + SegmentOffset, ExpectedSegmentBytes, 64), 0); // Check that the number of entries is 2. - EXPECT_EQ(*reinterpret_cast<const u64 *>(Buffer + MIBOffset), 2ULL); + EXPECT_EQ(*reinterpret_cast<const uint64_t *>(Buffer + MIBOffset), 2ULL); // Check that stack id is set. - EXPECT_EQ(*reinterpret_cast<const u64 *>(Buffer + MIBOffset + 8), FakeIds[0]); + EXPECT_EQ(*reinterpret_cast<const uint64_t *>(Buffer + MIBOffset + 8), + FakeIds[0]); // Only check a few fields of the first MemInfoBlock. unsigned char ExpectedMIBBytes[sizeof(MemInfoBlock)] = { @@ -159,9 +161,9 @@ TEST(MemProf, Basic) { 0); // Check that the number of entries is 2. - EXPECT_EQ(*reinterpret_cast<const u64 *>(Buffer + StackOffset), 2ULL); + EXPECT_EQ(*reinterpret_cast<const uint64_t *>(Buffer + StackOffset), 2ULL); // Check that the 1st stack id is set. - EXPECT_EQ(*reinterpret_cast<const u64 *>(Buffer + StackOffset + 8), + EXPECT_EQ(*reinterpret_cast<const uint64_t *>(Buffer + StackOffset + 8), FakeIds[0]); // Contents are num pcs, value of each pc - 1. unsigned char ExpectedStackBytes[2][6 * 8] = { @@ -184,7 +186,7 @@ TEST(MemProf, Basic) { // Check that the 2nd stack id is set. EXPECT_EQ( - *reinterpret_cast<const u64 *>(Buffer + StackOffset + 8 + 6 * 8 + 8), + *reinterpret_cast<const uint64_t *>(Buffer + StackOffset + 8 + 6 * 8 + 8), FakeIds[1]); EXPECT_EQ(memcmp(Buffer + StackOffset + 16 + 6 * 8 + 8, ExpectedStackBytes[1], |
