summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
authorLucian Musat <george.l.musat@intel.com>2015-06-10 13:52:40 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-11 23:59:17 +0100
commitad0aa8d548e21e6e262c4b0d9fe7eb72b1b2c24f (patch)
treef273087f44eb657005350ca90cd01a4edc1eaf74 /meta/lib/oeqa/utils
parentf08baeed2cf480dfbd186493bfeaace193256ba7 (diff)
downloadpoky-ad0aa8d548e21e6e262c4b0d9fe7eb72b1b2c24f.tar.gz
oeqa/utils: Added timeout decorator for testcases.
(From OE-Core rev: c6fe26ade5734efb5250e00c56fdbb4095b0018b) Signed-off-by: Lucian Musat <george.l.musat@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/decorators.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 61a1a739ea..b9fc76c9ee 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -11,6 +11,8 @@ import logging
11import sys 11import sys
12import unittest 12import unittest
13import threading 13import threading
14import signal
15from functools import wraps
14 16
15#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame 17#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame
16class getResults(object): 18class getResults(object):
@@ -160,3 +162,27 @@ def LogResults(original_class):
160 162
161 original_class.run = run 163 original_class.run = run
162 return original_class 164 return original_class
165
166class TimeOut(BaseException):
167 pass
168
169def timeout(seconds):
170 def decorator(fn):
171 if hasattr(signal, 'alarm'):
172 @wraps(fn)
173 def wrapped_f(*args, **kw):
174 current_frame = sys._getframe()
175 def raiseTimeOut(signal, frame):
176 if frame is not current_frame:
177 raise TimeOut('%s seconds' % seconds)
178 prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut)
179 try:
180 signal.alarm(seconds)
181 return fn(*args, **kw)
182 finally:
183 signal.alarm(0)
184 signal.signal(signal.SIGALRM, prev_handler)
185 return wrapped_f
186 else:
187 return fn
188 return decorator \ No newline at end of file