1#!/usr/bin/env python3 2# 3# Copyright 2019 - 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 os 18import time 19import acts_contrib.test_utils.bt.bt_test_utils as bt_utils 20from acts_contrib.test_utils.bt.BtSarBaseTest import BtSarBaseTest 21from acts_contrib.test_utils.power.PowerBTBaseTest import ramp_attenuation 22import acts_contrib.test_utils.wifi.wifi_performance_test_utils as wifi_utils 23 24SLEEP_DURATION = 2 25 26class BtSarPowerLimitTest(BtSarBaseTest): 27 """Class to define BT SAR power cap tests. 28 29 This class defines tests that iterate over and force different 30 states in the BT SAR table and calculates the TX power at the 31 antenna port. 32 """ 33 def setup_test(self): 34 super().setup_test() 35 36 # To prevent default file from being overwritten 37 self.dut.adb.shell('cp {} {}'.format(self.power_file_paths[0], 38 self.power_file_paths[1])) 39 40 self.sar_file_path = self.power_file_paths[1] 41 self.sar_file_name = os.path.basename(self.power_file_paths[1]) 42 self.bt_sar_df = self.read_sar_table(self.dut) 43 44 # BokehFigure object 45 self.plot = wifi_utils.BokehFigure(title='{}'.format( 46 self.current_test_name), 47 x_label='Scenarios', 48 primary_y_label='TX power(dBm)') 49 50 def teardown_test(self): 51 # Deleting the table 52 self.dut.adb.shell('rm {}'.format(self.power_file_paths[1])) 53 super().teardown_test() 54 55 def test_bt_sar_table(self): 56 sar_df = self.sweep_table() 57 sar_df = self.process_table(sar_df) 58 self.process_results(sar_df) 59 60 def test_bt_sar_custom_table(self): 61 62 self.push_table(self.dut, self.custom_sar_path) 63 self.attenuator.set_atten(0) 64 65 # Connect master and slave 66 self.bt_device.reset() 67 self.dut.droid.bluetoothFactoryReset() 68 bt_utils.connect_phone_to_headset(self.dut, self.bt_device, 60) 69 time.sleep(SLEEP_DURATION) 70 ramp_attenuation(self.attenuator, self.pl10_atten) 71 time.sleep(SLEEP_DURATION) 72 sar_df = self.sweep_table() 73 sar_df = self.process_table(sar_df) 74 self.process_results(sar_df) 75