diff options
author | Zachary Turner <zturner@google.com> | 2017-08-02 22:31:39 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-08-02 22:31:39 +0000 |
commit | 9fb9d71d3e6a0515cb0ad416bc4400d47801888a (patch) | |
tree | f638998635c8f45b950a441be478e14b12b34c87 /llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp | |
parent | 018338e503880ac56457692ad2dee3c38945d629 (diff) | |
download | bcm5719-llvm-9fb9d71d3e6a0515cb0ad416bc4400d47801888a.tar.gz bcm5719-llvm-9fb9d71d3e6a0515cb0ad416bc4400d47801888a.zip |
[pdb/lld] Write a valid FPM.
The PDB reserves certain blocks for the FPM that describe which
blocks in the file are allocated and which are free. We weren't
filling that out at all, and in some cases we were even stomping
it with incorrect data. This patch writes a correct FPM.
Differential Revision: https://reviews.llvm.org/D36235
llvm-svn: 309896
Diffstat (limited to 'llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp b/llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp index 4791c982fd8..a91ac8d443f 100644 --- a/llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp +++ b/llvm/unittests/DebugInfo/MSF/MSFBuilderTest.cpp @@ -11,10 +11,13 @@ #include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/Testing/Support/Error.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" using namespace llvm; using namespace llvm::msf; +using namespace testing; namespace { class MSFBuilderTest : public testing::Test { @@ -359,3 +362,36 @@ TEST_F(MSFBuilderTest, DirectoryBlockHintOverestimated) { EXPECT_EQ(1U, L.DirectoryBlocks.size()); EXPECT_EQ(B + 1, L.DirectoryBlocks[0]); } + +TEST_F(MSFBuilderTest, StreamDoesntUseFpmBlocks) { + Expected<MSFBuilder> ExpectedMsf = MSFBuilder::create(Allocator, 4096); + ASSERT_THAT_EXPECTED(ExpectedMsf, Succeeded()); + auto &Msf = *ExpectedMsf; + + // A block is 4096 bytes, and every 4096 blocks we have 2 reserved FPM blocks. + // By creating add a stream that spans 4096*4096*3 bytes, we ensure that we + // cross over a couple of reserved FPM blocks, and that none of them are + // allocated to the stream. + constexpr uint32_t StreamSize = 4096 * 4096 * 3; + Expected<uint32_t> SN = Msf.addStream(StreamSize); + ASSERT_THAT_EXPECTED(SN, Succeeded()); + + auto ExpectedLayout = Msf.build(); + ASSERT_THAT_EXPECTED(ExpectedLayout, Succeeded()); + MSFLayout &L = *ExpectedLayout; + auto BlocksRef = L.StreamMap[*SN]; + std::vector<uint32_t> Blocks(BlocksRef.begin(), BlocksRef.end()); + EXPECT_EQ(StreamSize, L.StreamSizes[*SN]); + + for (uint32_t I = 0; I <= 3; ++I) { + // Pages from the regular FPM are allocated, while pages from the alt fpm + // are free. + EXPECT_FALSE(L.FreePageMap.test(1 + I * 4096)); + EXPECT_TRUE(L.FreePageMap.test(2 + I * 4096)); + } + + for (uint32_t I = 1; I <= 3; ++I) { + EXPECT_THAT(Blocks, Not(Contains(1 + I * 4096))); + EXPECT_THAT(Blocks, Not(Contains(2 + I * 4096))); + } +} |