diff options
author | Stefan Kral <sk@typedivision.de> | 2020-03-11 17:37:30 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-03-12 22:49:28 +0000 |
commit | b10131ea746efe6b7056dc670ac9839c17cba578 (patch) | |
tree | 40716e3d81ef7e02eee7feddb669380891806342 | |
parent | 4719298e34b7098465fd87355ed6d899583654d0 (diff) | |
download | poky-b10131ea746efe6b7056dc670ac9839c17cba578.tar.gz |
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>
-rw-r--r-- | meta/lib/oeqa/core/context.py | 30 | ||||
-rw-r--r-- | meta/lib/oeqa/core/runner.py | 13 |
2 files changed, 39 insertions, 4 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index 16320af115..b9a28ce319 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py | |||
@@ -116,6 +116,9 @@ class OETestContextExecutor(object): | |||
116 | default=self.default_output_log, | 116 | default=self.default_output_log, |
117 | help="results output log, default: %s" % self.default_output_log) | 117 | help="results output log, default: %s" % self.default_output_log) |
118 | 118 | ||
119 | self.parser.add_argument('--json-result-dir', action='store', | ||
120 | help="json result output dir, create testresults.json here if set") | ||
121 | |||
119 | group = self.parser.add_mutually_exclusive_group() | 122 | group = self.parser.add_mutually_exclusive_group() |
120 | group.add_argument('--run-tests', action='store', nargs='+', | 123 | group.add_argument('--run-tests', action='store', nargs='+', |
121 | default=self.default_tests, | 124 | default=self.default_tests, |
@@ -178,6 +181,22 @@ class OETestContextExecutor(object): | |||
178 | 181 | ||
179 | self.module_paths = args.CASES_PATHS | 182 | self.module_paths = args.CASES_PATHS |
180 | 183 | ||
184 | def _get_json_result_dir(self, args): | ||
185 | return args.json_result_dir | ||
186 | |||
187 | def _get_configuration(self): | ||
188 | td = self.tc_kwargs['init']['td'] | ||
189 | configuration = {'TEST_TYPE': self.name, | ||
190 | 'MACHINE': td.get("MACHINE"), | ||
191 | 'DISTRO': td.get("DISTRO"), | ||
192 | 'IMAGE_BASENAME': td.get("IMAGE_BASENAME"), | ||
193 | 'DATETIME': td.get("DATETIME")} | ||
194 | return configuration | ||
195 | |||
196 | def _get_result_id(self, configuration): | ||
197 | return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], | ||
198 | configuration['MACHINE'], configuration['DATETIME']) | ||
199 | |||
181 | def _pre_run(self): | 200 | def _pre_run(self): |
182 | pass | 201 | pass |
183 | 202 | ||
@@ -196,7 +215,16 @@ class OETestContextExecutor(object): | |||
196 | else: | 215 | else: |
197 | self._pre_run() | 216 | self._pre_run() |
198 | rc = self.tc.runTests(**self.tc_kwargs['run']) | 217 | rc = self.tc.runTests(**self.tc_kwargs['run']) |
199 | rc.logDetails() | 218 | |
219 | json_result_dir = self._get_json_result_dir(args) | ||
220 | if json_result_dir: | ||
221 | configuration = self._get_configuration() | ||
222 | rc.logDetails(json_result_dir, | ||
223 | configuration, | ||
224 | self._get_result_id(configuration)) | ||
225 | else: | ||
226 | rc.logDetails() | ||
227 | |||
200 | rc.logSummary(self.name) | 228 | rc.logSummary(self.name) |
201 | 229 | ||
202 | output_link = os.path.join(os.path.dirname(args.output_log), | 230 | output_link = os.path.join(os.path.dirname(args.output_log), |
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py index f656e1a9c5..1284295c34 100644 --- a/meta/lib/oeqa/core/runner.py +++ b/meta/lib/oeqa/core/runner.py | |||
@@ -319,10 +319,17 @@ class OETestResultJSONHelper(object): | |||
319 | the_file.write(file_content) | 319 | the_file.write(file_content) |
320 | 320 | ||
321 | def dump_testresult_file(self, write_dir, configuration, result_id, test_result): | 321 | def dump_testresult_file(self, write_dir, configuration, result_id, test_result): |
322 | bb.utils.mkdirhier(write_dir) | 322 | try: |
323 | lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) | 323 | import bb |
324 | has_bb = True | ||
325 | bb.utils.mkdirhier(write_dir) | ||
326 | lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock')) | ||
327 | except ImportError: | ||
328 | has_bb = False | ||
329 | os.makedirs(write_dir, exist_ok=True) | ||
324 | test_results = self._get_existing_testresults_if_available(write_dir) | 330 | test_results = self._get_existing_testresults_if_available(write_dir) |
325 | test_results[result_id] = {'configuration': configuration, 'result': test_result} | 331 | test_results[result_id] = {'configuration': configuration, 'result': test_result} |
326 | json_testresults = json.dumps(test_results, sort_keys=True, indent=4) | 332 | json_testresults = json.dumps(test_results, sort_keys=True, indent=4) |
327 | self._write_file(write_dir, self.testresult_filename, json_testresults) | 333 | self._write_file(write_dir, self.testresult_filename, json_testresults) |
328 | bb.utils.unlockfile(lf) | 334 | if has_bb: |
335 | bb.utils.unlockfile(lf) | ||