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 19from acts import utils 20 21import acts_contrib.test_utils.bt.bt_test_utils as bt_utils 22import acts_contrib.test_utils.wifi.wifi_performance_test_utils as wifi_utils 23from acts_contrib.test_utils.bt.ble_performance_test_utils import ble_gatt_disconnection 24from acts_contrib.test_utils.bt.ble_performance_test_utils import ble_coc_connection 25from acts_contrib.test_utils.bt.bt_constants import l2cap_max_inactivity_delay_after_disconnect 26from acts_contrib.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 27from acts_contrib.test_utils.bt.BtSarBaseTest import BtSarBaseTest 28 29FIXED_ATTENUATION = 36 30 31 32class BleSarPowerLimitTest(BtSarBaseTest): 33 """Class to define BLE SAR power cap tests. 34 35 This class defines tests that iterate over and force different 36 states in the BLE SAR table and calculates the TX power at the 37 antenna port. 38 """ 39 def setup_class(self): 40 super().setup_class() 41 self.bt_device = self.android_devices[1] 42 return setup_multiple_devices_for_bt_test(self.android_devices) 43 44 def setup_test(self): 45 46 #self.dut.droid.bluetoothFactoryReset() 47 #bt_utils.enable_bluetooth(self.dut.droid, self.bt_device.ed) 48 49 #Reset SAR test result to 0 before every test 50 self.sar_test_result.metric_value = 0 51 52 # To prevent default file from being overwritten 53 self.dut.adb.shell('cp {} {}'.format(self.power_file_paths[0], 54 self.power_file_paths[1])) 55 56 self.sar_file_path = self.power_file_paths[1] 57 self.sar_file_name = os.path.basename(self.power_file_paths[1]) 58 self.bt_sar_df = self.read_sar_table(self.dut) 59 60 utils.set_location_service(self.bt_device, True) 61 utils.set_location_service(self.dut, True) 62 63 self.attenuator.set_atten(FIXED_ATTENUATION) 64 self.log.info('Attenuation set to {} dB'.format(FIXED_ATTENUATION)) 65 66 # BokehFigure object 67 self.plot = wifi_utils.BokehFigure(title='{}'.format( 68 self.current_test_name), 69 x_label='Scenarios', 70 primary_y_label='TX power(dBm)') 71 72 def teardown_test(self): 73 # Deleting the table 74 self.dut.adb.shell('rm {}'.format(self.power_file_paths[1])) 75 self.attenuator.set_atten(self.atten_min) 76 self.log.info('Attenuation set to {} dB'.format(self.atten_min)) 77 ble_gatt_disconnection(self.bt_device, self.bluetooth_gatt, 78 self.gatt_callback) 79 self.bt_device.droid.bluetoothSocketConnStop() 80 self.dut.droid.bluetoothSocketConnStop() 81 time.sleep(l2cap_max_inactivity_delay_after_disconnect) 82 self.dut.droid.bluetoothFactoryReset() 83 bt_utils.disable_bluetooth(self.dut.droid) 84 85 def teardown_class(self): 86 bt_utils.disable_bluetooth(self.dut.droid) 87 88 def test_ble_sar_table(self): 89 """ Test for BLE SAR default table 90 91 BLE SAR table Test iterates over BT SAR default table and forces signal states, by 92 measuring ble RSSI and power level for each state and processes the results of 93 sweep_table and computes BLE TX power and parses the processed table with 94 computed BLE TX power values to return pass or fail 95 """ 96 # Establish CoC BLE connection 97 self.status, self.gatt_callback, self.gatt_server, self.bluetooth_gatt, \ 98 self.client_conn_id = ble_coc_connection(self.bt_device, self.dut) 99 sar_df = self.sweep_table(self.dut, 100 self.bt_device, 101 self.client_conn_id, 102 self.gatt_server, 103 self.gatt_callback, 104 isBLE=True) 105 sar_df = self.process_table(sar_df) 106 self.process_results(sar_df, type='BLE') 107 108 def test_ble_sar_custom_table(self): 109 """ Test for BLE SAR custom table 110 111 BLE SAR custom table Test Iterates over BT SAR custom table and forces signal states, by 112 measuring ble RSSI and power level for each state and processes the results of 113 sweep_table and computes BLE TX power and parses the processed table with 114 computed BLE TX power values to return pass or fail 115 """ 116 117 self.push_table(self.dut, self.custom_sar_path) 118 setup_multiple_devices_for_bt_test(self.android_devices) 119 120 # Establish CoC BLE connection 121 self.status, self.gatt_callback, self.gatt_server, self.bluetooth_gatt, \ 122 self.client_conn_id = ble_coc_connection(self.bt_device, self.dut) 123 sar_df = self.sweep_table(self.dut, 124 self.bt_device, 125 self.client_conn_id, 126 self.gatt_server, 127 self.gatt_callback, 128 isBLE=True) 129 sar_df = self.process_table(sar_df) 130 self.process_results(sar_df, type='BLE') 131