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