blob: 5844e493b527d587bacf08eb578564d810a74626 [file] [log] [blame]
Junyu Lai32a2d152024-07-03 16:05:41 +08001# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from net_tests_utils.host.python import adb_utils, apf_utils, assert_utils, mdns_utils, multi_devices_test_base, tether_utils
16from net_tests_utils.host.python.tether_utils import UpstreamType
17
18COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = "DROPPED_ETHERTYPE_NOT_ALLOWED"
19
20
21class ApfV4Test(multi_devices_test_base.MultiDevicesTestBase):
22
23 def test_apf_drop_ethercat(self):
24 tether_utils.assume_hotspot_test_preconditions(
25 self.serverDevice, self.clientDevice, UpstreamType.NONE
26 )
27 client = self.clientDevice.connectivity_multi_devices_snippet
28 try:
29 server_iface_name, client_network = (
30 tether_utils.setup_hotspot_and_client_for_upstream_type(
31 self.serverDevice, self.clientDevice, UpstreamType.NONE
32 )
33 )
34 client_iface_name = client.getInterfaceNameFromNetworkHandle(
35 client_network
36 )
37
38 adb_utils.set_doze_mode(self.clientDevice, True)
39
40 count_before_test = apf_utils.get_apf_counter(
41 self.clientDevice,
42 client_iface_name,
43 COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
44 )
45 try:
46 apf_utils.send_broadcast_empty_ethercat_packet(
47 self.serverDevice, server_iface_name
48 )
49 except apf_utils.UnsupportedOperationException:
50 asserts.skip(
51 "NetworkStack is too old to support send raw packet, skip test."
52 )
53
54 assert_utils.expect_with_retry(
55 lambda: apf_utils.get_apf_counter(
56 self.clientDevice,
57 client_iface_name,
58 COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED,
59 )
60 > count_before_test
61 )
62
63 # TODO: Verify the packet is not actually received.
64 finally:
65 adb_utils.set_doze_mode(self.clientDevice, False)
66 tether_utils.cleanup_tethering_for_upstream_type(
67 self.serverDevice, UpstreamType.NONE
68 )