Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2020 - 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 | |
| 17 | import time |
| 18 | import random |
| 19 | import re |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 20 | import logging |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 21 | import acts_contrib.test_utils.wifi.wifi_test_utils as wutils |
| 22 | import acts_contrib.test_utils.tel.tel_test_utils as tel_utils |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 23 | import acts.utils as utils |
| 24 | from acts import asserts |
| 25 | from acts.test_decorators import test_tracker_info |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 26 | from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 27 | from acts import signals |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 28 | from acts.controllers import packet_capture |
| 29 | from acts.controllers.ap_lib.hostapd_constants import BAND_2G |
| 30 | from acts.controllers.ap_lib.hostapd_constants import BAND_5G |
| 31 | |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 32 | |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 33 | WifiEnums = wutils.WifiEnums |
| 34 | |
| 35 | |
| 36 | class WifiChannelSwitchStressTest(WifiBaseTest): |
| 37 | |
| 38 | def setup_class(self): |
| 39 | super().setup_class() |
| 40 | self.dut = self.android_devices[0] |
| 41 | self.dut_client = self.android_devices[1] |
| 42 | utils.require_sl4a((self.dut, self.dut_client)) |
| 43 | |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 44 | if hasattr(self, 'packet_capture'): |
| 45 | self.packet_capture = self.packet_capture[0] |
| 46 | |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 47 | req_params = ["dbs_supported_models"] |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 48 | opt_param = ["stress_count", "cs_count"] |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 49 | self.unpack_userparams( |
| 50 | req_param_names=req_params, opt_param_names=opt_param) |
| 51 | |
| 52 | self.AP_IFACE = 'wlan0' |
| 53 | if self.dut.model in self.dbs_supported_models: |
| 54 | self.AP_IFACE = 'wlan1' |
| 55 | |
| 56 | for ad in self.android_devices: |
| 57 | wutils.wifi_test_device_init(ad) |
| 58 | utils.sync_device_time(ad) |
Alfie Chen | d024f49 | 2020-07-23 20:12:14 +0800 | [diff] [blame] | 59 | wutils.set_wifi_country_code(ad, WifiEnums.CountryCode.US) |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 60 | |
| 61 | def setup_test(self): |
Xianyuan Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 62 | super().setup_test() |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 63 | for ad in self.android_devices: |
| 64 | ad.droid.wakeLockAcquireBright() |
| 65 | ad.droid.wakeUpNow() |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 66 | try: |
| 67 | if self.dut.droid.wifiIsApEnabled(): |
| 68 | wutils.stop_wifi_tethering(self.dut) |
| 69 | except signals.TestFailure: |
| 70 | pass |
| 71 | wutils.wifi_toggle_state(self.dut_client, True) |
| 72 | init_sim_state = tel_utils.is_sim_ready(self.log, self.dut) |
| 73 | if init_sim_state: |
| 74 | self.check_cell_data_and_enable() |
| 75 | self.config = wutils.create_softap_config() |
| 76 | self.channel_list_2g = self.generate_random_list( |
| 77 | WifiEnums.ALL_2G_FREQUENCIES) |
| 78 | self.channel_list_5g = self.generate_random_list( |
| 79 | WifiEnums.NONE_DFS_5G_FREQUENCIES) |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 80 | |
| 81 | def teardown_test(self): |
Xianyuan Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 82 | super().teardown_test() |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 83 | for ad in self.android_devices: |
| 84 | ad.droid.wakeLockRelease() |
| 85 | ad.droid.goToSleepNow() |
| 86 | wutils.reset_wifi(ad) |
| 87 | try: |
| 88 | wutils.stop_wifi_tethering(self.dut) |
| 89 | except signals.TestFailure: |
| 90 | pass |
| 91 | |
| 92 | def on_fail(self, test_name, begin_time): |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 93 | try: |
| 94 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
| 95 | except signals.TestFailure: |
| 96 | pass |
Xianyuan Jia | 97a865e | 2020-11-10 02:09:40 +0000 | [diff] [blame] | 97 | super().on_fail(test_name, begin_time) |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 98 | |
| 99 | def check_cell_data_and_enable(self): |
| 100 | """Make sure that cell data is enabled if there is a sim present. |
| 101 | |
| 102 | If a sim is active, cell data needs to be enabled to allow provisioning |
| 103 | checks through (when applicable). This is done to relax hardware |
| 104 | requirements on DUTs - without this check, running this set of tests |
| 105 | after other wifi tests may cause failures. |
| 106 | """ |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 107 | if not self.dut.droid.telephonyIsDataEnabled(): |
| 108 | self.dut.log.info("need to enable data") |
| 109 | self.dut.droid.telephonyToggleDataConnection(True) |
| 110 | asserts.assert_true(self.dut.droid.telephonyIsDataEnabled(), |
| 111 | "Failed to enable cell data for dut.") |
| 112 | |
| 113 | def get_wlan0_link(self, dut): |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 114 | """ get wlan0 interface status""" |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 115 | get_wlan0 = 'wpa_cli -iwlan0 -g@android:wpa_wlan0 IFNAME=wlan0 status' |
| 116 | out = dut.adb.shell(get_wlan0) |
| 117 | out = dict(re.findall(r'(\S+)=(".*?"|\S+)', out)) |
| 118 | asserts.assert_true("ssid" in out, |
| 119 | "Client doesn't connect to any network") |
| 120 | return out |
| 121 | |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 122 | def get_wlan1_status(self, dut): |
| 123 | """ get wlan1 interface status""" |
| 124 | get_wlan1 = 'hostapd_cli status' |
| 125 | out_wlan1 = dut.adb.shell(get_wlan1) |
| 126 | out_wlan1 = dict(re.findall(r'(\S+)=(".*?"|\S+)', out_wlan1)) |
| 127 | return out_wlan1 |
| 128 | |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 129 | def generate_random_list(self, lst): |
| 130 | """Generate a list where |
| 131 | the previous and subsequent items |
| 132 | do not repeat""" |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 133 | channel_list = [] |
| 134 | num = random.choice(lst) |
| 135 | channel_list.append(num) |
| 136 | for i in range(1, self.stress_count): |
| 137 | num = random.choice(lst) |
| 138 | while num == channel_list[-1]: |
| 139 | num = random.choice(lst) |
| 140 | channel_list.append(num) |
| 141 | return channel_list |
| 142 | |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 143 | def conf_packet_capture(self, band, channel): |
| 144 | """Configure packet capture on necessary channels.""" |
| 145 | freq_to_chan = wutils.WifiEnums.freq_to_channel[int(channel)] |
| 146 | logging.info("Capturing packets from " |
| 147 | "frequency:{}, Channel:{}".format(channel, freq_to_chan)) |
| 148 | result = self.packet_capture.configure_monitor_mode(band, freq_to_chan) |
| 149 | if not result: |
| 150 | logging.error("Failed to configure channel " |
| 151 | "for {} band".format(band)) |
| 152 | self.pcap_procs = wutils.start_pcap( |
| 153 | self.packet_capture, band, self.test_name) |
| 154 | |
| 155 | time.sleep(5) |
| 156 | |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 157 | @test_tracker_info(uuid="b1a8b00e-eca8-4eba-99e9-c7a3beb2a009") |
| 158 | def test_softap_channel_switch_stress_2g(self): |
| 159 | """ |
| 160 | 1. Disable DUT's Wi-Fi |
| 161 | 2. Enable CLIENT's Wi-Fi |
| 162 | 3. Check DUT's sim is ready or not |
| 163 | 4. Enable DUT's mobile data |
| 164 | 5. Bring up DUT's softap in 2g |
| 165 | 6. CLIENT connect to DUT |
| 166 | 7. DUT switch to different 2g channel |
| 167 | 8. Verify CLIENT follow the change |
| 168 | 9, Repeat step 7 and 8 |
| 169 | """ |
| 170 | wutils.start_wifi_tethering(self.dut, |
| 171 | self.config[wutils.WifiEnums.SSID_KEY], |
| 172 | self.config[wutils.WifiEnums.PWD_KEY], |
| 173 | WifiEnums.WIFI_CONFIG_APBAND_2G) |
| 174 | wutils.connect_to_wifi_network(self.dut_client, self.config) |
| 175 | time.sleep(10) |
| 176 | for count in range(len(self.channel_list_2g)): |
| 177 | self.dut.log.info("2g channel switch iteration : {}".format(count+1)) |
| 178 | channel_2g = str(self.channel_list_2g[count]) |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 179 | # Configure sniffer before set SoftAP channel |
| 180 | if hasattr(self, 'packet_capture'): |
| 181 | self.conf_packet_capture(BAND_2G, channel_2g) |
| 182 | # Set SoftAP channel |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 183 | wutils.set_softap_channel(self.dut, |
| 184 | self.AP_IFACE, |
| 185 | self.cs_count, channel_2g) |
| 186 | time.sleep(10) |
| 187 | softap_frequency = int(self.get_wlan1_status(self.dut)['freq']) |
| 188 | self.dut.log.info('softap frequency : {}'.format(softap_frequency)) |
| 189 | client_frequency = int(self.get_wlan0_link(self.dut_client)["freq"]) |
| 190 | self.dut_client.log.info( |
| 191 | "client frequency : {}".format(client_frequency)) |
| 192 | asserts.assert_true( |
| 193 | softap_frequency == client_frequency, |
| 194 | "hotspot frequency != client frequency") |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 195 | if hasattr(self, 'packet_capture'): |
| 196 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 197 | |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 198 | @test_tracker_info(uuid="3411cb7c-2609-433a-97b6-202a096dc71b") |
| 199 | def test_softap_channel_switch_stress_5g(self): |
| 200 | """ |
| 201 | 1. Disable DUT's Wi-Fi |
| 202 | 2. Enable CLIENT's Wi-Fi |
| 203 | 3. Check DUT's sim is ready or not |
| 204 | 4. Enable DUT's mobile data |
| 205 | 5. Bring up DUT's softap in 5g |
| 206 | 6. CLIENT connect to DUT |
| 207 | 7. DUT switch to different 5g channel |
| 208 | 8. Verify CLIENT follow the change |
| 209 | 9, Repeat step 7 and 8 |
| 210 | """ |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 211 | wutils.start_wifi_tethering(self.dut, |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 212 | self.config[wutils.WifiEnums.SSID_KEY], |
| 213 | self.config[wutils.WifiEnums.PWD_KEY], |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 214 | WifiEnums.WIFI_CONFIG_APBAND_5G) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 215 | wutils.connect_to_wifi_network(self.dut_client, self.config) |
| 216 | time.sleep(10) |
| 217 | for count in range(len(self.channel_list_5g)): |
| 218 | self.dut.log.info("5g channel switch iteration : {}".format(count+1)) |
| 219 | channel_5g = str(self.channel_list_5g[count]) |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 220 | # Configure sniffer before set SoftAP channel |
| 221 | if hasattr(self, 'packet_capture'): |
| 222 | self.conf_packet_capture(BAND_5G, channel_5g) |
| 223 | # Set SoftAP channel |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 224 | wutils.set_softap_channel(self.dut, |
| 225 | self.AP_IFACE, |
| 226 | self.cs_count, channel_5g) |
| 227 | time.sleep(10) |
| 228 | softap_frequency = int(self.get_wlan1_status(self.dut)['freq']) |
| 229 | self.dut.log.info('softap frequency : {}'.format(softap_frequency)) |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 230 | client_frequency = int(self.get_wlan0_link(self.dut_client)["freq"]) |
| 231 | self.dut_client.log.info( |
| 232 | "client frequency : {}".format(client_frequency)) |
| 233 | asserts.assert_true( |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 234 | softap_frequency == client_frequency, |
Alfie Chen | 0e932be | 2020-02-19 00:36:00 +0800 | [diff] [blame] | 235 | "hotspot frequency != client frequency") |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 236 | if hasattr(self, 'packet_capture'): |
| 237 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 238 | |
| 239 | @test_tracker_info(uuid="0f279058-119f-49fc-b8d6-fb2991cc35aa") |
| 240 | def test_softap_channel_switch_stress_2g_5g(self): |
| 241 | """ |
| 242 | 1. Disable DUT's Wi-Fi |
| 243 | 2. Enable CLIENT's Wi-Fi |
| 244 | 3. Check DUT's sim is ready or not |
| 245 | 4. Enable DUT's mobile data |
| 246 | 5. Bring up DUT's softap in 2g |
| 247 | 6. CLIENT connect to DUT |
| 248 | 7. DUT switch to different 2g channel |
| 249 | 8. Verify CLIENT follow the change |
| 250 | 9. DUT switch to 5g channel |
| 251 | 10. Verify CLIENT follow the change |
| 252 | 11. Repeat step 7 to 10 |
| 253 | """ |
| 254 | for count in range(self.stress_count): |
| 255 | self.log.info("2g 5g channel switch iteration : {}".format(count+1)) |
| 256 | wutils.start_wifi_tethering(self.dut, |
| 257 | self.config[wutils.WifiEnums.SSID_KEY], |
| 258 | self.config[wutils.WifiEnums.PWD_KEY], |
| 259 | WifiEnums.WIFI_CONFIG_APBAND_2G) |
| 260 | wutils.connect_to_wifi_network(self.dut_client, self.config) |
| 261 | self.log.info("wait 10 secs for client reconnect to dut") |
| 262 | time.sleep(10) |
| 263 | channel_2g = self.channel_list_2g[count] |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 264 | if hasattr(self, 'packet_capture'): |
| 265 | self.conf_packet_capture(BAND_2G, channel_2g) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 266 | wutils.set_softap_channel(self.dut, |
| 267 | self.AP_IFACE, |
| 268 | self.cs_count, channel_2g) |
| 269 | time.sleep(10) |
| 270 | softap_frequency = int(self.get_wlan1_status(self.dut)['freq']) |
| 271 | self.dut.log.info('softap frequency : {}'.format(softap_frequency)) |
| 272 | client_frequency = int(self.get_wlan0_link(self.dut_client)["freq"]) |
| 273 | self.dut_client.log.info( |
| 274 | "client frequency : {}".format(client_frequency)) |
| 275 | asserts.assert_true( |
| 276 | softap_frequency == client_frequency, |
| 277 | "hotspot frequency != client frequency") |
| 278 | wutils.stop_wifi_tethering(self.dut) |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 279 | if hasattr(self, 'packet_capture'): |
| 280 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 281 | self.dut.log.info('switch to SoftAP 5g') |
| 282 | |
| 283 | # switch to SoftAp 5g |
| 284 | wutils.start_wifi_tethering(self.dut, |
| 285 | self.config[wutils.WifiEnums.SSID_KEY], |
| 286 | self.config[wutils.WifiEnums.PWD_KEY], |
| 287 | WifiEnums.WIFI_CONFIG_APBAND_5G) |
| 288 | wutils.connect_to_wifi_network(self.dut_client, self.config) |
| 289 | self.log.info("wait 10 secs for client reconnect to dut") |
| 290 | time.sleep(10) |
| 291 | channel_5g = self.channel_list_5g[count] |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 292 | if hasattr(self, 'packet_capture'): |
| 293 | self.conf_packet_capture(BAND_5G, channel_5g) |
Alfie Chen | 675be87 | 2020-06-04 10:48:14 +0800 | [diff] [blame] | 294 | wutils.set_softap_channel(self.dut, |
| 295 | self.AP_IFACE, |
| 296 | self.cs_count, channel_5g) |
| 297 | time.sleep(10) |
| 298 | softap_frequency = int(self.get_wlan1_status(self.dut)['freq']) |
| 299 | self.dut.log.info('softap frequency : {}'.format(softap_frequency)) |
| 300 | client_frequency = int(self.get_wlan0_link(self.dut_client)["freq"]) |
| 301 | self.dut_client.log.info( |
| 302 | "client frequency : {}".format(client_frequency)) |
| 303 | asserts.assert_true( |
| 304 | softap_frequency == client_frequency, |
| 305 | "hotspot frequency != client frequency") |
| 306 | wutils.stop_wifi_tethering(self.dut) |
Alfie Chen | f7736ce | 2020-06-23 18:24:18 +0800 | [diff] [blame] | 307 | if hasattr(self, 'packet_capture'): |
Alfie Chen | d024f49 | 2020-07-23 20:12:14 +0800 | [diff] [blame] | 308 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |