Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 1 | # Copyright 2019 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 | |
howardchung | 4e03f36 | 2019-06-10 17:18:33 +0800 | [diff] [blame] | 5 | """A Batch of Bluetooth stand alone sanity tests""" |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 6 | |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 7 | import logging |
| 8 | |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 9 | from autotest_lib.server.cros.bluetooth import advertisements_data |
Yoni Shavit | 93c2491 | 2019-05-14 10:37:04 -0700 | [diff] [blame] | 10 | from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import \ |
| 11 | BluetoothAdapterQuickTests |
Shijin Abraham | bcd7c02 | 2020-01-30 17:50:41 -0800 | [diff] [blame] | 12 | from autotest_lib.server.cros.bluetooth import bluetooth_dbus_api_tests |
howardchung | 414856e | 2019-06-11 15:34:07 +0800 | [diff] [blame] | 13 | from autotest_lib.server.cros.bluetooth import bluetooth_default_state_test |
| 14 | from autotest_lib.server.cros.bluetooth import bluetooth_valid_address_test |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 15 | from autotest_lib.server.cros.bluetooth.bluetooth_adapter_leadvertising_tests \ |
| 16 | import bluetooth_AdapterLEAdvertising |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 17 | |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 18 | |
howardchung | 414856e | 2019-06-11 15:34:07 +0800 | [diff] [blame] | 19 | class bluetooth_AdapterSASanity(BluetoothAdapterQuickTests, |
| 20 | bluetooth_default_state_test.bluetooth_Sanity_DefaultStateTest, |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 21 | bluetooth_valid_address_test.bluetooth_Sanity_ValidAddressTest, |
Shijin Abraham | bcd7c02 | 2020-01-30 17:50:41 -0800 | [diff] [blame] | 22 | bluetooth_dbus_api_tests.BluetoothDBusAPITests, |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 23 | bluetooth_AdapterLEAdvertising): |
Shijin Abraham | bcd7c02 | 2020-01-30 17:50:41 -0800 | [diff] [blame] | 24 | |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 25 | """A Batch of Bluetooth stand alone sanity tests. This test is written as |
| 26 | a batch of tests in order to reduce test time, since auto-test ramp up |
| 27 | time is costy. The batch is using BluetoothAdapterQuickTests wrapper |
| 28 | methods to start and end a test and a batch of tests. |
| 29 | |
| 30 | This class can be called to run the entire test batch or to run a |
howardchung | 4e03f36 | 2019-06-10 17:18:33 +0800 | [diff] [blame] | 31 | specific test only |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 32 | """ |
| 33 | |
Yoni Shavit | 93c2491 | 2019-05-14 10:37:04 -0700 | [diff] [blame] | 34 | test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator |
| 35 | batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator |
| 36 | |
| 37 | |
| 38 | @test_wrapper('Stand Alone basic test') |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 39 | def sa_basic_test(self): |
| 40 | """Set of basic stand alone test""" |
| 41 | |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 42 | # The bluetoothd must be running in the beginning. |
| 43 | self.test_bluetoothd_running() |
| 44 | |
| 45 | # It is possible that the adapter is not powered on yet. |
| 46 | # Power it on anyway and verify that it is actually powered on. |
| 47 | self.test_power_on_adapter() |
| 48 | |
| 49 | # Verify that the adapter could be powered off and powered on, |
| 50 | # and that it is in the correct working state. |
| 51 | self.test_power_off_adapter() |
| 52 | self.test_power_on_adapter() |
| 53 | self.test_adapter_work_state() |
| 54 | |
| 55 | # Verify that the bluetoothd could be simply stopped and then |
| 56 | # be started again, and that it is in the correct working state. |
| 57 | self.test_stop_bluetoothd() |
| 58 | self.test_start_bluetoothd() |
| 59 | self.test_adapter_work_state() |
| 60 | |
| 61 | # Verify that the adapter could be reset off and on which includes |
| 62 | # removing all cached information. |
| 63 | self.test_reset_off_adapter() |
| 64 | self.test_reset_on_adapter() |
| 65 | self.test_adapter_work_state() |
| 66 | |
| 67 | # Verify that the adapter supports basic profiles. |
| 68 | self.test_UUIDs() |
| 69 | |
| 70 | # Verify that the adapter could start and stop discovery. |
| 71 | self.test_start_discovery() |
| 72 | self.test_stop_discovery() |
| 73 | self.test_start_discovery() |
| 74 | |
| 75 | # Verify that the adapter could set both discoverable and |
| 76 | # non-discoverable successfully. |
| 77 | self.test_discoverable() |
| 78 | self.test_nondiscoverable() |
| 79 | self.test_discoverable() |
| 80 | |
| 81 | # Verify that the adapter could set pairable and non-pairable. |
| 82 | self.test_pairable() |
| 83 | self.test_nonpairable() |
| 84 | self.test_pairable() |
| 85 | |
howardchung | 4e03f36 | 2019-06-10 17:18:33 +0800 | [diff] [blame] | 86 | |
| 87 | @test_wrapper('Adapter suspend resume test') |
| 88 | def sa_adapter_suspend_resume_test(self): |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 89 | """Test dapter power states is perserved through suspend resume.""" |
howardchung | 4e03f36 | 2019-06-10 17:18:33 +0800 | [diff] [blame] | 90 | def adapter_on_SR_test(): |
| 91 | """Test Case: Power on - SR""" |
| 92 | self.test_power_on_adapter() |
| 93 | self.test_bluetoothd_running() |
| 94 | self.suspend_resume() |
| 95 | self.test_bluetoothd_running() |
| 96 | self.test_adapter_work_state() |
| 97 | self.test_power_on_adapter() |
| 98 | |
| 99 | |
| 100 | def adapter_off_SR_test(): |
| 101 | """Test Case: Power off - SR""" |
| 102 | self.test_power_off_adapter() |
| 103 | self.test_bluetoothd_running() |
| 104 | self.suspend_resume() |
| 105 | self.test_power_off_adapter() |
| 106 | self.test_bluetoothd_running() |
| 107 | |
| 108 | adapter_on_SR_test() |
| 109 | adapter_off_SR_test() |
| 110 | |
| 111 | |
| 112 | @test_wrapper('Adapter present test') |
| 113 | def sa_adapter_present_test(self): |
| 114 | """Verify that the client has a Bluetooth adapter.""" |
| 115 | |
| 116 | # Reset the adapter (if any) to the powered off state. |
| 117 | self.test_reset_off_adapter() |
| 118 | |
| 119 | # Verify that there is an adapter. This will only return True if both |
| 120 | # the kernel and bluetooth daemon see the adapter. |
| 121 | self.test_has_adapter() |
| 122 | |
| 123 | |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 124 | @test_wrapper('Adapter DiscoverableTimeout test') |
| 125 | def sa_adapter_discoverable_timeout_test(self): |
| 126 | """Verify that DiscoverableTimout Property works.""" |
howardchung | b8cd3c7 | 2019-09-11 11:05:04 +0800 | [diff] [blame] | 127 | result = self.test_discoverable_timeout(timeout_values=[0, 7, 15]) |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 128 | logging.info("Result is %s", result) |
| 129 | |
Shijin Abraham | a9f4792 | 2019-06-28 12:43:43 -0700 | [diff] [blame] | 130 | @test_wrapper('Adapter PairableTimeout test') |
| 131 | def sa_adapter_pairable_timeout_test(self): |
| 132 | """Verify that PairableTimout Property works.""" |
howardchung | b8cd3c7 | 2019-09-11 11:05:04 +0800 | [diff] [blame] | 133 | result = self.test_pairable_timeout(timeout_values=[0, 7, 15]) |
Shijin Abraham | a9f4792 | 2019-06-28 12:43:43 -0700 | [diff] [blame] | 134 | logging.info("Result is %s", result) |
| 135 | |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 136 | |
howardchung | 414856e | 2019-06-11 15:34:07 +0800 | [diff] [blame] | 137 | @test_wrapper('Default state test') |
| 138 | def sa_default_state_test(self): |
| 139 | """Verify that the Bluetooth adapter has correct state.""" |
| 140 | self.default_state_test() |
| 141 | |
| 142 | |
| 143 | @test_wrapper('Valid address test') |
| 144 | def sa_valid_address_test(self): |
| 145 | """Verify that the client Bluetooth adapter has a valid address.""" |
| 146 | self.valid_address_test() |
| 147 | |
| 148 | |
Daniel Winkler | c907d41 | 2020-02-04 15:11:44 -0800 | [diff] [blame^] | 149 | @test_wrapper('Valid adapter ID test') |
| 150 | def sa_valid_id_test(self): |
| 151 | """Verify that the adapter has a correctly-formatted ID""" |
| 152 | self.test_check_valid_adapter_id() |
| 153 | |
| 154 | |
| 155 | @test_wrapper('Valid adapter alias test') |
| 156 | def sa_valid_alias_test(self): |
| 157 | """Verify that the adapter has a correctly-formatted alias""" |
| 158 | self.test_check_valid_alias() |
| 159 | |
| 160 | |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 161 | @test_wrapper('Multiple LE advertising test') |
| 162 | def sa_multiple_advertising_test(self): |
| 163 | """Run all test cases for multiple advertisements.""" |
| 164 | self.run_le_advertising_test(self.host, \ |
| 165 | advertisements_data.ADVERTISEMENTS, 'multi_advertising', \ |
| 166 | num_iterations=1) |
| 167 | |
| 168 | |
| 169 | @test_wrapper('Single LE advertising test') |
| 170 | def sa_single_advertising_test(self): |
| 171 | """Run all test cases for single advertisements.""" |
| 172 | self.run_le_advertising_test(self.host, \ |
| 173 | advertisements_data.ADVERTISEMENTS, 'single_advertising', \ |
| 174 | num_iterations=1) |
| 175 | |
| 176 | |
| 177 | @test_wrapper('Suspend resume LE advertising test') |
| 178 | def sa_suspend_resume_advertising_test(self): |
| 179 | """Run all test cases for multiple advertisements.""" |
| 180 | self.run_le_advertising_test(self.host, \ |
| 181 | advertisements_data.ADVERTISEMENTS, 'suspend_resume', \ |
| 182 | num_iterations=1) |
| 183 | |
| 184 | |
| 185 | @test_wrapper('Reboot LE advertising test') |
| 186 | def sa_reboot_advertising_test(self): |
| 187 | """Run all test cases for single advertisements.""" |
| 188 | self.run_le_advertising_test(self.host, \ |
| 189 | advertisements_data.ADVERTISEMENTS, 'reboot', \ |
| 190 | num_iterations=1) |
| 191 | |
Shijin Abraham | bcd7c02 | 2020-01-30 17:50:41 -0800 | [diff] [blame] | 192 | @test_wrapper('DBUS API tests') |
| 193 | def sa_dbus_api_tests(self): |
| 194 | """ Verify that the Bluetooth DBus API calls work.""" |
| 195 | self.test_dbus_start_discovery_success() |
| 196 | self.test_dbus_start_discovery_fail_discovery_in_progress() |
| 197 | self.test_dbus_start_discovery_fail_power_off() |
| 198 | self.test_dbus_stop_discovery_success() |
| 199 | self.test_dbus_stop_discovery_fail_discovery_not_in_progress() |
| 200 | self.test_dbus_stop_discovery_fail_power_off() |
| 201 | |
| 202 | |
Daniel Winkler | 74b7f7b | 2020-01-17 15:59:29 -0800 | [diff] [blame] | 203 | |
Yoni Shavit | 93c2491 | 2019-05-14 10:37:04 -0700 | [diff] [blame] | 204 | @batch_wrapper('Stand Alone Sanity') |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 205 | def sa_sanity_batch_run(self, num_iterations=1, test_name=None): |
Yoni Shavit | 93c2491 | 2019-05-14 10:37:04 -0700 | [diff] [blame] | 206 | """Run the stand alone sanity test batch or a specific given test. |
| 207 | The wrapper of this method is implemented in batch_decorator. |
| 208 | Using the decorator a test batch method can implement the only its |
| 209 | core tests invocations and let the decorator handle the wrapper, |
| 210 | which is taking care for whether to run a specific test or the |
| 211 | batch as a whole, and running the batch in iterations |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 212 | |
Yoni Shavit | 93c2491 | 2019-05-14 10:37:04 -0700 | [diff] [blame] | 213 | @param num_iterations: how many interations to run |
| 214 | @param test_name: specifc test to run otherwise None to run the |
| 215 | whole batch |
| 216 | """ |
| 217 | self.sa_basic_test() |
howardchung | 4e03f36 | 2019-06-10 17:18:33 +0800 | [diff] [blame] | 218 | self.sa_adapter_suspend_resume_test() |
| 219 | self.sa_adapter_present_test() |
Shijin Abraham | 0d7d8fa | 2019-06-14 16:48:46 -0700 | [diff] [blame] | 220 | self.sa_adapter_discoverable_timeout_test() |
howardchung | 414856e | 2019-06-11 15:34:07 +0800 | [diff] [blame] | 221 | self.sa_default_state_test() |
| 222 | self.sa_valid_address_test() |
Shijin Abraham | bcd7c02 | 2020-01-30 17:50:41 -0800 | [diff] [blame] | 223 | #self.sa_dbus_api_tests() Disabled since tests is not stable yet. |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 224 | |
| 225 | |
howardchung | 92d1470 | 2019-10-17 15:57:54 +0800 | [diff] [blame] | 226 | def run_once(self, host, num_iterations=1, test_name=None, |
| 227 | flag='Quick Sanity'): |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 228 | """Run the batch of Bluetooth stand sanity tests |
| 229 | |
| 230 | @param host: the DUT, usually a chromebook |
| 231 | @param num_iterations: the number of rounds to execute the test |
| 232 | """ |
| 233 | # Initialize and run the test batch or the requested specific test |
howardchung | 92d1470 | 2019-10-17 15:57:54 +0800 | [diff] [blame] | 234 | self.quick_test_init(host, use_chameleon=False, flag=flag) |
Yoni Shavit | 99696e9 | 2019-05-02 14:45:02 -0700 | [diff] [blame] | 235 | self.sa_sanity_batch_run(num_iterations, test_name) |
| 236 | self.quick_test_cleanup() |