• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import time
18from acts import asserts
19from acts.test_decorators import test_info
20from acts.test_decorators import test_tracker_info
21from acts.logger import epoch_to_log_line_timestamp
22from acts.utils import get_current_epoch_time
23from acts.libs.utils.multithread import multithread_func
24from acts.base_test import BaseTestClass
25from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
26from acts_contrib.test_utils.tel.tel_logging_utils import get_screen_shot_log
27from acts_contrib.test_utils.tel.tel_logging_utils import get_screen_shot_logs
28from acts_contrib.test_utils.tel.tel_logging_utils import log_screen_shot
29from acts_contrib.test_utils.tel.tel_test_utils import get_service_state_by_adb
30from acts_contrib.test_utils.tel.tel_voice_utils import hangup_call
31from acts_contrib.test_utils.tel.tel_voice_utils import is_phone_in_call
32from acts_contrib.test_utils.tel.gft_inout_utils import mo_voice_call
33from acts_contrib.test_utils.tel.gft_inout_utils import get_voice_call_type
34from acts_contrib.test_utils.tel.gft_inout_utils import verify_data_connection
35from acts_contrib.test_utils.tel.gft_inout_utils import check_network_service
36from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_POWER_LEVEL
37from acts_contrib.test_utils.tel.gft_inout_defines import IN_SERVICE_POWER_LEVEL
38from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_AREA
39from acts_contrib.test_utils.tel.gft_inout_defines import IN_SERVICE_AREA
40from acts_contrib.test_utils.tel.gft_inout_defines import WIFI_AREA
41from acts_contrib.test_utils.tel.gft_inout_defines import NO_WIFI_AREA
42from acts_contrib.test_utils.tel.gft_inout_defines import NO_SERVICE_TIME
43from acts_contrib.test_utils.tel.gft_inout_defines import WAIT_FOR_SERVICE_TIME
44from acts_contrib.test_utils.tel.loggers.telephony_metric_logger import TelephonyMetricLogger
45
46CELLULAR_PORT = 0
47WIFI_PORT = 1
48UNKNOWN = "UNKNOWN"
49
50
51class GFTInOutBaseTest(TelephonyBaseTest):
52    def __init__(self, controllers):
53        TelephonyBaseTest.__init__(self, controllers)
54        self.my_error_msg = ""
55        self.tel_logger = TelephonyMetricLogger.for_test_case()
56
57    def setup_test(self):
58        TelephonyBaseTest.setup_test(self)
59        self.user_params["telephony_auto_rerun"] = 0
60        self.my_error_msg = ""
61
62    def teardown_test(self):
63        TelephonyBaseTest.teardown_test(self)
64        begin_time = get_current_epoch_time()
65        for ad in self.android_devices:
66            hangup_call(self.log, ad)
67        get_screen_shot_logs(self.android_devices)
68        for ad in self.android_devices:
69            ad.adb.shell("rm -rf /sdcard/Pictures/screenvideo_*", ignore_status=True)
70
71    def check_network(self):
72        """check service state of network
73        Returns:
74            return True if android_devices are in service else return false
75        """
76        for ad in self.android_devices:
77            network_type_voice = ad.droid.telephonyGetCurrentVoiceNetworkType()
78            network_type_data = ad.droid.telephonyGetCurrentDataNetworkType()
79            data_state = ad.droid.telephonyGetDataConnectionState()
80            service_state = get_service_state_by_adb(ad.log,ad)
81            wifi_info = ad.droid.wifiGetConnectionInfo()
82            sim_state = ad.droid.telephonyGetSimState()
83            if ad.droid.wifiCheckState():
84                if wifi_info["supplicant_state"] == "completed":
85                    ad.log.info("Wifi is connected=%s" %(wifi_info["SSID"]))
86                else:
87                    ad.log.info("wifi_info =%s" %(wifi_info))
88            else:
89                ad.log.info("Wifi state is down.")
90            ad.log.info("data_state=%s" %(data_state))
91            ad.log.info("sim_state=%s" %(sim_state))
92            ad.log.info("networkType_voice=%s" %(network_type_voice))
93            ad.log.info("network_type_data=%s" %(network_type_data))
94            ad.log.info("service_state=%s" %(service_state))
95            if network_type_voice == UNKNOWN:
96                return False
97        return True
98
99    def adjust_cellular_signal(self, power, adjust_gradually=False):
100        """Sets the attenuation value of cellular port
101        Args:
102             power: power level for attenuator to be set
103        Returns:
104            return True if ceullular port is set
105        """
106        if self.user_params.get("Attenuator"):
107            if adjust_gradually:
108                self.log.info("adjust cellular signal gradually to mini-circuits to %s" %(power))
109                self.adjust_atten_slowly(10, NO_SERVICE_AREA)
110            else:
111                self.log.info("adjust cellular signal set mini-circuits to %s" %(power))
112                self.attenuators[CELLULAR_PORT].set_atten(power)
113            return True
114        else:
115            self.log.info("Attenuator is set to False in config file")
116            return False
117
118    def adjust_wifi_signal(self, power, adjust_gradually=False):
119        """Sets the attenuation value of wifi port
120        Args:
121             power: power level for attenuator to be set
122        Returns:
123            return True if wifi port is set
124        """
125        if self.user_params.get("Attenuator"):
126            if adjust_gradually:
127                self.log.info("adjust wifi signal set mini-circuits to %s" %(power))
128                self.adjust_atten_slowly(10, NO_WIFI_AREA)
129            else:
130                self.log.info("adjust wifi signal and set mini-circuits to %s" %(power))
131                self.attenuators[WIFI_PORT].set_atten(power)
132                self.attenuators[2].set_atten(power)
133                self.attenuators[3].set_atten(power)
134        else:
135            self.log.info("Attenuator is set to False in config file")
136            return False
137        return True
138
139    def adjust_attens(self, power):
140        """Sets the attenuation value of all attenuators in the group
141        Args:
142             power: power level for attenuator to be set
143        Returns:
144            return True if all ports are set
145        """
146        if self.user_params.get("Attenuator"):
147            self.log.info("set attenuator ports to %s" %(power))
148            self.attenuators[0].set_atten(power)
149            self.attenuators[1].set_atten(power)
150            self.attenuators[2].set_atten(power)
151            self.attenuators[3].set_atten(power)
152        else:
153            self.log.info("Attenuator is set to False in config file")
154            return False
155        return True
156
157    def adjust_atten(self, port , power):
158        """Sets the attenuation value of given port
159        Args:
160            port: port of attenuator
161            power: power level for attenuator to be set
162        Returns:
163            return True if given port is set
164        """
165        if self.user_params.get("Attenuator"):
166            self.log.info("set attenuator port=%s to %s" %(port, power))
167            self.attenuators[port].set_atten(power)
168        else:
169            self.log.info("Attenuator is set to False in config file")
170            return False
171        return True
172
173    def adjust_atten_slowly(self, adjust_level, move_to, step=9 , step_time=5):
174        """adjust attenuator slowly
175        Args:
176            adjust_level: adjust power level for each cycle
177            move_to: NO_SERVICE_AREA, IN_SERVICE_AREA , WIFI_AREA, NO_WIFI_AREA
178            step: adjust attenuator how many time
179            step_time: wait for how many sec for each loop
180        Returns:
181            return True if given port is set
182        """
183        if move_to == NO_SERVICE_AREA:
184            self.log.info("Move UE from coverage area to no/poor service area")
185            power_level = IN_SERVICE_POWER_LEVEL
186            for x in range (step):
187                power_level += adjust_level
188                self.log.info("adjust power level = %s" %power_level)
189                self.adjust_cellular_signal(power_level)
190                time.sleep(step_time)
191                self.log.info("wait device to be in no service state")
192                self.check_network()
193        elif move_to == IN_SERVICE_AREA:
194            # Move UE to service area
195            self.log.info("Move UE to service area")
196            power_level = NO_SERVICE_POWER_LEVEL
197            for x in range (step):
198                power_level -= adjust_level
199                self.log.info("adjust power level = %s" %power_level)
200                self.adjust_cellular_signal(power_level)
201                time.sleep(step_time)
202                self.log.info("wait device to be in service state")
203                self.check_network()
204        elif move_to == WIFI_AREA:
205            self.log.info("Move UE to good wifi area")
206            power_level = IN_SERVICE_POWER_LEVEL
207            for x in range (step):
208                power_level += adjust_level
209                self.log.info("adjust power level = %s" %power_level)
210                self.adjust_wifi_signal(power_level)
211                time.sleep(step_time)
212                self.log.info("wait device to connected to wifi")
213                self.check_network()
214        elif move_to == NO_WIFI_AREA:
215            self.log.info("Move UE to poor/no wifi area")
216            power_level = NO_SERVICE_POWER_LEVEL
217            for x in range (step):
218                power_level -= adjust_level
219                self.log.info("adjust power level = %s" %power_level)
220                self.adjust_wifi_signal(power_level)
221                time.sleep(step_time)
222                self.log.info("wait device to disconnected from wifi")
223                self.check_network()
224        return True
225
226    def verify_device_status(self, ad, call_type=None, end_call=True,
227        talk_time=30, verify_data=True, verify_voice=True, data_retries=2, voice_retries=2):
228        """verfiy device status includes network service, data connection and voice call
229        Args:
230            ad: android device
231            call_type: WFC call, VOLTE call. CSFB call, voice call
232            end_call: hangup call after voice call flag
233            talk_time: in call duration in sec
234            verify_data: flag to check data connection
235            verify_voice: flag to check voice
236            data_retries: retry times for data verification
237            voice_retris:retry times for voice call
238        Returns:
239            return True if pass
240        """
241        tasks = [(check_network_service, (ad, )) for ad in self.android_devices]
242        if not multithread_func(self.log, tasks):
243            log_screen_shot(ad, "check_network_service_fail")
244            ad.log.info("check_network_service fail")
245            return False
246        else:
247            self.log.info("check_network_service pass")
248        if verify_data:
249            tasks = [(verify_data_connection, (ad, data_retries ))
250                for ad in self.android_devices]
251            if not multithread_func(self.log, tasks):
252                log_screen_shot(ad, "verify_data_connection_fail")
253                ad.log.info("verify_data_connection_fail")
254                return False
255            else:
256                self.log.info("verify_data_connection pass")
257        if verify_voice:
258            if call_type:
259                tasks = [(mo_voice_call, (self.log, ad, call_type, end_call,
260                    talk_time, voice_retries)) for ad in self.android_devices]
261            if not multithread_func(self.log, tasks):
262                log_screen_shot(ad, "verify_voice_call_fail")
263                ad.log.info("verify_voice_call_fail")
264                return False
265            else:
266                self.log.info("verify_voice_call pass")
267                return True
268        return True
269
270
271    def _on_failure(self, error_msg="", assert_on_fail=True, test_result=False):
272        """ operation on fail
273
274        Args:
275            error_msg: error message to be written to log
276
277        """
278        if assert_on_fail:
279            asserts.assert_true(False, "assert_on_fail: %s."
280                %(error_msg),extras={"failure_cause": error_msg})
281        for ad in self.android_devices:
282            log_screen_shot(ad, error_msg)
283        self.log.info(error_msg)
284
285