From 26c81bd9a3ec3bb716b430f8db96198b2d595fc8 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Wed, 12 Jun 2024 10:45:46 +0800 Subject: [PATCH] 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 --- .../connectivity_multi_devices_test.py | 6 +++ .../ConnectivityMultiDevicesSnippet.kt | 6 +-- tests/cts/multidevices/tether_utils.py | 40 +++++++++++++------ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tests/cts/multidevices/connectivity_multi_devices_test.py b/tests/cts/multidevices/connectivity_multi_devices_test.py index 417db99711..1d6fb51292 100644 --- a/tests/cts/multidevices/connectivity_multi_devices_test.py +++ b/tests/cts/multidevices/connectivity_multi_devices_test.py @@ -34,6 +34,9 @@ class ConnectivityMultiDevicesTest(base_test.BaseTestClass): ) 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 @@ class ConnectivityMultiDevicesTest(base_test.BaseTestClass): ) 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 8805edd818..f4ad2c4288 100644 --- a/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt +++ b/tests/cts/multidevices/snippet/ConnectivityMultiDevicesSnippet.kt @@ -77,9 +77,9 @@ class ConnectivityMultiDevicesSnippet : Snippet { 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 a2d703ca56..61f5c43f0e 100644 --- a/tests/cts/multidevices/tether_utils.py +++ b/tests/cts/multidevices/tether_utils.py @@ -46,6 +46,32 @@ def generate_uuid32_base64() -> str: 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 @@ def setup_hotspot_and_client_for_upstream_type( 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 @@ def cleanup_tethering_for_upstream_type( ) -> None: server = server_device.connectivity_multi_devices_snippet if upstream_type == UpstreamType.CELLULAR: - server.unrequestCellular() + server.unregisterAll() # Teardown the hotspot. server.stopAllTethering()