From fa34e3255e306b3e1537310be5b3bddd12be6b83 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 25 Feb 2022 20:04:50 +0200 Subject: [PATCH] tests: Make test cases more robust by clearing scan cache explicitly This test cases can fail if previously executed tests leave older scan results in cfg80211 scan table. Clear that scan table explicitly to avoid such issues. Signed-off-by: Jouni Malinen --- tests/hwsim/test_ap_ft.py | 14 ++++++++++++++ tests/hwsim/test_ap_hs20.py | 2 ++ tests/hwsim/test_ap_params.py | 1 + tests/hwsim/test_ap_roam.py | 2 ++ tests/hwsim/test_dbus.py | 7 ++++++- tests/hwsim/test_scan.py | 1 + 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py index fb93e07f4..4167bcfc3 100644 --- a/tests/hwsim/test_ap_ft.py +++ b/tests/hwsim/test_ap_ft.py @@ -1932,6 +1932,7 @@ def test_ap_ft_gtk_rekey(dev, apdev): params['wpa_group_rekey'] = '1' hapd = hostapd.add_ap(apdev[0], params) + dev[0].flush_scan_cache() dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", ieee80211w="1", scan_freq="2412") @@ -2071,6 +2072,7 @@ def test_ap_ft_invalid_resp(dev, apdev): params = ft_params1(ssid=ssid, passphrase=passphrase) hapd0 = hostapd.add_ap(apdev[0], params) + dev[0].flush_scan_cache() dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") @@ -2148,6 +2150,7 @@ def setup_ap_ft_oom(dev, apdev): params = ft_params2(ssid=ssid, passphrase=passphrase) hapd1 = hostapd.add_ap(apdev[1], params) + dev[0].flush_scan_cache() dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") if dev[0].get_status_field('bssid') == apdev[0]['bssid']: @@ -2196,6 +2199,7 @@ def test_ap_ft_ap_oom(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") with alloc_fail(hapd0, 1, "wpa_ft_store_pmk_r0"): dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", @@ -2217,6 +2221,7 @@ def test_ap_ft_ap_oom2(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") with alloc_fail(hapd0, 1, "wpa_ft_store_pmk_r1"): dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", @@ -2241,6 +2246,7 @@ def test_ap_ft_ap_oom3(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") @@ -2291,6 +2297,7 @@ def test_ap_ft_ap_oom4(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") @@ -2323,6 +2330,7 @@ def test_ap_ft_ap_oom5(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") @@ -2385,6 +2393,7 @@ def test_ap_ft_ap_oom7a(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", ieee80211w="2", scan_freq="2412") @@ -2408,6 +2417,7 @@ def test_ap_ft_ap_oom7b(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", ieee80211w="2", scan_freq="2412") @@ -2431,6 +2441,7 @@ def test_ap_ft_ap_oom7c(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", ieee80211w="2", scan_freq="2412") @@ -2454,6 +2465,7 @@ def test_ap_ft_ap_oom7d(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", ieee80211w="2", scan_freq="2412") @@ -2477,6 +2489,7 @@ def test_ap_ft_ap_oom8(dev, apdev): hapd0 = hostapd.add_ap(apdev[0], params) bssid0 = hapd0.own_addr() + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid0, freq="2412") dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") @@ -3333,6 +3346,7 @@ def test_ap_ft_roam_rrm(dev, apdev): bssid0 = hapd0.own_addr() addr = dev[0].own_addr() + dev[0].flush_scan_cache() dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2", scan_freq="2412") check_beacon_req(hapd0, addr, 1) diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index e3cb8a4c7..c5317d1c6 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -2787,6 +2787,8 @@ def test_ap_hs20_osen_single_ssid(dev, apdev): params['hessid'] = bssid hapd = hostapd.add_ap(apdev[0], params) + dev[0].flush_scan_cache() + # RSN-OSEN (for OSU) dev[0].connect("test-hs20", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP", group="CCMP GTK_NOT_USED", diff --git a/tests/hwsim/test_ap_params.py b/tests/hwsim/test_ap_params.py index 72ac8e443..2b4c3720b 100644 --- a/tests/hwsim/test_ap_params.py +++ b/tests/hwsim/test_ap_params.py @@ -818,6 +818,7 @@ def test_ap_dtim_period(dev, apdev): params = {'ssid': ssid, 'dtim_period': "10"} hapd = hostapd.add_ap(apdev[0], params) bssid = hapd.own_addr() + dev[0].flush_scan_cache() dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") for i in range(10): dev[0].scan(freq="2412") diff --git a/tests/hwsim/test_ap_roam.py b/tests/hwsim/test_ap_roam.py index 0bc54b391..63f8fa809 100644 --- a/tests/hwsim/test_ap_roam.py +++ b/tests/hwsim/test_ap_roam.py @@ -149,6 +149,7 @@ def test_ap_reconnect_auth_timeout(dev, apdev, params): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1,force_bss_selection=1") + wpas.flush_scan_cache() params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") hapd0 = hostapd.add_ap(apdev[0], params) @@ -380,6 +381,7 @@ def test_ap_roam_signal_level_override(dev, apdev): def test_ap_roam_during_scan(dev, apdev): """Roam command during a scan operation""" hapd0 = hostapd.add_ap(apdev[0], {"ssid": "test-open"}) + dev[0].flush_scan_cache() dev[0].scan_for_bss(hapd0.own_addr(), freq=2412) dev[0].connect("test-open", key_mgmt="NONE") hapd1 = hostapd.add_ap(apdev[1], {"ssid": "test-open"}) diff --git a/tests/hwsim/test_dbus.py b/tests/hwsim/test_dbus.py index 28fb05014..fe59e1856 100644 --- a/tests/hwsim/test_dbus.py +++ b/tests/hwsim/test_dbus.py @@ -114,6 +114,8 @@ def test_dbus_getall(dev, apdev): """D-Bus GetAll""" (bus, wpas_obj, path, if_obj) = prepare_dbus(dev[0]) + dev[0].flush_scan_cache() + props = wpas_obj.GetAll(WPAS_DBUS_SERVICE, dbus_interface=dbus.PROPERTIES_IFACE) logger.debug("GetAll(fi.w1.wpa.supplicant1, /fi/w1/wpa_supplicant1) ==> " + str(props)) @@ -145,8 +147,10 @@ def test_dbus_getall(dev, apdev): res = if_obj.Get(WPAS_DBUS_IFACE, 'BSSs', dbus_interface=dbus.PROPERTIES_IFACE) - if len(res) != 1: + if len(res) < 1: raise Exception("Missing BSSs entry: " + str(res)) + if len(res) > 1: + raise Exception("Too manu BSSs entries: " + str(res)) bss_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0]) props = bss_obj.GetAll(WPAS_DBUS_BSS, dbus_interface=dbus.PROPERTIES_IFACE) logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_BSS, res[0], str(props))) @@ -621,6 +625,7 @@ def _test_dbus_wps_pbc(dev, apdev): hapd = start_ap(apdev[0]) hapd.request("WPS_PBC") bssid = apdev[0]['bssid'] + dev[0].flush_scan_cache() dev[0].scan_for_bss(bssid, freq="2412") dev[0].request("SET wps_cred_processing 2") diff --git a/tests/hwsim/test_scan.py b/tests/hwsim/test_scan.py index ccb52dc9e..c6267606e 100644 --- a/tests/hwsim/test_scan.py +++ b/tests/hwsim/test_scan.py @@ -262,6 +262,7 @@ def test_scan_bss_operations(dev, apdev): hostapd.add_ap(apdev[1], {"ssid": "test2-scan"}) bssid2 = apdev[1]['bssid'] + dev[0].flush_scan_cache() dev[0].scan(freq="2412") dev[0].scan(freq="2412") dev[0].scan(freq="2412")