Add acts test for WifiManager coex APIs
Add acts test for setting and getting coex unsafe channels in
WifiManager.
Bug: 153651001
Test: act.py -c <config> -tc WifiManagerTest:test_set_get_coex_unsafe_channels
Change-Id: I5719c8663e9f3a8eba52387e2ef770f5c1f6a49c
diff --git a/acts_tests/acts_contrib/test_utils/wifi/wifi_constants.py b/acts_tests/acts_contrib/test_utils/wifi/wifi_constants.py
index 3a49905..36714f8 100644
--- a/acts_tests/acts_contrib/test_utils/wifi/wifi_constants.py
+++ b/acts_tests/acts_contrib/test_utils/wifi/wifi_constants.py
@@ -81,3 +81,10 @@
# Delay before registering the match callback.
NETWORK_REQUEST_CB_REGISTER_DELAY_SEC = 2
+
+# Constants for JSONObject representation of CoexUnsafeChannel
+COEX_BAND = "band"
+COEX_BAND_24_GHZ = "24_GHZ"
+COEX_BAND_5_GHZ = "5_GHZ"
+COEX_CHANNEL = "channel"
+COEX_POWER_CAP_DBM = "powerCapDbm"
diff --git a/acts_tests/tests/google/wifi/WifiManagerTest.py b/acts_tests/tests/google/wifi/WifiManagerTest.py
index e220c2a..8dbd1f4 100644
--- a/acts_tests/tests/google/wifi/WifiManagerTest.py
+++ b/acts_tests/tests/google/wifi/WifiManagerTest.py
@@ -29,6 +29,7 @@
from acts_contrib.test_utils.bt.bt_test_utils import enable_bluetooth
from acts_contrib.test_utils.bt.bt_test_utils import disable_bluetooth
from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
+from acts_contrib.test_utils.wifi.wifi_constants import COEX_BAND, COEX_CHANNEL, COEX_POWER_CAP_DBM
WifiEnums = wutils.WifiEnums
# Default timeout used for reboot, toggle WiFi and Airplane mode,
@@ -67,7 +68,8 @@
req_params = []
opt_param = [
"open_network", "reference_networks", "iperf_server_address",
- "wpa_networks", "wep_networks", "iperf_server_port"
+ "wpa_networks", "wep_networks", "iperf_server_port",
+ "coex_unsafe_channels", "coex_restrictions"
]
self.unpack_userparams(
req_param_names=req_params, opt_param_names=opt_param)
@@ -1037,3 +1039,75 @@
assert_on_fail=False), "Device should not connect.")
self.dut.droid.wifiEnableAutojoin(network_id, True)
wutils.wait_for_connect(self.dut, network[WifiEnums.SSID_KEY], assert_on_fail=False)
+
+ def coex_unsafe_channel_key(self, unsafe_channel):
+ if COEX_POWER_CAP_DBM in unsafe_channel:
+ return (unsafe_channel[COEX_BAND], unsafe_channel[COEX_CHANNEL],
+ unsafe_channel[COEX_POWER_CAP_DBM])
+ return (unsafe_channel[COEX_BAND], unsafe_channel[COEX_CHANNEL])
+
+ def test_set_get_coex_unsafe_channels(self):
+ """
+ Set the unsafe channels to avoid for coex, then retrieve the active values and compare to
+ values set. If the default algorithm is enabled, then ensure that the active values are
+ unchanged.
+
+ Steps:
+ 1. Create list of coex unsafe channels and restrictions
+
+ coex_unsafe_channels format:
+ [
+ {
+ "band": <"24_GHZ" or "5_GHZ">
+ "channel" : <Channel number>
+ (Optional) "powerCapDbm" : <Power Cap in Dbm>
+ }
+ ...
+ ]
+
+ coex_restrictions format:
+ [
+ (Optional) "WIFI_DIRECT",
+ (Optional) "SOFTAP",
+ (Optional) "WIFI_AWARE"
+ ]
+
+ 2. Set these values as the active values
+ 3. Compare the current values and see if they are the same as the provided values, or if the
+ default algorithm is enabled, see if they have not changed.
+ 4. Restore the previous values if the test values were set.
+ """
+ test_unsafe_channels = sorted(self.coex_unsafe_channels,
+ key=self.coex_unsafe_channel_key)
+ test_restrictions = sorted(self.coex_restrictions)
+ prev_unsafe_channels = sorted(self.dut.droid.wifiGetCoexUnsafeChannels(),
+ key=self.coex_unsafe_channel_key)
+ prev_restrictions = sorted(self.dut.droid.wifiGetCoexRestrictions())
+ # Set the unsafe channels
+ default_algo_disabled = self.dut.droid.wifiSetCoexUnsafeChannels(
+ test_unsafe_channels, test_restrictions)
+ curr_unsafe_channels = sorted(self.dut.droid.wifiGetCoexUnsafeChannels(),
+ key=self.coex_unsafe_channel_key)
+ curr_restrictions = sorted(self.dut.droid.wifiGetCoexRestrictions())
+
+ if default_algo_disabled:
+ # Reset the previous values
+ self.dut.droid.wifiSetCoexUnsafeChannels(prev_unsafe_channels, prev_restrictions)
+ # Default algorithm is disabled, so the set values should be returned
+ asserts.assert_true(curr_unsafe_channels == test_unsafe_channels,
+ "default coex algorithm disabled but current unsafe channels "
+ "does not match the set values")
+ asserts.assert_true(curr_restrictions == test_restrictions,
+ "default coex algorithm disabled but current restrictions "
+ "does not match the set value")
+ # Restore the previous values
+ self.dut.droid.wifiSetCoexUnsafeChannels(prev_unsafe_channels, prev_restrictions)
+ else:
+ # Default algorithm is enabled, so the previous values should be returned
+ asserts.assert_true(curr_unsafe_channels == prev_unsafe_channels,
+ "default coex algorithm enabled but current unsafe channels "
+ "does not match the set values")
+
+ asserts.assert_true(curr_restrictions == prev_restrictions,
+ "default coex algorithm enabled but current restriction "
+ "does not match the previous value")