[oe-commits] Lucian Musat : oeqa/utils: Added timeout decorator for testcases.
git at git.openembedded.org
git at git.openembedded.org
Thu Jun 11 23:00:21 UTC 2015
Module: openembedded-core.git
Branch: master
Commit: c6fe26ade5734efb5250e00c56fdbb4095b0018b
URL: http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=c6fe26ade5734efb5250e00c56fdbb4095b0018b
Author: Lucian Musat <george.l.musat at intel.com>
Date: Wed Jun 10 13:52:40 2015 +0300
oeqa/utils: Added timeout decorator for testcases.
Signed-off-by: Lucian Musat <george.l.musat at intel.com>
Signed-off-by: Ross Burton <ross.burton at intel.com>
---
meta/lib/oeqa/utils/decorators.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index 61a1a73..b9fc76c 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -11,6 +11,8 @@ import logging
import sys
import unittest
import threading
+import signal
+from functools import wraps
#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame
class getResults(object):
@@ -160,3 +162,27 @@ def LogResults(original_class):
original_class.run = run
return original_class
+
+class TimeOut(BaseException):
+ pass
+
+def timeout(seconds):
+ def decorator(fn):
+ if hasattr(signal, 'alarm'):
+ @wraps(fn)
+ def wrapped_f(*args, **kw):
+ current_frame = sys._getframe()
+ def raiseTimeOut(signal, frame):
+ if frame is not current_frame:
+ raise TimeOut('%s seconds' % seconds)
+ prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut)
+ try:
+ signal.alarm(seconds)
+ return fn(*args, **kw)
+ finally:
+ signal.alarm(0)
+ signal.signal(signal.SIGALRM, prev_handler)
+ return wrapped_f
+ else:
+ return fn
+ return decorator
\ No newline at end of file
More information about the Openembedded-commits
mailing list