summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oeqa/buildperf/base.py40
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"""
13import glob 13import glob
14import json
14import logging 15import logging
15import os 16import os
16import re 17import re
@@ -80,6 +81,20 @@ def time_cmd(cmd, **kwargs):
80 return ret, timedata 81 return ret, timedata
81 82
82 83
84class 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
83class BuildPerfTestResult(unittest.TextTestResult): 98class 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"""