1#!/usr/bin/env python3 2# 3# Copyright (C) 2018 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""" 17Test to check MultiProfile Stress with Wlan. 18 19Test Setup: 20 21One Android device. 22""" 23import time 24 25from acts_contrib.test_utils.bt import BtEnum 26from acts_contrib.test_utils.bt.bt_test_utils import clear_bonded_devices 27from acts_contrib.test_utils.coex.CoexBaseTest import CoexBaseTest 28from acts_contrib.test_utils.coex.coex_test_utils import disconnect_headset_from_dev 29from acts_contrib.test_utils.coex.coex_test_utils import pair_and_connect_headset 30 31 32class CoexBtMultiProfileStressTest(CoexBaseTest): 33 34 def setup_class(self): 35 super().setup_class() 36 37 self.receiver = self.relay_devices[1] 38 req_params = ["iterations"] 39 self.unpack_userparams(req_params) 40 41 def setup_test(self): 42 super().setup_test() 43 self.audio_receiver.enter_pairing_mode() 44 self.receiver.setup() 45 self.receiver.power_on() 46 self.receiver.enter_pairing_mode() 47 48 def teardown_test(self): 49 clear_bonded_devices(self.pri_ad) 50 super().teardown_test() 51 self.audio_receiver.clean_up() 52 self.receiver.clean_up() 53 54 def initiate_classic_connection_to_multiple_devices(self): 55 """Initiates multiple BR/EDR connections. 56 57 Steps: 58 1. Initiate A2DP Connection. 59 2. Initiate HFP Connection. 60 3. Disconnect A2DP Connection. 61 4. Disconnect HFP Connection. 62 5. Repeat step 1 to 4. 63 64 Returns: 65 True if successful, False otherwise. 66 """ 67 for i in range(self.iterations): 68 if not pair_and_connect_headset( 69 self.pri_ad, self.receiver.mac_address, 70 {BtEnum.BluetoothProfile.A2DP.value}): 71 self.log.error("Failed to connect A2DP Profile.") 72 return False 73 time.sleep(2) 74 75 if not pair_and_connect_headset( 76 self.pri_ad, self.audio_receiver.mac_address, 77 {BtEnum.BluetoothProfile.HEADSET.value}): 78 self.log.error("Failed to connect HEADSET profile.") 79 return False 80 time.sleep(2) 81 82 if not disconnect_headset_from_dev( 83 self.pri_ad, self.receiver.mac_address, 84 [BtEnum.BluetoothProfile.A2DP.value]): 85 self.log.error("Could not disconnect {}".format( 86 self.receiver.mac_address)) 87 return False 88 89 if not disconnect_headset_from_dev( 90 self.pri_ad, self.audio_receiver.mac_address, 91 [BtEnum.BluetoothProfile.HEADSET.value]): 92 self.log.error("Could not disconnect {}".format( 93 self.audio_receiver.mac_address)) 94 return False 95 return True 96 97 def initiate_classic_connection_with_iperf(self): 98 """Wrapper function to initiate bluetooth classic connection to 99 multiple devices. 100 """ 101 self.run_iperf_and_get_result() 102 if not self.initiate_classic_connection_to_multiple_devices(): 103 return False 104 return self.teardown_result() 105 106 def test_stress_multiple_connection_with_tcp_ul(self): 107 """ Connects multiple headsets with wlan traffic over TCP-uplink. 108 109 This test is to perform connect and disconnect with A2DP and HFP 110 profiles on two different bluetooth devices. 111 112 Steps: 113 1. Run wlan traffic over TCP-uplink. 114 2. Initiate connect and disconnect to multiple profiles from primary 115 device. 116 117 Returns: 118 True if successful, False otherwise. 119 120 Test Id: Bt_CoEx_Stress_037 121 """ 122 if not self.initiate_classic_connection_with_iperf(): 123 return False 124 return True 125 126 def test_stress_multiple_connection_with_tcp_dl(self): 127 """ Connects multiple headsets with wlan traffic over TCP-downlink. 128 129 This test is to perform connect and disconnect with A2DP and HFP 130 profiles on two different bluetooth devices. 131 132 Steps: 133 1. Run wlan traffic over TCP-downlink. 134 2. Initiate connect and disconnect to multiple profiles from primary 135 device. 136 137 Returns: 138 True if successful, False otherwise. 139 140 Test Id: Bt_CoEx_Stress_038 141 """ 142 if not self.initiate_classic_connection_with_iperf(): 143 return False 144 return True 145 146 def test_stress_multiple_connection_with_udp_ul(self): 147 """ Connects multiple headsets with wlan traffic over UDP-uplink. 148 149 This test is to perform connect and disconnect with A2DP and HFP 150 profiles on two different bluetooth devices. 151 152 Steps: 153 1. Run wlan traffic over UDP-uplink. 154 2. Initiate connect and disconnect to multiple profiles from primary 155 device. 156 157 Returns: 158 True if successful, False otherwise. 159 160 Test Id: Bt_CoEx_Stress_039 161 """ 162 if not self.initiate_classic_connection_with_iperf(): 163 return False 164 return True 165 166 def test_stress_multiple_connection_with_udp_dl(self): 167 """ Connects multiple headsets with wlan traffic over UDP-downlink. 168 169 This test is to perform connect and disconnect with A2DP and HFP 170 profiles. 171 172 Steps: 173 1. Run wlan traffic over UDP-downlink. 174 2. Initiate connect and disconnect to multiple profiles from primary 175 device. 176 177 Returns: 178 True if successful, False otherwise. 179 180 Test Id: Bt_CoEx_Stress_040 181 """ 182 if not self.initiate_classic_connection_with_iperf(): 183 return False 184 return True 185