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