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 def __init__(self, configs): 25 super().__init__(configs) 26 req_params = ['attenuation_vector', 'codecs'] 27 #'attenuation_vector' is a dict containing: start, stop and step of 28 #attenuation changes 29 #'codecs' is a list containing all codecs required in the tests 30 self.unpack_userparams(req_params) 31 for codec_config in self.codecs: 32 self.generate_test_case(codec_config) 33 34 def setup_class(self): 35 super().setup_class() 36 opt_params = ['gain_mismatch', 'dual_chain'] 37 self.unpack_userparams(opt_params, dual_chain=None, gain_mismatch=None) 38 # Enable BQR on all android devices 39 btutils.enable_bqr(self.android_devices) 40 if hasattr(self, 'dual_chain') and self.dual_chain == 1: 41 self.atten_c0 = self.attenuators[0] 42 self.atten_c1 = self.attenuators[1] 43 self.atten_c0.set_atten(INIT_ATTEN) 44 self.atten_c1.set_atten(INIT_ATTEN) 45 46 def teardown_class(self): 47 super().teardown_class() 48 if hasattr(self, 'atten_c0') and hasattr(self, 'atten_c1'): 49 self.atten_c0.set_atten(INIT_ATTEN) 50 self.atten_c1.set_atten(INIT_ATTEN) 51 52 def generate_test_case(self, codec_config): 53 def test_case_fn(): 54 self.run_a2dp_to_max_range(codec_config) 55 56 if hasattr(self, 'dual_chain') and self.dual_chain == 1: 57 test_case_name = 'test_dual_bt_a2dp_range_codec_{}_gainmimatch_{}dB'.format( 58 codec_config['codec_type'], self.gain_mismatch) 59 else: 60 test_case_name = 'test_bt_a2dp_range_codec_{}'.format( 61 codec_config['codec_type']) 62 setattr(self, test_case_name, test_case_fn) 63