diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-08-29 22:48:21 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-09-03 09:58:41 +0100 |
commit | e8c47a634328fff6a53919fd37755bd50c02f548 (patch) | |
tree | b30ea36f95881d85307553e5738ba5020f76cecb | |
parent | 44188933ce52544a31f0692393deea2a9acc56f7 (diff) | |
download | poky-e8c47a634328fff6a53919fd37755bd50c02f548.tar.gz |
oeqa.buildperf: enable json-formatted results
Automatically create a json.formatted file (results.json) in the results
directory that contains results from all tests.
(From OE-Core rev: 6df3263531a41805b2280bb999cb4a73f9f91eae)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/buildperf/base.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py index ed8ff4ae29..eed026681b 100644 --- a/meta/lib/oeqa/buildperf/base.py +++ b/meta/lib/oeqa/buildperf/base.py | |||
@@ -11,6 +11,7 @@ | |||
11 | # | 11 | # |
12 | """Build performance test base classes and functionality""" | 12 | """Build performance test base classes and functionality""" |
13 | import glob | 13 | import glob |
14 | import json | ||
14 | import logging | 15 | import logging |
15 | import os | 16 | import os |
16 | import re | 17 | import re |
@@ -80,6 +81,20 @@ def time_cmd(cmd, **kwargs): | |||
80 | return ret, timedata | 81 | return ret, timedata |
81 | 82 | ||
82 | 83 | ||
84 | class ResultsJsonEncoder(json.JSONEncoder): | ||
85 | """Extended encoder for build perf test results""" | ||
86 | unix_epoch = datetime.utcfromtimestamp(0) | ||
87 | |||
88 | def default(self, obj): | ||
89 | """Encoder for our types""" | ||
90 | if isinstance(obj, datetime): | ||
91 | # NOTE: we assume that all timestamps are in UTC time | ||
92 | return (obj - self.unix_epoch).total_seconds() | ||
93 | if isinstance(obj, timedelta): | ||
94 | return obj.total_seconds() | ||
95 | return json.JSONEncoder.default(self, obj) | ||
96 | |||
97 | |||
83 | class BuildPerfTestResult(unittest.TextTestResult): | 98 | class BuildPerfTestResult(unittest.TextTestResult): |
84 | """Runner class for executing the individual tests""" | 99 | """Runner class for executing the individual tests""" |
85 | # List of test cases to run | 100 | # List of test cases to run |
@@ -143,6 +158,7 @@ class BuildPerfTestResult(unittest.TextTestResult): | |||
143 | def stopTestRun(self): | 158 | def stopTestRun(self): |
144 | """Pre-run hook""" | 159 | """Pre-run hook""" |
145 | self.elapsed_time = datetime.utcnow() - self.start_time | 160 | self.elapsed_time = datetime.utcnow() - self.start_time |
161 | self.write_results_json() | ||
146 | 162 | ||
147 | def all_results(self): | 163 | def all_results(self): |
148 | result_map = {'SUCCESS': self.successes, | 164 | result_map = {'SUCCESS': self.successes, |
@@ -190,6 +206,30 @@ class BuildPerfTestResult(unittest.TextTestResult): | |||
190 | git_tag_rev)) | 206 | git_tag_rev)) |
191 | fobj.write(','.join(values) + '\n') | 207 | fobj.write(','.join(values) + '\n') |
192 | 208 | ||
209 | def write_results_json(self): | ||
210 | """Write test results into a json-formatted file""" | ||
211 | results = {'tester_host': self.hostname, | ||
212 | 'git_branch': self.git_branch, | ||
213 | 'git_commit': self.git_commit, | ||
214 | 'git_commit_count': self.git_commit_count, | ||
215 | 'product': self.product, | ||
216 | 'start_time': self.start_time, | ||
217 | 'elapsed_time': self.elapsed_time} | ||
218 | |||
219 | tests = {} | ||
220 | for status, (test, reason) in self.all_results(): | ||
221 | tests[test.name] = {'name': test.name, | ||
222 | 'description': test.shortDescription(), | ||
223 | 'status': status, | ||
224 | 'start_time': test.start_time, | ||
225 | 'elapsed_time': test.elapsed_time, | ||
226 | 'measurements': test.measurements} | ||
227 | results['tests'] = tests | ||
228 | |||
229 | with open(os.path.join(self.out_dir, 'results.json'), 'w') as fobj: | ||
230 | json.dump(results, fobj, indent=4, sort_keys=True, | ||
231 | cls=ResultsJsonEncoder) | ||
232 | |||
193 | 233 | ||
194 | def git_commit_results(self, repo_path, branch=None, tag=None): | 234 | def git_commit_results(self, repo_path, branch=None, tag=None): |
195 | """Commit results into a Git repository""" | 235 | """Commit results into a Git repository""" |