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 Basic Stress with Wlan.
18
19Test Setup:
20
21One Android device.
22"""
23import time
24
25from acts.test_utils.coex.CoexBaseTest import CoexBaseTest
26from acts.test_utils.coex.coex_test_utils import toggle_bluetooth
27from acts.test_utils.coex.coex_test_utils import device_discoverable
28
29
30class CoexBasicStressTest(CoexBaseTest):
31
32    def setup_class(self):
33        super().setup_class()
34
35        req_params = ["iterations"]
36        self.unpack_userparams(req_params)
37
38    def start_stop_classic_discovery_with_iperf(self):
39        """Starts and stop bluetooth discovery for 1000 iterations.
40
41        Steps:
42        1. Start Discovery on Primary device.
43        2. Stop Discovery on Secondary device.
44        3. Repeat step 1 and 2.
45
46        Returns:
47            True if successful, False otherwise.
48        """
49        self.run_iperf_and_get_result()
50        for i in range(self.iterations):
51            self.log.info("Discovery iteration {}".format(i))
52            if not self.pri_ad.droid.bluetoothStartDiscovery():
53                self.log.error("Bluetooth discovery failed.")
54                return False
55            time.sleep(2)
56            if not self.pri_ad.droid.bluetoothCancelDiscovery():
57                self.log.error("Bluetooth cancel discovery failed.")
58                return False
59        return self.teardown_result()
60
61    def check_device_discoverability_with_iperf(self):
62        """Checks if primary device is visible from secondary device.
63
64        Steps:
65        1. Start discovery on primary device.
66        2. Discover primary device from Secondary device.
67        3. Repeat step 1 and 2.
68
69        Returns:
70            True if successful, False otherwise.
71        """
72        self.run_iperf_and_get_result()
73        for i in range(self.iterations):
74            self.log.info("Discovery iteration = {}".format(i))
75            if not device_discoverable(self.pri_ad, self.sec_ad):
76                self.log.error("Primary device could not be discovered.")
77                return False
78        return self.teardown_result()
79
80    def toogle_bluetooth_with_iperf(self):
81        """Wrapper function to start iperf traffic and toggling bluetooth."""
82        self.run_iperf_and_get_result()
83        if not toggle_bluetooth(self.pri_ad, self.iperf["duration"]):
84            return False
85        return self.teardown_result()
86
87    def test_stress_toggle_bluetooth_with_tcp_ul(self):
88        """Stress test toggling bluetooth on and off.
89
90        This test is to start TCP-uplink traffic between host machine
91        and android device and test the integrity of toggling bluetooth
92        on and off.
93
94        Steps:
95        1. Starts TCP-uplink traffic.
96        2. Toggle bluetooth state on and off for N iterations.
97
98        Returns:
99            True if successful, False otherwise.
100
101        Test Id: Bt_CoEx_Stress_001
102        """
103        if not self.toogle_bluetooth_with_iperf():
104            return False
105        return True
106
107    def test_stress_toggle_bluetooth_with_tcp_dl(self):
108        """Stress test toggling bluetooth on and off.
109
110        This test is to start TCP-downlink traffic between host machine
111        and android device and test the integrity of toggling bluetooth
112        on and off.
113
114        Steps:
115        1. Starts TCP-downlink traffic.
116        2. Toggle bluetooth state on and off for N iterations.
117
118        Returns:
119            True if successful, False otherwise.
120
121        Test Id: Bt_CoEx_Stress_002
122        """
123        if not self.toogle_bluetooth_with_iperf():
124            return False
125        return True
126
127    def test_stress_toggle_bluetooth_with_udp_ul(self):
128        """Stress test toggling bluetooth on and off.
129
130        This test is to start UDP-uplink traffic between host machine
131        and android device and test the integrity of toggling bluetooth
132        on and off.
133
134        Steps:
135        1. Starts UDP-uplink traffic.
136        2. Toggle bluetooth state on and off for N iterations.
137
138        Returns:
139            True if successful, False otherwise.
140
141        Test Id: Bt_CoEx_Stress_003
142        """
143        if not self.toogle_bluetooth_with_iperf():
144            return False
145        return True
146
147    def test_stress_toggle_bluetooth_with_udp_dl(self):
148        """Stress test toggling bluetooth on and off.
149
150        This test is to start UDP-downlink traffic between host machine
151        and android device and test the integrity of toggling bluetooth
152        on and off.
153
154        Steps:
155        1. Starts UDP-downlink traffic.
156        2. Toggle bluetooth state on and off for N iterations.
157
158        Returns:
159            True if successful, False otherwise.
160
161        Test Id: Bt_CoEx_Stress_004
162        """
163        if not self.toogle_bluetooth_with_iperf():
164            return False
165        return True
166
167    def test_stress_bluetooth_discovery_with_tcp_ul(self):
168        """Stress test on bluetooth discovery.
169
170        This test is to start TCP-uplink traffic between host machine
171        and android device and test the integrity of start and stop discovery.
172
173        Steps:
174        1. Starts TCP-uplink traffic.
175        2. Performs start and stop discovery in quick succession.
176
177        Returns:
178            True if successful, False otherwise.
179
180        Test Id: Bt_CoEx_Stress_005
181        """
182        if not self.start_stop_classic_discovery_with_iperf():
183            return False
184        return True
185
186    def test_stress_bluetooth_discovery_with_tcp_dl(self):
187        """Stress test on bluetooth discovery.
188
189        This test is to start TCP-downlink traffic between host machine
190        and android device and test the integrity of start and stop discovery.
191
192        Steps:
193        1. Starts TCP-downlink traffic.
194        2. Performs start and stop discovery in quick succession.
195
196        Returns:
197            True if successful, False otherwise.
198
199        Test Id: Bt_CoEx_Stress_006
200        """
201        if not self.start_stop_classic_discovery_with_iperf():
202            return False
203        return True
204
205    def test_stress_bluetooth_discovery_with_udp_ul(self):
206        """Stress test on bluetooth discovery.
207
208        This test is to start UDP-uplink traffic between host machine
209        and android device and test the integrity of start and stop discovery.
210
211        Steps:
212        1. Starts UDP-uplink traffic.
213        2. Performs start and stop discovery in quick succession.
214
215        Returns:
216            True if successful, False otherwise.
217
218        Test Id: Bt_CoEx_Stress_007
219        """
220        if not self.start_stop_classic_discovery_with_iperf():
221            return False
222        return True
223
224    def test_stress_bluetooth_discovery_with_udp_dl(self):
225        """Stress test on bluetooth discovery.
226
227        This test is to start UDP-downlink traffic between host machine
228        and android device and test the integrity of start and stop discovery.
229
230        Steps:
231        1. Starts UDP-downlink traffic.
232        2. Performs start and stop discovery in quick succession.
233
234        Returns:
235            True if successful, False otherwise.
236
237        Test Id: Bt_CoEx_Stress_008
238        """
239        if not self.start_stop_classic_discovery_with_iperf():
240            return False
241        return True
242
243    def test_stress_primary_device_visibility_with_tcp_ul(self):
244        """Stress test on device visibility from secondary device.
245
246        This test is to start TCP-uplink traffic between host machine
247        and android device and stress test on device discoverability from
248        secondary device
249
250        Steps:
251        1. Start TCP-uplink traffic.
252        2. Make primary device visible.
253        3. Check if primary device name is visible from secondary device.
254        4. Repeat step 2 and 3 for n iterations
255
256        Returns:
257            True if successful, False otherwise.
258
259        Test Id: Bt_CoEx_Stress_009
260        """
261        if not self.check_device_discoverability_with_iperf():
262            return False
263        return True
264
265    def test_stress_primary_device_visibility_with_tcp_dl(self):
266        """Stress test on device visibility from secondary device.
267
268        This test is to start TCP-downlink traffic between host machine
269        and android device and stress test on device discoverability from
270        secondary device
271
272        Steps:
273        1. Start TCP-downlink traffic.
274        2. Make primary device visible.
275        3. Check if primary device name is visible from secondary device.
276        4. Repeat step 2 and 3 for n iterations
277
278        Returns:
279            True if successful, False otherwise.
280
281        Test Id: Bt_CoEx_Stress_010
282        """
283        if not self.check_device_discoverability_with_iperf():
284            return False
285        return True
286
287    def test_stress_primary_device_visibility_with_udp_ul(self):
288        """Stress test on device visibility from secondary device.
289
290        This test is to start UDP-uplink traffic between host machine
291        and android device and stress test on device discoverability from
292        secondary device
293
294        Steps:
295        1. Start UDP-uplink traffic.
296        2. Make primary device visible.
297        3. Check if primary device name is visible from secondary device.
298        4. Repeat step 2 and 3 for n iterations
299
300        Returns:
301            True if successful, False otherwise.
302
303        Test Id: Bt_CoEx_Stress_011
304        """
305        if not self.check_device_discoverability_with_iperf():
306            return False
307        return True
308
309    def test_stress_primary_device_visibility_with_udp_dl(self):
310        """Stress test on device visibility from secondary device.
311
312        This test is to start UDP-downlink traffic between host machine
313        and android device and stress test on device discoverability from
314        secondary device
315
316        Steps:
317        1. Start UDP-downlink traffic.
318        2. Make primary device visible.
319        3. Check if primary device name is visible from secondary device.
320        4. Repeat step 2 and 3 for n iterations
321
322        Returns:
323            True if successful, False otherwise.
324
325        Test Id: Bt_CoEx_Stress_012
326        """
327        if not self.check_device_discoverability_with_iperf():
328            return False
329        return True
330
331    def test_stress_toggle_bluetooth_with_tcp_bidirectional(self):
332        """Stress test toggling bluetooth on and off.
333
334        This test is to start TCP-bidirectional traffic between host machine
335        and android device and test the integrity of toggling bluetooth
336        on and off.
337
338        Steps:
339        1. Starts TCP-bidirectional traffic.
340        2. Toggle bluetooth state on and off for N iterations.
341
342        Returns:
343            True if successful, False otherwise.
344
345        Test Id: Bt_CoEx_Stress_051
346        """
347        if not self.toogle_bluetooth_with_iperf():
348            return False
349        return True
350
351    def test_stress_toggle_bluetooth_with_udp_bidirectional(self):
352        """Stress test toggling bluetooth on and off.
353
354        This test is to start UDP-bidirectional traffic between host machine
355        and android device and test the integrity of toggling bluetooth
356        on and off.
357
358        Steps:
359        1. Starts TCP-bidirectional traffic.
360        2. Toggle bluetooth state on and off for N iterations.
361
362        Returns:
363            True if successful, False otherwise.
364
365        Test Id: Bt_CoEx_Stress_052
366        """
367        if not self.toogle_bluetooth_with_iperf():
368            return False
369        return True
370
371    def test_stress_bluetooth_discovery_with_tcp_bidirectional(self):
372        """Stress test on bluetooth discovery.
373
374        This test is to start TCP-bidirectional traffic between host machine
375        and android device and test the integrity of start and stop discovery.
376
377        Steps:
378        1. Starts TCP-bidirectional traffic.
379        2. Performs start and stop discovery in quick succession.
380
381        Returns:
382            True if successful, False otherwise.
383
384        Test Id: Bt_CoEx_Stress_053
385        """
386        if not self.start_stop_classic_discovery_with_iperf():
387            return False
388        return True
389
390    def test_stress_bluetooth_discovery_with_udp_bidirectional(self):
391        """Stress test on bluetooth discovery.
392
393        This test is to start UDP-bidirectional traffic between host machine
394        and android device and test the integrity of start and stop discovery.
395
396        Steps:
397        1. Start wlan traffic with UDP-bidirectional.
398        2. Start bluetooth discovery for N iterations.
399
400        Returns:
401            True if successful, False otherwise.
402
403        Test Id: Bt_CoEx_Stress_054
404        """
405        if not self.start_stop_classic_discovery_with_iperf():
406            return False
407        return True
408
409    def test_stress_primary_device_visiblity_tcp_bidirectional(self):
410        """Stress test on device visibility from secondary device.
411
412        This test is to start TCP-bidirectional traffic between host machine
413        and android device and stress test on device discoverability from
414        secondary device
415
416        Steps:
417        1. Start TCP-bidirectional traffic.
418        2. Make primary device visible.
419        3. Check if primary device name is visible from secondary device.
420        4. Repeat step 2 and 3 for n iterations
421
422        Returns:
423            True if successful, False otherwise.
424
425        Test Id: Bt_CoEx_Stress_055
426        """
427        if not self.check_device_discoverability_with_iperf():
428            return False
429        return True
430
431    def test_stress_primary_device_visiblity_udp_bidirectional(self):
432        """Stress test on device visibility from secondary device.
433
434        This test is to start UDP-bidirectional traffic between host machine
435        and android device and stress test on device discoverability from
436        secondary device
437
438        Steps:
439        1. Start UDP-bidirectional traffic.
440        2. Make primary device visible.
441        3. Check if primary device name is visible from secondary device.
442        4. Repeat step 2 and 3 for n iterations.
443
444        Returns:
445            True if successful, False otherwise.
446
447        Test Id: Bt_CoEx_Stress_056
448        """
449        if not self.check_device_discoverability_with_iperf():
450            return False
451        return True
452