diff options
| author | Aníbal Limón <anibal.limon@linux.intel.com> | 2017-05-26 15:37:34 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-02 13:36:13 +0100 |
| commit | ce422c7008aa394755c45a466c1a165dbbc1d356 (patch) | |
| tree | fa810791bd157a7b853a5668f1503499fa2e699b | |
| parent | c118f80f17a93a425b256d64cd7c1d5fcb5fc127 (diff) | |
| download | poky-ce422c7008aa394755c45a466c1a165dbbc1d356.tar.gz | |
oeqa/core/threaded: Add OEStreamLoggerThreaded class
The OEStreamLoggerThreaded overrides OEStreamLogger to redirect
the PyUnit output to a logger.
Instead of log every line when comes the OEStreamLoggerThreaded
will buffer the PyUnit output and write everything at end of every
suite execution to don't have mixed suite outputs.
[YOCTO #11450]
(From OE-Core rev: 87d3e5b70c52e5c7439afe4af5aa002522043e81)
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oeqa/core/threaded.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/threaded.py b/meta/lib/oeqa/core/threaded.py index e6f214088c..73b7f2fa64 100644 --- a/meta/lib/oeqa/core/threaded.py +++ b/meta/lib/oeqa/core/threaded.py | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | 1 | # Copyright (C) 2017 Intel Corporation |
| 2 | # Released under the MIT license (see COPYING.MIT) | 2 | # Released under the MIT license (see COPYING.MIT) |
| 3 | 3 | ||
| 4 | import threading | ||
| 4 | import multiprocessing | 5 | import multiprocessing |
| 5 | 6 | ||
| 6 | from unittest.suite import TestSuite | 7 | from unittest.suite import TestSuite |
| 8 | |||
| 7 | from oeqa.core.loader import OETestLoader | 9 | from oeqa.core.loader import OETestLoader |
| 10 | from oeqa.core.runner import OEStreamLogger | ||
| 8 | 11 | ||
| 9 | class OETestLoaderThreaded(OETestLoader): | 12 | class OETestLoaderThreaded(OETestLoader): |
| 10 | def __init__(self, tc, module_paths, modules, tests, modules_required, | 13 | def __init__(self, tc, module_paths, modules, tests, modules_required, |
| @@ -89,3 +92,25 @@ class OETestLoaderThreaded(OETestLoader): | |||
| 89 | 92 | ||
| 90 | return suites | 93 | return suites |
| 91 | 94 | ||
| 95 | class OEStreamLoggerThreaded(OEStreamLogger): | ||
| 96 | _lock = threading.Lock() | ||
| 97 | buffers = {} | ||
| 98 | |||
| 99 | def write(self, msg): | ||
| 100 | tid = threading.get_ident() | ||
| 101 | |||
| 102 | if not tid in self.buffers: | ||
| 103 | self.buffers[tid] = "" | ||
| 104 | |||
| 105 | if msg: | ||
| 106 | self.buffers[tid] += msg | ||
| 107 | |||
| 108 | def finish(self): | ||
| 109 | tid = threading.get_ident() | ||
| 110 | |||
| 111 | self._lock.acquire() | ||
| 112 | self.logger.info('THREAD: %d' % tid) | ||
| 113 | self.logger.info('-' * 70) | ||
| 114 | for line in self.buffers[tid].split('\n'): | ||
| 115 | self.logger.info(line) | ||
| 116 | self._lock.release() | ||
