From 419e088796b798179ca7bd9cac418b9ead3dae6f Mon Sep 17 00:00:00 2001 From: Jimi Chen Date: Mon, 14 Jul 2025 14:24:42 +0000 Subject: [PATCH 1/2] refactor: Lazy load IP addresses for APF tests Previously, IPv4 and IPv6 addresses were retrieved in `ApfTestBase.setup_class`, which meant all APF tests assumed the presence of both. This change refactors `ApfTestBase` to introduce dedicated methods: - `get_and_expect_ipv4_addresses_exist()` - `get_and_expect_ipv6_addresses_exist()` These methods now handle the retrieval and assertion of IP addresses. Individual test cases in `ApfV6Test` are updated to call these methods only when the respective address type is required for the specific test scenario. This improves test robustness by ensuring tests only depend on the necessary IP addresses, allowing for more precise test setup and failure reporting. Additionally, the doze mode activation is reordered to occur after initial network setup. Flag: EXEMPT mainline Bug: 419427388 Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test Change-Id: I340bcb77fe66cc9927dcd58e5899cdf9a4375daa --- .../testutils/host/python/apf_test_base.py | 48 ++++++++++++++----- tests/cts/multidevices/apfv6_test.py | 12 +++++ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/staticlibs/testutils/host/python/apf_test_base.py b/staticlibs/testutils/host/python/apf_test_base.py index 1ccf0ab423..a9ebca959e 100644 --- a/staticlibs/testutils/host/python/apf_test_base.py +++ b/staticlibs/testutils/host/python/apf_test_base.py @@ -61,18 +61,6 @@ class ApfTestBase(multi_devices_test_base.MultiDevicesTestBase): self.client_mac_address = apf_utils.get_hardware_address( self.clientDevice, self.client_iface_name ) - self.server_ipv4_addresses = apf_utils.get_ipv4_addresses( - self.serverDevice, self.server_iface_name - ) - self.client_ipv4_addresses = apf_utils.get_ipv4_addresses( - self.clientDevice, self.client_iface_name - ) - self.server_ipv6_addresses = apf_utils.get_non_tentative_ipv6_addresses( - self.serverDevice, self.server_iface_name - ) - self.client_ipv6_addresses = apf_utils.get_non_tentative_ipv6_addresses( - self.clientDevice, self.client_iface_name - ) # Enable doze mode to activate APF. adb_utils.set_doze_mode(self.clientDevice, True) @@ -83,6 +71,42 @@ class ApfTestBase(multi_devices_test_base.MultiDevicesTestBase): self.serverDevice, UpstreamType.NONE ) + def get_and_expect_ipv4_addresses_exist(self): + self.server_ipv4_addresses = apf_utils.get_ipv4_addresses( + self.serverDevice, self.server_iface_name + ) + + asserts.assert_true( + self.server_ipv4_addresses, + 'Server does not have IPv4 address, fail the test.', + ) + + self.client_ipv4_addresses = apf_utils.get_ipv4_addresses( + self.clientDevice, self.client_iface_name + ) + asserts.assert_true( + self.client_ipv4_addresses, + 'Client does not have IPv4 address, fail the test.', + ) + + def get_and_expect_ipv6_addresses_exist(self): + self.server_ipv6_addresses = apf_utils.get_non_tentative_ipv6_addresses( + self.serverDevice, self.server_iface_name + ) + + asserts.assert_true( + self.server_ipv6_addresses, + 'Server does not have IPv6 address, fail the test.', + ) + + self.client_ipv6_addresses = apf_utils.get_non_tentative_ipv6_addresses( + self.clientDevice, self.client_iface_name + ) + asserts.assert_true( + self.client_ipv6_addresses, + 'Client does not have IPv6 address, fail the test.', + ) + def send_packet_and_expect_counter_increased( self, packet: str, counter_name: str ) -> None: diff --git a/tests/cts/multidevices/apfv6_test.py b/tests/cts/multidevices/apfv6_test.py index dc68ee8e13..fec3b516da 100644 --- a/tests/cts/multidevices/apfv6_test.py +++ b/tests/cts/multidevices/apfv6_test.py @@ -56,6 +56,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): super().teardown_class() def test_unicast_arp_request_offload(self): + self.get_and_expect_ipv4_addresses_exist() + # Longer wait time is required for APF to become active in CTS test suite. time.sleep(apf_test_base.APF_ACTIVATION_WAIT_TIME_SEC) self.expect_apf_offload_enabled('ARP') @@ -89,6 +91,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): ) def test_non_dad_ipv6_neighbor_solicitation_offload(self): + self.get_and_expect_ipv6_addresses_exist() + # Longer wait time is required for APF to become active in CTS test suite. time.sleep(apf_test_base.APF_ACTIVATION_WAIT_TIME_SEC) self.expect_apf_offload_enabled('ND') @@ -116,6 +120,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): @apf_utils.at_least_B() def test_ipv4_icmp_echo_request_offload(self): + self.get_and_expect_ipv4_addresses_exist() + # Longer wait time is required for APF to become active in CTS test suite. time.sleep(apf_test_base.APF_ACTIVATION_WAIT_TIME_SEC) self.expect_apf_offload_enabled('Ping4') @@ -140,6 +146,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): @apf_utils.at_least_B() @apf_utils.apf_ram_at_least(3000) def test_ipv6_icmp_echo_request_offload(self): + self.get_and_expect_ipv6_addresses_exist() + # Longer wait time is required for APF to become active in CTS test suite. time.sleep(apf_test_base.APF_ACTIVATION_WAIT_TIME_SEC) self.expect_apf_offload_enabled('Ping6') @@ -166,6 +174,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): @apf_utils.at_least_B() def test_igmpv3_general_query_offload(self): + self.get_and_expect_ipv4_addresses_exist() + mcast_addrs = ['239.0.0.1', '239.0.0.2', '239.0.0.3'] self.client.createMulticastSocket(self.client_iface_name) @@ -214,6 +224,8 @@ class ApfV6Test(apf_test_base.ApfTestBase): @apf_utils.at_least_B() @apf_utils.apf_ram_at_least(3000) def test_mldv2_general_query_offload(self): + self.get_and_expect_ipv6_addresses_exist() + # Longer wait time is required for APF to become active in CTS test suite. time.sleep(apf_test_base.APF_ACTIVATION_WAIT_TIME_SEC) self.expect_apf_offload_enabled('MLD') From e42fb901b936f56f83385011898156dee2397e4c Mon Sep 17 00:00:00 2001 From: Jimi Chen Date: Tue, 15 Jul 2025 07:12:12 +0000 Subject: [PATCH 2/2] Simplify APF IGMPv3 general query offload test Reduce the number of multicast addresses used in `test_igmpv3_general_query_offload` to simplify the test case and focus on the core functionality. Flag: EXEMPT mainline Bug: 419427388 Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test Change-Id: I332c8d43bd89a444728ed7ebde3f4e064e4e39aa --- tests/cts/multidevices/apfv6_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cts/multidevices/apfv6_test.py b/tests/cts/multidevices/apfv6_test.py index fec3b516da..6125e891d4 100644 --- a/tests/cts/multidevices/apfv6_test.py +++ b/tests/cts/multidevices/apfv6_test.py @@ -176,7 +176,7 @@ class ApfV6Test(apf_test_base.ApfTestBase): def test_igmpv3_general_query_offload(self): self.get_and_expect_ipv4_addresses_exist() - mcast_addrs = ['239.0.0.1', '239.0.0.2', '239.0.0.3'] + mcast_addrs = ['239.0.0.1'] self.client.createMulticastSocket(self.client_iface_name) for addr in mcast_addrs: