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')