[PATCH 35/42] tests: allow specifying multiple failure locations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Benjamin Berg <benjamin.berg@xxxxxxxxx>

Having the ability to trigger multiple failures in one test can be
useful. Add support to the test infrastructure to do this.

Signed-off-by: Benjamin Berg <benjamin.berg@xxxxxxxxx>
---
 tests/hwsim/utils.py | 45 ++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py
index 769f824c7b..d572bdc4c9 100644
--- a/tests/hwsim/utils.py
+++ b/tests/hwsim/utils.py
@@ -35,33 +35,38 @@ def long_duration_test(func):
     func.long_duration_test = True
     return func
 
-class alloc_fail(object):
-    def __init__(self, dev, count, funcs):
-        self._dev = dev
-        self._count = count
-        self._funcs = funcs
-    def __enter__(self):
-        cmd = "TEST_ALLOC_FAIL %d:%s" % (self._count, self._funcs)
-        if "OK" not in self._dev.request(cmd):
-            raise HwsimSkip("TEST_ALLOC_FAIL not supported")
-    def __exit__(self, type, value, traceback):
-        if type is None:
-            if self._dev.request("GET_ALLOC_FAIL") != "0:%s" % self._funcs:
-                raise Exception("Allocation failure did not trigger")
-
 class fail_test(object):
-    def __init__(self, dev, count, funcs):
+    _test_fail = 'TEST_FAIL'
+    _get_fail = 'GET_FAIL'
+
+    def __init__(self, dev, count, funcs, *args):
         self._dev = dev
-        self._count = count
-        self._funcs = funcs
+        self._funcs = [(count, funcs)]
+
+        args = list(args)
+        while args:
+            count = args.pop(0)
+            funcs = args.pop(0)
+            self._funcs.append((count, funcs))
     def __enter__(self):
-        cmd = "TEST_FAIL %d:%s" % (self._count, self._funcs)
+        patterns = ' '.join(['%d:%s' % (c, f) for c, f in self._funcs])
+        cmd = '%s %s' % (self._test_fail, patterns)
         if "OK" not in self._dev.request(cmd):
             raise HwsimSkip("TEST_FAIL not supported")
     def __exit__(self, type, value, traceback):
+        pending = self._dev.request(self._get_fail)
         if type is None:
-            if self._dev.request("GET_FAIL") != "0:%s" % self._funcs:
-                raise Exception("Test failure did not trigger")
+            expected = ' '.join(['0:%s' % f for c, f in self._funcs])
+            if pending != expected:
+                # Ensure the failure cannot trigger in the future
+                self._dev.request('%s 0:' % self._test_fail)
+                raise Exception("Not all failures triggered (pending: %s)" % pending)
+        else:
+            logger.info("Pending failures at time of exception: %s" % pending)
+
+class alloc_fail(fail_test):
+    _test_fail = 'TEST_ALLOC_FAIL'
+    _get_fail = 'GET_ALLOC_FAIL'
 
 def wait_fail_trigger(dev, cmd, note="Failure not triggered", max_iter=40,
 		      timeout=0.05):
-- 
2.38.1


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux