Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: tools/cygprofile/cyglog_to_orderfile_unittest.py

Issue 874683004: Refactor the symbolize step of the orderfile generation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/cygprofile/cyglog_to_orderfile.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 cyglog_to_orderfile
9 import symbol_extractor
10
11
12 class TestCyglogToOrderfile(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 offsets = cyglog_to_orderfile._ParseLogLines(lines)
21 self.assertListEqual(
22 offsets, [0x509e105c - 0x5086e000, 0x509e0eb4 - 0x5086e000])
23
24 def testFindSymbolInfosAtOffsetExactMatch(self):
25 offset_map = {0x10: [symbol_extractor.SymbolInfo(
26 name='Symbol', offset=0x10, size=0x13, section='.text')]}
27 functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x10)
28 self.assertEquals(len(functions), 1)
29 self.assertEquals(functions[0], offset_map[0x10][0])
30
31 def testFindSymbolInfosAtOffsetInexactMatch(self):
32 offset_map = {0x10: [symbol_extractor.SymbolInfo(
33 name='Symbol', offset=0x10, size=0x13, section='.text')]}
34 functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x11)
35 self.assertEquals(len(functions), 1)
36 self.assertEquals(functions[0], offset_map[0x10][0])
37
38 def testFindSymbolInfosAtOffsetNoMatch(self):
39 offset_map = {0x10: [symbol_extractor.SymbolInfo(
40 name='Symbol', offset=0x10, size=0x13, section='.text')]}
41 self.assertRaises(
42 cyglog_to_orderfile.SymbolNotFoundException,
43 cyglog_to_orderfile._FindSymbolInfosAtOffset, offset_map, 0x12)
44
45 def testWarnAboutDuplicates(self):
46 offsets = [0x1, 0x2, 0x3]
47 self.assertTrue(cyglog_to_orderfile._WarnAboutDuplicates(offsets))
48 offsets.append(0x1)
49 self.assertFalse(cyglog_to_orderfile._WarnAboutDuplicates(offsets))
50
51 def testOutputOrderfile(self):
52 class FakeOutputFile(object):
53 def __init__(self):
54 self.writes = []
55 def write(self, data):
56 self.writes.append(data)
57
58 # One symbol not matched, one with an odd address, one regularly matched
59 # And two symbols aliased to the same address
60 offsets = [0x12, 0x17]
61 offset_to_symbol_infos = {
62 0x10:[symbol_extractor.SymbolInfo(
63 name='Symbol', offset=0x10, size=0x13, section='dummy')],
64 0x12:[symbol_extractor.SymbolInfo(
65 name='Symbol2', offset=0x12, size=0x13, section='dummy')],
66 0x16:[symbol_extractor.SymbolInfo(
67 name='Symbol3', offset=0x16, size=0x13, section='dummy'),
68 symbol_extractor.SymbolInfo(
69 name='Symbol32', offset=0x16, size=0x13, section='dummy'),]}
70 symbol_to_section_map = {
71 'Symbol': '.text.Symbol',
72 'Symbol2': '.text.Symbol2',
73 'Symbol3': '.text.Symbol3',
74 'Symbol32': '.text.Symbol32'}
75 fake_output = FakeOutputFile()
76 cyglog_to_orderfile._OutputOrderfile(
77 offsets, offset_to_symbol_infos, symbol_to_section_map, fake_output)
78 expected = """.text.Symbol2
79 .text.Symbol3
80 .text.Symbol32
81 """
82 self.assertEquals(expected, "".join(fake_output.writes))
83
84
85 if __name__ == '__main__':
86 unittest.main()
OLDNEW
« no previous file with comments | « tools/cygprofile/cyglog_to_orderfile.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698