OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium 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 |
| 6 import datetime |
| 7 import default_flavor |
| 8 import posixpath |
| 9 import ssh_devices |
| 10 |
| 11 |
| 12 """Utils for running coverage tests.""" |
| 13 |
| 14 |
| 15 class CoverageFlavorUtils(default_flavor.DefaultFlavorUtils): |
| 16 |
| 17 def step(self, name, cmd, **kwargs): |
| 18 """Run the given step through coverage.""" |
| 19 compile_target = 'dm' |
| 20 build_cmd = [self._skia_api.skia_dir.join('tools', 'llvm_coverage_build'), |
| 21 compile_target] |
| 22 self._skia_api.run(self._skia_api.m.step, |
| 23 'build %s' % compile_target, |
| 24 cmd=build_cmd, |
| 25 cwd=self._skia_api.m.path['checkout']) |
| 26 |
| 27 # Slice out the 'key' and 'properties' arguments to be reused. |
| 28 key = [] |
| 29 properties = [] |
| 30 current = None |
| 31 for i in xrange(0, len(cmd)): |
| 32 if isinstance(cmd[i], basestring) and cmd[i] == '--key': |
| 33 current = key |
| 34 elif isinstance(cmd[i], basestring) and cmd[i] == '--properties': |
| 35 current = properties |
| 36 elif isinstance(cmd[i], basestring) and cmd[i].startswith('--'): |
| 37 current = None |
| 38 if current is not None: |
| 39 current.append(cmd[i]) |
| 40 |
| 41 results_dir = self._skia_api.skia_out.join('coverage_results') |
| 42 self.create_clean_host_dir(results_dir) |
| 43 |
| 44 # Run DM under coverage. |
| 45 report_file_basename = '%s.cov' % self._skia_api.got_revision |
| 46 report_file = results_dir.join(report_file_basename) |
| 47 args = [ |
| 48 'python', |
| 49 self._skia_api.skia_dir.join('tools', 'llvm_coverage_run.py'), |
| 50 ] + cmd + ['--outResultsFile', report_file] |
| 51 self._skia_api.run(self._skia_api.m.step, name=name, cmd=args, |
| 52 cwd=self._skia_api.m.path['checkout'], **kwargs) |
| 53 |
| 54 # Generate nanobench-style JSON output from the coverage report. |
| 55 nanobench_json = results_dir.join('nanobench_%s.json' % ( |
| 56 self._skia_api.got_revision)) |
| 57 line_by_line_basename = ('coverage_by_line_%s.json' % ( |
| 58 self._skia_api.got_revision)) |
| 59 line_by_line = results_dir.join(line_by_line_basename) |
| 60 args = [ |
| 61 'python', |
| 62 self._skia_api.skia_dir.join('tools', 'parse_llvm_coverage.py'), |
| 63 '--report', report_file, '--nanobench', nanobench_json, |
| 64 '--linebyline', line_by_line] |
| 65 args.extend(key) |
| 66 args.extend(properties) |
| 67 self._skia_api.run( |
| 68 self._skia_api.m.step, |
| 69 'Generate Coverage Data', |
| 70 cmd=args, cwd=self._skia_api.m.path['checkout']) |
| 71 |
| 72 # Copy files from results_dir into swarming_out_dir. |
| 73 for r in self._skia_api.m.file.listdir('results_dir', results_dir): |
| 74 self._skia_api.m.file.copy( |
| 75 'Copy to swarming out', results_dir.join(r), |
| 76 self._skia_api.swarming_out_dir) |
OLD | NEW |