• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2021 - Google
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"""
17    Test Script for 5G SA Data scenarios
18"""
19
20import time
21
22from acts.test_decorators import test_tracker_info
23from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
24from acts_contrib.test_utils.tel.tel_defines import GEN_5G
25from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_USER_PLANE_DATA
26from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_NR_ONLY
27from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
28from acts_contrib.test_utils.tel.tel_test_utils import break_internet_except_sl4a_port
29from acts_contrib.test_utils.tel.tel_test_utils import check_data_stall_detection
30from acts_contrib.test_utils.tel.tel_test_utils import check_data_stall_recovery
31from acts_contrib.test_utils.tel.tel_test_utils import check_network_validation_fail
32from acts_contrib.test_utils.tel.tel_test_utils import get_current_override_network_type
33from acts_contrib.test_utils.tel.tel_test_utils import get_device_epoch_time
34from acts_contrib.test_utils.tel.tel_test_utils import resume_internet_with_sl4a_port
35from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_network_mode_pref
36from acts_contrib.test_utils.tel.tel_test_utils import test_data_browsing_failure_using_sl4a
37from acts_contrib.test_utils.tel.tel_test_utils import test_data_browsing_success_using_sl4a
38from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
39from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
40from acts_contrib.test_utils.tel.tel_test_utils import wifi_reset
41from acts_contrib.test_utils.tel.tel_test_utils import wifi_toggle_state
42from acts_contrib.test_utils.tel.tel_data_utils import browsing_test
43from acts_contrib.test_utils.tel.tel_data_utils import data_connectivity_single_bearer
44from acts_contrib.test_utils.tel.tel_data_utils import test_wifi_connect_disconnect
45from acts_contrib.test_utils.tel.tel_data_utils import wifi_cell_switching
46from acts_contrib.test_utils.tel.tel_5g_utils import is_current_network_5g_sa
47from acts_contrib.test_utils.tel.tel_5g_test_utils import provision_device_for_5g
48
49
50class Sa5gDataTest(TelephonyBaseTest):
51    def setup_class(self):
52        super().setup_class()
53
54    def setup_test(self):
55        TelephonyBaseTest.setup_test(self)
56        self.provider = self.android_devices[0]
57        self.clients = self.android_devices[1:]
58
59    def teardown_class(self):
60        TelephonyBaseTest.teardown_class(self)
61
62
63    """ Tests Begin """
64
65    @test_tracker_info(uuid="2bb5fa22-d931-426f-a11d-22f514d867d0")
66    @TelephonyBaseTest.tel_test_wrap
67    def test_5g_sa_data_browsing(self):
68        """ Verifying connectivity of internet and  browsing websites on 5G SA network.
69
70        Ensure
71            1. ping to IP of websites is successful.
72            2. http ping to IP of websites is successful.
73            3. browsing websites is successful.
74        Returns:
75            True if pass; False if fail.
76        """
77        ad = self.android_devices[0]
78        wifi_toggle_state(ad.log, ad, False)
79        sub_id = ad.droid.subscriptionGetDefaultSubId()
80        if not set_preferred_network_mode_pref(ad.log, ad, sub_id,
81                                               NETWORK_MODE_NR_ONLY):
82            ad.log.error("Failed to set network mode to SA")
83            return False
84        ad.log.info("Set network mode to SA successfully")
85        ad.log.info("Waiting for 5g SA attach for 60 secs")
86        if is_current_network_5g_sa(ad):
87            ad.log.info("Success! attached on 5g SA")
88        else:
89            ad.log.error("Failure - expected NR, current %s",
90                         get_current_override_network_type(ad))
91            return False
92        for iteration in range(3):
93            connectivity = False
94            browsing = False
95            ad.log.info("Attempt %d", iteration + 1)
96            if not verify_internet_connection(self.log, ad):
97                ad.log.error("Failed to connect to internet!")
98            else:
99                ad.log.info("Connect to internet successfully!")
100                connectivity = True
101            if not browsing_test(ad.log, ad):
102                ad.log.error("Failed to browse websites!")
103            else:
104                ad.log.info("Successful to browse websites!")
105                browsing = True
106            if connectivity and browsing:
107                return True
108            time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
109        ad.log.error("5G SA Connectivity and Data Browsing test FAIL for all 3 iterations")
110        return False
111
112
113    @test_tracker_info(uuid="785b0ef8-b326-42f8-a399-51ebc1f9e93e")
114    @TelephonyBaseTest.tel_test_wrap
115    def test_5g_sa_data_stall_recovery(self):
116        """ Verifies 5G SA data stall
117
118        Set Mode to 5G
119        Wait for 5G attached on SA
120        Browse websites for success
121        Trigger data stall and verify browsing fails
122        Resume data and verify browsing success
123
124        Returns:
125            True if pass; False if fail.
126        """
127        ad = self.android_devices[0]
128        result = True
129        wifi_toggle_state(ad.log, ad, False)
130        toggle_airplane_mode(ad.log, ad, False)
131
132        if not provision_device_for_5g(ad.log, ad, sa_5g=True):
133            return False
134
135        cmd = ('ss -l -p -n | grep "tcp.*droid_script" | tr -s " " '
136               '| cut -d " " -f 5 | sed s/.*://g')
137        sl4a_port = ad.adb.shell(cmd)
138
139        if not test_data_browsing_success_using_sl4a(ad.log, ad):
140            ad.log.error("Browsing failed before the test, aborting!")
141            return False
142
143        begin_time = get_device_epoch_time(ad)
144        break_internet_except_sl4a_port(ad, sl4a_port)
145
146        if not test_data_browsing_failure_using_sl4a(ad.log, ad):
147            ad.log.error("Browsing after breaking the internet, aborting!")
148            result = False
149
150        if not check_data_stall_detection(ad):
151            ad.log.warning("NetworkMonitor unable to detect Data Stall")
152
153        if not check_network_validation_fail(ad, begin_time):
154            ad.log.warning("Unable to detect NW validation fail")
155
156        if not check_data_stall_recovery(ad, begin_time):
157            ad.log.error("Recovery was not triggered")
158            result = False
159
160        resume_internet_with_sl4a_port(ad, sl4a_port)
161        time.sleep(MAX_WAIT_TIME_USER_PLANE_DATA)
162        if not test_data_browsing_success_using_sl4a(ad.log, ad):
163            ad.log.error("Browsing failed after resuming internet")
164            result = False
165        if result:
166            ad.log.info("PASS - data stall over 5G SA")
167        else:
168            ad.log.error("FAIL - data stall over 5G SA")
169        return result
170
171
172    @test_tracker_info(uuid="6c0ef257-6381-4c1d-8b8e-0371db7e08ac")
173    @TelephonyBaseTest.tel_test_wrap
174    def test_5g_sa_wifi_connect_disconnect(self):
175        """Perform multiple connects and disconnects from WiFi and verify that
176            data switches between WiFi and Cell.
177
178        Steps:
179        1. DUT Cellular Data is on sa 5G. Reset Wifi on DUT
180        2. Connect DUT to a WiFi AP
181        3. Repeat steps 1-2, alternately disconnecting and disabling wifi
182
183        Expected Results:
184        1. Verify Data on Cell
185        2. Verify Data on Wifi
186
187        Returns:
188            True if success.
189            False if failed.
190        """
191        if not provision_device_for_5g(self.log, self.provider, sa_5g=True):
192            return False
193
194        return test_wifi_connect_disconnect(self.log, self.provider, self.wifi_network_ssid, self.wifi_network_pass)
195
196
197    @test_tracker_info(uuid="f70ad253-4b77-4d9b-b7dc-d7cd3e945e5f")
198    @TelephonyBaseTest.tel_test_wrap
199    def test_5g_sa_wifi_switching(self):
200        """Test data connection network switching when phone camped on sa 5G.
201
202        Ensure phone is camped on sa 5G
203        Ensure WiFi can connect to live network,
204        Airplane mode is off, data connection is on, WiFi is on.
205        Turn off WiFi, verify data is on cell and browse to google.com is OK.
206        Turn on WiFi, verify data is on WiFi and browse to google.com is OK.
207        Turn off WiFi, verify data is on cell and browse to google.com is OK.
208
209        Returns:
210            True if pass.
211        """
212        ad = self.android_devices[0]
213        return wifi_cell_switching(ad.log, ad, GEN_5G, self.wifi_network_ssid,
214                                   self.wifi_network_pass, sa_5g=True)
215
216
217    @test_tracker_info(uuid="8df1b65c-197e-40b3-83a4-6da1f0a51b97")
218    @TelephonyBaseTest.tel_test_wrap
219    def test_5g_sa_wifi_not_associated(self):
220        """Test data connection in sa 5g.
221
222        Turn off airplane mode, enable WiFi (but not connected), enable Cellular Data.
223        Ensure phone data generation is sa 5g.
224        Verify Internet.
225        Disable Cellular Data, verify Internet is inaccessible.
226        Enable Cellular Data, verify Internet.
227
228        Returns:
229            True if success.
230            False if failed.
231        """
232        ad = self.android_devices[0]
233        wifi_reset(ad.log, ad)
234        wifi_toggle_state(ad.log, ad, False)
235        wifi_toggle_state(ad.log, ad, True)
236        return data_connectivity_single_bearer(ad.log, ad, GEN_5G, sa_5g=True)
237
238    """ Tests End """
239