OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Unittest for symbolize.py. | 7 """Unittest for symbolize.py. |
8 | 8 |
9 This test uses test libraries generated by the Android g++ toolchain. | 9 This test uses test libraries generated by the Android g++ toolchain. |
10 | 10 |
11 Should things break you can recreate the libraries and get the updated | 11 Should things break you can recreate the libraries and get the updated |
12 addresses and demangled names by running the following: | 12 addresses and demangled names by running the following: |
13 cd test/symbolize/ | 13 cd test/symbolize/ |
14 make | 14 make |
15 nm -gC *.so | 15 nm -gC *.so |
16 """ | 16 """ |
17 | 17 |
18 import sys | 18 import sys |
19 import StringIO | 19 import StringIO |
20 import unittest | 20 import unittest |
21 | 21 |
22 import symbolize | 22 import symbolize |
23 | 23 |
24 LIB_A_PATH = '/build/android/tests/symbolize/liba.so' | 24 LIB_A_PATH = '/build/android/tests/symbolize/liba.so' |
25 LIB_B_PATH = '/build/android/tests/symbolize/libb.so' | 25 LIB_B_PATH = '/build/android/tests/symbolize/libb.so' |
26 | 26 |
27 def RunSymbolizer(text): | 27 def RunSymbolizer(text): |
28 output = StringIO.StringIO() | 28 output = StringIO.StringIO() |
29 s = symbolize.Symbolizer(StringIO.StringIO(text), output) | 29 s = symbolize.Symbolizer(output) |
30 s.ProcessInput() | 30 s.write(text) |
31 return output.getvalue() | 31 return output.getvalue() |
32 | 32 |
33 | 33 |
34 class SymbolizerUnittest(unittest.TestCase): | 34 class SymbolizerUnittest(unittest.TestCase): |
35 def testSingleLineNoMatch(self): | 35 def testSingleLineNoMatch(self): |
36 # Leading '#' is required. | 36 # Leading '#' is required. |
37 expected = '00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' | 37 expected = '00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
38 self.assertEqual(expected, RunSymbolizer(expected)) | 38 self.assertEqual(expected, RunSymbolizer(expected)) |
39 | 39 |
40 # Whitespace should be exactly one space. | 40 # Whitespace should be exactly one space. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 expected = 'TOP\n' | 122 expected = 'TOP\n' |
123 expected += 'LEFT #00 0x00000000 A::Bar(char const*) RIGHT\n' | 123 expected += 'LEFT #00 0x00000000 A::Bar(char const*) RIGHT\n' |
124 expected += 'LEFT #01 0x00000000 B::Baz(float) RIGHT\n' | 124 expected += 'LEFT #01 0x00000000 B::Baz(float) RIGHT\n' |
125 expected += 'BOTTOM\n' | 125 expected += 'BOTTOM\n' |
126 actual = RunSymbolizer(text) | 126 actual = RunSymbolizer(text) |
127 self.assertEqual(expected, actual) | 127 self.assertEqual(expected, actual) |
128 | 128 |
129 | 129 |
130 if __name__ == '__main__': | 130 if __name__ == '__main__': |
131 unittest.main() | 131 unittest.main() |
OLD | NEW |