• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2019 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 stand alone health tests"""
7
8from __future__ import absolute_import
9from __future__ import division
10from __future__ import print_function
11
12import logging
13
14from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import (
15        BluetoothAdapterQuickTests)
16from autotest_lib.server.cros.bluetooth import bluetooth_dbus_api_tests
17from autotest_lib.server.cros.bluetooth import bluetooth_default_state_test
18from autotest_lib.server.cros.bluetooth import bluetooth_valid_address_test
19from six.moves import range
20
21
22class bluetooth_AdapterSAHealth(BluetoothAdapterQuickTests,
23        bluetooth_default_state_test.bluetooth_Health_DefaultStateTest,
24        bluetooth_valid_address_test.bluetooth_Health_ValidAddressTest,
25        bluetooth_dbus_api_tests.BluetoothDBusAPITests):
26
27    """A Batch of Bluetooth stand alone health tests. This test is written as
28       a batch of tests in order to reduce test time, since auto-test ramp up
29       time is costy. The batch is using BluetoothAdapterQuickTests wrapper
30       methods to start and end a test and a batch of tests.
31
32       This class can be called to run the entire test batch or to run a
33       specific test only
34    """
35
36    test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator
37    batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator
38
39
40    @test_wrapper('Stand Alone basic test')
41    def sa_basic_test(self):
42        """Set of basic stand alone test"""
43
44        # The bluetoothd must be running in the beginning.
45        self.test_bluetoothd_running()
46
47        # It is possible that the adapter is not powered on yet.
48        # Power it on anyway and verify that it is actually powered on.
49        self.test_power_on_adapter()
50
51        # Verify that the adapter could be powered off and powered on,
52        # and that it is in the correct working state.
53        self.test_power_off_adapter()
54        self.test_power_on_adapter()
55        self.test_adapter_work_state()
56
57        # Verify that the bluetoothd could be simply stopped and then
58        # be started again, and that it is in the correct working state.
59        self.test_stop_bluetoothd()
60        self.test_start_bluetoothd()
61        self.test_adapter_work_state()
62
63        # Verify that the adapter could be reset off and on which includes
64        # removing all cached information.
65        self.test_reset_off_adapter()
66        self.test_reset_on_adapter()
67        self.test_adapter_work_state()
68
69        # Verify that the adapter supports basic profiles.
70        self.test_UUIDs()
71
72        # Verify that the adapter could start and stop discovery.
73        self.test_start_discovery()
74        self.test_stop_discovery()
75        self.test_start_discovery()
76
77        # Verify that the adapter could set both discoverable and
78        # non-discoverable successfully.
79        self.test_discoverable()
80        self.test_nondiscoverable()
81        self.test_discoverable()
82
83        # Verify that the adapter could set pairable and non-pairable.
84        self.test_pairable()
85        self.test_nonpairable()
86        self.test_pairable()
87
88
89    @test_wrapper('Adapter suspend resume test')
90    def sa_adapter_suspend_resume_test(self):
91        """Test dapter power states is perserved through suspend resume."""
92        def adapter_on_SR_test():
93            """Test Case: Power on - SR"""
94            self.test_power_on_adapter()
95            self.test_bluetoothd_running()
96            self.suspend_resume()
97            self.test_bluetoothd_running()
98            self.test_adapter_work_state()
99            self.test_power_on_adapter()
100
101
102        def adapter_off_SR_test():
103            """Test Case: Power off - SR"""
104            self.test_power_off_adapter()
105            self.test_bluetoothd_running()
106            self.suspend_resume()
107            self.test_power_off_adapter()
108            self.test_bluetoothd_running()
109
110        adapter_on_SR_test()
111        adapter_off_SR_test()
112
113
114    @test_wrapper('Adapter present test')
115    def sa_adapter_present_test(self):
116        """Verify that the client has a Bluetooth adapter."""
117
118        # Reset the adapter (if any) to the powered off state.
119        self.test_reset_off_adapter()
120
121        # Verify that there is an adapter. This will only return True if both
122        # the kernel and bluetooth daemon see the adapter.
123        self.test_has_adapter()
124
125    @test_wrapper('Adapter reboot test')
126    def sa_adapter_reboot_test(self):
127        """Verify that adapter power setting persist over reboot
128
129        Test whether power setting persist after a reboot and whether
130        adapter can be turned on after reboot
131        """
132
133        def test_case_adapter_on_reboot():
134            """Test Case: Power on - reboot"""
135            self.test_power_on_adapter()
136            self.test_bluetoothd_running()
137            self.reboot()
138            self.test_bluetoothd_running()
139            self.test_adapter_work_state()
140
141        def test_case_adapter_off_reboot():
142            """Test Case: Power on - reboot"""
143            self.test_power_off_adapter()
144            self.test_bluetoothd_running()
145            self.reboot()
146            self.test_has_adapter()
147            self.test_is_powered_off()
148            self.test_power_on_adapter()
149            self.test_bluetoothd_running()
150
151        NUM_ITERATIONS = 3
152        for i in range(NUM_ITERATIONS):
153            logging.debug('Starting reboot test loop number #%d', i)
154            test_case_adapter_on_reboot()
155            test_case_adapter_off_reboot()
156
157
158
159    # TODO(b/145302986): Silencing known firmware issue with AC7260 (WP2)
160    @test_wrapper('Adapter DiscoverableTimeout test',
161                  skip_chipsets=['Intel-AC7260'])
162    def sa_adapter_discoverable_timeout_test(self):
163        """Verify that DiscoverableTimout Property works."""
164        result = self.test_discoverable_timeout(timeout_values=[0, 7, 15])
165        logging.info("Result is %s", result)
166
167    @test_wrapper('Adapter PairableTimeout test')
168    def sa_adapter_pairable_timeout_test(self):
169        """Verify that PairableTimout Property works."""
170        result = self.test_pairable_timeout(timeout_values=[0, 7, 15])
171        logging.info("Result is %s", result)
172
173
174    @test_wrapper('Default state test')
175    def sa_default_state_test(self):
176        """Verify that the Bluetooth adapter has correct state."""
177        self.default_state_test()
178
179
180    @test_wrapper('Valid address test')
181    def sa_valid_address_test(self):
182        """Verify that the client Bluetooth adapter has a valid address."""
183        self.valid_address_test()
184
185
186    @test_wrapper('Valid adapter ID test')
187    def sa_valid_id_test(self):
188        """Verify that the adapter has a correctly-formatted ID"""
189        self.test_check_valid_adapter_id()
190
191
192    @test_wrapper('Valid adapter alias test')
193    def sa_valid_alias_test(self):
194        """Verify that the adapter has a correctly-formatted alias"""
195        self.test_check_valid_alias()
196
197
198    @test_wrapper('DBUS API tests')
199    def sa_dbus_api_tests(self):
200        """ Verify that the Bluetooth DBus API calls work."""
201        self.test_dbus_start_discovery_success()
202        self.test_dbus_start_discovery_fail_discovery_in_progress()
203        self.test_dbus_start_discovery_fail_power_off()
204
205        self.test_dbus_stop_discovery_success()
206        self.test_dbus_stop_discovery_fail_discovery_not_in_progress()
207        self.test_dbus_stop_discovery_fail_power_off()
208
209        self.test_dbus_get_supported_capabilities_success()
210        self.test_dbus_get_supported_capabilities_success_power_off()
211
212    @test_wrapper('EIR Max Alias Size test')
213    def sa_eir_max_name_size_test(self):
214        """ Verify that the non-default max eir name size is used """
215        EIR_80_char_name = ('1234567890123456789012345678901234567890'
216                            '1234567890123456789012345678901234567890')
217
218        self.test_set_adapter_alias(EIR_80_char_name)
219
220
221    @batch_wrapper('Stand Alone Health')
222    def sa_health_batch_run(self, num_iterations=1, test_name=None):
223        """Run the stand alone health test batch or a specific given test.
224           The wrapper of this method is implemented in batch_decorator.
225           Using the decorator a test batch method can implement the only its
226           core tests invocations and let the decorator handle the wrapper,
227           which is taking care for whether to run a specific test or the
228           batch as a whole, and running the batch in iterations
229
230           @param num_iterations: how many interations to run
231           @param test_name: specifc test to run otherwise None to run the
232                             whole batch
233        """
234        self.sa_basic_test()
235        self.sa_adapter_suspend_resume_test()
236        self.sa_adapter_present_test()
237        # self.sa_adapter_reboot_test() disabled since the test is not stable
238        self.sa_adapter_discoverable_timeout_test()
239        self.sa_default_state_test()
240        self.sa_valid_address_test()
241        self.sa_dbus_api_tests()
242
243
244    def run_once(self, host, num_iterations=1, test_name=None,
245                 flag='Quick Health'):
246        """Run the batch of Bluetooth stand health tests
247
248        @param host: the DUT, usually a chromebook
249        @param num_iterations: the number of rounds to execute the test
250        """
251        # Initialize and run the test batch or the requested specific test
252        self.quick_test_init(host, use_btpeer=False, flag=flag,
253                             start_browser=False)
254        self.sa_health_batch_run(num_iterations, test_name)
255        self.quick_test_cleanup()
256