Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Unified Diff: tools/cygprofile/cyglog_to_orderfile_unittest.py

Issue 874683004: Refactor the symbolize step of the orderfile generation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Change filenames. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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()
« tools/cygprofile/cyglog_to_orderfile.py ('K') | « tools/cygprofile/cyglog_to_orderfile.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698