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