aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2014-10-20 10:00:05 (GMT)
committerJouni Malinen <j@w1.fi>2014-10-21 14:35:20 (GMT)
commit8a5cc2fe385bc8afa4260f8953664db9861430eb (patch)
tree0fad4e80cf173f3b50cfc993c68566e21d7dd1c0 /tests
parent91d7a9a1c50ed33ee8073df209f6e823df8f90d5 (diff)
downloadhostap-8a5cc2fe385bc8afa4260f8953664db9861430eb.zip
hostap-8a5cc2fe385bc8afa4260f8953664db9861430eb.tar.gz
hostap-8a5cc2fe385bc8afa4260f8953664db9861430eb.tar.bz2
tests: Introduce hwsim radio context manager
The new HWSimRadio context manager allows the following syntax to create (and appropriately destroy) a new radio: with HWSimRadio([...]) as (radio_id, iface_name): [...] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/hwsim/hwsim.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/hwsim/hwsim.py b/tests/hwsim/hwsim.py
index 5fe91b5..e21c814 100644
--- a/tests/hwsim/hwsim.py
+++ b/tests/hwsim/hwsim.py
@@ -7,7 +7,7 @@
# This software may be distributed under the terms of the BSD license.
# See README for more details.
-import netlink
+import netlink, os
# constants
HWSIM_CMD_CREATE_RADIO = 4
@@ -48,6 +48,32 @@ class HWSimController(object):
attrs = attrs)
msg.send_and_recv(self._conn)
+class HWSimRadio(object):
+ def __init__(self, n_channels=None, use_chanctx=False,
+ use_p2p_device=False):
+ self._controller = HWSimController()
+ self._n_channels = n_channels
+ self._use_chanctx = use_chanctx
+ self._use_p2p_dev = use_p2p_device
+
+ def __enter__(self):
+ self._radio_id = self._controller.create_radio(
+ n_channels=self._n_channels,
+ use_chanctx=self._use_chanctx,
+ use_p2p_device=self._use_p2p_dev)
+ if self._radio_id < 0:
+ raise Exception("Failed to create radio (err:%d)" % self._radio_id)
+ try:
+ iface = os.listdir('/sys/class/mac80211_hwsim/hwsim%d/net/' % self._radio_id)[0]
+ except Exception,e:
+ self._controller.destroy_radio(self._radio_id)
+ raise e
+ return self._radio_id, iface
+
+ def __exit__(self, type, value, traceback):
+ self._controller.destroy_radio(self._radio_id)
+
+
def create(args):
print 'Created radio %d' % c.create_radio(n_channels=args.channels,
use_chanctx=args.chanctx)