testimage.bbclass: correctly process SIGTERM
PATCH 1/2 testimage.bbclass: correctly process SIGTERM
Python's unittest will not propagate exceptions upside of itself, but rather will just catch and print them.
The working way to make it stop is to send a SIGINT (e.g. simulate a ctrl-c press), which will make it exit with a KeyboardInterrupt exception.
This also makes pressing ctrl-c twice from bitbake work again (previously hanging instances of bitbake and qemu were left around, and bitbake would no longer start until they were killed manually).
Signed-off-by Alexander Kanavin <[email protected]>
--- meta/classes/testimage.bbclass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes/testimage.bbclass +4 -4
@@ -204,7 +204,7 @@ def testimage_main(d): """ Catch SIGTERM from worker in order to stop qemu. """ - raise RuntimeError + os.kill(os.getpid(), signal.SIGINT) testimage_sanity(d)
@@ -360,9 +360,9 @@ def testimage_main(d): # or if the worker send us a SIGTERM tc.target.start(params=d.getVar("TEST_QEMUPARAMS"), runqemuparams=d.getVar("TEST_RUNQEMUPARAMS")) results = tc.runTests() - except (RuntimeError, BlockingIOError) as err: - if isinstance(err, RuntimeError): - bb.error('testimage received SIGTERM, shutting down...') + except (KeyboardInterrupt, BlockingIOError) as err: + if isinstance(err, KeyboardInterrupt): + bb.error('testimage interrupted, shutting down...') else: bb.error('runqemu failed, shutting down...') if results:
Signature · 1 line
2.26.0
PATCH 2/2 testimage: add an overall timeout setting
This is useful when tests misbehave and get stuck, or when a significant increase in testing time is undesirable and needs to be caught automatically.
Signed-off-by Alexander Kanavin <[email protected]>
--- meta/classes/testimage.bbclass | 11 +++++++++++ 1 file changed, 11 insertions(+)
meta/classes/testimage.bbclass +11 -0
@@ -31,6 +31,7 @@ TESTIMAGE_AUTO ??= "0" # TEST_LOG_DIR contains a command ssh log and may contain infromation about what command is running, output and return codes and for qemu a boot log till login. # Booting is handled by this class, and it's not a test in itself. # TEST_QEMUBOOT_TIMEOUT can be used to set the maximum time in seconds the launch code will wait for the login prompt. +# TEST_OVERALL_TIMEOUT can be used to set the maximum time in seconds the tests will be allowed to run (defaults to no limit). # TEST_QEMUPARAMS can be used to pass extra parameters to qemu, e.g. "-m 1024" for setting the amount of ram to 1 GB. # TEST_RUNQEMUPARAMS can be used to pass extra parameters to runqemu, e.g. "gl" to enable OpenGL acceleration.
@@ -75,6 +76,7 @@ DEFAULT_TEST_SUITES_remove_qemumips64 = "${MIPSREMOVE}" TEST_SUITES ?= "${DEFAULT_TEST_SUITES}" TEST_QEMUBOOT_TIMEOUT ?= "1000" +TEST_OVERALL_TIMEOUT ?= "" TEST_TARGET ?= "qemu" TEST_QEMUPARAMS ?= "" TEST_RUNQEMUPARAMS ?= ""
@@ -206,6 +208,10 @@ def testimage_main(d): """ os.kill(os.getpid(), signal.SIGINT) + def handle_test_timeout(timeout): + bb.warn("Global test timeout reached (%s seconds), stopping the tests." %(timeout)) + os.kill(os.getpid(), signal.SIGINT) + testimage_sanity(d) if (d.getVar('IMAGE_PKGTYPE') == 'rpm'
@@ -359,6 +365,11 @@ def testimage_main(d): # We need to check if runqemu ends unexpectedly # or if the worker send us a SIGTERM tc.target.start(params=d.getVar("TEST_QEMUPARAMS"), runqemuparams=d.getVar("TEST_RUNQEMUPARAMS")) + import threading + try: + threading.Timer(int(d.getVar("TEST_OVERALL_TIMEOUT")), handle_test_timeout, (int(d.getVar("TEST_OVERALL_TIMEOUT")),)).start() + except ValueError: + pass results = tc.runTests() except (KeyboardInterrupt, BlockingIOError) as err: if isinstance(err, KeyboardInterrupt):
Signature · 1 line
2.26.0