Add ICU message format support
[chromium-blink-merge.git] / tools / cygprofile / cyglog_to_orderfile_unittest.py
blob9ea0d182107d5b9432ee5e211f9cbdca93eeb3fd
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 os
10 import symbol_extractor
11 import sys
13 sys.path.insert(
14 0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
15 'third_party', 'android_platform', 'development',
16 'scripts'))
17 import symbol
20 class TestCyglogToOrderfile(unittest.TestCase):
21 def testParseLogLines(self):
22 lines = """5086e000-52e92000 r-xp 00000000 b3:02 51276 libchromeview.so
23 secs usecs pid:threadid func
24 START
25 1314897086 795828 3587:1074648168 0x509e105c
26 1314897086 795874 3587:1074648168 0x509e0eb4
27 END""".split('\n')
28 offsets = cyglog_to_orderfile._ParseLogLines(lines)
29 self.assertListEqual(
30 offsets, [0x509e105c - 0x5086e000, 0x509e0eb4 - 0x5086e000])
32 def testFindSymbolInfosAtOffsetExactMatch(self):
33 offset_map = {0x10: [symbol_extractor.SymbolInfo(
34 name='Symbol', offset=0x10, size=0x13, section='.text')]}
35 functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x10)
36 self.assertEquals(len(functions), 1)
37 self.assertEquals(functions[0], offset_map[0x10][0])
39 def testFindSymbolInfosAtOffsetInexactMatch(self):
40 offset_map = {0x10: [symbol_extractor.SymbolInfo(
41 name='Symbol', offset=0x10, size=0x13, section='.text')]}
42 functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x11)
43 self.assertEquals(len(functions), 1)
44 self.assertEquals(functions[0], offset_map[0x10][0])
46 def testFindSymbolInfosAtOffsetNoMatch(self):
47 offset_map = {0x10: [symbol_extractor.SymbolInfo(
48 name='Symbol', offset=0x10, size=0x13, section='.text')]}
49 self.assertRaises(
50 cyglog_to_orderfile.SymbolNotFoundException,
51 cyglog_to_orderfile._FindSymbolInfosAtOffset, offset_map, 0x12)
53 def testWarnAboutDuplicates(self):
54 offsets = [0x1, 0x2, 0x3]
55 self.assertTrue(cyglog_to_orderfile._WarnAboutDuplicates(offsets))
56 offsets.append(0x1)
57 self.assertFalse(cyglog_to_orderfile._WarnAboutDuplicates(offsets))
59 def testSameCtorOrDtorNames(self):
60 if not os.path.exists(symbol.ToolPath('c++filt')):
61 print 'Skipping test dependent on missing c++filt binary.'
62 return
63 self.assertTrue(cyglog_to_orderfile._SameCtorOrDtorNames(
64 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEEC1Ev',
65 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEEC2Ev'))
66 self.assertTrue(cyglog_to_orderfile._SameCtorOrDtorNames(
67 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEED1Ev',
68 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEED2Ev'))
69 self.assertFalse(cyglog_to_orderfile._SameCtorOrDtorNames(
70 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEEC1Ev',
71 '_ZNSt3__119foo_iteratorIcNS_11char_traitsIcEEEC1Ev'))
72 self.assertFalse(cyglog_to_orderfile._SameCtorOrDtorNames(
73 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEE',
74 '_ZNSt3__119istreambuf_iteratorIcNS_11char_traitsIcEEE'))
76 def testOutputOrderfile(self):
77 class FakeOutputFile(object):
78 def __init__(self):
79 self.writes = []
81 def write(self, data):
82 self.writes.append(data)
84 # One symbol not matched, one with an odd address, one regularly matched
85 # And two symbols aliased to the same address
86 offsets = [0x12, 0x17]
87 offset_to_symbol_infos = {
88 0x10: [symbol_extractor.SymbolInfo(
89 name='Symbol', offset=0x10, size=0x13, section='dummy')],
90 0x12: [symbol_extractor.SymbolInfo(
91 name='Symbol2', offset=0x12, size=0x13, section='dummy')],
92 0x16: [symbol_extractor.SymbolInfo(
93 name='Symbol3', offset=0x16, size=0x13, section='dummy'),
94 symbol_extractor.SymbolInfo(
95 name='Symbol32', offset=0x16, size=0x13, section='dummy'),]}
96 symbol_to_sections_map = {
97 'Symbol': ['.text.Symbol'],
98 'Symbol2': ['.text.Symbol2', '.text.hot.Symbol2'],
99 'Symbol3': ['.text.Symbol3'],
100 'Symbol32': ['.text.Symbol32']}
101 fake_output = FakeOutputFile()
102 cyglog_to_orderfile._OutputOrderfile(
103 offsets, offset_to_symbol_infos, symbol_to_sections_map, fake_output)
104 expected = """.text.Symbol2
105 .text.hot.Symbol2
106 .text.Symbol3
107 .text.Symbol32
109 self.assertEquals(expected, ''.join(fake_output.writes))
112 if __name__ == '__main__':
113 unittest.main()