• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
16
17import acts_contrib.test_utils.bt.bt_test_utils as btutils
18from acts_contrib.test_utils.bt.A2dpBaseTest import A2dpBaseTest
19from acts_contrib.test_utils.bt.bt_constants import ble_scan_settings_modes
20from acts_contrib.test_utils.bt.bt_test_utils import generate_ble_scan_objects
21from acts_contrib.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test
22from acts_contrib.test_utils.bt.bt_constants import scan_result
23
24INIT_ATTEN = 0
25
26
27class BtA2dpRangeWithBleScanTest(A2dpBaseTest):
28    """User can generate test case with below format.
29    test_bt_a2dp_range_codec_"Codec"_with_BLE_scan_"Scan Mode"
30
31    Below are the list of test cases:
32        test_bt_a2dp_range_codec_AAC_with_BLE_scan_balanced
33        test_bt_a2dp_range_codec_AAC_with_BLE_scan_low_latency
34        test_bt_a2dp_range_codec_AAC_with_BLE_scan_low_power
35        test_bt_a2dp_range_codec_AAC_with_BLE_scan_opportunistic
36        test_bt_a2dp_range_codec_SBC_with_BLE_scan_balanced
37        test_bt_a2dp_range_codec_SBC_with_BLE_scan_low_latency
38        test_bt_a2dp_range_codec_SBC_with_BLE_scan_low_power
39        test_bt_a2dp_range_codec_SBC_with_BLE_scan_opportunistic
40    """
41
42    def __init__(self, configs):
43        super().__init__(configs)
44        req_params = ['attenuation_vector', 'codecs']
45        opt_params = ['gain_mismatch', 'dual_chain']
46        #'attenuation_vector' is a dict containing: start, stop and step of attenuation changes
47        #'codecs' is a list containing all codecs required in the tests
48        #'gain_mismatch' is an offset value between the BT two chains
49        #'dual_chain' set to 1 enable sweeping attenuation for BT two chains
50        self.unpack_userparams(req_params)
51        self.unpack_userparams(opt_params, dual_chian=None, gain_mismatch=None)
52
53    def setup_generated_tests(self):
54        for codec_config in self.codecs:
55            for scan_mode in ble_scan_settings_modes.items():
56                arg_set = [(codec_config, scan_mode)]
57                self.generate_tests(
58                    test_logic=self.BtA2dp_with_ble_scan_test_logic,
59                    name_func=self.create_test_name,
60                    arg_sets=arg_set)
61
62    def setup_class(self):
63        super().setup_class()
64        #Enable BQR on all android devices
65        btutils.enable_bqr(self.android_devices)
66        if hasattr(self, 'dual_chain') and self.dual_chain == 1:
67            self.atten_c0 = self.attenuators[0]
68            self.atten_c1 = self.attenuators[1]
69            self.atten_c0.set_atten(INIT_ATTEN)
70            self.atten_c1.set_atten(INIT_ATTEN)
71        return setup_multiple_devices_for_bt_test(self.android_devices)
72
73    def teardown_class(self):
74        super().teardown_class()
75        if hasattr(self, 'atten_c0') and hasattr(self, 'atten_c1'):
76            self.atten_c0.set_atten(INIT_ATTEN)
77            self.atten_c1.set_atten(INIT_ATTEN)
78
79    def BtA2dp_with_ble_scan_test_logic(self, codec_config, scan_mode):
80        scan_callback = self.start_ble_scan(scan_mode[1])
81        self.run_a2dp_to_max_range(codec_config)
82        self.dut.droid.bleStopBleScan(scan_callback)
83        self.log.info("BLE Scan stopped successfully")
84
85    def create_test_name(self, codec_config, scan_mode):
86        if hasattr(self, 'dual_chain') and self.dual_chain == 1:
87            test_case_name = 'test_dual_bt_a2dp_range_codec_{}_gainmismatch_{}dB_with_BLE_scan_{}'.format(
88                codec_config['codec_type'], self.gain_mismatch, scan_mode[0])
89        else:
90            test_case_name = 'test_bt_a2dp_range_codec_{}_with_BLE_scan_{}'.format(
91                codec_config['codec_type'], scan_mode[0])
92        return test_case_name
93
94    def start_ble_scan(self, scan_mode):
95        """ This function will start Ble Scan with different scan mode.
96
97        Args:
98            Scan_mode: Ble scan setting modes
99
100        returns:
101        Scan_callback: Ble scan callback
102        """
103
104        self.dut.droid.bleSetScanSettingsScanMode(scan_mode)
105        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
106            self.dut.droid)
107        self.dut.droid.bleStartBleScan(filter_list, scan_settings,
108                                       scan_callback)
109        self.log.info("BLE Scanning started successfully")
110        return scan_callback
111
112