tests: Simplify test_ap_bss_add_remove implementation

Use lists and loops to avoid duplicated operations.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-11-02 13:53:23 +02:00
parent 57661377df
commit 78060b25a1

View file

@ -35,57 +35,33 @@ def test_ap_change_ssid(dev, apdev):
dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new") dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new")
dev[0].connect_network(id) dev[0].connect_network(id)
def multi_check(dev, check0, check1, check2): def multi_check(dev, check):
for d in dev: id = []
d.request("BSS_FLUSH 0") for i in range(0, 3):
d.dump_monitor() dev[i].request("BSS_FLUSH 0")
dev[i].dump_monitor()
id0 = dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412", id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
wait_connect=check0) scan_freq="2412", wait_connect=check[i]))
id1 = dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412", for i in range(0, 3):
wait_connect=check1) if not check[i]:
id2 = dev[2].connect("bss-3", key_mgmt="NONE", scan_freq="2412", ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
wait_connect=check2)
if not check0:
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
if ev:
raise Exception("Unexpected connection")
if not check1:
ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
if ev:
raise Exception("Unexpected connection")
if not check2:
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
if ev: if ev:
raise Exception("Unexpected connection") raise Exception("Unexpected connection")
dev[0].remove_network(id0) for i in range(0, 3):
dev[1].remove_network(id1) dev[i].remove_network(id[i])
dev[2].remove_network(id2)
time.sleep(0.3) time.sleep(0.3)
res0 = dev[0].request("BSS RANGE=ALL MASK=0x2") res = ''
res1 = dev[1].request("BSS RANGE=ALL MASK=0x2") for i in range(0, 3):
res2 = dev[2].request("BSS RANGE=ALL MASK=0x2") res = res + dev[i].request("BSS RANGE=ALL MASK=0x2")
if not check0: for i in range(0, 3):
if ('02:00:00:00:03:00' in res0 or if not check[i]:
'02:00:00:00:03:00' in res1 or bssid = '02:00:00:00:03:0' + str(i)
'02:00:00:00:03:00' in res2): if bssid in res:
raise Exception("Unexpected BSS0 in scan results") raise Exception("Unexpected BSS" + str(i) + " in scan results")
if not check1:
if ('02:00:00:00:03:01' in res0 or
'02:00:00:00:03:01' in res1 or
'02:00:00:00:03:01' in res2):
raise Exception("Unexpected BSS1 in scan results")
if not check2:
if ('02:00:00:00:03:02' in res0 or
'02:00:00:00:03:02' in res1 or
'02:00:00:00:03:02' in res2):
raise Exception("Unexpected BSS2 in scan results")
def test_ap_bss_add_remove(dev, apdev): def test_ap_bss_add_remove(dev, apdev):
"""Dynamic BSS add/remove operations with hostapd""" """Dynamic BSS add/remove operations with hostapd"""
@ -96,68 +72,68 @@ def test_ap_bss_add_remove(dev, apdev):
ifname3 = apdev[0]['ifname'] + '-3' ifname3 = apdev[0]['ifname'] + '-3'
logger.info("Set up three BSSes one by one") logger.info("Set up three BSSes one by one")
hostapd.add_bss('phy3', ifname1, 'bss-1.conf') hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
multi_check(dev, True, False, False) multi_check(dev, [ True, False, False ])
hostapd.add_bss('phy3', ifname2, 'bss-2.conf') hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.add_bss('phy3', ifname3, 'bss-3.conf') hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove the last BSS and re-add it") logger.info("Remove the last BSS and re-add it")
hostapd.remove_bss(ifname3) hostapd.remove_bss(ifname3)
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.add_bss('phy3', ifname3, 'bss-3.conf') hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove the middle BSS and re-add it") logger.info("Remove the middle BSS and re-add it")
hostapd.remove_bss(ifname2) hostapd.remove_bss(ifname2)
multi_check(dev, True, False, True) multi_check(dev, [ True, False, True ])
hostapd.add_bss('phy3', ifname2, 'bss-2.conf') hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove the first BSS and re-add it") logger.info("Remove the first BSS and re-add it")
hostapd.remove_bss(ifname1) hostapd.remove_bss(ifname1)
multi_check(dev, False, True, True) multi_check(dev, [ False, True, True ])
hostapd.add_bss('phy3', ifname1, 'bss-1.conf') hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove two BSSes and re-add them") logger.info("Remove two BSSes and re-add them")
hostapd.remove_bss(ifname2) hostapd.remove_bss(ifname2)
multi_check(dev, True, False, True) multi_check(dev, [ True, False, True ])
hostapd.remove_bss(ifname3) hostapd.remove_bss(ifname3)
multi_check(dev, True, False, False) multi_check(dev, [ True, False, False ])
dev[0].request("NOTE failure-done") dev[0].request("NOTE failure-done")
hostapd.add_bss('phy3', ifname2, 'bss-2.conf') hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.add_bss('phy3', ifname3, 'bss-3.conf') hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove three BSSes and re-add them") logger.info("Remove three BSSes and re-add them")
hostapd.remove_bss(ifname1) hostapd.remove_bss(ifname1)
multi_check(dev, False, True, True) multi_check(dev, [ False, True, True ])
hostapd.remove_bss(ifname2) hostapd.remove_bss(ifname2)
multi_check(dev, False, False, True) multi_check(dev, [ False, False, True ])
hostapd.remove_bss(ifname3) hostapd.remove_bss(ifname3)
multi_check(dev, False, False, False) multi_check(dev, [ False, False, False ])
hostapd.add_bss('phy3', ifname1, 'bss-1.conf') hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
multi_check(dev, True, False, False) multi_check(dev, [ True, False, False ])
hostapd.add_bss('phy3', ifname2, 'bss-2.conf') hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.add_bss('phy3', ifname3, 'bss-3.conf') hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Remove three BSSes in reverse order and re-add them") logger.info("Remove three BSSes in reverse order and re-add them")
hostapd.remove_bss(ifname3) hostapd.remove_bss(ifname3)
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.remove_bss(ifname2) hostapd.remove_bss(ifname2)
multi_check(dev, True, False, False) multi_check(dev, [ True, False, False ])
hostapd.remove_bss(ifname1) hostapd.remove_bss(ifname1)
hostapd.add_bss('phy3', ifname1, 'bss-1.conf') hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
multi_check(dev, True, False, False) multi_check(dev, [ True, False, False ])
hostapd.add_bss('phy3', ifname2, 'bss-2.conf') hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
multi_check(dev, True, True, False) multi_check(dev, [ True, True, False ])
hostapd.add_bss('phy3', ifname3, 'bss-3.conf') hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])
logger.info("Test error handling if a duplicate ifname is tried") 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('phy3', ifname3, 'bss-3.conf', ignore_error=True)
multi_check(dev, True, True, True) multi_check(dev, [ True, True, True ])