[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / unittests / DebugInfo / MSF / MSFCommonTest.cpp
blob68d087526cc2f3e1eeb5792b674506ced55c4b3d
1 //===- MSFBuilderTest.cpp Tests manipulation of MSF stream metadata ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/MSF/MSFCommon.h"
10 #include "llvm/Testing/Support/Error.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
15 using namespace llvm::msf;
17 TEST(MSFCommonTest, BytesToBlocks) {
18 EXPECT_EQ(0ULL, bytesToBlocks(0, 4096));
19 EXPECT_EQ(1ULL, bytesToBlocks(12, 4096));
20 EXPECT_EQ(1ULL, bytesToBlocks(4096, 4096));
21 EXPECT_EQ(2ULL, bytesToBlocks(4097, 4096));
22 EXPECT_EQ(2ULL, bytesToBlocks(600, 512));
25 TEST(MSFCommonTest, FpmIntervals) {
26 SuperBlock SB;
27 SB.FreeBlockMapBlock = 1;
28 SB.BlockSize = 4096;
30 MSFLayout L;
31 L.SB = &SB;
33 SB.NumBlocks = 12;
34 EXPECT_EQ(1u, getNumFpmIntervals(L, false));
35 SB.NumBlocks = SB.BlockSize;
36 EXPECT_EQ(1u, getNumFpmIntervals(L, false));
37 SB.NumBlocks = SB.BlockSize + 1;
38 EXPECT_EQ(1u, getNumFpmIntervals(L, false));
39 SB.NumBlocks = SB.BlockSize * 8;
40 EXPECT_EQ(1u, getNumFpmIntervals(L, false));
41 SB.NumBlocks = SB.BlockSize * 8 + 1;
42 EXPECT_EQ(2u, getNumFpmIntervals(L, false));
44 SB.NumBlocks = 12;
45 EXPECT_EQ(1u, getNumFpmIntervals(L, true));
46 SB.NumBlocks = SB.BlockSize;
47 EXPECT_EQ(1u, getNumFpmIntervals(L, true));
48 SB.NumBlocks = SB.BlockSize * 8;
49 EXPECT_EQ(8u, getNumFpmIntervals(L, true));
51 // The FPM is going to look like this:
52 // | 0 | 1 | 2 | ... | 4096 | 4097 | 4098 | ... |
53 // | SB | FPM0 | FPM1 | Data | Data | FPM0 | FPM1 | ... |
55 // So when there are up to 4097 blocks (last index 4096), the final blocks
56 // are data blocks. When there are 4098 blocks (last index 4097), there is
57 // one terminating FPM block, and when there are 4099 blocks, there are two
58 // terminating FPM blocks. Make sure all these cases are handled.
60 // With 4096 or 4097 blocks, the last block is a data block so we only have
61 // 1 interval.
62 for (uint32_t I : {4096, 4097}) {
63 // 1 FPM0 interval
64 EXPECT_EQ(1U, getNumFpmIntervals(4096, I, true, 1));
65 EXPECT_EQ(1U, getNumFpmIntervals(4096, I, false, 1));
67 // 1 FPM1 interval
68 EXPECT_EQ(1U, getNumFpmIntervals(4096, I, true, 2));
69 EXPECT_EQ(1U, getNumFpmIntervals(4096, I, false, 2));
72 // With 4098 blocks, the last block belongs to FPM0 so we should have 2 FPM0
73 // intervals.
74 EXPECT_EQ(2U, getNumFpmIntervals(4096, 4098, true, 1));
75 EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, false, 1));
77 // And 1 FPM1 interval.
78 EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, true, 2));
79 EXPECT_EQ(1U, getNumFpmIntervals(4096, 4098, false, 2));
81 // With 4099 blocks, the last block belongs to FPM1 so we should have 2
82 // FPM0 intervals.
83 EXPECT_EQ(2U, getNumFpmIntervals(4096, 4099, true, 1));
84 EXPECT_EQ(1U, getNumFpmIntervals(4096, 4099, false, 1));
86 // And 2 FPM1 intervals.
87 EXPECT_EQ(2U, getNumFpmIntervals(4096, 4099, true, 2));
88 EXPECT_EQ(1U, getNumFpmIntervals(4096, 4099, false, 2));
91 TEST(MSFCommonTest, FpmStreamLayout) {
92 SuperBlock SB;
93 MSFLayout L;
94 L.SB = &SB;
95 SB.FreeBlockMapBlock = 1;
97 // Each FPM block has 4096 bytes for a maximum of 4096*8 allocation states.
98 SB.BlockSize = 4096;
100 // 1. When we're not including unused FPM data, the length of the FPM stream
101 // should be only long enough to contain 1 bit for each block.
103 // 1a. When the PDB has <= 4096*8 blocks, there should only be one FPM block.
104 SB.NumBlocks = 8000;
105 MSFStreamLayout SL = getFpmStreamLayout(L, false, false);
106 EXPECT_EQ(1000u, SL.Length);
107 EXPECT_EQ(1u, SL.Blocks.size());
108 EXPECT_EQ(SB.FreeBlockMapBlock, SL.Blocks.front());
110 SL = getFpmStreamLayout(L, false, true);
111 EXPECT_EQ(1000u, SL.Length);
112 EXPECT_EQ(1u, SL.Blocks.size());
113 EXPECT_EQ(3u - SB.FreeBlockMapBlock, SL.Blocks.front());
115 // 1b. When the PDB has > 4096*8 blocks, there should be multiple FPM blocks.
116 SB.NumBlocks = SB.BlockSize * 8 + 1;
117 SL = getFpmStreamLayout(L, false, false);
118 EXPECT_EQ(SB.BlockSize + 1, SL.Length);
119 EXPECT_EQ(2u, SL.Blocks.size());
120 EXPECT_EQ(SB.FreeBlockMapBlock, SL.Blocks[0]);
121 EXPECT_EQ(SB.FreeBlockMapBlock + SB.BlockSize, SL.Blocks[1]);
123 SL = getFpmStreamLayout(L, false, true);
124 EXPECT_EQ(SB.BlockSize + 1, SL.Length);
125 EXPECT_EQ(2u, SL.Blocks.size());
126 EXPECT_EQ(3u - SB.FreeBlockMapBlock, SL.Blocks[0]);
127 EXPECT_EQ(3u - SB.FreeBlockMapBlock + SB.BlockSize, SL.Blocks[1]);
129 // 2. When we are including unused FPM data, there should be one FPM block
130 // at every BlockSize interval in the file, even if entire FPM blocks are
131 // unused.
132 SB.NumBlocks = SB.BlockSize * 8 + 3;
133 SL = getFpmStreamLayout(L, true, false);
134 EXPECT_EQ(SB.BlockSize * 9, SL.Length);
135 EXPECT_EQ(9u, SL.Blocks.size());
136 for (int I = 0; I < 9; ++I)
137 EXPECT_EQ(I * SB.BlockSize + SB.FreeBlockMapBlock, SL.Blocks[I]);