summaryrefslogtreecommitdiffstats
path: root/meta/lib
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-12-16 14:31:27 +0000
commiteee5b0d104e6b36277a79afc9b02fdbffecc6aea (patch)
tree7df2e29a801937f660b1216ab67e6fc9c06740d8 /meta/lib
parentb3b337adb388d3261a48f4e2e82454013c56ccb8 (diff)
downloadpoky-eee5b0d104e6b36277a79afc9b02fdbffecc6aea.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) (From OE-Core rev: 045511425577ccbe89d8eb91e2a87e385390cabf) Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-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 a7b7463388..7e0b61b587 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
@@ -104,8 +105,9 @@ class OETestResult(_TestResult):
104 self.successes.append((test, None)) 105 self.successes.append((test, None))
105 super(OETestResult, self).addSuccess(test) 106 super(OETestResult, self).addSuccess(test)
106 107
107 def logDetails(self): 108 def logDetails(self, json_file_dir=None, configuration=None, result_id=None):
108 self.tc.logger.info("RESULTS:") 109 self.tc.logger.info("RESULTS:")
110 result = {}
109 for case_name in self.tc._registry['cases']: 111 for case_name in self.tc._registry['cases']:
110 case = self.tc._registry['cases'][case_name] 112 case = self.tc._registry['cases'][case_name]
111 113
@@ -118,6 +120,11 @@ class OETestResult(_TestResult):
118 oeid = d.oeid 120 oeid = d.oeid
119 121
120 self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), oeid, status)) 122 self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), oeid, status))
123 result[case.id()] = {'status': status, 'log': log}
124
125 if json_file_dir:
126 tresultjsonhelper = OETestResultJSONHelper()
127 tresultjsonhelper.dump_testresult_file(json_file_dir, configuration, result_id, result)
121 128
122class OEListTestsResult(object): 129class OEListTestsResult(object):
123 def wasSuccessful(self): 130 def wasSuccessful(self):
@@ -230,3 +237,29 @@ class OETestRunner(_TestRunner):
230 self._list_tests_module(suite) 237 self._list_tests_module(suite)
231 238
232 return OEListTestsResult() 239 return OEListTestsResult()
240
241class OETestResultJSONHelper(object):
242
243 testresult_filename = 'testresults.json'
244
245 def _get_existing_testresults_if_available(self, write_dir):
246 testresults = {}
247 file = os.path.join(write_dir, self.testresult_filename)
248 if os.path.exists(file):
249 with open(file, "r") as f:
250 testresults = json.load(f)
251 return testresults
252
253 def _write_file(self, write_dir, file_name, file_content):
254 file_path = os.path.join(write_dir, file_name)
255 with open(file_path, 'w') as the_file:
256 the_file.write(file_content)
257
258 def dump_testresult_file(self, write_dir, configuration, result_id, test_result):
259 bb.utils.mkdirhier(write_dir)
260 lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
261 test_results = self._get_existing_testresults_if_available(write_dir)
262 test_results[result_id] = {'configuration': configuration, 'result': test_result}
263 json_testresults = json.dumps(test_results, sort_keys=True, indent=4)
264 self._write_file(write_dir, self.testresult_filename, json_testresults)
265 bb.utils.unlockfile(lf)