summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYeoh Ee Peng <ee.peng.yeoh@intel.com>2018-10-23 13:57:19 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-29 17:26:47 +0000
commit4ef72d556f706e301e5155f5f228c38431acafe6 (patch)
tree7ae43a10288c53b33867e79ba6dc9c07257f7d86
parent3ca7d58e6fad35ac9170b3f7fba1a70a2e114ada (diff)
downloadpoky-4ef72d556f706e301e5155f5f228c38431acafe6.tar.gz
oeqa/core/runner: write testresult to json files
As part of the solution to replace Testopia to store testresult, OEQA need to output testresult into single json file, where json testresult file will be stored in git repository by the future test-case-management tools. The json testresult file will store more than one set of results, where each set of results was uniquely identified by the result_id. The result_id would be like "runtime-qemux86-core-image-sato", where it was a runtime test with target machine equal to qemux86 and running on core-image-sato image. The json testresult file will only store the latest test content for a given result_id. The json testresult file contains the configuration (eg. COMMIT, BRANCH, MACHINE, IMAGE), result (eg. PASSED, FAILED, ERROR), test log, and result_id. Based on the destination json testresult file directory provided, it could have multiple instances of bitbake trying to write json testresult to a single testresult file, using locking a lockfile alongside the results file directory to prevent races. Also the library class inside this patch will be reused by the future test-case-management tools to write json testresult for manual test case executed. (From OE-Core rev: 00e03b5004f1eb6d59295544b3a8620504278f51) Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/core/runner.py35
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
6import unittest 6import unittest
7import logging 7import logging
8import re 8import re
9import json
9 10
10from unittest import TextTestResult as _TestResult 11from unittest import TextTestResult as _TestResult
11from unittest import TextTestRunner as _TestRunner 12from 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
141class OEListTestsResult(object): 148class 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
260class 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)