diff options
Diffstat (limited to 'meta/lib/oeqa/core/runner.py')
-rw-r--r-- | meta/lib/oeqa/core/runner.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py index f1dd08014c..d6d5afe0c7 100644 --- a/meta/lib/oeqa/core/runner.py +++ b/meta/lib/oeqa/core/runner.py | |||
@@ -6,6 +6,7 @@ import time | |||
6 | import unittest | 6 | import unittest |
7 | import logging | 7 | import logging |
8 | import re | 8 | import re |
9 | import json | ||
9 | 10 | ||
10 | from unittest import TextTestResult as _TestResult | 11 | from unittest import TextTestResult as _TestResult |
11 | from unittest import TextTestRunner as _TestRunner | 12 | from unittest import TextTestRunner as _TestRunner |
@@ -119,8 +120,9 @@ class OETestResult(_TestResult): | |||
119 | self.successes.append((test, None)) | 120 | self.successes.append((test, None)) |
120 | super(OETestResult, self).addSuccess(test) | 121 | super(OETestResult, self).addSuccess(test) |
121 | 122 | ||
122 | def logDetails(self): | 123 | def logDetails(self, json_file_dir=None, configuration=None, result_id=None): |
123 | self.tc.logger.info("RESULTS:") | 124 | self.tc.logger.info("RESULTS:") |
125 | result = {} | ||
124 | for case_name in self.tc._registry['cases']: | 126 | for case_name in self.tc._registry['cases']: |
125 | case = self.tc._registry['cases'][case_name] | 127 | case = self.tc._registry['cases'][case_name] |
126 | 128 | ||
@@ -137,6 +139,11 @@ class OETestResult(_TestResult): | |||
137 | t = " (" + "{0:.2f}".format(self.endtime[case.id()] - self.starttime[case.id()]) + "s)" | 139 | t = " (" + "{0:.2f}".format(self.endtime[case.id()] - self.starttime[case.id()]) + "s)" |
138 | 140 | ||
139 | self.tc.logger.info("RESULTS - %s - Testcase %s: %s%s" % (case.id(), oeid, status, t)) | 141 | self.tc.logger.info("RESULTS - %s - Testcase %s: %s%s" % (case.id(), oeid, status, t)) |
142 | result[case.id()] = {'status': status, 'log': log} | ||
143 | |||
144 | if json_file_dir: | ||
145 | tresultjsonhelper = OETestResultJSONHelper() | ||
146 | tresultjsonhelper.dump_testresult_file(json_file_dir, configuration, result_id, result) | ||
140 | 147 | ||
141 | class OEListTestsResult(object): | 148 | class OEListTestsResult(object): |
142 | def wasSuccessful(self): | 149 | def wasSuccessful(self): |
@@ -249,3 +256,29 @@ class OETestRunner(_TestRunner): | |||
249 | self._list_tests_module(suite) | 256 | self._list_tests_module(suite) |
250 | 257 | ||
251 | return OEListTestsResult() | 258 | return OEListTestsResult() |
259 | |||
260 | class OETestResultJSONHelper(object): | ||
261 | |||
262 | testresult_filename = 'testresults.json' | ||
263 | |||
264 | def _get_existing_testresults_if_available(self, write_dir): | ||
265 | testresults = {} | ||
266 | file = os.path.join(write_dir, self.testresult_filename) | ||
267 | if os.path.exists(file): | ||
268 | with open(file, "r") as f: | ||
269 | testresults = json.load(f) | ||
270 | return testresults | ||
271 | |||
272 | def _write_file(self, write_dir, file_name, file_content): | ||
273 | file_path = os.path.join(write_dir, file_name) | ||
274 | with open(file_path, 'w') as the_file: | ||
275 | the_file.write(file_content) | ||
276 | |||
277 | def dump_testresult_file(self, write_dir, configuration, result_id, test_result): | ||
278 | bb.utils.mkdirhier(write_dir) | ||
279 | lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) | ||
280 | test_results = self._get_existing_testresults_if_available(write_dir) | ||
281 | test_results[result_id] = {'configuration': configuration, 'result': test_result} | ||
282 | json_testresults = json.dumps(test_results, sort_keys=True, indent=4) | ||
283 | self._write_file(write_dir, self.testresult_filename, json_testresults) | ||
284 | bb.utils.unlockfile(lf) | ||