diff options
author | Nathan Rossi <nathan@nathanrossi.com> | 2019-09-27 05:31:08 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-09-30 16:55:21 +0100 |
commit | ec1104fd7fc0311e918fa832a566d3c8aedc2f11 (patch) | |
tree | a87481ad426890a557e5946d7974c5c97cdb5bed | |
parent | 02a334c98fef6a8af9ee3dcd29815dbe6d145d3c (diff) | |
download | poky-ec1104fd7fc0311e918fa832a566d3c8aedc2f11.tar.gz |
oeqa/core/case.py: Encode binary data of log
Do not decode the log content into a string only to re-encode it as
binary data again. Some logs might un-intentionally contain bytes that
do not decode as utf-8, as such preserve the log file content as it was
on disk.
Handle the decoding on the resulttool side, but also handle the failure
to decode the data.
(From OE-Core rev: 20531dc0b8f76a6e37cc856f36cd94077b6aba50)
Signed-off-by: Nathan Rossi <nathan@nathanrossi.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/core/case.py | 4 | ||||
-rw-r--r-- | scripts/lib/resulttool/resultutils.py | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/meta/lib/oeqa/core/case.py b/meta/lib/oeqa/core/case.py index 180635ac6c..aae451fef2 100644 --- a/meta/lib/oeqa/core/case.py +++ b/meta/lib/oeqa/core/case.py | |||
@@ -59,7 +59,7 @@ class OEPTestResultTestCase: | |||
59 | """ | 59 | """ |
60 | @staticmethod | 60 | @staticmethod |
61 | def _compress_log(log): | 61 | def _compress_log(log): |
62 | logdata = log.encode("utf-8") | 62 | logdata = log.encode("utf-8") if isinstance(log, str) else log |
63 | logdata = zlib.compress(logdata) | 63 | logdata = zlib.compress(logdata) |
64 | logdata = base64.b64encode(logdata).decode("utf-8") | 64 | logdata = base64.b64encode(logdata).decode("utf-8") |
65 | return {"compressed" : logdata} | 65 | return {"compressed" : logdata} |
@@ -80,7 +80,7 @@ class OEPTestResultTestCase: | |||
80 | if log is not None: | 80 | if log is not None: |
81 | sections[section]["log"] = self._compress_log(log) | 81 | sections[section]["log"] = self._compress_log(log) |
82 | elif logfile is not None: | 82 | elif logfile is not None: |
83 | with open(logfile, "r") as f: | 83 | with open(logfile, "rb") as f: |
84 | sections[section]["log"] = self._compress_log(f.read()) | 84 | sections[section]["log"] = self._compress_log(f.read()) |
85 | 85 | ||
86 | if duration is not None: | 86 | if duration is not None: |
diff --git a/scripts/lib/resulttool/resultutils.py b/scripts/lib/resulttool/resultutils.py index 177fb25f93..7cb85a6aa9 100644 --- a/scripts/lib/resulttool/resultutils.py +++ b/scripts/lib/resulttool/resultutils.py | |||
@@ -126,7 +126,11 @@ def decode_log(logdata): | |||
126 | if "compressed" in logdata: | 126 | if "compressed" in logdata: |
127 | data = logdata.get("compressed") | 127 | data = logdata.get("compressed") |
128 | data = base64.b64decode(data.encode("utf-8")) | 128 | data = base64.b64decode(data.encode("utf-8")) |
129 | return zlib.decompress(data).decode("utf-8") | 129 | data = zlib.decompress(data) |
130 | try: | ||
131 | return data.decode("utf-8") | ||
132 | except UnicodeDecodeError: | ||
133 | return data | ||
130 | return None | 134 | return None |
131 | 135 | ||
132 | def ptestresult_get_log(results, section): | 136 | def ptestresult_get_log(results, section): |