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

Side by Side Diff: unittests/Bitcode/NaClAbbrevErrorTests.cpp

Issue 1113023005: Add abilities to generate bitcode buffers from munged bitcode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. 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 | « unittests/Bitcode/CMakeLists.txt ('k') | unittests/Bitcode/NaClMungedIoTest.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 //===- llvm/unittest/Bitcode/NaClAbbrevErrorTests.cpp ---------------------===// 1 //===- llvm/unittest/Bitcode/NaClAbbrevErrorTests.cpp ---------------------===//
2 // Tests parser for PNaCl bitcode instructions. 2 // Tests parser for PNaCl bitcode instructions.
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 22 matching lines...) Expand all
33 3, naclbitc::TYPE_CODE_FUNCTION, 0, 0, Terminator, 33 3, naclbitc::TYPE_CODE_FUNCTION, 0, 0, Terminator,
34 0, naclbitc::BLK_CODE_EXIT, Terminator, 34 0, naclbitc::BLK_CODE_EXIT, Terminator,
35 3, naclbitc::MODULE_CODE_FUNCTION, 1, 0, 0, 0, Terminator, 35 3, naclbitc::MODULE_CODE_FUNCTION, 1, 0, 0, 0, Terminator,
36 1, naclbitc::BLK_CODE_ENTER, naclbitc::FUNCTION_BLOCK_ID, 2, Terminator, 36 1, naclbitc::BLK_CODE_ENTER, naclbitc::FUNCTION_BLOCK_ID, 2, Terminator,
37 3, naclbitc::FUNC_CODE_DECLAREBLOCKS, 1, Terminator, 37 3, naclbitc::FUNC_CODE_DECLAREBLOCKS, 1, Terminator,
38 3, naclbitc::FUNC_CODE_INST_RET, Terminator, 38 3, naclbitc::FUNC_CODE_INST_RET, Terminator,
39 0, naclbitc::BLK_CODE_EXIT, Terminator, 39 0, naclbitc::BLK_CODE_EXIT, Terminator,
40 0, naclbitc::BLK_CODE_EXIT, Terminator 40 0, naclbitc::BLK_CODE_EXIT, Terminator
41 }; 41 };
42 42
43 const uint64_t ReplaceIndex = 3; // Index for TYPE_CODE_VOID; 43 const char* ExpectedDump =
44
45 // Show that we can parse this code.
46 NaClObjDumpMunger DumpMunger(BitcodeRecords,
47 array_lengthof(BitcodeRecords), Terminator);
48 EXPECT_TRUE(DumpMunger.runTest("BadAbbreviationIndex assembly"));
49 EXPECT_EQ(
50 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, " 44 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, "
51 "88, 69)\n" 45 "88, 69)\n"
52 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n" 46 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n"
53 " | 0> |\n" 47 " | 0> |\n"
54 " 16:0|1: <65535, 8, 2> |module { // BlockID = 8\n" 48 " 16:0|1: <65535, 8, 2> |module { // BlockID = 8\n"
55 " 24:0| 1: <65535, 17, 3> | types { // BlockID = 17\n" 49 " 24:0| 1: <65535, 17, 3> | types { // BlockID = 17\n"
56 " 32:0| 3: <1, 2> | count 2;\n" 50 " 32:0| 3: <1, 2> | count 2;\n"
57 " 34:5| 3: <2> | @t0 = void;\n" 51 " 34:5| 3: <2> | @t0 = void;\n"
58 " 36:4| 3: <21, 0, 0> | @t1 = void ();\n" 52 " 36:4| 3: <21, 0, 0> | @t1 = void ();\n"
59 " 39:7| 0: <65534> | }\n" 53 " 39:7| 0: <65534> | }\n"
60 " 44:0| 3: <8, 1, 0, 0, 0> | define external void @f0();\n" 54 " 44:0| 3: <8, 1, 0, 0, 0> | define external void @f0();\n"
61 " 48:6| 1: <65535, 12, 2> | function void @f0() { \n" 55 " 48:6| 1: <65535, 12, 2> | function void @f0() { \n"
62 " | | // BlockID " 56 " | | // BlockID "
63 "= 12\n" 57 "= 12\n"
64 " 56:0| 3: <1, 1> | blocks 1;\n" 58 " 56:0| 3: <1, 1> | blocks 1;\n"
65 " | | %b0:\n" 59 " | | %b0:\n"
66 " 58:4| 3: <10> | ret void;\n" 60 " 58:4| 3: <10> | ret void;\n"
67 " 60:2| 0: <65534> | }\n" 61 " 60:2| 0: <65534> | }\n"
68 " 64:0|0: <65534> |}\n" 62 " 64:0|0: <65534> |}\n"
69 "", 63 ;
70 DumpMunger.getTestResults()); 64
65 // Show that we can parse this code.
66 NaClObjDumpMunger DumpMunger(BitcodeRecords,
67 array_lengthof(BitcodeRecords), Terminator);
68
69 EXPECT_TRUE(DumpMunger.runTest("BadAbbreviationIndex assembly"));
70 EXPECT_EQ(ExpectedDump, DumpMunger.getTestResults());
71 71
72 // Shows what happens when we change the abbreviation index to an 72 // Shows what happens when we change the abbreviation index to an
73 // illegal value. 73 // illegal value.
74 const uint64_t ReplaceIndex = 3; // Index for TYPE_CODE_VOID;
74 const uint64_t AbbrevIndex4[] = { 75 const uint64_t AbbrevIndex4[] = {
75 ReplaceIndex, NaClMungedBitcode::Replace, 76 ReplaceIndex, NaClMungedBitcode::Replace,
76 4, naclbitc::TYPE_CODE_VOID, Terminator, 77 4, naclbitc::TYPE_CODE_VOID, Terminator,
77 }; 78 };
78 DumpMunger.setRunAsDeathTest(true); 79
79 EXPECT_DEATH( 80 // Show that by default, one can't write a bad abbreviation index.
81 {
82 NaClObjDumpMunger DumpMunger(BitcodeRecords,
83 array_lengthof(BitcodeRecords), Terminator);
84 DumpMunger.setRunAsDeathTest(true);
85 EXPECT_DEATH(
86 DumpMunger.runTest("Bad abbreviation index 4",
87 AbbrevIndex4, array_lengthof(AbbrevIndex4)),
88 ".*Error \\(Block 17\\)\\: Uses illegal abbreviation index\\:"
89 " 4\\: \\[2\\].*");
90 }
91
92 // Show that the corresponding error is generated when reading
93 // bitcode with a bad abbreviation index.
94 {
95 NaClObjDumpMunger DumpMunger(BitcodeRecords,
96 array_lengthof(BitcodeRecords), Terminator);
97 DumpMunger.setRunAsDeathTest(true);
98 DumpMunger.setWriteBadAbbrevIndex(true);
99 EXPECT_DEATH(
80 DumpMunger.runTest("Bad abbreviation index 4", 100 DumpMunger.runTest("Bad abbreviation index 4",
81 AbbrevIndex4, array_lengthof(AbbrevIndex4)), 101 AbbrevIndex4, array_lengthof(AbbrevIndex4)),
102 ".*Error \\(Block 17\\)\\: Uses illegal abbreviation index\\:"
103 " 4\\: \\[2\\].*"
82 ".*Fatal\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*"); 104 ".*Fatal\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*");
105 }
83 106
84 // Test that bitcode reader reports problem correctly. 107 // Test that bitcode reader reports problem correctly.
108 {
109 NaClParseBitcodeMunger Munger(BitcodeRecords,
110 array_lengthof(BitcodeRecords), Terminator);
111 Munger.setRunAsDeathTest(true);
112 Munger.setWriteBadAbbrevIndex(true);
113 EXPECT_DEATH(
114 Munger.runTest("Bad abbreviation index",
115 AbbrevIndex4, array_lengthof(AbbrevIndex4), true),
116 ".*Error \\(Block 17\\)\\: Uses illegal abbreviation index\\:"
117 " 4\\: \\[2\\].*"
118 ".*Fatal\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*");
119 }
120
121 // Show that error recovery works when dumping bitcode.
122 DumpMunger.setTryToRecoverOnWrite(true);
123 EXPECT_TRUE(
124 DumpMunger.runTest("Bad abbreviation index 4",
125 AbbrevIndex4, array_lengthof(AbbrevIndex4)));
126 std::string Results(
127 "Error (Block 17): Uses illegal abbreviation index: 4: [2]\n");
128 Results.append(ExpectedDump);
129 EXPECT_EQ(Results, DumpMunger.getTestResults());
130
131 // Show that error recovery works when parsing bitcode.
85 NaClParseBitcodeMunger Munger(BitcodeRecords, 132 NaClParseBitcodeMunger Munger(BitcodeRecords,
86 array_lengthof(BitcodeRecords), Terminator); 133 array_lengthof(BitcodeRecords), Terminator);
87 EXPECT_DEATH( 134 Munger.setTryToRecoverOnWrite(true);
88 Munger.runTest("Bad abbreviation index", 135 EXPECT_TRUE(
89 AbbrevIndex4, array_lengthof(AbbrevIndex4), true), 136 Munger.runTest("Bad abbreviation index 4",
90 ".*Fatal\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*"); 137 AbbrevIndex4, array_lengthof(AbbrevIndex4), true));
138 EXPECT_EQ(
139 "Error (Block 17): Uses illegal abbreviation index: 4: [2]\n"
140 "Successful parse!\n",
141 Munger.getTestResults());
91 } 142 }
92 143
93 } // end of anonymous namespace. 144 } // end of anonymous namespace.
OLDNEW
« no previous file with comments | « unittests/Bitcode/CMakeLists.txt ('k') | unittests/Bitcode/NaClMungedIoTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698