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