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.
13 with open("/proc/net/dev", "r") as f:
18 ifnames.append(val[0].strip(' '))
21 class HwsimSkip(Exception):
22 def __init__(self, reason):
27 class alloc_fail(object):
28 def __init__(self, dev, count, funcs):
33 cmd = "TEST_ALLOC_FAIL %d:%s" % (self._count, self._funcs)
34 if "OK" not in self._dev.request(cmd):
35 raise HwsimSkip("TEST_ALLOC_FAIL not supported")
36 def __exit__(self, type, value, traceback):
38 if self._dev.request("GET_ALLOC_FAIL") != "0:%s" % self._funcs:
39 raise Exception("Allocation failure did not trigger")
41 class fail_test(object):
42 def __init__(self, dev, count, funcs):
47 cmd = "TEST_FAIL %d:%s" % (self._count, self._funcs)
48 if "OK" not in self._dev.request(cmd):
49 raise HwsimSkip("TEST_FAIL not supported")
50 def __exit__(self, type, value, traceback):
52 if self._dev.request("GET_FAIL") != "0:%s" % self._funcs:
53 raise Exception("Test failure did not trigger")
55 def wait_fail_trigger(dev, cmd, note="Failure not triggered"):
56 for i in range(0, 40):
57 if dev.request(cmd).startswith("0:"):
63 def require_under_vm():
64 with open('/proc/1/cmdline', 'r') as f:
66 if "inside.sh" not in cmd:
67 raise HwsimSkip("Not running under VM")
69 def iface_is_in_bridge(bridge, ifname):
70 fname = "/sys/class/net/"+ifname+"/brport/bridge"
71 if not os.path.exists(fname):
73 if not os.path.islink(fname):
75 truebridge = os.path.basename(os.readlink(fname))
76 if bridge == truebridge:
80 def skip_with_fips(dev, reason="Not supported in FIPS mode"):
81 res = dev.get_capability("fips")
82 if res and 'FIPS' in res:
83 raise HwsimSkip(reason)
85 def get_phy(ap, ifname=None):
88 hostname = ap['hostname']
91 host = remotehost.Host(hostname)
95 status, buf = host.execute(["iw", "dev", ifname, "info"])
97 raise Exception("iw " + ifname + " info failed")
98 lines = buf.split("\n")
102 phy = "phy" + words[1]