Fire callbacks in FlushAndStop if AvStreamerProxy isn't running
[chromium-blink-merge.git] / tools / cygprofile / symbol_extractor_unittest.py
blob986a18768bd7c518f99c5b7b2b43a6e60246823e
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 symbol_extractor
7 import unittest
9 class TestSymbolInfo(unittest.TestCase):
10 def testIgnoresBlankLine(self):
11 symbol_info = symbol_extractor._FromObjdumpLine('')
12 self.assertIsNone(symbol_info)
14 def testIgnoresMalformedLine(self):
15 # This line is too short.
16 line = ('00c1b228 F .text 00000060 _ZN20trace_event')
17 symbol_info = symbol_extractor._FromObjdumpLine(line)
18 self.assertIsNone(symbol_info)
19 # This line has the wrong marker.
20 line = '00c1b228 l f .text 00000060 _ZN20trace_event'
21 symbol_info = symbol_extractor._FromObjdumpLine(line)
22 self.assertIsNone(symbol_info)
24 def testAssertionErrorOnInvalidLines(self):
25 # This line has an invalid scope.
26 line = ('00c1b228 z F .text 00000060 _ZN20trace_event')
27 self.assertRaises(AssertionError, symbol_extractor._FromObjdumpLine, line)
28 # This line has too many fields.
29 line = ('00c1b228 l F .text 00000060 _ZN20trace_event too many')
30 self.assertRaises(AssertionError, symbol_extractor._FromObjdumpLine, line)
31 # This line has invalid characters in the symbol.
32 line = ('00c1b228 l F .text 00000060 _ZN20trace_$bad')
33 self.assertRaises(AssertionError, symbol_extractor._FromObjdumpLine, line)
35 def testSymbolInfo(self):
36 line = ('00c1c05c l F .text 0000002c '
37 '_GLOBAL__sub_I_chrome_main_delegate.cc')
38 test_name = '_GLOBAL__sub_I_chrome_main_delegate.cc'
39 test_offset = 0x00c1c05c
40 test_size = 0x2c
41 test_section = '.text'
42 symbol_info = symbol_extractor._FromObjdumpLine(line)
43 self.assertIsNotNone(symbol_info)
44 self.assertEquals(test_offset, symbol_info.offset)
45 self.assertEquals(test_size, symbol_info.size)
46 self.assertEquals(test_name, symbol_info.name)
47 self.assertEquals(test_section, symbol_info.section)
49 def testHiddenSymbol(self):
50 line = ('00c1c05c l F .text 0000002c '
51 '.hidden _GLOBAL__sub_I_chrome_main_delegate.cc')
52 test_name = '_GLOBAL__sub_I_chrome_main_delegate.cc'
53 test_offset = 0x00c1c05c
54 test_size = 0x2c
55 test_section = '.text'
56 symbol_info = symbol_extractor._FromObjdumpLine(line)
57 self.assertIsNotNone(symbol_info)
58 self.assertEquals(test_offset, symbol_info.offset)
59 self.assertEquals(test_size, symbol_info.size)
60 self.assertEquals(test_name, symbol_info.name)
61 self.assertEquals(test_section, symbol_info.section)
64 class TestSymbolInfosFromStream(unittest.TestCase):
65 def testSymbolInfosFromStream(self):
66 lines = ['Garbage',
67 '',
68 '00c1c05c l F .text 0000002c first',
70 'more garbage',
71 '00155 g F .text 00000012 second']
72 symbol_infos = symbol_extractor._SymbolInfosFromStream(lines)
73 self.assertEquals(len(symbol_infos), 2)
74 first = symbol_extractor.SymbolInfo('first', 0x00c1c05c, 0x2c, '.text')
75 self.assertEquals(first, symbol_infos[0])
76 second = symbol_extractor.SymbolInfo('second', 0x00155, 0x12, '.text')
77 self.assertEquals(second, symbol_infos[1])
80 class TestSymbolInfoMappings(unittest.TestCase):
81 def setUp(self):
82 self.symbol_infos = [
83 symbol_extractor.SymbolInfo('firstNameAtOffset', 0x42, 42, '.text'),
84 symbol_extractor.SymbolInfo('secondNameAtOffset', 0x42, 42, '.text'),
85 symbol_extractor.SymbolInfo('thirdSymbol', 0x64, 20, '.text')]
87 def testGroupSymbolInfosByOffset(self):
88 offset_to_symbol_info = symbol_extractor.GroupSymbolInfosByOffset(
89 self.symbol_infos)
90 self.assertEquals(len(offset_to_symbol_info), 2)
91 self.assertIn(0x42, offset_to_symbol_info)
92 self.assertEquals(offset_to_symbol_info[0x42][0], self.symbol_infos[0])
93 self.assertEquals(offset_to_symbol_info[0x42][1], self.symbol_infos[1])
94 self.assertIn(0x64, offset_to_symbol_info)
95 self.assertEquals(offset_to_symbol_info[0x64][0], self.symbol_infos[2])
97 def testCreateNameToSymbolInfo(self):
98 name_to_symbol_info = symbol_extractor.CreateNameToSymbolInfo(
99 self.symbol_infos)
100 self.assertEquals(len(name_to_symbol_info), 3)
101 for i in range(3):
102 name = self.symbol_infos[i].name
103 self.assertIn(name, name_to_symbol_info)
104 self.assertEquals(self.symbol_infos[i], name_to_symbol_info[name])
106 def testSymbolCollisions(self):
107 symbol_infos_with_collision = list(self.symbol_infos)
108 symbol_infos_with_collision.append(symbol_extractor.SymbolInfo(
109 'secondNameAtOffset', 0x84, 42, '.text'))
111 # The symbol added above should not affect the output.
112 name_to_symbol_info = symbol_extractor.CreateNameToSymbolInfo(
113 self.symbol_infos)
114 self.assertEquals(len(name_to_symbol_info), 3)
115 for i in range(3):
116 name = self.symbol_infos[i].name
117 self.assertIn(name, name_to_symbol_info)
118 self.assertEquals(self.symbol_infos[i], name_to_symbol_info[name])
120 if __name__ == '__main__':
121 unittest.main()