OLD | NEW |
1 //===- llvm/unittest/Bitcode/NaClCompressTests.cpp ------------------------===// | 1 //===- llvm/unittest/Bitcode/NaClCompressTests.cpp ------------------------===// |
2 // Tests pnacl compression of bitcode files. | 2 // Tests pnacl compression of bitcode files. |
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 |
11 #include "llvm/ADT/STLExtras.h" | 11 #include "NaClMungeTest.h" |
12 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h" | 12 |
13 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" | |
14 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | 13 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" |
15 | 14 |
16 #include "gtest/gtest.h" | |
17 | |
18 using namespace llvm; | 15 using namespace llvm; |
19 | 16 |
20 namespace { | 17 namespace naclmungetest { |
21 | |
22 static const uint64_t Terminator = 0x5768798008978675LL; | |
23 | 18 |
24 // Note: Tests fix for bug in | 19 // Note: Tests fix for bug in |
25 // https://code.google.com/p/nativeclient/issues/detail?id=4104 | 20 // https://code.google.com/p/nativeclient/issues/detail?id=4104 |
26 TEST(NaClCompressTests, FixedModuleAbbrevIdBug) { | 21 TEST(NaClCompressTests, FixedModuleAbbrevIdBug) { |
27 const uint64_t BitcodeRecords[] = { | 22 const uint64_t BitcodeRecords[] = { |
28 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 4, Terminator, | 23 1, naclbitc::BLK_CODE_ENTER, naclbitc::MODULE_BLOCK_ID, 4, Terminator, |
29 // Note: We need at least one module abbreviation to activate bug. | 24 // Note: We need at least one module abbreviation to activate bug. |
30 2, naclbitc::BLK_CODE_DEFINE_ABBREV, 2, | 25 2, naclbitc::BLK_CODE_DEFINE_ABBREV, 2, |
31 0, NaClBitCodeAbbrevOp::Array, | 26 0, NaClBitCodeAbbrevOp::Array, |
32 0, NaClBitCodeAbbrevOp::VBR, 6, | 27 0, NaClBitCodeAbbrevOp::VBR, 6, |
33 Terminator, | 28 Terminator, |
34 // Note: We need at least one record in the module that can introduce | 29 // Note: We need at least one record in the module that can introduce |
35 // a new abbreviation and cause the bug. | 30 // a new abbreviation and cause the bug. |
36 4, naclbitc::MODULE_CODE_VERSION, 1, Terminator, | 31 4, naclbitc::MODULE_CODE_VERSION, 1, Terminator, |
37 1, naclbitc::BLK_CODE_ENTER, 17, 4, Terminator, | 32 1, naclbitc::BLK_CODE_ENTER, 17, 4, Terminator, |
38 3, naclbitc::TYPE_CODE_NUMENTRY, 0, Terminator, | 33 3, naclbitc::TYPE_CODE_NUMENTRY, 0, Terminator, |
39 0, naclbitc::BLK_CODE_EXIT, Terminator, | 34 0, naclbitc::BLK_CODE_EXIT, Terminator, |
40 0, naclbitc::BLK_CODE_EXIT, Terminator, | 35 0, naclbitc::BLK_CODE_EXIT, Terminator, |
41 }; | 36 }; |
42 | 37 |
43 // Show textual version of sample input. | 38 // Show textual version of sample input. |
44 NaClObjDumpMunger DumpMunger(BitcodeRecords, | 39 NaClObjDumpMunger DumpMunger(ARRAY_TERM(BitcodeRecords)); |
45 array_lengthof(BitcodeRecords), Terminator); | 40 EXPECT_TRUE(DumpMunger.runTest()); |
46 EXPECT_TRUE(DumpMunger.runTest("Test fixed module abbreviation ID bug")); | |
47 EXPECT_EQ( | 41 EXPECT_EQ( |
48 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 8" | 42 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 8" |
49 "8, 69)\n" | 43 "8, 69)\n" |
50 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n" | 44 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n" |
51 " | 0> |\n" | 45 " | 0> |\n" |
52 " 16:0|1: <65535, 8, 4> |module { // BlockID = 8\n" | 46 " 16:0|1: <65535, 8, 4> |module { // BlockID = 8\n" |
53 " 24:0| 2: <65533, 2, 0, 3, 0, 2, 6| %a0 = abbrev <array(vbr(6))>;" | 47 " 24:0| 2: <65533, 2, 0, 3, 0, 2, 6| %a0 = abbrev <array(vbr(6))>;" |
54 "\n" | 48 "\n" |
55 " | > |\n" | 49 " | > |\n" |
56 " 26:6| 4: <1, 1> | version 1; <%a0>\n" | 50 " 26:6| 4: <1, 1> | version 1; <%a0>\n" |
57 " 29:4| 1: <65535, 17, 4> | types { // BlockID = 17\n" | 51 " 29:4| 1: <65535, 17, 4> | types { // BlockID = 17\n" |
58 " 36:0| 3: <1, 0> | count 0;\n" | 52 " 36:0| 3: <1, 0> | count 0;\n" |
59 " 38:6| 0: <65534> | }\n" | 53 " 38:6| 0: <65534> | }\n" |
60 " 40:0|0: <65534> |}\n", | 54 " 40:0|0: <65534> |}\n", |
61 DumpMunger.getTestResults()); | 55 DumpMunger.getTestResults()); |
62 | 56 |
63 // Show that we can compress as well. | 57 // Show that we can compress as well. |
64 NaClCompressMunger CompressMunger(BitcodeRecords, | 58 NaClCompressMunger CompressMunger(BitcodeRecords, |
65 array_lengthof(BitcodeRecords), Terminator); | 59 array_lengthof(BitcodeRecords), Terminator); |
66 EXPECT_TRUE(CompressMunger.runTest("Test fixed module abbreviation ID bug")); | 60 EXPECT_TRUE(CompressMunger.runTest()); |
67 } | 61 } |
68 | 62 |
69 } | 63 } // end of namespace naclmungetest |
OLD | NEW |