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 5from __future__ import absolute_import 6 7import logging 8 9import common 10from autotest_lib.client.common_lib import error 11from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests 12 13 14class bluetooth_Health_ValidAddressTest( 15 bluetooth_adapter_tests.BluetoothAdapterTests): 16 """ 17 This class implements the valid address test. 18 It should be invoked by other classes e.g. BluetoothHealthValidAddress. 19 """ 20 version = 1 21 22 def valid_address_test(self): 23 """Verify that the client Bluetooth adapter has a valid address.""" 24 # Reset the adapter to the powered off state. 25 self.test_reset_off_adapter() 26 27 # Read the address both via BlueZ and via the kernel mgmt_ops interface. 28 # Compare the two, they should not differ. 29 bluez_properties = self.get_adapter_properties() 30 controller_info = self.read_info() 31 32 if bluez_properties['Address'] != controller_info[0]: 33 raise error.TestFail( 34 'BlueZ and Kernel adapter address differ: %s != %s' % 35 (bluez_properties['Address'], controller_info[0])) 36 37 address = controller_info[0] 38 logging.debug('Bluetooth address of adapter is %s', address) 39 40 # Health check the address 41 if address == '00:00:00:00:00:00': 42 raise error.TestFail('Adapter address is all zeros') 43 if address.startswith('00:00:00:'): 44 raise error.TestFail('Vendor portion of address is all zeros') 45 if address.endswith(':00:00:00'): 46 raise error.TestFail('Device portion of address is all zeros') 47 48 if address == 'FF:FF:FF:FF:FF:FF': 49 raise error.TestFail('Adapter address is all ones') 50 if address.startswith('FF:FF:FF:'): 51 raise error.TestFail('Vendor portion of address is all ones') 52 if address.endswith(':FF:FF:FF'): 53 raise error.TestFail('Device portion of address is all ones') 54 55 # Verify that the address is still the same after powering on the radio. 56 self.test_power_on_adapter() 57 bluez_properties = self.get_adapter_properties() 58 controller_info = self.read_info() 59 60 if bluez_properties['Address'] != address: 61 raise error.TestFail( 62 'BlueZ adapter address changed after power on: %s != %s' % 63 (bluez_properties['Address'], address)) 64 if controller_info[0] != address: 65 raise error.TestFail( 66 'Kernel adapter address changed after power on: %s != %s' % 67 (controller_info[0], address)) 68