v8/tools/sanitizers/sancov_merger_test.py
machenbach 33ffced5cc [coverage] Enable sanitizer coverage.
This adds sanitizer-coverage compilation, test-runner
features and post processing.

Sanitizer coverage is expected to be used together with
asan.

During test runner execution, the produced sancov files
are disambiguated and match the pattern:
<executable name>.test.<test id>.sancov.

Two additional scripts are added for merging raw sancov
files and for generating json data containing all
instrumented lines + all covered lines from merged sancov
files. Both scripts use multiprocessing for speed.

The json data will later be uploaded to google storage
for further use, e.g. to show coverage data in rietveld.

Sancov documentation:
http://clang.llvm.org/docs/SanitizerCoverage.html

BUG=chromium:568949
LOG=n
NOTRY=true
TEST=python -m unittest sancov_formatter_test
TEST=python -m unittest sancov_merger_test

Review URL: https://codereview.chromium.org/1737263003

Cr-Commit-Position: refs/heads/master@{#34578}
2016-03-08 10:48:35 +00:00

83 lines
2.1 KiB
Python

# Copyright 2016 the V8 project 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 sancov_merger
# Files on disk after test runner completes. The files are mapped by
# executable name -> file list.
FILE_MAP = {
'd8': [
'd8.test.1.sancov',
'd8.test.2.sancov',
'd8.test.3.sancov',
'd8.test.4.sancov',
'd8.test.5.sancov',
'd8.test.6.sancov',
'd8.test.7.sancov',
],
'cctest': [
'cctest.test.1.sancov',
'cctest.test.2.sancov',
'cctest.test.3.sancov',
'cctest.test.4.sancov',
],
}
# Inputs for merge process with 2 cpus. The tuples contain:
# (flag, path, executable name, intermediate result index, file list).
EXPECTED_INPUTS_2 = [
(False, '/some/path', 'cctest', 0, [
'cctest.test.1.sancov',
'cctest.test.2.sancov']),
(False, '/some/path', 'cctest', 1, [
'cctest.test.3.sancov',
'cctest.test.4.sancov']),
(False, '/some/path', 'd8', 0, [
'd8.test.1.sancov',
'd8.test.2.sancov',
'd8.test.3.sancov',
'd8.test.4.sancov']),
(False, '/some/path', 'd8', 1, [
'd8.test.5.sancov',
'd8.test.6.sancov',
'd8.test.7.sancov']),
]
# The same for 4 cpus.
EXPECTED_INPUTS_4 = [
(True, '/some/path', 'cctest', 0, [
'cctest.test.1.sancov',
'cctest.test.2.sancov']),
(True, '/some/path', 'cctest', 1, [
'cctest.test.3.sancov',
'cctest.test.4.sancov']),
(True, '/some/path', 'd8', 0, [
'd8.test.1.sancov',
'd8.test.2.sancov']),
(True, '/some/path', 'd8', 1, [
'd8.test.3.sancov',
'd8.test.4.sancov']),
(True, '/some/path', 'd8', 2, [
'd8.test.5.sancov',
'd8.test.6.sancov']),
(True, '/some/path', 'd8', 3, [
'd8.test.7.sancov'])]
class MergerTests(unittest.TestCase):
def test_generate_inputs_2_cpu(self):
inputs = sancov_merger.generate_inputs(
False, '/some/path', FILE_MAP, 2)
self.assertEquals(EXPECTED_INPUTS_2, inputs)
def test_generate_inputs_4_cpu(self):
inputs = sancov_merger.generate_inputs(
True, '/some/path', FILE_MAP, 4)
self.assertEquals(EXPECTED_INPUTS_4, inputs)