Refactor ApfV4Test
This is a no-op refactoring, which is preparation for follow-up
changes to add more apf test classes.
This includes:
1. Move initialization code to a base class, which setup a hotspot
and a client connects to it, and enable doze mode to
activate the apf.
2. Check whether send raw packet is supported before testing.
Test: m connectivity_multi_devices_snippet && \
atest CtsConnectivityMultiDevicesTestCases
Test: atest NetworkStaticLibHostPythonTests
Bug: 350880989
Change-Id: I6376935883653182728e473e2f5533407d993d7b
diff --git a/tests/cts/multidevices/apfv4_test.py b/tests/cts/multidevices/apfv4_test.py
index 5844e49..7652c65 100644
--- a/tests/cts/multidevices/apfv4_test.py
+++ b/tests/cts/multidevices/apfv4_test.py
@@ -12,57 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from net_tests_utils.host.python import adb_utils, apf_utils, assert_utils, mdns_utils, multi_devices_test_base, tether_utils
+from mobly import asserts
+from net_tests_utils.host.python import adb_utils, apf_test_base, apf_utils, assert_utils, tether_utils
from net_tests_utils.host.python.tether_utils import UpstreamType
COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = "DROPPED_ETHERTYPE_NOT_ALLOWED"
-class ApfV4Test(multi_devices_test_base.MultiDevicesTestBase):
+class ApfV4Test(apf_test_base.ApfTestBase):
def test_apf_drop_ethercat(self):
- tether_utils.assume_hotspot_test_preconditions(
- self.serverDevice, self.clientDevice, UpstreamType.NONE
+ count_before_test = apf_utils.get_apf_counter(
+ self.clientDevice,
+ self.client_iface_name,
+ COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
)
- client = self.clientDevice.connectivity_multi_devices_snippet
- try:
- server_iface_name, client_network = (
- tether_utils.setup_hotspot_and_client_for_upstream_type(
- self.serverDevice, self.clientDevice, UpstreamType.NONE
- )
- )
- client_iface_name = client.getInterfaceNameFromNetworkHandle(
- client_network
- )
+ apf_utils.send_broadcast_empty_ethercat_packet(
+ self.serverDevice, self.server_iface_name
+ )
- adb_utils.set_doze_mode(self.clientDevice, True)
-
- count_before_test = apf_utils.get_apf_counter(
- self.clientDevice,
- client_iface_name,
- COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
- )
- try:
- apf_utils.send_broadcast_empty_ethercat_packet(
- self.serverDevice, server_iface_name
+ assert_utils.expect_with_retry(
+ lambda: apf_utils.get_apf_counter(
+ self.clientDevice,
+ self.client_iface_name,
+ COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
)
- except apf_utils.UnsupportedOperationException:
- asserts.skip(
- "NetworkStack is too old to support send raw packet, skip test."
- )
+ > count_before_test
+ )
- assert_utils.expect_with_retry(
- lambda: apf_utils.get_apf_counter(
- self.clientDevice,
- client_iface_name,
- COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
- )
- > count_before_test
- )
-
- # TODO: Verify the packet is not actually received.
- finally:
- adb_utils.set_doze_mode(self.clientDevice, False)
- tether_utils.cleanup_tethering_for_upstream_type(
- self.serverDevice, UpstreamType.NONE
- )
+ # TODO: Verify the packet is not actually received.