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 cyglog_to_orderfile | |
pasko
2015/01/30 19:31:33
should these be sorted alphabetically? (gotcha, my
Benoit L
2015/02/02 09:28:15
Done.
| |
10 | |
11 | |
12 class TestSymbolizeTest(unittest.TestCase): | |
pasko
2015/01/30 19:31:33
nit: TestCyglogToOrderfile
Benoit L
2015/02/02 09:28:15
Done.
| |
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 = cyglog_to_orderfile._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 = cyglog_to_orderfile._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 = cyglog_to_orderfile._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( | |
47 cyglog_to_orderfile.SymbolNotFoundException, | |
48 cyglog_to_orderfile._FindSymbolInfosAtOffset, offset_map, 0x12) | |
49 | |
50 def testWarnAboutDuplicates(self): | |
51 offsets = [0x1, 0x2, 0x3] | |
52 self.assertTrue(cyglog_to_orderfile._WarnAboutDuplicates(offsets)) | |
53 offsets.append(0x1) | |
54 self.assertFalse(cyglog_to_orderfile._WarnAboutDuplicates(offsets)) | |
55 | |
56 def testOutputOrderfile(self): | |
57 class FakeOutputFile(object): | |
58 def __init__(self): | |
59 self.writes = [] | |
60 def write(self, data): | |
61 self.writes.append(data) | |
62 | |
63 # One symbol not matched, one with an odd address, one regularly matched | |
64 # And two symbols aliased to the same address | |
65 offsets = [0x12, 0x17] | |
66 offset_to_symbol_infos = { | |
67 0x10:[symbol_extractor.SymbolInfo( | |
68 name='Symbol', offset=0x10, size=0x13, section='dummy')], | |
69 0x12:[symbol_extractor.SymbolInfo( | |
70 name='Symbol2', offset=0x12, size=0x13, section='dummy')], | |
71 0x16:[symbol_extractor.SymbolInfo( | |
72 name='Symbol3', offset=0x16, size=0x13, section='dummy'), | |
73 symbol_extractor.SymbolInfo( | |
74 name='Symbol32', offset=0x16, size=0x13, section='dummy'),]} | |
75 symbol_to_section_map = { | |
76 'Symbol': '.text.Symbol', | |
77 'Symbol2': '.text.Symbol2', | |
78 'Symbol3': '.text.Symbol3', | |
79 'Symbol32': '.text.Symbol32'} | |
80 fake_output = FakeOutputFile() | |
81 cyglog_to_orderfile._OutputOrderfile(offsets, offset_to_symbol_infos, | |
82 symbol_to_section_map, | |
83 fake_output) | |
84 expected = """.text.Symbol2 | |
85 .text.Symbol3 | |
86 .text.Symbol32 | |
87 """ | |
88 self.assertEquals(expected, "".join(fake_output.writes)) | |
89 | |
90 | |
91 if __name__ == '__main__': | |
92 unittest.main() | |
OLD | NEW |