OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright 2016 Google Inc. | |
4 # | |
5 # Use of this source code is governed by a BSD-style license that can be | |
6 # found in the LICENSE file. | |
7 | |
8 | |
9 import datetime | |
rmistry
2016/02/18 15:29:21
unused
borenet
2016/02/18 15:40:56
Done.
| |
10 import default_flavor | |
11 import os | |
12 import ssh_devices | |
rmistry
2016/02/18 15:29:21
unused
borenet
2016/02/18 15:40:56
Done.
| |
13 import subprocess | |
14 import time | |
15 | |
16 | |
17 """Utils for running coverage tests.""" | |
18 | |
19 | |
20 class CoverageFlavorUtils(default_flavor.DefaultFlavorUtils): | |
21 def compile(self, target): | |
22 """Build the given target.""" | |
23 cmd = [os.path.join(self._bot_info.skia_dir, 'tools', | |
24 'llvm_coverage_build'), | |
25 target] | |
26 self._bot_info.run(cmd) | |
27 | |
28 def step(self, cmd, **kwargs): | |
29 """Run the given step through coverage.""" | |
30 # Slice out the 'key' and 'properties' arguments to be reused. | |
31 key = [] | |
32 properties = [] | |
33 current = None | |
34 for i in xrange(0, len(cmd)): | |
35 if isinstance(cmd[i], basestring) and cmd[i] == '--key': | |
36 current = key | |
37 elif isinstance(cmd[i], basestring) and cmd[i] == '--properties': | |
38 current = properties | |
39 elif isinstance(cmd[i], basestring) and cmd[i].startswith('--'): | |
40 current = None | |
41 if current is not None: | |
42 current.append(cmd[i]) | |
43 | |
44 results_dir = self._bot_info.out_dir.join('coverage_results') | |
45 self.create_clean_host_dir(results_dir) | |
46 | |
47 # Run DM under coverage. | |
48 report_file_basename = '%s.cov' % self._bot_info.got_revision | |
49 report_file = os.path.join(results_dir, report_file_basename) | |
50 args = [ | |
51 'python', | |
52 os.path.join(self._bot_info.skia_dir, 'tools', 'llvm_coverage_run.py'), | |
53 ] + cmd + ['--outResultsFile', report_file] | |
54 self._bot_info.run(args, **kwargs) | |
55 | |
56 # Generate nanobench-style JSON output from the coverage report. | |
57 git_timestamp = subprocess.check_output(['git', 'log', '-n1', | |
58 self._bot_info.got_revision, '--format=%%ci']).rstrip() | |
59 nanobench_json = results_dir.join('nanobench_%s_%s.json' % ( | |
60 self._bot_info.got_revision, git_timestamp)) | |
61 line_by_line_basename = ('coverage_by_line_%s_%s.json' % ( | |
62 self._bot_info.got_revision, git_timestamp)) | |
63 line_by_line = results_dir.join(line_by_line_basename) | |
64 args = [ | |
65 'python', | |
66 os.path.join(self._bot_info.skia_dir, 'tools', | |
67 'parse_llvm_coverage.py'), | |
68 '--report', report_file, '--nanobench', nanobench_json, | |
69 '--linebyline', line_by_line] | |
70 args.extend(key) | |
71 args.extend(properties) | |
72 self._bot_info.run(args) | |
73 | |
74 # Upload raw coverage data. | |
75 now = time.utcnow() | |
76 gs_json_path = '/'.join(( | |
77 str(now.year).zfill(4), str(now.month).zfill(2), | |
78 str(now.day).zfill(2), str(now.hour).zfill(2), | |
79 self._bot_info.name, | |
80 str(self._bot_info.build_number))) | |
81 if self._bot_info.is_trybot: | |
82 gs_json_path = '/'.join(('trybot', gs_json_path, | |
83 str(self._bot_info.issue))) | |
84 | |
85 self._bot_info.gsutil_upload( | |
86 'upload raw coverage data', | |
87 source=report_file, | |
88 bucket='skia-infra', | |
89 dest='/'.join(('coverage-raw-v1', gs_json_path, report_file_basename))) | |
90 | |
91 # Upload nanobench JSON data. | |
92 gsutil_path = self._bot_info.m.path['depot_tools'].join( | |
93 'third_party', 'gsutil', 'gsutil') | |
94 upload_args = [self._bot_info.name, | |
95 self._bot_info.m.properties['buildnumber'], | |
96 results_dir, | |
97 self._bot_info.got_revision, gsutil_path] | |
98 if self._bot_info.is_trybot: | |
99 upload_args.append(self._bot_info.m.properties['issue']) | |
100 self._bot_info.run( | |
101 self._bot_info.m.python, | |
102 'upload nanobench coverage results', | |
103 script=self._bot_info.resource('upload_bench_results.py'), | |
104 args=upload_args, | |
105 cwd=self._bot_info.m.path['checkout'], | |
106 abort_on_failure=False, | |
107 infra_step=True) | |
108 | |
109 # Upload line-by-line coverage data. | |
110 self._bot_info.gsutil_upload( | |
111 'upload line-by-line coverage data', | |
112 source=line_by_line, | |
113 bucket='skia-infra', | |
114 dest='/'.join(('coverage-json-v1', gs_json_path, | |
115 line_by_line_basename))) | |
116 | |
OLD | NEW |