1 #/usr/bin/env python3.4 2 # 3 # Copyright (C) 2016 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 # use this file except in compliance with the License. You may obtain a copy of 7 # the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 # License for the specific language governing permissions and limitations under 15 # the License. 16 """ 17 Test script to execute Bluetooth basic functionality test cases. 18 This test was designed to be run in a shield box. 19 """ 20 21 import time 22 23 from queue import Empty 24 from acts.test_decorators import test_tracker_info 25 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 26 from acts.test_utils.bt.BtEnum import BluetoothScanModeType 27 from acts.test_utils.bt.bt_test_utils import check_device_supported_profiles 28 from acts.test_utils.bt.bt_test_utils import reset_bluetooth 29 from acts.test_utils.bt.bt_test_utils import set_device_name 30 from acts.test_utils.bt.bt_test_utils import set_bt_scan_mode 31 from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 32 from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs 33 34 35 class BtBasicFunctionalityTest(BluetoothBaseTest): 36 default_timeout = 10 37 scan_discovery_time = 5 38 39 def __init__(self, controllers): 40 BluetoothBaseTest.__init__(self, controllers) 41 self.droid_ad = self.android_devices[0] 42 self.droid1_ad = self.android_devices[1] 43 44 def setup_class(self): 45 return setup_multiple_devices_for_bt_test(self.android_devices) 46 47 def setup_test(self): 48 for a in self.android_devices: 49 a.ed.clear_all_events() 50 return True 51 52 def teardown_test(self): 53 return True 54 55 def on_fail(self, test_name, begin_time): 56 take_btsnoop_logs(self.android_devices, self, test_name, begin_time) 57 reset_bluetooth(self.android_devices) 58 59 @BluetoothBaseTest.bt_test_wrap 60 @test_tracker_info(uuid='5a5dcf94-8114-405c-a048-b80d73e80ecc') 61 def test_bluetooth_reset(self): 62 """Test resetting bluetooth. 63 64 Test the integrity of resetting bluetooth on Android. 65 66 Steps: 67 1. Toggle bluetooth off. 68 2. Toggle bluetooth on. 69 70 Expected Result: 71 Bluetooth should toggle on and off without failing. 72 73 Returns: 74 Pass if True 75 Fail if False 76 77 TAGS: Classic 78 Priority: 1 79 """ 80 return reset_bluetooth([self.droid_ad]) 81 82 @BluetoothBaseTest.bt_test_wrap 83 @test_tracker_info(uuid='fc205cb8-6878-4f97-b9c8-7ed532742a1b') 84 def test_make_device_discoverable(self): 85 """Test device discoverablity. 86 87 Test that verifies devices is discoverable. 88 89 Steps: 90 1. Initialize two android devices 91 2. Make device1 discoverable 92 3. Check discoverable device1 scan mode 93 4. Make device2 start discovery 94 5. Use device2 get all discovered bluetooth devices list 95 6. Verify device1 is in the list 96 97 Expected Result: 98 Device1 is in the discovered devices list. 99 100 Returns: 101 Pass if True 102 Fail if False 103 104 TAGS: Classic 105 Priority: 1 106 """ 107 self.droid_ad.droid.bluetoothMakeDiscoverable() 108 scan_mode = self.droid_ad.droid.bluetoothGetScanMode() 109 if (scan_mode == 110 BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE): 111 self.log.debug("Android device1 scan mode is " 112 "SCAN_MODE_CONNECTABLE_DISCOVERABLE") 113 else: 114 self.log.debug("Android device1 scan mode is not " 115 "SCAN_MODE_CONNECTABLE_DISCOVERABLE") 116 return False 117 if self.droid1_ad.droid.bluetoothStartDiscovery(): 118 self.log.debug("Android device2 start discovery process success") 119 # Give Bluetooth time to discover advertising devices 120 time.sleep(self.scan_discovery_time) 121 droid_name = self.droid_ad.droid.bluetoothGetLocalName() 122 get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices( 123 ) 124 find_flag = False 125 if get_all_discovered_devices: 126 self.log.debug( 127 "Android device2 get all the discovered devices " 128 "list {}".format(get_all_discovered_devices)) 129 for i in get_all_discovered_devices: 130 if 'name' in i and i['name'] == droid_name: 131 self.log.debug("Android device1 is in the discovery " 132 "list of device2") 133 find_flag = True 134 break 135 else: 136 self.log.debug( 137 "Android device2 get all the discovered devices " 138 "list is empty") 139 return False 140 else: 141 self.log.debug("Android device2 start discovery process error") 142 return False 143 if not find_flag: 144 return False 145 return True 146 147 @BluetoothBaseTest.bt_test_wrap 148 @test_tracker_info(uuid='c4d77bde-04ed-4805-9185-9bc46dc8af4b') 149 def test_make_device_undiscoverable(self): 150 """Test device un-discoverability. 151 152 Test that verifies device is un-discoverable. 153 154 Steps: 155 1. Initialize two android devices 156 2. Make device1 un-discoverable 157 3. Check un-discoverable device1 scan mode 158 4. Make device2 start discovery 159 5. Use device2 get all discovered bluetooth devices list 160 6. Verify device1 is not in the list 161 162 Expected Result: 163 Device1 should not be in the discovered devices list. 164 165 Returns: 166 Pass if True 167 Fail if False 168 169 TAGS: Classic 170 Priority: 1 171 """ 172 self.droid_ad.droid.bluetoothMakeUndiscoverable() 173 set_bt_scan_mode(self.droid1_ad, BluetoothScanModeType.SCAN_MODE_NONE) 174 scan_mode = self.droid1_ad.droid.bluetoothGetScanMode() 175 if scan_mode == BluetoothScanModeType.SCAN_MODE_NONE: 176 self.log.debug("Android device1 scan mode is SCAN_MODE_NONE") 177 else: 178 self.log.debug("Android device1 scan mode is not SCAN_MODE_NONE") 179 return False 180 if self.droid1_ad.droid.bluetoothStartDiscovery(): 181 self.log.debug("Android device2 start discovery process success") 182 # Give Bluetooth time to discover advertising devices 183 time.sleep(self.scan_discovery_time) 184 droid_name = self.droid_ad.droid.bluetoothGetLocalName() 185 get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices( 186 ) 187 find_flag = False 188 if get_all_discovered_devices: 189 self.log.debug( 190 "Android device2 get all the discovered devices " 191 "list {}".format(get_all_discovered_devices)) 192 for i in get_all_discovered_devices: 193 if 'name' in i and i['name'] == droid_name: 194 self.log.debug( 195 "Android device1 is in the discovery list of " 196 "device2") 197 find_flag = True 198 break 199 else: 200 self.log.debug("Android device2 found no devices.") 201 return True 202 else: 203 self.log.debug("Android device2 start discovery process error") 204 return False 205 if find_flag: 206 return False 207 return True 208 209 @BluetoothBaseTest.bt_test_wrap 210 @test_tracker_info(uuid='2bcb6288-64c3-437e-bc89-bcd416310135') 211 def test_set_device_name(self): 212 """Test bluetooth device name. 213 214 Test that a single device can be set device name. 215 216 Steps: 217 1. Initialize one android devices 218 2. Set device name 219 3. Return true is set device name success 220 221 Expected Result: 222 Bluetooth device name is set correctly. 223 224 Returns: 225 Pass if True 226 Fail if False 227 228 TAGS: Classic 229 Priority: 1 230 """ 231 name = "SetDeviceName" 232 return set_device_name(self.droid_ad.droid, name) 233 234 @BluetoothBaseTest.bt_test_wrap 235 @test_tracker_info(uuid='b38fb110-a707-47cf-b1c3-981266373786') 236 def test_scan_mode_off(self): 237 """Test disabling bluetooth scanning. 238 239 Test that changes scan mode to off. 240 241 Steps: 242 1. Initialize android device. 243 2. Set scan mode STATE_OFF by disabling bluetooth. 244 3. Verify scan state. 245 246 Expected Result: 247 Verify scan state is off. 248 249 Returns: 250 Pass if True 251 Fail if False 252 253 TAGS: Classic 254 Priority: 1 255 """ 256 self.log.debug("Test scan mode STATE_OFF.") 257 return set_bt_scan_mode(self.droid_ad, BluetoothScanModeType.STATE_OFF) 258 259 #@BluetoothTest(UUID=27576aa8-d52f-45ad-986a-f44fb565167d) 260 @BluetoothBaseTest.bt_test_wrap 261 @test_tracker_info(uuid='702c3d58-94fd-47ee-9323-2421ce182ddb') 262 def test_scan_mode_none(self): 263 """Test bluetooth scan mode none. 264 265 Test that changes scan mode to none. 266 267 Steps: 268 1. Initialize android device. 269 2. Set scan mode SCAN_MODE_NONE by disabling bluetooth. 270 3. Verify scan state. 271 272 Expected Result: 273 Verify that scan mode is set to none. 274 275 Returns: 276 Pass if True 277 Fail if False 278 279 TAGS: Classic 280 Priority: 1 281 """ 282 self.log.debug("Test scan mode SCAN_MODE_NONE.") 283 return set_bt_scan_mode(self.droid_ad, 284 BluetoothScanModeType.SCAN_MODE_NONE) 285 286 @BluetoothBaseTest.bt_test_wrap 287 @test_tracker_info(uuid='cb998a99-31a6-46b6-9de6-a9a17081a604') 288 def test_scan_mode_connectable(self): 289 """Test bluetooth scan mode connectable. 290 291 Test that changes scan mode to connectable. 292 293 Steps: 294 1. Initialize android device. 295 2. Set scan mode SCAN_MODE_CONNECTABLE. 296 3. Verify scan state. 297 298 Expected Result: 299 Verify that scan mode is set to connectable. 300 301 Returns: 302 Pass if True 303 Fail if False 304 305 TAGS: Classic 306 Priority: 2 307 """ 308 self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE.") 309 return set_bt_scan_mode(self.droid_ad, 310 BluetoothScanModeType.SCAN_MODE_CONNECTABLE) 311 312 @BluetoothBaseTest.bt_test_wrap 313 @test_tracker_info(uuid='59bec55c-c64e-43e4-9a9a-e44408a801d7') 314 def test_scan_mode_connectable_discoverable(self): 315 """Test bluetooth scan mode connectable. 316 317 Test that changes scan mode to connectable. 318 319 Steps: 320 1. Initialize android device. 321 2. Set scan mode SCAN_MODE_DISCOVERABLE. 322 3. Verify scan state. 323 324 Expected Result: 325 Verify that scan mode is set to discoverable. 326 327 Returns: 328 Pass if True 329 Fail if False 330 331 TAGS: Classic 332 Priority: 2 333 """ 334 self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE_DISCOVERABLE.") 335 return set_bt_scan_mode( 336 self.droid_ad, 337 BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE) 338 339 @BluetoothBaseTest.bt_test_wrap 340 @test_tracker_info(uuid='cd20a09d-a68d-4f55-b016-ba283b0460df') 341 def test_if_support_hid_profile(self): 342 """ Test that a single device can support HID profile. 343 Steps 344 1. Initialize one android devices 345 2. Check devices support profiles and return a dictionary 346 3. Check the value of key 'hid' 347 348 Expected Result: 349 Device1 is in the discovered devices list. 350 351 Returns: 352 Pass if True 353 Fail if False 354 355 TAGS: Classic 356 Priority: 1 357 """ 358 profiles = check_device_supported_profiles(self.droid_ad.droid) 359 if not profiles['hid']: 360 self.log.debug("Android device do not support HID profile.") 361 return False 362 return True 363 364 @BluetoothBaseTest.bt_test_wrap 365 @test_tracker_info(uuid='a110d330-7090-4784-a33b-33089dc5f67f') 366 def test_if_support_hsp_profile(self): 367 """ Test that a single device can support HSP profile. 368 Steps 369 1. Initialize one android devices 370 2. Check devices support profiles and return a dictionary 371 3. Check the value of key 'hsp' 372 :return: test_result: bool 373 """ 374 profiles = check_device_supported_profiles(self.droid_ad.droid) 375 if not profiles['hsp']: 376 self.log.debug("Android device do not support HSP profile.") 377 return False 378 return True 379 380 @BluetoothBaseTest.bt_test_wrap 381 @test_tracker_info(uuid='9ccefdd9-62a9-4aed-b4d9-7b0a55c338b2') 382 def test_if_support_a2dp_profile(self): 383 """ Test that a single device can support A2DP profile. 384 Steps 385 1. Initialize one android devices 386 2. Check devices support profiles and return a dictionary 387 3. Check the value of key 'a2dp' 388 :return: test_result: bool 389 """ 390 profiles = check_device_supported_profiles(self.droid_ad.droid) 391 if not profiles['a2dp']: 392 self.log.debug("Android device do not support A2DP profile.") 393 return False 394 return True 395