diff options
author | Zachary Turner <zturner@google.com> | 2018-01-05 18:12:14 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-01-05 18:12:14 +0000 |
commit | de6a487d7027c8f0d9df74b806a3bc777b4f6f77 (patch) | |
tree | febf6295879a6815184793a87fc66a0c1de8cb91 /llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp | |
parent | 08e52bc80195f5e1a3369ad46d09cefb066f0eb3 (diff) | |
download | bcm5719-llvm-de6a487d7027c8f0d9df74b806a3bc777b4f6f77.tar.gz bcm5719-llvm-de6a487d7027c8f0d9df74b806a3bc777b4f6f77.zip |
[MSF] Fix FPM interval calcluation
We have some code to try to determine how many pieces an MSF
Free Page Map is split into, and this code had an off by one
error which would cause the calculation to be incorrect when
there were exactly 4096*k + 1 blocks in an MSF file.
Original investigation and patch outline by Colden Cullen.
Differential Revision: https://reviews.llvm.org/D41742
llvm-svn: 321880
Diffstat (limited to 'llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp b/llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp index 144f5b113fb..ee9ac75d15c 100644 --- a/llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp +++ b/llvm/unittests/DebugInfo/MSF/MSFCommonTest.cpp @@ -46,12 +46,47 @@ TEST(MSFCommonTest, FpmIntervals) { EXPECT_EQ(1u, getNumFpmIntervals(L, true)); SB.NumBlocks = SB.BlockSize; EXPECT_EQ(1u, getNumFpmIntervals(L, true)); - SB.NumBlocks = SB.BlockSize + 1; - EXPECT_EQ(2u, getNumFpmIntervals(L, true)); SB.NumBlocks = SB.BlockSize * 8; EXPECT_EQ(8u, getNumFpmIntervals(L, true)); - SB.NumBlocks = SB.BlockSize * 8 + 1; - EXPECT_EQ(9u, getNumFpmIntervals(L, true)); + + // The FPM is going to look like this: + // | 0 | 1 | 2 | ... | 4096 | 4097 | 4098 | ... | + // | SB | FPM0 | FPM1 | Data | Data | FPM0 | FPM1 | ... | + // + // So when there are up to 4097 blocks (last index 4096), the final blocks + // are data blocks. When there are 4098 blocks (last index 4097), there is + // one terminating FPM block, and when there are 4099 blocks, there are two + // terminating FPM blocks. Make sure all these cases are handled. + + // With 4096 or 4097 blocks, the last block is a data block so we only have + // 1 interval. + for (uint32_t I : {4096, 4097}) { + // 1 FPM0 interval + EXPECT_EQ(1U, getNumFpmIntervals(4096, I, true, 1)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, I, false, 1)); + + // 1 FPM1 interval + EXPECT_EQ(1U, getNumFpmIntervals(4096, I, true, 2)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, I, false, 2)); + } + + // With 4098 blocks, the last block belongs to FPM0 so we should have 2 FPM0 + // intervals. + EXPECT_EQ(2U, getNumFpmIntervals(4096, 4098, true, 1)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, false, 1)); + + // And 1 FPM1 interval. + EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, true, 2)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, false, 2)); + + // With 4099 blocks, the last block belongs to FPM1 so we should have 2 + // FPM0 intervals. + EXPECT_EQ(2U, getNumFpmIntervals(4096, 4099, true, 1)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, 4099, false, 1)); + + // And 2 FPM1 intervals. + EXPECT_EQ(2U, getNumFpmIntervals(4096, 4099, true, 2)); + EXPECT_EQ(1U, getNumFpmIntervals(4096, 4099, false, 2)); } TEST(MSFCommonTest, FpmStreamLayout) { @@ -95,7 +130,7 @@ TEST(MSFCommonTest, FpmStreamLayout) { // 2. When we are including unused FPM data, there should be one FPM block // at every BlockSize interval in the file, even if entire FPM blocks are // unused. - SB.NumBlocks = SB.BlockSize * 8 + 1; + SB.NumBlocks = SB.BlockSize * 8 + 3; SL = getFpmStreamLayout(L, true, false); EXPECT_EQ(SB.BlockSize * 9, SL.Length); EXPECT_EQ(9u, SL.Blocks.size()); |