1 # Copyright 2015 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import time 6 7 from autotest_lib.client.common_lib import error 8 from autotest_lib.server import autotest 9 from autotest_lib.server import site_linux_system 10 from autotest_lib.server.cros.network import hostap_config 11 from autotest_lib.server.cros.network import wifi_cell_test_base 12 from autotest_lib.client.common_lib.cros.network \ 13 import chrome_net_constants 14 15 class network_WiFi_RoamSuspendEndToEnd(wifi_cell_test_base.WiFiCellTestBase): 16 """Base class that configures two APs with the same SSID that will be used 17 by RoamWifiEndToEnd client test to test networking UI. 18 19 The test is run in two phases. First, where we configure the first AP and 20 trigger the client test. Second, where we Suspend/Resume the DUT using servo 21 and configure a second AP, tear down the first and trigger client side test. 22 23 """ 24 version = 1 25 26 27 def _config_ap(self, channel, mode, ssid=None): 28 """Configure an AP with the given parameters. 29 30 @param channel: int Wifi channel to conduct test on. 31 @param ssid: Name to be assigned to the Wifi network. 32 @param mode: Mode for the AP configuration. 33 34 """ 35 ap_config = hostap_config.HostapConfig(channel=channel, mode=mode, 36 ssid=ssid) 37 self.context.configure(ap_config, multi_interface=True) 38 39 40 def _do_suspend_deconfig(self, timeout_seconds): 41 """Suspend the DUT and deconfigure the AP. 42 43 @param timeout_seconds: Number of seconds to suspend the DUT. 44 45 """ 46 if self._host.servo.get('lid_open') == 'not_applicable': 47 self.context.client.do_suspend_bg(timeout_seconds) 48 self.context.router.deconfig_aps(instance=0) 49 else: 50 self._host.servo.lid_close() 51 self._host.wait_down(timeout=timeout_seconds) 52 self.context.router.deconfig_aps(instance=0) 53 self._host.servo.lid_open() 54 self._host.wait_up(timeout=timeout_seconds) 55 56 57 def run_once(self, host): 58 """Set up two APs, run the client side test and then exit. 59 60 """ 61 self.context.router.require_capabilities( 62 [site_linux_system.LinuxSystem.CAPABILITY_MULTI_AP]) 63 self.context.router.deconfig() 64 self._host = host 65 66 if not self._host.servo: 67 raise error.TestNAError( 68 'Servo object returned None. Check if servo is missing or bad') 69 70 # Configure first AP with channel 5 and mode G and default ssid. 71 self._config_ap(5, hostap_config.HostapConfig.MODE_11G) 72 73 client_at = autotest.Autotest(self._host) 74 ssid = self.context.router.get_ssid(instance=0) 75 time.sleep(chrome_net_constants.LONG_TIMEOUT) 76 client_at.run_test('network_RoamWifiEndToEnd', 77 ssid=ssid, test=chrome_net_constants.OPEN_CONNECT) 78 79 # Configure second AP with channel 149, mode N and same ssid as before. 80 self._config_ap(149, hostap_config.HostapConfig.MODE_11N_PURE, ssid) 81 ssid = self.context.router.get_ssid(instance=1) 82 83 # Suspend the DUT for 15 seconds and tear down the first AP. 84 self._do_suspend_deconfig(15) 85 client_at.run_test('network_RoamWifiEndToEnd', 86 ssid=ssid, test=chrome_net_constants.OPEN_ROAM) 87 self.context.router.deconfig() 88