]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/decorators: Added decorator to restart the DUT in case of test hang.
authorLucian Musat <george.l.musat@intel.com>
Tue, 15 Sep 2015 15:11:59 +0000 (18:11 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 15 Sep 2015 16:50:07 +0000 (17:50 +0100)
Once the DUT is hanged during testing, currently all the following test
cases have to wait for default timeout to exit. Using this decorator the
user can choose a timeout at case by case basis and what happens when the
timeout is reached by overwriting the self.target.restart method.

[YOCTO #7853]

Signed-off-by: Lucian Musat <george.l.musat@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/oetest.py
meta/lib/oeqa/utils/decorators.py

index 0fe68d4d521139af1814e062878afbf1edaa8b02..a6f89b6a86a0c92ae8ab7143c27aa9bcb7addf59 100644 (file)
@@ -151,6 +151,12 @@ class oeRuntimeTest(oeTest):
         elif (type(self.target).__name__ == "QemuTarget"):
             self.assertTrue(self.target.check(), msg = "Qemu not running?")
 
+        self.setUpLocal()
+
+    # a setup method before tests but after the class instantiation
+    def setUpLocal(self):
+        pass
+
     def tearDown(self):
         # If a test fails or there is an exception
         if not exc_info() == (None, None, None):
index 162a88fb789eaa66bbf09abccac3d6f708ddb2c6..b6adcb18466b24bfd971b23276dcc0d227396617 100644 (file)
@@ -220,3 +220,28 @@ def getAllTags(obj):
     ret = __gettags(obj)
     ret.update(__gettags(tc_method))
     return ret
+
+def timeout_handler(seconds):
+    def decorator(fn):
+        if hasattr(signal, 'alarm'):
+            @wraps(fn)
+            def wrapped_f(self, *args, **kw):
+                current_frame = sys._getframe()
+                def raiseTimeOut(signal, frame):
+                    if frame is not current_frame:
+                        try:
+                            self.target.restart()
+                            raise TimeOut('%s seconds' % seconds)
+                        except:
+                            raise TimeOut('%s seconds' % seconds)
+                prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut)
+                try:
+                    signal.alarm(seconds)
+                    return fn(self, *args, **kw)
+                finally:
+                    signal.alarm(0)
+                    signal.signal(signal.SIGALRM, prev_handler)
+            return wrapped_f
+        else:
+            return fn
+    return decorator