From e01a492caa70631e7d67b6682a05345883d58992 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 17 Mar 2019 17:55:43 +0200 Subject: [PATCH] tests: Helper function for DISCONNECT + ABORT_SCAN + wait Use a helper function to perform this common sequence to disconnect and stop any possibly started reconnection attempt. Signed-off-by: Jouni Malinen --- tests/hwsim/run-tests.py | 4 +--- tests/hwsim/test_ap_acs.py | 28 +++++++--------------------- tests/hwsim/test_ap_eap.py | 2 +- tests/hwsim/test_ap_params.py | 11 ++--------- tests/hwsim/test_ap_tdls.py | 13 ++----------- tests/hwsim/test_ap_vht.py | 20 +++++--------------- tests/hwsim/test_ocv.py | 15 ++++----------- tests/hwsim/test_rrm.py | 8 ++------ tests/hwsim/test_wnm.py | 22 +++------------------- tests/hwsim/test_wpas_ap.py | 4 +--- tests/hwsim/utils.py | 4 ++-- tests/hwsim/wpasupplicant.py | 8 ++++++++ 12 files changed, 38 insertions(+), 101 deletions(-) diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index b49e9d644..717d0dfa6 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -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() diff --git a/tests/hwsim/test_ap_acs.py b/tests/hwsim/test_ap_acs.py index 0046000d6..2a5e1dc5f 100644 --- a/tests/hwsim/test_ap_acs.py +++ b/tests/hwsim/test_ap_acs.py @@ -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() diff --git a/tests/hwsim/test_ap_eap.py b/tests/hwsim/test_ap_eap.py index 32bafdcb5..c506fbc1b 100644 --- a/tests/hwsim/test_ap_eap.py +++ b/tests/hwsim/test_ap_eap.py @@ -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", ""), diff --git a/tests/hwsim/test_ap_params.py b/tests/hwsim/test_ap_params.py index cfd39b974..8e4ab8e3b 100644 --- a/tests/hwsim/test_ap_params.py +++ b/tests/hwsim/test_ap_params.py @@ -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() diff --git a/tests/hwsim/test_ap_tdls.py b/tests/hwsim/test_ap_tdls.py index fb74065eb..5a639d087 100644 --- a/tests/hwsim/test_ap_tdls.py +++ b/tests/hwsim/test_ap_tdls.py @@ -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() diff --git a/tests/hwsim/test_ap_vht.py b/tests/hwsim/test_ap_vht.py index e17b39780..cd98539e9 100644 --- a/tests/hwsim/test_ap_vht.py +++ b/tests/hwsim/test_ap_vht.py @@ -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() diff --git a/tests/hwsim/test_ocv.py b/tests/hwsim/test_ocv.py index 97dabedcf..d3ab804b5 100644 --- a/tests/hwsim/test_ocv.py +++ b/tests/hwsim/test_ocv.py @@ -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)""" diff --git a/tests/hwsim/test_rrm.py b/tests/hwsim/test_rrm.py index 1ee455273..23af269d1 100644 --- a/tests/hwsim/test_rrm.py +++ b/tests/hwsim/test_rrm.py @@ -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() diff --git a/tests/hwsim/test_wnm.py b/tests/hwsim/test_wnm.py index 952cb86cb..7baa24cff 100644 --- a/tests/hwsim/test_wnm.py +++ b/tests/hwsim/test_wnm.py @@ -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() diff --git a/tests/hwsim/test_wpas_ap.py b/tests/hwsim/test_wpas_ap.py index b5cbc28ec..102edbc0d 100644 --- a/tests/hwsim/test_wpas_ap.py +++ b/tests/hwsim/test_wpas_ap.py @@ -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): diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py index 1968d804d..dbf9a18f1 100644 --- a/tests/hwsim/utils.py +++ b/tests/hwsim/utils.py @@ -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") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 00dec57b3..71fdb55eb 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -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):