[PATCH v2 04/17] tests: pass apdev to hostapd.add_bss()

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

 



Pass apdev param to hostapd.add_bss().
Kill hardcoded phy param and get phy
base on apdev.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx>
---
 tests/hwsim/hostapd.py         | 15 ++++++++---
 tests/hwsim/test_ap_dynamic.py | 61 +++++++++++++++++++++---------------------
 tests/hwsim/test_ap_ht.py      |  6 ++---
 tests/hwsim/test_ap_wps.py     |  2 +-
 tests/hwsim/utils.py           | 22 +++++++++++++++
 5 files changed, 68 insertions(+), 38 deletions(-)

diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 868f664..01b336e 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -11,6 +11,7 @@ import binascii
 import struct
 import wpaspy
 import remotehost
+import utils
 
 logger = logging.getLogger()
 hapd_ctrl = '/var/run/hostapd'
@@ -389,9 +390,17 @@ def add_ap(apdev, params, wait_enabled=True, no_enable=False, timeout=30):
                 raise Exception("AP startup failed")
         return hapd
 
-def add_bss(phy, ifname, confname, ignore_error=False, hostname=None,
-            port=8878):
-    logger.info("Starting BSS phy=" + phy + " ifname=" + ifname)
+def add_bss(apdev, ifname, confname, phy=None, ignore_error=False):
+    if phy == None:
+        phy = utils.get_phy(apdev)
+    try:
+        hostname = apdev['hostname']
+        port = apdev['port']
+        logger.info("Starting BSS " + hostname + "/" + port + " phy=" + phy + " ifname=" + ifname)
+    except:
+        logger.info("Starting BSS phy=" + phy + " ifname=" + ifname)
+        hostname = None
+        port = 8878
     hapd_global = HostapdGlobal(hostname=hostname, port=port)
     hapd_global.add_bss(phy, confname, ignore_error)
     port = hapd_global.get_ctrl_iface_port(ifname)
diff --git a/tests/hwsim/test_ap_dynamic.py b/tests/hwsim/test_ap_dynamic.py
index a859651..fb8e35c 100644
--- a/tests/hwsim/test_ap_dynamic.py
+++ b/tests/hwsim/test_ap_dynamic.py
@@ -96,31 +96,31 @@ def _test_ap_bss_add_remove(dev, apdev):
     ifname2 = apdev[0]['ifname'] + '-2'
     ifname3 = apdev[0]['ifname'] + '-3'
     logger.info("Set up three BSSes one by one")
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
     multi_check(dev, [ True, False, False ])
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     multi_check(dev, [ True, True, False ])
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Remove the last BSS and re-add it")
     hostapd.remove_bss(apdev[0], ifname3)
     multi_check(dev, [ True, True, False ])
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Remove the middle BSS and re-add it")
     hostapd.remove_bss(apdev[0], ifname2)
     multi_check(dev, [ True, False, True ])
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Remove the first BSS and re-add it and other BSSs")
     hostapd.remove_bss(apdev[0], ifname1)
     multi_check(dev, [ False, False, False ])
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Remove two BSSes and re-add them")
@@ -128,9 +128,9 @@ def _test_ap_bss_add_remove(dev, apdev):
     multi_check(dev, [ True, False, True ])
     hostapd.remove_bss(apdev[0], ifname3)
     multi_check(dev, [ True, False, False ])
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     multi_check(dev, [ True, True, False ])
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Remove three BSSes in and re-add them")
@@ -140,15 +140,15 @@ def _test_ap_bss_add_remove(dev, apdev):
     multi_check(dev, [ True, False, False ])
     hostapd.remove_bss(apdev[0], ifname1)
     multi_check(dev, [ False, False, False ])
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
     multi_check(dev, [ True, False, False ])
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     multi_check(dev, [ True, True, False ])
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
     multi_check(dev, [ True, True, True ])
 
     logger.info("Test error handling if a duplicate ifname is tried")
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf', ignore_error=True)
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf', ignore_error=True)
     multi_check(dev, [ True, True, True ])
 
 def test_ap_bss_add_remove_during_ht_scan(dev, apdev):
@@ -157,20 +157,20 @@ def test_ap_bss_add_remove_during_ht_scan(dev, apdev):
         dev[i].flush_scan_cache()
     ifname1 = apdev[0]['ifname']
     ifname2 = apdev[0]['ifname'] + '-2'
-    hostapd.add_bss('phy3', ifname1, 'bss-ht40-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-ht40-2.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
     multi_check(dev, [ True, True ], scan_opt=False)
     hostapd.remove_bss(apdev[0], ifname2)
     hostapd.remove_bss(apdev[0], ifname1)
 
-    hostapd.add_bss('phy3', ifname1, 'bss-ht40-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-ht40-2.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
     hostapd.remove_bss(apdev[0], ifname2)
     multi_check(dev, [ True, False ], scan_opt=False)
     hostapd.remove_bss(apdev[0], ifname1)
 
-    hostapd.add_bss('phy3', ifname1, 'bss-ht40-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-ht40-2.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-ht40-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-ht40-2.conf')
     hostapd.remove_bss(apdev[0], ifname1)
     multi_check(dev, [ False, False ])
 
@@ -348,8 +348,8 @@ def test_ap_enable_disable_reenable(dev, apdev):
 
 def test_ap_double_disable(dev, apdev):
     """Double DISABLE regression test"""
-    hostapd.add_bss('phy3', apdev[0]['ifname'], 'bss-1.conf')
-    hostapd.add_bss('phy3', apdev[0]['ifname'] + '-2', 'bss-2.conf')
+    hostapd.add_bss(apdev[0], apdev[0]['ifname'], 'bss-1.conf')
+    hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf')
     hapd = hostapd.Hostapd(apdev[0]['ifname'])
     hapd.disable()
     if "FAIL" not in hapd.request("DISABLE"):
@@ -378,8 +378,7 @@ def test_ap_bss_add_many(dev, apdev):
 
 def _test_ap_bss_add_many(dev, apdev):
     ifname = apdev[0]['ifname']
-    phy = 'phy3'
-    hostapd.add_bss(phy, ifname, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname, 'bss-1.conf')
     hapd = hostapd.HostapdGlobal()
     fname = '/tmp/hwsim-bss.conf'
     for i in range(16):
@@ -393,7 +392,7 @@ def _test_ap_bss_add_many(dev, apdev):
             f.write("bssid=02:00:00:00:03:%02x\n" % (i + 1))
             f.write("ctrl_interface=/var/run/hostapd\n")
             f.write("ssid=test-%d\n" % i)
-        hostapd.add_bss(phy, ifname2, fname)
+        hostapd.add_bss(apdev[0], ifname2, fname)
         os.remove(fname)
 
     dev[0].request("SCAN_INTERVAL 1")
@@ -411,10 +410,10 @@ def test_ap_bss_add_reuse_existing(dev, apdev):
     """Dynamic BSS add operation reusing existing interface"""
     ifname1 = apdev[0]['ifname']
     ifname2 = apdev[0]['ifname'] + '-2'
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
     subprocess.check_call(["iw", "dev", ifname1, "interface", "add", ifname2,
                            "type", "__ap"])
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     hostapd.remove_bss(apdev[0], ifname2)
     subprocess.check_call(["iw", "dev", ifname2, "del"])
 
@@ -439,14 +438,14 @@ def test_ap_bss_add_out_of_memory(dev, apdev):
     hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-1.conf',
                         1, 'ieee802_11_build_ap_params')
 
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
 
     hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-2.conf',
                         1, 'hostapd_interface_init_bss')
     hapd_bss_out_of_mem(hapd2, 'phy3', 'bss-2.conf',
                         1, 'ieee802_11_build_ap_params')
 
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     hostapd.remove_bss(apdev[0], ifname2)
     hostapd.remove_bss(apdev[0], ifname1)
 
@@ -454,8 +453,8 @@ def test_ap_multi_bss(dev, apdev):
     """Multiple BSSes with hostapd"""
     ifname1 = apdev[0]['ifname']
     ifname2 = apdev[0]['ifname'] + '-2'
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
     dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
     dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412")
 
diff --git a/tests/hwsim/test_ap_ht.py b/tests/hwsim/test_ap_ht.py
index e66f7a9..cd52578 100644
--- a/tests/hwsim/test_ap_ht.py
+++ b/tests/hwsim/test_ap_ht.py
@@ -702,9 +702,9 @@ def test_olbc_table_limit(dev, apdev):
     ifname1 = apdev[0]['ifname']
     ifname2 = apdev[0]['ifname'] + '-2'
     ifname3 = apdev[0]['ifname'] + '-3'
-    hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
-    hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
-    hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
+    hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
+    hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
+    hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
 
     params = { "ssid": "test-olbc",
                "channel": "1",
diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py
index ed1de58..aded40b 100644
--- a/tests/hwsim/test_ap_wps.py
+++ b/tests/hwsim/test_ap_wps.py
@@ -2287,7 +2287,7 @@ def test_ap_wps_auto_setup_with_config_file(dev, apdev):
             f.write("ssid=wps\n")
             f.write("eap_server=1\n")
             f.write("wps_state=1\n")
-        hostapd.add_bss('phy3', ifname, conffile)
+        hostapd.add_bss(apdev[0], ifname, conffile)
         hapd = hostapd.Hostapd(ifname)
         hapd.request("WPS_PBC")
         dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py
index 1661b20..5fb824e 100644
--- a/tests/hwsim/utils.py
+++ b/tests/hwsim/utils.py
@@ -6,6 +6,7 @@
 
 import os
 import time
+import remotehost
 
 def get_ifnames():
     ifnames = []
@@ -80,3 +81,24 @@ def skip_with_fips(dev, reason="Not supported in FIPS mode"):
     res = dev.get_capability("fips")
     if res and 'FIPS' in res:
         raise HwsimSkip(reason)
+
+def get_phy(ap, ifname=None):
+    phy = "phy3"
+    try:
+        hostname = ap['hostname']
+    except:
+        hostname = None
+    host = remotehost.Host(hostname)
+
+    if ifname == None:
+        ifname = ap['ifname']
+    status, buf = host.execute("iw dev " + ifname + " info")
+    if status != 0:
+        raise Exception("iw " + ifname + " info failed")
+    lines = buf.split("\n")
+    for line in lines:
+        if "wiphy" in line:
+            words = line.split()
+            phy = "phy" + words[1]
+            break
+    return phy
-- 
1.9.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