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_contrib.test_utils.bt.BleEnum as bleenum 19import acts_contrib.test_utils.bt.bt_power_test_utils as btputils 20import acts_contrib.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 29 def __init__(self, configs): 30 super().__init__(configs) 31 req_params = ['adv_modes', 'adv_power_levels'] 32 self.unpack_userparams(req_params) 33 # Loop all advertise modes and power levels 34 for adv_mode in self.adv_modes: 35 for adv_power_level in self.adv_power_levels: 36 # As a temporary fix, set high power tests directly 37 if adv_power_level != 3: 38 self.generate_test_case(adv_mode, adv_power_level) 39 40 def setup_class(self): 41 42 super().setup_class() 43 self.dut.adb.shell(BLE_LOCATION_SCAN_ENABLE) 44 # Make sure during power measurement, advertisement is always on 45 self.adv_duration = self.mon_info.duration + self.mon_offset + ADV_TAIL + EXTRA_ADV_TIME 46 47 def generate_test_case(self, adv_mode, adv_power_level): 48 def test_case_fn(): 49 50 self.measure_ble_advertise_power(adv_mode, adv_power_level) 51 52 adv_mode_str = bleenum.AdvertiseSettingsAdvertiseMode(adv_mode).name 53 adv_txpl_str = bleenum.AdvertiseSettingsAdvertiseTxPower( 54 adv_power_level).name.strip('ADVERTISE').strip('_') 55 test_case_name = ('test_BLE_{}_{}'.format(adv_mode_str, adv_txpl_str)) 56 setattr(self, test_case_name, test_case_fn) 57 58 def measure_ble_advertise_power(self, adv_mode, adv_power_level): 59 60 btputils.start_apk_ble_adv(self.dut, adv_mode, adv_power_level, 61 self.adv_duration) 62 time.sleep(EXTRA_ADV_TIME) 63 self.measure_power_and_validate() 64 65 def test_BLE_ADVERTISE_MODE_LOW_POWER_TX_POWER_HIGH(self): 66 self.measure_ble_advertise_power(0, 3) 67 68 def test_BLE_ADVERTISE_MODE_BALANCED_TX_POWER_HIGH(self): 69 self.measure_ble_advertise_power(1, 3) 70 71 def test_BLE_ADVERTISE_MODE_LOW_LATENCY_TX_POWER_HIGH(self): 72 self.measure_ble_advertise_power(2, 3) 73