tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 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 test the integrity of LE scan results upon resetting the |
| 18 | Bluetooth stack. |
| 19 | """ |
| 20 | |
| 21 | import concurrent |
| 22 | import os |
| 23 | import time |
| 24 | |
| 25 | from queue import Empty |
tturney | 31ae5b6 | 2017-07-21 15:48:35 -0700 | [diff] [blame^] | 26 | from acts.test_decorators import test_tracker_info |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 27 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
tturney | 31ae5b6 | 2017-07-21 15:48:35 -0700 | [diff] [blame^] | 28 | from acts.test_utils.bt.bt_constants import ble_advertise_settings_modes |
| 29 | from acts.test_utils.bt.bt_constants import ble_scan_settings_callback_types |
| 30 | from acts.test_utils.bt.bt_constants import ble_scan_settings_modes |
| 31 | from acts.test_utils.bt.bt_constants import adv_succ |
| 32 | from acts.test_utils.bt.bt_constants import scan_result |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 33 | from acts.test_utils.bt.bt_test_utils import BtTestUtilsError |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 34 | from acts.test_utils.bt.bt_test_utils import generate_ble_advertise_objects |
| 35 | from acts.test_utils.bt.bt_test_utils import generate_ble_scan_objects |
| 36 | from acts.test_utils.bt.bt_test_utils import get_advanced_droid_list |
| 37 | from acts.test_utils.bt.bt_test_utils import reset_bluetooth |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 38 | from acts.test_utils.bt.bt_test_utils import setup_n_advertisements |
| 39 | from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs |
| 40 | from acts.test_utils.bt.bt_test_utils import teardown_n_advertisements |
| 41 | from acts.test_utils.bt.bt_test_utils import scan_and_verify_n_advertisements |
| 42 | |
| 43 | |
| 44 | class ConcurrentBleAdvertisementDiscoveryTest(BluetoothBaseTest): |
| 45 | default_timeout = 10 |
| 46 | max_advertisements = -1 |
| 47 | advertise_callback_list = [] |
| 48 | |
| 49 | def __init__(self, controllers): |
| 50 | BluetoothBaseTest.__init__(self, controllers) |
| 51 | self.droid_list = get_advanced_droid_list(self.android_devices) |
| 52 | self.scn_ad = self.android_devices[0] |
| 53 | self.adv_ad = self.android_devices[1] |
| 54 | self.max_advertisements = self.droid_list[1]['max_advertisements'] |
| 55 | |
| 56 | def setup_test(self): |
| 57 | return reset_bluetooth(self.android_devices) |
| 58 | |
| 59 | def setup_test(self): |
tturney | f02ac39 | 2016-09-21 10:37:35 -0700 | [diff] [blame] | 60 | super(BluetoothBaseTest, self).setup_test() |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 61 | self.log.info("Setting up advertisements") |
| 62 | try: |
| 63 | self.advertise_callback_list = setup_n_advertisements( |
| 64 | self.adv_ad, self.max_advertisements) |
| 65 | except BtTestUtilsError: |
| 66 | return False |
| 67 | return True |
| 68 | |
| 69 | def teardown_test(self): |
tturney | f02ac39 | 2016-09-21 10:37:35 -0700 | [diff] [blame] | 70 | super(BluetoothBaseTest, self).teardown_test() |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 71 | self.log.info("Tearing down advertisements") |
| 72 | teardown_n_advertisements(self.adv_ad, |
| 73 | len(self.advertise_callback_list), |
| 74 | self.advertise_callback_list) |
| 75 | return True |
| 76 | |
| 77 | @BluetoothBaseTest.bt_test_wrap |
tturney | 31ae5b6 | 2017-07-21 15:48:35 -0700 | [diff] [blame^] | 78 | @test_tracker_info(uuid='e02d6ca6-4db3-4a1d-adaf-98db7c7c2c7a') |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 79 | def test_max_advertisements_defaults(self): |
| 80 | """Test scan integrity after BT state is reset |
| 81 | |
| 82 | This test is to verify that LE devices are found |
| 83 | successfully after the Bluetooth stack is |
| 84 | reset. This is repeated multiple times in order |
| 85 | to verify that LE devices are not lost in scanning |
| 86 | when the stack is brought back up. |
| 87 | |
| 88 | Steps: |
| 89 | 1. Pre-Condition: Max advertisements are active |
| 90 | 2. With the DUT android device, scan for all advertisements |
| 91 | and verify that all expected advertisements are found. |
| 92 | 3. Reset Bluetooth on DUT. |
| 93 | 4. Repeat steps 2-3 for defined iterations |
| 94 | |
| 95 | Expected Result: |
| 96 | All expected advertisements should be found on all iterations. |
| 97 | |
| 98 | Returns: |
| 99 | Pass if True |
| 100 | Fail if False |
| 101 | |
| 102 | TAGS: LE, Advertising, Concurrency, Scanning |
| 103 | Priority: 2 |
| 104 | """ |
tturney | 31ae5b6 | 2017-07-21 15:48:35 -0700 | [diff] [blame^] | 105 | filter_list = self.scn_ad.droid.bleGenFilterList() |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 106 | self.scn_ad.droid.bleBuildScanFilter(filter_list) |
| 107 | self.scn_ad.droid.bleSetScanSettingsCallbackType( |
tturney | 31ae5b6 | 2017-07-21 15:48:35 -0700 | [diff] [blame^] | 108 | ble_scan_settings_callback_types['all_matches']) |
| 109 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 110 | 'low_latency']) |
tturney | c8e17bf | 2016-07-12 10:32:42 -0700 | [diff] [blame] | 111 | iterations = 20 |
| 112 | for _ in range(iterations): |
| 113 | self.log.info("Verify all advertisements found") |
| 114 | try: |
| 115 | if not scan_and_verify_n_advertisements( |
| 116 | self.scn_ad, self.max_advertisements): |
| 117 | self.log.error("Failed to find all advertisements") |
| 118 | return False |
| 119 | except BtTestUtilsError: |
| 120 | return False |
| 121 | if not reset_bluetooth([self.scn_ad]): |
| 122 | self.log.error("Failed to reset Bluetooth state") |
| 123 | return False |
| 124 | return True |