Add NetworkTechnology types to ONC
[chromium-blink-merge.git] / tools / cygprofile / cyglog_to_orderfile_unittest.py
blob714d102ff20e20656217f9193b79b2e675e64245
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.
6 import unittest
8 import cyglog_to_orderfile
9 import symbol_extractor
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])
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])
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])
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)
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))
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)
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))
85 if __name__ == '__main__':
86 unittest.main()