1#!/usr/bin/env python3.4 2# 3# Copyright 2020 - 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 Activation 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_4G 25from acts_contrib.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA 26from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_WCDMA_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 reboot_device 29from acts_contrib.test_utils.tel.tel_test_utils import get_current_override_network_type 30from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode 31from acts_contrib.test_utils.tel.tel_test_utils import wait_for_network_generation 32from acts_contrib.test_utils.tel.tel_test_utils import wifi_toggle_state 33from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_network_mode_pref 34from acts_contrib.test_utils.tel.tel_5g_utils import is_current_network_5g_nsa 35from acts_contrib.test_utils.tel.tel_5g_test_utils import set_preferred_mode_for_5g 36 37 38class Nsa5gActivationTest(TelephonyBaseTest): 39 def setup_class(self): 40 super().setup_class() 41 42 def setup_test(self): 43 TelephonyBaseTest.setup_test(self) 44 self.number_of_devices = 1 45 46 def teardown_class(self): 47 TelephonyBaseTest.teardown_class(self) 48 49 50 """ Tests Begin """ 51 52 53 @test_tracker_info(uuid="b10b3779-b535-4cac-a12f-2fb6daed55a5") 54 @TelephonyBaseTest.tel_test_wrap 55 def test_5g_nsa_activation_from_apm(self): 56 """ Verifies 5G NSA activation from Airplane Mode 57 58 Toggle Airplane mode on and off 59 Ensure phone attach, data on, LTE attach 60 Wait for 120 secs for ENDC attach 61 Verify is data network type is NR_NSA 62 63 Returns: 64 True if pass; False if fail. 65 """ 66 ad = self.android_devices[0] 67 wifi_toggle_state(ad.log, ad, False) 68 set_preferred_mode_for_5g(ad) 69 for iteration in range(3): 70 ad.log.info("Attempt %d", iteration + 1) 71 # APM toggle 72 toggle_airplane_mode(ad.log, ad, True) 73 toggle_airplane_mode(ad.log, ad, False) 74 # LTE attach 75 if not wait_for_network_generation( 76 ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 77 ad.log.error("Fail to ensure initial data in 4G") 78 # 5G attach 79 ad.log.info("Waiting for 5g NSA attach for 60 secs") 80 if is_current_network_5g_nsa(ad, timeout=60): 81 ad.log.info("Success! attached on 5g NSA") 82 return True 83 else: 84 ad.log.error("Failure - expected NR_NSA, current %s", 85 get_current_override_network_type(ad)) 86 time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) 87 ad.log.info("nsa5g attach test FAIL for all 3 iterations") 88 return False 89 90 91 @test_tracker_info(uuid="d4f5f0c5-cc58-4531-96dd-32eed9121b95") 92 @TelephonyBaseTest.tel_test_wrap 93 def test_5g_nsa_activation_from_reboot(self): 94 """ Verifies 5G NSA activation from Reboot 95 96 Reboot device 97 Ensure phone attach, data on, LTE attach 98 Wait for 120 secs for ENDC attach 99 Verify is data network type is NR_NSA 100 101 Returns: 102 True if pass; False if fail. 103 """ 104 ad = self.android_devices[0] 105 wifi_toggle_state(ad.log, ad, False) 106 toggle_airplane_mode(ad.log, ad, False) 107 set_preferred_mode_for_5g(ad) 108 for iteration in range(3): 109 ad.log.info("Attempt %d", iteration + 1) 110 # Reboot phone 111 reboot_device(ad) 112 # LTE attach 113 if not wait_for_network_generation( 114 ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 115 ad.log.error("Fail to ensure initial data in 4G") 116 # 5G attach 117 ad.log.info("Waiting for 5g NSA attach for 60 secs") 118 if is_current_network_5g_nsa(ad, timeout=60): 119 ad.log.info("Success! attached on 5g NSA") 120 return True 121 else: 122 ad.log.error("Failure - expected NR_NSA, current %s", 123 get_current_override_network_type(ad)) 124 time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) 125 ad.log.info("nsa5g reboot test FAIL for all 3 iterations") 126 return False 127 128 129 @test_tracker_info(uuid="1ceda4b5-4a6a-43fa-8976-67cbfb7eab5b") 130 @TelephonyBaseTest.tel_test_wrap 131 def test_5g_nsa_activation_from_3g(self): 132 """ Verifies 5G NSA activation from 3G Mode Pref 133 134 Change Mode to 3G and wait for 15 secs 135 Change Mode back to 5G 136 Ensure phone attach, data on, LTE attach 137 Wait for 120 secs for ENDC attach 138 Verify is data network type is NR_NSA 139 140 Returns: 141 True if pass; False if fail. 142 """ 143 ad = self.android_devices[0] 144 sub_id = ad.droid.subscriptionGetDefaultSubId() 145 wifi_toggle_state(ad.log, ad, False) 146 toggle_airplane_mode(ad.log, ad, False) 147 for iteration in range(3): 148 ad.log.info("Attempt %d", iteration + 1) 149 # Set mode pref to 3G 150 set_preferred_network_mode_pref(ad.log, ad, sub_id, 151 NETWORK_MODE_WCDMA_ONLY) 152 time.sleep(15) 153 # Set mode pref to 5G 154 set_preferred_mode_for_5g(ad) 155 # LTE attach 156 if not wait_for_network_generation( 157 ad.log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): 158 ad.log.error("Fail to ensure initial data in 4G") 159 # 5G attach 160 ad.log.info("Waiting for 5g NSA attach for 60 secs") 161 if is_current_network_5g_nsa(ad, timeout=60): 162 ad.log.info("Success! attached on 5g NSA") 163 return True 164 else: 165 ad.log.error("Failure - expected NR_NSA, current %s", 166 get_current_override_network_type(ad)) 167 time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) 168 ad.log.info("nsa5g mode pref from 3G test FAIL for all 3 iterations") 169 return False 170 171 """ Tests End """ 172