Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 1 | # 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 | |
| 5 | import logging |
| 6 | import re |
| 7 | |
| 8 | from autotest_lib.client.bin import utils |
| 9 | from autotest_lib.client.common_lib import error |
| 10 | from autotest_lib.client.cros.bluetooth import bluetooth_semiauto_helper |
| 11 | |
| 12 | |
| 13 | class bluetooth_IDCheck(bluetooth_semiauto_helper.BluetoothSemiAutoHelper): |
Katherine Threlkeld | f570800 | 2016-02-17 15:32:18 -0800 | [diff] [blame] | 14 | """Checks whether the Bluetooth ID and Alias are in the correct format.""" |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 15 | version = 1 |
| 16 | |
Dinesh Kumar Sunkara | e46f4ee | 2015-05-15 10:30:12 -0700 | [diff] [blame] | 17 | # Boards which only support bluetooth version 3 and below |
| 18 | _BLUETOOTH_3_BOARDS = ['x86-mario', 'x86-zgb'] |
| 19 | |
Katherine Threlkeld | 9f729af | 2015-10-21 15:01:21 -0700 | [diff] [blame] | 20 | # Boards which are not shipped to customers and don't need an id. |
Furquan Shaikh | e6b5a3b | 2018-06-18 09:28:05 -0700 | [diff] [blame] | 21 | _REFERENCE_ONLY = ['rambi', 'nyan', 'oak', 'reef', 'yorp', 'bip'] |
Katherine Threlkeld | 9f729af | 2015-10-21 15:01:21 -0700 | [diff] [blame] | 22 | |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 23 | def warmup(self): |
| 24 | """Overwrite parent warmup; no need to log in.""" |
| 25 | pass |
| 26 | |
Katherine Threlkeld | f570800 | 2016-02-17 15:32:18 -0800 | [diff] [blame] | 27 | 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 Sunkara | e46f4ee | 2015-05-15 10:30:12 -0700 | [diff] [blame] | 34 | modalias = adapter_info['Modalias'] |
| 35 | logging.info('Saw Bluetooth ID of: %s', modalias) |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 36 | |
Katherine Threlkeld | 9f729af | 2015-10-21 15:01:21 -0700 | [diff] [blame] | 37 | if self._device in self._BLUETOOTH_3_BOARDS: |
Dinesh Kumar Sunkara | e46f4ee | 2015-05-15 10:30:12 -0700 | [diff] [blame] | 38 | bt_format = 'bluetooth:v00E0p24..d0300' |
| 39 | else: |
| 40 | bt_format = 'bluetooth:v00E0p24..d0400' |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 41 | |
Dinesh Kumar Sunkara | e46f4ee | 2015-05-15 10:30:12 -0700 | [diff] [blame] | 42 | if not re.match(bt_format, modalias): |
Katherine Threlkeld | f570800 | 2016-02-17 15:32:18 -0800 | [diff] [blame] | 43 | raise error.TestFail('%s does not match expected format: %s' |
Dinesh Kumar Sunkara | e46f4ee | 2015-05-15 10:30:12 -0700 | [diff] [blame] | 44 | % (modalias, bt_format)) |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 45 | |
Katherine Threlkeld | f570800 | 2016-02-17 15:32:18 -0800 | [diff] [blame] | 46 | 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 Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 62 | def run_once(self): |
| 63 | """Entry point of this test.""" |
Katherine Threlkeld | d9a8244 | 2015-06-25 11:49:24 -0700 | [diff] [blame] | 64 | if not self.supports_bluetooth(): |
Katherine Threlkeld | 129d0f4 | 2015-03-12 15:01:01 -0700 | [diff] [blame] | 65 | return |
| 66 | |
Furquan Shaikh | df55595 | 2018-07-20 11:59:45 -0700 | [diff] [blame] | 67 | self._device = utils.get_platform() |
Katherine Threlkeld | 9f729af | 2015-10-21 15:01:21 -0700 | [diff] [blame] | 68 | if self._device in self._REFERENCE_ONLY: |
| 69 | return |
| 70 | |
Katherine Threlkeld | d9a8244 | 2015-06-25 11:49:24 -0700 | [diff] [blame] | 71 | self.poll_adapter_presence() |
Katherine Threlkeld | f570800 | 2016-02-17 15:32:18 -0800 | [diff] [blame] | 72 | adapter_info = self._get_adapter_info() |
| 73 | self._check_id(adapter_info) |
| 74 | self._check_name(adapter_info) |