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

Side by Side Diff: tools/sanitizers/sancov_formatter_test.py

Issue 1737263003: [coverage] Enable sanitizer coverage. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Documentation Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 the V8 project authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import copy
6 import coverage
kjellander_chromium 2016/03/04 14:35:22 Can coverage be assumed to be present? Since it's
Michael Achenbach 2016/03/04 15:00:26 Added a comment. I assume it's installed by whoeve
7 import os
8 import sys
9 import unittest
10
11
12 # Directory of this file.
13 LOCATION = os.path.dirname(os.path.abspath(__file__))
14
15 # V8 checkout directory.
16 BASE_DIR = os.path.dirname(os.path.dirname(LOCATION))
17
18 # Executable location.
19 BUILD_DIR = os.path.join(BASE_DIR, 'out', 'Release')
20
21 def abs_line(line):
22 """Absolute paths as output by the llvm symbolizer."""
23 return '%s/%s' % (BUILD_DIR, line)
24
25 #------------------------------------------------------------------------------
26
27 # Data for test_process_symbolizer_output. This simulates output from the
28 # llvm symbolizer. The paths are not normlized.
29 SYMBOLIZER_OUTPUT = (
30 abs_line('../../src/foo.cc:87:7\n') +
31 abs_line('../../src/foo.cc:92:0\n') + # Test sorting.
32 abs_line('../../src/baz/bar.h:1234567:0\n') + # Test large line numbers.
33 abs_line('../../src/foo.cc:92:0\n') + # Test duplicates.
34 abs_line('../../src/baz/bar.h:0:0\n') + # Test subdirs.
35 '/usr/include/cool_stuff.h:14:2\n' + # Test dropping absolute paths.
36 abs_line('../../src/foo.cc:87:10\n') + # Test dropping character indexes.
37 abs_line('../../third_party/icu.cc:0:0\n') + # Test dropping excluded dirs.
38 abs_line('../../src/baz/bar.h:11:0\n')
39 )
40
41 # The expected post-processed output maps relative file names to line numbers.
42 # The numbers are sorted and unique.
43 EXPECTED_PROCESSED_OUTPUT = {
44 'src/baz/bar.h': [0, 11, 1234567],
45 'src/foo.cc': [87, 92],
46 }
47
48 #------------------------------------------------------------------------------
49
50 # Data for test_merge_instrumented_line_results. A list of absolute paths to
51 # all executables.
52 EXE_LIST = [
53 '/path/to/d8',
54 '/path/to/cctest',
55 '/path/to/unittests',
56 ]
57
58 # Post-processed llvm symbolizer output as returned by
59 # process_symbolizer_output. These are lists of this output for merging.
60 INSTRUMENTED_LINE_RESULTS = [
61 {
62 'src/baz/bar.h': [0, 3, 7],
63 'src/foo.cc': [11],
64 },
65 {
66 'src/baz/bar.h': [3, 7, 8],
67 'src/baz.cc': [2],
68 'src/foo.cc': [1, 92],
69 },
70 {
71 'src/baz.cc': [1],
72 'src/foo.cc': [92, 93],
73 },
74 ]
75
76 # This shows initial instrumentation. No lines are covered, hence,
77 # the coverage mask is 0 for all lines. The line tuples remain sorted by
78 # line number and contain no duplicates.
79 EXPECTED_INSTRUMENTED_LINES_DATA = {
80 'version': 1,
81 'tests': ['cctest', 'd8', 'unittests'],
82 'files': {
83 'src/baz/bar.h': [[0, 0], [3, 0], [7, 0], [8, 0]],
84 'src/baz.cc': [[1, 0], [2, 0]],
85 'src/foo.cc': [[1, 0], [11, 0], [92, 0], [93, 0]],
86 },
87 }
88
89 #------------------------------------------------------------------------------
90
91 # Data for test_merge_covered_line_results. List of post-processed
92 # llvm-symbolizer output as a tuple including the executable name of each data
93 # set.
94 COVERED_LINE_RESULTS = [
95 ({
96 'src/baz/bar.h': [3, 7],
97 'src/foo.cc': [11],
98 }, 'd8'),
99 ({
100 'src/baz/bar.h': [3, 7],
101 'src/baz.cc': [2],
102 'src/foo.cc': [1],
103 }, 'cctest'),
104 ({
105 'src/foo.cc': [92],
106 'src/baz.cc': [2],
107 }, 'unittests'),
108 ]
109
110 # This shows initial instrumentation + coverage. The mask bits are:
111 # cctest: 1, d8: 2, unittests:4. So a line covered by cctest and unittests
112 # has a coverage mask of 5, e.g. line 2 in src/baz.cc.
113 EXPECTED_COVERED_LINES_DATA = {
114 'version': 1,
115 'tests': ['cctest', 'd8', 'unittests'],
116 'files': {
117 'src/baz/bar.h': [[0, 0], [3, 3], [7, 3], [8, 0]],
118 'src/baz.cc': [[1, 0], [2, 5]],
119 'src/foo.cc': [[1, 1], [11, 2], [92, 4], [93, 0]],
120 },
121 }
122
kjellander_chromium 2016/03/04 14:35:22 nit: +1 blank line before top-level class.
Michael Achenbach 2016/03/04 15:00:25 Done.
123 class FormatterTests(unittest.TestCase):
124 @classmethod
125 def setUpClass(cls):
126 sys.path.append(LOCATION)
127 cls._cov = coverage.coverage(
kjellander_chromium 2016/03/04 14:35:22 I guess coverage was used mostly for development t
Michael Achenbach 2016/03/04 15:00:26 Don't know. Development isn't over yet :) This is
128 include=([os.path.join(LOCATION, 'sancov_formatter.py')]))
129 cls._cov.start()
130 import sancov_formatter
131 global sancov_formatter
132
133 @classmethod
134 def tearDownClass(cls):
135 cls._cov.stop()
136 print ""
137 print cls._cov.report()
kjellander_chromium 2016/03/04 14:35:22 I don't think you should print things to stdout by
Michael Achenbach 2016/03/04 15:00:26 Just using the raw reporting now. It's tricky to g
138
139 def test_process_symbolizer_output(self):
140 result = sancov_formatter.process_symbolizer_output(SYMBOLIZER_OUTPUT)
141 self.assertEquals(EXPECTED_PROCESSED_OUTPUT, result)
142
143 def test_merge_instrumented_line_results(self):
144 result = sancov_formatter.merge_instrumented_line_results(
145 EXE_LIST, INSTRUMENTED_LINE_RESULTS)
146 self.assertEquals(EXPECTED_INSTRUMENTED_LINES_DATA, result)
147
148 def test_merge_covered_line_results(self):
149 data = copy.deepcopy(EXPECTED_INSTRUMENTED_LINES_DATA)
150 sancov_formatter.merge_covered_line_results(
151 data, COVERED_LINE_RESULTS)
152 self.assertEquals(EXPECTED_COVERED_LINES_DATA, data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698