summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2017-05-26 15:37:40 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:14 +0100
commitd3d4ba902dee8b19fa1054330cffdf73f9b81fe7 (patch)
treecbf70954f69170253d3882ecb3b277b88c0ce5da /meta/lib
parent008cc04790845721bea649e9a9ff84f0d466f771 (diff)
downloadpoky-d3d4ba902dee8b19fa1054330cffdf73f9b81fe7.tar.gz
oeqa/core/decorator/oetimeout: Add support for OEQA threaded mode
In python signals are only allowed to delivery into the main thread, to support the threading mode test if the runner is threaded and use threading.Timer instead. There are some considerations like SIGALRM interrupts the execution after N seconds but the Timer only starts a Thread to notice the timeout and the exception will be raised when the test run ends. [YOCTO #11450] (From OE-Core rev: 8ab201612e22493dc2509ba339a8f07ade611a54) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/core/decorator/oetimeout.py40
1 files changed, 30 insertions, 10 deletions
diff --git a/meta/lib/oeqa/core/decorator/oetimeout.py b/meta/lib/oeqa/core/decorator/oetimeout.py
index a247583f7f..f85e7d9792 100644
--- a/meta/lib/oeqa/core/decorator/oetimeout.py
+++ b/meta/lib/oeqa/core/decorator/oetimeout.py
@@ -1,8 +1,12 @@
1# Copyright (C) 2016 Intel Corporation 1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT) 2# Released under the MIT license (see COPYING.MIT)
3 3
4import signal
5from . import OETestDecorator, registerDecorator 4from . import OETestDecorator, registerDecorator
5
6import signal
7from threading import Timer
8
9from oeqa.core.threaded import OETestRunnerThreaded
6from oeqa.core.exception import OEQATimeoutError 10from oeqa.core.exception import OEQATimeoutError
7 11
8@registerDecorator 12@registerDecorator
@@ -10,16 +14,32 @@ class OETimeout(OETestDecorator):
10 attrs = ('oetimeout',) 14 attrs = ('oetimeout',)
11 15
12 def setUpDecorator(self): 16 def setUpDecorator(self):
13 timeout = self.oetimeout 17 self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout)
14 def _timeoutHandler(signum, frame): 18
15 raise OEQATimeoutError("Timed out after %s " 19 if isinstance(self.case.tc.runner, OETestRunnerThreaded):
20 self.timeouted = False
21 def _timeoutHandler():
22 self.timeouted = True
23
24 self.timer = Timer(self.oetimeout, _timeoutHandler)
25 self.timer.start()
26 else:
27 timeout = self.oetimeout
28 def _timeoutHandler(signum, frame):
29 raise OEQATimeoutError("Timed out after %s "
16 "seconds of execution" % timeout) 30 "seconds of execution" % timeout)
17 31
18 self.logger.debug("Setting up a %d second(s) timeout" % self.oetimeout) 32 self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler)
19 self.alarmSignal = signal.signal(signal.SIGALRM, _timeoutHandler) 33 signal.alarm(self.oetimeout)
20 signal.alarm(self.oetimeout)
21 34
22 def tearDownDecorator(self): 35 def tearDownDecorator(self):
23 signal.alarm(0) 36 if isinstance(self.case.tc.runner, OETestRunnerThreaded):
24 signal.signal(signal.SIGALRM, self.alarmSignal) 37 self.timer.cancel()
25 self.logger.debug("Removed SIGALRM handler") 38 self.logger.debug("Removed Timer handler")
39 if self.timeouted:
40 raise OEQATimeoutError("Timed out after %s "
41 "seconds of execution" % self.oetimeout)
42 else:
43 signal.alarm(0)
44 signal.signal(signal.SIGALRM, self.alarmSignal)
45 self.logger.debug("Removed SIGALRM handler")