Skip to contentSkip to conversation

testimage: handle SIGTERM to conclude runqemu

PATCH Superseded [email protected] 1 participant 1 message Sep 5, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 testimage: handle SIGTERM to conclude runqemu

From: Mariano Lopez <[email protected]>

In the current state if a SIGTERM is sent to
the testimage worker, the worker will exit but
runqemu and qemu won't exit and the processes
need to be killed manually to free the
bitbake lock.

This allows to catch the SIGTERM signal in testimage, this way it is possible to stop runqemu and qemu and allow to free the bitbake lock.

Also this allows to skip the rest of the tests
when running the tests in qemu or real hardware.

This also solves minimal breaks when handling the
SIGCHLD in qemurunner and when checking if qemu
is alive in the test setup.

[YOCTO #8239]

---
 meta/classes/testimage.bbclass    | 12 +++++++++++-
 meta/lib/oeqa/oetest.py           |  6 +++++-
 meta/lib/oeqa/utils/qemurunner.py |  3 +--
 3 files changed, 17 insertions(+), 4 deletions(-)
meta/classes/testimage.bbclass +11 -1
index 7c783ea..19a37cb 100644
@@ -236,6 +236,7 @@ def testimage_main(d):
     import os
     import oeqa.runtime
     import time
+    import signal
     from oeqa.oetest import loadTests, runTests
     from oeqa.targetcontrol import get_target_controller
     from oeqa.utils.dump import get_host_dumper
@@ -273,12 +274,20 @@ def testimage_main(d):
             self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split()
             self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split()
             manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + ".manifest")
+            self.sigterm = False
+            self.origsigtermhandler = signal.getsignal(signal.SIGTERM)
+            signal.signal(signal.SIGTERM, self.sigterm_exception)
             try:
                 with open(manifest) as f:
                     self.pkgmanifest = f.read()
             except IOError as e:
                 bb.fatal("No package manifest file found. Did you build the image?\n%s" % e)
 
+        def sigterm_exception(self, signum, stackframe):
+            bb.warn("TestImage received SIGTERM, shutting down...")
+            self.sigterm = True
+            self.target.stop()
+
     # test context
     tc = TestContext()
 
@@ -293,8 +302,8 @@ def testimage_main(d):
 
     target.deploy()
 
-    target.start()
     try:
+        target.start()
         if export:
             exportTests(d,tc)
         else:
@@ -311,6 +320,7 @@ def testimage_main(d):
             else:
                 raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn )
     finally:
+        signal.signal(signal.SIGTERM, tc.origsigtermhandler)
         target.stop()
 
 testimage_main[vardepsexclude] =+ "BB_ORIGENV"
meta/lib/oeqa/oetest.py +5 -1
index ff62c30..0fe68d4 100644
@@ -145,7 +145,11 @@ class oeRuntimeTest(oeTest):
         super(oeRuntimeTest, self).__init__(methodName)
 
     def setUp(self):
-        self.assertTrue(self.target.check(), msg = "Qemu not running?")
+        # Check if test needs to run
+        if self.tc.sigterm:
+            self.fail("Got SIGTERM")
+        elif (type(self.target).__name__ == "QemuTarget"):
+            self.assertTrue(self.target.check(), msg = "Qemu not running?")
 
     def tearDown(self):
         # If a test fails or there is an exception
meta/lib/oeqa/utils/qemurunner.py +1 -2
index c04ee0d..4b29284 100644
@@ -232,7 +232,7 @@ class QemuRunner:
         return self.is_alive()
 
     def stop(self):
-
+        signal.signal(signal.SIGCHLD, self.origchldhandler)
         self.stop_thread()
         if self.runqemu:
             logger.info("Sending SIGTERM to runqemu")
@@ -253,7 +253,6 @@ class QemuRunner:
             self.server_socket = None
         self.qemupid = None
         self.ip = None
-        signal.signal(signal.SIGCHLD, self.origchldhandler)
 
     def stop_thread(self):
         if self.thread and self.thread.is_alive():
Signature · 1 line
1.8.4.5