From 6ca3a98bc2c9e298a738e0690b8654281fafdb85 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 28 Sep 2013 17:31:54 +0300 Subject: [PATCH] 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 --- tests/hwsim/wpasupplicant.py | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 6f1340bbc..640d98521 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -10,6 +10,7 @@ import os import time import logging import re +import subprocess import wpaspy logger = logging.getLogger(__name__) @@ -58,6 +59,32 @@ class WpaSupplicant: self.request("P2P_SET per_sta_psk 0") self.group_ifname = None 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(): logger.info("No PING response from " + self.ifname + " after reset") @@ -153,6 +180,21 @@ class WpaSupplicant: return vals[field] 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): return self.get_status_field("p2p_device_address")