diff options
Diffstat (limited to 'llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp index 0ca24c716d1..9ff37e93b15 100644 --- a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp +++ b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp @@ -11,12 +11,14 @@ #include "llvm/ADT/SmallBitVector.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" +#include "llvm/DebugInfo/CodeView/RandomAccessTypeVisitor.h" +#include "llvm/DebugInfo/CodeView/TypeDeserializer.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" #include "llvm/DebugInfo/CodeView/TypeRecordMapping.h" #include "llvm/DebugInfo/CodeView/TypeSerializer.h" #include "llvm/DebugInfo/CodeView/TypeServerHandler.h" #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h" +#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h" #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" #include "llvm/DebugInfo/PDB/Native/RawTypes.h" #include "llvm/Support/Allocator.h" @@ -128,16 +130,20 @@ public: void SetUp() override { TestState = llvm::make_unique<PerTestState>(); + + TestState->Pipeline.addCallbackToPipeline(TestState->Deserializer); + TestState->Pipeline.addCallbackToPipeline(TestState->Callbacks); } void TearDown() override { TestState.reset(); } protected: - bool ValidateDatabaseRecord(LazyRandomTypeCollection &Types, uint32_t Index) { + bool ValidateDatabaseRecord(const RandomAccessTypeVisitor &Visitor, + uint32_t Index) { TypeIndex TI = TypeIndex::fromArrayIndex(Index); - if (!Types.contains(TI)) + if (!Visitor.database().contains(TI)) return false; - if (GlobalState->TypeVector[Index] != Types.getType(TI)) + if (GlobalState->TypeVector[Index] != Visitor.database().getTypeRecord(TI)) return false; return true; } @@ -178,6 +184,8 @@ protected: struct PerTestState { FixedStreamArray<TypeIndexOffset> Offsets; + TypeVisitorCallbackPipeline Pipeline; + TypeDeserializer Deserializer; MockCallbacks Callbacks; }; @@ -210,22 +218,21 @@ std::unique_ptr<RandomAccessVisitorTest::GlobalTestState> TEST_F(RandomAccessVisitorTest, MultipleVisits) { TestState->Offsets = createPartialOffsets(GlobalState->Stream, {0, 8}); - LazyRandomTypeCollection Types(GlobalState->TypeArray, - GlobalState->TypeVector.size(), - TestState->Offsets); + RandomAccessTypeVisitor Visitor(GlobalState->TypeArray, + GlobalState->TypeVector.size(), + TestState->Offsets); std::vector<uint32_t> IndicesToVisit = {5, 5, 5}; for (uint32_t I : IndicesToVisit) { TypeIndex TI = TypeIndex::fromArrayIndex(I); - CVType T = Types.getType(TI); - EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks)); + EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline)); } // [0,8) should be present - EXPECT_EQ(8u, Types.size()); + EXPECT_EQ(8u, Visitor.database().size()); for (uint32_t I = 0; I < 8; ++I) - EXPECT_TRUE(ValidateDatabaseRecord(Types, I)); + EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I)); // 5, 5, 5 EXPECT_EQ(3u, TestState->Callbacks.count()); @@ -241,19 +248,19 @@ TEST_F(RandomAccessVisitorTest, DescendingWithinChunk) { std::vector<uint32_t> IndicesToVisit = {7, 4, 2}; - LazyRandomTypeCollection Types(GlobalState->TypeArray, - GlobalState->TypeVector.size(), - TestState->Offsets); + RandomAccessTypeVisitor Visitor(GlobalState->TypeArray, + GlobalState->TypeVector.size(), + TestState->Offsets); + for (uint32_t I : IndicesToVisit) { TypeIndex TI = TypeIndex::fromArrayIndex(I); - CVType T = Types.getType(TI); - EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks)); + EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline)); } // [0, 7] - EXPECT_EQ(8u, Types.size()); + EXPECT_EQ(8u, Visitor.database().size()); for (uint32_t I = 0; I < 8; ++I) - EXPECT_TRUE(ValidateDatabaseRecord(Types, I)); + EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I)); // 2, 4, 7 EXPECT_EQ(3u, TestState->Callbacks.count()); @@ -269,19 +276,19 @@ TEST_F(RandomAccessVisitorTest, AscendingWithinChunk) { std::vector<uint32_t> IndicesToVisit = {2, 4, 7}; - LazyRandomTypeCollection Types(GlobalState->TypeArray, - GlobalState->TypeVector.size(), - TestState->Offsets); + RandomAccessTypeVisitor Visitor(GlobalState->TypeArray, + GlobalState->TypeVector.size(), + TestState->Offsets); + for (uint32_t I : IndicesToVisit) { TypeIndex TI = TypeIndex::fromArrayIndex(I); - CVType T = Types.getType(TI); - EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks)); + EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline)); } // [0, 7] - EXPECT_EQ(8u, Types.size()); + EXPECT_EQ(8u, Visitor.database().size()); for (uint32_t I = 0; I < 8; ++I) - EXPECT_TRUE(ValidateDatabaseRecord(Types, I)); + EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I)); // 2, 4, 7 EXPECT_EQ(3u, TestState->Callbacks.count()); @@ -298,20 +305,19 @@ TEST_F(RandomAccessVisitorTest, StopPrematurelyInChunk) { std::vector<uint32_t> IndicesToVisit = {0, 1, 2}; - LazyRandomTypeCollection Types(GlobalState->TypeArray, - GlobalState->TypeVector.size(), - TestState->Offsets); + RandomAccessTypeVisitor Visitor(GlobalState->TypeArray, + GlobalState->TypeVector.size(), + TestState->Offsets); for (uint32_t I : IndicesToVisit) { TypeIndex TI = TypeIndex::fromArrayIndex(I); - CVType T = Types.getType(TI); - EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks)); + EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline)); } // [0, 8) should be visited. - EXPECT_EQ(8u, Types.size()); + EXPECT_EQ(8u, Visitor.database().size()); for (uint32_t I = 0; I < 8; ++I) - EXPECT_TRUE(ValidateDatabaseRecord(Types, I)); + EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I)); // [0, 2] EXPECT_EQ(3u, TestState->Callbacks.count()); @@ -327,20 +333,19 @@ TEST_F(RandomAccessVisitorTest, InnerChunk) { std::vector<uint32_t> IndicesToVisit = {5, 7}; - LazyRandomTypeCollection Types(GlobalState->TypeArray, - GlobalState->TypeVector.size(), - TestState->Offsets); + RandomAccessTypeVisitor Visitor(GlobalState->TypeArray, + GlobalState->TypeVector.size(), + TestState->Offsets); for (uint32_t I : IndicesToVisit) { TypeIndex TI = TypeIndex::fromArrayIndex(I); - CVType T = Types.getType(TI); - EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks)); + EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline)); } // [4, 9) - EXPECT_EQ(5u, Types.size()); + EXPECT_EQ(5u, Visitor.database().size()); for (uint32_t I = 4; I < 9; ++I) - EXPECT_TRUE(ValidateDatabaseRecord(Types, I)); + EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I)); // 5, 7 EXPECT_EQ(2u, TestState->Callbacks.count()); |