Home | History | Annotate | Download | only in scan
      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 """
     18 
     19 from queue import Empty
     20 
     21 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
     22 from acts.test_utils.bt.BleEnum import *
     23 from acts.test_utils.bt.bt_test_utils import *
     24 
     25 
     26 class DeathToBluetoothTest(BluetoothBaseTest):
     27     tests = None
     28     default_timeout = 10
     29     max_scan_instances = 28
     30     report_delay = 2000
     31     scan_callbacks = []
     32     adv_callbacks = []
     33     active_scan_callback_list = []
     34     active_adv_callback_list = []
     35 
     36     def __init__(self, controllers):
     37         BluetoothBaseTest.__init__(self, controllers)
     38         self.scn_ad = self.android_devices[0]
     39         self.tests = ("test_death", )
     40 
     41     def teardown_test(self):
     42         self.active_adv_callback_list = []
     43         self.active_scan_callback_list = []
     44 
     45     def on_exception(self, test_name, begin_time):
     46         reset_bluetooth(self.android_devices)
     47 
     48     def on_fail(self, test_name, begin_time):
     49         reset_bluetooth(self.android_devices)
     50 
     51     def _setup_generic_advertisement(self):
     52         adv_callback, adv_data, adv_settings = generate_ble_advertise_objects(
     53             self.adv_droid)
     54         self.adv_droid.bleStartBleAdvertising(adv_callback, adv_data,
     55                                               adv_settings)
     56         self.active_adv_callback_list.append(adv_callback)
     57 
     58     def _verify_no_events_found(self, event_name):
     59         try:
     60             self.scn_ad.ed.pop_event(event_name, self.default_timeout)
     61             self.log.error("Found an event when none was expected.")
     62             return False
     63         except Empty:
     64             self.log.info("No scan result found as expected.")
     65             return True
     66 
     67     @BluetoothBaseTest.bt_test_wrap
     68     def test_death(self):
     69         """
     70         Tests ...
     71         Steps
     72         1: ...
     73         :return: boolean
     74         """
     75         filter_list = self.scn_ad.droid.bleGenFilterList()
     76         self.scn_ad.droid.bleSetScanSettingsScanMode(
     77             ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value)
     78         self.scn_ad.droid.bleSetScanSettingsCallbackType(6)
     79         # self.scn_ad.droid.bleSetScanSettingsMatchMode(2) #sticky
     80         self.scn_ad.droid.bleSetScanSettingsMatchMode(1)  # aggresive
     81         self.scn_ad.droid.bleSetScanSettingsNumOfMatches(1)
     82         scan_settings = self.scn_ad.droid.bleBuildScanSetting()
     83         scan_callback = self.scn_ad.droid.bleGenScanCallback()
     84         self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
     85                                           scan_callback)
     86         for _ in range(10000):
     87             self.scn_ad.ed.pop_event(scan_result.format(scan_callback))
     88         return True
     89