blob: 6ab4ee3abadb8ed1cc2daa079b2fef5845297707 [file] [log] [blame]
Katherine Threlkeld129d0f42015-03-12 15:01:01 -07001# Copyright 2015 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
5import logging
6import re
7
8from autotest_lib.client.bin import utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.cros.bluetooth import bluetooth_semiauto_helper
11
12
13class bluetooth_IDCheck(bluetooth_semiauto_helper.BluetoothSemiAutoHelper):
Katherine Threlkeldf5708002016-02-17 15:32:18 -080014 """Checks whether the Bluetooth ID and Alias are in the correct format."""
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070015 version = 1
16
Dinesh Kumar Sunkarae46f4ee2015-05-15 10:30:12 -070017 # Boards which only support bluetooth version 3 and below
18 _BLUETOOTH_3_BOARDS = ['x86-mario', 'x86-zgb']
19
Katherine Threlkeld9f729af2015-10-21 15:01:21 -070020 # Boards which are not shipped to customers and don't need an id.
Furquan Shaikhe6b5a3b2018-06-18 09:28:05 -070021 _REFERENCE_ONLY = ['rambi', 'nyan', 'oak', 'reef', 'yorp', 'bip']
Katherine Threlkeld9f729af2015-10-21 15:01:21 -070022
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070023 def warmup(self):
24 """Overwrite parent warmup; no need to log in."""
25 pass
26
Katherine Threlkeldf5708002016-02-17 15:32:18 -080027 def _check_id(self, adapter_info):
28 """Fail if the Bluetooth ID is not in the correct format.
29
30 @param adapter_info: a dict of information about this device's adapter
31 @raises: error.TestFail if incorrect format is found.
32
33 """
Dinesh Kumar Sunkarae46f4ee2015-05-15 10:30:12 -070034 modalias = adapter_info['Modalias']
35 logging.info('Saw Bluetooth ID of: %s', modalias)
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070036
Katherine Threlkeld9f729af2015-10-21 15:01:21 -070037 if self._device in self._BLUETOOTH_3_BOARDS:
Dinesh Kumar Sunkarae46f4ee2015-05-15 10:30:12 -070038 bt_format = 'bluetooth:v00E0p24..d0300'
39 else:
40 bt_format = 'bluetooth:v00E0p24..d0400'
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070041
Dinesh Kumar Sunkarae46f4ee2015-05-15 10:30:12 -070042 if not re.match(bt_format, modalias):
Katherine Threlkeldf5708002016-02-17 15:32:18 -080043 raise error.TestFail('%s does not match expected format: %s'
Dinesh Kumar Sunkarae46f4ee2015-05-15 10:30:12 -070044 % (modalias, bt_format))
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070045
Katherine Threlkeldf5708002016-02-17 15:32:18 -080046 def _check_name(self, adapter_info):
47 """Fail if the Bluetooth name is not in the correct format.
48
49 @param adapter_info: a dict of information about this device's adapter
50 @raises: error.TestFail if incorrect format is found.
51
52 """
53 alias = adapter_info['Alias']
54 logging.info('Saw Bluetooth Alias of: %s', alias)
55
56 device_type = utils.get_device_type().lower()
57 alias_format = '%s_[a-z0-9]{4}' % device_type
58 if not re.match(alias_format, alias.lower()):
59 raise error.TestFail('%s does not match expected format: %s'
60 % (alias, alias_format))
61
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070062 def run_once(self):
63 """Entry point of this test."""
Katherine Threlkeldd9a82442015-06-25 11:49:24 -070064 if not self.supports_bluetooth():
Katherine Threlkeld129d0f42015-03-12 15:01:01 -070065 return
66
Furquan Shaikhdf555952018-07-20 11:59:45 -070067 self._device = utils.get_platform()
Katherine Threlkeld9f729af2015-10-21 15:01:21 -070068 if self._device in self._REFERENCE_ONLY:
69 return
70
Katherine Threlkeldd9a82442015-06-25 11:49:24 -070071 self.poll_adapter_presence()
Katherine Threlkeldf5708002016-02-17 15:32:18 -080072 adapter_info = self._get_adapter_info()
73 self._check_id(adapter_info)
74 self._check_name(adapter_info)