summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oeqa/oetest.py6
-rw-r--r--meta/lib/oeqa/utils/decorators.py25
2 files changed, 31 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 0fe68d4d52..a6f89b6a86 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -151,6 +151,12 @@ class oeRuntimeTest(oeTest):
151 elif (type(self.target).__name__ == "QemuTarget"): 151 elif (type(self.target).__name__ == "QemuTarget"):
152 self.assertTrue(self.target.check(), msg = "Qemu not running?") 152 self.assertTrue(self.target.check(), msg = "Qemu not running?")
153 153
154 self.setUpLocal()
155
156 # a setup method before tests but after the class instantiation
157 def setUpLocal(self):
158 pass
159
154 def tearDown(self): 160 def tearDown(self):
155 # If a test fails or there is an exception 161 # If a test fails or there is an exception
156 if not exc_info() == (None, None, None): 162 if not exc_info() == (None, None, None):
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 162a88fb78..b6adcb1846 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -220,3 +220,28 @@ def getAllTags(obj):
220 ret = __gettags(obj) 220 ret = __gettags(obj)
221 ret.update(__gettags(tc_method)) 221 ret.update(__gettags(tc_method))
222 return ret 222 return ret
223
224def timeout_handler(seconds):
225 def decorator(fn):
226 if hasattr(signal, 'alarm'):
227 @wraps(fn)
228 def wrapped_f(self, *args, **kw):
229 current_frame = sys._getframe()
230 def raiseTimeOut(signal, frame):
231 if frame is not current_frame:
232 try:
233 self.target.restart()
234 raise TimeOut('%s seconds' % seconds)
235 except:
236 raise TimeOut('%s seconds' % seconds)
237 prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut)
238 try:
239 signal.alarm(seconds)
240 return fn(self, *args, **kw)
241 finally:
242 signal.alarm(0)
243 signal.signal(signal.SIGALRM, prev_handler)
244 return wrapped_f
245 else:
246 return fn
247 return decorator