[OE-core] [PATCH] oeqa: enable testresults.json for testexport

Stefan Kral sk at typedivision.de
Wed Mar 11 16:37:30 UTC 2020


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 .

Signed-off-by: Stefan Kral <sk at typedivision.de>
---
 meta/lib/oeqa/core/context.py | 30 +++++++++++++++++++++++++++++-
 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):
                 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),
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py
index f656e1a9c5..fc3872aa73 100644
--- a/meta/lib/oeqa/core/runner.py
+++ b/meta/lib/oeqa/core/runner.py
@@ -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
+            lf = bb.utils.lockfile(os.path.join(write_dir, 'jsontestresult.lock'))
+            bb.utils.mkdirhier(write_dir, exist_ok=True)
+        except ImportError:
+            has_bb = False
+            os.makedirs(write_dir)
         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)
-- 
2.17.2 (Apple Git-113)



More information about the Openembedded-core mailing list