1#!/usr/bin/env python3 2# 3# Copyright 2021 - The Android secure 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 17from acts import signals 18import time 19from acts.base_test import BaseTestClass 20from acts_contrib.test_utils.abstract_devices.wlan_device import create_wlan_device 21 22 23class ToggleWlanInterfaceStressTest(BaseTestClass): 24 25 def setup_class(self): 26 dut = self.user_params.get('dut', None) 27 if dut: 28 if dut == 'fuchsia_devices': 29 self.dut = create_wlan_device(self.fuchsia_devices[0]) 30 elif dut == 'android_devices': 31 self.dut = create_wlan_device(self.android_devices[0]) 32 else: 33 raise ValueError('Invalid DUT specified in config. (%s)' % 34 self.user_params['dut']) 35 else: 36 # Default is an Fuchsia device 37 self.dut = create_wlan_device(self.fuchsia_devices[0]) 38 39 def test_iface_toggle_and_ping(self): 40 """Test that we don't error out when toggling WLAN interfaces. 41 42 Steps: 43 1. Find a WLAN interface 44 2. Destroy it 45 3. Create a new WLAN interface 46 4. Ping after association 47 5. Repeat 1-4 1,000 times 48 49 Expected Result: 50 Verify there are no errors in destroying the wlan interface. 51 52 Returns: 53 signals.TestPass if no errors 54 signals.TestFailure if there are any errors during the test. 55 56 TAGS: WLAN, Stability 57 Priority: 1 58 """ 59 60 # Test assumes you've already connected to some AP. 61 62 for i in range(1000): 63 wlan_interfaces = self.dut.get_wlan_interface_id_list() 64 print(wlan_interfaces) 65 if len(wlan_interfaces) < 1: 66 raise signals.TestFailure( 67 "Not enough wlan interfaces for test") 68 if not self.dut.destroy_wlan_interface(wlan_interfaces[0]): 69 raise signals.TestFailure("Failed to destroy WLAN interface") 70 # Really make sure it is dead 71 self.fuchsia_devices[0].ssh.run( 72 f"wlan iface del {wlan_interfaces[0]}") 73 # Grace period 74 time.sleep(2) 75 self.fuchsia_devices[0].ssh.run( 76 'wlan iface new --phy 0 --role Client') 77 end_time = time.time() + 300 78 while time.time() < end_time: 79 time.sleep(1) 80 if self.dut.is_connected(): 81 try: 82 ping_result = self.dut.ping("8.8.8.8", 10, 1000, 1000, 83 25) 84 print(ping_result) 85 except Exception as err: 86 # TODO: Once we gain more stability, fail test when pinging fails 87 print("some err {}".format(err)) 88 time.sleep(2) #give time for some traffic 89 break 90 if not self.dut.is_connected(): 91 raise signals.TestFailure("Failed at iteration {}".format(i + 92 1)) 93 self.log.info("Iteration {} successful".format(i + 1)) 94 raise signals.TestPass("Success") 95