tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 1 | #/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright (C) 2016 The Android Open Source Project |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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. |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 16 | """ |
| 17 | This test script exercises different opportunistic scan scenarios. |
| 18 | It is expected that the second AndroidDevice is able to advertise. |
| 19 | |
| 20 | This test script was designed with this setup in mind: |
| 21 | Shield box one: Android Device, Android Device |
| 22 | """ |
| 23 | |
| 24 | from queue import Empty |
| 25 | |
Hansong Zhang | af1d789 | 2018-05-21 15:48:01 -0700 | [diff] [blame] | 26 | from acts import utils |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 27 | from acts.test_decorators import test_tracker_info |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 28 | from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 29 | from acts.test_utils.bt.bt_constants import ble_scan_settings_modes |
| 30 | from acts.test_utils.bt.bt_constants import ble_scan_settings_modes |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 31 | from acts.test_utils.bt.bt_test_utils import batch_scan_result |
| 32 | from acts.test_utils.bt.bt_test_utils import cleanup_scanners_and_advertisers |
| 33 | from acts.test_utils.bt.bt_test_utils import generate_ble_advertise_objects |
| 34 | from acts.test_utils.bt.bt_test_utils import generate_ble_scan_objects |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 35 | from acts.test_utils.bt.bt_test_utils import reset_bluetooth |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 36 | from acts.test_utils.bt.bt_constants import scan_result |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | class BleOpportunisticScanTest(BluetoothBaseTest): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 40 | default_timeout = 10 |
Jakub Pawłowski | ba99e8c | 2018-05-04 17:19:22 +0200 | [diff] [blame^] | 41 | max_scan_instances = 27 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 42 | report_delay = 2000 |
| 43 | scan_callbacks = [] |
| 44 | adv_callbacks = [] |
| 45 | active_scan_callback_list = [] |
| 46 | active_adv_callback_list = [] |
| 47 | |
| 48 | def __init__(self, controllers): |
| 49 | BluetoothBaseTest.__init__(self, controllers) |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 50 | self.scn_ad = self.android_devices[0] |
| 51 | self.adv_ad = self.android_devices[1] |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 52 | |
Hansong Zhang | af1d789 | 2018-05-21 15:48:01 -0700 | [diff] [blame] | 53 | def setup_class(self): |
| 54 | super(BluetoothBaseTest, self).setup_class() |
| 55 | utils.set_location_service(self.scn_ad, True) |
| 56 | utils.set_location_service(self.adv_ad, True) |
| 57 | return True |
| 58 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 59 | def teardown_test(self): |
| 60 | cleanup_scanners_and_advertisers( |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 61 | self.scn_ad, self.active_scan_callback_list, self.adv_ad, |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 62 | self.active_adv_callback_list) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 63 | self.active_adv_callback_list = [] |
| 64 | self.active_scan_callback_list = [] |
| 65 | |
| 66 | def on_exception(self, test_name, begin_time): |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 67 | reset_bluetooth(self.android_devices) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 68 | |
| 69 | def _setup_generic_advertisement(self): |
| 70 | adv_callback, adv_data, adv_settings = generate_ble_advertise_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 71 | self.adv_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 72 | self.adv_ad.droid.bleStartBleAdvertising(adv_callback, adv_data, |
| 73 | adv_settings) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 74 | self.active_adv_callback_list.append(adv_callback) |
| 75 | |
| 76 | def _verify_no_events_found(self, event_name): |
| 77 | try: |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 78 | event = self.scn_ad.ed.pop_event(event_name, self.default_timeout) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 79 | self.log.error("Found an event when none was expected: {}".format( |
| 80 | event)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 81 | return False |
| 82 | except Empty: |
| 83 | self.log.info("No scan result found as expected.") |
| 84 | return True |
| 85 | |
| 86 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 87 | @test_tracker_info(uuid='6bccfbea-3734-4504-8ea9-3511ad17a3e0') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 88 | def test_scan_result_no_advertisement(self): |
| 89 | """Test opportunistic scan with no advertisement. |
| 90 | |
| 91 | Tests opportunistic scan where there are no advertisements. This should |
| 92 | not find any onScanResults. |
| 93 | |
| 94 | Steps: |
| 95 | 1. Initialize scanner with scan mode set to opportunistic mode. |
| 96 | 2. Start scanning on dut 0 |
| 97 | 3. Pop onScanResults event on the scanner |
| 98 | |
| 99 | Expected Result: |
| 100 | Find no advertisements with the opportunistic scan instance. |
| 101 | |
| 102 | Returns: |
| 103 | Pass if True |
| 104 | Fail if False |
| 105 | |
| 106 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 107 | Priority: 1 |
| 108 | """ |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 109 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 110 | 'opportunistic']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 111 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 112 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 113 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 114 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 115 | self.active_scan_callback_list.append(scan_callback) |
| 116 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 117 | return False |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 118 | self.scn_ad.droid.bleStopBleScan(scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 119 | return True |
| 120 | |
| 121 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 122 | @test_tracker_info(uuid='8430bc57-925c-4b70-a62e-cd34df264ca1') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 123 | def test_batch_scan_result_no_advertisement(self): |
| 124 | """Test batch opportunistic scan without an advertisement. |
| 125 | |
| 126 | Tests opportunistic scan where there are no advertisements. This should |
| 127 | not find any onBatchScanResult. |
| 128 | |
| 129 | Steps: |
| 130 | 1. Initialize scanner with scan mode set to opportunistic mode. |
| 131 | 2. Set report delay seconds such that onBatchScanResult events are |
| 132 | expected |
| 133 | 2. Start scanning on dut 0 |
| 134 | 3. Pop onBatchScanResult event on the scanner |
| 135 | |
| 136 | Expected Result: |
| 137 | Find no advertisements with the opportunistic scan instance. |
| 138 | |
| 139 | Returns: |
| 140 | Pass if True |
| 141 | Fail if False |
| 142 | |
| 143 | TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning |
| 144 | Priority: 1 |
| 145 | """ |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 146 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 147 | 'opportunistic']) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 148 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 149 | self.report_delay) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 150 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 151 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 152 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 153 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 154 | self.active_scan_callback_list.append(scan_callback) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 155 | if not self._verify_no_events_found( |
| 156 | batch_scan_result.format(scan_callback)): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 157 | return False |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 158 | self.scn_ad.droid.bleStopBleScan(scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 159 | return True |
| 160 | |
| 161 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 162 | @test_tracker_info(uuid='4613cb67-0f54-494e-8a56-2e8ce56fad41') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 163 | def test_scan_result(self): |
| 164 | """Test opportunistic scan with an advertisement. |
| 165 | |
| 166 | Tests opportunistic scan where it will only report scan results when |
| 167 | other registered scanners find results. |
| 168 | |
| 169 | Steps: |
| 170 | 1. Initialize advertiser and start advertisement on dut1 |
| 171 | 2. Initialize scanner with scan mode set to opportunistic mode on dut0 |
| 172 | and start scanning |
| 173 | 3. Try to find an event, expect none. |
| 174 | 4. Start a second scanner on dut0, with any other mode set |
| 175 | 5. Pop onScanResults event on the second scanner |
| 176 | 6. Pop onScanResults event on the first scanner |
| 177 | |
| 178 | Expected Result: |
| 179 | Scan result is found on the opportunistic scan instance. |
| 180 | |
| 181 | Returns: |
| 182 | Pass if True |
| 183 | Fail if False |
| 184 | |
| 185 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 186 | Priority: 1 |
| 187 | """ |
| 188 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 189 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 190 | 'opportunistic']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 191 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 192 | self.scn_ad.droid) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 193 | |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 194 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 195 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 196 | self.active_scan_callback_list.append(scan_callback) |
| 197 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 198 | return False |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 199 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 200 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 201 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 202 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 203 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 204 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 205 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 206 | try: |
| 207 | self.scn_ad.ed.pop_event( |
| 208 | scan_result.format(scan_callback2), self.default_timeout) |
| 209 | except Empty: |
| 210 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 211 | return False |
| 212 | try: |
| 213 | self.scn_ad.ed.pop_event( |
| 214 | scan_result.format(scan_callback), self.default_timeout) |
| 215 | except Empty: |
| 216 | self.log.error("Opportunistic scan found no scan results.") |
| 217 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 218 | return True |
| 219 | |
| 220 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 221 | @test_tracker_info(uuid='5b46fefc-70ef-48a0-acf4-35077cd72202') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 222 | def test_batch_scan_result(self): |
| 223 | """Test batch opportunistic scan with advertisement. |
| 224 | |
| 225 | Tests opportunistic scan where it will only report scan results when |
| 226 | other registered scanners find results. Set the report delay millis such |
| 227 | that an onBatchScanResult is expected. |
| 228 | |
| 229 | Steps: |
| 230 | 1. Initialize advertiser and start advertisement on dut1 |
| 231 | 2. Initialize scanner with scan mode set to opportunistic mode and |
| 232 | set scan settings report delay seconds such that a batch scan is |
| 233 | expected |
| 234 | 3. Start scanning on dut 0 |
| 235 | 4. Try to find an event, expect none. |
| 236 | 5. Start a second scanner on dut0, with any other mode set and set scan |
| 237 | settings report delay millis such that an onBatchScanResult is expected |
| 238 | 6. Pop onBatchScanResult event on the second scanner |
| 239 | 7. Pop onBatchScanResult event on the first scanner |
| 240 | |
| 241 | Expected Result: |
| 242 | Find a batch scan result on both opportunistic scan instances. |
| 243 | |
| 244 | Returns: |
| 245 | Pass if True |
| 246 | Fail if False |
| 247 | |
| 248 | TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning |
| 249 | Priority: 1 |
| 250 | """ |
| 251 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 252 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 253 | 'opportunistic']) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 254 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 255 | self.report_delay) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 256 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 257 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 258 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 259 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 260 | self.active_scan_callback_list.append(scan_callback) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 261 | if not self._verify_no_events_found( |
| 262 | batch_scan_result.format(scan_callback)): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 263 | return False |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 264 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 265 | self.report_delay) |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 266 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 267 | 'low_latency']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 268 | filter_list2, scan_settings2, scan_callback2 = generate_ble_scan_objects( |
| 269 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 270 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 271 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 272 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 273 | try: |
| 274 | self.scn_ad.ed.pop_event( |
| 275 | batch_scan_result.format(scan_callback2), self.default_timeout) |
| 276 | except Empty: |
| 277 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 278 | return False |
| 279 | try: |
| 280 | self.scn_ad.ed.pop_event( |
| 281 | batch_scan_result.format(scan_callback), self.default_timeout) |
| 282 | except Empty: |
| 283 | self.log.error("Opportunistic scan found no scan results.") |
| 284 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 285 | return True |
| 286 | |
| 287 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 288 | @test_tracker_info(uuid='fd85d95e-dc8c-48c1-8d8a-83c3475755ff') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 289 | def test_batch_scan_result_not_expected(self): |
| 290 | """Test opportunistic batch scan without expecting an event. |
| 291 | |
| 292 | Tests opportunistic scan where it will only report scan results when |
| 293 | other registered scanners find results. Set the report delay millis such |
| 294 | that a batch scan is not expected. |
| 295 | |
| 296 | Steps: |
| 297 | 1. Initialize advertiser and start advertisement on dut1 |
| 298 | 2. Initialize scanner with scan mode set to opportunistic mode and |
| 299 | set scan settings report delay seconds such that a batch scan is |
| 300 | expected. |
| 301 | 3. Start scanning on dut 0 |
| 302 | 4. Try to find an event, expect none. |
| 303 | 5. Start a second scanner on dut0, with any other mode set and set scan |
| 304 | settings report delay millis to 0 such that an onBatchScanResult is not |
| 305 | expected. |
| 306 | 6. Pop onScanResults event on the second scanner |
| 307 | 7. Pop onBatchScanResult event on the first scanner |
| 308 | |
| 309 | Expected Result: |
| 310 | Batch scan result is not expected on opportunistic scan instance. |
| 311 | |
| 312 | Returns: |
| 313 | Pass if True |
| 314 | Fail if False |
| 315 | |
| 316 | TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning |
| 317 | Priority: 1 |
| 318 | """ |
| 319 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 320 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 321 | 'opportunistic']) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 322 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 323 | self.report_delay) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 324 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 325 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 326 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 327 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 328 | self.active_scan_callback_list.append(scan_callback) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 329 | if not self._verify_no_events_found( |
| 330 | batch_scan_result.format(scan_callback)): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 331 | |
| 332 | return False |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 333 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 334 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 335 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 336 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 337 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 338 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 339 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 340 | try: |
| 341 | self.scn_ad.ed.pop_event( |
| 342 | scan_result.format(scan_callback2), self.default_timeout) |
| 343 | except Empty: |
| 344 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 345 | return False |
| 346 | return self._verify_no_events_found( |
| 347 | batch_scan_result.format(scan_callback)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 348 | |
| 349 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 350 | @test_tracker_info(uuid='6138592e-8fd5-444f-9a7c-25cd9695644a') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 351 | def test_scan_result_not_expected(self): |
| 352 | """Test opportunistic scan without expecting an event. |
| 353 | |
| 354 | Tests opportunistic scan where it will only report batch scan results |
| 355 | when other registered scanners find results. |
| 356 | |
| 357 | Steps: |
| 358 | 1. Initialize advertiser and start advertisement on dut1 |
| 359 | 2. Initialize scanner with scan mode set to opportunistic mode. |
| 360 | 3. Start scanning on dut 0 |
| 361 | 4. Try to find an event, expect none. |
| 362 | 5. Start a second scanner on dut0, with any other mode set and set scan |
| 363 | settings |
| 364 | report delay millis such that an onBatchScanResult is expected |
| 365 | 6. Pop onBatchScanResult event on the second scanner |
| 366 | 7. Pop onScanResults event on the first scanner |
| 367 | |
| 368 | Expected Result: |
| 369 | Scan result is not expected on opportunistic scan instance. |
| 370 | |
| 371 | Returns: |
| 372 | Pass if True |
| 373 | Fail if False |
| 374 | |
| 375 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 376 | Priority: 1 |
| 377 | """ |
| 378 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 379 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 380 | 'opportunistic']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 381 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
| 382 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 383 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 384 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 385 | self.active_scan_callback_list.append(scan_callback) |
| 386 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 387 | return False |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 388 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 389 | self.report_delay) |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 390 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 391 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 392 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 393 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 394 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 395 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 396 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 397 | try: |
| 398 | self.scn_ad.ed.pop_event( |
| 399 | batch_scan_result.format(scan_callback2), self.default_timeout) |
| 400 | except Empty: |
| 401 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 402 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 403 | return self._verify_no_events_found(scan_result.format(scan_callback)) |
| 404 | |
| 405 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 406 | @test_tracker_info(uuid='f7aba3d9-d3f7-4b2f-976e-441772705613') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 407 | def test_max_opportunistic_scan_instances(self): |
| 408 | """Test max number of opportunistic scan instances. |
| 409 | |
| 410 | Tests max instances of opportunistic scans. Each instances should |
| 411 | find an onScanResults event. |
| 412 | |
| 413 | Steps: |
| 414 | 1. Initialize advertiser and start advertisement on dut1 |
| 415 | 2. Set scan settings to opportunistic scan on dut0 scan instance |
| 416 | 3. Start scan scan from step 2 |
| 417 | 4. Repeat step two and three until there are max_scan_instances-1 scan |
| 418 | instances |
| 419 | 5. Start a regular ble scan on dut0 with the last available scan |
| 420 | instance |
| 421 | 6. Pop onScanResults event on all scan instances |
| 422 | |
| 423 | Expected Result: |
| 424 | Each opportunistic scan instance finds a advertisement. |
| 425 | |
| 426 | Returns: |
| 427 | Pass if True |
| 428 | Fail if False |
| 429 | |
| 430 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 431 | Priority: 1 |
| 432 | """ |
| 433 | self._setup_generic_advertisement() |
| 434 | for _ in range(self.max_scan_instances - 1): |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 435 | self.scn_ad.droid.bleSetScanSettingsScanMode( |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 436 | ble_scan_settings_modes['opportunistic']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 437 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
| 438 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 439 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 440 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 441 | self.active_scan_callback_list.append(scan_callback) |
| 442 | |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 443 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 444 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 445 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 446 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 447 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 448 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 449 | self.active_scan_callback_list.append(scan_callback2) |
| 450 | |
| 451 | for callback in self.active_scan_callback_list: |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 452 | try: |
| 453 | self.scn_ad.ed.pop_event( |
| 454 | scan_result.format(callback), self.default_timeout) |
| 455 | except Empty: |
| 456 | self.log.error("No scan results found for callback {}".format( |
| 457 | callback)) |
| 458 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 459 | return True |
| 460 | |
| 461 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 462 | @test_tracker_info(uuid='cf971f08-4d92-4046-bba6-b86a75aa773c') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 463 | def test_max_opportunistic_batch_scan_instances(self): |
| 464 | """Test max opportunistic batch scan instances. |
| 465 | |
| 466 | Tests max instances of opportunistic batch scans. Each instances should |
| 467 | find an onBatchScanResult event. |
| 468 | |
| 469 | Steps: |
| 470 | 1. Initialize advertiser and start advertisement on dut1 |
| 471 | 2. Set scan settings to opportunistic scan on dut0 scan instance and |
| 472 | set report delay seconds such that an onBatchScanResult is expected |
| 473 | 3. Start scan scan from step 2 |
| 474 | 4. Repeat step two and three until there are max_scan_instances-1 scan |
| 475 | instances |
| 476 | 5. Start a regular ble scan on dut0 with the last available scan |
| 477 | instance |
| 478 | 6. Pop onBatchScanResult event on all scan instances |
| 479 | |
| 480 | Expected Result: |
| 481 | Each opportunistic scan instance finds an advertisement. |
| 482 | |
| 483 | Returns: |
| 484 | Pass if True |
| 485 | Fail if False |
| 486 | |
| 487 | TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning |
| 488 | Priority: 1 |
| 489 | """ |
| 490 | self._setup_generic_advertisement() |
| 491 | for _ in range(self.max_scan_instances - 1): |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 492 | self.scn_ad.droid.bleSetScanSettingsScanMode( |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 493 | ble_scan_settings_modes['opportunistic']) |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 494 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 495 | self.report_delay) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 496 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
| 497 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 498 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 499 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 500 | self.active_scan_callback_list.append(scan_callback) |
| 501 | |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 502 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 503 | 'low_latency']) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 504 | self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( |
| 505 | self.report_delay) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 506 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 507 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 508 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 509 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 510 | self.active_scan_callback_list.append(scan_callback2) |
| 511 | |
| 512 | for callback in self.active_scan_callback_list: |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 513 | try: |
| 514 | self.scn_ad.ed.pop_event( |
| 515 | batch_scan_result.format(callback), self.default_timeout) |
| 516 | except Empty: |
| 517 | self.log.error("No scan results found for callback {}".format( |
| 518 | callback)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 519 | return True |
| 520 | |
| 521 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 522 | @test_tracker_info(uuid='965d84ef-11a7-418a-97e9-2a441c6de776') |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 523 | def test_discover_opportunistic_scan_result_off_secondary_scan_filter( |
| 524 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 525 | """Test opportunistic scan result from secondary scan filter. |
| 526 | |
| 527 | Tests opportunistic scan where the secondary scan instance does not find |
| 528 | an advertisement but the scan instance with scan mode set to |
| 529 | opportunistic scan will find an advertisement. |
| 530 | |
| 531 | Steps: |
| 532 | 1. Initialize advertiser and start advertisement on dut1 (make sure the |
| 533 | advertisement is not advertising the device name) |
| 534 | 2. Set scan settings to opportunistic scan on dut0 scan instance |
| 535 | 3. Start scan scan from step 2 |
| 536 | 4. Try to find an event, expect none |
| 537 | 5. Start a second scanner on dut0, with any other mode set and set the |
| 538 | scan filter device name to "opp_test" |
| 539 | 6. Pop onScanResults from the second scanner |
| 540 | 7. Expect no events |
| 541 | 8. Pop onScanResults from the first scanner |
| 542 | |
| 543 | Expected Result: |
| 544 | Opportunistic scan instance finds an advertisement. |
| 545 | |
| 546 | Returns: |
| 547 | Pass if True |
| 548 | Fail if False |
| 549 | |
| 550 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 551 | Priority: 1 |
| 552 | """ |
| 553 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 554 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 555 | 'opportunistic']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 556 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 557 | self.scn_ad.droid) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 558 | |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 559 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 560 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 561 | self.active_scan_callback_list.append(scan_callback) |
| 562 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 563 | return False |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 564 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 565 | 'low_latency']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 566 | self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 567 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 568 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 49a23d7 | 2016-09-30 15:50:49 -0700 | [diff] [blame] | 569 | self.scn_ad.droid.bleBuildScanFilter(filter_list2) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 570 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 571 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 572 | self.active_scan_callback_list.append(scan_callback2) |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 573 | if not self._verify_no_events_found( |
| 574 | scan_result.format(scan_callback2)): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 575 | return False |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 576 | try: |
| 577 | self.scn_ad.ed.pop_event( |
| 578 | scan_result.format(scan_callback), self.default_timeout) |
| 579 | except Empty: |
| 580 | self.log.error("Opportunistic scan found no scan results.") |
| 581 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 582 | return True |
| 583 | |
| 584 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 585 | @test_tracker_info(uuid='13b0a83f-e96e-4d64-84ef-66351ec5054c') |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 586 | def test_negative_opportunistic_scan_filter_result_off_secondary_scan_result( |
| 587 | self): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 588 | """Test opportunistic scan not found scenario. |
| 589 | |
| 590 | Tests opportunistic scan where the secondary scan instance does find an |
| 591 | advertisement but the scan instance with scan mode set to opportunistic |
| 592 | scan does not find an advertisement due to mismatched scan filters. |
| 593 | |
| 594 | Steps: |
| 595 | 1. Initialize advertiser and start advertisement on dut1 (make sure the |
| 596 | advertisement is not advertising the device name) |
| 597 | 2. Set scan settings to opportunistic scan on dut0 scan instance and set |
| 598 | the scan filter device name to "opp_test" |
| 599 | 3. Start scan scan from step 2 |
| 600 | 4. Try to find an event, expect none |
| 601 | 5. Start a second scanner on dut0, with any other mode set |
| 602 | 6. Pop onScanResults from the second scanner |
| 603 | 7. Pop onScanResults from the first scanner |
| 604 | 8. Expect no events |
| 605 | |
| 606 | Expected Result: |
| 607 | Opportunistic scan instance doesn't find any advertisements. |
| 608 | |
| 609 | Returns: |
| 610 | Pass if True |
| 611 | Fail if False |
| 612 | |
| 613 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 614 | Priority: 1 |
| 615 | """ |
| 616 | self._setup_generic_advertisement() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 617 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 618 | 'opportunistic']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 619 | self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 620 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 621 | self.scn_ad.droid) |
tturney | 49a23d7 | 2016-09-30 15:50:49 -0700 | [diff] [blame] | 622 | self.scn_ad.droid.bleBuildScanFilter(filter_list) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 623 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 624 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 625 | self.active_scan_callback_list.append(scan_callback) |
| 626 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 627 | return False |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 628 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 629 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 630 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 631 | generate_ble_scan_objects(self.scn_ad.droid)) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 632 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 633 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 634 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 635 | try: |
| 636 | self.scn_ad.ed.pop_event( |
| 637 | scan_result.format(scan_callback2), self.default_timeout) |
| 638 | except Empty: |
| 639 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 640 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 641 | return self._verify_no_events_found(scan_result.format(scan_callback)) |
| 642 | |
| 643 | @BluetoothBaseTest.bt_test_wrap |
tturney | cd48631 | 2017-01-11 14:04:55 -0800 | [diff] [blame] | 644 | @test_tracker_info(uuid='087f60b2-f6a1-4919-b4c5-cdf3debcfeff') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 645 | def test_opportunistic_scan_filter_result_off_secondary_scan_result(self): |
| 646 | """Test opportunistic scan from a secondary scan result. |
| 647 | |
| 648 | Tests opportunistic scan where the scan filters are the same between the |
| 649 | first scan instance with opportunistic scan set and the second instance |
| 650 | with any other mode set. |
| 651 | |
| 652 | Steps: |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 653 | 1. Initialize advertiser and start advertisement on dut1 |
| 654 | 2. On dut0, set the scan settings mode to opportunistic scan and set |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 655 | the scan filter device name to the advertiser's device name |
| 656 | 3. Start scan scan from step 2 |
| 657 | 4. Try to find an event, expect none |
| 658 | 5. Start a second scanner on dut0, with any other mode set and set the |
| 659 | scan filter device name to the advertiser's device name |
| 660 | 6. Pop onScanResults from the second scanner |
| 661 | 7. Pop onScanResults from the first scanner |
| 662 | |
| 663 | Expected Result: |
| 664 | Opportunistic scan instance finds a advertisement. |
| 665 | |
| 666 | Returns: |
| 667 | Pass if True |
| 668 | Fail if False |
| 669 | |
| 670 | TAGS: LE, Advertising, Scanning, Opportunistic Scan |
| 671 | Priority: 1 |
| 672 | """ |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 673 | self.adv_ad.droid.bleSetAdvertiseDataIncludeDeviceName(True) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 674 | self._setup_generic_advertisement() |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 675 | adv_device_name = self.adv_ad.droid.bluetoothGetLocalName() |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 676 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 677 | 'opportunistic']) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 678 | self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 679 | filter_list, scan_settings, scan_callback = generate_ble_scan_objects( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 680 | self.scn_ad.droid) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 681 | self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, |
| 682 | scan_callback) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 683 | self.active_scan_callback_list.append(scan_callback) |
| 684 | if not self._verify_no_events_found(scan_result.format(scan_callback)): |
| 685 | return False |
tturney | 2378ac1 | 2017-07-24 12:42:39 -0700 | [diff] [blame] | 686 | self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[ |
| 687 | 'low_latency']) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 688 | filter_list2, scan_settings2, scan_callback2 = ( |
tturney | 1ce8dc6 | 2016-02-18 09:55:53 -0800 | [diff] [blame] | 689 | generate_ble_scan_objects(self.scn_ad.droid)) |
| 690 | self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name) |
| 691 | self.scn_ad.droid.bleBuildScanFilter(filter_list2) |
tturney | 6d448de | 2016-06-24 08:46:18 -0700 | [diff] [blame] | 692 | self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, |
| 693 | scan_callback2) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 694 | self.active_scan_callback_list.append(scan_callback2) |
tturney | fc22e30 | 2016-09-08 17:20:36 -0700 | [diff] [blame] | 695 | try: |
| 696 | self.scn_ad.ed.pop_event( |
| 697 | scan_result.format(scan_callback2), self.default_timeout) |
| 698 | except Empty: |
| 699 | self.log.error("Opportunistic scan found no scan results.") |
| 700 | return False |
| 701 | try: |
| 702 | self.scn_ad.ed.pop_event( |
| 703 | scan_result.format(scan_callback), self.default_timeout) |
| 704 | except Empty: |
| 705 | self.log.error("Non-Opportunistic scan found no scan results.") |
| 706 | return False |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 707 | return True |