xref: /aosp_15_r20/external/autotest/server/cros/bluetooth/bluetooth_valid_address_test.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from __future__ import absolute_import
7
8import logging
9
10import common
11from autotest_lib.client.common_lib import error
12from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests
13
14
15class bluetooth_Health_ValidAddressTest(
16        bluetooth_adapter_tests.BluetoothAdapterTests):
17    """
18    This class implements the valid address test.
19    It should be invoked by other classes e.g. BluetoothHealthValidAddress.
20    """
21    version = 1
22
23    def valid_address_test(self):
24        """Verify that the client Bluetooth adapter has a valid address.
25
26        The test is different when running Floss vs Bluez.
27
28        On Floss, we enable the adapter and check the address is valid.
29
30        On Bluez, we power off the adapter, verify the address, then power on
31        the adapter to make sure nothing changes. We also compare the address
32        seen in userspace vs kernel.
33        """
34        if self.bluetooth_facade.is_floss():
35            self.test_reset_on_adapter()
36        else:
37            # Reset the adapter to the powered off state.
38            self.test_reset_off_adapter()
39
40        address = self.bluetooth_facade.get_address()
41
42        # Bluez needs to compare address against kernel
43        if not self.bluetooth_facade.is_floss():
44            # Read the address both via BlueZ and via the kernel mgmt_ops
45            # interface.  Compare the two, they should not differ.
46            controller_info = self.read_info()
47
48            if address != controller_info[0]:
49                raise error.TestFail(
50                        'BlueZ and Kernel adapter address differ: %s != %s' %
51                        (address, controller_info[0]))
52
53        logging.debug('Bluetooth address of adapter is %s', address)
54
55        # Health check the address
56        if address == '00:00:00:00:00:00':
57            raise error.TestFail('Adapter address is all zeros')
58        if address.startswith('00:00:00:'):
59            raise error.TestFail('Vendor portion of address is all zeros')
60        if address.endswith(':00:00:00'):
61            raise error.TestFail('Device portion of address is all zeros')
62
63        if address == 'FF:FF:FF:FF:FF:FF':
64            raise error.TestFail('Adapter address is all ones')
65        if address.startswith('FF:FF:FF:'):
66            raise error.TestFail('Vendor portion of address is all ones')
67        if address.endswith(':FF:FF:FF'):
68            raise error.TestFail('Device portion of address is all ones')
69
70        if not self.bluetooth_facade.is_floss():
71            # Verify that the address is still the same after powering on the radio.
72            self.test_power_on_adapter()
73            new_address = self.bluetooth_facade.get_address()
74            controller_info = self.read_info()
75
76            if new_address != address:
77                raise error.TestFail(
78                        'BlueZ adapter address changed after power on: %s != %s'
79                        % (new_address, address))
80            if controller_info[0] != address:
81                raise error.TestFail(
82                        'Kernel adapter address changed after power on: %s != %s'
83                        % (controller_info[0], address))
84