| 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' |
| 25 LIB_B_PATH = '/build/android/tests/symbolize/libb.so' |
| 26 |
| 24 def RunSymbolizer(text): | 27 def RunSymbolizer(text): |
| 25 output = StringIO.StringIO() | 28 output = StringIO.StringIO() |
| 26 s = symbolize.Symbolizer(StringIO.StringIO(text), output) | 29 s = symbolize.Symbolizer(StringIO.StringIO(text), output) |
| 27 s.ProcessInput() | 30 s.ProcessInput() |
| 28 return output.getvalue() | 31 return output.getvalue() |
| 29 | 32 |
| 30 | 33 |
| 31 class SymbolizerUnittest(unittest.TestCase): | 34 class SymbolizerUnittest(unittest.TestCase): |
| 32 def testSingleLineNoMatch(self): | 35 def testSingleLineNoMatch(self): |
| 33 # Leading '#' is required. | 36 # Leading '#' is required. |
| 34 expected = '00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 37 expected = '00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 35 self.assertEqual(expected, RunSymbolizer(expected)) | 38 self.assertEqual(expected, RunSymbolizer(expected)) |
| 36 | 39 |
| 37 # Whitespace should be exactly one space. | 40 # Whitespace should be exactly one space. |
| 38 expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 41 expected = '#00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 39 self.assertEqual(expected, RunSymbolizer(expected)) | 42 self.assertEqual(expected, RunSymbolizer(expected)) |
| 40 expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 43 expected = '#00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 41 self.assertEqual(expected, RunSymbolizer(expected)) | |
| 42 expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | |
| 43 self.assertEqual(expected, RunSymbolizer(expected)) | 44 self.assertEqual(expected, RunSymbolizer(expected)) |
| 44 | 45 |
| 45 # Decimal stack frame numbers are required. | 46 # Decimal stack frame numbers are required. |
| 46 expected = '#0a pc 00000254 /build/android/tests/symbolize/liba.so\n' | 47 expected = '#0a 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 47 self.assertEqual(expected, RunSymbolizer(expected)) | |
| 48 | |
| 49 # Lowercase 'pc' token is required. | |
| 50 expected = '#00 PC 00000254 /build/android/tests/symbolize/liba.so\n' | |
| 51 self.assertEqual(expected, RunSymbolizer(expected)) | 48 self.assertEqual(expected, RunSymbolizer(expected)) |
| 52 | 49 |
| 53 # Hexadecimal addresses are required. | 50 # Hexadecimal addresses are required. |
| 54 expected = '#00 pc ghijklmn /build/android/tests/symbolize/liba.so\n' | 51 expected = '#00 0xghijklmn ' + LIB_A_PATH + '+0x00000254\n' |
| 52 self.assertEqual(expected, RunSymbolizer(expected)) |
| 53 expected = '#00 0x00000000 ' + LIB_A_PATH + '+0xghijklmn\n' |
| 55 self.assertEqual(expected, RunSymbolizer(expected)) | 54 self.assertEqual(expected, RunSymbolizer(expected)) |
| 56 | 55 |
| 57 # Addresses must be exactly 8 characters. | 56 # Addresses must be exactly 8 characters. |
| 58 expected = '#00 pc 254 /build/android/tests/symbolize/liba.so\n' | 57 expected = '#00 0x0000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 59 self.assertEqual(expected, RunSymbolizer(expected)) | 58 self.assertEqual(expected, RunSymbolizer(expected)) |
| 60 expected = '#00 pc 0254 /build/android/tests/symbolize/liba.so\n' | 59 expected = '#00 0x000000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 61 self.assertEqual(expected, RunSymbolizer(expected)) | |
| 62 expected = '#00 pc 00254 /build/android/tests/symbolize/liba.so\n' | |
| 63 self.assertEqual(expected, RunSymbolizer(expected)) | |
| 64 expected = '#00 pc 000254 /build/android/tests/symbolize/liba.so\n' | |
| 65 self.assertEqual(expected, RunSymbolizer(expected)) | |
| 66 expected = '#00 pc 0000254 /build/android/tests/symbolize/liba.so\n' | |
| 67 self.assertEqual(expected, RunSymbolizer(expected)) | 60 self.assertEqual(expected, RunSymbolizer(expected)) |
| 68 | 61 |
| 69 # Addresses must not be prefixed with '0x'. | 62 expected = '#00 0x0000000 ' + LIB_A_PATH + '+0x0000254\n' |
| 70 expected = '#00 pc 0x00000254 /build/android/tests/symbolize/liba.so\n' | 63 self.assertEqual(expected, RunSymbolizer(expected)) |
| 64 expected = '#00 0x000000000 ' + LIB_A_PATH + '+0x000000254\n' |
| 65 self.assertEqual(expected, RunSymbolizer(expected)) |
| 66 |
| 67 # Addresses must be prefixed with '0x'. |
| 68 expected = '#00 00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 69 self.assertEqual(expected, RunSymbolizer(expected)) |
| 70 expected = '#00 0x00000000 ' + LIB_A_PATH + '+00000254\n' |
| 71 self.assertEqual(expected, RunSymbolizer(expected)) | 71 self.assertEqual(expected, RunSymbolizer(expected)) |
| 72 | 72 |
| 73 # Library name is required. | 73 # Library name is required. |
| 74 expected = '#00 pc 00000254\n' | 74 expected = '#00 0x00000000\n' |
| 75 self.assertEqual(expected, RunSymbolizer(expected)) |
| 76 expected = '#00 0x00000000 +0x00000254\n' |
| 77 self.assertEqual(expected, RunSymbolizer(expected)) |
| 78 |
| 79 # Library name must be followed by offset with no spaces around '+'. |
| 80 expected = '#00 0x00000000 ' + LIB_A_PATH + ' +0x00000254\n' |
| 81 self.assertEqual(expected, RunSymbolizer(expected)) |
| 82 expected = '#00 0x00000000 ' + LIB_A_PATH + '+ 0x00000254\n' |
| 83 self.assertEqual(expected, RunSymbolizer(expected)) |
| 84 expected = '#00 0x00000000 ' + LIB_A_PATH + ' 0x00000254\n' |
| 85 self.assertEqual(expected, RunSymbolizer(expected)) |
| 86 expected = '#00 0x00000000 ' + LIB_A_PATH + '+\n' |
| 75 self.assertEqual(expected, RunSymbolizer(expected)) | 87 self.assertEqual(expected, RunSymbolizer(expected)) |
| 76 | 88 |
| 77 def testSingleLine(self): | 89 def testSingleLine(self): |
| 78 text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 90 text = '#00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 79 expected = '#00 pc 00000254 A::Bar(char const*)\n' | 91 expected = '#00 0x00000000 A::Bar(char const*)\n' |
| 80 actual = RunSymbolizer(text) | 92 actual = RunSymbolizer(text) |
| 81 self.assertEqual(expected, actual) | 93 self.assertEqual(expected, actual) |
| 82 | 94 |
| 83 def testSingleLineWithSurroundingText(self): | 95 def testSingleLineWithSurroundingText(self): |
| 84 text = 'LEFT #00 pc 00000254 /build/android/tests/symbolize/liba.so RIGHT\n' | 96 text = 'LEFT #00 0x00000000 ' + LIB_A_PATH + '+0x00000254 RIGHT\n' |
| 85 expected = 'LEFT #00 pc 00000254 A::Bar(char const*) RIGHT\n' | 97 expected = 'LEFT #00 0x00000000 A::Bar(char const*) RIGHT\n' |
| 86 actual = RunSymbolizer(text) | 98 actual = RunSymbolizer(text) |
| 87 self.assertEqual(expected, actual) | 99 self.assertEqual(expected, actual) |
| 88 | 100 |
| 89 def testMultipleLinesSameLibrary(self): | 101 def testMultipleLinesSameLibrary(self): |
| 90 text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 102 text = '#00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 91 text += '#01 pc 00000234 /build/android/tests/symbolize/liba.so\n' | 103 text += '#01 0x00000000 ' + LIB_A_PATH + '+0x00000234\n' |
| 92 expected = '#00 pc 00000254 A::Bar(char const*)\n' | 104 expected = '#00 0x00000000 A::Bar(char const*)\n' |
| 93 expected += '#01 pc 00000234 A::Foo(int)\n' | 105 expected += '#01 0x00000000 A::Foo(int)\n' |
| 94 actual = RunSymbolizer(text) | 106 actual = RunSymbolizer(text) |
| 95 self.assertEqual(expected, actual) | 107 self.assertEqual(expected, actual) |
| 96 | 108 |
| 97 def testMultipleLinesDifferentLibrary(self): | 109 def testMultipleLinesDifferentLibrary(self): |
| 98 text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' | 110 text = '#00 0x00000000 ' + LIB_A_PATH + '+0x00000254\n' |
| 99 text += '#01 pc 00000234 /build/android/tests/symbolize/libb.so\n' | 111 text += '#01 0x00000000 ' + LIB_B_PATH + '+0x00000234\n' |
| 100 expected = '#00 pc 00000254 A::Bar(char const*)\n' | 112 expected = '#00 0x00000000 A::Bar(char const*)\n' |
| 101 expected += '#01 pc 00000234 B::Baz(float)\n' | 113 expected += '#01 0x00000000 B::Baz(float)\n' |
| 102 actual = RunSymbolizer(text) | 114 actual = RunSymbolizer(text) |
| 103 self.assertEqual(expected, actual) | 115 self.assertEqual(expected, actual) |
| 104 | 116 |
| 105 def testMultipleLinesWithSurroundingTextEverywhere(self): | 117 def testMultipleLinesWithSurroundingTextEverywhere(self): |
| 106 text = 'TOP\n' | 118 text = 'TOP\n' |
| 107 text += ('LEFT #00 pc 00000254 ' | 119 text += 'LEFT #00 0x00000000 ' + LIB_A_PATH + '+0x00000254 RIGHT\n' |
| 108 '/build/android/tests/symbolize/liba.so RIGHT\n') | 120 text += 'LEFT #01 0x00000000 ' + LIB_B_PATH + '+0x00000234 RIGHT\n' |
| 109 text += ('LEFT #01 pc 00000234 ' | |
| 110 '/build/android/tests/symbolize/libb.so RIGHT\n') | |
| 111 text += 'BOTTOM\n' | 121 text += 'BOTTOM\n' |
| 112 expected = 'TOP\n' | 122 expected = 'TOP\n' |
| 113 expected += 'LEFT #00 pc 00000254 A::Bar(char const*) RIGHT\n' | 123 expected += 'LEFT #00 0x00000000 A::Bar(char const*) RIGHT\n' |
| 114 expected += 'LEFT #01 pc 00000234 B::Baz(float) RIGHT\n' | 124 expected += 'LEFT #01 0x00000000 B::Baz(float) RIGHT\n' |
| 115 expected += 'BOTTOM\n' | 125 expected += 'BOTTOM\n' |
| 116 actual = RunSymbolizer(text) | 126 actual = RunSymbolizer(text) |
| 117 self.assertEqual(expected, actual) | 127 self.assertEqual(expected, actual) |
| 118 | 128 |
| 119 | 129 |
| 120 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 121 unittest.main() | 131 unittest.main() |
| OLD | NEW |