diff options
| -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." |
