• 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
17
18from acts.controllers.buds_lib.apollo_utils import get_serial_object
19from acts.test_utils.bt import BtEnum
20from acts.test_utils.bt.bt_test_utils import clear_bonded_devices
21from acts.test_utils.coex.audio_test_utils import SshAudioCapture
22from acts.test_utils.coex.CoexBaseTest import CoexBaseTest
23from acts.test_utils.coex.coex_test_utils import connect_disconnect_a2dp_headset
24from acts.test_utils.coex.coex_test_utils import connect_disconnect_headset
25from acts.test_utils.coex.coex_test_utils import multithread_func
26from acts.test_utils.coex.coex_test_utils import music_play_and_check
27from acts.test_utils.coex.coex_test_utils import pair_and_connect_headset
28from acts.test_utils.coex.coex_test_utils import push_music_to_android_device
29
30
31class ApolloWithA2dpStressTest(CoexBaseTest):
32
33    def setup_class(self):
34        super().setup_class()
35        req_params = ["serial_device", "iterations", "audio_params"]
36        self.unpack_userparams(req_params)
37        self.buds_device = get_serial_object(self.pri_ad, self.serial_device)
38        self.headset_mac_address = self.buds_device.bluetooth_address
39        self.music_file_to_play = push_music_to_android_device(
40            self.pri_ad, self.audio_params)
41
42    def setup_test(self):
43        super().setup_test()
44        if "a2dp_streaming" in self.current_test_name:
45            self.audio = SshAudioCapture(self.audio_params, self.log_path)
46        self.buds_device.send("ResetPair\n")
47        self.buds_device.set_pairing_mode()
48        if not pair_and_connect_headset(
49                self.pri_ad, self.headset_mac_address,
50                set([BtEnum.BluetoothProfile.A2DP.value])):
51            self.log.error("Failed to pair and connect to headset")
52            return False
53        self.buds_device.set_stay_connected(1)
54
55    def teardown_test(self):
56        if "a2dp_streaming" in self.current_test_name:
57            analysis_path = self.audio.audio_quality_analysis(self.log_path)
58            if analysis_path:
59                with open(analysis_path) as f:
60                    self.result['audio_artifacts'] = f.readline()
61            self.audio.terminate_and_store_audio_results()
62        clear_bonded_devices(self.pri_ad)
63        super().teardown_test()
64
65    def connect_disconnect_headset_with_iperf(self):
66        """Wrapper function to start iperf traffic and connect/disconnect
67        to headset for N iterations.
68        """
69        self.run_iperf_and_get_result()
70        if not connect_disconnect_headset(self.pri_ad,
71                        self.headset_mac_address, iterations=self.iterations):
72            return False
73        return self.teardown_result()
74
75    def connect_disconnect_a2dp_headset_with_iperf(self):
76        """Wrapper function to start iperf traffic and connect/disconnect
77        to headset for N iterations.
78        """
79        self.run_iperf_and_get_result()
80        if not connect_disconnect_a2dp_headset(self.pri_ad,
81                        self.headset_mac_address, iterations=self.iterations):
82            return False
83        return self.teardown_result()
84
85    def music_streaming_with_iperf(self):
86        """Wrapper function to start iperf traffic and music streaming."""
87        tasks = [(self.audio.capture_audio, ()),
88                 (music_play_and_check, (self.pri_ad,
89                                         self.headset_mac_address,
90                                         self.music_file_to_play,
91                                         self.audio_params[
92                                             'music_play_time'])),
93                (self.run_iperf_and_get_result, ())]
94        if not multithread_func(self.log, tasks):
95            return False
96        return self.teardown_result()
97
98    def test_stress_connect_disconnect_headset_with_tcp_ul(self):
99        """Stress test for connect/disconnect headset.
100
101        This test is to start TCP-uplink traffic between host machine and
102        android device and test the integrity of connection and disconnection
103        to headset.
104
105        Steps:
106        1. Run TCP-uplink traffic.
107        2. Connect and disconnect headset.
108        3. Repeat step 2 for N iterations.
109
110        Returns:
111            True if successful, False otherwise.
112        """
113        return self.connect_disconnect_headset_with_iperf()
114
115    def test_stress_connect_disconnect_headset_with_tcp_dl(self):
116        """Stress test for connect/disconnect headset.
117
118        This test is to start TCP-downlink traffic between host machine and
119        android device and test the integrity of connection and disconnection
120        to headset.
121
122        Steps:
123        1. Run TCP-downlink traffic.
124        2. Connect and disconnect headset.
125        3. Repeat step 2 for N iterations.
126
127        Returns:
128            True if successful, False otherwise.
129        """
130        return self.connect_disconnect_headset_with_iperf()
131
132    def test_stress_connect_disconnect_headset_with_udp_ul(self):
133        """Stress test for connect/disconnect headset.
134
135        This test is to start UDP-uplink traffic between host machine and
136        android device and test the integrity of connection and disconnection
137        to headset.
138
139        Steps:
140        1. Run UDP-uplink traffic.
141        2. Connect and disconnect headset.
142        3. Repeat step 2 for N iterations.
143
144        Returns:
145            True if successful, False otherwise.
146        """
147        return self.connect_disconnect_headset_with_iperf()
148
149    def test_stress_connect_disconnect_headset_with_udp_dl(self):
150        """Stress test for connect/disconnect headset.
151
152        This test is to start UDP-downlink traffic between host machine and
153        android device and test the integrity of connection and disconnection
154        to headset.
155
156        Steps:
157        1. Run UDP-downlink traffic.
158        2. Connect and disconnect headset.
159        3. Repeat step 2 for N iterations.
160
161        Returns:
162            True if successful, False otherwise.
163        """
164        return self.connect_disconnect_headset_with_iperf()
165
166    def test_stress_a2dp_streaming_long_duration_with_tcp_ul(self):
167        """Stress test to stream music to headset continuously for 12 hours.
168
169        This test is to start TCP-uplink traffic between host machine and
170        android device and test the integrity of audio streaming for 12 hours.
171
172        Steps:
173        1. Start TCP uplink traffic.
174        2. Start music streaming to headset.
175
176        Returns:
177            True if successful, False otherwise.
178        """
179        return self.music_streaming_with_iperf()
180
181    def test_stress_a2dp_streaming_long_duration_with_tcp_dl(self):
182        """Stress test to stream music to headset continuously for 12 hours.
183
184        This test is to start TCP-downlink traffic between host machine and
185        android device and test the integrity of audio streaming for 12 hours.
186
187        Steps:
188        1. Start TCP downlink traffic.
189        2. Start music streaming to headset.
190
191        Returns:
192            True if successful, False otherwise.
193        """
194        return self.music_streaming_with_iperf()
195
196    def test_stress_a2dp_streaming_long_duration_with_udp_ul(self):
197        """Stress test to stream music to headset continuously for 12 hours.
198
199        This test is to start UDP-uplink traffic between host machine and
200        android device and test the integrity of audio streaming for 12 hours.
201
202        Steps:
203        1. Start UDP uplink traffic.
204        2. Start music streaming to headset.
205
206        Returns:
207            True if successful, False otherwise.
208        """
209        return self.music_streaming_with_iperf()
210
211    def test_stress_a2dp_streaming_long_duration_with_udp_dl(self):
212        """Stress test to stream music to headset continuously for 12 hours.
213
214        This test is to start UDP-downlink traffic between host machine and
215        android device and test the integrity of audio streaming for 12 hours.
216
217        Steps:
218        1. Start UDP downlink traffic.
219        2. Start music streaming to headset.
220
221        Returns:
222            True if successful, False otherwise.
223        """
224        return self.music_streaming_with_iperf()
225
226    def test_stress_connect_disconnect_a2dp_profile_with_tcp_ul(self):
227        """Stress test for connect/disconnect a2dp headset.
228
229        This test is to start TCP-uplink traffic between host machine and
230        android device and test the integrity of connection and disconnection
231        to headset with a2dp profile.
232
233        Steps:
234        1. Run TCP-uplink traffic.
235        2. Connect and disconnect headset with a2dp profile.
236        3. Repeat step 2 for N iterations.
237
238        Returns:
239            True if successful, False otherwise.
240        """
241        return self.connect_disconnect_a2dp_headset_with_iperf()
242
243    def test_stress_connect_disconnect_a2dp_profile_with_tcp_dl(self):
244        """Stress test for connect/disconnect a2dp headset.
245
246        This test is to start TCP-downlink traffic between host machine and
247        android device and test the integrity of connection and disconnection
248        to headset with a2dp profile.
249
250        Steps:
251        1. Run TCP-downlink traffic.
252        2. Connect and disconnect headset with a2dp profile.
253        3. Repeat step 2 for N iterations.
254
255        Returns:
256            True if successful, False otherwise.
257        """
258        return self.connect_disconnect_a2dp_headset_with_iperf()
259
260    def test_stress_connect_disconnect_a2dp_profile_with_udp_ul(self):
261        """Stress test for connect/disconnect a2dp headset.
262
263        This test is to start UDP-uplink traffic between host machine and
264        android device and test the integrity of connection and disconnection
265        to headset with a2dp profile.
266
267        Steps:
268        1. Run UDP-uplink traffic.
269        2. Connect and disconnect headset with a2dp profile.
270        3. Repeat step 2 for N iterations.
271
272        Returns:
273            True if successful, False otherwise.
274        """
275        return self.connect_disconnect_a2dp_headset_with_iperf()
276
277    def test_stress_connect_disconnect_a2dp_profile_with_udp_dl(self):
278        """Stress test for connect/disconnect a2dp headset.
279
280        This test is to start UDP-downlink traffic between host machine and
281        android device and test the integrity of connection and disconnection
282        to headset with a2dp profile.
283
284        Steps:
285        1. Run UDP-downlink traffic.
286        2. Connect and disconnect headset with a2dp profile.
287        3. Repeat step 2 for N iterations.
288
289        Returns:
290            True if successful, False otherwise.
291        """
292        return self.connect_disconnect_a2dp_headset_with_iperf()
293
294    def test_stress_connect_disconnect_headset_with_tcp_bidirectional(self):
295        """Stress test for connect/disconnect headset.
296
297        This test starts TCP-bidirectional traffic between host machine and
298        android device and test the integrity of connection and disconnection
299        to headset.
300
301        Steps:
302        1. Run TCP-bidirectional traffic.
303        2. Connect and disconnect headset.
304        3. Repeat step 2 for N iterations.
305
306        Returns:
307            True if successful, False otherwise.
308        """
309        return self.connect_disconnect_headset_with_iperf()
310
311    def test_stress_connect_disconnect_headset_with_udp_bidirectional(self):
312        """Stress test for connect/disconnect headset.
313
314        This test starts UDP-bidirectional traffic between host machin and
315        android device and test the integrity of connection and disconnection
316        to headset.
317
318        Steps:
319        1. Run UDP-bidirectional traffic.
320        2. Connect and disconnect headset.
321        3. Repeat step 2 for N iterations.
322
323        Returns:
324            True if successful, False otherwise.
325        """
326        return self.connect_disconnect_headset_with_iperf()
327
328    def test_stress_a2dp_streaming_long_duration_with_tcp_bidirectional(self):
329        """Stress test to stream music to headset continuously for 12 hours.
330
331        This test starts TCP-bidirectional traffic between host machin and
332        android device and test the integrity of audio streaming for 12 hours.
333
334        Steps:
335        1. Start TCP bidirectional traffic.
336        2. Start music streaming to headset.
337
338        Returns:
339            True if successful, False otherwise.
340        """
341        return self.music_streaming_with_iperf()
342
343    def test_stress_a2dp_streaming_long_duration_with_udp_bidirectional(self):
344        """Stress test to stream music to headset continuously for 12 hours.
345
346        This test starts UDP-bidirectional traffic between host machin and
347        android device and test the integrity of audio streaming for 12 hours.
348
349        Steps:
350        1. Start UDP bidirectional traffic.
351        2. Start music streaming to headset.
352
353        Returns:
354            True if successful, False otherwise.
355        """
356        return self.music_streaming_with_iperf()
357