Convert display_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / tools / cygprofile / patch_orderfile_unittest.py
blob047d447f10ce49ceb4e198dab986d93d195fd0ff
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 patch_orderfile
9 import symbol_extractor
12 class TestPatchOrderFile(unittest.TestCase):
13 def testRemoveSuffixes(self):
14 no_clone = 'this.does.not.contain.clone'
15 self.assertEquals(no_clone, patch_orderfile.RemoveSuffixes(no_clone))
16 with_clone = 'this.does.contain.clone.'
17 self.assertEquals(
18 'this.does.contain', patch_orderfile.RemoveSuffixes(with_clone))
19 with_part = 'this.is.a.part.42'
20 self.assertEquals(
21 'this.is.a', patch_orderfile.RemoveSuffixes(with_part))
23 def testAliasClonedSymbols(self):
24 symbol_infos = [
25 symbol_extractor.SymbolInfo(name='aSymbol', offset=0x42, size=0x12,
26 section='.text'),
27 symbol_extractor.SymbolInfo(name='aSymbol.clone.', offset=8, size=1,
28 section='.text')]
29 (offset_to_symbol_infos, name_to_symbol_infos) = \
30 patch_orderfile._GroupSymbolInfos(symbol_infos)
31 self.assertEquals(len(offset_to_symbol_infos), 2)
32 for i in range(2):
33 s = symbol_infos[i]
34 matching = offset_to_symbol_infos[s.offset][0]
35 self.assertEquals(matching.offset, s.offset)
36 self.assertEquals(matching.size, s.size)
37 self.assertEquals(len(name_to_symbol_infos), 1)
38 self.assertEquals(len(name_to_symbol_infos['aSymbol']), 2)
40 def testGroupSymbolsByOffset(self):
41 symbol_infos = (
42 symbol_extractor.SymbolInfo(name='aSymbol', offset=0x42, size=0x12,
43 section='.text'),
44 symbol_extractor.SymbolInfo(name='anotherSymbol', offset=0x42, size=1,
45 section='.text'))
46 (offset_to_symbol_infos, _) = \
47 patch_orderfile._GroupSymbolInfos(symbol_infos)
48 self.assertEquals(len(offset_to_symbol_infos), 1)
49 self.assertEquals(tuple(offset_to_symbol_infos[0x42]), symbol_infos)
51 def testSymbolsWithSameOffset(self):
52 symbol_name = "dummySymbol"
53 symbol_name2 = "other"
54 name_to_symbol_infos = {symbol_name: [
55 symbol_extractor.SymbolInfo(symbol_name, 0x42, 0x12,
56 section='.text')]}
57 offset_to_symbol_infos = {
58 0x42: [symbol_extractor.SymbolInfo(symbol_name, 0x42, 0x12,
59 section='.text'),
60 symbol_extractor.SymbolInfo(symbol_name2, 0x42, 0x12,
61 section='.text')]}
62 symbol_names = patch_orderfile._SymbolsWithSameOffset(
63 symbol_name, name_to_symbol_infos, offset_to_symbol_infos)
64 self.assertEquals(len(symbol_names), 2)
65 self.assertEquals(symbol_names[0], symbol_name)
66 self.assertEquals(symbol_names[1], symbol_name2)
67 self.assertEquals([], patch_orderfile._SymbolsWithSameOffset(
68 "symbolThatShouldntMatch",
69 name_to_symbol_infos, offset_to_symbol_infos))
71 def testSectionNameToSymbols(self):
72 mapping = {'.text.foo': ['foo'],
73 '.text.startup.bar': ['bar', 'bar1']}
74 self.assertEquals(list(patch_orderfile._SectionNameToSymbols(
75 '.text.foo', mapping)),
76 ['foo'])
77 self.assertEquals(list(patch_orderfile._SectionNameToSymbols(
78 '.text.startup.bar', mapping)),
79 ['bar', 'bar1'])
80 self.assertEquals(list(patch_orderfile._SectionNameToSymbols(
81 '.text.startup.bar', mapping)),
82 ['bar', 'bar1'])
83 self.assertEquals(list(patch_orderfile._SectionNameToSymbols(
84 '.text.hot.foobar', mapping)),
85 ['foobar'])
86 self.assertEquals(list(patch_orderfile._SectionNameToSymbols(
87 '.text.startup.*', mapping)),
88 [])
90 def testSectionMatchingRules(self):
91 symbol_name1 = 'symbol1'
92 symbol_name2 = 'symbol2'
93 symbol_name3 = 'symbol3'
94 section_name1 = '.text.' + symbol_name1
95 section_name3 = '.text.foo'
96 suffixed = set([section_name3])
97 name_to_symbol_infos = {symbol_name1: [
98 symbol_extractor.SymbolInfo(symbol_name1, 0x42, 0x12,
99 section='.text')]}
100 offset_to_symbol_infos = {
101 0x42: [symbol_extractor.SymbolInfo(symbol_name1, 0x42, 0x12,
102 section='.text'),
103 symbol_extractor.SymbolInfo(symbol_name2, 0x42, 0x12,
104 section='.text')]}
105 section_to_symbols_map = {section_name1: [symbol_name1],
106 section_name3: [symbol_name1, symbol_name3]}
107 symbol_to_sections_map = {symbol_name1:
108 [section_name1, section_name3],
109 symbol_name3: [section_name3]}
110 expected = [
111 section_name1,
112 section_name3,
113 section_name3 + '.*',
114 '.text.startup.' + symbol_name1,
115 '.text.hot.' + symbol_name1,
116 '.text.unlikely.' + symbol_name1,
117 '.text.startup.symbol2',
118 '.text.hot.symbol2',
119 '.text.unlikely.symbol2',
120 '.text.symbol2']
121 self.assertEqual(expected, list(patch_orderfile._SectionMatchingRules(
122 section_name1, name_to_symbol_infos, offset_to_symbol_infos,
123 section_to_symbols_map, symbol_to_sections_map, suffixed)))
125 def testUniqueGenerator(self):
126 @patch_orderfile._UniqueGenerator
127 def TestIterator():
128 yield 1
129 yield 2
130 yield 1
131 yield 3
133 self.assertEqual(list(TestIterator()), [1,2,3])
135 def testCombineSectionListsByPrimaryName(self):
136 self.assertEqual(patch_orderfile._CombineSectionListsByPrimaryName(
137 {'foo': ['.text.foo', '.text.bar.constprop.1'],
138 'foo.part.1': ['.text.baz'],
139 'foobar': ['.text.foobar']}),
140 {'foo': ['.text.foo', '.text.bar', '.text.baz'],
141 'foobar': ['.text.foobar']})
143 def testSectionsWithSuffixes(self):
144 self.assertEqual(patch_orderfile._SectionsWithSuffixes(
145 {'foo': ['.text.foo', '.text.bar.constprop.1'],
146 'foo.part.1': ['.text.baz'],
147 'foobar': ['.text.foobar']}),
148 set(['.text.bar']))
151 if __name__ == "__main__":
152 unittest.main()