1 # /usr/bin/env python3.4 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 17 import time 18 19 from acts.test_utils.bt import BtEnum 20 from acts.test_utils.bt.bt_test_utils import clear_bonded_devices 21 from acts.test_utils.coex.CoexBaseTest import CoexBaseTest 22 from acts.test_utils.coex.coex_test_utils import connect_dev_to_headset 23 from acts.test_utils.coex.coex_test_utils import disconnect_headset_from_dev 24 from acts.test_utils.coex.coex_test_utils import music_play_and_check 25 from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset 26 27 28 class CoexA2dpStressTest(CoexBaseTest): 29 30 def __init__(self, controllers): 31 CoexBaseTest.__init__(self, controllers) 32 33 def setup_class(self): 34 CoexBaseTest.setup_class(self) 35 req_params = ["iterations"] 36 self.unpack_userparams(req_params) 37 38 def setup_test(self): 39 CoexBaseTest.setup_test(self) 40 self.audio_receiver.pairing_mode() 41 if not pair_and_connect_headset( 42 self.pri_ad, self.audio_receiver.mac_address, 43 set([BtEnum.BluetoothProfile.A2DP.value])): 44 self.log.error("Failed to pair and connect to headset") 45 return False 46 47 def teardown_test(self): 48 clear_bonded_devices(self.pri_ad) 49 CoexBaseTest.teardown_test(self) 50 self.audio_receiver.clean_up() 51 52 def connect_disconnect_headset(self): 53 """Initiates connection to paired headset and disconnects headset. 54 55 Returns: 56 True if successful False otherwise. 57 """ 58 for i in range(self.iterations): 59 self.log.info("Headset connect/disconnect iteration={}".format(i)) 60 self.pri_ad.droid.bluetoothConnectBonded( 61 self.audio_receiver.mac_address) 62 time.sleep(2) 63 self.pri_ad.droid.bluetoothDisconnectConnected( 64 self.audio_receiver.mac_address) 65 return True 66 67 def connect_disconnect_a2dp_headset(self): 68 """Connect and disconnect a2dp profile on headset for multiple 69 iterations. 70 71 Steps: 72 1.Connect a2dp profile on headset. 73 2.Disconnect a2dp profile on headset. 74 3.Repeat step 1 and 2 for N iterations. 75 76 Returns: 77 True if successful, False otherwise. 78 """ 79 for i in range(self.iterations): 80 if not connect_dev_to_headset( 81 self.pri_ad, self.audio_receiver.mac_address, 82 {BtEnum.BluetoothProfile.A2DP.value}): 83 self.log.error("Failure to connect A2dp headset.") 84 return False 85 86 if not disconnect_headset_from_dev( 87 self.pri_ad, self.audio_receiver.mac_address, 88 [BtEnum.BluetoothProfile.A2DP.value]): 89 self.log.error("Could not disconnect {}".format( 90 self.audio_receiver.mac_address)) 91 return False 92 return True 93 94 def connect_disconnect_headset_with_iperf(self): 95 """Wrapper function to start iperf traffic and connect/disconnect 96 to headset for N iterations. 97 """ 98 self.run_iperf_and_get_result() 99 if not self.connect_disconnect_headset(): 100 return False 101 return self.teardown_result() 102 103 def connect_disconnect_a2dp_headset_with_iperf(self): 104 """Wrapper function to start iperf traffic and connect/disconnect 105 to a2dp headset for N iterations. 106 """ 107 self.run_iperf_and_get_result() 108 if not self.connect_disconnect_a2dp_headset(): 109 return False 110 return self.teardown_result() 111 112 def music_streaming_with_iperf(self): 113 """Wrapper function to start iperf traffic and music streaming.""" 114 self.run_iperf_and_get_result() 115 if not music_play_and_check( 116 self.pri_ad, self.audio_receiver.mac_address, 117 self.music_file_to_play, self.iperf["duration"]): 118 return False 119 return self.teardown_result() 120 121 def test_stress_connect_disconnect_headset_with_tcp_ul(self): 122 """Stress test for connect/disconnect headset. 123 124 This test is to start TCP-uplink traffic between host machine and 125 android device and test the integrity of connection and disconnection 126 to headset. 127 128 Steps: 129 1. Run TCP-uplink traffic. 130 2. Connect and disconnect headset. 131 3. Repeat step 2 for N iterations. 132 133 Returns: 134 True if successful, False otherwise. 135 136 Test Id: Bt_CoEx_Stress_013 137 """ 138 if not self.connect_disconnect_headset_with_iperf(): 139 return False 140 return True 141 142 def test_stress_connect_disconnect_headset_with_tcp_dl(self): 143 """Stress test for connect/disconnect headset. 144 145 This test is to start TCP-downlink traffic between host machine and 146 android device and test the integrity of connection and disconnection 147 to headset. 148 149 Steps: 150 1. Run TCP-downlink traffic. 151 2. Connect and disconnect headset. 152 3. Repeat step 2 for N iterations. 153 154 Returns: 155 True if successful, False otherwise. 156 157 Test Id: Bt_CoEx_Stress_014 158 """ 159 if not self.connect_disconnect_headset_with_iperf(): 160 return False 161 return True 162 163 def test_stress_connect_disconnect_headset_with_udp_ul(self): 164 """Stress test for connect/disconnect headset. 165 166 This test is to start UDP-uplink traffic between host machine and 167 android device and test the integrity of connection and disconnection 168 to headset. 169 170 Steps: 171 1. Run UDP-uplink traffic. 172 2. Connect and disconnect headset. 173 3. Repeat step 2 for N iterations. 174 175 Returns: 176 True if successful, False otherwise. 177 178 Test Id: Bt_CoEx_Stress_015 179 """ 180 if not self.connect_disconnect_headset_with_iperf(): 181 return False 182 return True 183 184 def test_stress_connect_disconnect_headset_with_udp_dl(self): 185 """Stress test for connect/disconnect headset. 186 187 This test is to start UDP-downlink traffic between host machine and 188 android device and test the integrity of connection and disconnection 189 to headset. 190 191 Steps: 192 1. Run UDP-downlink traffic. 193 2. Connect and disconnect headset. 194 3. Repeat step 2 for N iterations. 195 196 Returns: 197 True if successful, False otherwise. 198 199 Test Id: Bt_CoEx_Stress_016 200 """ 201 if not self.connect_disconnect_headset_with_iperf(): 202 return False 203 return True 204 205 def test_stress_a2dp_long_duration_with_tcp_ul(self): 206 """Stress test to stream music to headset continuously for 12 hours. 207 208 This test is to start TCP-uplink traffic between host machine and 209 android device and test the integrity of audio streaming for 12 hours. 210 211 Steps: 212 1. Start TCP uplink traffic. 213 2. Start music streaming to headset. 214 215 Returns: 216 True if successful, False otherwise. 217 218 Test Id: Bt_CoEx_Stress_017 219 """ 220 if not self.music_streaming_with_iperf(): 221 return False 222 return True 223 224 def test_stress_a2dp_long_duration_with_tcp_dl(self): 225 """Stress test to stream music to headset continuously for 12 hours. 226 227 This test is to start TCP-downlink traffic between host machine and 228 android device and test the integrity of audio streaming for 12 hours. 229 230 Steps: 231 1. Start TCP downlink traffic. 232 2. Start music streaming to headset. 233 234 Returns: 235 True if successful, False otherwise. 236 237 Test Id: Bt_CoEx_Stress_018 238 """ 239 if not self.music_streaming_with_iperf(): 240 return False 241 return True 242 243 def test_stress_a2dp_long_duration_with_udp_ul(self): 244 """Stress test to stream music to headset continuously for 12 hours. 245 246 This test is to start UDP-uplink traffic between host machine and 247 android device and test the integrity of audio streaming for 12 hours. 248 249 Steps: 250 1. Start UDP uplink traffic. 251 2. Start music streaming to headset. 252 253 Returns: 254 True if successful, False otherwise. 255 256 Test Id: Bt_CoEx_Stress_019 257 """ 258 if not self.music_streaming_with_iperf(): 259 return False 260 return True 261 262 def test_stress_a2dp_long_duration_with_udp_dl(self): 263 """Stress test to stream music to headset continuously for 12 hours. 264 265 This test is to start UDP-downlink traffic between host machine and 266 android device and test the integrity of audio streaming for 12 hours. 267 268 Steps: 269 1. Start UDP downlink traffic. 270 2. Start music streaming to headset. 271 272 Returns: 273 True if successful, False otherwise. 274 275 Test Id: Bt_CoEx_Stress_020 276 """ 277 if not self.music_streaming_with_iperf(): 278 return False 279 return True 280 281 def test_stress_connect_disconnect_a2dp_profile_with_tcp_ul(self): 282 """Stress test for connect/disconnect a2dp headset. 283 284 This test is to start TCP-uplink traffic between host machine and 285 android device and test the integrity of connection and disconnection 286 to headset with a2dp profile. 287 288 Steps: 289 1. Run TCP-uplink traffic. 290 2. Connect and disconnect headset with a2dp profile. 291 3. Repeat step 2 for N iterations. 292 293 Returns: 294 True if successful, False otherwise. 295 296 Test Id: Bt_CoEx_Stress_029 297 """ 298 if not self.connect_disconnect_a2dp_headset_with_iperf(): 299 return False 300 return True 301 302 def test_stress_connect_disconnect_a2dp_profile_with_tcp_dl(self): 303 """Stress test for connect/disconnect a2dp headset. 304 305 This test is to start TCP-downlink traffic between host machine and 306 android device and test the integrity of connection and disconnection 307 to headset with a2dp profile. 308 309 Steps: 310 1. Run TCP-downlink traffic. 311 2. Connect and disconnect headset with a2dp profile. 312 3. Repeat step 2 for N iterations. 313 314 Returns: 315 True if successful, False otherwise. 316 317 Test Id: Bt_CoEx_Stress_030 318 """ 319 if not self.connect_disconnect_a2dp_headset_with_iperf(): 320 return False 321 return True 322 323 def test_stress_connect_disconnect_a2dp_profile_with_udp_ul(self): 324 """Stress test for connect/disconnect a2dp headset. 325 326 This test is to start UDP-uplink traffic between host machine and 327 android device and test the integrity of connection and disconnection 328 to headset with a2dp profile. 329 330 Steps: 331 1. Run UDP-uplink traffic. 332 2. Connect and disconnect headset with a2dp profile. 333 3. Repeat step 2 for N iterations. 334 335 Returns: 336 True if successful, False otherwise. 337 338 Test Id: Bt_CoEx_Stress_031 339 """ 340 if not self.connect_disconnect_a2dp_headset_with_iperf(): 341 return False 342 return True 343 344 def test_stress_connect_disconnect_a2dp_profile_with_udp_dl(self): 345 """Stress test for connect/disconnect a2dp headset. 346 347 This test is to start UDP-downlink traffic between host machine and 348 android device and test the integrity of connection and disconnection 349 to headset with a2dp profile. 350 351 Steps: 352 1. Run UDP-downlink traffic. 353 2. Connect and disconnect headset with a2dp profile. 354 3. Repeat step 2 for N iterations. 355 356 Returns: 357 True if successful, False otherwise. 358 359 Test Id: Bt_CoEx_Stress_032 360 """ 361 if not self.connect_disconnect_a2dp_headset_with_iperf(): 362 return False 363 return True 364 365 def test_stress_connect_disconnect_headset_with_tcp_bidirectional(self): 366 """Stress test for connect/disconnect headset. 367 368 This test starts TCP-bidirectional traffic between host machine and 369 android device and test the integrity of connection and disconnection 370 to headset. 371 372 Steps: 373 1. Run TCP-bidirectional traffic. 374 2. Connect and disconnect headset. 375 3. Repeat step 2 for N iterations. 376 377 Returns: 378 True if successful, False otherwise. 379 380 Test Id: Bt_CoEx_Stress_057 381 """ 382 if not self.connect_disconnect_headset_with_iperf(): 383 return False 384 return True 385 386 def test_stress_connect_disconnect_headset_with_udp_bidirectional(self): 387 """Stress test for connect/disconnect headset. 388 389 This test starts UDP-bidirectional traffic between host machin and 390 android device and test the integrity of connection and disconnection 391 to headset. 392 393 Steps: 394 1. Run UDP-bidirectional traffic. 395 2. Connect and disconnect headset. 396 3. Repeat step 2 for N iterations. 397 398 Returns: 399 True if successful, False otherwise. 400 401 Test Id: Bt_CoEx_Stress_058 402 """ 403 if not self.connect_disconnect_headset_with_iperf(): 404 return False 405 return True 406 407 def test_stress_a2dp_long_duration_with_tcp_bidirectional(self): 408 """Stress test to stream music to headset continuously for 12 hours. 409 410 This test starts TCP-bidirectional traffic between host machin and 411 android device and test the integrity of audio streaming for 12 hours. 412 413 Steps: 414 1. Start TCP bidirectional traffic. 415 2. Start music streaming to headset. 416 417 Returns: 418 True if successful, False otherwise. 419 420 Test Id: Bt_CoEx_Stress_065 421 """ 422 if not self.music_streaming_with_iperf(): 423 return False 424 return True 425 426 def test_stress_a2dp_long_duration_with_udp_bidirectional(self): 427 """Stress test to stream music to headset continuously for 12 hours. 428 429 This test starts UDP-bidirectional traffic between host machin and 430 android device and test the integrity of audio streaming for 12 hours. 431 432 Steps: 433 1. Start UDP bidirectional traffic. 434 2. Start music streaming to headset. 435 436 Returns: 437 True if successful, False otherwise. 438 439 Test Id: Bt_CoEx_Stress_066 440 """ 441 if not self.music_streaming_with_iperf(): 442 return False 443 return True 444