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 of Bluetooth Classic health tests""" 7 8 9from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import \ 10 BluetoothAdapterQuickTests 11from autotest_lib.server.cros.bluetooth.bluetooth_adapter_pairing_tests import \ 12 BluetoothAdapterPairingTests 13from autotest_lib.server.cros.bluetooth.bluetooth_adapter_hidreports_tests \ 14 import BluetoothAdapterHIDReportTests 15from autotest_lib.server.cros.bluetooth.bluetooth_sdp_tests import \ 16 BluetoothSDPTests 17 18 19class bluetooth_AdapterCLHealth(BluetoothAdapterQuickTests, 20 BluetoothAdapterPairingTests, 21 BluetoothAdapterHIDReportTests, 22 BluetoothSDPTests): 23 """A Batch of Bluetooth Classic health tests. This test is written as a batch 24 of tests in order to reduce test time, since auto-test ramp up time is 25 costly. The batch is using BluetoothAdapterQuickTests wrapper methods to 26 start and end a test and a batch of tests. 27 28 This class can be called to run the entire test batch or to run a 29 specific test only 30 """ 31 32 test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator 33 batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator 34 35 36 @test_wrapper('Discovery Test', devices={"MOUSE": 1}, supports_floss=True) 37 def cl_adapter_discovery_test(self): 38 """Performs pairing test with mouse peripheral""" 39 device = self.devices['MOUSE'][0] 40 41 self.test_discover_device(device.address) 42 self.test_device_name(device.address, device.name) 43 44 45 @test_wrapper('Discoverable Test', 46 devices={"MOUSE": 1}, 47 supports_floss=True) 48 def cl_adapter_discoverable_test(self): 49 """Verifies that DUT can become discoverable and be discovered""" 50 51 device = self.devices['MOUSE'][0] 52 53 # Put DUT into discoverable state 54 self.test_discoverable() 55 56 # Try and discover DUT from peripheral device 57 self.test_discover_by_device(device) 58 59 60 @test_wrapper('Pairing Test', devices={"MOUSE": 1}, supports_floss=True) 61 def cl_adapter_pairing_test(self): 62 """Performs pairing test with mouse peripheral""" 63 device = self.devices['MOUSE'][0] 64 self.pairing_test(device, 65 check_connected_method=\ 66 self.test_mouse_right_click) 67 68 69 @test_wrapper('keyboard Pairing Test', 70 devices={"KEYBOARD": 1}, 71 supports_floss=True) 72 def cl_adapter_keyboard_pairing_test(self): 73 """Performs pairing test with keyboard peripheral""" 74 device = self.devices['KEYBOARD'][0] 75 self.pairing_test(device, 76 check_connected_method=\ 77 self.run_keyboard_tests) 78 79 80 @test_wrapper('Pairing Suspend Resume Test', 81 devices={"MOUSE": 1}, 82 supports_floss=True) 83 def cl_adapter_pairing_suspend_resume_test(self): 84 """Performs pairing test over resume with mouse peripheral""" 85 device = self.devices['MOUSE'][0] 86 self.pairing_test(device, 87 check_connected_method=\ 88 self.test_mouse_right_click, 89 suspend_resume=True) 90 91 92 @test_wrapper('Pairing Twice Test', 93 devices={"MOUSE": 1}, 94 supports_floss=True) 95 def cl_adapter_pairing_twice_test(self): 96 """Performs pairing twice test with mouse peripheral""" 97 device = self.devices['MOUSE'][0] 98 self.pairing_test(device, 99 check_connected_method=\ 100 self.test_mouse_right_click, 101 pairing_twice=True) 102 103 104 @test_wrapper('HID Reports Test', 105 devices={"MOUSE": 1}, 106 supports_floss=True) 107 def cl_HID_reports_test(self): 108 """Performs HID report test with mouse peripheral""" 109 device = self.devices['MOUSE'][0] 110 self.run_hid_reports_test(device, 111 check_connected_method=\ 112 self.test_mouse_right_click) 113 114 115 @test_wrapper('HID keyboard Reports Test', 116 devices={'KEYBOARD': 1}, 117 supports_floss=True) 118 def cl_HID_keyboard_reports_test(self): 119 """Performs HID report test with keyboard peripheral""" 120 device = self.devices['KEYBOARD'][0] 121 self.run_hid_reports_test(device, 122 check_connected_method=\ 123 self.run_keyboard_tests) 124 125 126 @test_wrapper('HID Reconnect Speed Test', 127 devices={"MOUSE": 1}, 128 flags=['Quick Health'], 129 supports_floss=True) 130 def cl_HID_reconnect_speed_test(self): 131 """Performs HID reconnect speed test with mouse peripheral""" 132 device = self.devices['MOUSE'][0] 133 self.hid_reconnect_speed(device=device, device_type='MOUSE') 134 135 136 @test_wrapper('HID Reports Suspend Resume Test', 137 devices={"MOUSE": 1}, 138 supports_floss=True) 139 def cl_HID_reports_suspend_resume_test(self): 140 """Performs HID report test over resume with mouse peripheral""" 141 device = self.devices['MOUSE'][0] 142 self.run_hid_reports_test(device, 143 check_connected_method=\ 144 self.test_mouse_right_click, suspend_resume=True) 145 146 147 @test_wrapper('HID Reports Reboot Test', 148 devices={"MOUSE": 1}, 149 supports_floss=True) 150 def cl_HID_reports_reboot_test(self): 151 """Performs HID report test over reboot with mouse peripheral""" 152 device = self.devices['MOUSE'][0] 153 self.run_hid_reports_test(device, 154 check_connected_method=\ 155 self.test_mouse_right_click, reboot=True) 156 157 158 @test_wrapper('HID Reports Restart Test', 159 devices={"MOUSE": 1}, 160 flags=['Quick Health'], 161 supports_floss=True) 162 def cl_HID_reports_restart_test(self): 163 """Performs HID report test over bluetoothd restart with mouse 164 peripheral 165 """ 166 device = self.devices['MOUSE'][0] 167 self.run_hid_reports_test( 168 device, 169 check_connected_method=self.test_mouse_move_in_xy, 170 restart=True) 171 172 173 @test_wrapper('Connect Disconnect by Device Loop Test', 174 devices={"MOUSE": 1}, 175 flags=['Quick Health'], 176 supports_floss=True) 177 def cl_connect_disconnect_by_device_loop_test(self): 178 """Performs connect/disconnect by device test with mouse peripheral""" 179 device = self.devices['MOUSE'][0] 180 self.connect_disconnect_by_device_loop( 181 device=device, 182 loops=3, 183 device_type='MOUSE', 184 check_connected_method=self.test_mouse_move_in_xy) 185 186 187 @test_wrapper('Connect Disconnect Loop Test', 188 devices={"MOUSE": 1}, 189 supports_floss=True) 190 def cl_connect_disconnect_loop_test(self): 191 """Performs connect/disconnect test with mouse peripheral""" 192 device = self.devices['MOUSE'][0] 193 self.connect_disconnect_loop(device=device, loops=3) 194 195 196 @test_wrapper('Page scan during Inquiry', devices={"MOUSE": 1}) 197 def cl_page_scan_during_inquiry(self): 198 """Checks page scan is working during inquiry. 199 200 Scan and pair peer device. 201 Start inquiry. 202 Disconnect peer device from DUT. 203 Reconnect peer device by initiating connection from peer. 204 """ 205 device = self.devices['MOUSE'][0] 206 207 # Setup 208 self.assert_discover_and_pair(device) 209 self.test_start_discovery() 210 211 # Disconnection should set up page scan so a reconnect immediately 212 # afterwards should always succeed 213 self.test_disconnection_by_adapter(device.address) 214 self.test_connection_by_device(device) 215 216 # Cleanup 217 self.test_stop_discovery() 218 219 @test_wrapper('SDP Service Browse Test', devices={"BLUETOOTH_TESTER":1}) 220 def cl_sdp_service_browse_test(self): 221 """Performs sdp browse with tester peripheral""" 222 device = self.devices['BLUETOOTH_TESTER'][0] 223 self.sdp_service_browse_test(device=device) 224 225 226 @test_wrapper('SDP Service Attribute Request Test', \ 227 devices={"BLUETOOTH_TESTER":1}) 228 def cl_sdp_service_attribute_request_test(self): 229 """Performs sdp browse with tester peripheral""" 230 device = self.devices['BLUETOOTH_TESTER'][0] 231 self.sdp_service_attribute_request_test(device=device) 232 233 234 @test_wrapper('SDP Service Search Attribute Request Test', \ 235 devices={"BLUETOOTH_TESTER":1}) 236 def cl_sdp_service_search_attribute_request_test(self): 237 """Performs sdp browse with tester peripheral""" 238 device = self.devices['BLUETOOTH_TESTER'][0] 239 self.sdp_service_search_attribute_request_test(device=device) 240 241 242 @test_wrapper('SDP Service Search Request Basic Test', \ 243 devices={"BLUETOOTH_TESTER":1}) 244 def cl_sdp_service_search_request_basic_test(self): 245 """Performs sdp browse with tester peripheral""" 246 device = self.devices['BLUETOOTH_TESTER'][0] 247 self.sdp_service_search_request_basic_test(device=device) 248 249 250 @batch_wrapper('Classic Health') 251 def cl_health_batch_run(self, num_iterations=1, test_name=None): 252 """Run the Classic health test batch or a specific given test. 253 The wrapper of this method is implemented in batch_decorator. 254 Using the decorator a test batch method can implement the only its 255 core tests invocations and let the decorator handle the wrapper, 256 which is taking care for whether to run a specific test or the 257 batch as a whole, and running the batch in iterations 258 259 @param num_iterations: how many interations to run 260 @param test_name: specifc test to run otherwise None to run the 261 whole batch 262 """ 263 self.cl_HID_keyboard_reports_test() 264 self.cl_HID_reports_reboot_test() 265 self.cl_HID_reports_restart_test() 266 self.cl_HID_reports_suspend_resume_test() 267 self.cl_HID_reports_test() 268 self.cl_adapter_discoverable_test() 269 self.cl_adapter_discovery_test() 270 self.cl_adapter_keyboard_pairing_test() 271 self.cl_adapter_pairing_suspend_resume_test() 272 self.cl_adapter_pairing_test() 273 self.cl_adapter_pairing_twice_test() 274 self.cl_connect_disconnect_by_device_loop_test() 275 self.cl_connect_disconnect_loop_test() 276 self.cl_sdp_service_attribute_request_test() 277 self.cl_sdp_service_browse_test() 278 self.cl_sdp_service_search_attribute_request_test() 279 self.cl_sdp_service_search_request_basic_test() 280 281 282 def run_once(self, 283 host, 284 num_iterations=1, 285 args_dict=None, 286 test_name=None, 287 flag='Quick Health', 288 floss=False): 289 """Run the batch of Bluetooth Classic health tests 290 291 @param host: the DUT, usually a chromebook 292 @param num_iterations: the number of rounds to execute the test 293 @test_name: the test to run, or None for all tests 294 """ 295 296 # Initialize and run the test batch or the requested specific test 297 self.quick_test_init(host, 298 use_btpeer=True, 299 flag=flag, 300 args_dict=args_dict, 301 floss=floss) 302 self.cl_health_batch_run(num_iterations, test_name) 303 self.quick_test_cleanup() 304