OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 Google Inc. | |
2 // All rights reserved. | |
3 // | |
4 // Redistribution and use in source and binary forms, with or without | |
5 // modification, are permitted provided that the following conditions are | |
6 // met: | |
7 // | |
8 // * Redistributions of source code must retain the above copyright | |
9 // notice, this list of conditions and the following disclaimer. | |
10 // * Redistributions in binary form must reproduce the above | |
11 // copyright notice, this list of conditions and the following disclaimer | |
12 // in the documentation and/or other materials provided with the | |
13 // distribution. | |
14 // * Neither the name of Google Inc. nor the names of its | |
15 // contributors may be used to endorse or promote products derived from | |
16 // this software without specific prior written permission. | |
17 // | |
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | |
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | |
31 | |
32 // dwarf_line_to_module.cc: Unit tests for google_breakpad::DwarfLineToModule. | |
33 | |
34 #include "breakpad_googletest_includes.h" | |
35 #include "common/dwarf_line_to_module.h" | |
36 | |
37 using google_breakpad::DwarfLineToModule; | |
38 using google_breakpad::Module; | |
39 using google_breakpad::Module; | |
40 | |
41 TEST(Simple, One) { | |
42 Module m("name", "os", "architecture", "id"); | |
43 vector<Module::Line> lines; | |
44 DwarfLineToModule h(&m, &lines); | |
45 | |
46 h.DefineFile("file1", 0x30bf0f27, 0, 0, 0); | |
47 h.AddLine(0x6fd126fbf74f2680LL, 0x63c9a14cf556712bLL, 0x30bf0f27, | |
48 0x4c090cbf, 0x1cf9fe0d); | |
49 | |
50 vector<Module::File *> files; | |
51 m.GetFiles(&files); | |
52 EXPECT_EQ(1U, files.size()); | |
53 EXPECT_STREQ("file1", files[0]->name.c_str()); | |
54 | |
55 EXPECT_EQ(1U, lines.size()); | |
56 EXPECT_EQ(0x6fd126fbf74f2680ULL, lines[0].address); | |
57 EXPECT_EQ(0x63c9a14cf556712bULL, lines[0].size); | |
58 EXPECT_TRUE(lines[0].file == files[0]); | |
59 EXPECT_EQ(0x4c090cbf, lines[0].number); | |
60 } | |
61 | |
62 TEST(Simple, Many) { | |
63 Module m("name", "os", "architecture", "id"); | |
64 vector<Module::Line> lines; | |
65 DwarfLineToModule h(&m, &lines); | |
66 | |
67 h.DefineDir("directory1", 0x838299ab); | |
68 h.DefineDir("directory2", 0xf85de023); | |
69 h.DefineFile("file1", 0x2b80377a, 0x838299ab, 0, 0); | |
70 h.DefineFile("file1", 0x63beb4a4, 0xf85de023, 0, 0); | |
71 h.DefineFile("file2", 0x1d161d56, 0x838299ab, 0, 0); | |
72 h.DefineFile("file2", 0x1e7a667c, 0xf85de023, 0, 0); | |
73 h.AddLine(0x69900c5d553b7274ULL, 0x90fded183f0d0d3cULL, 0x2b80377a, | |
74 0x15b0f0a9U, 0x3ff5abd6U); | |
75 h.AddLine(0x45811219a39b7101ULL, 0x25a5e6a924afc41fULL, 0x63beb4a4, | |
76 0x4d259ce9U, 0x41c5ee32U); | |
77 h.AddLine(0xfa90514c1dc9704bULL, 0x0063efeabc02f313ULL, 0x1d161d56, | |
78 0x1ee9fa4fU, 0xbf70e46aU); | |
79 h.AddLine(0x556b55fb6a647b10ULL, 0x3f3089ca2bfd80f5ULL, 0x1e7a667c, | |
80 0x77fc280eU, 0x2c4a728cU); | |
81 h.DefineFile("file3", -1, 0, 0, 0); | |
82 h.AddLine(0xe2d72a37f8d9403aULL, 0x034dfab5b0d4d236ULL, 0x63beb4a5, | |
83 0x75047044U, 0xb6a0016cU); | |
84 | |
85 vector<Module::File *> files; | |
86 m.GetFiles(&files); | |
87 ASSERT_EQ(5U, files.size()); | |
88 EXPECT_STREQ("directory1/file1", files[0]->name.c_str()); | |
89 EXPECT_STREQ("directory1/file2", files[1]->name.c_str()); | |
90 EXPECT_STREQ("directory2/file1", files[2]->name.c_str()); | |
91 EXPECT_STREQ("directory2/file2", files[3]->name.c_str()); | |
92 EXPECT_STREQ("file3", files[4]->name.c_str()); | |
93 | |
94 ASSERT_EQ(5U, lines.size()); | |
95 | |
96 EXPECT_EQ(0x69900c5d553b7274ULL, lines[0].address); | |
97 EXPECT_EQ(0x90fded183f0d0d3cULL, lines[0].size); | |
98 EXPECT_TRUE(lines[0].file == files[0]); | |
99 EXPECT_EQ(0x15b0f0a9, lines[0].number); | |
100 | |
101 EXPECT_EQ(0x45811219a39b7101ULL, lines[1].address); | |
102 EXPECT_EQ(0x25a5e6a924afc41fULL, lines[1].size); | |
103 EXPECT_TRUE(lines[1].file == files[2]); | |
104 EXPECT_EQ(0x4d259ce9, lines[1].number); | |
105 | |
106 EXPECT_EQ(0xfa90514c1dc9704bULL, lines[2].address); | |
107 EXPECT_EQ(0x0063efeabc02f313ULL, lines[2].size); | |
108 EXPECT_TRUE(lines[2].file == files[1]); | |
109 EXPECT_EQ(0x1ee9fa4f, lines[2].number); | |
110 | |
111 EXPECT_EQ(0x556b55fb6a647b10ULL, lines[3].address); | |
112 EXPECT_EQ(0x3f3089ca2bfd80f5ULL, lines[3].size); | |
113 EXPECT_TRUE(lines[3].file == files[3]); | |
114 EXPECT_EQ(0x77fc280e, lines[3].number); | |
115 | |
116 EXPECT_EQ(0xe2d72a37f8d9403aULL, lines[4].address); | |
117 EXPECT_EQ(0x034dfab5b0d4d236ULL, lines[4].size); | |
118 EXPECT_TRUE(lines[4].file == files[4]); | |
119 EXPECT_EQ(0x75047044, lines[4].number); | |
120 } | |
121 | |
122 TEST(Filenames, Absolute) { | |
123 Module m("name", "os", "architecture", "id"); | |
124 vector<Module::Line> lines; | |
125 DwarfLineToModule h(&m, &lines); | |
126 | |
127 h.DefineDir("directory1", 1); | |
128 h.DefineFile("/absolute", 1, 1, 0, 0); | |
129 | |
130 h.AddLine(1, 1, 1, 0, 0); | |
131 | |
132 vector<Module::File *> files; | |
133 m.GetFiles(&files); | |
134 ASSERT_EQ(1U, files.size()); | |
135 EXPECT_STREQ("/absolute", files[0]->name.c_str()); | |
136 ASSERT_EQ(1U, lines.size()); | |
137 EXPECT_TRUE(lines[0].file == files[0]); | |
138 } | |
139 | |
140 TEST(Filenames, Relative) { | |
141 Module m("name", "os", "architecture", "id"); | |
142 vector<Module::Line> lines; | |
143 DwarfLineToModule h(&m, &lines); | |
144 | |
145 h.DefineDir("directory1", 1); | |
146 h.DefineFile("relative", 1, 1, 0, 0); | |
147 | |
148 h.AddLine(1, 1, 1, 0, 0); | |
149 | |
150 vector<Module::File *> files; | |
151 m.GetFiles(&files); | |
152 ASSERT_EQ(1U, files.size()); | |
153 EXPECT_STREQ("directory1/relative", files[0]->name.c_str()); | |
154 ASSERT_EQ(1U, lines.size()); | |
155 EXPECT_TRUE(lines[0].file == files[0]); | |
156 } | |
157 | |
158 TEST(Filenames, StrangeFile) { | |
159 Module m("name", "os", "architecture", "id"); | |
160 vector<Module::Line> lines; | |
161 DwarfLineToModule h(&m, &lines); | |
162 | |
163 h.DefineDir("directory1", 1); | |
164 h.DefineFile("", 1, 1, 0, 0); | |
165 h.AddLine(1, 1, 1, 0, 0); | |
166 | |
167 ASSERT_EQ(1U, lines.size()); | |
168 EXPECT_STREQ("directory1/", lines[0].file->name.c_str()); | |
169 } | |
170 | |
171 TEST(Filenames, StrangeDirectory) { | |
172 Module m("name", "os", "architecture", "id"); | |
173 vector<Module::Line> lines; | |
174 DwarfLineToModule h(&m, &lines); | |
175 | |
176 h.DefineDir("", 1); | |
177 h.DefineFile("file1", 1, 1, 0, 0); | |
178 h.AddLine(1, 1, 1, 0, 0); | |
179 | |
180 ASSERT_EQ(1U, lines.size()); | |
181 EXPECT_STREQ("/file1", lines[0].file->name.c_str()); | |
182 } | |
183 | |
184 TEST(Filenames, StrangeDirectoryAndFile) { | |
185 Module m("name", "os", "architecture", "id"); | |
186 vector<Module::Line> lines; | |
187 DwarfLineToModule h(&m, &lines); | |
188 | |
189 h.DefineDir("", 1); | |
190 h.DefineFile("", 1, 1, 0, 0); | |
191 h.AddLine(1, 1, 1, 0, 0); | |
192 | |
193 ASSERT_EQ(1U, lines.size()); | |
194 EXPECT_STREQ("/", lines[0].file->name.c_str()); | |
195 } | |
196 | |
197 // We should silently ignore attempts to define directory number zero, | |
198 // since that is always the compilation directory. | |
199 TEST(Errors, DirectoryZero) { | |
200 Module m("name", "os", "architecture", "id"); | |
201 vector<Module::Line> lines; | |
202 DwarfLineToModule h(&m, &lines); | |
203 | |
204 h.DefineDir("directory0", 0); // should be ignored | |
205 h.DefineFile("relative", 1, 0, 0, 0); | |
206 | |
207 h.AddLine(1, 1, 1, 0, 0); | |
208 | |
209 ASSERT_EQ(1U, lines.size()); | |
210 EXPECT_STREQ("relative", lines[0].file->name.c_str()); | |
211 } | |
212 | |
213 // We should refuse to add lines with bogus file numbers. We should | |
214 // produce only one warning, however. | |
215 TEST(Errors, BadFileNumber) { | |
216 Module m("name", "os", "architecture", "id"); | |
217 vector<Module::Line> lines; | |
218 DwarfLineToModule h(&m, &lines); | |
219 | |
220 h.DefineFile("relative", 1, 0, 0, 0); | |
221 h.AddLine(1, 1, 2, 0, 0); // bad file number | |
222 h.AddLine(2, 1, 2, 0, 0); // bad file number (no duplicate warning) | |
223 | |
224 EXPECT_EQ(0U, lines.size()); | |
225 } | |
226 | |
227 // We should treat files with bogus directory numbers as relative to | |
228 // the compilation unit. | |
229 TEST(Errors, BadDirectoryNumber) { | |
230 Module m("name", "os", "architecture", "id"); | |
231 vector<Module::Line> lines; | |
232 DwarfLineToModule h(&m, &lines); | |
233 | |
234 h.DefineDir("directory1", 1); | |
235 h.DefineFile("baddirnumber1", 1, 2, 0, 0); // bad directory number | |
236 h.DefineFile("baddirnumber2", 2, 2, 0, 0); // bad dir number (no warning) | |
237 h.AddLine(1, 1, 1, 0, 0); | |
238 | |
239 ASSERT_EQ(1U, lines.size()); | |
240 EXPECT_STREQ("baddirnumber1", lines[0].file->name.c_str()); | |
241 } | |
242 | |
243 // We promise not to report empty lines. | |
244 TEST(Errors, EmptyLine) { | |
245 Module m("name", "os", "architecture", "id"); | |
246 vector<Module::Line> lines; | |
247 DwarfLineToModule h(&m, &lines); | |
248 | |
249 h.DefineFile("filename1", 1, 0, 0, 0); | |
250 h.AddLine(1, 0, 1, 0, 0); | |
251 | |
252 ASSERT_EQ(0U, lines.size()); | |
253 } | |
254 | |
255 // We are supposed to clip lines that extend beyond the end of the | |
256 // address space. | |
257 TEST(Errors, BigLine) { | |
258 Module m("name", "os", "architecture", "id"); | |
259 vector<Module::Line> lines; | |
260 DwarfLineToModule h(&m, &lines); | |
261 | |
262 h.DefineFile("filename1", 1, 0, 0, 0); | |
263 h.AddLine(0xffffffffffffffffULL, 2, 1, 0, 0); | |
264 | |
265 ASSERT_EQ(1U, lines.size()); | |
266 EXPECT_EQ(1U, lines[0].size); | |
267 } | |
268 | |
269 // The 'Omitted' tests verify that we correctly omit line information | |
270 // for code in sections that the linker has dropped. See "GNU | |
271 // toolchain omitted sections support" at the top of the | |
272 // DwarfLineToModule class. | |
273 | |
274 TEST(Omitted, DroppedThenGood) { | |
275 Module m("name", "os", "architecture", "id"); | |
276 vector<Module::Line> lines; | |
277 DwarfLineToModule h(&m, &lines); | |
278 | |
279 h.DefineFile("filename1", 1, 0, 0, 0); | |
280 h.AddLine(0, 10, 1, 83816211, 0); // should be omitted | |
281 h.AddLine(20, 10, 1, 13059195, 0); // should be recorded | |
282 | |
283 ASSERT_EQ(1U, lines.size()); | |
284 EXPECT_EQ(13059195, lines[0].number); | |
285 } | |
286 | |
287 TEST(Omitted, GoodThenDropped) { | |
288 Module m("name", "os", "architecture", "id"); | |
289 vector<Module::Line> lines; | |
290 DwarfLineToModule h(&m, &lines); | |
291 | |
292 h.DefineFile("filename1", 1, 0, 0, 0); | |
293 h.AddLine(0x9dd6a372, 10, 1, 41454594, 0); // should be recorded | |
294 h.AddLine(0, 10, 1, 44793413, 0); // should be omitted | |
295 | |
296 ASSERT_EQ(1U, lines.size()); | |
297 EXPECT_EQ(41454594, lines[0].number); | |
298 } | |
299 | |
300 TEST(Omitted, Mix1) { | |
301 Module m("name", "os", "architecture", "id"); | |
302 vector<Module::Line> lines; | |
303 DwarfLineToModule h(&m, &lines); | |
304 | |
305 h.DefineFile("filename1", 1, 0, 0, 0); | |
306 h.AddLine(0x679ed72f, 10, 1, 58932642, 0); // should be recorded | |
307 h.AddLine(0xdfb5a72d, 10, 1, 39847385, 0); // should be recorded | |
308 h.AddLine(0, 0x78, 1, 23053829, 0); // should be omitted | |
309 h.AddLine(0x78, 0x6a, 1, 65317783, 0); // should be omitted | |
310 h.AddLine(0x78 + 0x6a, 0x2a, 1, 77601423, 0); // should be omitted | |
311 h.AddLine(0x9fe0cea5, 10, 1, 91806582, 0); // should be recorded | |
312 h.AddLine(0x7e41a109, 10, 1, 56169221, 0); // should be recorded | |
313 | |
314 ASSERT_EQ(4U, lines.size()); | |
315 EXPECT_EQ(58932642, lines[0].number); | |
316 EXPECT_EQ(39847385, lines[1].number); | |
317 EXPECT_EQ(91806582, lines[2].number); | |
318 EXPECT_EQ(56169221, lines[3].number); | |
319 } | |
320 | |
321 TEST(Omitted, Mix2) { | |
322 Module m("name", "os", "architecture", "id"); | |
323 vector<Module::Line> lines; | |
324 DwarfLineToModule h(&m, &lines); | |
325 | |
326 h.DefineFile("filename1", 1, 0, 0, 0); | |
327 h.AddLine(0, 0xf2, 1, 58802211, 0); // should be omitted | |
328 h.AddLine(0xf2, 0xb9, 1, 78958222, 0); // should be omitted | |
329 h.AddLine(0xf2 + 0xb9, 0xf7, 1, 64861892, 0); // should be omitted | |
330 h.AddLine(0x4e4d271e, 9, 1, 67355743, 0); // should be recorded | |
331 h.AddLine(0xdfb5a72d, 30, 1, 23365776, 0); // should be recorded | |
332 h.AddLine(0, 0x64, 1, 76196762, 0); // should be omitted | |
333 h.AddLine(0x64, 0x33, 1, 71066611, 0); // should be omitted | |
334 h.AddLine(0x64 + 0x33, 0xe3, 1, 61749337, 0); // should be omitted | |
335 | |
336 ASSERT_EQ(2U, lines.size()); | |
337 EXPECT_EQ(67355743, lines[0].number); | |
338 EXPECT_EQ(23365776, lines[1].number); | |
339 } | |
OLD | NEW |