tests: Allow specifying multiple failure locations

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@intel.com>
This commit is contained in:
Benjamin Berg 2023-11-21 01:51:49 +02:00 committed by Jouni Malinen
parent 781e87c418
commit a5d5b63d61

View file

@ -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):