Index: build/android/symbolize_test.py |
diff --git a/build/android/symbolize_test.py b/build/android/symbolize_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..05934b876dce6b473447118cc303c3174fc097c9 |
--- /dev/null |
+++ b/build/android/symbolize_test.py |
@@ -0,0 +1,121 @@ |
+#!/usr/bin/env python |
+# |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Unittest for symbolize.py. |
+ |
+This test uses test libraries generated by the Android g++ toolchain. |
+ |
+Should things break you can recreate the libraries and get the updated |
+addresses and demangled names by running the following: |
+ cd test/symbolize/ |
+ make |
+ nm -gC *.so |
+""" |
+ |
+import sys |
+import StringIO |
+import unittest |
+ |
+import symbolize |
+ |
+def RunSymbolizer(text): |
+ output = StringIO.StringIO() |
+ s = symbolize.Symbolizer(StringIO.StringIO(text), output) |
+ s.ProcessInput() |
+ return output.getvalue() |
+ |
+ |
+class SymbolizerUnittest(unittest.TestCase): |
+ def testSingleLineNoMatch(self): |
+ # Leading '#' is required. |
+ expected = '00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Whitespace should be exactly one space. |
+ expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Decimal stack frame numbers are required. |
+ expected = '#0a pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Lowercase 'pc' token is required. |
+ expected = '#00 PC 00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Hexadecimal addresses are required. |
+ expected = '#00 pc ghijklmn /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Addresses must be exactly 8 characters. |
+ expected = '#00 pc 254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 0254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 00254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ expected = '#00 pc 0000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Addresses must not be prefixed with '0x'. |
+ expected = '#00 pc 0x00000254 /build/android/tests/symbolize/liba.so\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ # Library name is required. |
+ expected = '#00 pc 00000254\n' |
+ self.assertEqual(expected, RunSymbolizer(expected)) |
+ |
+ def testSingleLine(self): |
+ text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ expected = '#00 pc 00000254 A::Bar(char const*)\n' |
+ actual = RunSymbolizer(text) |
+ self.assertEqual(expected, actual) |
+ |
+ def testSingleLineWithSurroundingText(self): |
+ text = 'LEFT #00 pc 00000254 /build/android/tests/symbolize/liba.so RIGHT\n' |
+ expected = 'LEFT #00 pc 00000254 A::Bar(char const*) RIGHT\n' |
+ actual = RunSymbolizer(text) |
+ self.assertEqual(expected, actual) |
+ |
+ def testMultipleLinesSameLibrary(self): |
+ text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ text += '#01 pc 00000234 /build/android/tests/symbolize/liba.so\n' |
+ expected = '#00 pc 00000254 A::Bar(char const*)\n' |
+ expected += '#01 pc 00000234 A::Foo(int)\n' |
+ actual = RunSymbolizer(text) |
+ self.assertEqual(expected, actual) |
+ |
+ def testMultipleLinesDifferentLibrary(self): |
+ text = '#00 pc 00000254 /build/android/tests/symbolize/liba.so\n' |
+ text += '#01 pc 00000234 /build/android/tests/symbolize/libb.so\n' |
+ expected = '#00 pc 00000254 A::Bar(char const*)\n' |
+ expected += '#01 pc 00000234 B::Baz(float)\n' |
+ actual = RunSymbolizer(text) |
+ self.assertEqual(expected, actual) |
+ |
+ def testMultipleLinesWithSurroundingTextEverywhere(self): |
+ text = 'TOP\n' |
+ text += ('LEFT #00 pc 00000254 ' |
+ '/build/android/tests/symbolize/liba.so RIGHT\n') |
+ text += ('LEFT #01 pc 00000234 ' |
+ '/build/android/tests/symbolize/libb.so RIGHT\n') |
+ text += 'BOTTOM\n' |
+ expected = 'TOP\n' |
+ expected += 'LEFT #00 pc 00000254 A::Bar(char const*) RIGHT\n' |
+ expected += 'LEFT #01 pc 00000234 B::Baz(float) RIGHT\n' |
+ expected += 'BOTTOM\n' |
+ actual = RunSymbolizer(text) |
+ self.assertEqual(expected, actual) |
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |