mirror of
https://git.yoctoproject.org/poky
synced 2026-03-19 13:49:41 +01:00
oeqa: enable testresults.json for testexport
Add the option --json-result-dir to oeqa core context to enable testresults.json creation for test runs via testexport. Eg. oe-test runtime --json-result-dir . (From OE-Core rev: 9d8edf33d1f5d89b310923b0aa3cc967317c7c49) Signed-off-by: Stefan Kral <sk@typedivision.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
4719298e34
commit
b10131ea74
@@ -116,6 +116,9 @@ class OETestContextExecutor(object):
|
||||
default=self.default_output_log,
|
||||
help="results output log, default: %s" % self.default_output_log)
|
||||
|
||||
self.parser.add_argument('--json-result-dir', action='store',
|
||||
help="json result output dir, create testresults.json here if set")
|
||||
|
||||
group = self.parser.add_mutually_exclusive_group()
|
||||
group.add_argument('--run-tests', action='store', nargs='+',
|
||||
default=self.default_tests,
|
||||
@@ -178,6 +181,22 @@ class OETestContextExecutor(object):
|
||||
|
||||
self.module_paths = args.CASES_PATHS
|
||||
|
||||
def _get_json_result_dir(self, args):
|
||||
return args.json_result_dir
|
||||
|
||||
def _get_configuration(self):
|
||||
td = self.tc_kwargs['init']['td']
|
||||
configuration = {'TEST_TYPE': self.name,
|
||||
'MACHINE': td.get("MACHINE"),
|
||||
'DISTRO': td.get("DISTRO"),
|
||||
'IMAGE_BASENAME': td.get("IMAGE_BASENAME"),
|
||||
'DATETIME': td.get("DATETIME")}
|
||||
return configuration
|
||||
|
||||
def _get_result_id(self, configuration):
|
||||
return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'],
|
||||
configuration['MACHINE'], configuration['DATETIME'])
|
||||
|
||||
def _pre_run(self):
|
||||
pass
|
||||
|
||||
@@ -196,7 +215,16 @@ class OETestContextExecutor(object):
|
||||
else:
|
||||
self._pre_run()
|
||||
rc = self.tc.runTests(**self.tc_kwargs['run'])
|
||||
rc.logDetails()
|
||||
|
||||
json_result_dir = self._get_json_result_dir(args)
|
||||
if json_result_dir:
|
||||
configuration = self._get_configuration()
|
||||
rc.logDetails(json_result_dir,
|
||||
configuration,
|
||||
self._get_result_id(configuration))
|
||||
else:
|
||||
rc.logDetails()
|
||||
|
||||
rc.logSummary(self.name)
|
||||
|
||||
output_link = os.path.join(os.path.dirname(args.output_log),
|
||||
|
||||
@@ -319,10 +319,17 @@ class OETestResultJSONHelper(object):
|
||||
the_file.write(file_content)
|
||||
|
||||
def dump_testresult_file(self, write_dir, configuration, result_id, test_result):
|
||||
bb.utils.mkdirhier(write_dir)
|
||||
lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
|
||||
try:
|
||||
import bb
|
||||
has_bb = True
|
||||
bb.utils.mkdirhier(write_dir)
|
||||
lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
|
||||
except ImportError:
|
||||
has_bb = False
|
||||
os.makedirs(write_dir, exist_ok=True)
|
||||
test_results = self._get_existing_testresults_if_available(write_dir)
|
||||
test_results[result_id] = {'configuration': configuration, 'result': test_result}
|
||||
json_testresults = json.dumps(test_results, sort_keys=True, indent=4)
|
||||
self._write_file(write_dir, self.testresult_filename, json_testresults)
|
||||
bb.utils.unlockfile(lf)
|
||||
if has_bb:
|
||||
bb.utils.unlockfile(lf)
|
||||
|
||||
Reference in New Issue
Block a user