Index: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h |
diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h |
index 9d25a8542ca19b912fa362822c2a9513dcd87a0e..6b45509738a65eb7f4b2ba42fc34843b4512da02 100644 |
--- a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h |
+++ b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h |
@@ -8,7 +8,7 @@ |
//===----------------------------------------------------------------------===// |
// |
// Test harness for generating a PNaCl bitcode memory buffer from |
-// an array, and objdump the resulting contents. |
+// an array, and parse/objdump the resulting contents. |
// |
// Generates a bitcode memory buffer from an array containing 1 or |
// more PNaCl records. Used to test errors in PNaCl bitcode. |
@@ -63,10 +63,11 @@ |
namespace llvm { |
+class MemoryBuffer; |
class NaClBitstreamWriter; |
class NaClBitCodeAbbrev; |
-/// Class to run tests for function llvm::NaClObjDump. |
+/// Base class to run tests on munged bitcode files. |
class NaClBitcodeMunger { |
public: |
/// The types of editing actions that can be applied. |
@@ -82,73 +83,20 @@ public: |
uint64_t RecordTerminator) |
: Records(Records), RecordsSize(RecordsSize), |
RecordTerminator(RecordTerminator), WriteBlockID(-1), SetBID(-1), |
- DumpResults("Error: No previous dump results!\n"), |
- DumpStream(NULL), Writer(NULL), FoundErrors(false), |
+ DumpResults("Error: No previous dump results!\n"), MungedInput(nullptr), |
+ DumpStream(nullptr), Writer(nullptr), FoundErrors(false), |
FatalBuffer(), FatalStream(FatalBuffer) {} |
- /// Runs function NaClObjDump on the sequence of records associated |
- /// with the instance. The memory buffer containing the bitsequence |
- /// associated with the record is automatically generated, and |
- /// passed to NaClObjDump. TestName is the name associated with the |
- /// memory buffer. If AddHeader is true, test assumes that the |
- /// sequence of records doesn't contain a header record, and the |
- /// test should add one. Arguments NoRecords and NoAssembly are |
- /// passed to NaClObjDump. Returns true if test succeeds without |
- /// errors. |
- bool runTestWithFlags(const char *TestName, bool AddHeader, |
- bool NoRecords, bool NoAssembly) { |
- uint64_t NoMunges[] = {0}; |
- return runTestWithFlags(TestName, NoMunges, 0, AddHeader, NoRecords, |
- NoAssembly); |
- } |
- |
- /// Same as above except it runs function NaClObjDump with flags |
- /// NoRecords and NoAssembly set to false, and AddHeader set to true. |
- bool runTest(const char *TestName) { |
- return runTestWithFlags(TestName, true, false, false); |
- } |
- |
- /// Same as runTest, but only print out assembly and errors. |
- bool runTestForAssembly(const char *TestName) { |
- return runTestWithFlags(TestName, true, true, false); |
- } |
- |
- /// Same as runTest, but only generate error messages. |
- bool runTestForErrors(const char *TestName) { |
- return runTestWithFlags(TestName, true, true, true); |
- } |
- |
- /// Runs function llvm::NaClObjDump on the sequence of records |
- /// associated with the instance. Array Munges contains the sequence |
- /// of edits to apply to the sequence of records when generating the |
- /// bitsequence in a memory buffer. This generated bitsequence is |
- /// then passed to NaClObjDump. TestName is the name associated |
- /// with the memory buffer. Arguments NoRecords and NoAssembly are |
- /// passed to NaClObjDump. Returns true if test succeeds without |
- /// errors. |
- bool runTestWithFlags(const char* TestName, const uint64_t Munges[], |
- size_t MungesSize, bool AddHeader, |
- bool NoRecords, bool NoAssembly); |
- |
- /// Same as above except it runs function NaClObjDump with flags |
- /// NoRecords and NoAssembly set to false, and AddHeader set to |
- /// true. |
- bool runTest(const char* TestName, const uint64_t Munges[], |
- size_t MungesSize) { |
- return runTestWithFlags(TestName, Munges, MungesSize, true, false, false); |
- } |
+ /// Creates MungedInput and DumpStream for running tests, based on |
+ /// given Munges. |
+ void setupTest( |
+ const char *TestName, const uint64_t Munges[], size_t MungesSize, |
+ bool AddHeader); |
- bool runTestForAssembly(const char* TestName, const uint64_t Munges[], |
- size_t MungesSize) { |
- return runTestWithFlags(TestName, Munges, MungesSize, true, true, false); |
- } |
+ /// Cleans up state after a test. |
+ void cleanupTest(); |
- bool runTestForErrors(const char* TestName, const uint64_t Munges[], |
- size_t MungesSize) { |
- return runTestWithFlags(TestName, Munges, MungesSize, true, true, true); |
- } |
- |
- /// Returns the resulting string generated by NaClObjDump. |
+ /// Returns the resulting string generated by the corresponding test. |
const std::string &getTestResults() const { |
return DumpResults; |
} |
@@ -165,7 +113,7 @@ public: |
return getLinesWithTextMatch(Prefix, true); |
} |
-private: |
+protected: |
// The list of (base) records. |
const uint64_t *Records; |
// The number of (base) records. |
@@ -178,6 +126,8 @@ private: |
int SetBID; |
// The results buffer of the last dump. |
std::string DumpResults; |
+ // The memory buffer containing the munged input. |
+ MemoryBuffer *MungedInput; |
// The stream containing errors and the objdump of the generated bitcode file. |
raw_ostream *DumpStream; |
// The bitstream writer to use to generate the bitcode file. |
@@ -239,6 +189,97 @@ private: |
size_t &Index); |
}; |
+/// Class to run tests for function llvm::NaClObjDump. |
+class NaClObjDumpMunger : public NaClBitcodeMunger { |
+public: |
+ |
+ /// Creates a bitcode munger, based on the given array of values. |
+ NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize, |
+ uint64_t RecordTerminator) |
+ : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} |
+ |
+ /// Runs function NaClObjDump on the sequence of records associated |
+ /// with the instance. The memory buffer containing the bitsequence |
+ /// associated with the record is automatically generated, and |
+ /// passed to NaClObjDump. TestName is the name associated with the |
+ /// memory buffer. If AddHeader is true, test assumes that the |
+ /// sequence of records doesn't contain a header record, and the |
+ /// test should add one. Arguments NoRecords and NoAssembly are |
+ /// passed to NaClObjDump. Returns true if test succeeds without |
+ /// errors. |
+ bool runTestWithFlags(const char *TestName, bool AddHeader, |
+ bool NoRecords, bool NoAssembly) { |
+ uint64_t NoMunges[] = {0}; |
+ return runTestWithFlags(TestName, NoMunges, 0, AddHeader, NoRecords, |
+ NoAssembly); |
+ } |
+ |
+ /// Same as above except it runs function NaClObjDump with flags |
+ /// NoRecords and NoAssembly set to false, and AddHeader set to true. |
+ bool runTest(const char *TestName) { |
+ return runTestWithFlags(TestName, true, false, false); |
+ } |
+ |
+ /// Same as runTest, but only print out assembly and errors. |
+ bool runTestForAssembly(const char *TestName) { |
+ return runTestWithFlags(TestName, true, true, false); |
+ } |
+ |
+ /// Same as runTest, but only generate error messages. |
+ bool runTestForErrors(const char *TestName) { |
+ return runTestWithFlags(TestName, true, true, true); |
+ } |
+ |
+ /// Runs function llvm::NaClObjDump on the sequence of records |
+ /// associated with the instance. Array Munges contains the sequence |
+ /// of edits to apply to the sequence of records when generating the |
+ /// bitsequence in a memory buffer. This generated bitsequence is |
+ /// then passed to NaClObjDump. TestName is the name associated |
+ /// with the memory buffer. Arguments NoRecords and NoAssembly are |
+ /// passed to NaClObjDump. Returns true if test succeeds without |
+ /// errors. |
+ bool runTestWithFlags(const char* TestName, const uint64_t Munges[], |
+ size_t MungesSize, bool AddHeader, |
+ bool NoRecords, bool NoAssembly); |
+ |
+ /// Same as above except it runs function NaClObjDump with flags |
+ /// NoRecords and NoAssembly set to false, and AddHeader set to |
+ /// true. |
+ bool runTest(const char* TestName, const uint64_t Munges[], |
+ size_t MungesSize) { |
+ return runTestWithFlags(TestName, Munges, MungesSize, true, false, false); |
+ } |
+ |
+ bool runTestForAssembly(const char* TestName, const uint64_t Munges[], |
+ size_t MungesSize) { |
+ return runTestWithFlags(TestName, Munges, MungesSize, true, true, false); |
+ } |
+ |
+ bool runTestForErrors(const char* TestName, const uint64_t Munges[], |
+ size_t MungesSize) { |
+ return runTestWithFlags(TestName, Munges, MungesSize, true, true, true); |
+ } |
+}; |
+ |
+// Class to run tests for function NaClParseBitcodeFile. |
+class NaClParseBitcodeMunger : public NaClBitcodeMunger { |
+public: |
+ NaClParseBitcodeMunger(const uint64_t Records[], size_t RecordsSize, |
+ uint64_t RecordTerminator) |
+ : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} |
+ |
+ /// Runs function llvm::NaClParseBitcodeFile, and puts error messages |
+ /// into DumpResults. Returns true if parse is successful. |
+ bool runTest(const char* TestName, const uint64_t Munges[], |
+ size_t MungesSize, bool VerboseErrors); |
+ |
+ // Same as above, but without any edits. |
+ bool runTest(const char* TestName, bool VerboseErrors) { |
+ uint64_t NoMunges[] = {0}; |
+ return runTest(TestName, NoMunges, 0, VerboseErrors); |
+ } |
+}; |
+ |
} // end namespace llvm. |
#endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H |