1 //===- 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
13 using namespace llvm;
14 using namespace llvm::dwarf;
15
16 namespace {
17
TEST(DwarfTest,TagStringOnInvalid)18 TEST(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
TEST(DwarfTest,getTag)29 TEST(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
TEST(DwarfTest,getOperationEncoding)45 TEST(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
TEST(DwarfTest,LanguageStringOnInvalid)59 TEST(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
TEST(DwarfTest,getLanguage)69 TEST(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
TEST(DwarfTest,AttributeEncodingStringOnInvalid)86 TEST(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
TEST(DwarfTest,getAttributeEncoding)96 TEST(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
TEST(DwarfTest,VirtualityString)112 TEST(DwarfTest, VirtualityString) {
113 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"),
118 VirtualityString(DW_VIRTUALITY_pure_virtual));
119
120 // DW_VIRTUALITY_max should be pure virtual.
121 EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"),
122 VirtualityString(DW_VIRTUALITY_max));
123
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
TEST(DwarfTest,getVirtuality)129 TEST(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
141 } // end namespace
142