| #!/usr/bin/env python3 |
| # |
| # Copyright 2023 The Fuchsia Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import logging |
| import time |
| |
| from mobly import asserts, signals, test_runner |
| from mobly.config_parser import TestRunConfig |
| |
| from antlion.test_utils.wifi import base_test |
| |
| # Time to wait until an interface is recreated after the softmac WLAN driver |
| # restarts. |
| DELAY_FOR_DRIVER_RESTART_SEC = 2.0 |
| |
| |
| class WlanDriverRestartTest(base_test.WifiBaseTest): |
| def __init__(self, configs: TestRunConfig) -> None: |
| super().__init__(configs) |
| self.log = logging.getLogger() |
| |
| def setup_class(self) -> None: |
| super().setup_class() |
| |
| if len(self.fuchsia_devices) < 1: |
| raise signals.TestFailure("Requires at least one Fuchsia device") |
| self.fd = self.fuchsia_devices[0] |
| |
| # Skip this test suite if the device isn't running a softmac WLAN driver. |
| driver_list_resp = self.fd.ffx.run(["driver", "list"]) |
| driver_list = str(driver_list_resp.stdout, "UTF-8") |
| if not driver_list.find("iwlwifi"): |
| raise signals.TestSkip( |
| "No intel WiFi driver found on this device, skipping test" |
| ) |
| |
| def test_driver_restart_recreates_interface(self) -> None: |
| """Verify the WLAN interface gets recreated after its driver restarts.""" |
| # Store existing phy and interface identifiers. |
| phys = self.fd.sl4f.wlan_lib.get_phy_id_list() |
| asserts.assert_equal(len(phys), 1, "Expected one phy_id") |
| old_interfaces = self.fd.sl4f.wlan_lib.get_iface_id_list() |
| asserts.assert_not_equal(old_interfaces, [], "Iface not found.") |
| |
| # Restarting should replace the old interface with a new one. |
| self.fd.ffx.run( |
| [ |
| "driver", |
| "restart", |
| "fuchsia-pkg://fuchsia.com/iwlwifi#meta/iwlwifi.cm", |
| ] |
| ) |
| |
| # Check for new phy and interface identifiers. |
| timeout = time.time() + DELAY_FOR_DRIVER_RESTART_SEC |
| while time.time() < timeout: |
| new_interfaces = self.fd.sl4f.wlan_lib.get_iface_id_list() |
| |
| if new_interfaces == old_interfaces: |
| # Interface has not been deleted yet. Keep waiting. |
| time.sleep(0.1) |
| continue |
| if len(new_interfaces) == 0: |
| # Interface has not come back up yet. Keep waiting. |
| time.sleep(0.1) |
| continue |
| if len(new_interfaces) == 1: |
| # New interface has been added! All done here |
| break |
| |
| asserts.fail( |
| "More interfaces exist than before! \n" |
| f"Old: {old_interfaces}\n" |
| f"New: {new_interfaces}" |
| ) |
| else: |
| asserts.fail( |
| f"New interface not created within {DELAY_FOR_DRIVER_RESTART_SEC}s" |
| ) |
| |
| phys = self.fd.sl4f.wlan_lib.get_phy_id_list() |
| asserts.assert_equal(len(phys), 1, "Expected one phy_id") |
| |
| |
| if __name__ == "__main__": |
| test_runner.main() |