aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/recipe_modules/skia/coverage_flavor.py
blob: 5fd853363dc1616f8c2f55c48bfd8b465757f0ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2014 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 datetime
import default_flavor
import posixpath
import ssh_devices


"""Utils for running coverage tests."""


class CoverageFlavorUtils(default_flavor.DefaultFlavorUtils):

  def step(self, name, cmd, **kwargs):
    """Run the given step through coverage."""
    compile_target = 'dm'
    build_cmd = [self._skia_api.skia_dir.join('tools', 'llvm_coverage_build'),
                 compile_target]
    self._skia_api.run(self._skia_api.m.step,
                       'build %s' % compile_target,
                       cmd=build_cmd,
                       cwd=self._skia_api.m.path['checkout'])

    # Slice out the 'key' and 'properties' arguments to be reused.
    key = []
    properties = []
    current = None
    for i in xrange(0, len(cmd)):
      if isinstance(cmd[i], basestring) and cmd[i] == '--key':
        current = key
      elif isinstance(cmd[i], basestring) and cmd[i] == '--properties':
        current = properties
      elif isinstance(cmd[i], basestring) and cmd[i].startswith('--'):
        current = None
      if current is not None:
        current.append(cmd[i])

    results_dir = self._skia_api.skia_out.join('coverage_results')
    self.create_clean_host_dir(results_dir)

    # Run DM under coverage.
    report_file_basename = '%s.cov' % self._skia_api.got_revision
    report_file = results_dir.join(report_file_basename)
    args = [
        'python',
        self._skia_api.skia_dir.join('tools', 'llvm_coverage_run.py'),
    ] + cmd + ['--outResultsFile', report_file]
    self._skia_api.run(self._skia_api.m.step, name=name, cmd=args,
                       cwd=self._skia_api.m.path['checkout'], **kwargs)

    # Generate nanobench-style JSON output from the coverage report.
    nanobench_json = results_dir.join('nanobench_%s.json' % (
        self._skia_api.got_revision))
    line_by_line_basename = ('coverage_by_line_%s.json' % (
        self._skia_api.got_revision))
    line_by_line = results_dir.join(line_by_line_basename)
    args = [
        'python',
        self._skia_api.skia_dir.join('tools', 'parse_llvm_coverage.py'),
        '--report', report_file, '--nanobench', nanobench_json,
        '--linebyline', line_by_line]
    args.extend(key)
    args.extend(properties)
    self._skia_api.run(
        self._skia_api.m.step,
        'Generate Coverage Data',
        cmd=args, cwd=self._skia_api.m.path['checkout'])

    # Copy files from results_dir into swarming_out_dir.
    for r in self._skia_api.m.file.listdir('results_dir', results_dir):
      self._skia_api.m.file.copy(
          'Copy to swarming out', results_dir.join(r),
          self._skia_api.swarming_out_dir)