Fix test_hotspot_upstream_cellular failure
This change:
1. Move precondition checks prior to setup hotspot.
This removes the need of redundant clean-up if
the device doesn't meet preconditions.
2. Use unregisterAll instead of unregisterCell to
clean-up registered connections to prevent from
complex error handling in clean-up stage.
Test: m connectivity_multi_devices_snippet && \
atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Fix: 345110845
Change-Id: I4de0e7401d52f891948eb7b5a8c112a837cb0c3e
diff --git a/tests/cts/multidevices/connectivity_multi_devices_test.py b/tests/cts/multidevices/connectivity_multi_devices_test.py
index 417db99..1d6fb51 100644
--- a/tests/cts/multidevices/connectivity_multi_devices_test.py
+++ b/tests/cts/multidevices/connectivity_multi_devices_test.py
@@ -34,6 +34,9 @@
)
def test_hotspot_upstream_wifi(self):
+ tether_utils.assume_hotspot_test_preconditions(
+ self.serverDevice, self.clientDevice, UpstreamType.WIFI
+ )
try:
# Connectivity of the client verified by asserting the validated capability.
tether_utils.setup_hotspot_and_client_for_upstream_type(
@@ -45,6 +48,9 @@
)
def test_hotspot_upstream_cellular(self):
+ tether_utils.assume_hotspot_test_preconditions(
+ self.serverDevice, self.clientDevice, UpstreamType.CELLULAR
+ )
try:
# Connectivity of the client verified by asserting the validated capability.
tether_utils.setup_hotspot_and_client_for_upstream_type(
diff --git a/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt b/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt
index 8805edd..f4ad2c4 100644
--- a/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt
+++ b/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt
@@ -77,9 +77,9 @@
ctsNetUtils.expectNetworkIsSystemDefault(network)
}
- @Rpc(description = "Unrequest cellular connection.")
- fun unrequestCellular() {
- cbHelper.unrequestCell()
+ @Rpc(description = "Unregister all connections.")
+ fun unregisterAll() {
+ cbHelper.unregisterAll()
}
@Rpc(description = "Ensure any wifi is connected and is the default network.")
diff --git a/tests/cts/multidevices/tether_utils.py b/tests/cts/multidevices/tether_utils.py
index a2d703c..61f5c43 100644
--- a/tests/cts/multidevices/tether_utils.py
+++ b/tests/cts/multidevices/tether_utils.py
@@ -46,6 +46,32 @@
return base64.b64encode(uuid.uuid1().bytes).decode("utf-8").strip("=")
+def assume_hotspot_test_preconditions(
+ server_device: android_device,
+ client_device: android_device,
+ upstream_type: UpstreamType,
+) -> None:
+ server = server_device.connectivity_multi_devices_snippet
+ client = client_device.connectivity_multi_devices_snippet
+
+ # Assert pre-conditions specific to each upstream type.
+ asserts.skip_if(not client.hasWifiFeature(), "Client requires Wifi feature")
+ asserts.skip_if(
+ not server.hasHotspotFeature(), "Server requires hotspot feature"
+ )
+ if upstream_type == UpstreamType.CELLULAR:
+ asserts.skip_if(
+ not server.hasTelephonyFeature(), "Server requires Telephony feature"
+ )
+ elif upstream_type == UpstreamType.WIFI:
+ asserts.skip_if(
+ not server.isStaApConcurrencySupported(),
+ "Server requires Wifi AP + STA concurrency",
+ )
+ else:
+ raise ValueError(f"Invalid upstream type: {upstream_type}")
+
+
def setup_hotspot_and_client_for_upstream_type(
server_device: android_device,
client_device: android_device,
@@ -60,21 +86,9 @@
server = server_device.connectivity_multi_devices_snippet
client = client_device.connectivity_multi_devices_snippet
- # Assert pre-conditions specific to each upstream type.
- asserts.skip_if(not client.hasWifiFeature(), "Client requires Wifi feature")
- asserts.skip_if(
- not server.hasHotspotFeature(), "Server requires hotspot feature"
- )
if upstream_type == UpstreamType.CELLULAR:
- asserts.skip_if(
- not server.hasTelephonyFeature(), "Server requires Telephony feature"
- )
server.requestCellularAndEnsureDefault()
elif upstream_type == UpstreamType.WIFI:
- asserts.skip_if(
- not server.isStaApConcurrencySupported(),
- "Server requires Wifi AP + STA concurrency",
- )
server.ensureWifiIsDefault()
else:
raise ValueError(f"Invalid upstream type: {upstream_type}")
@@ -98,6 +112,6 @@
) -> None:
server = server_device.connectivity_multi_devices_snippet
if upstream_type == UpstreamType.CELLULAR:
- server.unrequestCellular()
+ server.unregisterAll()
# Teardown the hotspot.
server.stopAllTethering()