]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Wait for driver scan state to clear between tests
authorJouni Malinen <j@w1.fi>
Sat, 28 Sep 2013 14:31:54 +0000 (17:31 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 28 Sep 2013 15:18:33 +0000 (18:18 +0300)
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>

tests/hwsim/wpasupplicant.py

index 6f1340bbc44f248ca0dd41e8c063fc3ce1d500e9..640d98521b009acb36a3a2d8a9022acc2b3eacc9 100644 (file)
@@ -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")