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