diff options
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/core/case.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/case.py b/meta/lib/oeqa/core/case.py index aca144e9dc..180635ac6c 100644 --- a/meta/lib/oeqa/core/case.py +++ b/meta/lib/oeqa/core/case.py | |||
@@ -4,6 +4,8 @@ | |||
4 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
5 | # | 5 | # |
6 | 6 | ||
7 | import base64 | ||
8 | import zlib | ||
7 | import unittest | 9 | import unittest |
8 | 10 | ||
9 | from oeqa.core.exception import OEQAMissingVariable | 11 | from oeqa.core.exception import OEQAMissingVariable |
@@ -49,3 +51,50 @@ class OETestCase(unittest.TestCase): | |||
49 | for d in self.decorators: | 51 | for d in self.decorators: |
50 | d.tearDownDecorator() | 52 | d.tearDownDecorator() |
51 | self.tearDownMethod() | 53 | self.tearDownMethod() |
54 | |||
55 | class OEPTestResultTestCase: | ||
56 | """ | ||
57 | Mix-in class to provide functions to make interacting with extraresults for | ||
58 | the purposes of storing ptestresult data. | ||
59 | """ | ||
60 | @staticmethod | ||
61 | def _compress_log(log): | ||
62 | logdata = log.encode("utf-8") | ||
63 | logdata = zlib.compress(logdata) | ||
64 | logdata = base64.b64encode(logdata).decode("utf-8") | ||
65 | return {"compressed" : logdata} | ||
66 | |||
67 | def ptest_rawlog(self, log): | ||
68 | if not hasattr(self, "extraresults"): | ||
69 | self.extraresults = {"ptestresult.sections" : {}} | ||
70 | self.extraresults["ptestresult.rawlogs"] = {"log" : self._compress_log(log)} | ||
71 | |||
72 | def ptest_section(self, section, duration = None, log = None, logfile = None, exitcode = None): | ||
73 | if not hasattr(self, "extraresults"): | ||
74 | self.extraresults = {"ptestresult.sections" : {}} | ||
75 | |||
76 | sections = self.extraresults.get("ptestresult.sections") | ||
77 | if section not in sections: | ||
78 | sections[section] = {} | ||
79 | |||
80 | if log is not None: | ||
81 | sections[section]["log"] = self._compress_log(log) | ||
82 | elif logfile is not None: | ||
83 | with open(logfile, "r") as f: | ||
84 | sections[section]["log"] = self._compress_log(f.read()) | ||
85 | |||
86 | if duration is not None: | ||
87 | sections[section]["duration"] = duration | ||
88 | if exitcode is not None: | ||
89 | sections[section]["exitcode"] = exitcode | ||
90 | |||
91 | def ptest_result(self, section, test, result): | ||
92 | if not hasattr(self, "extraresults"): | ||
93 | self.extraresults = {"ptestresult.sections" : {}} | ||
94 | |||
95 | sections = self.extraresults.get("ptestresult.sections") | ||
96 | if section not in sections: | ||
97 | sections[section] = {} | ||
98 | resultname = "ptestresult.{}.{}".format(section, test) | ||
99 | self.extraresults[resultname] = {"status" : result} | ||
100 | |||