blob: 7e6d58ffd77ce59c5a324fff2b154527969056b8 [file] [log] [blame]
Jaineel7e67a3f2019-08-28 15:58:49 -07001#!/usr/bin/env python3
2#
3# Copyright 2019 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import time
18
19from acts import asserts
20from acts.test_decorators import test_tracker_info
21from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
22import acts.test_utils.wifi.wifi_test_utils as wutils
23
24WifiEnums = wutils.WifiEnums
25NUM_LINK_PROBES = 8
26PROBE_DELAY_SEC = 3
27ATTENUATION = 40
28
29
30class WifiLinkProbeTest(WifiBaseTest):
31 """
32 Tests sending 802.11 Probe Request frames to the currently connected AP to
33 determine if the uplink to the AP is working.
34
35 Test Bed Requirements:
36 * One Android Device
37 * One Wi-Fi network visible to the device, with an attenuator
38 """
39
Jaineel7e67a3f2019-08-28 15:58:49 -070040 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070041 super().setup_class()
42
Jaineel7e67a3f2019-08-28 15:58:49 -070043 self.dut = self.android_devices[0]
44 wutils.wifi_test_device_init(self.dut)
45 self.unpack_userparams(req_param_names=[],
46 opt_param_names=["reference_networks"])
47
48 if "AccessPoint" in self.user_params:
49 self.legacy_configure_ap_and_start()
50
51 asserts.assert_true(len(self.reference_networks) > 0,
52 "Need at least one reference network with psk.")
53 self.attenuators = wutils.group_attenuators(self.attenuators)
54
55 def setup_test(self):
56 self.dut.droid.wakeLockAcquireBright()
57 self.dut.droid.wakeUpNow()
58 wutils.wifi_toggle_state(self.dut, True)
59 self.attenuators[0].set_atten(0)
60 self.attenuators[1].set_atten(0)
61
62 def teardown_test(self):
63 self.dut.droid.wakeLockRelease()
64 self.dut.droid.goToSleepNow()
65 wutils.reset_wifi(self.dut)
66
67 def on_fail(self, test_name, begin_time):
68 self.dut.take_bug_report(test_name, begin_time)
69 self.dut.cat_adb_log(test_name, begin_time)
70
71 def teardown_class(self):
72 if "AccessPoint" in self.user_params:
73 del self.user_params["reference_networks"]
74
75 # HELPER METHODS
76
77 def _test_link_probe_does_not_crash_device(self, network):
78 """
79 Connect to a network, send link probes, and verify that the device did
80 not crash. Also verify that at least one link probe succeeded.
81
82 Steps:
83 1. Connect to a network.
84 2. Send a few link probes.
85 3. Verify that at least one link probe succeeded.
86 4. Ensure that the device did not crash (by checking that it is
87 connected to the expected network).
88 """
89 wutils.wifi_connect(self.dut, network, num_of_tries=3)
90
91 results = wutils.send_link_probes(
92 self.dut, NUM_LINK_PROBES, PROBE_DELAY_SEC)
93
94 asserts.assert_true(any(result.is_success for result in results),
95 "Expect at least 1 probe success: " + str(results))
96
97 wifi_info = self.dut.droid.wifiGetConnectionInfo()
98 expected = network[WifiEnums.SSID_KEY]
99 actual = wifi_info[WifiEnums.SSID_KEY]
100 asserts.assert_equal(
101 expected, actual,
102 "Device did not remain connected after sending link probes!")
103
104 def _test_link_probe_ap_attenuated(self, network):
105 """
106 Connect to a network, significantly attenuate the signal, and verify
107 that the device did not crash.
108
109 Steps:
110 1. Connect to a network.
111 2. Attenuate the signal.
112 3. Send a few link probes.
113 4. Stop attenuating the signal.
114 5. Ensure that the device did not crash (by checking that it is
115 connected to the expected network).
116 """
117 wutils.wifi_connect(self.dut, network, num_of_tries=3)
118 self.attenuators[0].set_atten(ATTENUATION)
119
120 wutils.send_link_probes(self.dut, NUM_LINK_PROBES, PROBE_DELAY_SEC)
121
122 # we cannot assert for failed link probe when attenuated, this would
123 # depend too much on the attenuator setup => too flaky
124
125 self.attenuators[0].set_atten(0)
126 time.sleep(PROBE_DELAY_SEC * 3)
127 wifi_info = self.dut.droid.wifiGetConnectionInfo()
128 expected = network[WifiEnums.SSID_KEY]
129 actual = wifi_info[WifiEnums.SSID_KEY]
130 asserts.assert_equal(
131 expected, actual,
132 "Device did not remain connected after sending link probes!")
133
134 # TEST METHODS
135
136 @test_tracker_info(uuid='2afd309b-6bf3-4de4-9d8a-e4d35354a2cb')
137 def test_link_probe_does_not_crash_device_2g(self):
138 network = self.reference_networks[0]["2g"]
139 self._test_link_probe_does_not_crash_device(network)
140
141 @test_tracker_info(uuid='69417a6d-7090-4dd0-81ad-55fa3f12b7b1')
142 def test_link_probe_does_not_crash_device_5g(self):
143 network = self.reference_networks[0]["5g"]
144 self._test_link_probe_does_not_crash_device(network)
145
146 @test_tracker_info(uuid='54b8ffaa-c305-4772-928d-03342c51122d')
147 def test_link_probe_ap_attenuated_2g(self):
148 network = self.reference_networks[0]["2g"]
149 self._test_link_probe_ap_attenuated(network)
150
151 @test_tracker_info(uuid='54e29fa4-ff44-4aad-8999-676b361cacf4')
152 def test_link_probe_ap_attenuated_5g(self):
153 network = self.reference_networks[0]["5g"]
154 self._test_link_probe_ap_attenuated(network)
155