tests: Wait for driver scan state to clear between tests

cfg80211/mac80211 seems to getting stuck with scans every now and then.
Check for this special state and delay return from reset() until the
driver has stopped the scan operation. This reduces likelihood of
failing multiple test cases in a row because of a single error.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-09-28 17:31:54 +03:00
parent a771c07dfc
commit 6ca3a98bc2

View file

@ -10,6 +10,7 @@ import os
import time import time
import logging import logging
import re import re
import subprocess
import wpaspy import wpaspy
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -58,6 +59,32 @@ class WpaSupplicant:
self.request("P2P_SET per_sta_psk 0") self.request("P2P_SET per_sta_psk 0")
self.group_ifname = None self.group_ifname = None
self.dump_monitor() self.dump_monitor()
iter = 0
while iter < 60:
state = self.get_driver_status_field("scan_state")
if "SCAN_STARTED" in state or "SCAN_REQUESTED" in state:
logger.info(self.ifname + ": Waiting for scan operation to complete before continuing")
time.sleep(1)
else:
break
iter = iter + 1
if iter == 60:
logger.error(self.ifname + ": Driver scan state did not clear")
print "Trying to clear cfg80211/mac80211 scan state"
try:
cmd = ["sudo", "ifconfig", self.ifname, "down"]
subprocess.call(cmd)
except subprocess.CalledProcessError, e:
logger.info("ifconfig failed: " + str(e.returncode))
logger.info(e.output)
try:
cmd = ["sudo", "ifconfig", self.ifname, "up"]
subprocess.call(cmd)
except subprocess.CalledProcessError, e:
logger.info("ifconfig failed: " + str(e.returncode))
logger.info(e.output)
if not self.ping(): if not self.ping():
logger.info("No PING response from " + self.ifname + " after reset") logger.info("No PING response from " + self.ifname + " after reset")
@ -153,6 +180,21 @@ class WpaSupplicant:
return vals[field] return vals[field]
return None return None
def get_driver_status(self):
res = self.request("STATUS-DRIVER")
lines = res.splitlines()
vals = dict()
for l in lines:
[name,value] = l.split('=', 1)
vals[name] = value
return vals
def get_driver_status_field(self, field):
vals = self.get_driver_status()
if field in vals:
return vals[field]
return None
def p2p_dev_addr(self): def p2p_dev_addr(self):
return self.get_status_field("p2p_device_address") return self.get_status_field("p2p_device_address")