1# Lint as: python2, python3
2# Copyright 2020 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
6"""A Batch of Bluetooth LE tests for Better Together"""
7
8from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import \
9    BluetoothAdapterQuickTests
10from autotest_lib.server.cros.bluetooth.bluetooth_adapter_better_together \
11    import BluetoothAdapterBetterTogether
12
13class bluetooth_AdapterLEBetterTogether(BluetoothAdapterBetterTogether):
14    """A Batch of Bluetooth LE tests for Better Together. This test is written
15       as a batch of tests in order to reduce test time, since auto-test ramp up
16       time is costly. The batch is using BluetoothAdapterQuickTests wrapper
17       methods to start and end a test and a batch of tests.
18
19       This class can be called to run the entire test batch or to run a
20       specific test only
21    """
22
23    batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator
24    test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator
25
26    @test_wrapper('Smart Unlock', devices={'BLE_PHONE':1})
27    def smart_unlock_test(self):
28        """Run the smart unlock test"""
29
30        device = self.devices['BLE_PHONE'][0]
31        device.RemoveDevice(self.bluetooth_facade.address)
32        self.test_smart_unlock(address=device.address)
33
34
35    @batch_wrapper('Better Together')
36    def better_together_batch_run(self, num_iterations=1, test_name=None):
37        """Run the Bluetooth LE for Better Together test batch or a specific
38           given test. The wrapper of this method is implemented in
39           batch_decorator. Using the decorator a test batch method can
40           implement the only its core tests invocations and let the
41           decorator handle the wrapper, which is taking care for whether to
42           run a specific test or the batch as a whole, and running the batch
43           in iterations
44
45           @param num_iterations: how many iterations to run
46           @param test_name: specific test to run otherwise None to run the
47                             whole batch
48        """
49        self.smart_unlock_test()
50
51
52    def run_once(self,
53                 host,
54                 num_iterations=1,
55                 args_dict=None,
56                 test_name=None,
57                 flag='Quick Health'):
58        """Run the batch of Bluetooth LE tests for Better Together
59
60        @param host: the DUT, usually a chromebook
61        @param num_iterations: the number of rounds to execute the test
62        @test_name: the test to run, or None for all tests
63        """
64
65        # Initialize and run the test batch or the requested specific test
66        self.quick_test_init(host,
67                             use_btpeer=True,
68                             flag=flag,
69                             args_dict=args_dict)
70        self.better_together_batch_run(num_iterations, test_name)
71        self.quick_test_cleanup()
72