Update wifi enterprise test scripts for new wifi test setup.
Apply pep8 style.
Use asserts properly.
Update string format convention.
Clean up import statements and namespace.
Update attenuator usage for new Wi-Fi test setup.
Also fix a syntax issue in scanner test.
Bug=29182983
Change-Id: Iedfaa1ffe4e72f5b2a356d5b25c2a681344c81c8
diff --git a/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py b/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
index 84884c9..29eb3c8 100644
--- a/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
+++ b/acts/tests/google/wifi/WifiEnterpriseRoamingTest.py
@@ -17,11 +17,10 @@
import random
import time
-import acts.base_test
-import acts.signals
-import acts.test_utils.wifi.wifi_test_utils as wutils
-
from acts import asserts
+from acts import base_test
+from acts import signals
+from acts.test_utils.wifi import wifi_test_utils as wutils
WifiEnums = wutils.WifiEnums
@@ -32,14 +31,8 @@
# Enterprise Config Macros
Ent = WifiEnums.Enterprise
-class WifiEnterpriseRoamingTest(acts.base_test.BaseTestClass):
- def __init__(self, controllers):
- acts.base_test.BaseTestClass.__init__(self, controllers)
- self.tests = (
- "test_roaming_with_different_auth_method",
- )
-
+class WifiEnterpriseRoamingTest(base_test.BaseTestClass):
def setup_class(self):
self.dut = self.android_devices[0]
wutils.wifi_test_device_init(self.dut)
@@ -55,8 +48,7 @@
"client_key",
"eap_identity",
"eap_password",
- "device_password"
- )
+ "device_password")
self.unpack_userparams(req_params)
self.config_peap = {
Ent.EAP: EAP.PEAP,
@@ -86,6 +78,7 @@
Ent.EAP: EAP.SIM,
WifiEnums.SSID_KEY: self.ent_roaming_ssid,
}
+ self.attenuators = wutils.group_attenuators(self.attenuators)
self.attn_a = self.attenuators[0]
self.attn_b = self.attenuators[1]
# Set screen lock password so ConfigStore is unlocked.
@@ -104,7 +97,6 @@
self.dut.droid.wakeUpNow()
wutils.reset_wifi(self.dut)
self.dut.ed.clear_all_events()
- return True
def teardown_test(self):
self.dut.droid.wakeLockRelease()
@@ -121,14 +113,14 @@
Args:
attn_val_name: Name of the attenuation value pair to use.
"""
- msg = "Set attenuation values to %s" % self.attn_vals[attn_val_name]
- self.log.info(msg)
+ self.log.info("Set attenuation values to %s",
+ self.attn_vals[attn_val_name])
try:
self.attn_a.set_atten(self.attn_vals[attn_val_name][0])
self.attn_b.set_atten(self.attn_vals[attn_val_name][1])
except:
- msg = "Failed to set attenuation values %s." % attn_val_name
- self.log.error(msg)
+ self.log.exception("Failed to set attenuation values %s.",
+ attn_val_name)
raise
def gen_eap_configs(self):
@@ -138,7 +130,7 @@
A list of dicts each representing an EAP configuration.
"""
configs = [self.config_tls]
- # self.config_sim
+ # self.config_sim
configs += wutils.expand_enterprise_config_by_phase2(self.config_ttls)
configs += wutils.expand_enterprise_config_by_phase2(self.config_peap)
return configs
@@ -167,14 +159,14 @@
to roam to.
"""
self.set_attns(attn_val_name)
- self.log.info("Wait %ss for roaming to finish." % self.roam_interval)
+ self.log.info("Wait %ss for roaming to finish.", self.roam_interval)
time.sleep(self.roam_interval)
try:
self.dut.droid.wakeLockAcquireBright()
self.dut.droid.wakeUpNow()
wutils.verify_wifi_connection_info(self.dut, expected_con)
expected_bssid = expected_con[WifiEnums.BSSID_KEY]
- self.log.info("Roamed to %s successfully" % expected_bssid)
+ self.log.info("Roamed to %s successfully", expected_bssid)
finally:
self.dut.droid.wifiLockRelease()
self.dut.droid.goToSleepNow()
@@ -201,22 +193,25 @@
self.set_attns("a_on_b_off")
wutils.eap_connect(config, self.dut, validate_con=False)
wutils.verify_wifi_connection_info(self.dut, expected_con_to_a)
- self.log.info("Roaming from %s to %s" % (self.bssid_a, self.bssid_b))
+ self.log.info("Roaming from %s to %s", self.bssid_a, self.bssid_b)
self.trigger_roaming_and_validate("b_on_a_off", expected_con_to_b)
- self.log.info("Roaming from %s to %s" % (self.bssid_b, self.bssid_a))
+ self.log.info("Roaming from %s to %s", self.bssid_b, self.bssid_a)
self.trigger_roaming_and_validate("a_on_b_off", expected_con_to_a)
""" Tests Begin """
- @acts.signals.generated_test
+
+ @signals.generated_test
def test_roaming_with_different_auth_method(self):
eap_configs = self.gen_eap_configs()
- self.log.info("Testing %d different configs." % len(eap_configs))
+ self.log.info("Testing %d different configs.", len(eap_configs))
random.shuffle(eap_configs)
failed = self.run_generated_testcases(
self.roaming_between_a_and_b_logic,
eap_configs,
name_func=self.gen_eap_roaming_test_name)
- msg = ("The following configs failed enterprise roaming test: %s" %
- pprint.pformat(failed))
- asserts.assert_true(len(failed) == 0, msg)
+ asserts.assert_equal(
+ len(failed), 0,
+ "The following configs failed enterprise roaming test: %s" %
+ pprint.pformat(failed))
+
""" Tests End """
diff --git a/acts/tests/google/wifi/WifiEnterpriseTest.py b/acts/tests/google/wifi/WifiEnterpriseTest.py
index 433816e..eba2dff 100755
--- a/acts/tests/google/wifi/WifiEnterpriseTest.py
+++ b/acts/tests/google/wifi/WifiEnterpriseTest.py
@@ -31,45 +31,28 @@
# Enterprise Config Macros
Ent = WifiEnums.Enterprise
-class WifiEnterpriseTest(base_test.BaseTestClass):
+class WifiEnterpriseTest(base_test.BaseTestClass):
def __init__(self, controllers):
base_test.BaseTestClass.__init__(self, controllers)
- self.tests = (
- "test_eap_connect",
- "test_eap_connect_negative",
- )
+ self.tests = ("test_eap_connect", "test_eap_connect_negative", )
def setup_class(self):
self.dut = self.android_devices[0]
wutils.wifi_test_device_init(self.dut)
+ # If running in a setup with attenuators, set attenuation on all
+ # channels to zero.
+ if getattr(self, "attenuators", []):
+ for a in self.attenuators:
+ a.set_atten(0)
required_userparam_names = (
- "ca_cert",
- "client_cert",
- "client_key",
- "passpoint_ca_cert",
- "passpoint_client_cert",
- "passpoint_client_key",
- "eap_identity",
- "eap_password",
- "invalid_ca_cert",
- "invalid_client_cert",
- "invalid_client_key",
- "fqdn",
- "provider_friendly_name",
- "realm",
- "ssid_peap0",
- "ssid_peap1",
- "ssid_tls",
- "ssid_ttls",
- "ssid_pwd",
- "ssid_sim",
- "ssid_aka",
- "ssid_aka_prime",
- "ssid_passpoint",
- "device_password",
- "ping_addr"
- )
+ "ca_cert", "client_cert", "client_key", "passpoint_ca_cert",
+ "passpoint_client_cert", "passpoint_client_key", "eap_identity",
+ "eap_password", "invalid_ca_cert", "invalid_client_cert",
+ "invalid_client_key", "fqdn", "provider_friendly_name", "realm",
+ "ssid_peap0", "ssid_peap1", "ssid_tls", "ssid_ttls", "ssid_pwd",
+ "ssid_sim", "ssid_aka", "ssid_aka_prime", "ssid_passpoint",
+ "device_password", "ping_addr")
self.unpack_userparams(required_userparam_names,
roaming_consortium_ids=None,
plmn=None)
@@ -129,13 +112,15 @@
if self.plmn:
self.config_passpoint[Ent.PLMN] = self.plmn
if self.roaming_consortium_ids:
- self.config_passpoint[Ent.ROAMING_IDS] = self.roaming_consortium_ids
+ self.config_passpoint[
+ Ent.ROAMING_IDS] = self.roaming_consortium_ids
# Default configs for passpoint networks.
self.config_passpoint_tls = dict(self.config_tls)
self.config_passpoint_tls.update(self.config_passpoint)
self.config_passpoint_tls[Ent.CLIENT_CERT] = self.passpoint_client_cert
- self.config_passpoint_tls[Ent.PRIVATE_KEY_ID] = self.passpoint_client_key
+ self.config_passpoint_tls[
+ Ent.PRIVATE_KEY_ID] = self.passpoint_client_key
del self.config_passpoint_tls[WifiEnums.SSID_KEY]
self.config_passpoint_ttls = dict(self.config_ttls)
self.config_passpoint_ttls.update(self.config_passpoint)
@@ -205,11 +190,8 @@
Returns:
A list of dicts each representing an EAP configuration.
"""
- configs = [self.config_tls,
- self.config_pwd,
- self.config_sim,
- self.config_aka,
- self.config_aka_prime]
+ configs = [self.config_tls, self.config_pwd, self.config_sim,
+ self.config_aka, self.config_aka_prime]
configs += wutils.expand_enterprise_config_by_phase2(self.config_ttls)
configs += wutils.expand_enterprise_config_by_phase2(self.config_peap0)
configs += wutils.expand_enterprise_config_by_phase2(self.config_peap1)
@@ -224,7 +206,8 @@
passpoint networks.
"""
configs = [self.config_passpoint_tls]
- configs += wutils.expand_enterprise_config_by_phase2(self.config_passpoint_ttls)
+ configs += wutils.expand_enterprise_config_by_phase2(
+ self.config_passpoint_ttls)
return configs
def gen_negative_configs(self, configs, neg_params):
@@ -340,6 +323,7 @@
return name
"""Tests"""
+
@signals.generated_test
def test_eap_connect(self):
"""Test connecting to enterprise networks of different authentication
@@ -360,16 +344,15 @@
networks.
"""
eap_configs = self.gen_eap_configs()
- self.log.info("Testing %d different configs." % len(eap_configs))
+ self.log.info("Testing %d different configs.", len(eap_configs))
random.shuffle(eap_configs)
- failed = self.run_generated_testcases(
- wutils.eap_connect,
- eap_configs,
- args=(self.dut,),
- name_func=self.gen_eap_test_name)
- msg = ("The following configs failed EAP connect test: %s" %
- pprint.pformat(failed))
- asserts.assert_equal(len(failed), 0, msg)
+ failed = self.run_generated_testcases(wutils.eap_connect,
+ eap_configs,
+ args=(self.dut, ),
+ name_func=self.gen_eap_test_name)
+ asserts.assert_equal(
+ len(failed), 0, "The following configs failed EAP connect test: %s"
+ % pprint.pformat(failed))
@signals.generated_test
def test_eap_connect_negative(self):
@@ -383,17 +366,18 @@
Fail to establish connection.
"""
neg_eap_configs = self.gen_negative_eap_configs()
- self.log.info("Testing %d different configs." % len(neg_eap_configs))
+ self.log.info("Testing %d different configs.", len(neg_eap_configs))
random.shuffle(neg_eap_configs)
+
def name_gen(config, ad):
name = self.gen_eap_test_name(config, ad)
name += "-with_wrong-{}".format(config["invalid_field"])
return name
- failed = self.run_generated_testcases(
- self.eap_negative_connect_logic,
- neg_eap_configs,
- args=(self.dut,),
- name_func=name_gen)
+
+ failed = self.run_generated_testcases(self.eap_negative_connect_logic,
+ neg_eap_configs,
+ args=(self.dut, ),
+ name_func=name_gen)
msg = ("The following configs failed negative EAP connect test: %s" %
pprint.pformat(failed))
asserts.assert_equal(len(failed), 0, msg)
@@ -417,18 +401,20 @@
networks with passpoint support.
"""
asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(),
- "Passpoint is not supported on device %s" % self.dut.model)
+ "Passpoint is not supported on device %s" %
+ self.dut.model)
passpoint_configs = self.gen_passpoint_configs()
- self.log.info("Testing %d different configs." % len(passpoint_configs))
+ self.log.info("Testing %d different configs.", len(passpoint_configs))
random.shuffle(passpoint_configs)
failed = self.run_generated_testcases(
wutils.eap_connect,
passpoint_configs,
- args=(self.dut,),
+ args=(self.dut, ),
name_func=self.gen_passpoint_test_name)
- msg = ("The following configs failed passpoint connect test: %s" %
- pprint.pformat(failed))
- asserts.assert_equal(len(failed), 0, msg)
+ asserts.assert_equal(
+ len(failed), 0,
+ "The following configs failed passpoint connect test: %s" %
+ pprint.pformat(failed))
@signals.generated_test
def test_passpoint_connect_negative(self):
@@ -442,19 +428,23 @@
Fail to establish connection.
"""
asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(),
- "Passpoint is not supported on device %s" % self.dut.model)
+ "Passpoint is not supported on device %s" %
+ self.dut.model)
neg_passpoint_configs = self.gen_negative_passpoint_configs()
- self.log.info("Testing %d different configs." % len(neg_passpoint_configs))
+ self.log.info("Testing %d different configs.",
+ len(neg_passpoint_configs))
random.shuffle(neg_passpoint_configs)
+
def name_gen(config, ad):
name = self.gen_passpoint_test_name(config, ad)
name += "-with_wrong-{}".format(config["invalid_field"])
return name
- failed = self.run_generated_testcases(
- self.eap_negative_connect_logic,
- neg_passpoint_configs,
- args=(self.dut,),
- name_func=name_gen)
- msg = ("The following configs failed negative passpoint connect test: "
- "%s") % pprint.pformat(failed)
- asserts.assert_equal(len(failed), 0, msg)
+
+ failed = self.run_generated_testcases(self.eap_negative_connect_logic,
+ neg_passpoint_configs,
+ args=(self.dut, ),
+ name_func=name_gen)
+ asserts.assert_equal(
+ len(failed), 0,
+ "The following configs failed negative passpoint connect test: %s"
+ % pprint.pformat(failed))
diff --git a/acts/tests/google/wifi/WifiScannerScanTest.py b/acts/tests/google/wifi/WifiScannerScanTest.py
index b105ba3..2ce2534 100755
--- a/acts/tests/google/wifi/WifiScannerScanTest.py
+++ b/acts/tests/google/wifi/WifiScannerScanTest.py
@@ -43,7 +43,7 @@
class WifiScannerScanTest(base_test.BaseTestClass):
def __init__(self, controllers):
- BaseTestClass.__init__(self, controllers)
+ base_test.BaseTestClass.__init__(self, controllers)
# TODO(angli): Remove this list.
# There are order dependencies among these tests so we'll have to leave
# it here for now. :(