| OLD | NEW |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 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. | 76 /// given Munges. Returns true if able to set up test. |
| 77 void setupTest( | 77 bool setupTest( |
| 78 const char *TestName, const uint64_t Munges[], size_t MungesSize, | 78 const char *TestName, const uint64_t Munges[], size_t MungesSize, |
| 79 bool AddHeader); | 79 bool AddHeader); |
| 80 | 80 |
| 81 /// Cleans up state after a test. | 81 /// Cleans up state after a test. Returns true if no errors found. |
| 82 void cleanupTest(); | 82 bool cleanupTest(); |
| 83 | 83 |
| 84 /// Returns the resulting string generated by the corresponding test. | 84 /// Returns the resulting string generated by the corresponding test. |
| 85 const std::string &getTestResults() const { | 85 const std::string &getTestResults() const { |
| 86 return DumpResults; | 86 return DumpResults; |
| 87 } | 87 } |
| 88 | 88 |
| 89 /// Returns the lines containing the given Substring, from the | 89 /// Returns the lines containing the given Substring, from the |
| 90 /// string getTestResults(). | 90 /// string getTestResults(). |
| 91 std::string getLinesWithSubstring(const std::string &Substring) const { | 91 std::string getLinesWithSubstring(const std::string &Substring) const { |
| 92 return getLinesWithTextMatch(Substring, false); | 92 return getLinesWithTextMatch(Substring, false); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 void setTryToRecoverOnWrite(bool NewValue) { | 103 void setTryToRecoverOnWrite(bool NewValue) { |
| 104 WriteFlags.setTryToRecover(NewValue); | 104 WriteFlags.setTryToRecover(NewValue); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /// When NewValue, write bad abbreviation index into bitcode when | 107 /// When NewValue, write bad abbreviation index into bitcode when |
| 108 /// writing during next test. | 108 /// writing during next test. |
| 109 void setWriteBadAbbrevIndex(bool NewValue) { | 109 void setWriteBadAbbrevIndex(bool NewValue) { |
| 110 WriteFlags.setWriteBadAbbrevIndex(NewValue); | 110 WriteFlags.setWriteBadAbbrevIndex(NewValue); |
| 111 } | 111 } |
| 112 | 112 |
| 113 /// Get access to munged bitcodes. |
| 114 NaClMungedBitcode &getMungedBitcode() { |
| 115 return MungedBitcode; |
| 116 } |
| 117 |
| 118 /// Apply given munges to the munged bitcode. |
| 119 void munge(const uint64_t Munges[], size_t MungesSize) { |
| 120 MungedBitcode.munge(Munges, MungesSize, RecordTerminator); |
| 121 } |
| 122 |
| 113 protected: | 123 protected: |
| 114 // The bitcode records being munged. | 124 // The bitcode records being munged. |
| 115 NaClMungedBitcode MungedBitcode; | 125 NaClMungedBitcode MungedBitcode; |
| 116 // The value used as record terminator. | 126 // The value used as record terminator. |
| 117 uint64_t RecordTerminator; | 127 uint64_t RecordTerminator; |
| 118 // The results buffer of the last dump. | 128 // The results buffer of the last dump. |
| 119 std::string DumpResults; | 129 std::string DumpResults; |
| 120 // The memory buffer containing the munged input. | 130 // The memory buffer containing the munged input. |
| 121 std::unique_ptr<MemoryBuffer> MungedInput; | 131 std::unique_ptr<MemoryBuffer> MungedInput; |
| 122 // The stream containing errors and the objdump of the generated bitcode file. | 132 // The stream containing errors and the objdump of the generated bitcode file. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 144 bool MustBePrefix = false) const; | 154 bool MustBePrefix = false) const; |
| 145 | 155 |
| 146 // Returns the log stream to use. When running death tests, redirect output | 156 // Returns the log stream to use. When running death tests, redirect output |
| 147 // to the error stream (rather than buffering in DumpStream), so that | 157 // to the error stream (rather than buffering in DumpStream), so that |
| 148 // the output can be seen in gtest death tests. | 158 // the output can be seen in gtest death tests. |
| 149 raw_ostream &getDumpStream() const { | 159 raw_ostream &getDumpStream() const { |
| 150 return RunAsDeathTest ? errs() : *DumpStream; | 160 return RunAsDeathTest ? errs() : *DumpStream; |
| 151 } | 161 } |
| 152 }; | 162 }; |
| 153 | 163 |
| 164 /// Class to run tests writing munged bitcode. |
| 165 class NaClWriteMunger : public NaClBitcodeMunger { |
| 166 public: |
| 167 NaClWriteMunger(const uint64_t Records[], size_t RecordsSize, |
| 168 uint64_t RecordTerminator) |
| 169 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} |
| 170 |
| 171 /// Writes munged bitcode and puts error messages into DumpResults. |
| 172 /// Returns true if successful. |
| 173 bool runTest(const char* TestName, const uint64_t Munges[], |
| 174 size_t MungesSize); |
| 175 |
| 176 // Same as above, but without any edits. |
| 177 bool runTest(const char* TestName) { |
| 178 uint64_t NoMunges[] = {0}; |
| 179 return runTest(TestName, NoMunges, 0); |
| 180 } |
| 181 }; |
| 182 |
| 154 /// Class to run tests for function llvm::NaClObjDump. | 183 /// Class to run tests for function llvm::NaClObjDump. |
| 155 class NaClObjDumpMunger : public NaClBitcodeMunger { | 184 class NaClObjDumpMunger : public NaClBitcodeMunger { |
| 156 public: | 185 public: |
| 157 | 186 |
| 158 /// Creates a bitcode munger, based on the given array of values. | 187 /// Creates a bitcode munger, based on the given array of values. |
| 159 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize, | 188 NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize, |
| 160 uint64_t RecordTerminator) | 189 uint64_t RecordTerminator) |
| 161 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} | 190 : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {} |
| 162 | 191 |
| 163 /// Runs function NaClObjDump on the sequence of records associated | 192 /// Runs function NaClObjDump on the sequence of records associated |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 283 |
| 255 bool runTest(const char* TestName) { | 284 bool runTest(const char* TestName) { |
| 256 uint64_t NoMunges[] = {0}; | 285 uint64_t NoMunges[] = {0}; |
| 257 return runTest(TestName, NoMunges, 0); | 286 return runTest(TestName, NoMunges, 0); |
| 258 } | 287 } |
| 259 }; | 288 }; |
| 260 | 289 |
| 261 } // end namespace llvm. | 290 } // end namespace llvm. |
| 262 | 291 |
| 263 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H | 292 #endif // LLVM_BITCODE_NACL_NACLBITCODEMUNGE_H |
| OLD | NEW |