1#!/usr/bin/env python3 2# 3# Copyright 2017 - 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""" 17Sanity tests for voice tests in telephony 18""" 19import time 20 21from acts.test_decorators import test_tracker_info 22from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError 23from acts.controllers.anritsu_lib.md8475a import MD8475A 24from acts.controllers.anritsu_lib.md8475a import BtsServiceState 25from acts.controllers.anritsu_lib.md8475a import BtsPacketRate 26from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 27from acts.test_utils.tel.anritsu_utils import set_system_model_lte_wcdma 28from acts.test_utils.tel.anritsu_utils import set_usim_parameters 29from acts.test_utils.tel.anritsu_utils import set_post_sim_params 30from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA 31from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE 32from acts.test_utils.tel.tel_test_utils import ensure_network_rat 33from acts.test_utils.tel.tel_test_utils import ensure_phones_idle 34from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode 35from acts.test_utils.tel.tel_test_utils import toggle_cell_data_roaming 36from acts.test_utils.tel.tel_test_utils import set_preferred_apn_by_adb 37from acts.test_utils.tel.tel_test_utils import start_qxdm_loggers 38from acts.utils import adb_shell_ping 39 40PING_DURATION = 5 # Number of packets to ping 41PING_TARGET = "192.168.1.2" # Set to Eth0 IP address of MD8475A 42TIME_TO_WAIT_BEFORE_PING = 10 # Time(sec) to wait before ping 43 44 45class TelLabDataRoamingTest(TelephonyBaseTest): 46 def setup_class(self): 47 super().setup_class() 48 self.ad = self.android_devices[0] 49 self.ad.sim_card = getattr(self.ad, "sim_card", None) 50 self.md8475a_ip_address = self.user_params[ 51 "anritsu_md8475a_ip_address"] 52 self.wlan_option = self.user_params.get("anritsu_wlan_option", False) 53 self.md8475_version = self.user_params.get("md8475", "A") 54 if self.ad.sim_card == "VzW12349": 55 set_preferred_apn_by_adb(self.ad, "VZWINTERNET") 56 57 try: 58 self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option, 59 self.md8475_version) 60 except AnritsuError: 61 self.log.error("Error in connecting to Anritsu Simulator") 62 return False 63 return True 64 65 def setup_test(self): 66 if getattr(self, "qxdm_log", True): 67 start_qxdm_loggers(self.log, self.android_devices) 68 ensure_phones_idle(self.log, self.android_devices) 69 toggle_airplane_mode(self.log, self.ad, True) 70 self.ad.adb.shell( 71 "setprop net.lte.ims.volte.provisioned 1", ignore_status=True) 72 return True 73 74 def teardown_test(self): 75 self.log.info("Stopping Simulation") 76 self.anritsu.stop_simulation() 77 toggle_airplane_mode(self.log, self.ad, True) 78 return True 79 80 def teardown_class(self): 81 self.anritsu.disconnect() 82 return True 83 84 def phone_setup_data_roaming(self): 85 return ensure_network_rat( 86 self.log, 87 self.ad, 88 NETWORK_MODE_LTE_GSM_WCDMA, 89 RAT_FAMILY_LTE, 90 toggle_apm_after_setting=True) 91 92 def LTE_WCDMA_data_roaming(self, mcc, mnc, lte_band, wcdma_band): 93 try: 94 [self.bts1, self.bts2] = set_system_model_lte_wcdma( 95 self.anritsu, self.user_params, self.ad.sim_card) 96 set_usim_parameters(self.anritsu, self.ad.sim_card) 97 set_post_sim_params(self.anritsu, self.user_params, 98 self.ad.sim_card) 99 self.bts1.mcc = mcc 100 self.bts1.mnc = mnc 101 self.bts2.mcc = mcc 102 self.bts2.mnc = mnc 103 self.bts1.band = lte_band 104 self.bts2.band = wcdma_band 105 self.bts2.packet_rate = BtsPacketRate.WCDMA_DLHSAUTO_REL8_ULHSAUTO 106 self.anritsu.start_simulation() 107 self.bts2.service_state = BtsServiceState.SERVICE_STATE_OUT 108 self.log.info("Toggle Mobile Data On") 109 self.ad.droid.telephonyToggleDataConnection(True) 110 111 if not self.phone_setup_data_roaming(): 112 self.log.warning("phone_setup_func failed. Rebooting UE") 113 self.ad.reboot() 114 time.sleep(30) 115 if self.ad.sim_card == "VzW12349": 116 set_preferred_apn_by_adb(self.ad, "VZWINTERNET") 117 if not self.phone_setup_data_roaming(): 118 self.log.error( 119 "Failed to set rat family {}, preferred network:{}". 120 format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA)) 121 return False 122 123 toggle_cell_data_roaming(self.ad, True) 124 self.anritsu.wait_for_registration_state(1) # for BTS1 LTE 125 126 time.sleep(TIME_TO_WAIT_BEFORE_PING) 127 for i in range(3): 128 self.ad.log.info("Verify internet connection - attempt %d", 129 i + 1) 130 result = adb_shell_ping(self.ad, PING_DURATION, PING_TARGET) 131 if result: 132 self.ad.log.info("PING SUCCESS") 133 break 134 elif i == 2: 135 self.log.error( 136 "Test Fail: Phone {} can not ping {} with Data Roaming On" 137 .format(self.ad.serial, PING_TARGET)) 138 return False 139 140 toggle_cell_data_roaming(self.ad, False) 141 time.sleep(TIME_TO_WAIT_BEFORE_PING) 142 if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): 143 self.log.error( 144 "Test Fail: Phone {} can ping {} with Data Roaming Off" 145 .format(self.ad.serial, PING_TARGET)) 146 return False 147 148 toggle_airplane_mode(self.log, self.ad, True) 149 time.sleep(2) 150 self.bts2.service_state = BtsServiceState.SERVICE_STATE_IN 151 self.bts1.service_state = BtsServiceState.SERVICE_STATE_OUT 152 153 toggle_airplane_mode(self.log, self.ad, False) 154 toggle_cell_data_roaming(self.ad, True) 155 self.anritsu.wait_for_registration_state(2) # for BTS2 WCDMA 156 157 time.sleep(TIME_TO_WAIT_BEFORE_PING) 158 for i in range(3): 159 self.ad.log.info("Verify internet connection - attempt %d", 160 i + 1) 161 result = adb_shell_ping(self.ad, PING_DURATION, PING_TARGET) 162 if result: 163 self.ad.log.info("PING SUCCESS") 164 break 165 elif i == 2: 166 self.log.error( 167 "Test Fail: Phone {} can not ping {} with Data Roaming On" 168 .format(self.ad.serial, PING_TARGET)) 169 return False 170 171 toggle_cell_data_roaming(self.ad, False) 172 time.sleep(TIME_TO_WAIT_BEFORE_PING) 173 if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): 174 self.log.error( 175 "Test Fail: Phone {} can ping {} with Data Roaming Off" 176 .format(self.ad.serial, PING_TARGET)) 177 return False 178 179 except AnritsuError as e: 180 self.log.error("Error in connection with Anritsu Simulator: " + 181 str(e)) 182 return False 183 except Exception as e: 184 self.log.error("Exception during data roaming: " + str(e)) 185 return False 186 return True 187 188 """ Tests Begin """ 189 190 @test_tracker_info(uuid="46d49bff-9671-4ab0-a90d-b49d870af6f0") 191 @TelephonyBaseTest.tel_test_wrap 192 def test_data_roaming_optus(self): 193 """Data roaming test for Optus LTE and WCDMA networks 194 195 Tests if data roaming enabled/disabled work correctly with 196 Optus(Australia) LTE and WCDMA networks 197 198 Steps: 199 1. Setup Optus LTE network and make sure UE registers 200 2. Turn on data roaming, and check if Ping succeeds 201 3. Turn off data roaming, and check if Ping fails 202 4. Turn Airplane Mode On in UE 203 5. Setup Optus WCDMA network and make sure UE registers 204 6. Turn on data roaming, and check if Ping succeeds 205 7. Turn off data roaming, and check if Ping fails 206 207 Expected Result: 208 Ping succeeds when data roaming is turned on, 209 and Ping fails when data roaming is turned off 210 211 Returns: 212 True if pass; False if fail 213 """ 214 return self.LTE_WCDMA_data_roaming( 215 mcc="505", mnc="02F", lte_band="3", wcdma_band="1") 216 217 @test_tracker_info(uuid="68a6313c-d95a-4cae-8e35-2fdf3c94df56") 218 @TelephonyBaseTest.tel_test_wrap 219 def test_data_roaming_telus(self): 220 """Data roaming test for Telus LTE and WCDMA networks 221 222 Tests if data roaming enabled/disabled work correctly with 223 Telus(Canada) LTE and WCDMA networks 224 225 Steps: 226 1. Setup Telus LTE network and make sure UE registers 227 2. Turn on data roaming, and check if Ping succeeds 228 3. Turn off data roaming, and check if Ping fails 229 4. Turn Airplane Mode On in UE 230 5. Setup Telus WCDMA network and make sure UE registers 231 6. Turn on data roaming, and check if Ping succeeds 232 7. Turn off data roaming, and check if Ping fails 233 234 Expected Result: 235 Ping succeeds when data roaming is turned on, 236 and Ping fails when data roaming is turned off 237 238 Returns: 239 True if pass; False if fail 240 """ 241 return self.LTE_WCDMA_data_roaming( 242 mcc="302", mnc="220", lte_band="4", wcdma_band="2") 243 244 @test_tracker_info(uuid="16de850a-6511-42d4-8d8f-d800477aba6b") 245 @TelephonyBaseTest.tel_test_wrap 246 def test_data_roaming_vodafone(self): 247 """Data roaming test for Vodafone LTE and WCDMA networks 248 249 Tests if data roaming enabled/disabled work correctly with 250 Vodafone(UK) LTE and WCDMA networks 251 252 Steps: 253 1. Setup Vodafone LTE network and make sure UE registers 254 2. Turn on data roaming, and check if Ping succeeds 255 3. Turn off data roaming, and check if Ping fails 256 4. Turn Airplane Mode On in UE 257 5. Setup Vodafone WCDMA network and make sure UE registers 258 6. Turn on data roaming, and check if Ping succeeds 259 7. Turn off data roaming, and check if Ping fails 260 261 Expected Result: 262 Ping succeeds when data roaming is turned on, 263 and Ping fails when data roaming is turned off 264 265 Returns: 266 True if pass; False if fail 267 """ 268 return self.LTE_WCDMA_data_roaming( 269 mcc="234", mnc="15F", lte_band="20", wcdma_band="1") 270 271 @test_tracker_info(uuid="e9050f3d-b53c-4a87-9363-b88a842a3479") 272 @TelephonyBaseTest.tel_test_wrap 273 def test_data_roaming_o2(self): 274 """Data roaming test for O2 LTE and WCDMA networks 275 276 Tests if data roaming enabled/disabled work correctly with 277 O2(UK) LTE and WCDMA networks 278 279 Steps: 280 1. Setup O2 LTE network and make sure UE registers 281 2. Turn on data roaming, and check if Ping succeeds 282 3. Turn off data roaming, and check if Ping fails 283 4. Turn Airplane Mode On in UE 284 5. Setup O2 WCDMA network and make sure UE registers 285 6. Turn on data roaming, and check if Ping succeeds 286 7. Turn off data roaming, and check if Ping fails 287 288 Expected Result: 289 Ping succeeds when data roaming is turned on, 290 and Ping fails when data roaming is turned off 291 292 Returns: 293 True if pass; False if fail 294 """ 295 return self.LTE_WCDMA_data_roaming( 296 mcc="234", mnc="02F", lte_band="20", wcdma_band="1") 297 298 @test_tracker_info(uuid="a3f56da1-6a51-45b0-8016-3a492661e1f4") 299 @TelephonyBaseTest.tel_test_wrap 300 def test_data_roaming_orange(self): 301 """Data roaming test for Orange LTE and WCDMA networks 302 303 Tests if data roaming enabled/disabled work correctly with 304 Orange(UK) LTE and WCDMA networks 305 306 Steps: 307 1. Setup Orange LTE network and make sure UE registers 308 2. Turn on data roaming, and check if Ping succeeds 309 3. Turn off data roaming, and check if Ping fails 310 4. Turn Airplane Mode On in UE 311 5. Setup Orange WCDMA network and make sure UE registers 312 6. Turn on data roaming, and check if Ping succeeds 313 7. Turn off data roaming, and check if Ping fails 314 315 Expected Result: 316 Ping succeeds when data roaming is turned on, 317 and Ping fails when data roaming is turned off 318 319 Returns: 320 True if pass; False if fail 321 """ 322 return self.LTE_WCDMA_data_roaming( 323 mcc="234", mnc="33F", lte_band="20", wcdma_band="1") 324 325 @test_tracker_info(uuid="dcde16c1-730c-41ee-ad29-286f4962c66f") 326 @TelephonyBaseTest.tel_test_wrap 327 def test_data_roaming_idea(self): 328 """Data roaming test for Idea LTE and WCDMA networks 329 330 Tests if data roaming enabled/disabled work correctly with 331 Idea(India) LTE and WCDMA networks 332 333 Steps: 334 1. Setup Idea LTE network and make sure UE registers 335 2. Turn on data roaming, and check if Ping succeeds 336 3. Turn off data roaming, and check if Ping fails 337 4. Turn Airplane Mode On in UE 338 5. Setup Idea WCDMA network and make sure UE registers 339 6. Turn on data roaming, and check if Ping succeeds 340 7. Turn off data roaming, and check if Ping fails 341 342 Expected Result: 343 Ping succeeds when data roaming is turned on, 344 and Ping fails when data roaming is turned off 345 346 Returns: 347 True if pass; False if fail 348 """ 349 return self.LTE_WCDMA_data_roaming( 350 mcc="404", mnc="24F", lte_band="3", wcdma_band="1") 351 352 """ Tests End """ 353