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.
8 import cyglog_to_orderfile
10 import symbol_extractor
14 0, os
.path
.join(os
.path
.dirname(__file__
), os
.pardir
, os
.pardir
,
15 'third_party', 'android_platform', 'development',
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
25 1314897086 795828 3587:1074648168 0x509e105c
26 1314897086 795874 3587:1074648168 0x509e0eb4
28 offsets
= cyglog_to_orderfile
._ParseLogLines
(lines
)
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')]}
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
))
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.'
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):
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
109 self
.assertEquals(expected
, ''.join(fake_output
.writes
))
112 if __name__
== '__main__':