diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2017-05-26 15:37:36 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-02 13:36:13 +0100 |
commit | 44285351f5f9bc9d3c863d722f3fc00274a8ccba (patch) | |
tree | beadd7c883b05468b00f0d11feef98e837b7ca42 /meta/lib | |
parent | aeb8c9341b2250261592291269d0cfaf4498a917 (diff) | |
download | poky-44285351f5f9bc9d3c863d722f3fc00274a8ccba.tar.gz |
oeqa/core/threaded: Add OETestResultThreaded{,Internal} classes
The OETestResultThreadedInternal extends OETestResult to stores
results by Thread.
The OETestResultThreaded is a simple class that provides the
implementation of interfaces needed by outside like wasSuccesful,
stop, logSummary, logDetails.
[YOCTO #11450]
(From OE-Core rev: 8e71844fc4dd3fcc8a19f9d4c25aafb09c5525fe)
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/core/threaded.py | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/meta/lib/oeqa/core/threaded.py b/meta/lib/oeqa/core/threaded.py index 73b7f2fa64..f216685f46 100644 --- a/meta/lib/oeqa/core/threaded.py +++ b/meta/lib/oeqa/core/threaded.py | |||
@@ -7,7 +7,7 @@ import multiprocessing | |||
7 | from unittest.suite import TestSuite | 7 | from unittest.suite import TestSuite |
8 | 8 | ||
9 | from oeqa.core.loader import OETestLoader | 9 | from oeqa.core.loader import OETestLoader |
10 | from oeqa.core.runner import OEStreamLogger | 10 | from oeqa.core.runner import OEStreamLogger, OETestResult |
11 | 11 | ||
12 | class OETestLoaderThreaded(OETestLoader): | 12 | class OETestLoaderThreaded(OETestLoader): |
13 | def __init__(self, tc, module_paths, modules, tests, modules_required, | 13 | def __init__(self, tc, module_paths, modules, tests, modules_required, |
@@ -114,3 +114,74 @@ class OEStreamLoggerThreaded(OEStreamLogger): | |||
114 | for line in self.buffers[tid].split('\n'): | 114 | for line in self.buffers[tid].split('\n'): |
115 | self.logger.info(line) | 115 | self.logger.info(line) |
116 | self._lock.release() | 116 | self._lock.release() |
117 | |||
118 | class OETestResultThreadedInternal(OETestResult): | ||
119 | def _tc_map_results(self): | ||
120 | tid = threading.get_ident() | ||
121 | |||
122 | # PyUnit generates a result for every test module run, test | ||
123 | # if the thread already has an entry to avoid lose the previous | ||
124 | # test module results. | ||
125 | if not tid in self.tc._results: | ||
126 | self.tc._results[tid] = {} | ||
127 | self.tc._results[tid]['failures'] = self.failures | ||
128 | self.tc._results[tid]['errors'] = self.errors | ||
129 | self.tc._results[tid]['skipped'] = self.skipped | ||
130 | self.tc._results[tid]['expectedFailures'] = self.expectedFailures | ||
131 | |||
132 | class OETestResultThreaded(object): | ||
133 | _results = {} | ||
134 | _lock = threading.Lock() | ||
135 | |||
136 | def __init__(self, tc): | ||
137 | self.tc = tc | ||
138 | |||
139 | def _fill_tc_results(self): | ||
140 | tids = list(self.tc._results.keys()) | ||
141 | fields = ['failures', 'errors', 'skipped', 'expectedFailures'] | ||
142 | |||
143 | for tid in tids: | ||
144 | result = self.tc._results[tid] | ||
145 | for field in fields: | ||
146 | if not field in self.tc._results: | ||
147 | self.tc._results[field] = [] | ||
148 | self.tc._results[field].extend(result[field]) | ||
149 | |||
150 | def addResult(self, result, run_start_time, run_end_time): | ||
151 | tid = threading.get_ident() | ||
152 | |||
153 | self._lock.acquire() | ||
154 | self._results[tid] = {} | ||
155 | self._results[tid]['result'] = result | ||
156 | self._results[tid]['run_start_time'] = run_start_time | ||
157 | self._results[tid]['run_end_time'] = run_end_time | ||
158 | self._results[tid]['result'] = result | ||
159 | self._lock.release() | ||
160 | |||
161 | def wasSuccessful(self): | ||
162 | wasSuccessful = True | ||
163 | for tid in self._results.keys(): | ||
164 | wasSuccessful = wasSuccessful and \ | ||
165 | self._results[tid]['result'].wasSuccessful() | ||
166 | return wasSuccessful | ||
167 | |||
168 | def stop(self): | ||
169 | for tid in self._results.keys(): | ||
170 | self._results[tid]['result'].stop() | ||
171 | |||
172 | def logSummary(self, component, context_msg=''): | ||
173 | elapsed_time = (self.tc._run_end_time - self.tc._run_start_time) | ||
174 | |||
175 | self.tc.logger.info("SUMMARY:") | ||
176 | self.tc.logger.info("%s (%s) - Ran %d tests in %.3fs" % (component, | ||
177 | context_msg, len(self.tc._registry['cases']), elapsed_time)) | ||
178 | if self.wasSuccessful(): | ||
179 | msg = "%s - OK - All required tests passed" % component | ||
180 | else: | ||
181 | msg = "%s - FAIL - Required tests failed" % component | ||
182 | self.tc.logger.info(msg) | ||
183 | |||
184 | def logDetails(self): | ||
185 | tid = list(self._results)[0] | ||
186 | result = self._results[tid]['result'] | ||
187 | result.logDetails() | ||