Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- llvm/unittest/Bitcode/NaClAbbrevErrorTests.cpp ---------------------===// | |
| 2 // Tests parser for PNaCl bitcode instructions. | |
| 3 // | |
| 4 // The LLVM Compiler Infrastructure | |
| 5 // | |
| 6 // This file is distributed under the University of Illinois Open Source | |
| 7 // License. See LICENSE.TXT for details. | |
| 8 // | |
| 9 //===----------------------------------------------------------------------===// | |
| 10 | |
| 11 // Tests errors on bad abbreviation index. | |
| 12 | |
| 13 #include "llvm/ADT/STLExtras.h" | |
| 14 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h" | |
| 15 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | |
| 16 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | |
| 17 | |
| 18 #include "gtest/gtest.h" | |
| 19 | |
| 20 using namespace llvm; | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 static const uint64_t Terminator = 0x5768798008978675LL; | |
| 25 | |
| 26 /// Test if we handle badly defined abbreviation indices. | |
| 27 TEST(MyDeathNaClOtherParseTest, BadAbbreviationIndex) { | |
|
jvoung (off chromium)
2015/02/23 18:58:56
Could rename "MyDeathNaClOtherParseTest" to someth
Karl
2015/02/23 20:46:23
Done.
| |
| 28 const uint64_t BitcodeRecords[] = { | |
| 29 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 2, Terminator, | |
| 30 1, naclbitc::BLK_CODE_ENTER, naclbitc::TYPE_BLOCK_ID_NEW, 3, Terminator, | |
| 31 3, naclbitc::TYPE_CODE_NUMENTRY, 2, Terminator, | |
| 32 3, naclbitc::TYPE_CODE_VOID, Terminator, | |
| 33 3, naclbitc::TYPE_CODE_FUNCTION, 0, 0, Terminator, | |
| 34 0, naclbitc::BLK_CODE_EXIT, Terminator, | |
| 35 3, naclbitc::MODULE_CODE_FUNCTION, 1, 0, 0, 0, Terminator, | |
| 36 1, naclbitc::BLK_CODE_ENTER, naclbitc::FUNCTION_BLOCK_ID, 2, Terminator, | |
| 37 3, naclbitc::FUNC_CODE_DECLAREBLOCKS, 1, Terminator, | |
| 38 3, naclbitc::FUNC_CODE_INST_RET, Terminator, | |
| 39 0, naclbitc::BLK_CODE_EXIT, Terminator, | |
| 40 0, naclbitc::BLK_CODE_EXIT, Terminator | |
| 41 }; | |
| 42 | |
| 43 const uint64_t ReplaceIndex = 3; // Index for TYPE_CODE_VOID; | |
| 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, " | |
| 51 "88, 69)\n" | |
| 52 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n" | |
| 53 " | 0> |\n" | |
| 54 " 16:0|1: <65535, 8, 2> |module { // BlockID = 8\n" | |
| 55 " 24:0| 1: <65535, 17, 3> | types { // BlockID = 17\n" | |
| 56 " 32:0| 3: <1, 2> | count 2;\n" | |
| 57 " 34:5| 3: <2> | @t0 = void;\n" | |
| 58 " 36:4| 3: <21, 0, 0> | @t1 = void ();\n" | |
| 59 " 39:7| 0: <65534> | }\n" | |
| 60 " 44:0| 3: <8, 1, 0, 0, 0> | define external void @f0();\n" | |
| 61 " 48:6| 1: <65535, 12, 2> | function void @f0() { \n" | |
| 62 " | | // BlockID " | |
| 63 "= 12\n" | |
| 64 " 56:0| 3: <1, 1> | blocks 1;\n" | |
| 65 " | | %b0:\n" | |
| 66 " 58:4| 3: <10> | ret void;\n" | |
| 67 " 60:2| 0: <65534> | }\n" | |
| 68 " 64:0|0: <65534> |}\n" | |
| 69 "", | |
| 70 DumpMunger.getTestResults()); | |
| 71 | |
| 72 // Shows what happens when we change the abbreviation index to an | |
| 73 // illegal value. | |
| 74 const uint64_t AbbrevIndex4[] = { | |
| 75 ReplaceIndex, NaClBitcodeMunger::Replace, | |
| 76 4, naclbitc::TYPE_CODE_VOID, Terminator, | |
| 77 }; | |
| 78 DumpMunger.setRunAsDeathTest(true); | |
| 79 EXPECT_DEATH( | |
| 80 DumpMunger.runTest("Bad abbreviation index 4", | |
| 81 AbbrevIndex4, array_lengthof(AbbrevIndex4)), | |
| 82 ".*Error\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*"); | |
| 83 | |
| 84 // Test that bitcode reader reports problem correctly. | |
| 85 NaClParseBitcodeMunger Munger(BitcodeRecords, | |
| 86 array_lengthof(BitcodeRecords), Terminator); | |
| 87 EXPECT_DEATH( | |
| 88 Munger.runTest("Bad abbreviation index", | |
| 89 AbbrevIndex4, array_lengthof(AbbrevIndex4), true), | |
| 90 ".*Error\\(35\\:0\\)\\: Invalid abbreviation \\# 4 defined for record.*"); | |
| 91 } | |
| 92 | |
| 93 } // end of anonymous namespace. | |
| OLD | NEW |