1d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley# Use of this source code is governed by a BSD-style license that can be 3d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley# found in the LICENSE file. 4d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 5cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wileyimport logging 6cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 7d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wileyfrom autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes 899d42c95fa5c12285fb129b50445a60c9a145dd3Christopher Wileyfrom autotest_lib.server.cros.network import hostap_config 94961e848f54cb64f911c3ce03b3c377d171b35e5Christopher Wileyfrom autotest_lib.server.cros.network import wifi_cell_test_base 10d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 11d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 12e740d58afe535827ec234d02f23b2baa4c720928Christopher Wileyclass network_WiFi_Powersave(wifi_cell_test_base.WiFiCellTestBase): 13d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley """Test that we can enter and exit powersave mode without issue.""" 14d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley version = 1 15d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 16cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley def check_powersave(self, should_be_on): 17cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley """Raises an exception if powersave value is other than expected. 18cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 19cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley @param should_be_on: bool True iff powersave mode should be on 20cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley for the WiFi Phy on the device under test. 21cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 22cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley """ 23cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley expected_state = 'enabled' if should_be_on else 'disabled' 24cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley if should_be_on != self.context.client.powersave_on: 25cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley raise error.TestFail('Expected powersave mode to be %s but it ' 26cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 'was not.' % expected_state) 27cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 28cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley logging.debug('Power save is indeed %s.', expected_state) 29cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley 30d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 313e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley def run_once(self): 32d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley """Test body. 33d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 34d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley Powersave mode takes advantage of DTIM intervals, and so the two 35d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley are intimately tied. See network_WiFi_DTIMPeriod for a discussion 36d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley of their interaction. 37d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley 38d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley """ 39d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley dtim_val = 5 40d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley configuration = hostap_config.HostapConfig( 41d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley frequency=2437, 42d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley mode=hostap_config.HostapConfig.MODE_11G, 43d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley dtim_period=dtim_val) 44d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley self.context.configure(configuration) 45cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley self.check_powersave(False) 46d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley assoc_params = xmlrpc_datatypes.AssociationParameters() 47d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley assoc_params.ssid = self.context.router.get_ssid() 48d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley self.context.client.powersave_switch(True) 49cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley self.check_powersave(True) 503e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley self.context.assert_connect_wifi(assoc_params) 513e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley self.context.assert_ping_from_dut() 523e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley self.context.assert_ping_from_server() 53d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley self.context.client.shill.disconnect(assoc_params.ssid) 54d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley self.context.client.powersave_switch(False) 55cd8f12b3175188ebc24f2a9916276c56b6d25101Christopher Wiley self.check_powersave(False) 56d1d3b6a91a45a51e98c410936c27debc428c6e45Christopher Wiley self.context.router.deconfig() 57