summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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")