]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Helper function for DISCONNECT + ABORT_SCAN + wait
authorJouni Malinen <j@w1.fi>
Sun, 17 Mar 2019 15:55:43 +0000 (17:55 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 17 Mar 2019 15:58:33 +0000 (17:58 +0200)
Use a helper function to perform this common sequence to disconnect and
stop any possibly started reconnection attempt.

Signed-off-by: Jouni Malinen <j@w1.fi>
12 files changed:
tests/hwsim/run-tests.py
tests/hwsim/test_ap_acs.py
tests/hwsim/test_ap_eap.py
tests/hwsim/test_ap_params.py
tests/hwsim/test_ap_tdls.py
tests/hwsim/test_ap_vht.py
tests/hwsim/test_ocv.py
tests/hwsim/test_rrm.py
tests/hwsim/test_wnm.py
tests/hwsim/test_wpas_ap.py
tests/hwsim/utils.py
tests/hwsim/wpasupplicant.py

index b49e9d64483a1506b6f191d6853e485fbcbc5953..717d0dfa63e1ae20a63a5d6ecc14082e34e53ccc 100755 (executable)
@@ -447,9 +447,7 @@ def main():
                 dev[0].connect("country98", key_mgmt="NONE", scan_freq="2412")
                 dev[1].request("DISCONNECT")
                 dev[0].wait_disconnected()
-                dev[0].request("DISCONNECT")
-                dev[0].request("ABORT_SCAN")
-                time.sleep(1)
+                dev[0].disconnect_and_stop_scan()
             dev[0].reset()
             dev[1].reset()
             dev[0].dump_monitor()
index 0046000d602d2820798b83498ee9a6c2bc3c65ea..2a5e1dc5f67a7318a45e1f421885d7364b9f6baf 100644 (file)
@@ -162,9 +162,7 @@ def test_ap_acs_5ghz(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -194,9 +192,7 @@ def test_ap_acs_5ghz_40mhz(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -228,9 +224,7 @@ def test_ap_acs_vht(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -264,9 +258,7 @@ def test_ap_acs_vht40(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -302,9 +294,7 @@ def test_ap_acs_vht160(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -432,9 +422,7 @@ def test_ap_acs_dfs(dev, apdev, params):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -481,9 +469,7 @@ def test_ap_acs_vht160_dfs(dev, apdev, params):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
index 32bafdcb577cfbf276e362a19d826c0190ab8892..c506fbc1b5e394c25cea8d0bd016684940577e89 100644 (file)
@@ -2034,7 +2034,7 @@ def test_ap_wpa2_eap_peap_params(dev, apdev):
     if ev and "CTRL-EVENT-CONNECTED" in ev:
         raise Exception("Unexpected connection")
     dev[0].request("REMOVE_NETWORK all")
-    dev[0].request("ABORT_SCAN")
+    dev[0].disconnect_and_stop_scan()
 
     tests = [("peap-ver0", ""),
              ("peap-ver1", ""),
index cfd39b9743948cfd5fad78cc2b5abbbb463e5e68..8e4ab8e3ba1110f8fda0c42d05311fb238cf9041 100644 (file)
@@ -131,12 +131,7 @@ def test_ap_country(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        res = dev[0].request("ABORT_SCAN")
-        for i in range(2 if "OK" in res else 1):
-                dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
-                                   "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
-        dev[0].dump_monitor()
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -438,9 +433,7 @@ def test_ap_spectrum_management_required(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
index fb74065eb75d9057d829b4241bacf1573f1ba9a7..5a639d087ca0744f87c76a98f70ed5a35eef5174 100644 (file)
@@ -362,18 +362,9 @@ def test_ap_wpa2_tdls_responder_teardown(dev, apdev):
 def tdls_clear_reg(hapd, dev):
     if hapd:
         hapd.request("DISABLE")
-    dev[0].request("DISCONNECT")
-    res0 = dev[0].request("ABORT_SCAN")
     dev[1].request("DISCONNECT")
-    res1 = dev[1].request("ABORT_SCAN")
-    for i in range(2 if "OK" in res0 else 1):
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
-                           "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
-    dev[0].dump_monitor()
-    for i in range(2 if "OK" in res1 else 1):
-        dev[1].wait_event(["CTRL-EVENT-DISCONNECTED",
-                           "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
-    dev[1].dump_monitor()
+    dev[0].disconnect_and_stop_scan()
+    dev[1].disconnect_and_stop_scan()
     subprocess.call(['iw', 'reg', 'set', '00'])
     dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
     dev[0].flush_scan_cache()
index e17b397807399f4e08a5142e710845ba14aa886e..cd98539e986f0bad5201811c654b363c16ddcc1a 100644 (file)
@@ -425,9 +425,7 @@ def test_ap_vht160(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -499,9 +497,7 @@ def test_ap_vht160b(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -579,9 +575,7 @@ def run_ap_vht160_no_dfs(dev, apdev, channel, ht_capab):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -1021,9 +1015,7 @@ def test_ap_vht80_pwr_constraint(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -1132,9 +1124,7 @@ def test_ap_vht_40_fallback_to_20(devs, apdevs):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev.request("DISCONNECT")
-        dev.request("ABORT_SCAN")
-        dev.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev.disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev.wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev.flush_scan_cache()
index 97dabedcf6190ca50682e2ab2a9ef7ce3c0e5cc1..d3ab804b5cb8ce8eed6ec1c8bd7b2816ea08caf5 100644 (file)
@@ -334,9 +334,8 @@ def run_wpa2_ocv_vht80plus80(dev, apdev):
         hapd.disable()
         for i in range(3):
             dev[i].request("DISCONNECT")
-            dev[i].request("ABORT_SCAN")
         for i in range(3):
-            dev[i].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+            dev[i].disconnect_and_stop_scan()
 
 class APConnection:
     def init_params(self):
@@ -520,9 +519,7 @@ def run_wpa2_ocv_ap_vht160_mismatch(dev, apdev):
     dev[0].dump_monitor()
     if conn.hapd:
         conn.hapd.request("DISABLE")
-    dev[0].request("DISCONNECT")
-    dev[0].request("ABORT_SCAN")
-    dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+    dev[0].disconnect_and_stop_scan()
 
 @remote_compatible
 def test_wpa2_ocv_ap_vht80plus80_mismatch(dev, apdev):
@@ -556,9 +553,7 @@ def run_wpa2_ocv_ap_vht80plus80_mismatch(dev, apdev):
     dev[0].dump_monitor()
     if conn.hapd:
         conn.hapd.request("DISABLE")
-    dev[0].request("DISCONNECT")
-    dev[0].request("ABORT_SCAN")
-    dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+    dev[0].disconnect_and_stop_scan()
 
 @remote_compatible
 def test_wpa2_ocv_ap_unexpected1(dev, apdev):
@@ -857,9 +852,7 @@ def run_wpa2_ocv_vht160_mismatch_client(dev, apdev):
     dev[0].dump_monitor()
     if conn.hapd:
         conn.hapd.request("DISABLE")
-    dev[0].request("DISCONNECT")
-    dev[0].request("ABORT_SCAN")
-    dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+    dev[0].disconnect_and_stop_scan()
 
 def test_wpa2_ocv_sta_group_hs(dev, apdev):
     """OCV group handshake (STA)"""
index 1ee4552737f2c879f1d97f5e4ceeece799303ffb..23af269d1eeda8960031ac38394ece9eb0e37a80 100644 (file)
@@ -1670,9 +1670,7 @@ def test_rrm_beacon_req_passive_scan_vht(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -1719,9 +1717,7 @@ def test_rrm_beacon_req_passive_scan_vht160(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        dev[0].request("ABORT_SCAN")
-        dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
index 952cb86cbfcac950402b1e7e36c59a717aaf8481..7baa24cff77f803001dc587b7d53eabf87e1b7b4 100644 (file)
@@ -27,12 +27,7 @@ def clear_regdom_state(dev, hapd, hapd2):
             hapd.request("DISABLE")
         if hapd2:
             hapd2.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        res = dev[0].request("ABORT_SCAN")
-        for i in range(2 if "OK" in res else 1):
-                dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
-                                   "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
-        dev[0].dump_monitor()
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
@@ -1137,14 +1132,7 @@ def stop_wnm_tm(hapd, dev):
     if hapd:
         hapd.request("DISABLE")
         time.sleep(0.1)
-    dev[0].request("DISCONNECT")
-    res = dev[0].request("ABORT_SCAN")
-    try:
-        dev[0].wait_disconnected()
-    except:
-        pass
-    if "OK" in res:
-        dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
+    dev[0].disconnect_and_stop_scan()
     subprocess.call(['iw', 'reg', 'set', '00'])
     wait_regdom_changes(dev[0])
     country = dev[0].get_driver_status_field("country")
@@ -1884,11 +1872,7 @@ def test_wnm_bss_tm_reject(dev, apdev):
     finally:
         if hapd:
             hapd.request("DISABLE")
-        dev[0].request("DISCONNECT")
-        res = dev[0].request("ABORT_SCAN")
-        for i in range(2 if "OK" in res else 1):
-                dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
-                                   "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
+        dev[0].disconnect_and_stop_scan()
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=0.5)
         dev[0].flush_scan_cache()
index b5cbc28eccf04c5b864b5c3cd9a9371e65e086f0..102edbc0d142672f3b840ba43b8044bc1a3fdf4e 100644 (file)
@@ -384,9 +384,7 @@ def _test_wpas_ap_dfs(dev):
     dev[1].connect("wpas-ap-dfs", key_mgmt="NONE")
     dev[1].wait_regdom(country_ie=True)
     dev[0].request("DISCONNECT")
-    dev[1].request("DISCONNECT")
-    dev[1].request("ABORT_SCAN")
-    dev[1].wait_disconnected()
+    dev[1].disconnect_and_stop_scan()
 
 @remote_compatible
 def test_wpas_ap_disable(dev):
index 1968d804d9aaba0235dbc877d19585ad00c63234..dbf9a18f1c80d53a2aaa474516474f1fd8373e79 100644 (file)
@@ -152,8 +152,8 @@ def clear_regdom(hapd, dev, count=1):
         time.sleep(0.1)
     for i in range(count):
         dev[i].request("DISCONNECT")
-        dev[i].request("ABORT_SCAN")
-    dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
+    for i in range(count):
+        dev[i].disconnect_and_stop_scan()
     subprocess.call(['iw', 'reg', 'set', '00'])
     wait_regdom_changes(dev[0])
     country = dev[0].get_driver_status_field("country")
index 00dec57b3a6cab759c125c44549c34d8d9c75f23..71fdb55eb7ee9511d7d9b2a6030f24079b2b4ecc 100644 (file)
@@ -1152,6 +1152,14 @@ class WpaSupplicant:
             if len(res.splitlines()) > 1:
                 logger.info("flush_scan_cache: Could not clear all BSS entries. These remain:\n" + res)
 
+    def disconnect_and_stop_scan(self):
+        self.request("DISCONNECT")
+        res = self.request("ABORT_SCAN")
+        for i in range(2 if "OK" in res else 1):
+                self.wait_event(["CTRL-EVENT-DISCONNECTED",
+                                 "CTRL-EVENT-SCAN-RESULTS"], timeout=0.5)
+        self.dump_monitor()
+
     def roam(self, bssid, fail_test=False, assoc_reject_ok=False):
         self.dump_monitor()
         if "OK" not in self.request("ROAM " + bssid):