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