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