OLD | NEW |
1 //===- llvm/unittest/Bitcode/NaClMungedIoTest.cpp -------------------------===// | 1 //===- llvm/unittest/Bitcode/NaClMungedIoTest.cpp -------------------------===// |
2 // Tests munging NaCl bitcode records. | 2 // Tests munging NaCl bitcode records. |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 MungedBitcode.print(StrBuf); | 31 MungedBitcode.print(StrBuf); |
32 return StrBuf.str(); | 32 return StrBuf.str(); |
33 } | 33 } |
34 | 34 |
35 typedef SmallVector<char, 1024> TextBuffer; | 35 typedef SmallVector<char, 1024> TextBuffer; |
36 | 36 |
37 // Writes out a sequence of munged bitcode records, and writes them into | 37 // Writes out a sequence of munged bitcode records, and writes them into |
38 // the text buffer. Returns a corresponding memory buffer containing | 38 // the text buffer. Returns a corresponding memory buffer containing |
39 // the munged bitcode records. | 39 // the munged bitcode records. |
40 std::unique_ptr<MemoryBuffer> writeMungedBitcode( | 40 std::unique_ptr<MemoryBuffer> writeMungedBitcode( |
41 NaClMungedBitcode &Bitcode, TextBuffer &Buffer) { | 41 NaClMungedBitcode &Bitcode, TextBuffer &Buffer, |
42 Bitcode.write(Buffer, /* AddHeader = */ true); | 42 NaClMungedBitcode::WriteFlags &Flags) { |
| 43 Bitcode.write(Buffer, /* AddHeader = */ true, Flags); |
43 StringRef Input(Buffer.data(), Buffer.size()); | 44 StringRef Input(Buffer.data(), Buffer.size()); |
44 return MemoryBuffer::getMemBuffer(Input, "Test", false); | 45 return MemoryBuffer::getMemBuffer(Input, "Test", false); |
45 } | 46 } |
46 | 47 |
| 48 std::unique_ptr<MemoryBuffer> writeMungedBitcode( |
| 49 NaClMungedBitcode &Bitcode, TextBuffer &Buffer) { |
| 50 NaClMungedBitcode::WriteFlags Flags; |
| 51 return writeMungedBitcode(Bitcode, Buffer, Flags); |
| 52 } |
| 53 |
47 // Write out the bitcode, parse it back, and return the resulting | 54 // Write out the bitcode, parse it back, and return the resulting |
48 // munged bitcode. | 55 // munged bitcode. |
49 std::string parseWrittenMungedBitcode(NaClMungedBitcode &OutBitcode) { | 56 std::string parseWrittenMungedBitcode(NaClMungedBitcode &OutBitcode) { |
50 TextBuffer Buffer; | 57 TextBuffer Buffer; |
51 NaClMungedBitcode InBitcode(writeMungedBitcode(OutBitcode, Buffer)); | 58 NaClMungedBitcode InBitcode(writeMungedBitcode(OutBitcode, Buffer)); |
52 return stringify(InBitcode); | 59 return stringify(InBitcode); |
53 } | 60 } |
54 | 61 |
55 // Sample toy bitcode records. | 62 // Sample toy bitcode records. |
56 const uint64_t Records[] = { | 63 const uint64_t Records[] = { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 for (size_t i = 2, e = Bitcode.getBaseRecords().size(); i < e; ++i) | 160 for (size_t i = 2, e = Bitcode.getBaseRecords().size(); i < e; ++i) |
154 Bitcode.remove(i); | 161 Bitcode.remove(i); |
155 | 162 |
156 // The expected output when stringifying this input. | 163 // The expected output when stringifying this input. |
157 EXPECT_EQ( | 164 EXPECT_EQ( |
158 " 1: [65535, 8, 2]\n" | 165 " 1: [65535, 8, 2]\n" |
159 " 3: [1, 1]\n", | 166 " 3: [1, 1]\n", |
160 stringify(Bitcode)); | 167 stringify(Bitcode)); |
161 | 168 |
162 // Show that we can't write the bitcode correctly. | 169 // Show that we can't write the bitcode correctly. |
163 TextBuffer Buffer; | 170 TextBuffer WriteBuffer; |
164 EXPECT_DEATH(writeMungedBitcode(Bitcode, Buffer), | 171 std::string LogBuffer; |
165 ".*Unflushed data remaining.*"); | 172 raw_string_ostream StrBuf(LogBuffer); |
| 173 NaClMungedBitcode::WriteFlags Flags; |
| 174 Flags.setErrStream(StrBuf); |
| 175 writeMungedBitcode(Bitcode, WriteBuffer, Flags); |
| 176 EXPECT_EQ( |
| 177 "Error (Block 8): Missing close block.\n", |
| 178 StrBuf.str()); |
166 } | 179 } |
167 | 180 |
168 } // end of anonymous namespace | 181 } // end of anonymous namespace |
OLD | NEW |