diff options
author | Nathan Rossi <nathan@nathanrossi.com> | 2019-09-05 13:44:15 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-09-06 08:15:45 +0100 |
commit | 4364a26db198870b12749f04da2ed0f95a105ab0 (patch) | |
tree | 575887548845b50fce15dd837d1118a3c693f146 /scripts | |
parent | ecfa7aaea3e1c227704583347555e0b68de63104 (diff) | |
download | poky-4364a26db198870b12749f04da2ed0f95a105ab0.tar.gz |
oe-selftest: Implement console 'keepalive' output
Similar to bitbake, implement a 'keepalive' output to the console to
ensure CI systems do not kill the process. The default timeout for
bitbake is 5000s.
(From OE-Core rev: 77939cca96fa5467c88eafa3ac0db2db4aef09d6)
Signed-off-by: Nathan Rossi <nathan@nathanrossi.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/scriptutils.py | 43 | ||||
-rwxr-xr-x | scripts/oe-selftest | 2 |
2 files changed, 42 insertions, 3 deletions
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py index e7e7021c24..c573dc7f67 100644 --- a/scripts/lib/scriptutils.py +++ b/scripts/lib/scriptutils.py | |||
@@ -16,12 +16,51 @@ import string | |||
16 | import subprocess | 16 | import subprocess |
17 | import sys | 17 | import sys |
18 | import tempfile | 18 | import tempfile |
19 | import threading | ||
19 | import importlib | 20 | import importlib |
20 | from importlib import machinery | 21 | from importlib import machinery |
21 | 22 | ||
22 | def logger_create(name, stream=None): | 23 | class KeepAliveStreamHandler(logging.StreamHandler): |
24 | def __init__(self, keepalive=True, **kwargs): | ||
25 | super().__init__(**kwargs) | ||
26 | if keepalive is True: | ||
27 | keepalive = 5000 # default timeout | ||
28 | self._timeout = threading.Condition() | ||
29 | self._stop = False | ||
30 | |||
31 | # background thread waits on condition, if the condition does not | ||
32 | # happen emit a keep alive message | ||
33 | def thread(): | ||
34 | while not self._stop: | ||
35 | with self._timeout: | ||
36 | if not self._timeout.wait(keepalive): | ||
37 | self.emit(logging.LogRecord("keepalive", logging.INFO, | ||
38 | None, None, "Keepalive message", None, None)) | ||
39 | |||
40 | self._thread = threading.Thread(target = thread, daemon = True) | ||
41 | self._thread.start() | ||
42 | |||
43 | def close(self): | ||
44 | # mark the thread to stop and notify it | ||
45 | self._stop = True | ||
46 | with self._timeout: | ||
47 | self._timeout.notify() | ||
48 | # wait for it to join | ||
49 | self._thread.join() | ||
50 | super().close() | ||
51 | |||
52 | def emit(self, record): | ||
53 | super().emit(record) | ||
54 | # trigger timer reset | ||
55 | with self._timeout: | ||
56 | self._timeout.notify() | ||
57 | |||
58 | def logger_create(name, stream=None, keepalive=None): | ||
23 | logger = logging.getLogger(name) | 59 | logger = logging.getLogger(name) |
24 | loggerhandler = logging.StreamHandler(stream=stream) | 60 | if keepalive is not None: |
61 | loggerhandler = KeepAliveStreamHandler(stream=stream, keepalive=keepalive) | ||
62 | else: | ||
63 | loggerhandler = logging.StreamHandler(stream=stream) | ||
25 | loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) | 64 | loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) |
26 | logger.addHandler(loggerhandler) | 65 | logger.addHandler(loggerhandler) |
27 | logger.setLevel(logging.INFO) | 66 | logger.setLevel(logging.INFO) |
diff --git a/scripts/oe-selftest b/scripts/oe-selftest index 57662b2f75..18ac0f5869 100755 --- a/scripts/oe-selftest +++ b/scripts/oe-selftest | |||
@@ -33,7 +33,7 @@ scriptpath.add_bitbake_lib_path() | |||
33 | from oeqa.utils import load_test_components | 33 | from oeqa.utils import load_test_components |
34 | from oeqa.core.exception import OEQAPreRun | 34 | from oeqa.core.exception import OEQAPreRun |
35 | 35 | ||
36 | logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout) | 36 | logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True) |
37 | 37 | ||
38 | def main(): | 38 | def main(): |
39 | description = "Script that runs unit tests against bitbake and other Yocto related tools. The goal is to validate tools functionality and metadata integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more information." | 39 | description = "Script that runs unit tests against bitbake and other Yocto related tools. The goal is to validate tools functionality and metadata integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more information." |