6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #include " llvm/Bitstream/BitstreamReader .h"
9
+ #include " llvm/Bitcode/BitcodeAnalyzer .h"
10
10
#include " llvm/ProfileData/CtxInstrContextNode.h"
11
11
#include " llvm/ProfileData/PGOCtxProfReader.h"
12
12
#include " llvm/ProfileData/PGOCtxProfWriter.h"
@@ -106,8 +106,20 @@ TEST_F(PGOCtxProfRWTest, RoundTrip) {
106
106
MemoryBuffer::getFile (ProfileFile.path ());
107
107
ASSERT_TRUE (!!MB);
108
108
ASSERT_NE (*MB, nullptr );
109
- BitstreamCursor Cursor ((*MB)->getBuffer ());
110
- PGOCtxProfileReader Reader (Cursor);
109
+
110
+ // Check it's analyzable by the BCAnalyzer
111
+ BitcodeAnalyzer BA ((*MB)->getBuffer ());
112
+ std::string AnalyzerDump;
113
+ raw_string_ostream OS (AnalyzerDump);
114
+ BCDumpOptions Opts (OS);
115
+
116
+ // As in, expect no error.
117
+ EXPECT_FALSE (BA.analyze (Opts));
118
+ EXPECT_TRUE (AnalyzerDump.find (" <Metadata BlockID" ) != std::string::npos);
119
+ EXPECT_TRUE (AnalyzerDump.find (" <Context BlockID" ) != std::string::npos);
120
+ EXPECT_TRUE (AnalyzerDump.find (" <CalleeIndex codeid" ) != std::string::npos);
121
+
122
+ PGOCtxProfileReader Reader ((*MB)->getBuffer ());
111
123
auto Expected = Reader.loadContexts ();
112
124
ASSERT_TRUE (!!Expected);
113
125
auto &Ctxes = *Expected;
@@ -143,25 +155,22 @@ TEST_F(PGOCtxProfRWTest, InvalidCounters) {
143
155
auto MB = MemoryBuffer::getFile (ProfileFile.path ());
144
156
ASSERT_TRUE (!!MB);
145
157
ASSERT_NE (*MB, nullptr );
146
- BitstreamCursor Cursor ((*MB)->getBuffer ());
147
- PGOCtxProfileReader Reader (Cursor);
158
+ PGOCtxProfileReader Reader ((*MB)->getBuffer ());
148
159
auto Expected = Reader.loadContexts ();
149
160
EXPECT_FALSE (Expected);
150
161
consumeError (Expected.takeError ());
151
162
}
152
163
}
153
164
154
165
TEST_F (PGOCtxProfRWTest, Empty) {
155
- BitstreamCursor Cursor (" " );
156
- PGOCtxProfileReader Reader (Cursor);
166
+ PGOCtxProfileReader Reader (" " );
157
167
auto Expected = Reader.loadContexts ();
158
168
EXPECT_FALSE (Expected);
159
169
consumeError (Expected.takeError ());
160
170
}
161
171
162
172
TEST_F (PGOCtxProfRWTest, Invalid) {
163
- BitstreamCursor Cursor (" Surely this is not valid" );
164
- PGOCtxProfileReader Reader (Cursor);
173
+ PGOCtxProfileReader Reader (" Surely this is not valid" );
165
174
auto Expected = Reader.loadContexts ();
166
175
EXPECT_FALSE (Expected);
167
176
consumeError (Expected.takeError ());
@@ -182,8 +191,8 @@ TEST_F(PGOCtxProfRWTest, ValidButEmpty) {
182
191
auto MB = MemoryBuffer::getFile (ProfileFile.path ());
183
192
ASSERT_TRUE (!!MB);
184
193
ASSERT_NE (*MB, nullptr );
185
- BitstreamCursor Cursor ((*MB)-> getBuffer ());
186
- PGOCtxProfileReader Reader (Cursor );
194
+
195
+ PGOCtxProfileReader Reader ((*MB)-> getBuffer () );
187
196
auto Expected = Reader.loadContexts ();
188
197
EXPECT_TRUE (!!Expected);
189
198
EXPECT_TRUE (Expected->empty ());
@@ -204,8 +213,8 @@ TEST_F(PGOCtxProfRWTest, WrongVersion) {
204
213
auto MB = MemoryBuffer::getFile (ProfileFile.path ());
205
214
ASSERT_TRUE (!!MB);
206
215
ASSERT_NE (*MB, nullptr );
207
- BitstreamCursor Cursor ((*MB)-> getBuffer ());
208
- PGOCtxProfileReader Reader (Cursor );
216
+
217
+ PGOCtxProfileReader Reader ((*MB)-> getBuffer () );
209
218
auto Expected = Reader.loadContexts ();
210
219
EXPECT_FALSE (Expected);
211
220
consumeError (Expected.takeError ());
@@ -228,8 +237,7 @@ TEST_F(PGOCtxProfRWTest, DuplicateRoots) {
228
237
auto MB = MemoryBuffer::getFile (ProfileFile.path ());
229
238
ASSERT_TRUE (!!MB);
230
239
ASSERT_NE (*MB, nullptr );
231
- BitstreamCursor Cursor ((*MB)->getBuffer ());
232
- PGOCtxProfileReader Reader (Cursor);
240
+ PGOCtxProfileReader Reader ((*MB)->getBuffer ());
233
241
auto Expected = Reader.loadContexts ();
234
242
EXPECT_FALSE (Expected);
235
243
consumeError (Expected.takeError ());
@@ -255,8 +263,7 @@ TEST_F(PGOCtxProfRWTest, DuplicateTargets) {
255
263
auto MB = MemoryBuffer::getFile (ProfileFile.path ());
256
264
ASSERT_TRUE (!!MB);
257
265
ASSERT_NE (*MB, nullptr );
258
- BitstreamCursor Cursor ((*MB)->getBuffer ());
259
- PGOCtxProfileReader Reader (Cursor);
266
+ PGOCtxProfileReader Reader ((*MB)->getBuffer ());
260
267
auto Expected = Reader.loadContexts ();
261
268
EXPECT_FALSE (Expected);
262
269
consumeError (Expected.takeError ());
0 commit comments