bluetooth: Add id/alias check tests to QuickSanity

BUG=b:147515384
TEST=SASanity.stress on fizz and raspi peers

Change-Id: Ibe892f777f111fd019e6d5864b1ff93300116416
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2038016
Tested-by: Daniel Winkler <danielwinkler@google.com>
Commit-Queue: Daniel Winkler <danielwinkler@google.com>
Reviewed-by: Shijin Abraham <shijinabraham@google.com>
diff --git a/client/site_tests/bluetooth_IDCheck/bluetooth_IDCheck.py b/client/site_tests/bluetooth_IDCheck/bluetooth_IDCheck.py
deleted file mode 100644
index 6ab4ee3..0000000
--- a/client/site_tests/bluetooth_IDCheck/bluetooth_IDCheck.py
+++ /dev/null
@@ -1,74 +0,0 @@
-# Copyright 2015 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import logging
-import re
-
-from autotest_lib.client.bin import utils
-from autotest_lib.client.common_lib import error
-from autotest_lib.client.cros.bluetooth import bluetooth_semiauto_helper
-
-
-class bluetooth_IDCheck(bluetooth_semiauto_helper.BluetoothSemiAutoHelper):
-    """Checks whether the Bluetooth ID and Alias are in the correct format."""
-    version = 1
-
-    # Boards which only support bluetooth version 3 and below
-    _BLUETOOTH_3_BOARDS = ['x86-mario', 'x86-zgb']
-
-    # Boards which are not shipped to customers and don't need an id.
-    _REFERENCE_ONLY = ['rambi', 'nyan', 'oak', 'reef', 'yorp', 'bip']
-
-    def warmup(self):
-        """Overwrite parent warmup; no need to log in."""
-        pass
-
-    def _check_id(self, adapter_info):
-        """Fail if the Bluetooth ID is not in the correct format.
-
-        @param adapter_info: a dict of information about this device's adapter
-        @raises: error.TestFail if incorrect format is found.
-
-        """
-        modalias = adapter_info['Modalias']
-        logging.info('Saw Bluetooth ID of: %s', modalias)
-
-        if self._device in self._BLUETOOTH_3_BOARDS:
-            bt_format = 'bluetooth:v00E0p24..d0300'
-        else:
-            bt_format = 'bluetooth:v00E0p24..d0400'
-
-        if not re.match(bt_format, modalias):
-            raise error.TestFail('%s does not match expected format: %s'
-                                 % (modalias, bt_format))
-
-    def _check_name(self, adapter_info):
-        """Fail if the Bluetooth name is not in the correct format.
-
-        @param adapter_info: a dict of information about this device's adapter
-        @raises: error.TestFail if incorrect format is found.
-
-        """
-        alias = adapter_info['Alias']
-        logging.info('Saw Bluetooth Alias of: %s', alias)
-
-        device_type = utils.get_device_type().lower()
-        alias_format = '%s_[a-z0-9]{4}' % device_type
-        if not re.match(alias_format, alias.lower()):
-            raise error.TestFail('%s does not match expected format: %s'
-                                 % (alias, alias_format))
-
-    def run_once(self):
-        """Entry point of this test."""
-        if not self.supports_bluetooth():
-            return
-
-        self._device = utils.get_platform()
-        if self._device in self._REFERENCE_ONLY:
-            return
-
-        self.poll_adapter_presence()
-        adapter_info = self._get_adapter_info()
-        self._check_id(adapter_info)
-        self._check_name(adapter_info)
diff --git a/client/site_tests/bluetooth_IDCheck/control b/client/site_tests/bluetooth_IDCheck/control
deleted file mode 100644
index b3cd9b3..0000000
--- a/client/site_tests/bluetooth_IDCheck/control
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright 2015 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-AUTHOR = "kathrelkeld"
-NAME = "bluetooth_IDCheck"
-PURPOSE = "Check whether the chromebook is using a Google Bluetooth ID."
-CRITERIA = """
-This test will fail if the Bluetooth ID does not match the expected format.
-"""
-ATTRIBUTES = "suite:bvt-perbuild, suite:bluetooth_flaky"
-TIME = "SHORT"
-TEST_CATEGORY = "Functional"
-TEST_CLASS = "bluetooth"
-TEST_TYPE = "client"
-DEPENDENCIES = 'bluetooth'
-
-DOC = """
-Checks the Bluetooth ID and Alias of the system.  If the ID is not
-"00E0:24..:0400" or the name is not like 'Chromebook_1234' (or Chromebox, etc.),
-the test will fail.  It does not check the platform-specific number in the ID.
-
-A platform should not FSI without an assigned Bluetooth ID from Google.
-
-"""
-
-job.run_test('bluetooth_IDCheck')
diff --git a/server/cros/bluetooth/bluetooth_adapter_tests.py b/server/cros/bluetooth/bluetooth_adapter_tests.py
index 67d5b14..d7b0822 100644
--- a/server/cros/bluetooth/bluetooth_adapter_tests.py
+++ b/server/cros/bluetooth/bluetooth_adapter_tests.py
@@ -549,6 +549,8 @@
             'PNP_UUID': '00001200-0000-1000-8000-00805f9b34fb',
             'GAP_UUID': '00001800-0000-1000-8000-00805f9b34fb'}
 
+    # Board list for name/ID test check. These devices don't need to be tested
+    REFERENCE_BOARDS = ['rambi', 'nyan', 'oak', 'reef', 'yorp', 'bip']
 
     def group_chameleons_type(self):
         """Group all chameleons by the type of their detected device."""
@@ -1209,6 +1211,62 @@
         return all(self.results.values())
 
 
+    @_test_retry_and_log(False)
+    def test_check_valid_adapter_id(self):
+        """Fail if the Bluetooth ID is not in the correct format.
+
+        @returns True if adapter ID follows expected format, False otherwise
+        """
+
+        # Boards which only support bluetooth version 3 and below
+        BLUETOOTH_3_BOARDS = ['x86-mario', 'x86-zgb']
+
+        device = self.host.get_platform()
+        adapter_info = self.get_adapter_properties()
+
+        # Don't complete test if this is a reference board
+        if device in self.REFERENCE_BOARDS:
+            return True
+
+        modalias = adapter_info['Modalias']
+        logging.debug('Saw Bluetooth ID of: %s', modalias)
+
+        if device in BLUETOOTH_3_BOARDS:
+            bt_format = 'bluetooth:v00E0p24..d0300'
+        else:
+            bt_format = 'bluetooth:v00E0p24..d0400'
+
+        if not re.match(bt_format, modalias):
+            return False
+
+        return True
+
+
+    @_test_retry_and_log(False)
+    def test_check_valid_alias(self):
+        """Fail if the Bluetooth alias is not in the correct format.
+
+        @returns True if adapter alias follows expected format, False otherwise
+        """
+
+        device = self.host.get_platform()
+        adapter_info = self.get_adapter_properties()
+
+        # Don't complete test if this is a reference board
+        if device in self.REFERENCE_BOARDS:
+            return True
+
+        alias = adapter_info['Alias']
+        logging.debug('Saw Bluetooth Alias of: %s', alias)
+
+        device_type = self.host.get_board_type().lower()
+        alias_format = '%s_[a-z0-9]{4}' % device_type
+        if not re.match(alias_format, alias.lower()):
+            return False
+
+        return True
+
+
     # -------------------------------------------------------------------
     # Tests about general discovering, pairing, and connection
     # -------------------------------------------------------------------
diff --git a/server/site_tests/bluetooth_AdapterSASanity/bluetooth_AdapterSASanity.py b/server/site_tests/bluetooth_AdapterSASanity/bluetooth_AdapterSASanity.py
index 5a92cbf..ad3c6c5 100644
--- a/server/site_tests/bluetooth_AdapterSASanity/bluetooth_AdapterSASanity.py
+++ b/server/site_tests/bluetooth_AdapterSASanity/bluetooth_AdapterSASanity.py
@@ -146,6 +146,18 @@
         self.valid_address_test()
 
 
+    @test_wrapper('Valid adapter ID test')
+    def sa_valid_id_test(self):
+        """Verify that the adapter has a correctly-formatted ID"""
+        self.test_check_valid_adapter_id()
+
+
+    @test_wrapper('Valid adapter alias test')
+    def sa_valid_alias_test(self):
+        """Verify that the adapter has a correctly-formatted alias"""
+        self.test_check_valid_alias()
+
+
     @test_wrapper('Multiple LE advertising test')
     def sa_multiple_advertising_test(self):
         """Run all test cases for multiple advertisements."""
diff --git a/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_alias_test b/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_alias_test
new file mode 100644
index 0000000..abdf00a
--- /dev/null
+++ b/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_alias_test
@@ -0,0 +1,33 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.server import utils
+from autotest_lib.server.cros.bluetooth import bluetooth_test
+
+AUTHOR = 'chromeos-bluetooth'
+NAME = 'bluetooth_AdapterSASanity.sa_valid_alias_test'
+PURPOSE = 'Check whether the chromebook is using a Google Bluetooth ID.'
+CRITERIA = """
+This test will fail if the Bluetooth ID does not match the expected format.
+"""
+ATTRIBUTES = 'suite:bvt-perbuild, suite:bluetooth_flaky'
+TIME = 'SHORT'
+TEST_CATEGORY = 'Functional'
+TEST_CLASS = 'bluetooth'
+TEST_TYPE = 'server'
+DEPENDENCIES = 'bluetooth'
+
+DOC = """
+Checks the Bluetooth Alias of the system.  If the alias is not like
+'Chromebook_1234' (or Chromebox, etc.), the test will fail.
+"""
+
+args_dict = utils.args_to_dict(args)
+
+def run(machine):
+    host = hosts.create_host(machine)
+    job.run_test('bluetooth_AdapterSASanity', host=host,
+                  num_iterations=1, test_name=NAME.split('.')[1])
+
+parallel_simple(run, machines)
diff --git a/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_id_test b/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_id_test
new file mode 100644
index 0000000..9bc83cb
--- /dev/null
+++ b/server/site_tests/bluetooth_AdapterSASanity/control.sa_valid_id_test
@@ -0,0 +1,35 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.server import utils
+from autotest_lib.server.cros.bluetooth import bluetooth_test
+
+AUTHOR = 'chromeos-bluetooth'
+NAME = 'bluetooth_AdapterSASanity.sa_valid_id_test'
+PURPOSE = 'Check whether the chromebook is using a Google Bluetooth ID.'
+CRITERIA = """
+This test will fail if the Bluetooth ID does not match the expected format.
+"""
+ATTRIBUTES = 'suite:bvt-perbuild, suite:bluetooth_flaky'
+TIME = 'SHORT'
+TEST_CATEGORY = 'Functional'
+TEST_CLASS = 'bluetooth'
+TEST_TYPE = 'server'
+DEPENDENCIES = 'bluetooth'
+
+DOC = """
+Checks the Bluetooth ID of the system.  If the ID is not "00E0:24..:0400" the
+test will fail.  It does not check the platform-specific number in the ID.
+
+A platform should not FSI without an assigned Bluetooth ID from Google.
+"""
+
+args_dict = utils.args_to_dict(args)
+
+def run(machine):
+    host = hosts.create_host(machine)
+    job.run_test('bluetooth_AdapterSASanity', host=host,
+                  num_iterations=1, test_name=NAME.split('.')[1])
+
+parallel_simple(run, machines)