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

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

Issue 1310883003: Install notion of diagnostic handler into PNaCl bitcode readers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 3 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
OLDNEW
1 //===- llvm/unittest/Bitcode/NaClParseInstsTest.cpp ----------------------===// 1 //===- llvm/unittest/Bitcode/NaClParseInstsTest.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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 " 66:4| 3: <34, 0, 4, 2, 100> | call void @f0(i32 %p0, i32" 76 " 66:4| 3: <34, 0, 4, 2, 100> | call void @f0(i32 %p0, i32"
77 " @f0);\n" 77 " @f0);\n"
78 "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n" 78 "Error(66:4): Invalid relative value id: 100 (Must be <= 4)\n"
79 " 72:6| 3: <10> | ret void;\n" 79 " 72:6| 3: <10> | ret void;\n"
80 " 74:4| 0: <65534> | }\n" 80 " 74:4| 0: <65534> | }\n"
81 " 76:0|0: <65534> |}\n", 81 " 76:0|0: <65534> |}\n",
82 DumpMunger.getTestResults()); 82 DumpMunger.getTestResults());
83 83
84 NaClParseBitcodeMunger Munger(ARRAY_TERM(BitcodeRecords)); 84 NaClParseBitcodeMunger Munger(ARRAY_TERM(BitcodeRecords));
85 EXPECT_FALSE(Munger.runTest(true)); 85 EXPECT_FALSE(Munger.runTest(true));
86 EXPECT_EQ( 86 EXPECT_EQ("Invalid call argument: Index 1\n"
87 "Error(72:6): Invalid call argument: Index 1\n" 87 "Corrupted bitcode\n",
88 "Error: Invalid value in record\n", 88 stripErrorPrefix(Munger.getTestResults()));
89 Munger.getTestResults());
90 } 89 }
91 90
92 /// Test how we recognize alignments in alloca instructions. 91 /// Test how we recognize alignments in alloca instructions.
93 TEST(NaClParseInstsTests, BadAllocaAlignment) { 92 TEST(NaClParseInstsTests, BadAllocaAlignment) {
94 const uint64_t BitcodeRecords[] = { 93 const uint64_t BitcodeRecords[] = {
95 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 2, Terminator, 94 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 2, Terminator,
96 1, naclbitc::BLK_CODE_ENTER, naclbitc::TYPE_BLOCK_ID_NEW, 2, Terminator, 95 1, naclbitc::BLK_CODE_ENTER, naclbitc::TYPE_BLOCK_ID_NEW, 2, Terminator,
97 3, naclbitc::TYPE_CODE_NUMENTRY, 4, Terminator, 96 3, naclbitc::TYPE_CODE_NUMENTRY, 4, Terminator,
98 3, naclbitc::TYPE_CODE_INTEGER, 32, Terminator, 97 3, naclbitc::TYPE_CODE_INTEGER, 32, Terminator,
99 3, naclbitc::TYPE_CODE_VOID, Terminator, 98 3, naclbitc::TYPE_CODE_VOID, Terminator,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 EXPECT_EQ( 153 EXPECT_EQ(
155 " %v0 = alloca i8, i32 %p0, align 0;\n", 154 " %v0 = alloca i8, i32 %p0, align 0;\n",
156 DumpMunger.getLinesWithSubstring("alloca")); 155 DumpMunger.getLinesWithSubstring("alloca"));
157 156
158 // Show what happens when changing alignment to 2**30. 157 // Show what happens when changing alignment to 2**30.
159 const uint64_t Align30[] = { 158 const uint64_t Align30[] = {
160 ReplaceIndex, NaClMungedBitcode::Replace, 159 ReplaceIndex, NaClMungedBitcode::Replace,
161 3, naclbitc::FUNC_CODE_INST_ALLOCA, 1, getEncAlignPower(30), Terminator, 160 3, naclbitc::FUNC_CODE_INST_ALLOCA, 1, getEncAlignPower(30), Terminator,
162 }; 161 };
163 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true)); 162 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true));
164 EXPECT_EQ( 163 EXPECT_EQ("Alignment can't be greater than 2**29. Found: 2**30\n"
165 "Error(65:6): Alignment can't be greater than 2**29. Found: 2**30\n" 164 "Corrupted bitcode\n",
166 "Error: Invalid value in record\n", 165 stripErrorPrefix(Munger.getTestResults()));
167 Munger.getTestResults());
168 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30))); 166 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30)));
169 EXPECT_EQ( 167 EXPECT_EQ(
170 " %v0 = alloca i8, i32 %p0, align 0;\n", 168 " %v0 = alloca i8, i32 %p0, align 0;\n",
171 DumpMunger.getLinesWithSubstring("alloca")); 169 DumpMunger.getLinesWithSubstring("alloca"));
172 EXPECT_EQ( 170 EXPECT_EQ(
173 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n", 171 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n",
174 DumpMunger.getLinesWithSubstring("Error")); 172 DumpMunger.getLinesWithSubstring("Error"));
175 173
176 // Show what happens when changing alignment to 2**29. 174 // Show what happens when changing alignment to 2**29.
177 const uint64_t Align29[] = { 175 const uint64_t Align29[] = {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 " %v0 = load i32* %p0, align 536870912;\n" 276 " %v0 = load i32* %p0, align 536870912;\n"
279 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n", 277 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n",
280 DumpMunger.getLinesWithSubstring("load")); 278 DumpMunger.getLinesWithSubstring("load"));
281 279
282 // Show what happens when changing alignment to 2**30. 280 // Show what happens when changing alignment to 2**30.
283 const uint64_t Align30[] = { 281 const uint64_t Align30[] = {
284 ReplaceIndex, NaClMungedBitcode::Replace, 282 ReplaceIndex, NaClMungedBitcode::Replace,
285 3, naclbitc::FUNC_CODE_INST_LOAD, 1, getEncAlignPower(30), 0, Terminator, 283 3, naclbitc::FUNC_CODE_INST_LOAD, 1, getEncAlignPower(30), 0, Terminator,
286 }; 284 };
287 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true)); 285 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true));
288 EXPECT_EQ( 286 EXPECT_EQ("Alignment can't be greater than 2**29. Found: 2**30\n"
289 "Error(62:4): Alignment can't be greater than 2**29. Found: 2**30\n" 287 "Corrupted bitcode\n",
290 "Error: Invalid value in record\n", 288 stripErrorPrefix(Munger.getTestResults()));
291 Munger.getTestResults());
292 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30))); 289 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30)));
293 EXPECT_EQ( 290 EXPECT_EQ(
294 " %v0 = load i32* %p0, align 0;\n" 291 " %v0 = load i32* %p0, align 0;\n"
295 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n", 292 "Error(58:4): load: Illegal alignment for i32. Expects: 1\n",
296 DumpMunger.getLinesWithSubstring("load")); 293 DumpMunger.getLinesWithSubstring("load"));
297 } 294 }
298 295
299 // Test how we recognize alignments in store instructions. 296 // Test how we recognize alignments in store instructions.
300 TEST(NaClParseInstsTests, BadStoreAlignment) { 297 TEST(NaClParseInstsTests, BadStoreAlignment) {
301 const uint64_t BitcodeRecords[] = { 298 const uint64_t BitcodeRecords[] = {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 " store float %p1, float* %p0, align 536870912;\n" 395 " store float %p1, float* %p0, align 536870912;\n"
399 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n", 396 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n",
400 DumpMunger.getLinesWithSubstring("store")); 397 DumpMunger.getLinesWithSubstring("store"));
401 398
402 // Show what happens when changing alignment to 2**30. 399 // Show what happens when changing alignment to 2**30.
403 const uint64_t Align30[] = { 400 const uint64_t Align30[] = {
404 ReplaceIndex, NaClMungedBitcode::Replace, 401 ReplaceIndex, NaClMungedBitcode::Replace,
405 3, naclbitc::FUNC_CODE_INST_STORE, 2, 1, getEncAlignPower(30), Terminator, 402 3, naclbitc::FUNC_CODE_INST_STORE, 2, 1, getEncAlignPower(30), Terminator,
406 }; 403 };
407 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true)); 404 EXPECT_FALSE(Munger.runTest(ARRAY(Align30), true));
408 EXPECT_EQ( 405 EXPECT_EQ("Alignment can't be greater than 2**29. Found: 2**30\n"
409 "Error(66:4): Alignment can't be greater than 2**29. Found: 2**30\n" 406 "Corrupted bitcode\n",
410 "Error: Invalid value in record\n", 407 stripErrorPrefix(Munger.getTestResults()));
411 Munger.getTestResults());
412 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30))); 408 EXPECT_FALSE(DumpMunger.runTestForAssembly(ARRAY(Align30)));
413 EXPECT_EQ( 409 EXPECT_EQ(
414 " store float %p1, float* %p0, align 0;\n" 410 " store float %p1, float* %p0, align 0;\n"
415 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n", 411 "Error(62:4): store: Illegal alignment for float. Expects: 1 or 4\n",
416 DumpMunger.getLinesWithSubstring("store")); 412 DumpMunger.getLinesWithSubstring("store"));
417 } 413 }
418 414
419 } // end of namespace naclmungetest 415 } // end of namespace naclmungetest
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClMungeWriteErrorTests.cpp ('k') | unittests/Bitcode/NaClParseTypesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698