From: Jouni Malinen Date: Wed, 7 Jan 2015 12:19:30 +0000 (+0200) Subject: tests: Convert test skipping to use exception X-Git-Tag: hostap_2_4~501 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81e787b7501a1cd21c661b7ddb7166eb1fafab35;p=thirdparty%2Fhostap.git tests: Convert test skipping to use exception Instead of returning "skip" from the test function, raise the new HwsimSkip exception to indicate a test case was skipped. Signed-off-by: Jouni Malinen --- diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index 7a6d60e31..7556abd59 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -433,15 +433,12 @@ def main(): params = {} params['logdir'] = args.logdir params['long'] = args.long - res = t(dev, apdev, params) + t(dev, apdev, params) elif t.func_code.co_argcount > 1: - res = t(dev, apdev) + t(dev, apdev) else: - res = t(dev) - if res == "skip": - result = "SKIP" - else: - result = "PASS" + t(dev) + result = "PASS" except HwsimSkip, e: logger.info("Skip test case: %s" % e) result = "SKIP" diff --git a/tests/hwsim/test_ap_ciphers.py b/tests/hwsim/test_ap_ciphers.py index 01b5d456c..60dc64bd8 100644 --- a/tests/hwsim/test_ap_ciphers.py +++ b/tests/hwsim/test_ap_ciphers.py @@ -11,10 +11,11 @@ import os.path import hwsim_utils import hostapd +from utils import HwsimSkip def check_cipher(dev, ap, cipher): if cipher not in dev.get_capability("pairwise"): - return "skip" + raise HwsimSkip("Cipher %s not supported" % cipher) params = { "ssid": "test-wpa2-psk", "wpa_passphrase": "12345678", "wpa": "2", @@ -27,13 +28,13 @@ def check_cipher(dev, ap, cipher): def test_ap_cipher_tkip(dev, apdev): """WPA2-PSK/TKIP connection""" - return check_cipher(dev[0], apdev[0], "TKIP") + check_cipher(dev[0], apdev[0], "TKIP") def test_ap_cipher_tkip_countermeasures_ap(dev, apdev): """WPA-PSK/TKIP countermeasures (detected by AP)""" testfile = "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (dev[0].get_driver_status_field("phyname"), dev[0].ifname) if not os.path.exists(testfile): - return "skip" + raise HwsimSkip("tkip_mic_test not supported in mac80211") params = { "ssid": "tkip-countermeasures", "wpa_passphrase": "12345678", @@ -73,7 +74,7 @@ def test_ap_cipher_tkip_countermeasures_sta(dev, apdev): testfile = "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd.get_driver_status_field("phyname"), apdev[0]['ifname']) if not os.path.exists(testfile): - return "skip" + raise HwsimSkip("tkip_mic_test not supported in mac80211") dev[0].connect("tkip-countermeasures", psk="12345678", pairwise="TKIP", group="TKIP", scan_freq="2412") @@ -97,19 +98,19 @@ def test_ap_cipher_tkip_countermeasures_sta(dev, apdev): def test_ap_cipher_ccmp(dev, apdev): """WPA2-PSK/CCMP connection""" - return check_cipher(dev[0], apdev[0], "CCMP") + check_cipher(dev[0], apdev[0], "CCMP") def test_ap_cipher_gcmp(dev, apdev): """WPA2-PSK/GCMP connection""" - return check_cipher(dev[0], apdev[0], "GCMP") + check_cipher(dev[0], apdev[0], "GCMP") def test_ap_cipher_ccmp_256(dev, apdev): """WPA2-PSK/CCMP-256 connection""" - return check_cipher(dev[0], apdev[0], "CCMP-256") + check_cipher(dev[0], apdev[0], "CCMP-256") def test_ap_cipher_gcmp_256(dev, apdev): """WPA2-PSK/GCMP-256 connection""" - return check_cipher(dev[0], apdev[0], "GCMP-256") + check_cipher(dev[0], apdev[0], "GCMP-256") def test_ap_cipher_mixed_wpa_wpa2(dev, apdev): """WPA2-PSK/CCMP/ and WPA-PSK/TKIP mixed configuration""" diff --git a/tests/hwsim/test_ap_csa.py b/tests/hwsim/test_ap_csa.py index ebf926fb1..c88e517e1 100644 --- a/tests/hwsim/test_ap_csa.py +++ b/tests/hwsim/test_ap_csa.py @@ -10,6 +10,7 @@ logger = logging.getLogger() import hwsim_utils import hostapd +from utils import HwsimSkip def connect(dev, apdev): params = { "ssid": "ap-csa", @@ -31,12 +32,12 @@ def switch_channel(ap, count, freq): # WpaSupplicant or Hostapd supports CSA. def csa_supported(dev): res = dev.get_driver_status() - return (int(res['capa.flags'], 0) & 0x80000000) != 0 + if (int(res['capa.flags'], 0) & 0x80000000) == 0: + raise HwsimSkip("CSA not supported") def test_ap_csa_1_switch(dev, apdev): """AP Channel Switch, one switch""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -45,8 +46,7 @@ def test_ap_csa_1_switch(dev, apdev): def test_ap_csa_2_switches(dev, apdev): """AP Channel Switch, two switches""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -57,8 +57,7 @@ def test_ap_csa_2_switches(dev, apdev): def test_ap_csa_1_switch_count_0(dev, apdev): """AP Channel Switch, one switch with count 0""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -68,8 +67,7 @@ def test_ap_csa_1_switch_count_0(dev, apdev): def test_ap_csa_2_switches_count_0(dev, apdev): """AP Channel Switch, two switches with count 0""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -82,8 +80,7 @@ def test_ap_csa_2_switches_count_0(dev, apdev): def test_ap_csa_1_switch_count_1(dev, apdev): """AP Channel Switch, one switch with count 1""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -93,8 +90,7 @@ def test_ap_csa_1_switch_count_1(dev, apdev): def test_ap_csa_2_switches_count_1(dev, apdev): """AP Channel Switch, two switches with count 1""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) @@ -107,8 +103,7 @@ def test_ap_csa_2_switches_count_1(dev, apdev): def test_ap_csa_1_switch_count_2(dev, apdev): """AP Channel Switch, one switch with count 2""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) ap = connect(dev[0], apdev) hwsim_utils.test_connectivity(dev[0], ap) diff --git a/tests/hwsim/test_ap_eap.py b/tests/hwsim/test_ap_eap.py index 5fe99eb10..700130a9f 100644 --- a/tests/hwsim/test_ap_eap.py +++ b/tests/hwsim/test_ap_eap.py @@ -15,8 +15,13 @@ import os import hwsim_utils import hostapd +from utils import HwsimSkip from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations +def check_hlr_auc_gw_support(): + if not os.path.exists("/tmp/hlr_auc_gw.sock"): + raise HwsimSkip("No hlr_auc_gw available") + def read_pem(fname): with open(fname, "r") as f: lines = f.readlines() @@ -103,9 +108,7 @@ def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False): def test_ap_wpa2_eap_sim(dev, apdev): """WPA2-Enterprise connection using EAP-SIM""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") hapd = hostapd.add_ap(apdev[0]['ifname'], params) eap_connect(dev[0], apdev[0], "SIM", "1232010000000000", @@ -156,13 +159,11 @@ def test_ap_wpa2_eap_sim(dev, apdev): def test_ap_wpa2_eap_sim_sql(dev, apdev, params): """WPA2-Enterprise connection using EAP-SIM (SQL)""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() try: import sqlite3 except ImportError: - return "skip" + raise HwsimSkip("No sqlite3 module available") con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['auth_server_port'] = "1814" @@ -248,14 +249,12 @@ def test_ap_wpa2_eap_sim_config(dev, apdev): def test_ap_wpa2_eap_sim_ext(dev, apdev): """WPA2-Enterprise connection using EAP-SIM and external GSM auth""" try: - return _test_ap_wpa2_eap_sim_ext(dev, apdev) + _test_ap_wpa2_eap_sim_ext(dev, apdev) finally: dev[0].request("SET external_sim 0") def _test_ap_wpa2_eap_sim_ext(dev, apdev): - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") hostapd.add_ap(apdev[0]['ifname'], params) dev[0].request("SET external_sim 1") @@ -380,9 +379,7 @@ def _test_ap_wpa2_eap_sim_ext(dev, apdev): def test_ap_wpa2_eap_aka(dev, apdev): """WPA2-Enterprise connection using EAP-AKA""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") hapd = hostapd.add_ap(apdev[0]['ifname'], params) eap_connect(dev[0], apdev[0], "AKA", "0232010000000000", @@ -436,13 +433,11 @@ def test_ap_wpa2_eap_aka(dev, apdev): def test_ap_wpa2_eap_aka_sql(dev, apdev, params): """WPA2-Enterprise connection using EAP-AKA (SQL)""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() try: import sqlite3 except ImportError: - return "skip" + raise HwsimSkip("No sqlite3 module available") con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['auth_server_port'] = "1814" @@ -505,14 +500,12 @@ def test_ap_wpa2_eap_aka_config(dev, apdev): def test_ap_wpa2_eap_aka_ext(dev, apdev): """WPA2-Enterprise connection using EAP-AKA and external UMTS auth""" try: - return _test_ap_wpa2_eap_aka_ext(dev, apdev) + _test_ap_wpa2_eap_aka_ext(dev, apdev) finally: dev[0].request("SET external_sim 0") def _test_ap_wpa2_eap_aka_ext(dev, apdev): - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") hostapd.add_ap(apdev[0]['ifname'], params) dev[0].request("SET external_sim 1") @@ -680,9 +673,7 @@ def _test_ap_wpa2_eap_aka_ext(dev, apdev): def test_ap_wpa2_eap_aka_prime(dev, apdev): """WPA2-Enterprise connection using EAP-AKA'""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") hapd = hostapd.add_ap(apdev[0]['ifname'], params) eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111", @@ -705,13 +696,11 @@ def test_ap_wpa2_eap_aka_prime(dev, apdev): def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params): """WPA2-Enterprise connection using EAP-AKA' (SQL)""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() try: import sqlite3 except ImportError: - return "skip" + raise HwsimSkip("No sqlite3 module available") con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db")) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['auth_server_port'] = "1814" @@ -2064,9 +2053,7 @@ def test_ap_wpa2_eap_request_identity_message(dev, apdev): def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev): """WPA2-Enterprise using EAP-SIM/AKA and protected result indication""" - if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return "skip" + check_hlr_auc_gw_support() params = int_eap_server_params() params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock" params['eap_sim_aka_result_ind'] = "1" @@ -2142,7 +2129,7 @@ def test_ap_wpa2_eap_sql(dev, apdev, params): try: import sqlite3 except ImportError: - return "skip" + raise HwsimSkip("No sqlite3 module available") dbfile = os.path.join(params['logdir'], "eap-user.db") try: os.remove(dbfile) @@ -2301,11 +2288,9 @@ def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params): get_key_locations(buf, msk, "MSK") get_key_locations(buf, emsk, "EMSK") if password not in buf: - print("Password not found while associated") - return "skip" + raise HwsimSkip("Password not found while associated") if pmk not in buf: - print("PMK not found while associated") - return "skip" + raise HwsimSkip("PMK not found while associated") if kck not in buf: raise Exception("KCK not found while associated") if kek not in buf: diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py index 6ec0e97c7..b00126269 100644 --- a/tests/hwsim/test_ap_ft.py +++ b/tests/hwsim/test_ap_ft.py @@ -13,6 +13,7 @@ logger = logging.getLogger() import hwsim_utils import hostapd +from utils import HwsimSkip from wlantest import Wlantest from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations @@ -514,14 +515,11 @@ def test_ft_psk_key_lifetime_in_memory(dev, apdev, params): get_key_locations(buf, pmkr0, "PMK-R0") get_key_locations(buf, pmkr1, "PMK-R1") if pmk not in buf: - print("PMK not found while associated") - return "skip" + raise HwsimSkip("PMK not found while associated") if pmkr0 not in buf: - print("PMK-R0 not found while associated") - return "skip" + raise HwsimSkip("PMK-R0 not found while associated") if pmkr1 not in buf: - print("PMK-R1 not found while associated") - return "skip" + raise HwsimSkip("PMK-R1 not found while associated") if kck not in buf: raise Exception("KCK not found while associated") if kek not in buf: diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index 804e9d02f..2172c3d2f 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -16,6 +16,7 @@ import socket import subprocess import hostapd +from utils import HwsimSkip import hwsim_utils from wlantest import Wlantest from wpasupplicant import WpaSupplicant @@ -95,12 +96,9 @@ def check_sp_type(dev, sp_type): def hlr_auc_gw_available(): if not os.path.exists("/tmp/hlr_auc_gw.sock"): - logger.info("No hlr_auc_gw available"); - return False + raise HwsimSkip("No hlr_auc_gw socket available") if not os.path.exists("../../hostapd/hlr_auc_gw"): - logger.info("No hlr_auc_gw available"); - return False - return True + raise HwsimSkip("No hlr_auc_gw available") def interworking_ext_sim_connect(dev, bssid, method): dev.request("INTERWORKING_CONNECT " + bssid) @@ -275,7 +273,7 @@ def test_ap_nai_home_realm_query(dev, apdev): def test_ap_interworking_scan_filtering(dev, apdev): """Interworking scan filtering with HESSID and access network type""" try: - return _test_ap_interworking_scan_filtering(dev, apdev) + _test_ap_interworking_scan_filtering(dev, apdev) finally: dev[0].request("SET hessid 00:00:00:00:00:00") dev[0].request("SET access_network_type 15") @@ -411,8 +409,7 @@ def hs20_simulated_sim(dev, ap, method): def test_ap_hs20_sim(dev, apdev): """Hotspot 2.0 with simulated SIM and EAP-SIM""" - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() hs20_simulated_sim(dev[0], apdev[0], "SIM") dev[0].request("INTERWORKING_SELECT auto freq=2412") ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15) @@ -421,20 +418,17 @@ def test_ap_hs20_sim(dev, apdev): def test_ap_hs20_aka(dev, apdev): """Hotspot 2.0 with simulated USIM and EAP-AKA""" - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() hs20_simulated_sim(dev[0], apdev[0], "AKA") def test_ap_hs20_aka_prime(dev, apdev): """Hotspot 2.0 with simulated USIM and EAP-AKA'""" - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() hs20_simulated_sim(dev[0], apdev[0], "AKA'") def test_ap_hs20_ext_sim(dev, apdev): """Hotspot 2.0 with external SIM processing""" - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() bssid = apdev[0]['bssid'] params = hs20_ap_params() params['hessid'] = bssid @@ -454,8 +448,7 @@ def test_ap_hs20_ext_sim(dev, apdev): def test_ap_hs20_ext_sim_roaming(dev, apdev): """Hotspot 2.0 with external SIM processing in roaming network""" - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() bssid = apdev[0]['bssid'] params = hs20_ap_params() params['hessid'] = bssid @@ -1274,13 +1267,12 @@ def test_ap_hs20_max_bss_load2(dev, apdev): def test_ap_hs20_multi_cred_sp_prio(dev, apdev): """Hotspot 2.0 multi-cred sp_priority""" try: - return _test_ap_hs20_multi_cred_sp_prio(dev, apdev) + _test_ap_hs20_multi_cred_sp_prio(dev, apdev) finally: dev[0].request("SET external_sim 0") def _test_ap_hs20_multi_cred_sp_prio(dev, apdev): - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() bssid = apdev[0]['bssid'] params = hs20_ap_params() params['hessid'] = bssid @@ -1317,13 +1309,12 @@ def _test_ap_hs20_multi_cred_sp_prio(dev, apdev): def test_ap_hs20_multi_cred_sp_prio2(dev, apdev): """Hotspot 2.0 multi-cred sp_priority with two BSSes""" try: - return _test_ap_hs20_multi_cred_sp_prio2(dev, apdev) + _test_ap_hs20_multi_cred_sp_prio2(dev, apdev) finally: dev[0].request("SET external_sim 0") def _test_ap_hs20_multi_cred_sp_prio2(dev, apdev): - if not hlr_auc_gw_available(): - return "skip" + hlr_auc_gw_available() bssid = apdev[0]['bssid'] params = hs20_ap_params() params['hessid'] = bssid @@ -2180,7 +2171,7 @@ def test_ap_hs20_remediation_sql(dev, apdev, params): try: import sqlite3 except ImportError: - return "skip" + raise HwsimSkip("No sqlite3 module available") dbfile = os.path.join(params['logdir'], "eap-user.db") try: os.remove(dbfile) @@ -2342,8 +2333,7 @@ def _test_ap_hs20_proxyarp(dev, apdev): hapd.enable() except: # For now, do not report failures due to missing kernel support - logger.info("Could not start hostapd - assume proxyarp not supported in kernel version") - return "skip" + raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) if ev is None: raise Exception("AP startup timed out") @@ -2413,17 +2403,14 @@ def _test_ap_hs20_proxyarp(dev, apdev): def test_ap_hs20_proxyarp(dev, apdev): """Hotspot 2.0 and ProxyARP""" - res = None try: - res = _test_ap_hs20_proxyarp(dev, apdev) + _test_ap_hs20_proxyarp(dev, apdev) finally: subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], stderr=open('/dev/null', 'w')) subprocess.call(['brctl', 'delbr', 'ap-br0'], stderr=open('/dev/null', 'w')) - return res - def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled): bssid = apdev[0]['bssid'] params = hs20_ap_params() @@ -2437,8 +2424,7 @@ def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled): hapd.enable() except: # For now, do not report failures due to missing kernel support - logger.info("Could not start hostapd - assume proxyarp not supported in kernel version") - return "skip" + raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") ev = hapd.wait_event(["AP-ENABLED"], timeout=10) if ev is None: raise Exception("AP startup timed out") @@ -2512,30 +2498,24 @@ def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled): def test_ap_hs20_proxyarp_disable_dgaf(dev, apdev): """Hotspot 2.0 and ProxyARP with DGAF disabled""" - res = None try: - res = _test_ap_hs20_proxyarp_dgaf(dev, apdev, True) + _test_ap_hs20_proxyarp_dgaf(dev, apdev, True) finally: subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], stderr=open('/dev/null', 'w')) subprocess.call(['brctl', 'delbr', 'ap-br0'], stderr=open('/dev/null', 'w')) - return res - def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev): """Hotspot 2.0 and ProxyARP with DGAF enabled""" - res = None try: - res = _test_ap_hs20_proxyarp_dgaf(dev, apdev, False) + _test_ap_hs20_proxyarp_dgaf(dev, apdev, False) finally: subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], stderr=open('/dev/null', 'w')) subprocess.call(['brctl', 'delbr', 'ap-br0'], stderr=open('/dev/null', 'w')) - return res - def ip_checksum(buf): sum = 0 if len(buf) & 0x01: @@ -2787,8 +2767,7 @@ def _test_proxyarp_open(dev, apdev, params): hapd.enable() except: # For now, do not report failures due to missing kernel support - logger.info("Could not start hostapd - assume proxyarp not supported in kernel version") - return "skip" + raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) if ev is None: raise Exception("AP startup timed out") @@ -3046,9 +3025,8 @@ def _test_proxyarp_open(dev, apdev, params): def test_proxyarp_open(dev, apdev, params): """ProxyARP with open network""" - res = None try: - res = _test_proxyarp_open(dev, apdev, params) + _test_proxyarp_open(dev, apdev, params) finally: try: subprocess.call(['ebtables', '-F', 'FORWARD']) @@ -3059,5 +3037,3 @@ def test_proxyarp_open(dev, apdev, params): stderr=open('/dev/null', 'w')) subprocess.call(['brctl', 'delbr', 'ap-br0'], stderr=open('/dev/null', 'w')) - - return res diff --git a/tests/hwsim/test_ap_ht.py b/tests/hwsim/test_ap_ht.py index 539413adf..f300efc7e 100644 --- a/tests/hwsim/test_ap_ht.py +++ b/tests/hwsim/test_ap_ht.py @@ -11,6 +11,7 @@ import struct import subprocess import hostapd +from utils import HwsimSkip import hwsim_utils from test_ap_csa import csa_supported @@ -630,8 +631,7 @@ def test_ap_ht_40mhz_intolerant_ap(dev, apdev): def test_ap_ht40_csa(dev, apdev): """HT with 40 MHz channel width and CSA""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) try: hapd = None params = { "ssid": "ht", @@ -675,8 +675,7 @@ def test_ap_ht40_csa(dev, apdev): def test_ap_ht40_csa2(dev, apdev): """HT with 40 MHz channel width and CSA""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) try: hapd = None params = { "ssid": "ht", @@ -720,8 +719,7 @@ def test_ap_ht40_csa2(dev, apdev): def test_ap_ht40_csa3(dev, apdev): """HT with 40 MHz channel width and CSA""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) try: hapd = None params = { "ssid": "ht", @@ -769,8 +767,7 @@ def test_ap_ht_smps(dev, apdev): try: hapd = hostapd.add_ap(apdev[0]['ifname'], params) except: - logger.info("Assume mac80211_hwsim was not recent enough to support SMPS") - return "skip" + raise HwsimSkip("Assume mac80211_hwsim was not recent enough to support SMPS") params = { "ssid": "ht2", "ht_capab": "[SMPS-DYNAMIC]" } hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) diff --git a/tests/hwsim/test_ap_psk.py b/tests/hwsim/test_ap_psk.py index 5baa7a379..e8806bf26 100644 --- a/tests/hwsim/test_ap_psk.py +++ b/tests/hwsim/test_ap_psk.py @@ -16,6 +16,7 @@ import subprocess import time import hostapd +from utils import HwsimSkip import hwsim_utils def check_mib(dev, vals): @@ -940,8 +941,7 @@ def test_wpa2_psk_key_lifetime_in_memory(dev, apdev, params): logger.info("Checking keys in memory while associated") get_key_locations(buf, pmk, "PMK") if pmk not in buf: - print("PMK not found while associated") - return "skip" + raise HwsimSkip("PMK not found while associated") if kck not in buf: raise Exception("KCK not found while associated") if kek not in buf: diff --git a/tests/hwsim/test_ap_qosmap.py b/tests/hwsim/test_ap_qosmap.py index 7a1f8a65e..67604b234 100644 --- a/tests/hwsim/test_ap_qosmap.py +++ b/tests/hwsim/test_ap_qosmap.py @@ -11,6 +11,7 @@ logger = logging.getLogger() import hwsim_utils import hostapd +from utils import HwsimSkip from wlantest import Wlantest def check_qos_map(ap, hapd, dev, sta, dscp, tid, ap_tid=None): @@ -36,7 +37,7 @@ def test_ap_qosmap(dev, apdev): """QoS mapping""" drv_flags = dev[0].get_driver_status_field("capa.flags") if int(drv_flags, 0) & 0x40000000 == 0: - return "skip" + raise HwsimSkip("Driver does not support QoS Map") ssid = "test-qosmap" params = { "ssid": ssid } params['qos_map_set'] = '53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55' diff --git a/tests/hwsim/test_ap_tdls.py b/tests/hwsim/test_ap_tdls.py index e1bb76e69..64ed7db12 100644 --- a/tests/hwsim/test_ap_tdls.py +++ b/tests/hwsim/test_ap_tdls.py @@ -13,6 +13,7 @@ import hwsim_utils from hostapd import HostapdGlobal from hostapd import Hostapd import hostapd +from utils import HwsimSkip from wlantest import Wlantest def start_ap_wpa2_psk(ifname): @@ -363,8 +364,7 @@ def test_tdls_chan_switch(dev, apdev): """Open AP and two stations using TDLS""" flags = int(dev[0].get_driver_status_field('capa.flags'), 16) if flags & 0x800000000 == 0: - logger.info("Driver does not support TDLS channel switching") - return "skip" + raise HwsimSkip("Driver does not support TDLS channel switching") hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" }) connect_2sta_open(dev, hapd) diff --git a/tests/hwsim/test_ap_vht.py b/tests/hwsim/test_ap_vht.py index 235508ecc..e59ec2e33 100644 --- a/tests/hwsim/test_ap_vht.py +++ b/tests/hwsim/test_ap_vht.py @@ -12,6 +12,7 @@ import subprocess, time import hwsim_utils import hostapd +from utils import HwsimSkip from test_dfs import wait_dfs_event from test_ap_csa import csa_supported @@ -42,8 +43,7 @@ def test_ap_vht80(dev, apdev): except Exception, e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): - logger.info("80 MHz channel not supported in regulatory information") - return "skip" + raise HwsimSkip("80 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") @@ -82,8 +82,7 @@ def test_ap_vht80_params(dev, apdev): except Exception, e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): - logger.info("80 MHz channel not supported in regulatory information") - return "skip" + raise HwsimSwkip("80 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") @@ -202,7 +201,7 @@ def test_ap_vht160(dev, apdev): # Not all systems have recent enough CRDA version and # wireless-regdb changes to support 160 MHz and DFS. For now, # do not report failures for this test case. - return "skip" + raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz") raise Exception("Unexpected interface state: " + state) params = { "ssid": "vht2", @@ -277,8 +276,7 @@ def test_ap_vht160(dev, apdev): except Exception, e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): - logger.info("80/160 MHz channel not supported in regulatory information") - return "skip" + raise HwsimSkip("80/160 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") @@ -347,8 +345,7 @@ def test_ap_vht80plus80(dev, apdev): except Exception, e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): - logger.info("80/160 MHz channel not supported in regulatory information") - return "skip" + raise HwsimSkip("80/160 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") @@ -363,8 +360,7 @@ def test_ap_vht80plus80(dev, apdev): def test_ap_vht80_csa(dev, apdev): """VHT with 80 MHz channel width and CSA""" - if not csa_supported(dev[0]): - return "skip" + csa_supported(dev[0]) try: hapd = None params = { "ssid": "vht", @@ -406,8 +402,7 @@ def test_ap_vht80_csa(dev, apdev): except Exception, e: if isinstance(e, Exception) and str(e) == "AP startup failed": if not vht_supported(): - logger.info("80 MHz channel not supported in regulatory information") - return "skip" + raise HwsimSkip("80 MHz channel not supported in regulatory information") raise finally: dev[0].request("DISCONNECT") diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index 70ef48f54..59f12b524 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -20,6 +20,7 @@ import StringIO import hwsim_utils import hostapd from wpasupplicant import WpaSupplicant +from utils import HwsimSkip def test_ap_wps_init(dev, apdev): """Initial AP configuration with first WPS Enrollee""" @@ -1569,8 +1570,7 @@ def test_ap_wps_auto_setup_with_config_file(dev, apdev): def test_ap_wps_pbc_timeout(dev, apdev, params): """wpa_supplicant PBC walk time [long]""" if not params['long']: - logger.info("Skip test case with long duration due to --long not specified") - return "skip" + raise HwsimSkip("Skip test case with long duration due to --long not specified") ssid = "test-wps" hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) diff --git a/tests/hwsim/test_dbus.py b/tests/hwsim/test_dbus.py index f5038607e..b7f50bd41 100644 --- a/tests/hwsim/test_dbus.py +++ b/tests/hwsim/test_dbus.py @@ -298,7 +298,7 @@ def test_dbus_invalid_method(dev, apdev): def test_dbus_get_set_wps(dev, apdev): """D-Bus Get/Set for WPS properties""" try: - return _test_dbus_get_set_wps(dev, apdev) + _test_dbus_get_set_wps(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") dev[0].request("SET config_methods display keypad virtual_display nfc_interface") @@ -427,7 +427,7 @@ def test_dbus_wps_invalid(dev, apdev): def test_dbus_wps_pbc(dev, apdev): """D-Bus WPS/PBC operation and signals""" try: - return _test_dbus_wps_pbc(dev, apdev) + _test_dbus_wps_pbc(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -490,7 +490,7 @@ def _test_dbus_wps_pbc(dev, apdev): def test_dbus_wps_pin(dev, apdev): """D-Bus WPS/PIN operation and signals""" try: - return _test_dbus_wps_pin(dev, apdev) + _test_dbus_wps_pin(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -551,7 +551,7 @@ def _test_dbus_wps_pin(dev, apdev): def test_dbus_wps_pin2(dev, apdev): """D-Bus WPS/PIN operation and signals (PIN from wpa_supplicant)""" try: - return _test_dbus_wps_pin2(dev, apdev) + _test_dbus_wps_pin2(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -614,7 +614,7 @@ def _test_dbus_wps_pin2(dev, apdev): def test_dbus_wps_pin_m2d(dev, apdev): """D-Bus WPS/PIN operation and signals with M2D""" try: - return _test_dbus_wps_pin_m2d(dev, apdev) + _test_dbus_wps_pin_m2d(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -677,7 +677,7 @@ def _test_dbus_wps_pin_m2d(dev, apdev): def test_dbus_wps_reg(dev, apdev): """D-Bus WPS/Registrar operation and signals""" try: - return _test_dbus_wps_reg(dev, apdev) + _test_dbus_wps_reg(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -1460,7 +1460,7 @@ def test_dbus_pkcs11(dev, apdev): def test_dbus_apscan(dev, apdev): """D-Bus Get/Set ApScan""" try: - return _test_dbus_apscan(dev, apdev) + _test_dbus_apscan(dev, apdev) finally: dev[0].request("AP_SCAN 1") @@ -1585,7 +1585,7 @@ def test_dbus_bss_expire(dev, apdev): def test_dbus_country(dev, apdev): """D-Bus Get/Set Country""" try: - return _test_dbus_country(dev, apdev) + _test_dbus_country(dev, apdev) finally: dev[0].request("SET country 00") subprocess.call(['iw', 'reg', 'set', '00']) diff --git a/tests/hwsim/test_dbus_old.py b/tests/hwsim/test_dbus_old.py index dd724327d..8285547c4 100644 --- a/tests/hwsim/test_dbus_old.py +++ b/tests/hwsim/test_dbus_old.py @@ -555,7 +555,7 @@ def test_dbus_old_connect_eap(dev, apdev): def test_dbus_old_wps_pbc(dev, apdev): """The old D-Bus interface and WPS/PBC""" try: - return _test_dbus_old_wps_pbc(dev, apdev) + _test_dbus_old_wps_pbc(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -622,7 +622,7 @@ def _test_dbus_old_wps_pbc(dev, apdev): def test_dbus_old_wps_pin(dev, apdev): """The old D-Bus interface and WPS/PIN""" try: - return _test_dbus_old_wps_pin(dev, apdev) + _test_dbus_old_wps_pin(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") @@ -677,7 +677,7 @@ def _test_dbus_old_wps_pin(dev, apdev): def test_dbus_old_wps_reg(dev, apdev): """The old D-Bus interface and WPS/Registar""" try: - return _test_dbus_old_wps_reg(dev, apdev) + _test_dbus_old_wps_reg(dev, apdev) finally: dev[0].request("SET wps_cred_processing 0") diff --git a/tests/hwsim/test_dfs.py b/tests/hwsim/test_dfs.py index 08ded31d9..cdf3c642d 100644 --- a/tests/hwsim/test_dfs.py +++ b/tests/hwsim/test_dfs.py @@ -12,6 +12,7 @@ logger = logging.getLogger() import hwsim_utils import hostapd +from utils import HwsimSkip def wait_dfs_event(hapd, event, timeout): dfs_events = [ "DFS-RADAR-DETECTED", "DFS-NEW-CHANNEL", @@ -68,7 +69,9 @@ def start_dfs_ap(ap, allow_failure=False, ssid="dfs", ht=True, ht40=False, if state != "DFS": if allow_failure: logger.info("Interface state not DFS: " + state) - return None + if not os.path.exists("dfs"): + raise HwsimSkip("Assume DFS testing not supported") + raise Exception("Failed to start DFS AP") raise Exception("Unexpected interface state: " + state) return hapd @@ -84,10 +87,6 @@ def test_dfs(dev, apdev): """DFS CAC functionality on clear channel""" try: hapd = start_dfs_ap(apdev[0], allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70) if "success=1" not in ev: @@ -141,10 +140,6 @@ def test_dfs_radar(dev, apdev): try: hapd2 = None hapd = start_dfs_ap(apdev[0], allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) @@ -231,10 +226,6 @@ def test_dfs_radar_chanlist(dev, apdev): """DFS chanlist when radar is detected""" try: hapd = start_dfs_ap(apdev[0], chanlist="40 44", allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) @@ -269,10 +260,6 @@ def test_dfs_radar_chanlist_vht80(dev, apdev): try: hapd = start_dfs_ap(apdev[0], chanlist="36", ht40=True, vht80=True, allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) @@ -310,10 +297,6 @@ def test_dfs_radar_chanlist_vht20(dev, apdev): try: hapd = start_dfs_ap(apdev[0], chanlist="36", vht20=True, allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) @@ -348,10 +331,6 @@ def test_dfs_radar_no_ht(dev, apdev): try: hapd = start_dfs_ap(apdev[0], chanlist="36", ht=False, allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) @@ -386,10 +365,6 @@ def test_dfs_radar_ht40minus(dev, apdev): try: hapd = start_dfs_ap(apdev[0], chanlist="36", ht40minus=True, allow_failure=True) - if hapd is None: - if not os.path.exists("dfs"): - return "skip" - raise Exception("Failed to start DFS AP") time.sleep(1) dfs_simulate_radar(hapd) diff --git a/tests/hwsim/test_eap_proto.py b/tests/hwsim/test_eap_proto.py index 94865454c..6c5d8e136 100644 --- a/tests/hwsim/test_eap_proto.py +++ b/tests/hwsim/test_eap_proto.py @@ -13,6 +13,7 @@ import threading import time import hostapd +from utils import HwsimSkip EAP_CODE_REQUEST = 1 EAP_CODE_RESPONSE = 2 @@ -53,7 +54,7 @@ def start_radius_server(eap_handler): import pyrad.packet import pyrad.dictionary except ImportError: - return None + raise HwsimSkip("No pyrad modules available") class TestServer(pyrad.server.Server): def _HandleAuthPacket(self, pkt): @@ -260,8 +261,6 @@ def test_eap_proto(dev, apdev): return None srv = start_radius_server(eap_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -528,8 +527,6 @@ def test_eap_proto_sake(dev, apdev): return sake_challenge(ctx) srv = start_radius_server(sake_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -704,8 +701,6 @@ def test_eap_proto_leap(dev, apdev): return None srv = start_radius_server(leap_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -766,8 +761,6 @@ def test_eap_proto_md5(dev, apdev): return None srv = start_radius_server(md5_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -819,8 +812,6 @@ def test_eap_proto_otp(dev, apdev): return None srv = start_radius_server(otp_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -1274,8 +1265,6 @@ def test_eap_proto_gpsk(dev, apdev): return None srv = start_radius_server(gpsk_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -1582,8 +1571,6 @@ def test_eap_proto_eke(dev, apdev): return None srv = start_radius_server(eke_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -1904,8 +1891,6 @@ def test_eap_proto_pax(dev, apdev): return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4) srv = start_radius_server(pax_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -2043,8 +2028,6 @@ def test_eap_proto_psk(dev, apdev): return None srv = start_radius_server(psk_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -2786,8 +2769,6 @@ def test_eap_proto_aka(dev, apdev): return None srv = start_radius_server(aka_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -3133,8 +3114,6 @@ def test_eap_proto_aka_prime(dev, apdev): return None srv = start_radius_server(aka_prime_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -3539,8 +3518,6 @@ def test_eap_proto_sim(dev, apdev): return None srv = start_radius_server(sim_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) @@ -4002,8 +3979,6 @@ def test_eap_proto_ikev2(dev, apdev): return None srv = start_radius_server(ikev2_handler) - if srv is None: - return "skip" try: hapd = start_ap(apdev[0]['ifname']) diff --git a/tests/hwsim/test_erp.py b/tests/hwsim/test_erp.py index af7c2d0e7..f14a7f155 100644 --- a/tests/hwsim/test_erp.py +++ b/tests/hwsim/test_erp.py @@ -11,9 +11,15 @@ import os import time import hostapd +from utils import HwsimSkip from test_ap_eap import int_eap_server_params from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations +def check_erp_capa(dev): + capab = dev.get_capability("erp") + if not capab or 'ERP' not in capab: + raise HwsimSkip("ERP not supported in the build") + def test_erp_initiate_reauth_start(dev, apdev): """Authenticator sending EAP-Initiate/Re-auth-Start, but ERP disabled on peer""" params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") @@ -43,9 +49,7 @@ def test_erp_enabled_on_server(dev, apdev): def test_erp(dev, apdev): """ERP enabled on server and peer""" - capab = dev[0].get_capability("erp") - if not capab or 'ERP' not in capab: - return "skip" + check_erp_capa(dev[0]) params = int_eap_server_params() params['erp_send_reauth_start'] = '1' params['erp_domain'] = 'example.com' @@ -71,9 +75,7 @@ def test_erp(dev, apdev): def test_erp_server_no_match(dev, apdev): """ERP enabled on server and peer, but server has no key match""" - capab = dev[0].get_capability("erp") - if not capab or 'ERP' not in capab: - return "skip" + check_erp_capa(dev[0]) params = int_eap_server_params() params['erp_send_reauth_start'] = '1' params['erp_domain'] = 'example.com' @@ -125,9 +127,7 @@ def start_erp_as(apdev): def test_erp_radius(dev, apdev): """ERP enabled on RADIUS server and peer""" - capab = dev[0].get_capability("erp") - if not capab or 'ERP' not in capab: - return "skip" + check_erp_capa(dev[0]) start_erp_as(apdev[1]) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['auth_server_port'] = "18128" @@ -175,9 +175,7 @@ def erp_test(dev, hapd, **kwargs): def test_erp_radius_eap_methods(dev, apdev): """ERP enabled on RADIUS server and peer""" - capab = dev[0].get_capability("erp") - if not capab or 'ERP' not in capab: - return "skip" + check_erp_capa(dev[0]) start_erp_as(apdev[1]) params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params['auth_server_port'] = "18128" @@ -222,9 +220,7 @@ def test_erp_radius_eap_methods(dev, apdev): def test_erp_key_lifetime_in_memory(dev, apdev, params): """ERP and key lifetime in memory""" - capab = dev[0].get_capability("erp") - if not capab or 'ERP' not in capab: - return "skip" + check_erp_capa(dev[0]) p = int_eap_server_params() p['erp_send_reauth_start'] = '1' p['erp_domain'] = 'example.com' @@ -298,11 +294,9 @@ def test_erp_key_lifetime_in_memory(dev, apdev, params): get_key_locations(buf, rRK, "rRK") get_key_locations(buf, rIK, "rIK") if password not in buf: - print("Password not found while associated") - return "skip" + raise HwsimSkip("Password not found while associated") if pmk not in buf: - print("PMK not found while associated") - return "skip" + raise HwsimSkip("PMK not found while associated") if kck not in buf: raise Exception("KCK not found while associated") if kek not in buf: diff --git a/tests/hwsim/test_p2p_autogo.py b/tests/hwsim/test_p2p_autogo.py index 1ab5acdd2..de4285700 100644 --- a/tests/hwsim/test_p2p_autogo.py +++ b/tests/hwsim/test_p2p_autogo.py @@ -11,6 +11,7 @@ logger = logging.getLogger() import hwsim_utils import utils +from utils import HwsimSkip from wlantest import Wlantest from wpasupplicant import WpaSupplicant @@ -340,7 +341,7 @@ def test_autogo_chan_switch(dev): if "FAIL" in res: # for now, skip test since mac80211_hwsim support is not yet widely # deployed - return 'skip' + raise HwsimSkip("Assume mac80211_hwsim did not support channel switching") ev = dev[0].wait_event(["AP-CSA-FINISHED"], timeout=10) if ev is None: raise Exception("CSA finished event timed out") diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index 152814242..57c6ff3a6 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -14,6 +14,7 @@ import os import hostapd import hwsim_utils import utils +from utils import HwsimSkip from wpasupplicant import WpaSupplicant def check_grpform_results(i_res, r_res): @@ -728,8 +729,7 @@ def test_grpform_goneg_fail_with_group_iface(dev): def test_grpform_cred_ready_timeout(dev, apdev, params): """P2P GO Negotiation wait for credentials to become ready [long]""" if not params['long']: - logger.info("Skip test case with long duration due to --long not specified") - return "skip" + raise HwsimSkip("Skip test case with long duration due to --long not specified") dev[1].p2p_listen() addr1 = dev[1].p2p_dev_addr() diff --git a/tests/hwsim/test_radius.py b/tests/hwsim/test_radius.py index e68747ec2..af42a84c6 100644 --- a/tests/hwsim/test_radius.py +++ b/tests/hwsim/test_radius.py @@ -15,6 +15,7 @@ import threading import time import hostapd +from utils import HwsimSkip def connect(dev, ssid, wait_connect=True): dev.connect(ssid, key_mgmt="WPA-EAP", scan_freq="2412", @@ -237,7 +238,7 @@ def test_radius_das_disconnect(dev, apdev): import pyrad.dictionary import radius_das except ImportError: - return "skip" + raise HwsimSkip("No pyrad modules available") params = hostapd.wpa2_eap_params(ssid="radius-das") params['radius_das_port'] = "3799" @@ -504,7 +505,7 @@ def test_radius_das_coa(dev, apdev): import pyrad.dictionary import radius_das except ImportError: - return "skip" + raise HwsimSkip("No pyrad modules available") params = hostapd.wpa2_eap_params(ssid="radius-das") params['radius_das_port'] = "3799" @@ -626,7 +627,7 @@ def test_radius_protocol(dev, apdev): import pyrad.packet import pyrad.dictionary except ImportError: - return "skip" + raise HwsimSkip("No pyrad modules available") class TestServer(pyrad.server.Server): def _HandleAuthPacket(self, pkt): @@ -734,7 +735,7 @@ def test_radius_psk(dev, apdev): import pyrad.packet import pyrad.dictionary except ImportError: - return "skip" + raise HwsimSkip("No pyrad modules available") class TestServer(pyrad.server.Server): def _HandleAuthPacket(self, pkt): diff --git a/tests/hwsim/test_rfkill.py b/tests/hwsim/test_rfkill.py index 27c620f4e..425b40fce 100644 --- a/tests/hwsim/test_rfkill.py +++ b/tests/hwsim/test_rfkill.py @@ -13,6 +13,7 @@ from hostapd import HostapdGlobal import hwsim_utils from wpasupplicant import WpaSupplicant from rfkill import RFKill +from utils import HwsimSkip def get_rfkill(dev): phy = dev.get_driver_status_field("phyname") @@ -21,15 +22,12 @@ def get_rfkill(dev): if r.name == phy: return r except Exception, e: - logger.info("No rfkill available: " + str(e)) - - return None + raise HwsimSkip("No rfkill available: " + str(e)) + raise HwsimSkip("No rfkill match found for the interface") def test_rfkill_open(dev, apdev): """rfkill block/unblock during open mode connection""" rfk = get_rfkill(dev[0]) - if rfk is None: - return "skip" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") @@ -59,8 +57,6 @@ def test_rfkill_open(dev, apdev): def test_rfkill_wpa2_psk(dev, apdev): """rfkill block/unblock during WPA2-PSK connection""" rfk = get_rfkill(dev[0]) - if rfk is None: - return "skip" ssid = "test-wpa2-psk" passphrase = 'qwertyuiop' @@ -84,11 +80,7 @@ def test_rfkill_wpa2_psk(dev, apdev): def test_rfkill_autogo(dev, apdev): """rfkill block/unblock for autonomous P2P GO""" rfk0 = get_rfkill(dev[0]) - if rfk0 is None: - return "skip" rfk1 = get_rfkill(dev[1]) - if rfk1 is None: - return "skip" dev[0].p2p_start_go() dev[1].request("SET p2p_no_group_iface 0") @@ -129,8 +121,6 @@ def test_rfkill_hostapd(dev, apdev): hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }) rfk = get_rfkill(hapd) - if rfk is None: - return "skip" try: rfk.block() @@ -169,8 +159,6 @@ def test_rfkill_wpas(dev, apdev): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") rfk = get_rfkill(wpas) - if rfk is None: - return "skip" wpas.interface_remove("wlan5") try: rfk.block() diff --git a/tests/hwsim/test_sae.py b/tests/hwsim/test_sae.py index 07afb1fea..da694da15 100644 --- a/tests/hwsim/test_sae.py +++ b/tests/hwsim/test_sae.py @@ -13,6 +13,7 @@ logger = logging.getLogger() import hwsim_utils import hostapd +from utils import HwsimSkip from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations def test_sae(dev, apdev): @@ -228,11 +229,9 @@ def test_sae_key_lifetime_in_memory(dev, apdev, params): get_key_locations(buf, password, "Password") get_key_locations(buf, pmk, "PMK") if password not in buf: - print("Password not found while associated") - return "skip" + raise HwsimSkip("Password not found while associated") if pmk not in buf: - print("PMK not found while associated") - return "skip" + raise HwsimSkip("PMK not found while associated") if kck not in buf: raise Exception("KCK not found while associated") if kek not in buf: diff --git a/tests/hwsim/test_suite_b.py b/tests/hwsim/test_suite_b.py index 77d0ebbb1..2b2c9c2dc 100644 --- a/tests/hwsim/test_suite_b.py +++ b/tests/hwsim/test_suite_b.py @@ -9,11 +9,12 @@ import logging logger = logging.getLogger() import hostapd +from utils import HwsimSkip def test_suite_b(dev, apdev): """WPA2-PSK/GCMP connection""" if "GCMP" not in dev[0].get_capability("pairwise"): - return "skip" + raise HwsimSkip("GCMP not supported") params = hostapd.wpa2_eap_params(ssid="test-suite-b") params["wpa_key_mgmt"] = "WPA-EAP-SUITE-B" params['rsn_pairwise'] = "GCMP" diff --git a/tests/hwsim/test_tnc.py b/tests/hwsim/test_tnc.py index 003d0f8e9..0b1b07fa1 100644 --- a/tests/hwsim/test_tnc.py +++ b/tests/hwsim/test_tnc.py @@ -8,6 +8,7 @@ import os.path import hostapd +from utils import HwsimSkip from test_ap_eap import int_eap_server_params def test_tnc_peap_soh(dev, apdev): @@ -47,8 +48,7 @@ def test_tnc_ttls(dev, apdev): hostapd.add_ap(apdev[0]['ifname'], params) if not os.path.exists("tnc/libhostap_imc.so"): - logger.info("No IMC installed - skip") - return "skip" + raise HwsimSkip("No IMC installed") dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS", identity="DOMAIN\mschapv2 user", @@ -69,8 +69,7 @@ def test_tnc_fast(dev, apdev): hostapd.add_ap(apdev[0]['ifname'], params) if not os.path.exists("tnc/libhostap_imc.so"): - logger.info("No IMC installed - skip") - return "skip" + raise HwsimSkip("No IMC installed") dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST", identity="user", diff --git a/tests/hwsim/test_wext.py b/tests/hwsim/test_wext.py index 97f332849..718466041 100644 --- a/tests/hwsim/test_wext.py +++ b/tests/hwsim/test_wext.py @@ -1,5 +1,5 @@ # Deprecated WEXT driver interface in wpa_supplicant -# Copyright (c) 2013-2014, Jouni Malinen +# Copyright (c) 2013-2015, Jouni Malinen # # This software may be distributed under the terms of the BSD license. # See README for more details. @@ -11,26 +11,23 @@ import os import hostapd import hwsim_utils from wpasupplicant import WpaSupplicant +from utils import HwsimSkip from test_rfkill import get_rfkill def get_wext_interface(): if not os.path.exists("/proc/net/wireless"): - logger.info("WEXT support not included in the kernel") - return + raise HwsimSkip("WEXT support not included in the kernel") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') try: wpas.interface_add("wlan5", driver="wext") except Exception, e: - logger.info("WEXT driver support not included in wpa_supplicant") - return + raise HwsimSkip("WEXT driver support not included in wpa_supplicant") return wpas def test_wext_open(dev, apdev): """WEXT driver interface with open network""" wpas = get_wext_interface() - if not wpas: - return "skip" params = { "ssid": "wext-open" } hapd = hostapd.add_ap(apdev[0]['ifname'], params) @@ -41,8 +38,6 @@ def test_wext_open(dev, apdev): def test_wext_wpa2_psk(dev, apdev): """WEXT driver interface with WPA2-PSK""" wpas = get_wext_interface() - if not wpas: - return "skip" params = hostapd.wpa2_params(ssid="wext-wpa2-psk", passphrase="12345678") hapd = hostapd.add_ap(apdev[0]['ifname'], params) @@ -59,14 +54,12 @@ def test_wext_wpa2_psk(dev, apdev): def test_wext_wpa_psk(dev, apdev): """WEXT driver interface with WPA-PSK""" wpas = get_wext_interface() - if not wpas: - return "skip" params = hostapd.wpa_params(ssid="wext-wpa-psk", passphrase="12345678") hapd = hostapd.add_ap(apdev[0]['ifname'], params) testfile = "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd.get_driver_status_field("phyname"), apdev[0]['ifname']) if not os.path.exists(testfile): - return "skip" + raise HwsimSkip("tkip_mic_test not supported in mac80211") wpas.connect("wext-wpa-psk", psk="12345678") hwsim_utils.test_connectivity(wpas, hapd) @@ -87,8 +80,6 @@ def test_wext_wpa_psk(dev, apdev): def test_wext_pmksa_cache(dev, apdev): """PMKSA caching with WEXT""" wpas = get_wext_interface() - if not wpas: - return "skip" params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") hostapd.add_ap(apdev[0]['ifname'], params) @@ -155,8 +146,6 @@ def test_wext_pmksa_cache(dev, apdev): def test_wext_wep_open_auth(dev, apdev): """WEP Open System authentication""" wpas = get_wext_interface() - if not wpas: - return "skip" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "wep-open", @@ -170,8 +159,6 @@ def test_wext_wep_open_auth(dev, apdev): def test_wext_wep_shared_key_auth(dev, apdev): """WEP Shared Key authentication""" wpas = get_wext_interface() - if not wpas: - return "skip" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "wep-shared-key", @@ -188,8 +175,6 @@ def test_wext_wep_shared_key_auth(dev, apdev): def test_wext_pmf(dev, apdev): """WEXT driver interface with WPA2-PSK and PMF""" wpas = get_wext_interface() - if not wpas: - return "skip" params = hostapd.wpa2_params(ssid="wext-wpa2-psk", passphrase="12345678") params["wpa_key_mgmt"] = "WPA-PSK-SHA256"; @@ -208,8 +193,6 @@ def test_wext_pmf(dev, apdev): def test_wext_scan_hidden(dev, apdev): """WEXT with hidden SSID""" wpas = get_wext_interface() - if not wpas: - return "skip" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan", "ignore_broadcast_ssid": "1" }) @@ -244,13 +227,9 @@ def test_wext_rfkill(dev, apdev): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") rfk = get_rfkill(wpas) - if rfk is None: - return "skip" wpas.interface_remove("wlan5") wpas = get_wext_interface() - if not wpas: - return "skip" hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }) wpas.connect("open", key_mgmt="NONE", scan_freq="2412") diff --git a/tests/hwsim/test_wpas_mesh.py b/tests/hwsim/test_wpas_mesh.py index 08baeb6ab..e66b3f18e 100644 --- a/tests/hwsim/test_wpas_mesh.py +++ b/tests/hwsim/test_wpas_mesh.py @@ -11,12 +11,12 @@ logger = logging.getLogger() import hwsim_utils from wpasupplicant import WpaSupplicant +from utils import HwsimSkip -def mesh_supported(dev): +def check_mesh_support(dev): flags = int(dev.get_driver_status_field('capa.flags'), 16) - if flags & 0x100000000: - return True - return False + if flags & 0x100000000 == 0: + raise HwsimSkip("Driver does not support mesh") def check_mesh_scan(dev, params, other_started=False, beacon_int=0): if not other_started: @@ -116,8 +116,7 @@ def add_open_mesh_network(dev, ht_mode=False, freq="2412", start=True, def test_wpas_mesh_group_added(dev): """wpa_supplicant MESH group add""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0]) # Check for MESH-GROUP-STARTED event @@ -126,8 +125,7 @@ def test_wpas_mesh_group_added(dev): def test_wpas_mesh_group_remove(dev): """wpa_supplicant MESH group remove""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0], ht_mode="NOHT") # Check for MESH-GROUP-STARTED event check_mesh_group_added(dev[0]) @@ -138,8 +136,7 @@ def test_wpas_mesh_group_remove(dev): def test_wpas_mesh_peer_connected(dev): """wpa_supplicant MESH peer connected""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0], ht_mode="HT20", beacon_int=160) add_open_mesh_network(dev[1], ht_mode="HT20", beacon_int=160) @@ -154,8 +151,7 @@ def test_wpas_mesh_peer_connected(dev): def test_wpas_mesh_peer_disconnected(dev): """wpa_supplicant MESH peer disconnected""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0]) add_open_mesh_network(dev[1]) @@ -175,8 +171,7 @@ def test_wpas_mesh_peer_disconnected(dev): def test_wpas_mesh_mode_scan(dev): """wpa_supplicant MESH scan support""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0], ht_mode="HT40+") add_open_mesh_network(dev[1], ht_mode="HT40+", beacon_int=175) @@ -189,8 +184,7 @@ def test_wpas_mesh_mode_scan(dev): def test_wpas_mesh_open(dev, apdev): """wpa_supplicant open MESH network connectivity""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) add_open_mesh_network(dev[0], ht_mode="HT40-", freq="2462") add_open_mesh_network(dev[1], ht_mode="HT40-", freq="2462") @@ -207,8 +201,7 @@ def test_wpas_mesh_open(dev, apdev): def test_wpas_mesh_open_no_auto(dev, apdev): """wpa_supplicant open MESH network connectivity""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) id = add_open_mesh_network(dev[0], start=False) dev[0].set_network(id, "dot11MeshMaxRetries", "16") dev[0].set_network(id, "dot11MeshRetryTimeout", "255") @@ -241,8 +234,7 @@ def add_mesh_secure_net(dev, psk=True): def test_wpas_mesh_secure(dev, apdev): """wpa_supplicant secure MESH network connectivity""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) dev[0].request("SET sae_groups ") id = add_mesh_secure_net(dev[0]) dev[0].mesh_group_add(id) @@ -264,8 +256,7 @@ def test_wpas_mesh_secure(dev, apdev): def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev): """wpa_supplicant secure MESH and SAE group mismatch""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) addr0 = dev[0].p2p_interface_addr() addr1 = dev[1].p2p_interface_addr() addr2 = dev[2].p2p_interface_addr() @@ -316,8 +307,7 @@ def test_wpas_mesh_secure_sae_group_mismatch(dev, apdev): def test_wpas_mesh_secure_sae_missing_password(dev, apdev): """wpa_supplicant secure MESH and missing SAE password""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) id = add_mesh_secure_net(dev[0], psk=False) dev[0].set_network(id, "psk", "8f20b381f9b84371d61b5080ad85cac3c61ab3ca9525be5b2d0f4da3d979187a") dev[0].mesh_group_add(id) @@ -333,8 +323,7 @@ def test_wpas_mesh_secure_sae_missing_password(dev, apdev): def test_wpas_mesh_secure_no_auto(dev, apdev): """wpa_supplicant secure MESH network connectivity""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) dev[0].request("SET sae_groups 19") id = add_mesh_secure_net(dev[0]) dev[0].mesh_group_add(id) @@ -360,8 +349,7 @@ def test_wpas_mesh_secure_no_auto(dev, apdev): def test_wpas_mesh_ctrl(dev): """wpa_supplicant ctrl_iface mesh command error cases""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) if "FAIL" not in dev[0].request("MESH_GROUP_ADD 123"): raise Exception("Unexpected MESH_GROUP_ADD success") id = dev[0].add_network() @@ -377,8 +365,7 @@ def test_wpas_mesh_ctrl(dev): def test_wpas_mesh_dynamic_interface(dev): """wpa_supplicant mesh with dynamic interface""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) mesh0 = None mesh1 = None try: @@ -455,8 +442,7 @@ def test_wpas_mesh_dynamic_interface(dev): def test_wpas_mesh_max_peering(dev, apdev): """Mesh max peering limit""" - if not mesh_supported(dev[0]): - return "skip" + check_mesh_support(dev[0]) try: dev[0].request("SET max_peer_links 1")