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.bt_constants import bt_scan_mode_types 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) 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 == bt_scan_mode_types['connectable_discoverable']): 110 self.log.debug("Android device1 scan mode is " 111 "SCAN_MODE_CONNECTABLE_DISCOVERABLE") 112 else: 113 self.log.debug("Android device1 scan mode is not " 114 "SCAN_MODE_CONNECTABLE_DISCOVERABLE") 115 return False 116 if self.droid1_ad.droid.bluetoothStartDiscovery(): 117 self.log.debug("Android device2 start discovery process success") 118 # Give Bluetooth time to discover advertising devices 119 time.sleep(self.scan_discovery_time) 120 droid_name = self.droid_ad.droid.bluetoothGetLocalName() 121 get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices( 122 ) 123 find_flag = False 124 if get_all_discovered_devices: 125 self.log.debug( 126 "Android device2 get all the discovered devices " 127 "list {}".format(get_all_discovered_devices)) 128 for i in get_all_discovered_devices: 129 if 'name' in i and i['name'] == droid_name: 130 self.log.debug("Android device1 is in the discovery " 131 "list of device2") 132 find_flag = True 133 break 134 else: 135 self.log.debug( 136 "Android device2 get all the discovered devices " 137 "list is empty") 138 return False 139 else: 140 self.log.debug("Android device2 start discovery process error") 141 return False 142 if not find_flag: 143 return False 144 return True 145 146 @BluetoothBaseTest.bt_test_wrap 147 @test_tracker_info(uuid='c4d77bde-04ed-4805-9185-9bc46dc8af4b') 148 def test_make_device_undiscoverable(self): 149 """Test device un-discoverability. 150 151 Test that verifies device is un-discoverable. 152 153 Steps: 154 1. Initialize two android devices 155 2. Make device1 un-discoverable 156 3. Check un-discoverable device1 scan mode 157 4. Make device2 start discovery 158 5. Use device2 get all discovered bluetooth devices list 159 6. Verify device1 is not in the list 160 161 Expected Result: 162 Device1 should not be in the discovered devices list. 163 164 Returns: 165 Pass if True 166 Fail if False 167 168 TAGS: Classic 169 Priority: 1 170 """ 171 self.droid_ad.droid.bluetoothMakeUndiscoverable() 172 set_bt_scan_mode(self.droid1_ad, bt_scan_mode_types['none']) 173 scan_mode = self.droid1_ad.droid.bluetoothGetScanMode() 174 if scan_mode == bt_scan_mode_types['none']: 175 self.log.debug("Android device1 scan mode is SCAN_MODE_NONE") 176 else: 177 self.log.debug("Android device1 scan mode is not SCAN_MODE_NONE") 178 return False 179 if self.droid1_ad.droid.bluetoothStartDiscovery(): 180 self.log.debug("Android device2 start discovery process success") 181 # Give Bluetooth time to discover advertising devices 182 time.sleep(self.scan_discovery_time) 183 droid_name = self.droid_ad.droid.bluetoothGetLocalName() 184 get_all_discovered_devices = self.droid1_ad.droid.bluetoothGetDiscoveredDevices( 185 ) 186 find_flag = False 187 if get_all_discovered_devices: 188 self.log.debug( 189 "Android device2 get all the discovered devices " 190 "list {}".format(get_all_discovered_devices)) 191 for i in get_all_discovered_devices: 192 if 'name' in i and i['name'] == droid_name: 193 self.log.debug( 194 "Android device1 is in the discovery list of " 195 "device2") 196 find_flag = True 197 break 198 else: 199 self.log.debug("Android device2 found no devices.") 200 return True 201 else: 202 self.log.debug("Android device2 start discovery process error") 203 return False 204 if find_flag: 205 return False 206 return True 207 208 @BluetoothBaseTest.bt_test_wrap 209 @test_tracker_info(uuid='2bcb6288-64c3-437e-bc89-bcd416310135') 210 def test_set_device_name(self): 211 """Test bluetooth device name. 212 213 Test that a single device can be set device name. 214 215 Steps: 216 1. Initialize one android devices 217 2. Set device name 218 3. Return true is set device name success 219 220 Expected Result: 221 Bluetooth device name is set correctly. 222 223 Returns: 224 Pass if True 225 Fail if False 226 227 TAGS: Classic 228 Priority: 1 229 """ 230 name = "SetDeviceName" 231 return set_device_name(self.droid_ad.droid, name) 232 233 @BluetoothBaseTest.bt_test_wrap 234 @test_tracker_info(uuid='b38fb110-a707-47cf-b1c3-981266373786') 235 def test_scan_mode_off(self): 236 """Test disabling bluetooth scanning. 237 238 Test that changes scan mode to off. 239 240 Steps: 241 1. Initialize android device. 242 2. Set scan mode STATE_OFF by disabling bluetooth. 243 3. Verify scan state. 244 245 Expected Result: 246 Verify scan state is off. 247 248 Returns: 249 Pass if True 250 Fail if False 251 252 TAGS: Classic 253 Priority: 1 254 """ 255 self.log.debug("Test scan mode STATE_OFF.") 256 return set_bt_scan_mode(self.droid_ad, bt_scan_mode_types['state_off']) 257 258 #@BluetoothTest(UUID=27576aa8-d52f-45ad-986a-f44fb565167d) 259 @BluetoothBaseTest.bt_test_wrap 260 @test_tracker_info(uuid='702c3d58-94fd-47ee-9323-2421ce182ddb') 261 def test_scan_mode_none(self): 262 """Test bluetooth scan mode none. 263 264 Test that changes scan mode to none. 265 266 Steps: 267 1. Initialize android device. 268 2. Set scan mode SCAN_MODE_NONE by disabling bluetooth. 269 3. Verify scan state. 270 271 Expected Result: 272 Verify that scan mode is set to none. 273 274 Returns: 275 Pass if True 276 Fail if False 277 278 TAGS: Classic 279 Priority: 1 280 """ 281 self.log.debug("Test scan mode SCAN_MODE_NONE.") 282 return set_bt_scan_mode(self.droid_ad, bt_scan_mode_types['none']) 283 284 @BluetoothBaseTest.bt_test_wrap 285 @test_tracker_info(uuid='cb998a99-31a6-46b6-9de6-a9a17081a604') 286 def test_scan_mode_connectable(self): 287 """Test bluetooth scan mode connectable. 288 289 Test that changes scan mode to connectable. 290 291 Steps: 292 1. Initialize android device. 293 2. Set scan mode SCAN_MODE_CONNECTABLE. 294 3. Verify scan state. 295 296 Expected Result: 297 Verify that scan mode is set to connectable. 298 299 Returns: 300 Pass if True 301 Fail if False 302 303 TAGS: Classic 304 Priority: 2 305 """ 306 self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE.") 307 return set_bt_scan_mode(self.droid_ad, 308 bt_scan_mode_types['connectable']) 309 310 @BluetoothBaseTest.bt_test_wrap 311 @test_tracker_info(uuid='59bec55c-c64e-43e4-9a9a-e44408a801d7') 312 def test_scan_mode_connectable_discoverable(self): 313 """Test bluetooth scan mode connectable. 314 315 Test that changes scan mode to connectable. 316 317 Steps: 318 1. Initialize android device. 319 2. Set scan mode SCAN_MODE_DISCOVERABLE. 320 3. Verify scan state. 321 322 Expected Result: 323 Verify that scan mode is set to discoverable. 324 325 Returns: 326 Pass if True 327 Fail if False 328 329 TAGS: Classic 330 Priority: 2 331 """ 332 self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE_DISCOVERABLE.") 333 return set_bt_scan_mode(self.droid_ad, 334 bt_scan_mode_types['connectable_discoverable']) 335 336 @BluetoothBaseTest.bt_test_wrap 337 @test_tracker_info(uuid='cd20a09d-a68d-4f55-b016-ba283b0460df') 338 def test_if_support_hid_profile(self): 339 """ Test that a single device can support HID profile. 340 Steps 341 1. Initialize one android devices 342 2. Check devices support profiles and return a dictionary 343 3. Check the value of key 'hid' 344 345 Expected Result: 346 Device1 is in the discovered devices list. 347 348 Returns: 349 Pass if True 350 Fail if False 351 352 TAGS: Classic 353 Priority: 1 354 """ 355 profiles = check_device_supported_profiles(self.droid_ad.droid) 356 if not profiles['hid']: 357 self.log.debug("Android device do not support HID profile.") 358 return False 359 return True 360 361 @BluetoothBaseTest.bt_test_wrap 362 @test_tracker_info(uuid='a110d330-7090-4784-a33b-33089dc5f67f') 363 def test_if_support_hsp_profile(self): 364 """ Test that a single device can support HSP profile. 365 Steps 366 1. Initialize one android devices 367 2. Check devices support profiles and return a dictionary 368 3. Check the value of key 'hsp' 369 :return: test_result: bool 370 """ 371 profiles = check_device_supported_profiles(self.droid_ad.droid) 372 if not profiles['hsp']: 373 self.log.debug("Android device do not support HSP profile.") 374 return False 375 return True 376 377 @BluetoothBaseTest.bt_test_wrap 378 @test_tracker_info(uuid='9ccefdd9-62a9-4aed-b4d9-7b0a55c338b2') 379 def test_if_support_a2dp_profile(self): 380 """ Test that a single device can support A2DP profile. 381 Steps 382 1. Initialize one android devices 383 2. Check devices support profiles and return a dictionary 384 3. Check the value of key 'a2dp' 385 :return: test_result: bool 386 """ 387 profiles = check_device_supported_profiles(self.droid_ad.droid) 388 if not profiles['a2dp']: 389 self.log.debug("Android device do not support A2DP profile.") 390 return False 391 return True 392