1#!/usr/bin/env python3
2#
3# Copyright (C) 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16import acts_contrib.test_utils.bt.bt_test_utils as btutils
17from acts import asserts
18from acts_contrib.test_utils.bt.A2dpBaseTest import A2dpBaseTest
19
20INIT_ATTEN = 0
21
22
23class BtA2dpRangeTest(A2dpBaseTest):
24
25    def __init__(self, configs):
26        super().__init__(configs)
27        req_params = ['attenuation_vector', 'codecs']
28        opt_params = ['gain_mismatch', 'dual_chain']
29        #'attenuation_vector' is a dict containing: start, stop and step of
30        #attenuation changes
31        #'codecs' is a list containing all codecs required in the tests
32        self.unpack_userparams(req_params)
33        self.unpack_userparams(opt_params, dual_chain=None, gain_mismatch=None)
34
35    def setup_generated_tests(self):
36        for codec_config in self.codecs:
37            arg_set = [(codec_config, )]
38            self.generate_tests(test_logic=self.BtA2dp_test_logic,
39                                name_func=self.create_test_name,
40                                arg_sets=arg_set)
41
42    def setup_class(self):
43        super().setup_class()
44        # Enable BQR on all android devices
45        btutils.enable_bqr(self.android_devices)
46        if hasattr(self, 'dual_chain') and self.dual_chain == 1:
47            self.atten_c0 = self.attenuators[0]
48            self.atten_c1 = self.attenuators[1]
49            self.atten_c0.set_atten(INIT_ATTEN)
50            self.atten_c1.set_atten(INIT_ATTEN)
51
52    def teardown_class(self):
53        super().teardown_class()
54        if hasattr(self, 'atten_c0') and hasattr(self, 'atten_c1'):
55            self.atten_c0.set_atten(INIT_ATTEN)
56            self.atten_c1.set_atten(INIT_ATTEN)
57
58    def BtA2dp_test_logic(self, codec_config):
59        self.run_a2dp_to_max_range(codec_config)
60
61    def create_test_name(self, arg_set):
62        if hasattr(self, 'dual_chain') and self.dual_chain == 1:
63            test_case_name = 'test_dual_bt_a2dp_range_codec_{}_gainmismatch_{}dB'.format(
64                arg_set['codec_type'], self.gain_mismatch)
65        else:
66            test_case_name = 'test_bt_a2dp_range_codec_{}'.format(
67                arg_set['codec_type'])
68        return test_case_name
69