oeqa/core/runner: write testresult to json files
PATCH 1/4 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 testresult 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.
--- meta/lib/oeqa/core/runner.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
meta/lib/oeqa/core/runner.py +39 -1
@@ -6,6 +6,7 @@ import time import unittest import logging import re +import json from unittest import TextTestResult as _TestResult from unittest import TextTestRunner as _TestRunner
@@ -119,8 +120,9 @@ class OETestResult(_TestResult): self.successes.append((test, None)) super(OETestResult, self).addSuccess(test) - def logDetails(self): + def logDetails(self, json_file_dir=None, configuration=None, result_id=None): self.tc.logger.info("RESULTS:") + result = {} for case_name in self.tc._registry['cases']: case = self.tc._registry['cases'][case_name]
@@ -137,6 +139,11 @@ class OETestResult(_TestResult): t = " (" + "{0:.2f}".format(self.endtime[case.id()] - self.starttime[case.id()]) + "s)" self.tc.logger.info("RESULTS - %s - Testcase %s: %s%s" % (case.id(), oeid, status, t)) + result[case.id()] = {'status': status, 'log': log} + + if json_file_dir: + tresultjsonhelper = OETestResultJSONHelper() + tresultjsonhelper.dump_testresult_file(result_id, result, configuration, json_file_dir) class OEListTestsResult(object): def wasSuccessful(self):
@@ -249,3 +256,34 @@ class OETestRunner(_TestRunner): self._list_tests_module(suite) return OEListTestsResult() + +class OETestResultJSONHelper(object): + + testresult_filename = 'testresults.json' + + def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults + + def _create_json_testresults_string(self, result_id, test_result, configuration, write_dir): + testresults = self._get_testresults(write_dir) + testresult = {'configuration': configuration, + 'result': test_result} + testresults[result_id] = testresult + return json.dumps(testresults, sort_keys=True, indent=4) + + def _write_file(self, write_dir, file_name, file_content): + file_path = os.path.join(write_dir, file_name) + with open(file_path, 'w') as the_file: + the_file.write(file_content) + + def dump_testresult_file(self, result_id, test_result, configuration, write_dir): + bb.utils.mkdirhier(write_dir) + lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) + json_testresults = self._create_json_testresults_string(result_id, test_result, configuration, write_dir) + self._write_file(write_dir, self.testresult_filename, json_testresults) + bb.utils.unlockfile(lf)
Signature · 1 line
2.7.4
PATCH 2/4 oeqa/selftest/context: write testresult to json files
As part of the solution to replace Testopia to store testresult, OEQA selftest need to output testresult into json files, where these json testresult files will be stored into git repository by the future test-case-management tools.
To configure multiple instances of bitbake to write json testresult to a single testresult file, user will define the variable "OEQA_JSON_RESULT_COMMON_DIR" with the common directory for writing json testresult.
--- meta/lib/oeqa/selftest/context.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
meta/lib/oeqa/selftest/context.py +32 -3
@@ -99,8 +99,8 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return cases_paths def _process_args(self, logger, args): - args.output_log = '%s-results-%s.log' % (self.name, - time.strftime("%Y%m%d%H%M%S")) + args.test_start_time = time.strftime("%Y%m%d%H%M%S") + args.output_log = '%s-results-%s.log' % (self.name, args.test_start_time) args.test_data_file = None args.CASES_PATHS = None
@@ -204,6 +204,32 @@ class OESelftestTestContextExecutor(OETestContextExecutor): self.tc.logger.info("Running bitbake -e to test the configuration is valid/parsable") runCmd("bitbake -e") + def _get_json_result_dir(self, args): + json_result_dir = os.path.join(os.path.dirname(os.path.abspath(args.output_log)), + 'json_testresults-%s' % args.test_start_time, + 'oe-selftest') + if "OEQA_JSON_RESULT_COMMON_DIR" in self.tc.td: + json_result_dir = self.tc.td["OEQA_JSON_RESULT_COMMON_DIR"] + + return json_result_dir + + def _get_configuration(self, args): + import platform + from oeqa.utils.metadata import metadata_from_bb + + metadata = metadata_from_bb() + return {'TEST_TYPE': 'oeselftest', + 'BRANCH': metadata['layers']['meta']['branch'], + 'COMMIT': metadata['layers']['meta']['commit'], + 'START_TIME': args.test_start_time, + 'MACHINE': self.tc.td["MACHINE"], + 'HOST_DISTRO': platform.linux_distribution(), + 'HOST_NAME': metadata['hostname']} + + def _get_result_id(self, configuration): + distro = '_'.join(configuration['HOST_DISTRO']) + return '%s-%s-%s' % (configuration['TEST_TYPE'], distro, configuration['MACHINE']) + def _internal_run(self, logger, args): self.module_paths = self._get_cases_paths( self.tc_kwargs['init']['td']['BBPATH'].split(':'))
@@ -220,7 +246,10 @@ class OESelftestTestContextExecutor(OETestContextExecutor): else: self._pre_run() rc = self.tc.runTests(**self.tc_kwargs['run']) - rc.logDetails() + configuration = self._get_configuration(args) + rc.logDetails(self._get_json_result_dir(args), + configuration, + self._get_result_id(configuration)) rc.logSummary(self.name) return rc
Signature · 1 line
2.7.4
PATCH 3/4 testimage.bbclass: write testresult to json files
In reply to Yeoh Ee PengAs part of the solution to replace Testopia to store testresult, OEQA testimage need to output testresult into json files, where these json testresult files will be stored into git repository by the future test-case-management tools.
To configure multiple instances of bitbake to write json testresult to a single testresult file, user will define the variable "OEQA_JSON_RESULT_COMMON_DIR" with the common directory for writing json testresult.
--- meta/classes/testimage.bbclass | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
meta/classes/testimage.bbclass +32 -2
@@ -2,7 +2,7 @@ # # Released under the MIT license (see COPYING.MIT) - +inherit metadata_scm # testimage.bbclass enables testing of qemu images using python unittests. # Most of the tests are commands run on target image over ssh. # To use it add testimage to global inherit and call your target image with -c testimage
@@ -141,6 +141,33 @@ def testimage_sanity(d): bb.fatal('When TEST_TARGET is set to "simpleremote" ' 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.') +def _get_configuration(d, test_type, pid, machine): + import platform + bb_core_dir = d.getVar("BBFILE_PATTERN_core=") + return {'TEST_TYPE': test_type, + 'BRANCH': base_get_metadata_git_branch(bb_core_dir, None).strip(), + 'COMMIT': base_get_metadata_git_revision(bb_core_dir, None), + 'PROCESS_ID': pid, + 'MACHINE': machine, + 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), + 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), + 'HOST_DISTRO': platform.linux_distribution()} + +def _get_json_result_dir(d, configuration): + json_result_dir = os.path.join(d.getVar("WORKDIR"), + 'temp', + 'json_testresults-%s' % configuration['PROCESS_ID'], + configuration['TEST_TYPE'], + configuration['MACHINE'], + configuration['IMAGE_BASENAME']) + oeqa_json_result_common_dir = d.getVar("OEQA_JSON_RESULT_COMMON_DIR") + if oeqa_json_result_common_dir: + json_result_dir = oeqa_json_result_common_dir + return json_result_dir + +def _get_result_id(configuration): + return '%s-%s-%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['MACHINE']) + def testimage_main(d): import os import json
@@ -308,7 +335,10 @@ def testimage_main(d): # Show results (if we have them) if not results: bb.fatal('%s - FAILED - tests were interrupted during execution' % pn, forcelog=True) - results.logDetails() + configuration = _get_configuration(d, 'runtime', os.getpid(), machine) + results.logDetails(_get_json_result_dir(d, configuration), + configuration, + _get_result_id(configuration)) results.logSummary(pn) if not results.wasSuccessful(): bb.fatal('%s - FAILED - check the task log and the ssh log' % pn, forcelog=True)
Signature · 1 line
2.7.4
Re: [PATCH 3/4] testimage.bbclass: write testresult to json files
Quoted 29 lines · Yeoh Ee Peng
As part of the solution to replace Testopia to store testresult, OEQA testimage need to output testresult into json files, where these json testresult files will be stored into git repository by the future test-case-management tools.
To configure multiple instances of bitbake to write json testresult to a single testresult file, user will define the variable "
OEQA_JSON_RESULT_COMMON_DIR" with the common directory for writing json testresult.Signed-off-by Yeoh Ee Peng <[email protected]>--- meta/classes/testimage.bbclass | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)meta/classes/testimage.bbclass +1
-1@@ -2,7 +2,7 @@ # # Released under the MIT license (see COPYING.MIT) - +inherit metadata_scm # testimage.bbclass enables testing of qemu images using python unittests. # Most of the tests are commands run on target image over ssh. # To use it add testimage to global inherit and call your target image with -c testimage
meta/classes/testimage.bbclass def testimage_sanity(d): · line 149
Quoted 9 lines
meta/classes/testimage.bbclass +6
-0@@ -141,6 +141,33 @@ def testimage_sanity(d): bb.fatal('When TEST_TARGET is set to "simpleremote" ' 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.') +def _get_configuration(d, test_type, pid, machine): + import platform + bb_core_dir = d.getVar("BBFILE_PATTERN_core=") + return {'TEST_TYPE': test_type, + 'BRANCH': base_get_metadata_git_branch(bb_core_dir, None).strip(), + 'COMMIT': base_get_metadata_git_revision(bb_core_dir, None),
We need to record all the revisions/branches that are being used. Could we just inject the contents of metadata['layers'] directly into the json file here?
Quoted 6 lines
meta/classes/testimage.bbclass +6
-0+ 'PROCESS_ID': pid, + 'MACHINE': machine, + 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), + 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), + 'HOST_DISTRO': platform.linux_distribution()} +
meta/classes/testimage.bbclass def testimage_sanity(d): · line 165
Quoted 10 lines
meta/classes/testimage.bbclass +10
-0+def _get_json_result_dir(d, configuration): + json_result_dir = os.path.join(d.getVar("WORKDIR"), + 'temp', + 'json_testresults-%s' % configuration['PROCESS_ID'], + configuration['TEST_TYPE'], + configuration['MACHINE'], + configuration['IMAGE_BASENAME']) + oeqa_json_result_common_dir = d.getVar("OEQA_JSON_RESULT_COMMON_DIR") + if oeqa_json_result_common_dir: + json_result_dir = oeqa_json_result_common_dir
Do we need both codepaths here or can we just place things in OEQA_JSON_RESULT_COMMON_DIR unconditionally here?
(we could rename it to OEQA_JSON_RESULT_DIR?)
Cheers,
Richard
Re: [PATCH 3/4] testimage.bbclass: write testresult to json files
Richard,
Noted, let's us made the changes to record all the revisions/branches that are being used.
The reason to provide the default result_dir here was to prevent the case where no json testresult being write out when user does not provide the specific OEQA_JSON_RESULT_DIR, otherwise user might need to rerun test to get the json testresult. Probably, it will be better that bitbake will prompt user to provide result_dir variable next round if it was not avaiable to write testresult to a specify location (eg. common location to write all testresult). Please let me know your inputs.
meta/classes/testimage.bbclass def testimage_sanity(d): · line 165
Quoted 10 lines
meta/classes/testimage.bbclass +10
-0+def _get_json_result_dir(d, configuration): + json_result_dir = os.path.join(d.getVar("WORKDIR"), + 'temp', + 'json_testresults-%s' % configuration['PROCESS_ID'], + configuration['TEST_TYPE'], + configuration['MACHINE'], + configuration['IMAGE_BASENAME']) + oeqa_json_result_common_dir = d.getVar("OEQA_JSON_RESULT_COMMON_DIR") + if oeqa_json_result_common_dir: + json_result_dir = oeqa_json_result_common_dir
Best regards,
Yeoh Ee Peng
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Monday, October 22, 2018 4:38 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH 3/4] testimage.bbclass: write testresult to json files
Quoted 33 lines · Yeoh Ee Peng
As part of the solution to replace Testopia to store testresult, OEQA testimage need to output testresult into json files, where these json testresult files will be stored into git repository by the future test-case-management tools.
To configure multiple instances of bitbake to write json testresult to a single testresult file, user will define the variable "
OEQA_JSON_RESULT_COMMON_DIR" with the common directory for writing json testresult.Signed-off-by Yeoh Ee Peng <[email protected]>--- meta/classes/testimage.bbclass | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)(quoted diff) +0
-0b/meta/classes/testimage.bbclass index 2642a72..112ba71 100644
meta/classes/testimage.bbclass +1
-1@@ -2,7 +2,7 @@ # # Released under the MIT license (see COPYING.MIT) - +inherit metadata_scm # testimage.bbclass enables testing of qemu images using python unittests. # Most of the tests are commands run on target image over ssh. # To use it add testimage to global inherit and call your targetimage with -c testimage @@ -141,6 +141,33 @@ def
testimage_sanity(d):
bb.fatal('WhenTEST_TARGETis set to "simpleremote" '
'TEST_TARGET_IPandTEST_SERVER_IPare needed too.')
meta/classes/testimage.bbclass def testimage_sanity(d):
Quoted 7 lines
meta/classes/testimage.bbclass +7
-0+def _get_configuration(d, test_type, pid, machine): + import platform + bb_core_dir = d.getVar("BBFILE_PATTERN_core=") + return {'TEST_TYPE': test_type, + 'BRANCH': base_get_metadata_git_branch(bb_core_dir, None).strip(), + 'COMMIT': base_get_metadata_git_revision(bb_core_dir, +None),
We need to record all the revisions/branches that are being used. Could we just inject the contents of metadata['layers'] directly into the json file here?
Quoted 6 lines
meta/classes/testimage.bbclass +6
-0+ 'PROCESS_ID': pid, + 'MACHINE': machine, + 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), + 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), + 'HOST_DISTRO': platform.linux_distribution()} +
meta/classes/testimage.bbclass def testimage_sanity(d): · line 165
Quoted 10 lines
meta/classes/testimage.bbclass +10
-0+def _get_json_result_dir(d, configuration): + json_result_dir = os.path.join(d.getVar("WORKDIR"), + 'temp', + 'json_testresults-%s' % configuration['PROCESS_ID'], + configuration['TEST_TYPE'], + configuration['MACHINE'], + configuration['IMAGE_BASENAME']) + oeqa_json_result_common_dir = d.getVar("OEQA_JSON_RESULT_COMMON_DIR") + if oeqa_json_result_common_dir: + json_result_dir = oeqa_json_result_common_dir
Do we need both codepaths here or can we just place things in OEQA_JSON_RESULT_COMMON_DIR unconditionally here?
(we could rename it to OEQA_JSON_RESULT_DIR?)
Cheers,
Richard
PATCH 4/4 testsdk.bbclass: write testresult to json files
In reply to Yeoh Ee PengAs part of the solution to replace Testopia to store testresult, OEQA sdk and sdkext need to output testresult into json files, where these json testresult files will be stored into git repository by the future test-case-management tools.
To configure multiple instances of bitbake to write json testresult to a single testresult file, user will define the variable "OEQA_JSON_RESULT_COMMON_DIR" with the common directory for writing json testresult.
--- meta/classes/testsdk.bbclass | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
meta/classes/testsdk.bbclass +36 -4
@@ -2,6 +2,7 @@ # # Released under the MIT license (see COPYING.MIT) +inherit metadata_scm # testsdk.bbclass enables testing for SDK and Extensible SDK # # To run SDK tests, run the commands:
@@ -14,6 +15,33 @@ # # where "<image-name>" is an image like core-image-sato. +def _get_configuration(d, test_type, pid): + import platform + bb_core_dir = d.getVar("BBFILE_PATTERN_core=") + return {'TEST_TYPE': test_type, + 'BRANCH': base_get_metadata_git_branch(bb_core_dir, None).strip(), + 'COMMIT': base_get_metadata_git_revision(bb_core_dir, None), + 'PROCESS_ID': pid, + 'SDK_MACHINE': d.getVar("SDKMACHINE"), + 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), + 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), + 'HOST_DISTRO': platform.linux_distribution()} + +def _get_json_result_dir(d, configuration): + json_result_dir = os.path.join(d.getVar("WORKDIR"), + 'temp', + 'json_testresults-%s' % configuration['PROCESS_ID'], + configuration['TEST_TYPE'], + configuration['SDK_MACHINE'], + configuration['IMAGE_BASENAME']) + oeqa_json_result_common_dir = d.getVar("OEQA_JSON_RESULT_COMMON_DIR") + if oeqa_json_result_common_dir: + json_result_dir = oeqa_json_result_common_dir + return json_result_dir + +def _get_result_id(configuration): + return '%s-%s-%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['SDK_MACHINE']) + def testsdk_main(d): import os import subprocess
@@ -80,8 +108,10 @@ def testsdk_main(d): component = "%s %s" % (pn, OESDKTestContextExecutor.name) context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) - - result.logDetails() + configuration = _get_configuration(d, 'sdk', os.getpid()) + result.logDetails(_get_json_result_dir(d, configuration), + configuration, + _get_result_id(configuration)) result.logSummary(component, context_msg) if not result.wasSuccessful():
@@ -184,8 +214,10 @@ def testsdkext_main(d): component = "%s %s" % (pn, OESDKExtTestContextExecutor.name) context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) - - result.logDetails() + configuration = _get_configuration(d, 'sdkext', os.getpid()) + result.logDetails(_get_json_result_dir(d, configuration), + configuration, + _get_result_id(configuration)) result.logSummary(component, context_msg) if not result.wasSuccessful():
Signature · 1 line
2.7.4
Hi Ee Peng,
Thanks, this is looking good, there is still one small tweak needed below.
Quoted 57 lines · Yeoh Ee Peng
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. Theresult_idwould 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 testresult for a givenresult_id. The json testresult file contains the configuration (eg. COMMIT, BRANCH, MACHINE, IMAGE), result (eg. PASSED, FAILED, ERROR), test log, andresult_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.
Signed-off-by Yeoh Ee Peng <[email protected]>--- meta/lib/oeqa/core/runner.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)meta/lib/oeqa/core/runner.py +21
-0@@ -249,3 +256,34 @@ class OETestRunner(_TestRunner): self._list_tests_module(suite) return OEListTestsResult() + +class OETestResultJSONHelper(object): + + testresult_filename = 'testresults.json' + + def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults + + def _create_json_testresults_string(self, result_id, test_result, configuration, write_dir): + testresults = self._get_testresults(write_dir) + testresult = {'configuration': configuration, + 'result': test_result} + testresults[result_id] = testresult + return json.dumps(testresults, sort_keys=True, indent=4) + + def _write_file(self, write_dir, file_name, file_content):
meta/lib/oeqa/core/runner.py class OETestRunner(_TestRunner): · line 289
Quoted 10 lines
meta/lib/oeqa/core/runner.py +10
-0+ file_path = os.path.join(write_dir, file_name) + with open(file_path, 'w') as the_file: + the_file.write(file_content) + + def dump_testresult_file(self, result_id, test_result, configuration, write_dir): + bb.utils.mkdirhier(write_dir) + lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) + json_testresults = self._create_json_testresults_string(result_id, test_result, configuration, write_dir) + self._write_file(write_dir, self.testresult_filename, json_testresults) + bb.utils.unlockfile(lf)
Before we write out the file we need to load in any existing data so we effectively append to the data. I think if we do that this patch should be ready to merge.
I did also wonder if we need a common configuration function rather than duplicating the code into each of the test classes.
Cheers,
Richard
Hi Richard
Current codes does load existing testresult json file if it exist, then it will write the new testresult into it based on the result_id.
meta/lib/oeqa/core/runner.py class OETestRunner(_TestRunner): · line 270
Quoted 7 lines
meta/lib/oeqa/core/runner.py +7
-0+ def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults
I did have the same thinking on if we can have a common function to manage configuration and result_id or let individual test classes to manage it, in the end, the thinking was configuration/result_id were really responsibility of each test classes, where the json helper class inside runner shall not have the knowledge or know-how on configuration/result_id. Thus the decision in the end was to make json helper class responsibility as simple as to consume the configuration, results, result_id information provided by the test classes. Hope this explain the reason behind current design.
Thank you very much for your attention & knowledge sharing!
Thanks,
Yeoh Ee Peng
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Monday, October 22, 2018 4:32 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH 1/4] oeqa/core/runner: write testresult to json files
Hi Ee Peng,
Thanks, this is looking good, there is still one small tweak needed below.
Quoted 58 lines · Yeoh Ee Peng
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. Theresult_idwould 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 testresult for a givenresult_id. The json testresult file contains the configuration (eg. COMMIT, BRANCH, MACHINE, IMAGE), result (eg. PASSED, FAILED, ERROR), test log, andresult_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.
Signed-off-by Yeoh Ee Peng <[email protected]>--- meta/lib/oeqa/core/runner.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/meta/lib/oeqa/core/runner.pyindex f1dd080..82463cf 100644meta/lib/oeqa/core/runner.py +21
-0@@ -249,3 +256,34 @@ class OETestRunner(_TestRunner): self._list_tests_module(suite) return OEListTestsResult() + +class OETestResultJSONHelper(object): + + testresult_filename = 'testresults.json' + + def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults + + def _create_json_testresults_string(self, result_id, test_result, configuration, write_dir): + testresults = self._get_testresults(write_dir) + testresult = {'configuration': configuration, + 'result': test_result} + testresults[result_id] = testresult + return json.dumps(testresults, sort_keys=True, indent=4) + + def _write_file(self, write_dir, file_name, file_content):
meta/lib/oeqa/core/runner.py class OETestRunner(_TestRunner): · line 289
Quoted 10 lines
meta/lib/oeqa/core/runner.py +10
-0+ file_path = os.path.join(write_dir, file_name) + with open(file_path, 'w') as the_file: + the_file.write(file_content) + + def dump_testresult_file(self, result_id, test_result, configuration, write_dir): + bb.utils.mkdirhier(write_dir) + lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) + json_testresults = self._create_json_testresults_string(result_id, test_result, configuration, write_dir) + self._write_file(write_dir, self.testresult_filename, json_testresults) + bb.utils.unlockfile(lf)
Before we write out the file we need to load in any existing data so we effectively append to the data. I think if we do that this patch should be ready to merge.
I did also wonder if we need a common configuration function rather than duplicating the code into each of the test classes.
Cheers,
Richard
Quoted 11 lines · Ee Peng
Hi Richard
Current codes does load existing testresult json file if it exist, then it will write the new testresult into it based on the
result_id.Quoted 7 lines
meta/lib/oeqa/core/runner.py +7
-0+ def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults
I managed to miss that function and call, sorry. That should be fine. I think we may want to inline some of these functions to make things clearer.
Quoted 11 lines
I did have the same thinking on if we can have a common function to manage configuration and
result_idor let individual test classes to manage it, in the end, the thinking was configuration/result_id were really responsibility of each test classes, where the json helper class inside runner shall not have the knowledge or know-how on configuration/result_id. Thus the decision in the end was to make json helper class responsibility as simple as to consume the configuration, results,result_idinformation provided by the test classes. Hope this explain the reason behind current design.Thank you very much for your attention & knowledge sharing!
You could just do what amounts to getVar("LOGDIR") + "/oeqa" and have that as the default test result location?
Cheers,
Richard
Hi Richard,
You are right, the current codes and functions does not express clearly what it does, especially on getting existing testresult, let me refactor this to make it clearer.
Yes, let me use getVar("LOGDIR") + "/oeqa" as default result_dir. Do you think we shall have OEQA_JSON_RESULT_DIR variable for user to define custom result_dir?
Thanks,
Yeoh Ee Peng
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Monday, October 22, 2018 5:34 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH 1/4] oeqa/core/runner: write testresult to json files
Quoted 11 lines · Ee Peng
Hi Richard
Current codes does load existing testresult json file if it exist, then it will write the new testresult into it based on the
result_id.Quoted 7 lines
meta/lib/oeqa/core/runner.py +7
-0+ def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults
I managed to miss that function and call, sorry. That should be fine. I think we may want to inline some of these functions to make things clearer.
Quoted 11 lines
I did have the same thinking on if we can have a common function to manage configuration and
result_idor let individual test classes to manage it, in the end, the thinking was configuration/result_id were really responsibility of each test classes, where the json helper class inside runner shall not have the knowledge or know-how on configuration/result_id. Thus the decision in the end was to make json helper class responsibility as simple as to consume the configuration, results,result_idinformation provided by the test classes. Hope this explain the reason behind current design.Thank you very much for your attention & knowledge sharing!
You could just do what amounts to getVar("LOGDIR") + "/oeqa" and have that as the default test result location?
Cheers,
Richard
Hi Richard,
I had refactor and incorporate the inputs your provided, submitted the patches for your review. Thank you very much for your attention and sharing!
http://lists.openembedded.org/pipermail/openembedded-core/2018-October/156945.html
http://lists.openembedded.org/pipermail/openembedded-core/2018-October/156946.html
http://lists.openembedded.org/pipermail/openembedded-core/2018-October/156947.html
http://lists.openembedded.org/pipermail/openembedded-core/2018-October/156948.html
Thanks,
Yeoh Ee Peng
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Monday, October 22, 2018 5:34 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH 1/4] oeqa/core/runner: write testresult to json files
Quoted 11 lines · Ee Peng
Hi Richard
Current codes does load existing testresult json file if it exist, then it will write the new testresult into it based on the
result_id.Quoted 7 lines
meta/lib/oeqa/core/runner.py +7
-0+ def _get_testresults(self, write_dir): + testresults = {} + file = os.path.join(write_dir, self.testresult_filename) + if os.path.exists(file): + with open(file, "r") as f: + testresults = json.load(f) + return testresults
I managed to miss that function and call, sorry. That should be fine. I think we may want to inline some of these functions to make things clearer.
Quoted 11 lines
I did have the same thinking on if we can have a common function to manage configuration and
result_idor let individual test classes to manage it, in the end, the thinking was configuration/result_id were really responsibility of each test classes, where the json helper class inside runner shall not have the knowledge or know-how on configuration/result_id. Thus the decision in the end was to make json helper class responsibility as simple as to consume the configuration, results,result_idinformation provided by the test classes. Hope this explain the reason behind current design.Thank you very much for your attention & knowledge sharing!
You could just do what amounts to getVar("LOGDIR") + "/oeqa" and have that as the default test result location?
Cheers,
Richard