• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2018 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of 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,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import time
18import pprint
19
20from acts import asserts
21from acts import signals
22from acts import utils
23from acts.test_decorators import test_tracker_info
24from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
25from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
26from WifiStaApConcurrencyTest import WifiStaApConcurrencyTest
27import acts.test_utils.wifi.wifi_test_utils as wutils
28
29WifiEnums = wutils.WifiEnums
30
31# Channels to configure the AP for various test scenarios.
32WIFI_NETWORK_AP_CHANNEL_2G = 1
33WIFI_NETWORK_AP_CHANNEL_5G = 36
34WIFI_NETWORK_AP_CHANNEL_5G_DFS = 132
35
36class WifiStaApConcurrencyStressTest(WifiStaApConcurrencyTest):
37    """Stress tests for STA + AP concurrency scenarios.
38
39    Test Bed Requirement:
40    * At least two Android devices (For AP)
41    * One Wi-Fi network visible to the device (for STA).
42    """
43
44    def __init__(self, controllers):
45        WifiStaApConcurrencyTest.__init__(self, controllers)
46        self.tests = ("test_stress_wifi_connection_2G_softap_2G",
47                      "test_stress_wifi_connection_5G_softap_5G",
48                      "test_stress_wifi_connection_5G_DFS_softap_5G",
49                      "test_stress_wifi_connection_5G_softap_2G",
50                      "test_stress_wifi_connection_5G_DFS_softap_2G",
51                      "test_stress_wifi_connection_2G_softap_5G",
52                      "test_stress_wifi_connection_5G_softap_2G_with_location_scan_on",
53                      "test_stress_softap_2G_wifi_connection_2G",
54                      "test_stress_softap_5G_wifi_connection_5G",
55                      "test_stress_softap_5G_wifi_connection_5G_DFS",
56                      "test_stress_softap_5G_wifi_connection_2G",
57                      "test_stress_softap_2G_wifi_connection_5G",
58                      "test_stress_softap_2G_wifi_connection_5G_DFS",
59                      "test_stress_softap_5G_wifi_connection_2G_with_location_scan_on")
60
61    def setup_class(self):
62        self.dut = self.android_devices[0]
63        self.dut_client = self.android_devices[1]
64        wutils.wifi_test_device_init(self.dut)
65        wutils.wifi_test_device_init(self.dut_client)
66        # Do a simple version of init - mainly just sync the time and enable
67        # verbose logging.  This test will fail if the DUT has a sim and cell
68        # data is disabled.  We would also like to test with phones in less
69        # constrained states (or add variations where we specifically
70        # constrain).
71        utils.require_sl4a((self.dut, self.dut_client))
72        utils.sync_device_time(self.dut)
73        utils.sync_device_time(self.dut_client)
74        # Set country code explicitly to "US".
75        self.dut.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
76        self.dut_client.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
77        # Enable verbose logging on the duts
78        self.dut.droid.wifiEnableVerboseLogging(1)
79        asserts.assert_equal(self.dut.droid.wifiGetVerboseLoggingLevel(), 1,
80            "Failed to enable WiFi verbose logging on the softap dut.")
81        self.dut_client.droid.wifiEnableVerboseLogging(1)
82        asserts.assert_equal(self.dut_client.droid.wifiGetVerboseLoggingLevel(), 1,
83            "Failed to enable WiFi verbose logging on the client dut.")
84
85        req_params = ["AccessPoint", "dbs_supported_models", "stress_count"]
86        opt_param = ["iperf_server_address"]
87        self.unpack_userparams(
88            req_param_names=req_params, opt_param_names=opt_param)
89
90        if self.dut.model not in self.dbs_supported_models:
91            asserts.skip(
92                ("Device %s does not support dual interfaces.")
93                % self.dut.model)
94
95        if "iperf_server_address" in self.user_params:
96            self.iperf_server = self.iperf_servers[0]
97        if hasattr(self, 'iperf_server'):
98            self.iperf_server.start()
99
100        # Set the client wifi state to on before the test begins.
101        wutils.wifi_toggle_state(self.dut_client, True)
102
103        # Init extra devices
104        if len(self.android_devices) > 2:
105            wutils.wifi_test_device_init(self.android_devices[2])
106            utils.sync_device_time(self.android_devices[2])
107            self.android_devices[2].droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
108            self.android_devices[2].droid.wifiEnableVerboseLogging(1)
109            asserts.assert_equal(self.android_devices[2].droid.wifiGetVerboseLoggingLevel(), 1,
110                "Failed to enable WiFi verbose logging on the client dut.")
111
112    """Helper Functions"""
113    def verify_wifi_full_on_off(self, network, softap_config):
114        wutils.wifi_toggle_state(self.dut, True)
115        self.connect_to_wifi_network_and_verify((network, self.dut))
116        self.run_iperf_client((network, self.dut))
117        self.run_iperf_client((softap_config, self.dut_client))
118        if len(self.android_devices) > 2:
119            self.log.info("Testbed has extra android devices, do more validation")
120            self.verify_traffic_between_ap_clients(
121                    self.dut, self.android_devices[2])
122        wutils.wifi_toggle_state(self.dut, False)
123
124    def verify_softap_full_on_off(self, network, softap_band):
125        softap_config = self.start_softap_and_verify(softap_band)
126        self.run_iperf_client((network, self.dut))
127        self.run_iperf_client((softap_config, self.dut_client))
128        if len(self.android_devices) > 2:
129            self.log.info("Testbed has extra android devices, do more validation")
130            self.verify_traffic_between_softap_clients(
131                    self.dut_client, self.android_devices[2])
132        wutils.reset_wifi(self.dut_client)
133        if len(self.android_devices) > 2:
134            wutils.reset_wifi(self.android_devices[2])
135        wutils.stop_wifi_tethering(self.dut)
136
137    """Tests"""
138    @test_tracker_info(uuid="615997cc-8290-4af3-b3ac-1f5bd5af6ed1")
139    def test_stress_wifi_connection_2G_softap_2G(self):
140        """Tests connection to 2G network the enable/disable SoftAp on 2G N times.
141        """
142        self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
143        wutils.wifi_toggle_state(self.dut, True)
144        self.connect_to_wifi_network_and_verify((self.wpapsk_2g, self.dut))
145        for count in range(self.stress_count):
146            self.log.info("Iteration %d", count+1)
147            self.verify_softap_full_on_off(self.wpapsk_2g, WIFI_CONFIG_APBAND_2G)
148        raise signals.TestPass(details="", extras={"Iterations":"%d" %
149            self.stress_count, "Pass":"%d" %(count+1)})
150
151    @test_tracker_info(uuid="03362d54-a624-4fb8-ad97-7abb9e6f655c")
152    def test_stress_wifi_connection_5G_softap_5G(self):
153        """Tests connection to 5G network followed by bringing up SoftAp on 5G.
154        """
155        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G)
156        wutils.wifi_toggle_state(self.dut, True)
157        self.connect_to_wifi_network_and_verify((self.wpapsk_5g, self.dut))
158        for count in range(self.stress_count):
159            self.log.info("Iteration %d", count+1)
160            self.verify_softap_full_on_off(self.wpapsk_5g, WIFI_CONFIG_APBAND_5G)
161        raise signals.TestPass(details="", extras={"Iterations":"%d" %
162            self.stress_count, "Pass":"%d" %(count+1)})
163
164    @test_tracker_info(uuid="fdda4ff2-38d5-4398-9a59-c7cee407a2b3")
165    def test_stress_wifi_connection_5G_DFS_softap_5G(self):
166        """Tests connection to 5G DFS network followed by bringing up SoftAp on 5G.
167        """
168        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS)
169        wutils.wifi_toggle_state(self.dut, True)
170        self.connect_to_wifi_network_and_verify((self.wpapsk_5g, self.dut))
171        for count in range(self.stress_count):
172            self.log.info("Iteration %d", count+1)
173            self.verify_softap_full_on_off(self.wpapsk_5g, WIFI_CONFIG_APBAND_5G)
174        raise signals.TestPass(details="", extras={"Iterations":"%d" %
175            self.stress_count, "Pass":"%d" %(count+1)})
176
177    @test_tracker_info(uuid="b3621721-7714-43eb-8438-b578164b9194")
178    def test_stress_wifi_connection_5G_softap_2G(self):
179        """Tests connection to 5G network followed by bringing up SoftAp on 2G.
180        """
181        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G)
182        wutils.wifi_toggle_state(self.dut, True)
183        self.connect_to_wifi_network_and_verify((self.wpapsk_5g, self.dut))
184        for count in range(self.stress_count):
185            self.log.info("Iteration %d", count+1)
186            self.verify_softap_full_on_off(self.wpapsk_5g, WIFI_CONFIG_APBAND_2G)
187        raise signals.TestPass(details="", extras={"Iterations":"%d" %
188            self.stress_count, "Pass":"%d" %(count+1)})
189
190    @test_tracker_info(uuid="bde1443f-f912-408e-b01a-537548dd023c")
191    def test_stress_wifi_connection_5G_DFS_softap_2G(self):
192        """Tests connection to 5G DFS network followed by bringing up SoftAp on 2G.
193        """
194        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS)
195        wutils.wifi_toggle_state(self.dut, True)
196        self.connect_to_wifi_network_and_verify((self.wpapsk_5g, self.dut))
197        for count in range(self.stress_count):
198            self.verify_softap_full_on_off(self.wpapsk_5g, WIFI_CONFIG_APBAND_2G)
199        raise signals.TestPass(details="", extras={"Iterations":"%d" %
200            self.stress_count, "Pass":"%d" %(count+1)})
201
202    @test_tracker_info(uuid="2b6a891a-e0d6-4660-abf6-579099ce6924")
203    def test_stress_wifi_connection_2G_softap_5G(self):
204        """Tests connection to 2G network followed by bringing up SoftAp on 5G.
205        """
206        self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
207        wutils.wifi_toggle_state(self.dut, True)
208        self.connect_to_wifi_network_and_verify((self.wpapsk_2g, self.dut))
209        for count in range(self.stress_count):
210            self.log.info("Iteration %d", count+1)
211            self.verify_softap_full_on_off(self.wpapsk_2g, WIFI_CONFIG_APBAND_2G)
212        raise signals.TestPass(details="", extras={"Iterations":"%d" %
213            self.stress_count, "Pass":"%d" %(count+1)})
214
215    @test_tracker_info(uuid="f28abf22-9df0-4500-b342-6682ca305e60")
216    def test_stress_wifi_connection_5G_softap_2G_with_location_scan_on(self):
217        """Tests connection to 5G network followed by bringing up SoftAp on 2G
218        with location scans turned on.
219        """
220        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G)
221        self.turn_location_on_and_scan_toggle_on()
222        wutils.wifi_toggle_state(self.dut, True)
223        self.connect_to_wifi_network_and_verify((self.wpapsk_5g, self.dut))
224        for count in range(self.stress_count):
225            self.log.info("Iteration %d", count+1)
226            self.verify_softap_full_on_off(self.wpapsk_5g, WIFI_CONFIG_APBAND_2G)
227        raise signals.TestPass(details="", extras={"Iterations":"%d" %
228            self.stress_count, "Pass":"%d" %(count+1)})
229
230    @test_tracker_info(uuid="0edb1500-6c60-442e-9268-a2ad9ee2b55c")
231    def test_stress_softap_2G_wifi_connection_2G(self):
232        """Tests enable SoftAp on 2G then connection/disconnection to 2G network for N times.
233        """
234        self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
235        softap_config = self.start_softap_and_verify(
236                WIFI_CONFIG_APBAND_2G, check_connectivity=False)
237        for count in range(self.stress_count):
238            self.log.info("Iteration %d", count+1)
239            self.verify_wifi_full_on_off(self.wpapsk_2g, softap_config)
240        raise signals.TestPass(details="", extras={"Iterations":"%d" %
241            self.stress_count, "Pass":"%d" %(count+1)})
242
243    @test_tracker_info(uuid="162a6679-edd5-4daa-9f25-75d79cf4bb4a")
244    def test_stress_softap_5G_wifi_connection_5G(self):
245        """Tests enable SoftAp on 5G then connection/disconnection to 5G network for N times.
246        """
247        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G)
248        softap_config = self.start_softap_and_verify(
249                WIFI_CONFIG_APBAND_5G, check_connectivity=False)
250        for count in range(self.stress_count):
251            self.log.info("Iteration %d", count+1)
252            self.verify_wifi_full_on_off(self.wpapsk_5g, softap_config)
253        raise signals.TestPass(details="", extras={"Iterations":"%d" %
254            self.stress_count, "Pass":"%d" %(count+1)})
255
256    @test_tracker_info(uuid="ee98f2dd-c4f9-4f48-ab59-f577267760d5")
257    def test_stress_softap_5G_wifi_connection_5G_DFS(self):
258        """Tests enable SoftAp on 5G then connection/disconnection to 5G DFS network for N times.
259        """
260        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS)
261        softap_config = self.start_softap_and_verify(
262                WIFI_CONFIG_APBAND_5G, check_connectivity=False)
263        for count in range(self.stress_count):
264            self.log.info("Iteration %d", count+1)
265            self.verify_wifi_full_on_off(self.wpapsk_5g, softap_config)
266        raise signals.TestPass(details="", extras={"Iterations":"%d" %
267            self.stress_count, "Pass":"%d" %(count+1)})
268
269    @test_tracker_info(uuid="b50750b5-d5b9-4687-b9e7-9fb15f54b428")
270    def test_stress_softap_5G_wifi_connection_2G(self):
271        """Tests enable SoftAp on 5G then connection/disconnection to 2G network for N times.
272        """
273        self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
274        softap_config = self.start_softap_and_verify(
275                WIFI_CONFIG_APBAND_5G, check_connectivity=False)
276        for count in range(self.stress_count):
277            self.log.info("Iteration %d", count+1)
278            self.verify_wifi_full_on_off(self.wpapsk_2g, softap_config)
279        raise signals.TestPass(details="", extras={"Iterations":"%d" %
280            self.stress_count, "Pass":"%d" %(count+1)})
281
282    @test_tracker_info(uuid="9a2865db-8e4b-4339-9999-000ce9b6970b")
283    def test_stress_softap_2G_wifi_connection_5G(self):
284        """Tests enable SoftAp on 2G then connection/disconnection to 5G network for N times.
285        """
286        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G)
287        softap_config = self.start_softap_and_verify(
288                WIFI_CONFIG_APBAND_2G, check_connectivity=False)
289        for count in range(self.stress_count):
290            self.log.info("Iteration %d", count+1)
291            self.verify_wifi_full_on_off(self.wpapsk_5g, softap_config)
292        raise signals.TestPass(details="", extras={"Iterations":"%d" %
293            self.stress_count, "Pass":"%d" %(count+1)})
294
295    @test_tracker_info(uuid="add6609d-91d6-4b89-94c5-0ad8b941e3d1")
296    def test_stress_softap_2G_wifi_connection_5G_DFS(self):
297        """Tests enable SoftAp on 2G then connection/disconnection to 5G DFS network for N times.
298        """
299        self.configure_ap(channel_5g=WIFI_NETWORK_AP_CHANNEL_5G_DFS)
300        softap_config = self.start_softap_and_verify(
301                WIFI_CONFIG_APBAND_2G, check_connectivity=False)
302        for count in range(self.stress_count):
303            self.log.info("Iteration %d", count+1)
304            self.verify_wifi_full_on_off(self.wpapsk_5g, softap_config)
305        raise signals.TestPass(details="", extras={"Iterations":"%d" %
306            self.stress_count, "Pass":"%d" %(count+1)})
307
308    @test_tracker_info(uuid="ee42afb6-99d0-4330-933f-d4dd8c3626c6")
309    def test_stress_softap_5G_wifi_connection_2G_with_location_scan_on(self):
310        """Tests enable SoftAp on 5G then connection/disconnection to 2G network for N times
311        with location scans turned on.
312        """
313        self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
314        self.turn_location_on_and_scan_toggle_on()
315        softap_config = self.start_softap_and_verify(
316                WIFI_CONFIG_APBAND_5G, check_connectivity=False)
317        for count in range(self.stress_count):
318            self.log.info("Iteration %d", count+1)
319            self.verify_wifi_full_on_off(self.wpapsk_2g, softap_config)
320        raise signals.TestPass(details="", extras={"Iterations":"%d" %
321            self.stress_count, "Pass":"%d" %(count+1)})
322