Home | History | Annotate | Download | only in bluetooth_Sanity_ValidAddress
      1 # Copyright (c) 2013 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
      6 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.server.cros.bluetooth import bluetooth_test
      9 
     10 
     11 class bluetooth_Sanity_ValidAddress(bluetooth_test.BluetoothTest):
     12     """
     13     Verify that the client Bluetooth adapter has a valid address.
     14     """
     15     version = 1
     16 
     17     def run_once(self):
     18         # Reset the adapter to the powered off state.
     19         if not self.device.reset_off():
     20             raise error.TestFail('DUT could not be reset to initial state')
     21 
     22         # Read the address both via BlueZ and via the kernel mgmt_ops interface.
     23         # Compare the two, they should not differ.
     24         bluez_properties = self.device.get_adapter_properties()
     25         controller_info = self.device.read_info()
     26 
     27         if bluez_properties['Address'] != controller_info[0]:
     28             raise error.TestFail(
     29                     'BlueZ and Kernel adapter address differ: %s != %s' %
     30                     (bluez_properties['Address'], controller_info[0]))
     31 
     32         address = controller_info[0]
     33         logging.debug('Bluetooth address of adapter is %s', address)
     34 
     35         # Sanity check the address
     36         if address == '00:00:00:00:00:00':
     37             raise error.TestFail('Adapter address is all zeros')
     38         if address.startswith('00:00:00:'):
     39             raise error.TestFail('Vendor portion of address is all zeros')
     40         if address.endswith(':00:00:00'):
     41             raise error.TestFail('Device portion of address is all zeros')
     42 
     43         if address == 'FF:FF:FF:FF:FF:FF':
     44             raise error.TestFail('Adapter address is all ones')
     45         if address.startswith('FF:FF:FF:'):
     46             raise error.TestFail('Vendor portion of address is all ones')
     47         if address.endswith(':FF:FF:FF'):
     48             raise error.TestFail('Device portion of address is all ones')
     49 
     50         # Verify that the address is still the same after powering on the radio.
     51         self.device.set_powered(True)
     52         bluez_properties = self.device.get_adapter_properties()
     53         controller_info = self.device.read_info()
     54 
     55         if bluez_properties['Address'] != address:
     56             raise error.TestFail(
     57                     'BlueZ adapter address changed after power on: %s != %s' %
     58                     (bluez_properties['Address'], address))
     59         if controller_info[0] != address:
     60             raise error.TestFail(
     61                     'Kernel adapter address changed after power on: %s != %s' %
     62                     (controller_info[0], address))
     63