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 17import time 18 19from acts.test_utils.bt import BtEnum 20from acts.test_utils.bt.bt_test_utils import clear_bonded_devices 21from acts.test_utils.coex.CoexBaseTest import CoexBaseTest 22from acts.test_utils.coex.coex_test_utils import connect_dev_to_headset 23from acts.test_utils.coex.coex_test_utils import disconnect_headset_from_dev 24from acts.test_utils.coex.coex_constants import AUDIO_ROUTE_BLUETOOTH 25from acts.test_utils.coex.coex_constants import AUDIO_ROUTE_SPEAKER 26from acts.test_utils.coex.coex_test_utils import initiate_disconnect_from_hf 27from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset 28from acts.test_utils.tel.tel_test_utils import hangup_call 29from acts.test_utils.tel.tel_voice_utils import set_audio_route 30 31 32class CoexHfpStressTest(CoexBaseTest): 33 34 def __init__(self, controllers): 35 CoexBaseTest.__init__(self, controllers) 36 37 def setup_class(self): 38 CoexBaseTest.setup_class(self) 39 req_params = ["iterations"] 40 self.unpack_userparams(req_params) 41 42 def setup_test(self): 43 CoexBaseTest.setup_test(self) 44 self.audio_receiver.enter_pairing_mode() 45 if not pair_and_connect_headset( 46 self.pri_ad, self.audio_receiver.mac_address, 47 set([BtEnum.BluetoothProfile.HEADSET.value])): 48 self.log.error("Failed to pair and connect to headset") 49 return False 50 51 def teardown_test(self): 52 clear_bonded_devices(self.pri_ad) 53 CoexBaseTest.teardown_test(self) 54 self.audio_receiver.clean_up() 55 56 def connect_disconnect_hfp_headset(self): 57 """Connect and disconnect hfp profile on headset for multiple 58 iterations. 59 60 Steps: 61 1.Connect hfp profile on headset. 62 2.Disconnect hfp profile on headset. 63 3.Repeat step 1 and 2 for N iterations. 64 65 Returns: 66 True if successful, False otherwise. 67 """ 68 for i in range(self.iterations): 69 if not connect_dev_to_headset( 70 self.pri_ad, self.audio_receiver.mac_address, 71 {BtEnum.BluetoothProfile.HEADSET.value}): 72 self.log.error("Failure to connect HFP headset.") 73 return False 74 75 if not disconnect_headset_from_dev( 76 self.pri_ad, self.audio_receiver.mac_address, 77 {BtEnum.BluetoothProfile.HEADSET.value}): 78 self.log.error("Could not disconnect {}".format( 79 self.audio_receiver.mac_address)) 80 return False 81 return True 82 83 def initiate_call_from_hf_disconnect_from_ag(self): 84 """Initiates call from HF and disconnect call from ag for multiple 85 iterations. 86 87 Returns: 88 True if successful, False otherwise. 89 """ 90 for i in range(self.iterations): 91 if not self.audio_receiver.press_initiate_call(): 92 self.log.error("Failed to initiate call.") 93 return False 94 time.sleep(5) #Wait time for intiating call. 95 if not hangup_call(self.log, self.pri_ad): 96 self.log.error("Failed to hang up the call.") 97 return False 98 return True 99 100 def route_audio_from_hf_to_speaker(self): 101 """Route audio from HF to primary device inbuilt speakers and 102 vice_versa. 103 104 Steps: 105 1. Initiate call from HF. 106 2. Toggle audio from HF to speaker and vice-versa from N iterations. 107 3. Hangup call from primary device. 108 109 Returns: 110 True if successful, False otherwise. 111 """ 112 if not self.audio_receiver.press_initiate_call(): 113 self.log.error("Failed to initiate call.") 114 return False 115 for i in range(self.iterations): 116 self.log.info("DUT speaker iteration = {}".format(i)) 117 if not set_audio_route(self.log, self.pri_ad, AUDIO_ROUTE_SPEAKER): 118 self.log.error("Failed switching to primary device speaker.") 119 hangup_call(self.log, self.pri_ad) 120 return False 121 time.sleep(2) 122 if not set_audio_route(self.log, self.pri_ad, 123 AUDIO_ROUTE_BLUETOOTH): 124 self.log.error("Failed switching to bluetooth headset.") 125 hangup_call(self.log, self.pri_ad) 126 return False 127 if not hangup_call(self.log, self.pri_ad): 128 self.log.error("Failed to hang up the call.") 129 return False 130 return True 131 132 def connect_disconnect_hfp_headset_with_iperf(self): 133 """Wrapper function to start iperf traffic and connect/disconnect 134 to a2dp headset for N iterations. 135 """ 136 self.run_iperf_and_get_result() 137 if not self.connect_disconnect_hfp_headset(): 138 return False 139 return self.teardown_result() 140 141 def hfp_long_duration_with_iperf(self): 142 """Wrapper function to start iperf traffic and initiate hfp call.""" 143 self.run_iperf_and_get_result() 144 if not initiate_disconnect_from_hf( 145 self.audio_receiver, self.pri_ad, self.sec_ad, 146 self.iperf["duration"]): 147 return False 148 return self.teardown_result() 149 150 def initiate_call_multiple_times_with_iperf(self): 151 """Wrapper function to start iperf traffic and initiate call and 152 disconnect call simultaneously. 153 """ 154 self.run_iperf_and_get_result() 155 if not self.initiate_call_from_hf_disconnect_from_ag(): 156 return False 157 return self.teardown_result() 158 159 def route_audio_from_hf_to_speaker_with_iperf(self): 160 """Wrapper function to start iperf traffic and route audio from 161 headset to speaker. 162 """ 163 self.run_iperf_and_get_result() 164 if not self.route_audio_from_hf_to_speaker(): 165 return False 166 return self.teardown_result() 167 168 def test_stress_hfp_long_duration_with_tcp_ul(self): 169 """Stress test on hfp call continuously for 12 hours. 170 171 This test is to start TCP-uplink traffic between host machine and 172 android device and test the integrity of hfp connection for 12 hours. 173 174 Steps: 175 1. Start TCP-uplink traffic. 176 2. Initiate call. 177 3. Verify call status. 178 4. Disconnect call. 179 5. Repeat steps 2 to 4 for N iterations 180 181 Returns: 182 True if successful, False otherwise. 183 184 Test Id: Bt_CoEx_Stress_021 185 """ 186 if not self.hfp_long_duration_with_iperf(): 187 return False 188 return True 189 190 def test_stress_hfp_long_duration_with_tcp_dl(self): 191 """Stress test on hfp call continuously for 12 hours. 192 193 This test is to start TCP-downlink traffic between host machine and 194 android device and test the integrity of hfp connection for 12 hours. 195 196 Steps: 197 1. Start TCP-downlink traffic. 198 2. Initiate call. 199 3. Verify call status. 200 4. Disconnect call. 201 5. Repeat steps 2 to 4 for N iterations 202 203 Returns: 204 True if successful, False otherwise. 205 206 Test Id: Bt_CoEx_Stress_022 207 """ 208 if not self.hfp_long_duration_with_iperf(): 209 return False 210 return True 211 212 def test_stress_hfp_long_duration_with_udp_ul(self): 213 """Stress test on hfp call continuously for 12 hours. 214 215 This test is to start UDP-uplink traffic between host machine and 216 android device and test the integrity of hfp connection for 12 hours. 217 218 Steps: 219 1. Start UDP-uplink traffic. 220 2. Initiate call. 221 3. Verify call status. 222 4. Disconnect call. 223 5. Repeat steps 2 to 4 for N iterations 224 225 Returns: 226 True if successful, False otherwise. 227 228 Test Id: Bt_CoEx_Stress_023 229 """ 230 if not self.hfp_long_duration_with_iperf(): 231 return False 232 return True 233 234 def test_stress_hfp_long_duration_with_udp_dl(self): 235 """Stress test on hfp call continuously for 12 hours. 236 237 This test is to start UDP-downlink traffic between host machine and 238 android device and test the integrity of hfp connection for 12 hours. 239 240 Steps: 241 1. Start UDP-downlink traffic. 242 2. Initiate call. 243 3. Verify call status. 244 4. Disconnect call. 245 5. Repeat steps 2 to 4 for N iterations 246 247 Returns: 248 True if successful, False otherwise. 249 250 Test Id: Bt_CoEx_Stress_024 251 """ 252 if not self.hfp_long_duration_with_iperf(): 253 return False 254 return True 255 256 def test_stress_hfp_call_multiple_times_with_tcp_ul(self): 257 """Stress test for initiate and disconnect hfp call. 258 259 This test is to start TCP-uplink traffic between host machine and 260 android device and test the integrity of hfp call. 261 262 Steps: 263 1. Start TCP-uplink traffic. 264 2. Initiate call from HF 265 3. Verify status of call 266 4. Disconnect from AG. 267 5. Repeat steps 2 to 4 for N iterations 268 269 Returns: 270 True if successful, False otherwise. 271 272 Test Id: Bt_CoEx_Stress_025 273 """ 274 if not self.initiate_call_multiple_times_with_iperf(): 275 return False 276 return True 277 278 def test_stress_hfp_call_multiple_times_with_tcp_dl(self): 279 """Stress test for initiate and disconnect hfp call. 280 281 This test is to start TCP-downlink traffic between host machine and 282 android device and test the integrity of hfp call. 283 284 Steps: 285 1. Start TCP-downlink traffic. 286 2. Initiate call from HF 287 3. Verify status of call 288 4. Disconnect from AG. 289 5. Repeat steps 2 to 4 for N iterations 290 291 Returns: 292 True if successful, False otherwise. 293 294 Test Id: Bt_CoEx_Stress_026 295 """ 296 if not self.initiate_call_multiple_times_with_iperf(): 297 return False 298 return True 299 300 def test_stress_hfp_call_multiple_times_with_udp_ul(self): 301 """Stress test for initiate and disconnect hfp call. 302 303 This test is to start UDP-uplink traffic between host machine and 304 android device and test the integrity of hfp call. 305 306 Steps: 307 1. Start UDP-uplink traffic. 308 2. Initiate call from HF 309 3. Verify status of call 310 4. Disconnect from AG. 311 5. Repeat steps 2 to 4 for N iterations 312 313 Returns: 314 True if successful, False otherwise. 315 316 Test Id: Bt_CoEx_Stress_027 317 """ 318 if not self.initiate_call_multiple_times_with_iperf(): 319 return False 320 return True 321 322 def test_stress_hfp_call_multiple_times_with_udp_dl(self): 323 """Stress test for initiate and disconnect hfp call. 324 325 This test is to start UDP-downlink traffic between host machine and 326 android device and test the integrity of hfp call. 327 328 Steps: 329 1. Start UDP-downlink traffic. 330 2. Initiate call from HF 331 3. Verify status of call 332 4. Disconnect from AG. 333 5. Repeat steps 2 to 4 for N iterations 334 335 Returns: 336 True if successful, False otherwise. 337 338 Test Id: Bt_CoEx_Stress_028 339 """ 340 if not self.initiate_call_multiple_times_with_iperf(): 341 return False 342 return True 343 344 def test_stress_connect_disconnect_hfp_profile_with_tcp_ul(self): 345 """Stress test for connect/disconnect hfp headset. 346 347 This test is to start TCP-uplink traffic between host machine and 348 android device and test the integrity of connection and disconnection 349 to headset with hfp profile. 350 351 Steps: 352 1. Run TCP-uplink traffic. 353 2. Connect and disconnect headset with hfp 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_033 360 """ 361 if not self.connect_disconnect_hfp_headset(): 362 return False 363 return True 364 365 def test_stress_connect_disconnect_hfp_profile_with_tcp_dl(self): 366 """Stress test for connect/disconnect hfp headset. 367 368 This test is to start TCP-downlink traffic between host machine and 369 android device and test the integrity of connection and disconnection 370 to headset with hfp profile. 371 372 Steps: 373 1. Run TCP-downlink traffic. 374 2. Connect and disconnect headset with hfp profile. 375 3. Repeat step 2 for N iterations. 376 377 Returns: 378 True if successful, False otherwise. 379 380 Test Id: Bt_CoEx_Stress_034 381 """ 382 if not self.connect_disconnect_hfp_headset(): 383 return False 384 return True 385 386 def test_stress_connect_disconnect_hfp_profile_with_udp_ul(self): 387 """Stress test for connect/disconnect hfp headset. 388 389 This test is to start UDP-uplink traffic between host machine and 390 android device and test the integrity of connection and disconnection 391 to headset with hfp profile. 392 393 Steps: 394 1. Run UDP-uplink traffic. 395 2. Connect and disconnect headset with hfp profile. 396 3. Repeat step 2 for N iterations. 397 398 Returns: 399 True if successful, False otherwise. 400 401 Test Id: Bt_CoEx_Stress_035 402 """ 403 if not self.connect_disconnect_hfp_headset(): 404 return False 405 return True 406 407 def test_stress_connect_disconnect_hfp_profile_with_udp_dl(self): 408 """Stress test for connect/disconnect hfp headset. 409 410 This test is to start UDP-downlink traffic between host machine and 411 android device and test the integrity of connection and disconnection 412 to headset with hfp profile. 413 414 Steps: 415 1. Run UDP-downlink traffic. 416 2. Connect and disconnect headset with hfp profile. 417 3. Repeat step 2 for N iterations. 418 419 Returns: 420 True if successful, False otherwise. 421 422 Test Id: Bt_CoEx_Stress_036 423 """ 424 if not self.connect_disconnect_hfp_headset(): 425 return False 426 return True 427 428 def test_stress_audio_routing_with_tcp_ul(self): 429 """Stress to route audio from HF to primary device speaker. 430 431 This test is to start TCP-uplink traffic between host machine and 432 android device and test the integrity of audio routing between 433 bluetooth headset and android device inbuilt speaker. 434 435 Steps: 436 1. Starts TCP-uplink traffic. 437 2. Route audio from hf to speaker and vice-versa. 438 439 Returns: 440 True if successful, False otherwise. 441 442 Test Id: Bt_CoEx_Stress_037 443 """ 444 if not self.route_audio_from_hf_to_speaker_with_iperf(): 445 return False 446 return True 447 448 def test_stress_audio_routing_with_tcp_dl(self): 449 """Stress to route audio from HF to primary device speaker. 450 451 This test is to start TCP-downlink traffic between host machine and 452 android device and test the integrity of audio routing between 453 bluetooth headset and android device inbuilt speaker. 454 455 Steps: 456 1. Starts TCP-downlink traffic. 457 2. Route audio from hf to speaker and vice-versa. 458 459 Returns: 460 True if successful, False otherwise. 461 462 Test Id: Bt_CoEx_Stress_038 463 """ 464 if not self.route_audio_from_hf_to_speaker_with_iperf(): 465 return False 466 return True 467 468 def test_stress_audio_routing_with_udp_ul(self): 469 """Stress to route audio from HF to primary device speaker. 470 471 This test is to start UDP-uplink traffic between host machine and 472 android device and test the integrity of audio routing between 473 bluetooth headset and android device inbuilt speaker. 474 475 Steps: 476 1. Starts UDP-uplink traffic. 477 2. Route audio from hf to speaker and vice-versa. 478 479 Returns: 480 True if successful, False otherwise. 481 482 Test Id: Bt_CoEx_Stress_039 483 """ 484 if not self.route_audio_from_hf_to_speaker_with_iperf(): 485 return False 486 return True 487 488 def test_stress_audio_routing_with_udp_dl(self): 489 """Stress to route audio from HF to primary device speaker. 490 491 This test is to start UDP-downlink traffic between host machine and 492 android device and test the integrity of audio routing between 493 bluetooth headset and android device inbuilt speaker. 494 495 Steps: 496 1. Starts UDP-downlink traffic. 497 2. Route audio from hf to speaker and vice-versa. 498 499 Returns: 500 True if successful, False otherwise. 501 502 Test Id: Bt_CoEx_Stress_040 503 """ 504 if not self.route_audio_from_hf_to_speaker_with_iperf(): 505 return False 506 return True 507 508 def test_stress_connect_disconnect_hfp_with_tcp_bidirectional(self): 509 """Stress test for connect/disconnect headset. 510 511 This test is to start TCP-bidirectional traffic between host machine and 512 android device and test the integrity of connection and disconnection 513 to headset with hfp profile. 514 515 Steps: 516 1. Run TCP-bidirectional traffic. 517 2. Connect and disconnect headset with hfp profile. 518 3. Repeat step 2 for N iterations. 519 520 Returns: 521 True if successful, False otherwise. 522 523 Test Id: Bt_CoEx_Stress_067 524 """ 525 if not self.connect_disconnect_hfp_headset(): 526 return False 527 return True 528 529 def test_stress_connect_disconnect_hfp_with_udp_bidirectional(self): 530 """Stress test for connect/disconnect headset. 531 532 This test is to start UDP-bidirectional traffic between host machine and 533 android device and test the integrity of connection and disconnection 534 to headset with hfp profile. 535 536 Steps: 537 1. Run UDP-bidirectional traffic. 538 2. Connect and disconnect headset with hfp profile. 539 3. Repeat step 2 for N iterations. 540 541 Returns: 542 True if successful, False otherwise. 543 544 Test Id: Bt_CoEx_Stress_068 545 """ 546 if not self.connect_disconnect_hfp_headset(): 547 return False 548 return True 549 550 def test_stress_hfp_long_duration_with_tcp_bidirectional(self): 551 """Stress test on hfp call continuously for 12 hours. 552 553 This test is to start TCP-bidirectional traffic between host machine and 554 android device and test the integrity of hfp connection for 12 hours. 555 556 Steps: 557 1. Start TCP-bidirectional traffic. 558 2. Initiate call. 559 3. Verify call status. 560 4. Disconnect call. 561 5. Repeat steps 2 to 4 for N iterations 562 563 Returns: 564 True if successful, False otherwise. 565 566 Test Id: Bt_CoEx_Stress_069 567 """ 568 if not self.hfp_long_duration_with_iperf(): 569 return False 570 return True 571 572 def test_stress_hfp_long_duration_with_udp_bidirectional(self): 573 """Stress test on hfp call continuously for 12 hours. 574 575 This test is to start UDP-bidirectional traffic between host machine and 576 android device and test the integrity of hfp connection for 12 hours. 577 578 Steps: 579 1. Start UDP-bidirectional traffic. 580 2. Initiate call. 581 3. Verify call status. 582 4. Disconnect call. 583 5. Repeat steps 2 to 4 for N iterations 584 585 Returns: 586 True if successful, False otherwise. 587 588 Test Id: Bt_CoEx_Stress_070 589 """ 590 if not self.hfp_long_duration_with_iperf(): 591 return False 592 return True 593 594 def test_stress_hfp_call_multiple_times_with_tcp_bidirectional(self): 595 """Stress test for initiate and disconnect hfp call. 596 597 This test is to start TCP-bidirectional traffic between host machine and 598 android device and test the integrity of hfp call. 599 600 Steps: 601 1. Start TCP-bidirectional traffic. 602 2. Initiate call from HF 603 3. Verify status of call 604 4. Disconnect from AG. 605 5. Repeat steps 2 to 4 for N iterations 606 607 Returns: 608 True if successful, False otherwise. 609 610 Test Id: Bt_CoEx_Stress_071 611 """ 612 if not self.initiate_call_multiple_times_with_iperf(): 613 return False 614 return True 615 616 def test_stress_hfp_call_multiple_times_with_udp_bidirectional(self): 617 """Stress test for initiate and disconnect hfp call. 618 619 This test is to start UDP-bidirectional traffic between host machine and 620 android device and test the integrity of hfp call. 621 622 Steps: 623 1. Start UDP-bidirectional traffic. 624 2. Initiate call from HF 625 3. Verify status of call 626 4. Disconnect from AG. 627 5. Repeat steps 2 to 4 for N iterations 628 629 Returns: 630 True if successful, False otherwise. 631 632 Test Id: Bt_CoEx_Stress_072 633 """ 634 if not self.initiate_call_multiple_times_with_iperf(): 635 return False 636 return True 637