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

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: Logging + exe blacklist 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
« no previous file with comments | « tools/sanitizers/sancov_formatter.py ('k') | tools/sanitizers/sancov_merger.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 # Requires python-coverage. Native python coverage version >= 3.7.1 should
6 # be installed to get the best speed.
7
8 import copy
9 import coverage
10 import logging
11 import os
12 import sys
13 import unittest
14
15
16 # Directory of this file.
17 LOCATION = os.path.dirname(os.path.abspath(__file__))
18
19 # V8 checkout directory.
20 BASE_DIR = os.path.dirname(os.path.dirname(LOCATION))
21
22 # Executable location.
23 BUILD_DIR = os.path.join(BASE_DIR, 'out', 'Release')
24
25 def abs_line(line):
26 """Absolute paths as output by the llvm symbolizer."""
27 return '%s/%s' % (BUILD_DIR, line)
28
29
30 #------------------------------------------------------------------------------
31
32 # Data for test_process_symbolizer_output. This simulates output from the
33 # llvm symbolizer. The paths are not normlized.
34 SYMBOLIZER_OUTPUT = (
35 abs_line('../../src/foo.cc:87:7\n') +
36 abs_line('../../src/foo.cc:92:0\n') + # Test sorting.
37 abs_line('../../src/baz/bar.h:1234567:0\n') + # Test large line numbers.
38 abs_line('../../src/foo.cc:92:0\n') + # Test duplicates.
39 abs_line('../../src/baz/bar.h:0:0\n') + # Test subdirs.
40 '/usr/include/cool_stuff.h:14:2\n' + # Test dropping absolute paths.
41 abs_line('../../src/foo.cc:87:10\n') + # Test dropping character indexes.
42 abs_line('../../third_party/icu.cc:0:0\n') + # Test dropping excluded dirs.
43 abs_line('../../src/baz/bar.h:11:0\n')
44 )
45
46 # The expected post-processed output maps relative file names to line numbers.
47 # The numbers are sorted and unique.
48 EXPECTED_PROCESSED_OUTPUT = {
49 'src/baz/bar.h': [0, 11, 1234567],
50 'src/foo.cc': [87, 92],
51 }
52
53
54 #------------------------------------------------------------------------------
55
56 # Data for test_merge_instrumented_line_results. A list of absolute paths to
57 # all executables.
58 EXE_LIST = [
59 '/path/to/d8',
60 '/path/to/cctest',
61 '/path/to/unittests',
62 ]
63
64 # Post-processed llvm symbolizer output as returned by
65 # process_symbolizer_output. These are lists of this output for merging.
66 INSTRUMENTED_LINE_RESULTS = [
67 {
68 'src/baz/bar.h': [0, 3, 7],
69 'src/foo.cc': [11],
70 },
71 {
72 'src/baz/bar.h': [3, 7, 8],
73 'src/baz.cc': [2],
74 'src/foo.cc': [1, 92],
75 },
76 {
77 'src/baz.cc': [1],
78 'src/foo.cc': [92, 93],
79 },
80 ]
81
82 # This shows initial instrumentation. No lines are covered, hence,
83 # the coverage mask is 0 for all lines. The line tuples remain sorted by
84 # line number and contain no duplicates.
85 EXPECTED_INSTRUMENTED_LINES_DATA = {
86 'version': 1,
87 'tests': ['cctest', 'd8', 'unittests'],
88 'files': {
89 'src/baz/bar.h': [[0, 0], [3, 0], [7, 0], [8, 0]],
90 'src/baz.cc': [[1, 0], [2, 0]],
91 'src/foo.cc': [[1, 0], [11, 0], [92, 0], [93, 0]],
92 },
93 }
94
95
96 #------------------------------------------------------------------------------
97
98 # Data for test_merge_covered_line_results. List of post-processed
99 # llvm-symbolizer output as a tuple including the executable name of each data
100 # set.
101 COVERED_LINE_RESULTS = [
102 ({
103 'src/baz/bar.h': [3, 7],
104 'src/foo.cc': [11],
105 }, 'd8'),
106 ({
107 'src/baz/bar.h': [3, 7],
108 'src/baz.cc': [2],
109 'src/foo.cc': [1],
110 }, 'cctest'),
111 ({
112 'src/foo.cc': [92],
113 'src/baz.cc': [2],
114 }, 'unittests'),
115 ]
116
117 # This shows initial instrumentation + coverage. The mask bits are:
118 # cctest: 1, d8: 2, unittests:4. So a line covered by cctest and unittests
119 # has a coverage mask of 0b101, e.g. line 2 in src/baz.cc.
120 EXPECTED_COVERED_LINES_DATA = {
121 'version': 1,
122 'tests': ['cctest', 'd8', 'unittests'],
123 'files': {
124 'src/baz/bar.h': [[0, 0b0], [3, 0b11], [7, 0b11], [8, 0b0]],
125 'src/baz.cc': [[1, 0b0], [2, 0b101]],
126 'src/foo.cc': [[1, 0b1], [11, 0b10], [92, 0b100], [93, 0b0]],
127 },
128 }
129
130
131 class FormatterTests(unittest.TestCase):
132 @classmethod
133 def setUpClass(cls):
134 sys.path.append(LOCATION)
135 cls._cov = coverage.coverage(
136 include=([os.path.join(LOCATION, 'sancov_formatter.py')]))
137 cls._cov.start()
138 import sancov_formatter
139 global sancov_formatter
140
141 @classmethod
142 def tearDownClass(cls):
143 cls._cov.stop()
144 cls._cov.report()
145
146 def test_process_symbolizer_output(self):
147 result = sancov_formatter.process_symbolizer_output(SYMBOLIZER_OUTPUT)
148 self.assertEquals(EXPECTED_PROCESSED_OUTPUT, result)
149
150 def test_merge_instrumented_line_results(self):
151 result = sancov_formatter.merge_instrumented_line_results(
152 EXE_LIST, INSTRUMENTED_LINE_RESULTS)
153 self.assertEquals(EXPECTED_INSTRUMENTED_LINES_DATA, result)
154
155 def test_merge_covered_line_results(self):
156 data = copy.deepcopy(EXPECTED_INSTRUMENTED_LINES_DATA)
157 sancov_formatter.merge_covered_line_results(
158 data, COVERED_LINE_RESULTS)
159 self.assertEquals(EXPECTED_COVERED_LINES_DATA, data)
OLDNEW
« no previous file with comments | « tools/sanitizers/sancov_formatter.py ('k') | tools/sanitizers/sancov_merger.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698