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 exercise Ble Scan Api's. This exercises all getters and 18 setters. This is important since there is a builder object that is immutable 19 after you set all attributes of each object. If this test suite doesn't pass, 20 then other test suites utilising Ble Scanner will also fail. 21 """ 22 23 from acts.controllers.sl4a_lib import rpc_client 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 ble_scan_settings_callback_types 27 from acts.test_utils.bt.bt_constants import ble_scan_settings_modes 28 from acts.test_utils.bt.bt_constants import ble_scan_settings_result_types 29 from acts.test_utils.bt.bt_constants import ble_scan_settings_report_delay_milli_seconds 30 from acts.test_utils.bt.bt_constants import ble_uuids 31 32 33 class BleScanResultsError(Exception): 34 """Error in getting scan results""" 35 36 37 class BleScanVerificationError(Exception): 38 """Error in comparing BleScan results""" 39 40 41 class BleSetScanSettingsError(Exception): 42 """Error in setting Ble Scan Settings""" 43 44 45 class BleSetScanFilterError(Exception): 46 """Error in setting Ble Scan Settings""" 47 48 49 class BleScanApiTest(BluetoothBaseTest): 50 def __init__(self, controllers): 51 BluetoothBaseTest.__init__(self, controllers) 52 self.ad_dut = self.android_devices[0] 53 54 def _format_defaults(self, input): 55 """ 56 Creates a dictionary of default ScanSetting and ScanFilter Values. 57 :return: input: dict 58 """ 59 if 'ScanSettings' not in input.keys(): 60 input['ScanSettings'] = ( 61 ble_scan_settings_callback_types['all_matches'], 0, 62 ble_scan_settings_modes['low_power'], 63 ble_scan_settings_result_types['full']) 64 if 'ScanFilterManufacturerDataId' not in input.keys(): 65 input['ScanFilterManufacturerDataId'] = -1 66 if 'ScanFilterDeviceName' not in input.keys(): 67 input['ScanFilterDeviceName'] = None 68 if 'ScanFilterDeviceAddress' not in input.keys(): 69 input['ScanFilterDeviceAddress'] = None 70 if 'ScanFilterManufacturerData' not in input.keys(): 71 input['ScanFilterManufacturerData'] = None 72 return input 73 74 def validate_scan_settings_helper(self, input, droid): 75 """ 76 Validates each input of the scan settings object that is matches what 77 was set or not set such that it matches the defaults. 78 :return: False at any point something doesn't match. True if everything 79 matches. 80 """ 81 filter_list = droid.bleGenFilterList() 82 if 'ScanSettings' in input.keys(): 83 try: 84 droid.bleSetScanSettingsCallbackType(input['ScanSettings'][0]) 85 droid.bleSetScanSettingsReportDelayMillis( 86 input['ScanSettings'][1]) 87 droid.bleSetScanSettingsScanMode(input['ScanSettings'][2]) 88 droid.bleSetScanSettingsResultType(input['ScanSettings'][3]) 89 except rpc_client.Sl4aApiError as error: 90 self.log.debug("Set Scan Settings failed with: ".format(error)) 91 return False 92 if 'ScanFilterDeviceName' in input.keys(): 93 try: 94 droid.bleSetScanFilterDeviceName(input['ScanFilterDeviceName']) 95 except rpc_client.Sl4aApiError as error: 96 self.log.debug("Set Scan Filter Device Name failed with: {}" 97 .format(error)) 98 return False 99 if 'ScanFilterDeviceAddress' in input.keys(): 100 try: 101 droid.bleSetScanFilterDeviceAddress( 102 input['ScanFilterDeviceAddress']) 103 except rpc_client.Sl4aApiError as error: 104 self.log.debug("Set Scan Filter Device Address failed with: {}" 105 .format(error)) 106 return False 107 if ('ScanFilterManufacturerDataId' in input.keys() 108 and 'ScanFilterManufacturerDataMask' in input.keys()): 109 try: 110 droid.bleSetScanFilterManufacturerData( 111 input['ScanFilterManufacturerDataId'], 112 input['ScanFilterManufacturerData'], 113 input['ScanFilterManufacturerDataMask']) 114 except rpc_client.Sl4aApiError as error: 115 self.log.debug("Set Scan Filter Manufacturer info with data " 116 "mask failed with: {}".format(error)) 117 return False 118 if ('ScanFilterManufacturerDataId' in input.keys() 119 and 'ScanFilterManufacturerData' in input.keys() 120 and 'ScanFilterManufacturerDataMask' not in input.keys()): 121 try: 122 droid.bleSetScanFilterManufacturerData( 123 input['ScanFilterManufacturerDataId'], 124 input['ScanFilterManufacturerData']) 125 except rpc_client.Sl4aApiError as error: 126 self.log.debug( 127 "Set Scan Filter Manufacturer info failed with: " 128 "{}".format(error)) 129 return False 130 if ('ScanFilterServiceUuid' in input.keys() 131 and 'ScanFilterServiceMask' in input.keys()): 132 133 droid.bleSetScanFilterServiceUuid(input['ScanFilterServiceUuid'], 134 input['ScanFilterServiceMask']) 135 136 input = self._format_defaults(input) 137 scan_settings_index = droid.bleBuildScanSetting() 138 scan_settings = ( 139 droid.bleGetScanSettingsCallbackType(scan_settings_index), 140 droid.bleGetScanSettingsReportDelayMillis(scan_settings_index), 141 droid.bleGetScanSettingsScanMode(scan_settings_index), 142 droid.bleGetScanSettingsScanResultType(scan_settings_index)) 143 144 scan_filter_index = droid.bleBuildScanFilter(filter_list) 145 device_name_filter = droid.bleGetScanFilterDeviceName( 146 filter_list, scan_filter_index) 147 device_address_filter = droid.bleGetScanFilterDeviceAddress( 148 filter_list, scan_filter_index) 149 manufacturer_id = droid.bleGetScanFilterManufacturerId( 150 filter_list, scan_filter_index) 151 manufacturer_data = droid.bleGetScanFilterManufacturerData( 152 filter_list, scan_filter_index) 153 154 if scan_settings != input['ScanSettings']: 155 self.log.debug("Scan Settings did not match. expected: {}, found: " 156 "{}".format(input['ScanSettings'], scan_settings)) 157 return False 158 if device_name_filter != input['ScanFilterDeviceName']: 159 self.log.debug("Scan Filter device name did not match. expected: " 160 "{}, found {}".format(input['ScanFilterDeviceName'], 161 device_name_filter)) 162 return False 163 if device_address_filter != input['ScanFilterDeviceAddress']: 164 self.log.debug( 165 "Scan Filter address name did not match. expected: " 166 "{}, found: {}".format(input['ScanFilterDeviceAddress'], 167 device_address_filter)) 168 return False 169 if manufacturer_id != input['ScanFilterManufacturerDataId']: 170 self.log.debug("Scan Filter manufacturer data id did not match. " 171 "expected: {}, found: {}".format( 172 input['ScanFilterManufacturerDataId'], 173 manufacturer_id)) 174 return False 175 if manufacturer_data != input['ScanFilterManufacturerData']: 176 self.log.debug("Scan Filter manufacturer data did not match. " 177 "expected: {}, found: {}".format( 178 input['ScanFilterManufacturerData'], 179 manufacturer_data)) 180 return False 181 if 'ScanFilterManufacturerDataMask' in input.keys(): 182 manufacturer_data_mask = droid.bleGetScanFilterManufacturerDataMask( 183 filter_list, scan_filter_index) 184 if manufacturer_data_mask != input['ScanFilterManufacturerDataMask']: 185 self.log.debug( 186 "Manufacturer data mask did not match. expected:" 187 " {}, found: {}".format( 188 input['ScanFilterManufacturerDataMask'], 189 manufacturer_data_mask)) 190 191 return False 192 if ('ScanFilterServiceUuid' in input.keys() 193 and 'ScanFilterServiceMask' in input.keys()): 194 195 expected_service_uuid = input['ScanFilterServiceUuid'] 196 expected_service_mask = input['ScanFilterServiceMask'] 197 service_uuid = droid.bleGetScanFilterServiceUuid( 198 filter_list, scan_filter_index) 199 service_mask = droid.bleGetScanFilterServiceUuidMask( 200 filter_list, scan_filter_index) 201 if service_uuid != expected_service_uuid.lower(): 202 self.log.debug("Service uuid did not match. expected: {}, " 203 "found {}".format(expected_service_uuid, 204 service_uuid)) 205 return False 206 if service_mask != expected_service_mask.lower(): 207 self.log.debug("Service mask did not match. expected: {}, " 208 "found {}".format(expected_service_mask, 209 service_mask)) 210 return False 211 self.scan_settings_index = scan_settings_index 212 self.filter_list = filter_list 213 self.scan_callback = droid.bleGenScanCallback() 214 return True 215 216 @BluetoothBaseTest.bt_test_wrap 217 @test_tracker_info(uuid='5ffc9f7b-c261-4bf0-9a6b-7fda182b6c97') 218 def test_start_ble_scan_with_default_settings(self): 219 """Test LE scan with default settings. 220 221 Test to validate all default scan settings values. 222 223 Steps: 224 1. Create LE scan objects. 225 2. Start LE scan. 226 227 Expected Result: 228 Scan starts successfully and matches expected settings. 229 230 Returns: 231 Pass if True 232 Fail if False 233 234 TAGS: LE, Scanning 235 Priority: 1 236 """ 237 input = {} 238 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 239 240 @BluetoothBaseTest.bt_test_wrap 241 @test_tracker_info(uuid='88c3b0cb-b4d4-45d1-be25-9855290a6d03') 242 def test_stop_ble_scan_default_settings(self): 243 """Test stopping an LE scan. 244 245 Test default scan settings on an actual scan. Verify it can also stop 246 the scan. 247 248 Steps: 249 1. Validate default scan settings. 250 2. Start ble scan. 251 3. Stop ble scan. 252 253 Expected Result: 254 LE scan is stopped successfully. 255 256 Returns: 257 Pass if True 258 Fail if False 259 260 TAGS: LE, Scanning 261 Priority: 0 262 """ 263 input = {} 264 test_result = self.validate_scan_settings_helper( 265 input, self.ad_dut.droid) 266 if not test_result: 267 self.log.error("Could not setup ble scanner.") 268 return test_result 269 self.ad_dut.droid.bleStartBleScan( 270 self.filter_list, self.scan_settings_index, self.scan_callback) 271 try: 272 self.ad_dut.droid.bleStopBleScan(self.scan_callback) 273 except BleScanResultsError as error: 274 self.log.error(str(error)) 275 test_result = False 276 return test_result 277 278 @BluetoothBaseTest.bt_test_wrap 279 @test_tracker_info(uuid='5aa7a4c2-0b7d-4000-a980-f00c9329a7b9') 280 def test_scan_settings_callback_type_all_matches(self): 281 """Test LE scan settings callback type all matches. 282 283 Test scan settings callback type all matches. 284 285 Steps: 286 1. Validate the scan settings callback type with all other settings set 287 to their respective defaults. 288 289 Expected Result: 290 Expected Scan settings should match found scan settings. 291 292 Returns: 293 Pass if True 294 Fail if False 295 296 TAGS: LE, Scanning 297 Priority: 1 298 """ 299 input = {} 300 input["ScanSettings"] = ( 301 ble_scan_settings_callback_types['all_matches'], 0, 302 ble_scan_settings_modes['low_power'], 303 ble_scan_settings_result_types['full']) 304 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 305 306 @BluetoothBaseTest.bt_test_wrap 307 @test_tracker_info(uuid='fd764861-aa76-480e-b2d2-5d55a888d123') 308 def test_scan_settings_set_callback_type_first_match(self): 309 """Test LE scan settings callback type first match 310 311 Test scan settings callback type first match. 312 313 Steps: 314 1. Validate the scan settings callback type with all other settings set 315 to their respective defaults. 316 317 Expected Result: 318 Expected Scan settings should match found scan settings. 319 320 Returns: 321 Pass if True 322 Fail if False 323 324 TAGS: LE, Scanning 325 Priority: 1 326 """ 327 input = {} 328 input["ScanSettings"] = ( 329 ble_scan_settings_callback_types['first_match'], 0, 330 ble_scan_settings_modes['low_power'], 331 ble_scan_settings_result_types['full']) 332 test_result = self.validate_scan_settings_helper( 333 input, self.ad_dut.droid) 334 return test_result 335 336 @BluetoothBaseTest.bt_test_wrap 337 @test_tracker_info(uuid='52e4626e-199c-4755-b9f1-8b38ecb30896') 338 def test_scan_settings_set_callback_type_match_lost(self): 339 """Test LE scan settings callback type match lost. 340 341 Test scan settings callback type match lost. 342 343 Steps: 344 1. Validate the scan settings callback type with all other settings set 345 to their respective defaults. 346 347 Expected Result: 348 Expected Scan settings should match found scan settings. 349 350 Returns: 351 Pass if True 352 Fail if False 353 354 TAGS: LE, Scanning 355 Priority: 1 356 """ 357 input = {} 358 input["ScanSettings"] = ( 359 ble_scan_settings_callback_types['match_lost'], 0, 360 ble_scan_settings_modes['low_power'], 361 ble_scan_settings_result_types['full']) 362 test_result = self.validate_scan_settings_helper( 363 input, self.ad_dut.droid) 364 return test_result 365 366 @BluetoothBaseTest.bt_test_wrap 367 @test_tracker_info(uuid='57476b3c-ba7a-4342-86f6-1b56b2c00181') 368 def test_scan_settings_set_invalid_callback_type(self): 369 """Test LE scan settings invalid callback type. 370 371 Test scan settings invalid callback type -1. 372 373 Steps: 374 1. Build a LE ScanSettings object with an invalid callback type. 375 376 Expected Result: 377 Api should fail to build object. 378 379 Returns: 380 Pass if True 381 Fail if False 382 383 TAGS: LE, Scanning 384 Priority: 2 385 """ 386 input = {} 387 input["ScanSettings"] = (-1, 0, ble_scan_settings_modes['low_power'], 388 ble_scan_settings_result_types['full']) 389 test_result = self.validate_scan_settings_helper( 390 input, self.ad_dut.droid) 391 return not test_result 392 393 @BluetoothBaseTest.bt_test_wrap 394 @test_tracker_info(uuid='52c80f0c-4f26-4cda-8a6b-291ac52f673a') 395 def test_scan_settings_set_scan_mode_low_power(self): 396 """Test LE scan settings scan mode low power mode. 397 398 Test scan settings scan mode low power. 399 400 Steps: 401 1. Validate the scan settings scan mode with all other settings set to 402 their respective defaults. 403 404 Expected Result: 405 Expected Scan settings should match found scan settings. 406 407 Returns: 408 Pass if True 409 Fail if False 410 411 TAGS: LE, Scanning 412 Priority: 1 413 """ 414 input = {} 415 input["ScanSettings"] = ( 416 ble_scan_settings_callback_types['all_matches'], 0, 417 ble_scan_settings_modes['low_power'], 418 ble_scan_settings_result_types['full']) 419 test_result = self.validate_scan_settings_helper( 420 input, self.ad_dut.droid) 421 return test_result 422 423 @BluetoothBaseTest.bt_test_wrap 424 @test_tracker_info(uuid='20f4513c-44a7-435d-be4e-03420093297a') 425 def test_scan_settings_set_scan_mode_balanced(self): 426 """Test LE scan settings scan mode balanced. 427 428 Test scan settings scan mode balanced. 429 430 Steps: 431 1. Validate the scan settings scan mode with all other settings set to 432 their respective defaults. 433 434 Expected Result: 435 Expected Scan settings should match found scan settings. 436 437 Returns: 438 Pass if True 439 Fail if False 440 441 TAGS: LE, Scanning 442 Priority: 1 443 """ 444 input = {} 445 input["ScanSettings"] = ( 446 ble_scan_settings_callback_types['all_matches'], 0, 447 ble_scan_settings_modes['balanced'], 448 ble_scan_settings_result_types['full']) 449 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 450 451 @BluetoothBaseTest.bt_test_wrap 452 @test_tracker_info(uuid='bf14e7fd-853b-4833-8fef-8c4bd629374b') 453 def test_scan_settings_set_scan_mode_low_latency(self): 454 """Test LE scan settings scan mode low latency. 455 456 Test scan settings scan mode low latency. 457 458 Steps: 459 1. Validate the scan settings scan mode with all other settings set to 460 their respective defaults. 461 462 Expected Result: 463 Expected Scan settings should match found scan settings. 464 465 Returns: 466 Pass if True 467 Fail if False 468 469 TAGS: LE, Scanning 470 Priority: 1 471 """ 472 input = {} 473 input["ScanSettings"] = ( 474 ble_scan_settings_callback_types['all_matches'], 0, 475 ble_scan_settings_modes['low_latency'], 476 ble_scan_settings_result_types['full']) 477 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 478 479 @BluetoothBaseTest.bt_test_wrap 480 @test_tracker_info(uuid='9f3b2e10-98f8-4d6a-b6b6-e8dee87063f0') 481 def test_scan_settings_set_invalid_scan_mode(self): 482 """Test LE scan settings scan mode as an invalid value. 483 Test scan settings invalid scan mode -2. 484 Steps: 485 1. Set the scan settings scan mode to -2. 486 487 Expected Result: 488 Building the ScanSettings object should fail. 489 490 Returns: 491 Pass if True 492 Fail if False 493 494 TAGS: LE, Scanning 495 Priority: 1 496 """ 497 input = {} 498 input["ScanSettings"] = ( 499 ble_scan_settings_callback_types['all_matches'], 0, -2, 500 ble_scan_settings_result_types['full']) 501 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 502 503 @BluetoothBaseTest.bt_test_wrap 504 @test_tracker_info(uuid='cb246be7-4fef-4313-964d-5fb6dbe558c8') 505 def test_scan_settings_set_report_delay_millis_min(self): 506 """Test scan settings report delay millis as min value 507 508 Test scan settings report delay millis min acceptable value. 509 510 Steps: 511 1. Validate the scan settings report delay millis with all other 512 settings set to their respective defaults. 513 514 Expected Result: 515 Expected Scan settings should match found scan settings. 516 517 Returns: 518 Pass if True 519 Fail if False 520 521 TAGS: LE, Scanning 522 Priority: 2 523 """ 524 input = {} 525 input["ScanSettings"] = ( 526 ble_scan_settings_callback_types['all_matches'], 527 ble_scan_settings_report_delay_milli_seconds['min'], 528 ble_scan_settings_modes['low_power'], 529 ble_scan_settings_result_types['full']) 530 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 531 532 @BluetoothBaseTest.bt_test_wrap 533 @test_tracker_info(uuid='db1ea8f6-503d-4e9a-b61a-01210508c5a2') 534 def test_scan_settings_set_report_delay_millis_min_plus_one(self): 535 """Test scan settings report delay millis as min value plus one. 536 537 Test scan settings report delay millis as min value plus one. 538 539 Steps: 540 1. Validate the scan settings report delay millis with all other 541 settings set to their respective defaults. 542 543 Expected Result: 544 Expected Scan settings should match found scan settings. 545 546 Returns: 547 Pass if True 548 Fail if False 549 550 TAGS: LE, Scanning 551 Priority: 4 552 """ 553 input = {} 554 input["ScanSettings"] = ( 555 ble_scan_settings_callback_types['all_matches'], 556 ble_scan_settings_report_delay_milli_seconds['min'] + 1, 557 ble_scan_settings_modes['low_power'], 558 ble_scan_settings_result_types['full']) 559 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 560 561 @BluetoothBaseTest.bt_test_wrap 562 @test_tracker_info(uuid='54e83ff8-92b0-473e-839a-1ff1c7dcea83') 563 def test_scan_settings_set_report_delay_millis_max(self): 564 """Test scan settings report delay millis as max value. 565 566 Test scan settings report delay millis max value. 567 568 Steps: 569 1. Validate the scan settings report delay millis with all other 570 settings set to their respective defaults. 571 572 Expected Result: 573 Expected Scan settings should match found scan settings. 574 575 Returns: 576 Pass if True 577 Fail if False 578 579 TAGS: LE, Scanning 580 Priority: 3 581 """ 582 input = {} 583 input["ScanSettings"] = ( 584 ble_scan_settings_callback_types['all_matches'], 585 ble_scan_settings_report_delay_milli_seconds['max'], 586 ble_scan_settings_modes['low_power'], 587 ble_scan_settings_result_types['full']) 588 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 589 590 @BluetoothBaseTest.bt_test_wrap 591 @test_tracker_info(uuid='45d918ec-7e43-463b-8f07-f009f8808903') 592 def test_scan_settings_set_report_delay_millis_max_minus_one(self): 593 """Test scan settings report delay millis as max value minus one. 594 595 Test scan settings report delay millis max value - 1. 596 597 Steps: 598 1. Validate the scan settings report delay millis with all other 599 settings set to their respective defaults. 600 601 Expected Result: 602 Expected Scan settings should match found scan settings. 603 604 Returns: 605 Pass if True 606 Fail if False 607 608 TAGS: LE, Scanning 609 Priority: 3 610 """ 611 input = {} 612 input["ScanSettings"] = ( 613 ble_scan_settings_callback_types['all_matches'], 614 ble_scan_settings_report_delay_milli_seconds['max'] - 1, 615 ble_scan_settings_modes['low_power'], 616 ble_scan_settings_result_types['full']) 617 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 618 619 @BluetoothBaseTest.bt_test_wrap 620 @test_tracker_info(uuid='eb94b5ee-f2e7-4322-b3df-7bdd3a250262') 621 def test_scan_settings_set_invalid_report_delay_millis_min_minus_one(self): 622 """Test scan settings report delay millis as an invalid value. 623 624 Test scan settings invalid report delay millis min value - 1. 625 626 Steps: 627 1. Set scan settings report delay millis to min value -1. 628 2. Build scan settings object. 629 630 Expected Result: 631 Building scan settings object should fail. 632 633 Returns: 634 Pass if True 635 Fail if False 636 637 TAGS: LE, Scanning 638 Priority: 2 639 """ 640 droid = self.ad_dut.droid 641 input = {} 642 input["ScanSettings"] = ( 643 ble_scan_settings_callback_types['all_matches'], 644 ble_scan_settings_report_delay_milli_seconds['min'] - 1, 645 ble_scan_settings_modes['low_power'], 646 ble_scan_settings_result_types['full']) 647 return not self.validate_scan_settings_helper(input, droid) 648 649 @BluetoothBaseTest.bt_test_wrap 650 @test_tracker_info(uuid='8f5a2bd0-6037-4ac6-a962-f11e7fc13920') 651 def test_scan_settings_set_scan_result_type_full(self): 652 """Test scan settings result type full. 653 654 Test scan settings result type full. 655 656 Steps: 657 1. Validate the scan settings result type with all other settings 658 set to their respective defaults. 659 660 Expected Result: 661 Expected Scan settings should match found scan settings. 662 663 Returns: 664 Pass if True 665 Fail if False 666 667 TAGS: LE, Scanning 668 Priority: 1 669 """ 670 input = {} 671 input["ScanSettings"] = ( 672 ble_scan_settings_callback_types['all_matches'], 0, 673 ble_scan_settings_modes['low_power'], 674 ble_scan_settings_result_types['full']) 675 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 676 677 @BluetoothBaseTest.bt_test_wrap 678 @test_tracker_info(uuid='610fe301-600e-443e-a28b-cd722cc8a4c1') 679 def test_scan_settings_set_scan_result_type_abbreviated(self): 680 """Test scan settings result type abbreviated. 681 682 Test scan settings result type abbreviated. 683 684 Steps: 685 1. Validate the scan settings result type with all other settings 686 set to their respective defaults. 687 688 Expected Result: 689 Expected Scan settings should match found scan settings. 690 691 Returns: 692 Pass if True 693 Fail if False 694 695 TAGS: LE, Scanning 696 Priority: 1 697 """ 698 input = {} 699 input["ScanSettings"] = ( 700 ble_scan_settings_callback_types['all_matches'], 0, 701 ble_scan_settings_modes['low_power'], 702 ble_scan_settings_result_types['abbreviated']) 703 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 704 705 @BluetoothBaseTest.bt_test_wrap 706 @test_tracker_info(uuid='ed58430b-8180-472f-a118-64f5fce5e84c') 707 def test_scan_settings_set_invalid_scan_result_type(self): 708 """Test scan settings result type as an invalid value. 709 710 Test scan settings invalid result type -1. 711 712 Steps: 713 1. Set scan settings result type as an invalid value. 714 2. Build scan settings object. 715 716 Expected Result: 717 Expected Scan settings should match found scan settings. 718 719 Returns: 720 Pass if True 721 Fail if False 722 723 TAGS: LE, Scanning 724 Priority: 2 725 """ 726 input = {} 727 input["ScanSettings"] = ( 728 ble_scan_settings_callback_types['all_matches'], 0, 729 ble_scan_settings_modes['low_power'], -1) 730 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 731 732 @BluetoothBaseTest.bt_test_wrap 733 @test_tracker_info(uuid='6489665f-313d-4b1b-bd7f-f0fdeeaad335') 734 def test_scan_filter_set_device_name(self): 735 """Test scan filter set valid device name. 736 737 Test scan filter device name sl4atest. 738 739 Steps: 740 1. Validate the scan filter device name with all other settings 741 set to their respective defaults. 742 743 Expected Result: 744 Expected Scan filter should match found scan settings. 745 746 Returns: 747 Pass if True 748 Fail if False 749 750 TAGS: LE, Scanning 751 Priority: 1 752 """ 753 input = {} 754 input['ScanFilterDeviceName'] = "sl4atest" 755 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 756 757 @BluetoothBaseTest.bt_test_wrap 758 @test_tracker_info(uuid='76021a9a-14ca-4a2f-a908-96ab90db39ce') 759 def test_scan_filter_set_device_name_blank(self): 760 """Test scan filter set blank device name. 761 762 Test scan filter device name blank. 763 764 Steps: 765 1. Validate the scan filter device name with all other settings 766 set to their respective defaults. 767 768 Expected Result: 769 Expected Scan filter should match found scan filter. 770 771 Returns: 772 Pass if True 773 Fail if False 774 775 TAGS: LE, Scanning 776 Priority: 1 777 """ 778 droid = self.ad_dut.droid 779 input = {} 780 input['ScanFilterDeviceName'] = "" 781 return self.validate_scan_settings_helper(input, droid) 782 783 @BluetoothBaseTest.bt_test_wrap 784 @test_tracker_info(uuid='d77c3d81-43a9-4572-a99b-87969117ede5') 785 def test_scan_filter_set_device_name_special_chars(self): 786 """Test scan filter set device name as special chars. 787 788 Test scan filter device name special characters. 789 790 Steps: 791 1. Validate the scan filter device name with all other settings 792 set to their respective defaults. 793 794 Expected Result: 795 Expected Scan filter should match found scan filter. 796 797 Returns: 798 Pass if True 799 Fail if False 800 801 TAGS: LE, Scanning 802 Priority: 1 803 """ 804 input = {} 805 input['ScanFilterDeviceName'] = "!@#$%^&*()\":<>/" 806 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 807 808 @BluetoothBaseTest.bt_test_wrap 809 @test_tracker_info(uuid='1697004e-76ab-444b-9419-0437e30444ad') 810 def test_scan_filter_set_device_address(self): 811 """Test scan filter set valid device address. 812 813 Test scan filter device address valid. 814 815 Steps: 816 1. Validate the scan filter device address with all other settings 817 set to their respective defaults. 818 819 Expected Result: 820 Expected Scan filter should match found scan filter. 821 822 Returns: 823 Pass if True 824 Fail if False 825 826 TAGS: LE, Scanning 827 Priority: 1 828 """ 829 input = {} 830 input['ScanFilterDeviceAddress'] = "01:02:03:AB:CD:EF" 831 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 832 833 @BluetoothBaseTest.bt_test_wrap 834 @test_tracker_info(uuid='eab0409c-7fc5-4d1f-8fbe-5ee2bb743f7e') 835 def test_scan_filter_set_invalid_device_address_lower_case(self): 836 """Test scan filter set invalid device address. 837 838 Test scan filter device address lower case. 839 840 Steps: 841 1. Set the scan filter address to an invalid, lowercase mac address 842 843 Expected Result: 844 Api to build scan filter should fail. 845 846 Returns: 847 Pass if True 848 Fail if False 849 850 TAGS: LE, Scanning 851 Priority: 2 852 """ 853 input = {} 854 input['ScanFilterDeviceAddress'] = "01:02:03:ab:cd:ef" 855 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 856 857 @BluetoothBaseTest.bt_test_wrap 858 @test_tracker_info(uuid='0ec491ac-d273-468e-bbfe-e36a290aeb2a') 859 def test_scan_filter_set_invalid_device_address_blank(self): 860 """Test scan filter set invalid device address. 861 862 Test scan filter invalid device address blank. 863 864 Steps: 865 1. Set the scan filter address to an invalid, blank mac address 866 867 Expected Result: 868 Api to build scan filter should fail. 869 870 Returns: 871 Pass if True 872 Fail if False 873 874 TAGS: LE, Scanning 875 Priority: 2 876 """ 877 input = {} 878 input['ScanFilterDeviceAddress'] = "" 879 test_result = self.validate_scan_settings_helper( 880 input, self.ad_dut.droid) 881 return not test_result 882 883 @BluetoothBaseTest.bt_test_wrap 884 @test_tracker_info(uuid='5cebc454-091c-4e46-b200-1e52c8dffbec') 885 def test_scan_filter_set_invalid_device_address_bad_format(self): 886 """Test scan filter set badly formatted device address. 887 888 Test scan filter badly formatted device address. 889 890 Steps: 891 1. Set the scan filter address to an invalid, blank mac address 892 893 Expected Result: 894 Api to build scan filter should fail. 895 896 Returns: 897 Pass if True 898 Fail if False 899 900 TAGS: LE, Scanning 901 Priority: 2 902 """ 903 input = {} 904 input['ScanFilterDeviceAddress'] = "10.10.10.10.10" 905 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 906 907 @BluetoothBaseTest.bt_test_wrap 908 @test_tracker_info(uuid='d5249d10-1486-4c38-a22d-1f1b077926db') 909 def test_scan_filter_set_invalid_device_address_bad_address(self): 910 """Test scan filter device address as an invalid value. 911 912 Test scan filter invalid device address invalid characters. 913 914 Steps: 915 1. Set a scan filter's device address as ZZ:ZZ:ZZ:ZZ:ZZ:ZZ 916 917 Expected Result: 918 Api to build the scan filter should fail. 919 920 Returns: 921 Pass if True 922 Fail if False 923 924 TAGS: LE, Scanning 925 Priority: 1 926 """ 927 input = {} 928 input['ScanFilterDeviceAddress'] = "ZZ:ZZ:ZZ:ZZ:ZZ:ZZ" 929 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 930 931 @BluetoothBaseTest.bt_test_wrap 932 @test_tracker_info(uuid='65c62d50-69f6-4a0b-bd74-2340e0ce32ca') 933 def test_scan_filter_set_manufacturer_id_data(self): 934 """Test scan filter manufacturer data. 935 936 Test scan filter manufacturer data with a valid input. 937 938 Steps: 939 1. Validate the scan filter manufacturer id with all other settings 940 set to their respective defaults. 941 942 Expected Result: 943 Expected Scan filter should match found scan filter. 944 945 Returns: 946 Pass if True 947 Fail if False 948 949 TAGS: LE, Scanning 950 Priority: 1 951 """ 952 expected_manufacturer_id = 0 953 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 954 input = {} 955 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 956 input['ScanFilterManufacturerData'] = expected_manufacturer_data 957 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 958 959 @BluetoothBaseTest.bt_test_wrap 960 @test_tracker_info(uuid='12807021-9f66-4784-b34a-80859cf4a32f') 961 def test_scan_filter_set_manufacturer_id_data_mask(self): 962 """Test scan filter manufacturer data mask. 963 964 Test scan filter manufacturer data with a valid data mask. 965 966 Steps: 967 1. Validate the scan filter manufacturer id with all other settings 968 set to their respective defaults. 969 970 Expected Result: 971 Expected Scan filter should match found scan filter. 972 973 Returns: 974 Pass if True 975 Fail if False 976 977 TAGS: LE, Scanning 978 Priority: 1 979 """ 980 expected_manufacturer_id = 1 981 expected_manufacturer_data = [1] 982 expected_manufacturer_data_mask = [1, 2, 1, 3, 4, 5, 6] 983 input = {} 984 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 985 input['ScanFilterManufacturerData'] = expected_manufacturer_data 986 input[ 987 'ScanFilterManufacturerDataMask'] = expected_manufacturer_data_mask 988 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 989 990 @BluetoothBaseTest.bt_test_wrap 991 @test_tracker_info(uuid='980e5ab6-5381-4471-8e5b-0b716665a9b8') 992 def test_scan_filter_set_manufacturer_max_id(self): 993 """Test scan filter manufacturer data id. 994 995 Test scan filter manufacturer data max id. 996 997 Steps: 998 1. Validate the scan filter manufacturer id with all other settings 999 set to their respective defaults. 1000 1001 Expected Result: 1002 Expected Scan filter should match found scan filter. 1003 1004 Returns: 1005 Pass if True 1006 Fail if False 1007 1008 TAGS: LE, Scanning 1009 Priority: 2 1010 """ 1011 expected_manufacturer_id = 2147483647 1012 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 1013 input = {} 1014 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1015 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1016 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1017 1018 @BluetoothBaseTest.bt_test_wrap 1019 @test_tracker_info(uuid='cf0efe38-8621-4288-be26-742719da2f6c') 1020 def test_scan_filter_set_manufacturer_data_empty(self): 1021 """Test scan filter empty manufacturer data. 1022 1023 Test scan filter manufacturer data as empty but valid manufacturer data. 1024 1025 Steps: 1026 1. Validate the scan filter manufacturer id with all other settings 1027 set to their respective defaults. 1028 1029 Expected Result: 1030 Expected Scan filter should match found scan filter. 1031 1032 Returns: 1033 Pass if True 1034 Fail if False 1035 1036 TAGS: LE, Scanning 1037 Priority: 2 1038 """ 1039 expected_manufacturer_id = 1 1040 expected_manufacturer_data = [] 1041 input = {} 1042 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1043 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1044 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1045 1046 @BluetoothBaseTest.bt_test_wrap 1047 @test_tracker_info(uuid='7ea0e82e-e92a-469c-8432-8f21978508cb') 1048 def test_scan_filter_set_manufacturer_data_mask_empty(self): 1049 """Test scan filter empty manufacturer data mask. 1050 1051 Test scan filter manufacturer mask empty. 1052 1053 Steps: 1054 1. Validate the scan filter manufacturer id with all other settings 1055 set to their respective defaults. 1056 1057 Expected Result: 1058 Expected Scan filter should match found scan filter. 1059 1060 Returns: 1061 Pass if True 1062 Fail if False 1063 1064 TAGS: LE, Scanning 1065 Priority: 1 1066 """ 1067 expected_manufacturer_id = 1 1068 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 1069 expected_manufacturer_data_mask = [] 1070 input = {} 1071 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1072 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1073 input[ 1074 'ScanFilterManufacturerDataMask'] = expected_manufacturer_data_mask 1075 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1076 1077 @BluetoothBaseTest.bt_test_wrap 1078 @test_tracker_info(uuid='88e4a9b8-afae-48cb-873a-fd6b4ef84116') 1079 def test_scan_filter_set_invalid_manufacturer_min_id_minus_one(self): 1080 """Test scan filter invalid manufacturer data. 1081 1082 Test scan filter invalid manufacturer id min value - 1. 1083 1084 Steps: 1085 1. Set the scan filters manufacturer id to -1. 1086 2. Build the scan filter. 1087 1088 Expected Result: 1089 Api to build the scan filter should fail. 1090 1091 Returns: 1092 Pass if True 1093 Fail if False 1094 1095 TAGS: LE, Scanning 1096 Priority: 2 1097 """ 1098 expected_manufacturer_id = -1 1099 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 1100 input = {} 1101 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1102 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1103 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 1104 1105 @BluetoothBaseTest.bt_test_wrap 1106 @test_tracker_info(uuid='2e8438dc-29cd-4f72-8747-4a161974d4d3') 1107 def test_scan_filter_set_service_uuid(self): 1108 """Test scan filter set valid service uuid. 1109 1110 Test scan filter service uuid. 1111 1112 Steps: 1113 1. Validate the scan filter service uuid with all other settings 1114 set to their respective defaults. 1115 1116 Expected Result: 1117 Expected Scan filter should match found scan filter. 1118 1119 Returns: 1120 Pass if True 1121 Fail if False 1122 1123 TAGS: LE, Scanning 1124 Priority: 1 1125 """ 1126 expected_service_uuid = "00000000-0000-1000-8000-00805F9B34FB" 1127 expected_service_mask = "00000000-0000-1000-8000-00805F9B34FB" 1128 input = {} 1129 input['ScanFilterServiceUuid'] = expected_service_uuid 1130 input['ScanFilterServiceMask'] = expected_service_mask 1131 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1132 1133 @BluetoothBaseTest.bt_test_wrap 1134 @test_tracker_info(uuid='e07b9985-44b6-4dc4-b570-0833b5d2893c') 1135 def test_scan_filter_service_uuid_p_service(self): 1136 """Test scan filter service uuid. 1137 1138 Test scan filter service uuid p service 1139 1140 Steps: 1141 1. Validate the scan filter service uuid with all other settings 1142 set to their respective defaults. 1143 1144 Expected Result: 1145 Expected Scan filter should match found scan filter. 1146 1147 Returns: 1148 Pass if True 1149 Fail if False 1150 1151 TAGS: LE, Scanning 1152 Priority: 2 1153 """ 1154 expected_service_uuid = ble_uuids['p_service'] 1155 expected_service_mask = "00000000-0000-1000-8000-00805F9B34FB" 1156 self.log.debug("Step 1: Setup environment.") 1157 1158 input = {} 1159 input['ScanFilterServiceUuid'] = expected_service_uuid 1160 input['ScanFilterServiceMask'] = expected_service_mask 1161 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1162 1163 @BluetoothBaseTest.bt_test_wrap 1164 @test_tracker_info(uuid='0467af19-6e9a-4cfe-9e10-878b0c224df2') 1165 def test_classic_ble_scan_with_service_uuids_p(self): 1166 """Test classic LE scan with valid service uuid. 1167 1168 Test classic ble scan with scan filter service uuid p service uuids. 1169 1170 Steps: 1171 1. Validate the scan filter service uuid with all other settings 1172 set to their respective defaults. 1173 2. Start classic ble scan. 1174 3. Stop classic ble scan 1175 1176 Expected Result: 1177 Expected Scan filter should match found scan filter. 1178 1179 Returns: 1180 Pass if True 1181 Fail if False 1182 1183 TAGS: LE, Scanning 1184 Priority: 1 1185 """ 1186 1187 droid = self.ad_dut.droid 1188 service_uuid_list = [ble_uuids['p_service']] 1189 scan_callback = droid.bleGenLeScanCallback() 1190 return self.verify_classic_ble_scan_with_service_uuids( 1191 droid, scan_callback, service_uuid_list) 1192 1193 @BluetoothBaseTest.bt_test_wrap 1194 @test_tracker_info(uuid='516c295f-a2df-44f6-b2ad-54451af43ce8') 1195 def test_classic_ble_scan_with_service_uuids_hr(self): 1196 """Test classic LE scan with valid service uuid. 1197 1198 Test classic ble scan with scan filter service uuid hr service 1199 1200 Steps: 1201 1. Validate the scan filter service uuid with all other settings 1202 set to their respective defaults. 1203 2. Start classic ble scan. 1204 3. Stop classic ble scan 1205 1206 Expected Result: 1207 Expected Scan filter should match found scan filter. 1208 1209 Returns: 1210 Pass if True 1211 Fail if False 1212 1213 TAGS: LE, Scanning 1214 Priority: 1 1215 """ 1216 droid = self.ad_dut.droid 1217 service_uuid_list = [ble_uuids['hr_service']] 1218 scan_callback = droid.bleGenLeScanCallback() 1219 return self.verify_classic_ble_scan_with_service_uuids( 1220 droid, scan_callback, service_uuid_list) 1221 1222 @BluetoothBaseTest.bt_test_wrap 1223 @test_tracker_info(uuid='0458b5e0-bb0b-4d6e-ab79-e21169d3256b') 1224 def test_classic_ble_scan_with_service_uuids_empty_uuid_list(self): 1225 """Test classic LE scan with empty but valid uuid list. 1226 1227 Test classic ble scan with service uuids as empty list. 1228 1229 Steps: 1230 1. Validate the scan filter service uuid with all other settings 1231 set to their respective defaults. 1232 2. Start classic ble scan. 1233 3. Stop classic ble scan 1234 1235 Expected Result: 1236 Expected Scan filter should match found scan filter. 1237 1238 Returns: 1239 Pass if True 1240 Fail if False 1241 1242 TAGS: LE, Scanning 1243 Priority: 1 1244 """ 1245 droid = self.ad_dut.droid 1246 service_uuid_list = [] 1247 scan_callback = droid.bleGenLeScanCallback() 1248 return self.verify_classic_ble_scan_with_service_uuids( 1249 droid, scan_callback, service_uuid_list) 1250 1251 @BluetoothBaseTest.bt_test_wrap 1252 @test_tracker_info(uuid='c0d84a37-c86c-43c4-9dc7-d16959fdbc2a') 1253 def test_classic_ble_scan_with_service_uuids_hr_and_p(self): 1254 """Test classic LE scan with multiple service uuids. 1255 1256 Test classic ble scan with service uuids a list of hr and p service. 1257 1258 Steps: 1259 1. Validate the scan filter service uuid with all other settings 1260 set to their respective defaults. 1261 2. Start classic ble scan. 1262 3. Stop classic ble scan 1263 1264 Expected Result: 1265 Expected Scan filter should match found scan filter. 1266 1267 Returns: 1268 Pass if True 1269 Fail if False 1270 1271 TAGS: LE, Scanning 1272 Priority: 1 1273 """ 1274 droid = self.ad_dut.droid 1275 service_uuid_list = [ble_uuids['hr_service'], ble_uuids['p_service']] 1276 scan_callback = droid.bleGenLeScanCallback() 1277 return self.verify_classic_ble_scan_with_service_uuids( 1278 droid, scan_callback, service_uuid_list) 1279 1280 def verify_classic_ble_scan_with_service_uuids(self, droid, scan_callback, 1281 service_uuid_list): 1282 1283 test_result = True 1284 try: 1285 test_result = droid.bleStartClassicBleScanWithServiceUuids( 1286 scan_callback, service_uuid_list) 1287 except BleScanResultsError as error: 1288 self.log.error(str(error)) 1289 return False 1290 droid.bleStopClassicBleScan(scan_callback) 1291 if not test_result: 1292 self.log.error( 1293 "Start classic ble scan with service uuids return false " 1294 "boolean value.") 1295 return False 1296 return True 1297