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

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

Issue 1140153004: Clean up bitcode munging tests. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. 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/NaClParseInstsTest.cpp ('k') | no next file » | 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/NaClParseTypesTest.cpp ---------------------===// 1 //===- llvm/unittest/Bitcode/NaClParseTypesTest.cpp ---------------------===//
2 // Tests parser for PNaCl bitcode. 2 // Tests parser for PNaCl bitcode.
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 // Tests record errors in the types block when parsing PNaCl bitcode. 11 // Tests record errors in the types block when parsing PNaCl bitcode.
12 12
13 // TODO(kschimpf) Add more tests. 13 // TODO(kschimpf) Add more tests.
14 14
15 #include "llvm/ADT/STLExtras.h" 15 #include "NaClMungeTest.h"
16 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h"
17
18 #include "gtest/gtest.h"
19 16
20 using namespace llvm; 17 using namespace llvm;
21 18
22 namespace { 19 namespace naclmungetest {
23
24 static const uint64_t Terminator = 0x5768798008978675LL;
25 20
26 TEST(NaClParseTypesTest, BadTypeReferences) { 21 TEST(NaClParseTypesTest, BadTypeReferences) {
27 const uint64_t BitcodeRecords[] = { 22 const uint64_t BitcodeRecords[] = {
28 1, 65535, 8, 2, Terminator, 23 1, 65535, 8, 2, Terminator,
29 1, 65535, 17, 2, Terminator, 24 1, 65535, 17, 2, Terminator,
30 3, 1, 2, Terminator, 25 3, 1, 2, Terminator,
31 3, 7, 32, Terminator, 26 3, 7, 32, Terminator,
32 3, 3, Terminator, 27 3, 3, Terminator,
33 0, 65534, Terminator, 28 0, 65534, Terminator,
34 0, 65534, Terminator 29 0, 65534, Terminator
35 }; 30 };
36 31
37 const uint64_t ReplaceIndex = 4; 32 const uint64_t ReplaceIndex = 4;
38 33
39 // Show text of base input. 34 // Show text of base input.
40 NaClObjDumpMunger BaseMunger(BitcodeRecords, 35 NaClObjDumpMunger BaseMunger(ARRAY_TERM(BitcodeRecords));
41 array_lengthof(BitcodeRecords), Terminator); 36 EXPECT_TRUE(BaseMunger.runTest());
42 EXPECT_TRUE(BaseMunger.runTest("Bad type references base"));
43 EXPECT_EQ( 37 EXPECT_EQ(
44 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, " 38 " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, "
45 "88, 69)\n" 39 "88, 69)\n"
46 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n" 40 " | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2\n"
47 " | 0> |\n" 41 " | 0> |\n"
48 " 16:0|1: <65535, 8, 2> |module { // BlockID = 8\n" 42 " 16:0|1: <65535, 8, 2> |module { // BlockID = 8\n"
49 " 24:0| 1: <65535, 17, 2> | types { // BlockID = 17\n" 43 " 24:0| 1: <65535, 17, 2> | types { // BlockID = 17\n"
50 " 32:0| 3: <1, 2> | count 2;\n" 44 " 32:0| 3: <1, 2> | count 2;\n"
51 " 34:4| 3: <7, 32> | @t0 = i32;\n" 45 " 34:4| 3: <7, 32> | @t0 = i32;\n"
52 " 37:6| 3: <3> | @t1 = float;\n" 46 " 37:6| 3: <3> | @t1 = float;\n"
53 " 39:4| 0: <65534> | }\n" 47 " 39:4| 0: <65534> | }\n"
54 " 40:0|0: <65534> |}\n", 48 " 40:0|0: <65534> |}\n",
55 BaseMunger.getTestResults()); 49 BaseMunger.getTestResults());
56 50
57 // Show that we successfully parse the base input. 51 // Show that we successfully parse the base input.
58 NaClParseBitcodeMunger Munger(BitcodeRecords, 52 NaClParseBitcodeMunger Munger(ARRAY_TERM(BitcodeRecords));
59 array_lengthof(BitcodeRecords), Terminator); 53 EXPECT_TRUE(Munger.runTest(true));
60 EXPECT_TRUE(Munger.runTest("base parse", true));
61 EXPECT_EQ( 54 EXPECT_EQ(
62 "Successful parse!\n", 55 "Successful parse!\n",
63 Munger.getTestResults()); 56 Munger.getTestResults());
64 57
65 // Show what happens when misdefining: @t1 = float" 58 // Show what happens when misdefining: @t1 = float"
66 const uint64_t AddSelfReference[] = { 59 const uint64_t AddSelfReference[] = {
67 ReplaceIndex, NaClMungedBitcode::Replace, 3, 3, 1, Terminator 60 ReplaceIndex, NaClMungedBitcode::Replace, 3, 3, 1, Terminator
68 }; 61 };
69 EXPECT_FALSE(Munger.runTest( 62 EXPECT_FALSE(Munger.runTest(ARRAY(AddSelfReference), false));
70 "@t1 = float(1)",
71 AddSelfReference, array_lengthof(AddSelfReference),
72 false));
73 EXPECT_EQ( 63 EXPECT_EQ(
74 "Error: Record doesn't have expected size or structure\n", 64 "Error: Record doesn't have expected size or structure\n",
75 Munger.getTestResults()); 65 Munger.getTestResults());
76 EXPECT_FALSE(Munger.runTest( 66 EXPECT_FALSE(Munger.runTest(ARRAY(AddSelfReference), true));
77 "@t1 = float(1)",
78 AddSelfReference, array_lengthof(AddSelfReference),
79 true));
80 EXPECT_EQ( 67 EXPECT_EQ(
81 "Error(40:2): Invalid TYPE_CODE_FLOAT record\n" 68 "Error(40:2): Invalid TYPE_CODE_FLOAT record\n"
82 "Error: Record doesn't have expected size or structure\n", 69 "Error: Record doesn't have expected size or structure\n",
83 Munger.getTestResults()); 70 Munger.getTestResults());
84 } 71 }
85 72
86 } // end of anonamous namespace. 73 } // end of namespace naclmungetest
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClParseInstsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698