Home | History | Annotate | Download | only in network_WiFiCaps
      1 # Copyright (c) 2009 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 logging, os, re, string
      6 
      7 from autotest_lib.client.bin import test, utils
      8 from autotest_lib.client.common_lib import error
      9 
     10 class network_WiFiCaps(test.test):
     11     version = 1
     12 
     13     def setup(self):
     14         self.job.setup_dep(['iwcap'])
     15         # create a empty srcdir to prevent the error that checks .version
     16         if not os.path.exists(self.srcdir):
     17             os.mkdir(self.srcdir)
     18 
     19 
     20     def __parse_iwcap(self, lines):
     21         """Parse the iwcap output"""
     22 
     23         results = {}
     24         parse_re = re.compile(r'([a-z0-9]*):[ ]*(.*)')
     25         for line in lines.split('\n'):
     26             line = line.rstrip()
     27             logging.info('==> %s' %line)
     28             match = parse_re.search(line)
     29             if match:
     30                 results[match.group(1)] = match.group(2)
     31                 continue
     32         return results
     33 
     34 
     35     def __run_iwcap(self, phy, caps):
     36         dir = os.path.join(self.autodir, 'deps', 'iwcap', 'iwcap')
     37         iwcap = utils.run(dir + ' ' + phy + ' ' + string.join(caps))
     38         return self.__parse_iwcap(iwcap.stdout)
     39 
     40     def run_once(self):
     41         phy = utils.system_output("iw list | awk '/^Wiphy/ {print $2}'")
     42         if not phy or 'phy' not in phy:
     43             raise error.TestFail('WiFi Physical interface not found')
     44 
     45         requiredCaps = {
     46             'sta'    : 'true',        # station mode
     47 
     48             '24ghz'  : 'true',        # 2.4GHz band
     49             '11b'    : 'true',
     50             '11g'    : 'true',
     51 
     52             '5ghz'   : 'true',        # 5GHz band
     53             '11a'    : 'true',
     54 
     55             '11n'    : 'true',        # 802.11n (both bands)
     56             'ht40'   : 'true',        # HT40
     57             'sgi40'  : 'true',        # Short GI in HT40
     58         }
     59 
     60         dep = 'iwcap'
     61         dep_dir = os.path.join(self.autodir, 'deps', dep)
     62         self.job.install_pkg(dep, 'dep', dep_dir)
     63 
     64         results = self.__run_iwcap(phy, requiredCaps.keys())
     65         for cap in requiredCaps:
     66             if not cap in results:
     67                 raise error.TestFail('Internal error, ' +
     68                     'capability "%s" not handled' % cap)
     69             if results[cap] != requiredCaps[cap]:
     70                 raise error.TestFail('Requirement not met: ' +
     71                     'cap "%s" is "%s" but expected "%s"'
     72                     % (cap, results[cap], requiredCaps[cap]))
     73