1#!/usr/bin/env python3.4 2# 3# Copyright 2018 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of 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, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import time 18import acts.test_utils.bt.BleEnum as bleenum 19import acts.test_utils.bt.bt_power_test_utils as btputils 20import acts.test_utils.power.PowerBTBaseTest as PBtBT 21 22BLE_LOCATION_SCAN_ENABLE = 'settings put secure location_mode 3' 23EXTRA_ADV_TIME = 3 24ADV_TAIL = 5 25 26 27class PowerBLEadvertiseTest(PBtBT.PowerBTBaseTest): 28 def __init__(self, configs): 29 super().__init__(configs) 30 req_params = ['adv_modes', 'adv_power_levels'] 31 self.unpack_userparams(req_params) 32 # Loop all advertise modes and power levels 33 for adv_mode in self.adv_modes: 34 for adv_power_level in self.adv_power_levels: 35 self.generate_test_case(adv_mode, adv_power_level) 36 37 def setup_class(self): 38 39 super().setup_class() 40 self.dut.adb.shell(BLE_LOCATION_SCAN_ENABLE) 41 # Make sure during power measurement, advertisement is always on 42 self.adv_duration = self.mon_info.duration + self.mon_offset + ADV_TAIL + EXTRA_ADV_TIME 43 44 def generate_test_case(self, adv_mode, adv_power_level): 45 def test_case_fn(): 46 47 self.measure_ble_advertise_power(adv_mode, adv_power_level) 48 49 adv_mode_str = bleenum.AdvertiseSettingsAdvertiseMode(adv_mode).name 50 adv_txpl_str = bleenum.AdvertiseSettingsAdvertiseTxPower( 51 adv_power_level).name.strip('ADVERTISE').strip('_') 52 test_case_name = ('test_BLE_{}_{}'.format(adv_mode_str, adv_txpl_str)) 53 setattr(self, test_case_name, test_case_fn) 54 55 def measure_ble_advertise_power(self, adv_mode, adv_power_level): 56 57 btputils.start_apk_ble_adv(self.dut, adv_mode, adv_power_level, 58 self.adv_duration) 59 time.sleep(EXTRA_ADV_TIME) 60 self.measure_power_and_validate() 61