blob: 74fcc989b45a2b4d9ff48a97f54a22c5f049ade2 [file] [log] [blame]
Duncan P. N. Exon Smithb036f1c2015-02-03 21:08:33 +00001//===- unittest/Support/DwarfTest.cpp - Dwarf support tests ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Support/Dwarf.h"
11#include "gtest/gtest.h"
12
13using namespace llvm;
14using namespace llvm::dwarf;
15
16namespace {
17
18TEST(DwarfTest, TagStringOnInvalid) {
19 // This is invalid, so it shouldn't be stringified.
20 EXPECT_EQ(nullptr, TagString(DW_TAG_invalid));
21
22 // These aren't really tags: they describe ranges within tags. They
23 // shouldn't be stringified either.
24 EXPECT_EQ(nullptr, TagString(DW_TAG_lo_user));
25 EXPECT_EQ(nullptr, TagString(DW_TAG_hi_user));
26 EXPECT_EQ(nullptr, TagString(DW_TAG_user_base));
27}
28
Duncan P. N. Exon Smith6f5546c2015-02-03 21:16:49 +000029TEST(DwarfTest, getTag) {
30 // A couple of valid tags.
31 EXPECT_EQ(DW_TAG_array_type, getTag("DW_TAG_array_type"));
32 EXPECT_EQ(DW_TAG_module, getTag("DW_TAG_module"));
33
34 // Invalid tags.
35 EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_invalid"));
36 EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_madeuptag"));
37 EXPECT_EQ(DW_TAG_invalid, getTag("something else"));
38
39 // Tag range markers should not be recognized.
40 EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_lo_user"));
41 EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_hi_user"));
42 EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_user_base"));
43}
44
Duncan P. N. Exon Smith3b631d22015-02-13 01:05:00 +000045TEST(DwarfTest, getOperationEncoding) {
46 // Some valid ops.
47 EXPECT_EQ(DW_OP_deref, getOperationEncoding("DW_OP_deref"));
48 EXPECT_EQ(DW_OP_bit_piece, getOperationEncoding("DW_OP_bit_piece"));
49
50 // Invalid ops.
51 EXPECT_EQ(0u, getOperationEncoding("DW_OP_otherthings"));
52 EXPECT_EQ(0u, getOperationEncoding("other"));
53
54 // Markers shouldn't be recognized.
55 EXPECT_EQ(0u, getOperationEncoding("DW_OP_lo_user"));
56 EXPECT_EQ(0u, getOperationEncoding("DW_OP_hi_user"));
57}
58
Duncan P. N. Exon Smith4031beb2015-02-06 22:34:48 +000059TEST(DwarfTest, LanguageStringOnInvalid) {
60 // This is invalid, so it shouldn't be stringified.
61 EXPECT_EQ(nullptr, LanguageString(0));
62
63 // These aren't really tags: they describe ranges within tags. They
64 // shouldn't be stringified either.
65 EXPECT_EQ(nullptr, LanguageString(DW_LANG_lo_user));
66 EXPECT_EQ(nullptr, LanguageString(DW_LANG_hi_user));
67}
68
Duncan P. N. Exon Smithd40af002015-02-06 22:55:13 +000069TEST(DwarfTest, getLanguage) {
70 // A couple of valid languages.
71 EXPECT_EQ(DW_LANG_C89, getLanguage("DW_LANG_C89"));
72 EXPECT_EQ(DW_LANG_C_plus_plus_11, getLanguage("DW_LANG_C_plus_plus_11"));
73 EXPECT_EQ(DW_LANG_OCaml, getLanguage("DW_LANG_OCaml"));
74 EXPECT_EQ(DW_LANG_Mips_Assembler, getLanguage("DW_LANG_Mips_Assembler"));
75
76 // Invalid languages.
77 EXPECT_EQ(0u, getLanguage("DW_LANG_invalid"));
78 EXPECT_EQ(0u, getLanguage("DW_TAG_array_type"));
79 EXPECT_EQ(0u, getLanguage("something else"));
80
81 // Language range markers should not be recognized.
82 EXPECT_EQ(0u, getLanguage("DW_LANG_lo_user"));
83 EXPECT_EQ(0u, getLanguage("DW_LANG_hi_user"));
84}
85
Duncan P. N. Exon Smith8d4eeb52015-02-06 23:44:24 +000086TEST(DwarfTest, AttributeEncodingStringOnInvalid) {
87 // This is invalid, so it shouldn't be stringified.
88 EXPECT_EQ(nullptr, AttributeEncodingString(0));
89
90 // These aren't really tags: they describe ranges within tags. They
91 // shouldn't be stringified either.
92 EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_lo_user));
93 EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_hi_user));
94}
95
Duncan P. N. Exon Smithe07f13a2015-02-06 23:46:49 +000096TEST(DwarfTest, getAttributeEncoding) {
97 // A couple of valid languages.
98 EXPECT_EQ(DW_ATE_boolean, getAttributeEncoding("DW_ATE_boolean"));
99 EXPECT_EQ(DW_ATE_imaginary_float,
100 getAttributeEncoding("DW_ATE_imaginary_float"));
101
102 // Invalid languages.
103 EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_invalid"));
104 EXPECT_EQ(0u, getAttributeEncoding("DW_TAG_array_type"));
105 EXPECT_EQ(0u, getAttributeEncoding("something else"));
106
107 // AttributeEncoding range markers should not be recognized.
108 EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_lo_user"));
109 EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_hi_user"));
110}
111
Duncan P. N. Exon Smithd6f35742015-02-07 00:36:23 +0000112TEST(DwarfTest, VirtualityString) {
Duncan P. N. Exon Smith7f95aac2015-02-07 01:07:30 +0000113 EXPECT_EQ(StringRef("DW_VIRTUALITY_none"),
114 VirtualityString(DW_VIRTUALITY_none));
115 EXPECT_EQ(StringRef("DW_VIRTUALITY_virtual"),
116 VirtualityString(DW_VIRTUALITY_virtual));
117 EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"),
Duncan P. N. Exon Smithd6f35742015-02-07 00:36:23 +0000118 VirtualityString(DW_VIRTUALITY_pure_virtual));
119
120 // DW_VIRTUALITY_max should be pure virtual.
Duncan P. N. Exon Smith7f95aac2015-02-07 01:07:30 +0000121 EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"),
122 VirtualityString(DW_VIRTUALITY_max));
Duncan P. N. Exon Smithd6f35742015-02-07 00:36:23 +0000123
124 // Invalid numbers shouldn't be stringified.
125 EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 1));
126 EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 77));
127}
128
Duncan P. N. Exon Smithe7e2abe2015-02-07 00:37:15 +0000129TEST(DwarfTest, getVirtuality) {
130 EXPECT_EQ(DW_VIRTUALITY_none, getVirtuality("DW_VIRTUALITY_none"));
131 EXPECT_EQ(DW_VIRTUALITY_virtual, getVirtuality("DW_VIRTUALITY_virtual"));
132 EXPECT_EQ(DW_VIRTUALITY_pure_virtual,
133 getVirtuality("DW_VIRTUALITY_pure_virtual"));
134
135 // Invalid strings.
136 EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_invalid"));
137 EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_max"));
138 EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("something else"));
139}
140
Duncan P. N. Exon Smithb036f1c2015-02-03 21:08:33 +0000141} // end namespace