Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h

Issue 1140153004: Clean up bitcode munging tests. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- NaClBitcodeMunge.h - Bitcode Munger ----------------------*- C++ -*-===// 1 //===- NaClBitcodeMunge.h - Bitcode Munger ----------------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Test harness for generating a PNaCl bitcode memory buffer from 10 // Test harness for generating a PNaCl bitcode memory buffer from
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 /// Sets death test flag. When true, output will be redirected to 68 /// Sets death test flag. When true, output will be redirected to
69 /// the errs() (rather than buffered) so that the test can be 69 /// the errs() (rather than buffered) so that the test can be
70 /// debugged. 70 /// debugged.
71 void setRunAsDeathTest(bool NewValue) { 71 void setRunAsDeathTest(bool NewValue) {
72 RunAsDeathTest = NewValue; 72 RunAsDeathTest = NewValue;
73 } 73 }
74 74
75 /// Creates MungedInput and DumpStream for running tests, based on 75 /// Creates MungedInput and DumpStream for running tests, based on
76 /// given Munges. Returns true if able to set up test. 76 /// given Munges. Returns true if able to set up test.
77 bool setupTest( 77 bool setupTest(const uint64_t Munges[], size_t MungesSize, bool AddHeader);
78 const char *TestName, const uint64_t Munges[], size_t MungesSize, 78
79 bool AddHeader); 79 // TODO(kschimpf): The following function is deprecated and only
80 // provided until subzero is updated to use the new API that no
81 // longer uses test names.
82 bool setupTest(const char *, const uint64_t Munges[], size_t MungesSize,
83 bool AddHeader) {
84 return setupTest(Munges, MungesSize, AddHeader);
85 }
80 86
81 /// Cleans up state after a test. Returns true if no errors found. 87 /// Cleans up state after a test. Returns true if no errors found.
82 bool cleanupTest(); 88 bool cleanupTest();
83 89
84 /// Returns the resulting string generated by the corresponding test. 90 /// Returns the resulting string generated by the corresponding test.
85 const std::string &getTestResults() const { 91 const std::string &getTestResults() const {
86 return DumpResults; 92 return DumpResults;
87 } 93 }
88 94
89 /// Returns the lines containing the given Substring, from the 95 /// Returns the lines containing the given Substring, from the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 169
164 /// Class to run tests writing munged bitcode. 170 /// Class to run tests writing munged bitcode.
165 class NaClWriteMunger : public NaClBitcodeMunger { 171 class NaClWriteMunger : public NaClBitcodeMunger {
166 public: 172 public:
167 NaClWriteMunger(const uint64_t Records[], size_t RecordsSize, 173 NaClWriteMunger(const uint64_t Records[], size_t RecordsSize,
168 uint64_t RecordTerminator) 174 uint64_t RecordTerminator)
169 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 175 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
170 176
171 /// Writes munged bitcode and puts error messages into DumpResults. 177 /// Writes munged bitcode and puts error messages into DumpResults.
172 /// Returns true if successful. 178 /// Returns true if successful.
173 bool runTest(const char* TestName, const uint64_t Munges[], 179 bool runTest(const uint64_t Munges[], size_t MungesSize);
174 size_t MungesSize);
175
176 /// Same as above, but without test name.
177 bool runTest(const uint64_t Munges[], size_t MungesSize) {
178 return runTest("Test", Munges, MungesSize);
179 }
180 180
181 /// Same as above, but without any edits. 181 /// Same as above, but without any edits.
182 bool runTest(const char* TestName) { 182 bool runTest() {
183 uint64_t NoMunges[] = {0}; 183 uint64_t NoMunges[] = {0};
184 return runTest(TestName, NoMunges, 0); 184 return runTest(NoMunges, 0);
185 }
186
187 /// Same as above, but without test name.
188 bool runTest() {
189 return runTest("Test");
190 } 185 }
191 }; 186 };
192 187
193 /// Class to run tests for function llvm::NaClObjDump. 188 /// Class to run tests for function llvm::NaClObjDump.
194 class NaClObjDumpMunger : public NaClBitcodeMunger { 189 class NaClObjDumpMunger : public NaClBitcodeMunger {
195 public: 190 public:
196 191
197 /// Creates a bitcode munger, based on the given array of values. 192 /// Creates a bitcode munger, based on the given array of values.
198 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize, 193 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize,
199 uint64_t RecordTerminator) 194 uint64_t RecordTerminator)
200 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 195 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
201 196
202 /// Runs function NaClObjDump on the sequence of records associated 197 /// Runs function NaClObjDump on the sequence of records associated
203 /// with the instance. The memory buffer containing the bitsequence 198 /// with the instance. The memory buffer containing the bitsequence
204 /// associated with the record is automatically generated, and 199 /// associated with the record is automatically generated, and
205 /// passed to NaClObjDump. TestName is the name associated with the 200 /// passed to NaClObjDump. If AddHeader is true, test assumes that the
206 /// memory buffer. If AddHeader is true, test assumes that the
207 /// sequence of records doesn't contain a header record, and the 201 /// sequence of records doesn't contain a header record, and the
208 /// test should add one. Arguments NoRecords and NoAssembly are 202 /// test should add one. Arguments NoRecords and NoAssembly are
209 /// passed to NaClObjDump. Returns true if test succeeds without 203 /// passed to NaClObjDump. Returns true if test succeeds without
210 /// errors. 204 /// errors.
211 bool runTestWithFlags(const char *TestName, bool AddHeader, 205 bool runTestWithFlags(bool AddHeader, bool NoRecords, bool NoAssembly) {
212 bool NoRecords, bool NoAssembly) {
213 uint64_t NoMunges[] = {0}; 206 uint64_t NoMunges[] = {0};
214 return runTestWithFlags(TestName, NoMunges, 0, AddHeader, NoRecords, 207 return runTestWithFlags(NoMunges, 0, AddHeader, NoRecords, NoAssembly);
215 NoAssembly);
216 } 208 }
217 209
218 /// Same as above except it runs function NaClObjDump with flags 210 /// Same as above except it runs function NaClObjDump with flags
219 /// NoRecords and NoAssembly set to false, and AddHeader set to true. 211 /// NoRecords and NoAssembly set to false, and AddHeader set to true.
220 bool runTest(const char *TestName) { 212 bool runTest() {
221 return runTestWithFlags(TestName, true, false, false); 213 return runTestWithFlags(true, false, false);
222 } 214 }
223 215
224 /// Same as above but without test name. 216 // TODO(kschimpf): The following function is deprecated and only
225 bool runTest() { 217 // provided until subzero is updated to use the new API that no
226 return runTest("Test"); 218 // longer uses test names.
219 bool runTest(const char *) {
220 return runTest();
227 } 221 }
228 222
229 /// Same as above, but only print out assembly and errors. 223 /// Same as above, but only print out assembly and errors.
230 bool runTestForAssembly(const char *TestName) { 224 bool runTestForAssembly() {
231 return runTestWithFlags(TestName, true, true, false); 225 return runTestWithFlags(true, true, false);
232 } 226 }
233
234 /// Same as above, but only generate error messages. 227 /// Same as above, but only generate error messages.
235 bool runTestForErrors(const char *TestName) { 228 bool runTestForErrors() {
236 return runTestWithFlags(TestName, true, true, true); 229 return runTestWithFlags(true, true, true);
237 } 230 }
238 231
239 /// Runs function llvm::NaClObjDump on the sequence of records 232 /// Runs function llvm::NaClObjDump on the sequence of records
240 /// associated with the instance. Array Munges contains the sequence 233 /// associated with the instance. Array Munges contains the sequence
241 /// of edits to apply to the sequence of records when generating the 234 /// of edits to apply to the sequence of records when generating the
242 /// bitsequence in a memory buffer. This generated bitsequence is 235 /// bitsequence in a memory buffer. This generated bitsequence is
243 /// then passed to NaClObjDump. TestName is the name associated 236 /// then passed to NaClObjDump. TestName is the name associated
244 /// with the memory buffer. Arguments NoRecords and NoAssembly are 237 /// with the memory buffer. Arguments NoRecords and NoAssembly are
245 /// passed to NaClObjDump. Returns true if test succeeds without 238 /// passed to NaClObjDump. Returns true if test succeeds without
246 /// errors. 239 /// errors.
247 bool runTestWithFlags(const char* TestName, const uint64_t Munges[], 240 bool runTestWithFlags(const uint64_t Munges[], size_t MungesSize,
248 size_t MungesSize, bool AddHeader, 241 bool AddHeader, bool NoRecords, bool NoAssembly);
249 bool NoRecords, bool NoAssembly);
250 242
251 /// Same as above except it runs function NaClObjDump with flags 243 /// Same as above except it runs function NaClObjDump with flags
252 /// NoRecords and NoAssembly set to false, and AddHeader set to 244 /// NoRecords and NoAssembly set to false, and AddHeader set to
253 /// true. 245 /// true.
254 bool runTest(const char* TestName, const uint64_t Munges[], 246 bool runTest(const uint64_t Munges[], size_t MungesSize) {
255 size_t MungesSize) { 247 return runTestWithFlags(Munges, MungesSize, true, false, false);
256 return runTestWithFlags(TestName, Munges, MungesSize, true, false, false);
257 } 248 }
258 249
259 bool runTest(const uint64_t Munges[], size_t MungesSize) { 250 bool runTestForAssembly(const uint64_t Munges[], size_t MungesSize) {
260 return runTest("Test", Munges, MungesSize); 251 return runTestWithFlags(Munges, MungesSize, true, true, false);
261 } 252 }
262 253
263 bool runTestForAssembly(const char* TestName, const uint64_t Munges[], 254 // TODO(kschimpf): The following function is deprecated and only
255 // provided until subzero is updated to use the new API that no
256 // longer uses test names.
257 bool runTestForAssembly(const char *, const uint64_t Munges[],
264 size_t MungesSize) { 258 size_t MungesSize) {
265 return runTestWithFlags(TestName, Munges, MungesSize, true, true, false); 259 return runTestForAssembly(Munges, MungesSize);
266 } 260 }
267 261
268 bool runTestForErrors(const char* TestName, const uint64_t Munges[], 262
269 size_t MungesSize) { 263 bool runTestForErrors(const uint64_t Munges[], size_t MungesSize) {
270 return runTestWithFlags(TestName, Munges, MungesSize, true, true, true); 264 return runTestWithFlags(Munges, MungesSize, true, true, true);
271 } 265 }
272 }; 266 };
273 267
274 // Class to run tests for function NaClParseBitcodeFile. 268 // Class to run tests for function NaClParseBitcodeFile.
275 class NaClParseBitcodeMunger : public NaClBitcodeMunger { 269 class NaClParseBitcodeMunger : public NaClBitcodeMunger {
276 public: 270 public:
277 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize, 271 NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize,
278 uint64_t RecordTerminator) 272 uint64_t RecordTerminator)
279 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 273 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
280 274
281 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages 275 /// Runs function llvm::NaClParseBitcodeFile, and puts error messages
282 /// into DumpResults. Returns true if parse is successful. 276 /// into DumpResults. Returns true if parse is successful.
283 bool runTest(const char* TestName, const uint64_t Munges[], 277 bool runTest(const uint64_t Munges[], size_t MungesSize, bool VerboseErrors);
284 size_t MungesSize, bool VerboseErrors);
285
286 /// Same as above, but without test name.
287 bool runTest(const uint64_t Munges[], size_t MungesSize, bool VerboseErrors) {
288 return runTest("Test", Munges, MungesSize, VerboseErrors);
289 }
290 278
291 // Same as above, but without any edits. 279 // Same as above, but without any edits.
292 bool runTest(const char* TestName, bool VerboseErrors) { 280 bool runTest(bool VerboseErrors) {
293 uint64_t NoMunges[] = {0}; 281 uint64_t NoMunges[] = {0};
294 return runTest(TestName, NoMunges, 0, VerboseErrors); 282 return runTest(NoMunges, 0, VerboseErrors);
295 } 283 }
296 }; 284 };
297 285
298 // Class to run tests for NaClBitcodeCompressor.compress(). 286 // Class to run tests for NaClBitcodeCompressor.compress().
299 class NaClCompressMunger : public NaClBitcodeMunger { 287 class NaClCompressMunger : public NaClBitcodeMunger {
300 public: 288 public:
301 NaClCompressMunger(const uint64_t Records[], size_t RecordsSize, 289 NaClCompressMunger(const uint64_t Records[], size_t RecordsSize,
302 uint64_t RecordTerminator) 290 uint64_t RecordTerminator)
303 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} 291 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
304 292
305 bool runTest(const char* TestName, const uint64_t Munges[], 293 bool runTest(const uint64_t Munges[], size_t MungesSize);
306 size_t MungesSize);
307 294
308 bool runTest(const char* TestName) { 295 bool runTest() {
309 uint64_t NoMunges[] = {0}; 296 uint64_t NoMunges[] = {0};
310 return runTest(TestName, NoMunges, 0); 297 return runTest(NoMunges, 0);
311 } 298 }
312 }; 299 };
313 300
314 } // end namespace llvm. 301 } // end namespace llvm.
315 302
316 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H 303 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H
OLDNEW
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698