OLD | NEW |
1 // Copyright (c) 2010 Google Inc. | 1 // Copyright (c) 2010 Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | 30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
31 | 31 |
32 // dwarf_cu_to_module.cc: Unit tests for google_breakpad::DwarfCUToModule. | 32 // dwarf_cu_to_module.cc: Unit tests for google_breakpad::DwarfCUToModule. |
33 | 33 |
| 34 #include <stdint.h> |
| 35 |
34 #include <string> | 36 #include <string> |
35 #include <utility> | 37 #include <utility> |
36 #include <vector> | 38 #include <vector> |
37 | 39 |
38 #include "breakpad_googletest_includes.h" | 40 #include "breakpad_googletest_includes.h" |
39 #include "common/dwarf_cu_to_module.h" | 41 #include "common/dwarf_cu_to_module.h" |
40 #include "common/using_std_string.h" | 42 #include "common/using_std_string.h" |
41 | 43 |
42 using std::make_pair; | 44 using std::make_pair; |
43 using std::vector; | 45 using std::vector; |
(...skipping 14 matching lines...) Expand all Loading... |
58 using ::testing::Test; | 60 using ::testing::Test; |
59 using ::testing::TestWithParam; | 61 using ::testing::TestWithParam; |
60 using ::testing::Values; | 62 using ::testing::Values; |
61 using ::testing::ValuesIn; | 63 using ::testing::ValuesIn; |
62 | 64 |
63 // Mock classes. | 65 // Mock classes. |
64 | 66 |
65 class MockLineToModuleHandler: public DwarfCUToModule::LineToModuleHandler { | 67 class MockLineToModuleHandler: public DwarfCUToModule::LineToModuleHandler { |
66 public: | 68 public: |
67 MOCK_METHOD1(StartCompilationUnit, void(const string& compilation_dir)); | 69 MOCK_METHOD1(StartCompilationUnit, void(const string& compilation_dir)); |
68 MOCK_METHOD4(ReadProgram, void(const char* program, uint64 length, | 70 MOCK_METHOD4(ReadProgram, void(const uint8_t *program, uint64 length, |
69 Module *module, vector<Module::Line> *lines)); | 71 Module *module, vector<Module::Line> *lines)); |
70 }; | 72 }; |
71 | 73 |
72 class MockWarningReporter: public DwarfCUToModule::WarningReporter { | 74 class MockWarningReporter: public DwarfCUToModule::WarningReporter { |
73 public: | 75 public: |
74 MockWarningReporter(const string &filename, uint64 cu_offset) | 76 MockWarningReporter(const string &filename, uint64 cu_offset) |
75 : DwarfCUToModule::WarningReporter(filename, cu_offset) { } | 77 : DwarfCUToModule::WarningReporter(filename, cu_offset) { } |
76 MOCK_METHOD1(SetCUName, void(const string &name)); | 78 MOCK_METHOD1(SetCUName, void(const string &name)); |
77 MOCK_METHOD2(UnknownSpecification, void(uint64 offset, uint64 target)); | 79 MOCK_METHOD2(UnknownSpecification, void(uint64 offset, uint64 target)); |
78 MOCK_METHOD2(UnknownAbstractOrigin, void(uint64 offset, uint64 target)); | 80 MOCK_METHOD2(UnknownAbstractOrigin, void(uint64 offset, uint64 target)); |
(...skipping 25 matching lines...) Expand all Loading... |
104 // | 106 // |
105 // MockLineToModuleHandler l2m; | 107 // MockLineToModuleHandler l2m; |
106 // EXPECT_CALL(l2m, ReadProgram(_,_,_,_)) | 108 // EXPECT_CALL(l2m, ReadProgram(_,_,_,_)) |
107 // .WillOnce(DoAll(Invoke(appender), Return())); | 109 // .WillOnce(DoAll(Invoke(appender), Return())); |
108 // | 110 // |
109 // in which case calling l2m with some line vector will append lines. | 111 // in which case calling l2m with some line vector will append lines. |
110 class AppendLinesFunctor { | 112 class AppendLinesFunctor { |
111 public: | 113 public: |
112 explicit AppendLinesFunctor( | 114 explicit AppendLinesFunctor( |
113 const vector<Module::Line> *lines) : lines_(lines) { } | 115 const vector<Module::Line> *lines) : lines_(lines) { } |
114 void operator()(const char *program, uint64 length, | 116 void operator()(const uint8_t *program, uint64 length, |
115 Module *module, vector<Module::Line> *lines) { | 117 Module *module, vector<Module::Line> *lines) { |
116 lines->insert(lines->end(), lines_->begin(), lines_->end()); | 118 lines->insert(lines->end(), lines_->begin(), lines_->end()); |
117 } | 119 } |
118 private: | 120 private: |
119 const vector<Module::Line> *lines_; | 121 const vector<Module::Line> *lines_; |
120 }; | 122 }; |
121 | 123 |
122 CUFixtureBase() | 124 CUFixtureBase() |
123 : module_("module-name", "module-os", "module-arch", "module-id"), | 125 : module_("module-name", "module-os", "module-arch", "module-id"), |
124 file_context_("dwarf-filename", &module_, true), | 126 file_context_("dwarf-filename", &module_, true), |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 string compilation_dir_; | 280 string compilation_dir_; |
279 | 281 |
280 // If this is not empty, we'll give the CU a DW_AT_stmt_list | 282 // If this is not empty, we'll give the CU a DW_AT_stmt_list |
281 // attribute that, when passed to line_reader_, adds these lines to the | 283 // attribute that, when passed to line_reader_, adds these lines to the |
282 // provided lines array. | 284 // provided lines array. |
283 vector<Module::Line> lines_; | 285 vector<Module::Line> lines_; |
284 | 286 |
285 // Mock line program reader. | 287 // Mock line program reader. |
286 MockLineToModuleHandler line_reader_; | 288 MockLineToModuleHandler line_reader_; |
287 AppendLinesFunctor appender_; | 289 AppendLinesFunctor appender_; |
288 static const char dummy_line_program_[]; | 290 static const uint8_t dummy_line_program_[]; |
289 static const size_t dummy_line_size_; | 291 static const size_t dummy_line_size_; |
290 | 292 |
291 MockWarningReporter reporter_; | 293 MockWarningReporter reporter_; |
292 DwarfCUToModule root_handler_; | 294 DwarfCUToModule root_handler_; |
293 | 295 |
294 private: | 296 private: |
295 // Fill functions_, if we haven't already. | 297 // Fill functions_, if we haven't already. |
296 void FillFunctions(); | 298 void FillFunctions(); |
297 | 299 |
298 // If functions_filled_ is true, this is a table of functions we've | 300 // If functions_filled_ is true, this is a table of functions we've |
299 // extracted from module_, sorted by address. | 301 // extracted from module_, sorted by address. |
300 vector<Module::Function *> functions_; | 302 vector<Module::Function *> functions_; |
301 // True if we have filled the above vector with this.module_'s function list. | 303 // True if we have filled the above vector with this.module_'s function list. |
302 bool functions_filled_; | 304 bool functions_filled_; |
303 }; | 305 }; |
304 | 306 |
305 const char CUFixtureBase::dummy_line_program_[] = "lots of fun data"; | 307 const uint8_t CUFixtureBase::dummy_line_program_[] = "lots of fun data"; |
306 const size_t CUFixtureBase::dummy_line_size_ = | 308 const size_t CUFixtureBase::dummy_line_size_ = |
307 sizeof(CUFixtureBase::dummy_line_program_); | 309 sizeof(CUFixtureBase::dummy_line_program_); |
308 | 310 |
309 void CUFixtureBase::PushLine(Module::Address address, Module::Address size, | 311 void CUFixtureBase::PushLine(Module::Address address, Module::Address size, |
310 const string &filename, int line_number) { | 312 const string &filename, int line_number) { |
311 Module::Line l; | 313 Module::Line l; |
312 l.address = address; | 314 l.address = address; |
313 l.size = size; | 315 l.size = size; |
314 l.file = module_.FindFile(filename); | 316 l.file = module_.FindFile(filename); |
315 l.number = line_number; | 317 l.number = line_number; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 dwarf2reader::DIEHandler *handler) { | 370 dwarf2reader::DIEHandler *handler) { |
369 handler->ProcessAttributeUnsigned((DwarfAttribute) 0xf560dead, | 371 handler->ProcessAttributeUnsigned((DwarfAttribute) 0xf560dead, |
370 (DwarfForm) 0x4106e4db, | 372 (DwarfForm) 0x4106e4db, |
371 0xa592571997facda1ULL); | 373 0xa592571997facda1ULL); |
372 handler->ProcessAttributeSigned((DwarfAttribute) 0x85380095, | 374 handler->ProcessAttributeSigned((DwarfAttribute) 0x85380095, |
373 (DwarfForm) 0x0f16fe87, | 375 (DwarfForm) 0x0f16fe87, |
374 0x12602a4e3bf1f446LL); | 376 0x12602a4e3bf1f446LL); |
375 handler->ProcessAttributeReference((DwarfAttribute) 0xf7f7480f, | 377 handler->ProcessAttributeReference((DwarfAttribute) 0xf7f7480f, |
376 (DwarfForm) 0x829e038a, | 378 (DwarfForm) 0x829e038a, |
377 0x50fddef44734fdecULL); | 379 0x50fddef44734fdecULL); |
378 static const char buffer[10] = "frobynode"; | 380 static const uint8_t buffer[10] = "frobynode"; |
379 handler->ProcessAttributeBuffer((DwarfAttribute) 0xa55ffb51, | 381 handler->ProcessAttributeBuffer((DwarfAttribute) 0xa55ffb51, |
380 (DwarfForm) 0x2f43b041, | 382 (DwarfForm) 0x2f43b041, |
381 buffer, sizeof(buffer)); | 383 buffer, sizeof(buffer)); |
382 handler->ProcessAttributeString((DwarfAttribute) 0x2f43b041, | 384 handler->ProcessAttributeString((DwarfAttribute) 0x2f43b041, |
383 (DwarfForm) 0x895ffa23, | 385 (DwarfForm) 0x895ffa23, |
384 "strange string"); | 386 "strange string"); |
385 } | 387 } |
386 | 388 |
387 DIEHandler *CUFixtureBase::StartNamedDIE(DIEHandler *parent, | 389 DIEHandler *CUFixtureBase::StartNamedDIE(DIEHandler *parent, |
388 DwarfTag tag, | 390 DwarfTag tag, |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 reporter.UncoveredLine(line); | 1772 reporter.UncoveredLine(line); |
1771 EXPECT_TRUE(reporter.uncovered_warnings_enabled()); | 1773 EXPECT_TRUE(reporter.uncovered_warnings_enabled()); |
1772 } | 1774 } |
1773 | 1775 |
1774 TEST_F(Reporter, UnnamedFunction) { | 1776 TEST_F(Reporter, UnnamedFunction) { |
1775 reporter.UnnamedFunction(0x90c0baff9dedb2d9ULL); | 1777 reporter.UnnamedFunction(0x90c0baff9dedb2d9ULL); |
1776 } | 1778 } |
1777 | 1779 |
1778 // Would be nice to also test: | 1780 // Would be nice to also test: |
1779 // - overlapping lines, functions | 1781 // - overlapping lines, functions |
OLD | NEW |