Chromium Code Reviews

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

Issue 770853002: Fix error reporting in the PNaCl bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix typo. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « unittests/Bitcode/NaClObjDumpTypesTest.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
(Empty)
1 //===- llvm/unittest/Bitcode/NaClParseTypesTest.cpp ---------------------===//
2 // Tests parser for PNaCl bitcode.
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) {
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.
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClObjDumpTypesTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine