[oe-commits] [openembedded-core] 03/05: oeqa/core/case.py: Add OEPTestResultTestCase for ptestresult helpers

git at git.openembedded.org git at git.openembedded.org
Wed Sep 11 06:30:49 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 8cfc0222432907ccbf32435f0152662e27ec2c26
Author: Nathan Rossi <nathan at nathanrossi.com>
AuthorDate: Tue Sep 10 12:40:59 2019 +0000

    oeqa/core/case.py: Add OEPTestResultTestCase for ptestresult helpers
    
    Add the OEPTestResultTestCase class as a mix-in class to provide helper
    functions for interacting with ptestresults within the extraresults
    object generated by the test case.
    
    This class also provides default compression of log text and log files.
    
    Also add support to resulttool for decoding/decompressing log files
    embedded in the test results.
    
    Signed-off-by: Nathan Rossi <nathan at nathanrossi.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/core/case.py    | 49 +++++++++++++++++++++++++++++++++++++++++++
 scripts/lib/resulttool/log.py | 12 ++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/meta/lib/oeqa/core/case.py b/meta/lib/oeqa/core/case.py
index aca144e..180635a 100644
--- a/meta/lib/oeqa/core/case.py
+++ b/meta/lib/oeqa/core/case.py
@@ -4,6 +4,8 @@
 # SPDX-License-Identifier: MIT
 #
 
+import base64
+import zlib
 import unittest
 
 from oeqa.core.exception import OEQAMissingVariable
@@ -49,3 +51,50 @@ class OETestCase(unittest.TestCase):
         for d in self.decorators:
             d.tearDownDecorator()
         self.tearDownMethod()
+
+class OEPTestResultTestCase:
+    """
+    Mix-in class to provide functions to make interacting with extraresults for
+    the purposes of storing ptestresult data.
+    """
+    @staticmethod
+    def _compress_log(log):
+        logdata = log.encode("utf-8")
+        logdata = zlib.compress(logdata)
+        logdata = base64.b64encode(logdata).decode("utf-8")
+        return {"compressed" : logdata}
+
+    def ptest_rawlog(self, log):
+        if not hasattr(self, "extraresults"):
+            self.extraresults = {"ptestresult.sections" : {}}
+        self.extraresults["ptestresult.rawlogs"] = {"log" : self._compress_log(log)}
+
+    def ptest_section(self, section, duration = None, log = None, logfile = None, exitcode = None):
+        if not hasattr(self, "extraresults"):
+            self.extraresults = {"ptestresult.sections" : {}}
+
+        sections = self.extraresults.get("ptestresult.sections")
+        if section not in sections:
+            sections[section] = {}
+
+        if log is not None:
+            sections[section]["log"] = self._compress_log(log)
+        elif logfile is not None:
+            with open(logfile, "r") as f:
+                sections[section]["log"] = self._compress_log(f.read())
+
+        if duration is not None:
+            sections[section]["duration"] = duration
+        if exitcode is not None:
+            sections[section]["exitcode"] = exitcode
+
+    def ptest_result(self, section, test, result):
+        if not hasattr(self, "extraresults"):
+            self.extraresults = {"ptestresult.sections" : {}}
+
+        sections = self.extraresults.get("ptestresult.sections")
+        if section not in sections:
+            sections[section] = {}
+        resultname = "ptestresult.{}.{}".format(section, test)
+        self.extraresults[resultname] = {"status" : result}
+
diff --git a/scripts/lib/resulttool/log.py b/scripts/lib/resulttool/log.py
index 2352c76..9966377 100644
--- a/scripts/lib/resulttool/log.py
+++ b/scripts/lib/resulttool/log.py
@@ -5,6 +5,8 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 import os
+import base64
+import zlib
 import resulttool.resultutils as resultutils
 
 def show_ptest(result, ptest, logger):
@@ -25,6 +27,9 @@ def show_reproducible(result, reproducible, logger):
         print("reproducible '%s' not found" % reproducible)
         return 1
 
+def decode_compressed_log(logdata):
+    data = base64.b64decode(logdata.encode("utf-8"))
+    return zlib.decompress(data).decode("utf-8")
 
 def log(args, logger):
     results = resultutils.load_resultsdata(args.source)
@@ -39,6 +44,7 @@ def log(args, logger):
             if 'ptestresult.sections' in r:
                 for name, ptest in r['ptestresult.sections'].items():
                     if 'log' in ptest:
+                        logdata = ptest['log']
                         dest_dir = args.dump_ptest
                         if args.prepend_run:
                             dest_dir = os.path.join(dest_dir, run_name)
@@ -48,7 +54,11 @@ def log(args, logger):
                         dest = os.path.join(dest_dir, '%s.log' % name)
                         print(dest)
                         with open(dest, 'w') as f:
-                            f.write(ptest['log'])
+                            if isinstance(logdata, str):
+                                f.write(logdata)
+                            elif isinstance(logdata, dict):
+                                if "compressed" in logdata:
+                                    f.write(decode_compressed_log(logdata.get("compressed")))
 
         if args.raw_ptest:
             if 'ptestresult.rawlogs' in r:

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list