Molly Chang | 7adf9df | 2021-04-22 14:49:59 +0800 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2021 - 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 | |
| 17 | |
| 18 | import time |
| 19 | import datetime |
| 20 | import logging |
| 21 | |
| 22 | from acts import asserts |
| 23 | from acts.test_decorators import test_tracker_info |
| 24 | |
| 25 | from acts.base_test import BaseTestClass |
| 26 | from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest |
| 27 | from acts_contrib.test_utils.tel.GFTInOutBaseTest import GFTInOutBaseTest |
| 28 | |
| 29 | from acts_contrib.test_utils.tel.tel_test_utils import get_service_state_by_adb |
| 30 | from acts_contrib.test_utils.tel.tel_test_utils import multithread_func |
| 31 | from acts_contrib.test_utils.tel.tel_test_utils import run_multithread_func |
| 32 | from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected |
| 33 | from acts_contrib.test_utils.tel.tel_test_utils import get_screen_shot_log |
| 34 | from acts_contrib.test_utils.tel.tel_test_utils import get_screen_shot_logs |
| 35 | from acts_contrib.test_utils.tel.tel_test_utils import log_screen_shot |
| 36 | from acts_contrib.test_utils.tel.tel_test_utils import hangup_call |
| 37 | |
| 38 | from acts_contrib.test_utils.tel.tel_defines import DATA_STATE_CONNECTED |
| 39 | from acts_contrib.test_utils.tel.tel_defines import DATA_STATE_DISCONNECTED |
| 40 | from acts_contrib.test_utils.tel.tel_defines import SERVICE_STATE_EMERGENCY_ONLY |
| 41 | from acts_contrib.test_utils.tel.tel_defines import SERVICE_STATE_IN_SERVICE |
| 42 | from acts_contrib.test_utils.tel.tel_defines import SERVICE_STATE_UNKNOWN |
| 43 | from acts_contrib.test_utils.tel.tel_defines import SERVICE_STATE_OUT_OF_SERVICE |
| 44 | from acts_contrib.test_utils.tel.tel_defines import SERVICE_STATE_POWER_OFF |
| 45 | |
| 46 | from acts_contrib.test_utils.tel.gft_inout_utils import check_no_service_time |
| 47 | from acts_contrib.test_utils.tel.gft_inout_utils import check_back_to_service_time |
| 48 | from acts_contrib.test_utils.tel.gft_inout_utils import mo_voice_call |
| 49 | from acts_contrib.test_utils.tel.gft_inout_utils import get_voice_call_type |
| 50 | |
| 51 | from acts_contrib.test_utils.tel.gft_inout_defines import VOICE_CALL |
| 52 | from acts_contrib.test_utils.tel.gft_inout_defines import VOLTE_CALL |
| 53 | from acts_contrib.test_utils.tel.gft_inout_defines import CSFB_CALL |
| 54 | from acts_contrib.test_utils.tel.gft_inout_defines import WFC_CALL |
| 55 | from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_POWER_LEVEL |
| 56 | from acts_contrib.test_utils.tel.gft_inout_defines import IN_SERVICE_POWER_LEVEL |
| 57 | from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_AREA |
| 58 | from acts_contrib.test_utils.tel.gft_inout_defines import IN_SERVICE_AREA |
| 59 | from acts_contrib.test_utils.tel.gft_inout_defines import WIFI_AREA |
| 60 | from acts_contrib.test_utils.tel.gft_inout_defines import NO_WIFI_AREA |
| 61 | from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_TIME |
| 62 | from acts_contrib.test_utils.tel.gft_inout_defines import WAIT_FOR_SERVICE_TIME |
| 63 | |
| 64 | |
| 65 | class TelLabGFTInOutServiceTest(GFTInOutBaseTest): |
| 66 | def __init__(self, controllers): |
| 67 | GFTInOutBaseTest.__init__(self, controllers) |
| 68 | |
| 69 | def setup_test(self): |
| 70 | self.adjust_cellular_signal(IN_SERVICE_POWER_LEVEL) |
| 71 | self.adjust_wifi_signal(IN_SERVICE_POWER_LEVEL) |
| 72 | GFTInOutBaseTest.setup_test(self) |
| 73 | self.check_network() |
| 74 | |
| 75 | @test_tracker_info(uuid="c602e556-8273-4c75-b8fa-4d51ba514654") |
| 76 | @TelephonyBaseTest.tel_test_wrap |
| 77 | def test_in_out_no_service_idle_1min(self, idle_time=60): |
| 78 | """ UE is in idle |
| 79 | Move UE from coverage area to no service area and UE shows no service |
| 80 | Wait for 1 min, then re-enter coverage area |
| 81 | |
| 82 | Args: |
| 83 | idle_time: idle time in service area |
| 84 | |
| 85 | Returns: |
| 86 | True if pass; False if fail. |
| 87 | """ |
| 88 | return self._test_in_out_service_idle(idle_time) |
| 89 | |
| 90 | @test_tracker_info(uuid="c602e556-8273-4c75-b8fa-4d51ba514654") |
| 91 | @TelephonyBaseTest.tel_test_wrap |
| 92 | def test_in_out_no_service_idle_2min(self, idle_time=120): |
| 93 | """ UE is in idle |
| 94 | Move UE from coverage area to no service area and UE shows no service |
| 95 | Wait for 2 min, then re-enter coverage area |
| 96 | |
| 97 | Args: |
| 98 | idle_time: idle time in service area |
| 99 | |
| 100 | Returns: |
| 101 | True if pass; False if fail. |
| 102 | """ |
| 103 | return self._test_in_out_service_idle(idle_time) |
| 104 | |
| 105 | |
| 106 | @test_tracker_info(uuid="1d437482-caff-4695-9f3f-f3daf6793540") |
| 107 | @TelephonyBaseTest.tel_test_wrap |
| 108 | def test_in_out_no_service_idle_5min(self, idle_time=300): |
| 109 | """ UE is in idle |
| 110 | Move UE from coverage area to no service area and UE shows no service |
| 111 | Wait for 5 min, then re-enter coverage area |
| 112 | |
| 113 | Args: |
| 114 | loop: cycle |
| 115 | idle_time: idle time in service area |
| 116 | |
| 117 | Returns: |
| 118 | True if pass; False if fail. |
| 119 | """ |
| 120 | return self._test_in_out_service_idle(idle_time) |
| 121 | |
| 122 | @test_tracker_info(uuid="339b4bf5-57a1-48f0-b26a-83a7db21b08b") |
| 123 | @TelephonyBaseTest.tel_test_wrap |
| 124 | def test_in_out_no_service_idle_10min(self, idle_time=600): |
| 125 | """ UE is in idle |
| 126 | Move UE from coverage area to no service area and UE shows no service |
| 127 | Wait for 10 min, then re-enter coverage area |
| 128 | |
| 129 | Args: |
| 130 | loop: cycle |
| 131 | idle_time: idle time in service area |
| 132 | |
| 133 | Returns: |
| 134 | True if pass; False if fail. |
| 135 | """ |
| 136 | return self._test_in_out_service_idle(idle_time) |
| 137 | |
| 138 | def _test_in_out_service_idle(self, idle_time, loop=1): |
| 139 | """ UE is in idle |
| 140 | Move UE from coverage area to no service area and UE shows no service |
| 141 | Args: |
| 142 | loop: cycle |
| 143 | idle_time: idle time in service area |
| 144 | |
| 145 | Returns: |
| 146 | True if pass; False if fail. |
| 147 | """ |
| 148 | test_result = True |
| 149 | if 'autoio_cycle' in self.user_params: |
| 150 | loop = self.user_params.get('autoio_cycle') |
| 151 | |
| 152 | for x in range (loop): |
| 153 | self.log.info("%s loop: %s/%s" %(self.current_test_name,x+1, loop)) |
| 154 | if not self._in_out_service_idle(idle_time): |
| 155 | test_result = False |
| 156 | return test_result |
| 157 | |
| 158 | |
| 159 | def _in_out_service_idle(self, no_service_time=60, check_back_to_service=True, |
| 160 | check_no_service=True): |
| 161 | """ Move UE from coverage area to no service area and UE shows no service |
| 162 | Wait for no_service_time sec , then re-enter coverage area |
| 163 | |
| 164 | Args: |
| 165 | no_service_time: stay at no service area time in sec |
| 166 | check_back_to_service: check device is back to service flag |
| 167 | check_no_service: check device is no service flag |
| 168 | |
| 169 | Returns: |
| 170 | True if pass; False if fail. |
| 171 | """ |
| 172 | test_result = True |
| 173 | for ad in self.android_devices: |
| 174 | network_type = ad.droid.telephonyGetNetworkType() |
| 175 | service_state = get_service_state_by_adb(self.log,ad) |
| 176 | ad.log.info("service_state=%s. network_type=%s" |
| 177 | %(service_state ,network_type)) |
| 178 | if service_state != SERVICE_STATE_IN_SERVICE: |
| 179 | ad.log.info("Device is not ready for AutoIO test. service_state=%s." |
| 180 | %(service_state)) |
| 181 | return False |
| 182 | |
| 183 | self.log.info("Move UE from coverage area to no service area") |
| 184 | self.adjust_cellular_signal(NO_SERVICE_POWER_LEVEL) |
| 185 | |
| 186 | if check_no_service: |
| 187 | tasks = [(check_no_service_time, (ad, )) for ad in self.android_devices] |
| 188 | if not multithread_func(self.log, tasks): |
| 189 | self.log.info("Device does not become no service") |
| 190 | return False |
| 191 | else: |
| 192 | self.log.info("wait for %s sec in no/limited service area" %(no_service_time)) |
| 193 | time.sleep(no_service_time) |
| 194 | self.log.info("Move UE back to service area") |
| 195 | self.adjust_cellular_signal(IN_SERVICE_POWER_LEVEL) |
| 196 | |
| 197 | if test_result: |
| 198 | if check_back_to_service: |
| 199 | tasks = [(check_back_to_service_time, (ad,)) for ad in self.android_devices] |
| 200 | test_result = multithread_func(self.log, tasks) |
| 201 | self.log.info("Device is not back to the service") |
| 202 | return test_result |