OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import unittest |
| 7 |
| 8 import symbol_extractor |
| 9 import symbolize |
| 10 |
| 11 |
| 12 class TestSymbolizeTest(unittest.TestCase): |
| 13 def testParseLogLines(self): |
| 14 lines = """5086e000-52e92000 r-xp 00000000 b3:02 51276 libchromeview.so |
| 15 secs usecs pid:threadid func |
| 16 START |
| 17 1314897086 795828 3587:1074648168 0x509e105c |
| 18 1314897086 795874 3587:1074648168 0x509e0eb4 |
| 19 END""".split('\n') |
| 20 call_info = symbolize._ParseLogLines(lines) |
| 21 self.assertEquals(len(call_info), 2) |
| 22 self.assertEquals( |
| 23 call_info[0], (1314897086, 795828, '3587:1074648168', |
| 24 0x509e105c - 0x5086e000)) |
| 25 self.assertEquals( |
| 26 call_info[1], (1314897086, 795874, '3587:1074648168', |
| 27 0x509e0eb4 - 0x5086e000)) |
| 28 |
| 29 def testFindSymbolInfosAtOffsetExactMatch(self): |
| 30 offset_map = {0x10: [symbol_extractor.SymbolInfo( |
| 31 name='Symbol', offset=0x10, size=0x13, section='.text')]} |
| 32 functions = symbolize._FindSymbolInfosAtOffset(offset_map, 0x10) |
| 33 self.assertEquals(len(functions), 1) |
| 34 self.assertEquals(functions[0], offset_map[0x10][0]) |
| 35 |
| 36 def testFindSymbolInfosAtOffsetInexactMatch(self): |
| 37 offset_map = {0x10: [symbol_extractor.SymbolInfo( |
| 38 name='Symbol', offset=0x10, size=0x13, section='.text')]} |
| 39 functions = symbolize._FindSymbolInfosAtOffset(offset_map, 0x11) |
| 40 self.assertEquals(len(functions), 1) |
| 41 self.assertEquals(functions[0], offset_map[0x10][0]) |
| 42 |
| 43 def testFindSymbolInfosAtOffsetNoMatch(self): |
| 44 offset_map = {0x10: [symbol_extractor.SymbolInfo( |
| 45 name='Symbol', offset=0x10, size=0x13, section='.text')]} |
| 46 self.assertRaises(symbolize.SymbolNotFoundException, |
| 47 symbolize._FindSymbolInfosAtOffset, offset_map, 0x12) |
| 48 |
| 49 def testWarnAboutDuplicates(self): |
| 50 offsets = [0x1, 0x2, 0x3] |
| 51 self.assertTrue(symbolize._WarnAboutDuplicates(offsets)) |
| 52 offsets.append(0x1) |
| 53 self.assertFalse(symbolize._WarnAboutDuplicates(offsets)) |
| 54 |
| 55 def testOutputOrderfile(self): |
| 56 class FakeOutputFile(object): |
| 57 def __init__(self): |
| 58 self.writes = [] |
| 59 def write(self, data): |
| 60 self.writes.append(data) |
| 61 |
| 62 # One symbol not matched, one with an odd address, one regularly matched |
| 63 # And two symbols aliased to the same address |
| 64 offsets = [0x12, 0x17] |
| 65 offset_to_symbol_infos = { |
| 66 0x10:[symbol_extractor.SymbolInfo( |
| 67 name='Symbol', offset=0x10, size=0x13, section='dummy')], |
| 68 0x12:[symbol_extractor.SymbolInfo( |
| 69 name='Symbol2', offset=0x12, size=0x13, section='dummy')], |
| 70 0x16:[symbol_extractor.SymbolInfo( |
| 71 name='Symbol3', offset=0x16, size=0x13, section='dummy'), |
| 72 symbol_extractor.SymbolInfo( |
| 73 name='Symbol32', offset=0x16, size=0x13, section='dummy'),]} |
| 74 symbol_to_section_map = { |
| 75 'Symbol': '.text.Symbol', |
| 76 'Symbol2': '.text.Symbol2', |
| 77 'Symbol3': '.text.Symbol3', |
| 78 'Symbol32': '.text.Symbol32'} |
| 79 fake_output = FakeOutputFile() |
| 80 symbolize._OutputOrderfile(offsets, offset_to_symbol_infos, |
| 81 symbol_to_section_map, |
| 82 fake_output) |
| 83 expected = """.text.Symbol2 |
| 84 .text.Symbol3 |
| 85 .text.Symbol32 |
| 86 """ |
| 87 self.assertEquals(expected, "".join(fake_output.writes)) |
| 88 |
| 89 |
| 90 if __name__ == '__main__': |
| 91 unittest.main() |
OLD | NEW |