]> code.ossystems Code Review - openembedded-core.git/commitdiff
oe-selftest: Implement console 'keepalive' output
authorNathan Rossi <nathan@nathanrossi.com>
Thu, 5 Sep 2019 13:44:15 +0000 (13:44 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 6 Sep 2019 07:13:40 +0000 (08:13 +0100)
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.

Signed-off-by: Nathan Rossi <nathan@nathanrossi.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/scriptutils.py
scripts/oe-selftest

index e7e7021c2458d21c2bbb5a6c2bd996527130d7ab..c573dc7f6783e754b66aa6c202a6ef2a39c543ec 100644 (file)
@@ -16,12 +16,51 @@ import string
 import subprocess
 import sys
 import tempfile
+import threading
 import importlib
 from importlib import machinery
 
-def logger_create(name, stream=None):
+class KeepAliveStreamHandler(logging.StreamHandler):
+    def __init__(self, keepalive=True, **kwargs):
+        super().__init__(**kwargs)
+        if keepalive is True:
+            keepalive = 5000 # default timeout
+        self._timeout = threading.Condition()
+        self._stop = False
+
+        # background thread waits on condition, if the condition does not
+        # happen emit a keep alive message
+        def thread():
+            while not self._stop:
+                with self._timeout:
+                    if not self._timeout.wait(keepalive):
+                        self.emit(logging.LogRecord("keepalive", logging.INFO,
+                            None, None, "Keepalive message", None, None))
+
+        self._thread = threading.Thread(target = thread, daemon = True)
+        self._thread.start()
+
+    def close(self):
+        # mark the thread to stop and notify it
+        self._stop = True
+        with self._timeout:
+            self._timeout.notify()
+        # wait for it to join
+        self._thread.join()
+        super().close()
+
+    def emit(self, record):
+        super().emit(record)
+        # trigger timer reset
+        with self._timeout:
+            self._timeout.notify()
+
+def logger_create(name, stream=None, keepalive=None):
     logger = logging.getLogger(name)
-    loggerhandler = logging.StreamHandler(stream=stream)
+    if keepalive is not None:
+        loggerhandler = KeepAliveStreamHandler(stream=stream, keepalive=keepalive)
+    else:
+        loggerhandler = logging.StreamHandler(stream=stream)
     loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
     logger.addHandler(loggerhandler)
     logger.setLevel(logging.INFO)
index 57662b2f75d0f4ebc02d8d6b41edaabbc132e2e1..18ac0f5869c81570be3d8a2b7e73a89d01bac055 100755 (executable)
@@ -33,7 +33,7 @@ scriptpath.add_bitbake_lib_path()
 from oeqa.utils import load_test_components
 from oeqa.core.exception import OEQAPreRun
 
-logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout)
+logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
 
 def main():
     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."