2 # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 with open("/proc/net/dev", "r") as f:
16 ifnames.append(val[0].strip(' '))
19 class HwsimSkip(Exception):
20 def __init__(self, reason):
25 class alloc_fail(object):
26 def __init__(self, dev, count, funcs):
31 cmd = "TEST_ALLOC_FAIL %d:%s" % (self._count, self._funcs)
32 if "OK" not in self._dev.request(cmd):
33 raise HwsimSkip("TEST_ALLOC_FAIL not supported")
34 def __exit__(self, type, value, traceback):
36 if self._dev.request("GET_ALLOC_FAIL") != "0:%s" % self._funcs:
37 raise Exception("Allocation failure did not trigger")
39 class fail_test(object):
40 def __init__(self, dev, count, funcs):
45 cmd = "TEST_FAIL %d:%s" % (self._count, self._funcs)
46 if "OK" not in self._dev.request(cmd):
47 raise HwsimSkip("TEST_FAIL not supported")
48 def __exit__(self, type, value, traceback):
50 if self._dev.request("GET_FAIL") != "0:%s" % self._funcs:
51 raise Exception("Test failure did not trigger")
53 def require_under_vm():
54 with open('/proc/1/cmdline', 'r') as f:
56 if "inside.sh" not in cmd:
57 raise HwsimSkip("Not running under VM")
59 def iface_is_in_bridge(bridge, ifname):
60 fname = "/sys/class/net/"+ifname+"/brport/bridge"
61 if not os.path.exists(fname):
63 if not os.path.islink(fname):
65 truebridge = os.path.basename(os.readlink(fname))
66 if bridge == truebridge:
70 def skip_with_fips(dev, reason="Not supported in FIPS mode"):
71 res = dev.get_capability("fips")
72 if res and 'FIPS' in res:
73 raise HwsimSkip(reason)