| 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 | |
| 10 | |
| 11 """Utils for running coverage tests.""" | |
| 12 | |
| 13 | |
| 14 class CoverageFlavorUtils(default_flavor.DefaultFlavorUtils): | |
| 15 | |
| 16 def step(self, name, cmd, **kwargs): | |
| 17 """Run the given step through coverage.""" | |
| 18 compile_target = 'dm' | |
| 19 build_cmd = [self.m.vars.skia_dir.join('tools', 'llvm_coverage_build'), | |
| 20 compile_target] | |
| 21 build_env = kwargs.pop('env', {}) | |
| 22 # We have to use Clang 3.6 because earlier versions do not support the | |
| 23 # compile flags we use and 3.7 and 3.8 hit asserts during compilation. | |
| 24 build_env['CC'] = '/usr/bin/clang-3.6' | |
| 25 build_env['CXX'] = '/usr/bin/clang++-3.6' | |
| 26 build_env['GYP_DEFINES'] = ( | |
| 27 'skia_arch_type=x86_64 ' | |
| 28 'skia_clang_build=1 ' | |
| 29 'skia_gpu=0 ' | |
| 30 'skia_warnings_as_errors=0') | |
| 31 self.m.step('build %s' % compile_target, | |
| 32 cmd=build_cmd, | |
| 33 cwd=self.m.path['checkout'], | |
| 34 env=build_env, | |
| 35 **kwargs) | |
| 36 | |
| 37 # Slice out the 'key' and 'properties' arguments to be reused. | |
| 38 key = [] | |
| 39 properties = [] | |
| 40 current = None | |
| 41 for i in xrange(0, len(cmd)): | |
| 42 if isinstance(cmd[i], basestring) and cmd[i] == '--key': | |
| 43 current = key | |
| 44 elif isinstance(cmd[i], basestring) and cmd[i] == '--properties': | |
| 45 current = properties | |
| 46 elif isinstance(cmd[i], basestring) and cmd[i].startswith('--'): | |
| 47 current = None | |
| 48 if current is not None: | |
| 49 current.append(cmd[i]) | |
| 50 | |
| 51 results_dir = self.m.vars.skia_out.join('coverage_results') | |
| 52 self.create_clean_host_dir(results_dir) | |
| 53 | |
| 54 # Run DM under coverage. | |
| 55 report_file_basename = '%s.cov' % self.m.vars.got_revision | |
| 56 report_file = results_dir.join(report_file_basename) | |
| 57 args = [ | |
| 58 'python', | |
| 59 self.m.vars.skia_dir.join('tools', 'llvm_coverage_run.py'), | |
| 60 ] + cmd + ['--outResultsFile', report_file] | |
| 61 self.m.run(self.m.step, name=name, cmd=args, | |
| 62 cwd=self.m.path['checkout'], **kwargs) | |
| 63 | |
| 64 # Generate nanobench-style JSON output from the coverage report. | |
| 65 nanobench_json = results_dir.join('nanobench_%s.json' % ( | |
| 66 self.m.vars.got_revision)) | |
| 67 line_by_line_basename = ('coverage_by_line_%s.json' % ( | |
| 68 self.m.vars.got_revision)) | |
| 69 line_by_line = results_dir.join(line_by_line_basename) | |
| 70 args = [ | |
| 71 'python', | |
| 72 self.m.vars.skia_dir.join('tools', 'parse_llvm_coverage.py'), | |
| 73 '--report', report_file, '--nanobench', nanobench_json, | |
| 74 '--linebyline', line_by_line] | |
| 75 args.extend(key) | |
| 76 args.extend(properties) | |
| 77 self.m.run( | |
| 78 self.m.step, | |
| 79 'Generate Coverage Data', | |
| 80 cmd=args, cwd=self.m.path['checkout']) | |
| 81 | |
| 82 # Copy files from results_dir into swarming_out_dir. | |
| 83 for r in self.m.file.listdir('results_dir', results_dir): | |
| 84 self.m.file.copy( | |
| 85 'Copy to swarming out', results_dir.join(r), | |
| 86 self.m.vars.swarming_out_dir) | |
| OLD | NEW |