OLD | NEW |
---|---|
(Empty) | |
1 //===- llvm/unittest/Bitcode/NaClParseTypesTest.cpp ---------------------===// | |
2 // Tests objdump stream for PNaCl bitcode. | |
jvoung (off chromium)
2014/12/03 19:43:46
Tests ... parser ...
instead of "objdump stream"
Karl
2014/12/03 20:53:44
Done.
| |
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 record errors in the types block when parsing PNaCl bitcode. | |
12 | |
13 // TODO(kschimpf) Add more tests. | |
14 | |
15 #include "llvm/ADT/STLExtras.h" | |
16 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.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(NaClParseTypesTest, BadTypeReferences) { | |
jvoung (off chromium)
2014/12/03 19:43:47
Thanks for adding the test!
Karl
2014/12/03 20:53:44
Acknowledged.
| |
27 const uint64_t BitcodeRecords[] = { | |
28 1, 65535, 8, 2, Terminator, | |
29 1, 65535, 17, 2, Terminator, | |
30 3, 1, 2, Terminator, | |
31 3, 7, 32, Terminator, | |
32 3, 3, Terminator, | |
33 0, 65534, Terminator, | |
34 0, 65534, Terminator | |
35 }; | |
36 | |
37 const uint64_t ReplaceIndex = 4; | |
38 | |
39 // Show text of base input. | |
40 NaClObjDumpMunger BaseMunger(BitcodeRecords, | |
41 array_lengthof(BitcodeRecords), Terminator); | |
42 EXPECT_TRUE(BaseMunger.runTestForAssembly("Bad type references base")); | |
43 EXPECT_EQ( | |
44 "module { // BlockID = 8\n" | |
45 " types { // BlockID = 17\n" | |
46 " count 2;\n" | |
47 " @t0 = i32;\n" | |
48 " @t1 = float;\n" | |
49 " }\n" | |
50 "}\n", | |
51 BaseMunger.getTestResults()); | |
52 | |
53 // Show that we successfully parse the base input. | |
54 NaClParseBitcodeMunger Munger(BitcodeRecords, | |
55 array_lengthof(BitcodeRecords), Terminator); | |
56 EXPECT_TRUE(Munger.runTest("base parse", true)); | |
57 EXPECT_EQ( | |
58 "Successful parse!\n", | |
59 Munger.getTestResults()); | |
60 | |
61 // Show what happens when misdefining: @t1 = float" | |
62 const uint64_t AddSelfReference[] = { | |
63 ReplaceIndex, NaClBitcodeMunger::Replace, 3, 3, 1, Terminator | |
64 }; | |
65 EXPECT_FALSE(Munger.runTest( | |
66 "@t1 = float(1)", | |
67 AddSelfReference, array_lengthof(AddSelfReference), | |
68 false)); | |
69 EXPECT_EQ( | |
70 "Error: Record doesn't have expected size or structure\n", | |
71 Munger.getTestResults()); | |
72 EXPECT_FALSE(Munger.runTest( | |
73 "@t1 = float(1)", | |
74 AddSelfReference, array_lengthof(AddSelfReference), | |
75 true)); | |
76 EXPECT_EQ( | |
77 "Error: Invalid TYPE_CODE_FLOAT record\n" | |
78 "Error: Record doesn't have expected size or structure\n", | |
79 Munger.getTestResults()); | |
80 } | |
81 | |
82 } // end of anonamous namespace. | |
OLD | NEW |