1 # Copyright (c) 2014 The Chromium 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 logging 6 import time 7 8 from autotest_lib.client.bin import test 9 from autotest_lib.client.bin import utils 10 from autotest_lib.client.common_lib import error 11 from autotest_lib.client.common_lib.cros.network import iw_runner 12 13 14 class network_WlanRegulatory(test.test): 15 """ 16 Ensure the "crda" tool works, and can be successfully triggered by 17 the kernel from the "iw" userspace utility to change the system 18 regulatory domain. 19 """ 20 version = 1 21 REGULATORY_DATABASE = '/usr/lib/crda/regulatory.bin' 22 23 def get_regulatory_domains(self): 24 """Get the list or regulatory domains in the DUT's database.""" 25 return utils.system_output('regdbdump %s | grep country | ' 26 'sed -e s/^country.// -e s/:.*//' % 27 self.REGULATORY_DATABASE).split() 28 29 30 def assert_set_regulatory_domain(self, regdomain): 31 """Set the system regulatory domain, then assert that it is correct. 32 33 @param regdomain string 2-letter country code of the regulatory 34 domain to set. 35 36 """ 37 logging.info('Using iw to set regulatory domain to %s', regdomain) 38 self._iw.set_regulatory_domain(regdomain) 39 40 # It takes time for the kernel to invoke udev, which will in turn 41 # invoke CRDA. Since this is asynchronous with the exit of the 42 # "iw" utility, we must wait a while. 43 time.sleep(1) 44 45 current_regdomain = self._iw.get_regulatory_domain() 46 if current_regdomain != regdomain: 47 raise error.TestFail('Expected iw to set regdomain %s but got %s' % 48 (regdomain, current_regdomain)) 49 50 51 def run_once(self): 52 """Test main loop""" 53 self._iw = iw_runner.IwRunner() 54 initial_regdomain = self._iw.get_regulatory_domain() 55 logging.info('Initial regulatory domain is %s', initial_regdomain) 56 57 domain_list = self.get_regulatory_domains() 58 if not domain_list: 59 raise error.TestFail('Did not get a domain list from the database') 60 61 for domain in domain_list: 62 self.assert_set_regulatory_domain(domain) 63 self.assert_set_regulatory_domain(initial_regdomain) 64