Index: tools/cygprofile/cyglog_to_orderfile_unittest.py |
diff --git a/tools/cygprofile/cyglog_to_orderfile_unittest.py b/tools/cygprofile/cyglog_to_orderfile_unittest.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..69abc8d3f0e0aa5bf77259a5c4c7ea005f0bccfa |
--- /dev/null |
+++ b/tools/cygprofile/cyglog_to_orderfile_unittest.py |
@@ -0,0 +1,92 @@ |
+#!/usr/bin/python |
+# Copyright 2015 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. |
+ |
+import unittest |
+ |
+import symbol_extractor |
+import cyglog_to_orderfile |
pasko
2015/01/30 19:31:33
should these be sorted alphabetically? (gotcha, my
Benoit L
2015/02/02 09:28:15
Done.
|
+ |
+ |
+class TestSymbolizeTest(unittest.TestCase): |
pasko
2015/01/30 19:31:33
nit: TestCyglogToOrderfile
Benoit L
2015/02/02 09:28:15
Done.
|
+ def testParseLogLines(self): |
+ lines = """5086e000-52e92000 r-xp 00000000 b3:02 51276 libchromeview.so |
+secs usecs pid:threadid func |
+START |
+1314897086 795828 3587:1074648168 0x509e105c |
+1314897086 795874 3587:1074648168 0x509e0eb4 |
+END""".split('\n') |
+ call_info = cyglog_to_orderfile._ParseLogLines(lines) |
+ self.assertEquals(len(call_info), 2) |
+ self.assertEquals( |
+ call_info[0], (1314897086, 795828, '3587:1074648168', |
+ 0x509e105c - 0x5086e000)) |
+ self.assertEquals( |
+ call_info[1], (1314897086, 795874, '3587:1074648168', |
+ 0x509e0eb4 - 0x5086e000)) |
+ |
+ def testFindSymbolInfosAtOffsetExactMatch(self): |
+ offset_map = {0x10: [symbol_extractor.SymbolInfo( |
+ name='Symbol', offset=0x10, size=0x13, section='.text')]} |
+ functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x10) |
+ self.assertEquals(len(functions), 1) |
+ self.assertEquals(functions[0], offset_map[0x10][0]) |
+ |
+ def testFindSymbolInfosAtOffsetInexactMatch(self): |
+ offset_map = {0x10: [symbol_extractor.SymbolInfo( |
+ name='Symbol', offset=0x10, size=0x13, section='.text')]} |
+ functions = cyglog_to_orderfile._FindSymbolInfosAtOffset(offset_map, 0x11) |
+ self.assertEquals(len(functions), 1) |
+ self.assertEquals(functions[0], offset_map[0x10][0]) |
+ |
+ def testFindSymbolInfosAtOffsetNoMatch(self): |
+ offset_map = {0x10: [symbol_extractor.SymbolInfo( |
+ name='Symbol', offset=0x10, size=0x13, section='.text')]} |
+ self.assertRaises( |
+ cyglog_to_orderfile.SymbolNotFoundException, |
+ cyglog_to_orderfile._FindSymbolInfosAtOffset, offset_map, 0x12) |
+ |
+ def testWarnAboutDuplicates(self): |
+ offsets = [0x1, 0x2, 0x3] |
+ self.assertTrue(cyglog_to_orderfile._WarnAboutDuplicates(offsets)) |
+ offsets.append(0x1) |
+ self.assertFalse(cyglog_to_orderfile._WarnAboutDuplicates(offsets)) |
+ |
+ def testOutputOrderfile(self): |
+ class FakeOutputFile(object): |
+ def __init__(self): |
+ self.writes = [] |
+ def write(self, data): |
+ self.writes.append(data) |
+ |
+ # One symbol not matched, one with an odd address, one regularly matched |
+ # And two symbols aliased to the same address |
+ offsets = [0x12, 0x17] |
+ offset_to_symbol_infos = { |
+ 0x10:[symbol_extractor.SymbolInfo( |
+ name='Symbol', offset=0x10, size=0x13, section='dummy')], |
+ 0x12:[symbol_extractor.SymbolInfo( |
+ name='Symbol2', offset=0x12, size=0x13, section='dummy')], |
+ 0x16:[symbol_extractor.SymbolInfo( |
+ name='Symbol3', offset=0x16, size=0x13, section='dummy'), |
+ symbol_extractor.SymbolInfo( |
+ name='Symbol32', offset=0x16, size=0x13, section='dummy'),]} |
+ symbol_to_section_map = { |
+ 'Symbol': '.text.Symbol', |
+ 'Symbol2': '.text.Symbol2', |
+ 'Symbol3': '.text.Symbol3', |
+ 'Symbol32': '.text.Symbol32'} |
+ fake_output = FakeOutputFile() |
+ cyglog_to_orderfile._OutputOrderfile(offsets, offset_to_symbol_infos, |
+ symbol_to_section_map, |
+ fake_output) |
+ expected = """.text.Symbol2 |
+.text.Symbol3 |
+.text.Symbol32 |
+""" |
+ self.assertEquals(expected, "".join(fake_output.writes)) |
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |