[Telemetry] Make sure all page_test use 'action_name_to_run' except RasterizeAndMicro...
[chromium-blink-merge.git] / tools / cygprofile / patch_orderfile_unittest.py
blob5d6c1d28c2af2cb9e4e266b0756e69f3513de911
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 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."
17 self.assertEquals(
18 "this.does.contain", patch_orderfile._RemoveClone(with_clone))
20 def testAliasClonedSymbols(self):
21 symbol_infos = [
22 symbol_extractor.SymbolInfo(name='aSymbol', offset=0x42, size=0x12,
23 section='.text'),
24 symbol_extractor.SymbolInfo(name='aSymbol.clone.', offset=8, size=1,
25 section='.text')]
26 (offset_to_symbol_infos, name_to_symbol_infos) = \
27 patch_orderfile._GroupSymbolInfos(symbol_infos)
28 self.assertEquals(len(offset_to_symbol_infos), 2)
29 for i in range(2):
30 s = symbol_infos[i]
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):
38 symbol_infos = (
39 symbol_extractor.SymbolInfo(name='aSymbol', offset=0x42, size=0x12,
40 section='.text'),
41 symbol_extractor.SymbolInfo(name='anotherSymbol', offset=0x42, size=1,
42 section='.text'))
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,
54 section='.text')]}
55 offset_to_symbol_infos = {
56 0x42: [symbol_extractor.SymbolInfo(symbol_name, 0x42, 0x12,
57 section='.text'),
58 symbol_extractor.SymbolInfo(symbol_name2, 0x42, 0x12,
59 section='.text')]}
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):
69 def __init__(self):
70 self.output = ''
71 def write(self, s):
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
78 .text.hot.dummySymbol
79 .text.unlikely.dummySymbol
80 .text.dummySymbol
81 """
82 self.assertEquals(fake_output.output, expected_output)
85 if __name__ == "__main__":
86 unittest.main()