tests: Verify scan behavior
Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
1cd93ff743
commit
cf9189b94c
2 changed files with 89 additions and 1 deletions
88
tests/hwsim/test_scan.py
Normal file
88
tests/hwsim/test_scan.py
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
#
|
||||||
|
# Scanning tests
|
||||||
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
||||||
|
#
|
||||||
|
# This software may be distributed under the terms of the BSD license.
|
||||||
|
# See README for more details.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
import hostapd
|
||||||
|
|
||||||
|
def check_scan(dev, params):
|
||||||
|
dev.dump_monitor()
|
||||||
|
id = dev.request("SCAN " + params)
|
||||||
|
if "FAIL" in id:
|
||||||
|
raise Exception("Failed to start scan")
|
||||||
|
id = int(id)
|
||||||
|
|
||||||
|
ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
|
||||||
|
if ev is None:
|
||||||
|
raise Exception("Scan did not start")
|
||||||
|
if "id=" + str(id) not in ev:
|
||||||
|
raise Exception("Scan id not included in start event")
|
||||||
|
|
||||||
|
ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
|
||||||
|
if ev is None:
|
||||||
|
raise Exception("Scan did not complete")
|
||||||
|
if "id=" + str(id) not in ev:
|
||||||
|
raise Exception("Scan id not included in completed event")
|
||||||
|
|
||||||
|
def test_scan(dev, apdev):
|
||||||
|
"""Control interface behavior on scan parameters"""
|
||||||
|
hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
|
||||||
|
bssid = apdev[0]['bssid']
|
||||||
|
|
||||||
|
logger.info("Full scan")
|
||||||
|
check_scan(dev[0], "use_id=1")
|
||||||
|
|
||||||
|
logger.info("Limited channel scan")
|
||||||
|
check_scan(dev[0], "freq=2412-2462,5180 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) > 1:
|
||||||
|
raise Exception("Unexpectedly old BSS entry")
|
||||||
|
|
||||||
|
# wait long enough to allow next scans to be verified not to find the AP
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
logger.info("Passive single-channel scan")
|
||||||
|
check_scan(dev[0], "freq=2457 passive=1 use_id=1")
|
||||||
|
logger.info("Active single-channel scan")
|
||||||
|
check_scan(dev[0], "freq=2452 passive=0 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) < 2:
|
||||||
|
raise Exception("Unexpectedly updated BSS entry")
|
||||||
|
|
||||||
|
logger.info("Active single-channel scan on AP's operating channel")
|
||||||
|
check_scan(dev[0], "freq=2412 passive=0 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) > 1:
|
||||||
|
raise Exception("Unexpectedly old BSS entry")
|
||||||
|
|
||||||
|
def test_scan_only(dev, apdev):
|
||||||
|
"""Control interface behavior on scan parameters with type=only"""
|
||||||
|
hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
|
||||||
|
bssid = apdev[0]['bssid']
|
||||||
|
|
||||||
|
logger.info("Full scan")
|
||||||
|
check_scan(dev[0], "type=only use_id=1")
|
||||||
|
|
||||||
|
logger.info("Limited channel scan")
|
||||||
|
check_scan(dev[0], "type=only freq=2412-2462,5180 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) > 1:
|
||||||
|
raise Exception("Unexpectedly old BSS entry")
|
||||||
|
|
||||||
|
# wait long enough to allow next scans to be verified not to find the AP
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
logger.info("Passive single-channel scan")
|
||||||
|
check_scan(dev[0], "type=only freq=2457 passive=1 use_id=1")
|
||||||
|
logger.info("Active single-channel scan")
|
||||||
|
check_scan(dev[0], "type=only freq=2452 passive=0 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) < 2:
|
||||||
|
raise Exception("Unexpectedly updated BSS entry")
|
||||||
|
|
||||||
|
logger.info("Active single-channel scan on AP's operating channel")
|
||||||
|
check_scan(dev[0], "type=only freq=2412 passive=0 use_id=1")
|
||||||
|
if int(dev[0].get_bss(bssid)['age']) > 1:
|
||||||
|
raise Exception("Unexpectedly old BSS entry")
|
|
@ -416,7 +416,7 @@ class WpaSupplicant:
|
||||||
return self.group_form_result(ev, expect_failure, go_neg_res)
|
return self.group_form_result(ev, expect_failure, go_neg_res)
|
||||||
raise Exception("P2P_CONNECT failed")
|
raise Exception("P2P_CONNECT failed")
|
||||||
|
|
||||||
def wait_event(self, events, timeout):
|
def wait_event(self, events, timeout=10):
|
||||||
count = 0
|
count = 0
|
||||||
while count < timeout * 10:
|
while count < timeout * 10:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
|
Loading…
Reference in a new issue