blob: afdef11e1f15d0ceb4b3e4a3ad026276a6a9292c [file] [log] [blame]
Mark De Ruyterd9c540a2018-05-04 11:21:55 -07001#!/usr/bin/env python3
tturneyc8e17bf2016-07-12 10:32:42 -07002#
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"""
17Test script to test the integrity of LE scan results upon resetting the
18Bluetooth stack.
19"""
20
21import concurrent
22import os
23import time
24
25from queue import Empty
tturney31ae5b62017-07-21 15:48:35 -070026from acts.test_decorators import test_tracker_info
tturneyc8e17bf2016-07-12 10:32:42 -070027from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
tturney31ae5b62017-07-21 15:48:35 -070028from acts.test_utils.bt.bt_constants import ble_advertise_settings_modes
29from acts.test_utils.bt.bt_constants import ble_scan_settings_callback_types
30from acts.test_utils.bt.bt_constants import ble_scan_settings_modes
31from acts.test_utils.bt.bt_constants import adv_succ
32from acts.test_utils.bt.bt_constants import scan_result
tturneyc8e17bf2016-07-12 10:32:42 -070033from acts.test_utils.bt.bt_test_utils import BtTestUtilsError
tturneyc8e17bf2016-07-12 10:32:42 -070034from acts.test_utils.bt.bt_test_utils import generate_ble_advertise_objects
35from acts.test_utils.bt.bt_test_utils import generate_ble_scan_objects
36from acts.test_utils.bt.bt_test_utils import get_advanced_droid_list
37from acts.test_utils.bt.bt_test_utils import reset_bluetooth
tturneyc8e17bf2016-07-12 10:32:42 -070038from acts.test_utils.bt.bt_test_utils import setup_n_advertisements
39from acts.test_utils.bt.bt_test_utils import take_btsnoop_logs
40from acts.test_utils.bt.bt_test_utils import teardown_n_advertisements
41from acts.test_utils.bt.bt_test_utils import scan_and_verify_n_advertisements
42
43
44class ConcurrentBleAdvertisementDiscoveryTest(BluetoothBaseTest):
45 default_timeout = 10
Aidan Holloway-bidwell35220552019-07-09 18:20:16 -070046 droid_list = []
tturneyc8e17bf2016-07-12 10:32:42 -070047 max_advertisements = -1
48 advertise_callback_list = []
49
50 def __init__(self, controllers):
51 BluetoothBaseTest.__init__(self, controllers)
tturneyc8e17bf2016-07-12 10:32:42 -070052 self.scn_ad = self.android_devices[0]
53 self.adv_ad = self.android_devices[1]
Aidan Holloway-bidwell35220552019-07-09 18:20:16 -070054
55 def setup_class(self):
56 super().setup_class()
57 self.droid_list = get_advanced_droid_list(self.android_devices)
tturneyc8e17bf2016-07-12 10:32:42 -070058 self.max_advertisements = self.droid_list[1]['max_advertisements']
59
60 def setup_test(self):
Aidan Holloway-bidwell35220552019-07-09 18:20:16 -070061 super().setup_test()
tturneyc8e17bf2016-07-12 10:32:42 -070062 self.log.info("Setting up advertisements")
Aidan Holloway-bidwell35220552019-07-09 18:20:16 -070063 reset_bluetooth(self.android_devices)
tturneyc8e17bf2016-07-12 10:32:42 -070064 try:
65 self.advertise_callback_list = setup_n_advertisements(
66 self.adv_ad, self.max_advertisements)
67 except BtTestUtilsError:
68 return False
69 return True
70
71 def teardown_test(self):
tturneyf02ac392016-09-21 10:37:35 -070072 super(BluetoothBaseTest, self).teardown_test()
tturneyc8e17bf2016-07-12 10:32:42 -070073 self.log.info("Tearing down advertisements")
74 teardown_n_advertisements(self.adv_ad,
75 len(self.advertise_callback_list),
76 self.advertise_callback_list)
77 return True
78
79 @BluetoothBaseTest.bt_test_wrap
tturney31ae5b62017-07-21 15:48:35 -070080 @test_tracker_info(uuid='e02d6ca6-4db3-4a1d-adaf-98db7c7c2c7a')
tturneyc8e17bf2016-07-12 10:32:42 -070081 def test_max_advertisements_defaults(self):
82 """Test scan integrity after BT state is reset
83
84 This test is to verify that LE devices are found
85 successfully after the Bluetooth stack is
86 reset. This is repeated multiple times in order
87 to verify that LE devices are not lost in scanning
88 when the stack is brought back up.
89
90 Steps:
91 1. Pre-Condition: Max advertisements are active
92 2. With the DUT android device, scan for all advertisements
93 and verify that all expected advertisements are found.
94 3. Reset Bluetooth on DUT.
95 4. Repeat steps 2-3 for defined iterations
96
97 Expected Result:
98 All expected advertisements should be found on all iterations.
99
100 Returns:
101 Pass if True
102 Fail if False
103
104 TAGS: LE, Advertising, Concurrency, Scanning
105 Priority: 2
106 """
tturney31ae5b62017-07-21 15:48:35 -0700107 filter_list = self.scn_ad.droid.bleGenFilterList()
tturneyc8e17bf2016-07-12 10:32:42 -0700108 self.scn_ad.droid.bleBuildScanFilter(filter_list)
109 self.scn_ad.droid.bleSetScanSettingsCallbackType(
tturney31ae5b62017-07-21 15:48:35 -0700110 ble_scan_settings_callback_types['all_matches'])
111 self.scn_ad.droid.bleSetScanSettingsScanMode(ble_scan_settings_modes[
112 'low_latency'])
tturneyc8e17bf2016-07-12 10:32:42 -0700113 iterations = 20
114 for _ in range(iterations):
115 self.log.info("Verify all advertisements found")
116 try:
117 if not scan_and_verify_n_advertisements(
118 self.scn_ad, self.max_advertisements):
119 self.log.error("Failed to find all advertisements")
120 return False
121 except BtTestUtilsError:
122 return False
123 if not reset_bluetooth([self.scn_ad]):
124 self.log.error("Failed to reset Bluetooth state")
125 return False
126 return True