def run_once(self, ssid_1, ssid_2, test): """Run the test. @param ssid_1: SSID of the first AP. @param ssid_2: SSID of the second AP. @param test: Set by the server test control file depending on the test that is being run. """ self.SSID_1 = ssid_1 self.SSID_2 = ssid_2 self.TEST = test with cntc.ChromeNetworkingTestContext() as testing_context: self.chrome_net = cnta.ChromeNetworkProvider(testing_context) enabled_devices = self.chrome_net.get_enabled_devices() if (self.chrome_net.WIFI_DEVICE not in enabled_devices): self.chrome_net.enable_network_device( self.chrome_net.WIFI_DEVICE) self.chrome_net.scan_for_networks() if test == 'all': self._find_and_transition_wifi_networks_in_range() self._enable_disable_wifi() self._autoconnect_wifi() elif test in ('findVerifyWiFiNetworks', 'transitionWiFiNetworks'): self._find_and_transition_wifi_networks_in_range() elif test == 'enableDisableWiFi': self._enable_disable_wifi() elif test == 'autoconnectWiFi': self._autoconnect_wifi()
def run_once(self, idle_time=120): """Collect power stats when wifi is on or off. Args: idle_time: time in seconds to stay idle and measure power """ # Find all wired ethernet interfaces. # TODO(seankao): This block to check whether ethernet interface # is active appears in several tests. Pull this into power_utils. ifaces = [ iface for iface in interface.get_interfaces() if (not iface.is_wifi_device() and iface.name.startswith('eth')) ] logging.debug('Ethernet interfaces include: ' + str([iface.name for iface in ifaces])) for iface in ifaces: if iface.is_lower_up: raise error.TestError('Ethernet interface is active. ' 'Please remove Ethernet cable.') with cntc.ChromeNetworkingTestContext() as testing_context: self.chrome_net = cnta.ChromeNetworkProvider(testing_context) # Ensure wifi is enabled. if not self._is_wifi_on(): self.chrome_net.enable_network_device( self.chrome_net.WIFI_DEVICE) if not self._is_wifi_on(): raise error.TestError('Failed to enable wifi.') self.chrome_net.scan_for_networks() self._verify_connected_to_network() # Test system idle with wifi turned on. self.start_measurements() time.sleep(idle_time) self.checkpoint_measurements('wifi_on') # Disable wifi. self.chrome_net.disable_network_device(self.chrome_net.WIFI_DEVICE) if self._is_wifi_on(): raise error.TestError('Failed to disable wifi.') # Test system idle with wifi turned off. start_time = time.time() time.sleep(idle_time) self.checkpoint_measurements('wifi_off', start_time) # Turn on wifi before leaving the test. self.chrome_net.enable_network_device(self.chrome_net.WIFI_DEVICE)
def run_once(self, test): """Runs the test. @param test: Set by the server test control file depending on the test that is being run. """ with cntc.ChromeNetworkingTestContext() as testing_context: self._chrome_testing = testing_context self.chrome_net = cnta.ChromeNetworkProvider(testing_context) enabled_devices = self.chrome_net.get_enabled_devices() logging.debug('Enabled devices: %s', enabled_devices) if (self.chrome_net.CELLULAR not in enabled_devices): self.chrome_net.enable_network_device(self.chrome_net.CELLULAR) self.chrome_net.scan_for_networks() if test == 'autoconnectCellular': self._autoconnect_cellular() elif test == 'ethernetPreferred': self._ethernet_preferred_over_cellular() elif test == 'enableDisableCellular': self._enable_disable_cellular()
def run_once(self, ssid, test): """Run the test. @param ssid: SSID of the APs. @param test: Set by the server test control file depending on the test that is being run. """ self.SSID = ssid with cntc.ChromeNetworkingTestContext() as testing_context: self.chrome_networking = cnta.ChromeNetworkProvider( testing_context) enabled_devices = self.chrome_networking.get_enabled_devices() if (self.chrome_networking.WIFI_DEVICE not in enabled_devices): self.chrome_networking.enable_network_device( self.chrome_networking.WIFI_DEVICE) self.chrome_networking.scan_for_networks() if test == chrome_net_constants.OPEN_CONNECT: self._find_and_connect_to_configured_network() elif test == chrome_net_constants.OPEN_ROAM: self._verify_device_roamed()
def _connect(self, ssid, uname): """Connect to particular network and assert access to page. @param ssid string - predefined SSID from user's preferred networks @param uname string - predefined username of managed user @return boolean - True if able to connect, False otherwise """ start_time = time.time() with cntc.ChromeNetworkingTestContext(username=uname, password=constants.PASSWORD, gaia_login=True) as \ testing_context: net_provider = cnta.ChromeNetworkProvider(testing_context) enabled_devices = net_provider.get_enabled_devices() if net_provider.WIFI_DEVICE not in enabled_devices: net_provider.enable_network_device(net_provider.WIFI_DEVICE) logging.info('Scanning for networks') connect_to_service = None while time.time() - start_time < constants.SCAN_RETRY_TIMEOUT: net_provider.scan_for_networks(timeout=20) logging.info('Attempting to connect to %s', ssid) networks = net_provider.get_wifi_networks() for service in networks: if service['Name'] == ssid: connect_to_service = service if not connect_to_service: logging.error('Unable to find %s', ssid) continue try: net_provider.connect_to_network(connect_to_service) logging.info('Successfully connected to network %s', ssid) return True except error.TestFail as e: logging.error('Unable to connect to %s', ssid) continue return False
def __init__(self, browser=None): testing_context = cntc.ChromeNetworkingTestContext() testing_context.setup(browser) self.chrome_net_context = cnta.ChromeNetworkProvider(testing_context) self.enable_wifi_on_dut()