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.
9 import symbol_extractor
12 class TestPatchOrderFile(unittest
.TestCase
):
13 def testRemoveClone(self
):
14 no_clone
= "this.does.not.contain.clone"
15 self
.assertEquals(no_clone
, patch_orderfile
._RemoveClone
(no_clone
))
16 with_clone
= "this.does.contain.clone."
18 "this.does.contain", patch_orderfile
._RemoveClone
(with_clone
))
20 def testAliasClonedSymbols(self
):
22 symbol_extractor
.SymbolInfo(name
='aSymbol', offset
=0x42, size
=0x12,
24 symbol_extractor
.SymbolInfo(name
='aSymbol.clone.', offset
=8, size
=1,
26 (offset_to_symbol_infos
, name_to_symbol_infos
) = \
27 patch_orderfile
._GroupSymbolInfos
(symbol_infos
)
28 self
.assertEquals(len(offset_to_symbol_infos
), 2)
31 matching
= offset_to_symbol_infos
[s
.offset
][0]
32 self
.assertEquals(matching
.offset
, s
.offset
)
33 self
.assertEquals(matching
.size
, s
.size
)
34 self
.assertEquals(len(name_to_symbol_infos
), 1)
35 self
.assertEquals(len(name_to_symbol_infos
['aSymbol']), 2)
37 def testGroupSymbolsByOffset(self
):
39 symbol_extractor
.SymbolInfo(name
='aSymbol', offset
=0x42, size
=0x12,
41 symbol_extractor
.SymbolInfo(name
='anotherSymbol', offset
=0x42, size
=1,
43 (offset_to_symbol_infos
, _
) = \
44 patch_orderfile
._GroupSymbolInfos
(symbol_infos
)
45 self
.assertEquals(len(offset_to_symbol_infos
), 1)
46 self
.assertEquals(tuple(offset_to_symbol_infos
[0x42]), symbol_infos
)
48 def testExpandSymbols(self
):
49 symbol_name
= "dummySymbol"
50 symbol_name2
= "other"
51 profiled_symbol_names
= [symbol_name
, "symbolThatShouldntMatch"]
52 name_to_symbol_infos
= {symbol_name
: [
53 symbol_extractor
.SymbolInfo(symbol_name
, 0x42, 0x12,
55 offset_to_symbol_infos
= {
56 0x42: [symbol_extractor
.SymbolInfo(symbol_name
, 0x42, 0x12,
58 symbol_extractor
.SymbolInfo(symbol_name2
, 0x42, 0x12,
60 symbol_names
= patch_orderfile
._ExpandSymbols
(
61 profiled_symbol_names
, name_to_symbol_infos
, offset_to_symbol_infos
)
62 self
.assertEquals(len(symbol_names
), 3)
63 self
.assertEquals(symbol_names
[0], symbol_name
)
64 self
.assertEquals(symbol_names
[1], symbol_name2
)
65 self
.assertEquals(symbol_names
[2], "symbolThatShouldntMatch")
67 def testPrintSymbolWithPrefixes(self
):
68 class FakeOutputFile(object):
72 self
.output
= self
.output
+ s
73 test_symbol
= "dummySymbol"
74 symbol_names
= [test_symbol
]
75 fake_output
= FakeOutputFile()
76 patch_orderfile
._PrintSymbolsWithPrefixes
(symbol_names
, fake_output
)
77 expected_output
= """.text.startup.dummySymbol
79 .text.unlikely.dummySymbol
82 self
.assertEquals(fake_output
.output
, expected_output
)
85 if __name__
== "__main__":