• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2016 - 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 BtsNumber
25from acts_contrib.test_utils.tel.anritsu_utils import WAIT_TIME_ANRITSU_REG_AND_CALL
26from acts_contrib.test_utils.tel.anritsu_utils import handover_tc
27from acts_contrib.test_utils.tel.anritsu_utils import make_ims_call
28from acts_contrib.test_utils.tel.anritsu_utils import tear_down_call
29from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte_lte
30from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte_wcdma
31from acts_contrib.test_utils.tel.anritsu_utils import set_usim_parameters
32from acts_contrib.test_utils.tel.anritsu_utils import set_post_sim_params
33from acts_contrib.test_utils.tel.tel_defines import CALL_TEARDOWN_PHONE
34from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
35from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_GSM
36from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_LTE
37from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
38from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
39from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
40from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
41from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_CDMA_EVDO
42from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
43from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
44from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
45from acts_contrib.test_utils.tel.tel_ims_utils import toggle_volte
46from acts_contrib.test_utils.tel.tel_logging_utils import start_qxdm_loggers
47from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_rat
48from acts_contrib.test_utils.tel.tel_test_utils import get_host_ip_address
49from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
50from acts_contrib.test_utils.tel.tel_test_utils import iperf_test_by_adb
51from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_apn_by_adb
52from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_idle_volte
53from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
54from acts.utils import adb_shell_ping
55from acts.libs.utils.multithread import run_multithread_func
56
57DEFAULT_CALL_NUMBER = "+11234567891"
58DEFAULT_PING_DURATION = 5
59WAITTIME_BEFORE_HANDOVER = 20
60WAITTIME_AFTER_HANDOVER = 20
61
62
63class TelLabMobilityTest(TelephonyBaseTest):
64    def setup_class(self):
65        super().setup_class()
66        self.ad = self.android_devices[0]
67        self.ad.sim_card = getattr(self.ad, "sim_card", None)
68        self.md8475a_ip_address = self.user_params[
69            "anritsu_md8475a_ip_address"]
70        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
71        self.md8475_version = self.user_params.get("md8475", "A")
72        self.voice_call_number = self.user_params.get('voice_call_number',
73                                                      DEFAULT_CALL_NUMBER)
74        self.ip_server = self.iperf_servers[0]
75        self.port_num = self.ip_server.port
76        self.log.info("Iperf Port is %s", self.port_num)
77        if self.ad.sim_card == "VzW12349":
78            set_preferred_apn_by_adb(self.ad, "VZWINTERNET")
79
80        try:
81            self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option,
82                                   self.md8475_version)
83        except AnritsuError:
84            self.log.error("Error in connecting to Anritsu Simulator")
85            return False
86        return True
87
88    def setup_test(self):
89        try:
90            if getattr(self, "qxdm_log", True):
91                start_qxdm_loggers(self.log, self.android_devices)
92            self.ad.droid.telephonyFactoryReset()
93        except Exception as e:
94            self.ad.log.error(e)
95        toggle_airplane_mode_by_adb(self.log, self.ad, True)
96        self.ad.adb.shell(
97            "setprop net.lte.ims.volte.provisioned 1", ignore_status=True)
98        # get a handle to virtual phone
99        self.virtualPhoneHandle = self.anritsu.get_VirtualPhone()
100        return True
101
102    def teardown_test(self):
103        self.log.info("Stopping Simulation")
104        self.anritsu.stop_simulation()
105        toggle_airplane_mode_by_adb(self.log, self.ad, True)
106        return True
107
108    def teardown_class(self):
109        self.anritsu.disconnect()
110        return True
111
112    def active_handover(self,
113                        set_simulation_func,
114                        phone_setup_func,
115                        phone_idle_func_after_registration=None,
116                        volte=True,
117                        iperf=True,
118                        all_bands=False,
119                        is_wait_for_registration=True,
120                        voice_number=DEFAULT_CALL_NUMBER,
121                        teardown_side=CALL_TEARDOWN_PHONE,
122                        wait_time_in_call=WAIT_TIME_IN_CALL):
123        try:
124            bts = set_simulation_func(self.anritsu, self.user_params,
125                                      self.ad.sim_card)
126            set_usim_parameters(self.anritsu, self.ad.sim_card)
127            set_post_sim_params(self.anritsu, self.user_params,
128                                self.ad.sim_card)
129            self.anritsu.start_simulation()
130            self.anritsu.send_command("IMSSTARTVN 1")
131            self.anritsu.send_command("IMSSTARTVN 2")
132            self.anritsu.send_command("IMSSTARTVN 3")
133            # turn off all other BTS to ensure UE registers on BTS1
134            simmodel = self.anritsu.get_simulation_model().split(',')
135            no_of_bts = len(simmodel)
136            for i in range(2, no_of_bts + 1):
137                self.anritsu.send_command("OUTOFSERVICE OUT,BTS{}".format(i))
138            if phone_setup_func is not None:
139                if not phone_setup_func(self.ad):
140                    self.log.warning("phone_setup_func failed. Rebooting UE")
141                    self.ad.reboot()
142                    time.sleep(30)
143                    if self.ad.sim_card == "VzW12349":
144                        set_preferred_apn_by_adb(self.ad, "VZWINTERNET")
145                    if not phone_setup_func(self.ad):
146                        self.log.error("phone_setup_func failed.")
147            if is_wait_for_registration:
148                self.anritsu.wait_for_registration_state()
149            if phone_idle_func_after_registration:
150                if not phone_idle_func_after_registration(self.log, self.ad):
151                    self.log.error("phone_idle_func failed.")
152            for i in range(2, no_of_bts + 1):
153                self.anritsu.send_command("OUTOFSERVICE IN,BTS{}".format(i))
154            time.sleep(WAIT_TIME_ANRITSU_REG_AND_CALL)
155            if iperf:  # setup iPerf server
156                server_ip = self.iperf_setup()
157                if not server_ip:
158                    self.log.error("iperf server can not be reached by ping")
159                    return False
160            if volte:  # make a VoLTE MO call
161                if not make_ims_call(self.log, self.ad, self.anritsu,
162                                     voice_number):
163                    self.log.error("Phone {} Failed to make volte call to {}"
164                                   .format(self.ad.serial, voice_number))
165                    return False
166            if all_bands and (simmodel[1] == "WCDMA"):
167                band = []
168                for rat in simmodel[:2]:
169                    band.append(self.anritsu.get_supported_bands(rat))
170                self.log.info("UE reported LTE bands are {}".format(band[0]))
171                self.log.info("UE reported WCDMA bands are {}".format(band[1]))
172                current_lte_band = bts[0].band
173                # move current LTE band to the last in the list
174                band[0].remove(current_lte_band)
175                band[0].append(current_lte_band)
176                n = max(len(band[0]), len(band[1]))
177            else:
178                n = 1  # n is the number of LTE->WCDMA->LTE handovers
179
180            for i in range(n):
181                if all_bands:
182                    bts[1].band = band[1][i % len(band[1])]
183                if not iperf:  # VoLTE only
184                    result = handover_tc(self.log, self.anritsu,
185                                         WAITTIME_BEFORE_HANDOVER,
186                                         BtsNumber.BTS1, BtsNumber.BTS2)
187                    time.sleep(WAITTIME_AFTER_HANDOVER)
188                else:  # with iPerf
189                    iperf_task = (self._iperf_task,
190                                  (server_ip, WAITTIME_BEFORE_HANDOVER +
191                                   WAITTIME_AFTER_HANDOVER - 10))
192                    ho_task = (handover_tc, (self.log, self.anritsu,
193                                             WAITTIME_BEFORE_HANDOVER,
194                                             BtsNumber.BTS1, BtsNumber.BTS2))
195                    result = run_multithread_func(self.log,
196                                                  [ho_task, iperf_task])
197                    if not result[1]:
198                        self.log.error("iPerf failed.")
199                        return False
200
201                self.log.info(
202                    "handover test case result code {}.".format(result[0]))
203                if volte:
204                    # check if the phone stay in call
205                    if not self.ad.droid.telecomIsInCall():
206                        self.log.error("Call is already ended in the phone.")
207                        return False
208
209                    if not tear_down_call(self.log, self.ad, self.anritsu):
210                        self.log.error("Phone {} Failed to tear down"
211                                       .format(self.ad.serial, voice_number))
212                        return False
213                if simmodel[1] == "WCDMA" and iperf:
214                    if all_bands:
215                        bts[0].band = band[0][i % len(band[0])]
216                    iperf_task = (self._iperf_task,
217                                  (server_ip, WAITTIME_BEFORE_HANDOVER +
218                                   WAITTIME_AFTER_HANDOVER - 10))
219                    ho_task = (handover_tc, (self.log, self.anritsu,
220                                             WAITTIME_BEFORE_HANDOVER,
221                                             BtsNumber.BTS2, BtsNumber.BTS1))
222                    result = run_multithread_func(self.log,
223                                                  [ho_task, iperf_task])
224                    if not result[1]:
225                        self.log.error("iPerf failed.")
226                        return False
227                    self.log.info(
228                        "handover test case result code {}.".format(result[0]))
229
230        except AnritsuError as e:
231            self.log.error("Error in connection with Anritsu Simulator: " +
232                           str(e))
233            return False
234        except Exception as e:
235            self.log.error("Exception during voice call procedure: " + str(e))
236            return False
237        return True
238
239    def iperf_setup(self):
240        # Fetch IP address of the host machine
241        destination_ip = get_host_ip_address(self)
242
243        if not adb_shell_ping(self.ad, DEFAULT_PING_DURATION, destination_ip):
244            self.log.error("Pings failed to Destination.")
245            return False
246
247        return destination_ip
248
249    def _iperf_task(self, destination_ip, duration):
250        self.log.info("Starting iPerf task")
251        self.ip_server.start()
252        tput_dict = {"Uplink": 0, "Downlink": 0}
253        if iperf_test_by_adb(
254                self.log,
255                self.ad,
256                destination_ip,
257                self.port_num,
258                True,  # reverse = true
259                duration,
260                rate_dict=tput_dict):
261            uplink = tput_dict["Uplink"]
262            downlink = tput_dict["Downlink"]
263            self.ip_server.stop()
264            return True
265        else:
266            self.log.error("iperf failed to Destination.")
267            self.ip_server.stop()
268            return False
269
270    def _phone_setup_lte_wcdma(self, ad):
271        return ensure_network_rat(
272            self.log,
273            ad,
274            NETWORK_MODE_LTE_GSM_WCDMA,
275            RAT_FAMILY_LTE,
276            toggle_apm_after_setting=True)
277
278    def _phone_setup_lte_1x(self, ad):
279        return ensure_network_rat(
280            self.log,
281            ad,
282            NETWORK_MODE_LTE_CDMA_EVDO,
283            RAT_FAMILY_LTE,
284            toggle_apm_after_setting=True)
285
286    def _phone_setup_wcdma(self, ad):
287        return ensure_network_rat(
288            self.log,
289            ad,
290            NETWORK_MODE_GSM_UMTS,
291            RAT_FAMILY_UMTS,
292            toggle_apm_after_setting=True)
293
294    def _phone_setup_gsm(self, ad):
295        return ensure_network_rat(
296            self.log,
297            ad,
298            NETWORK_MODE_GSM_ONLY,
299            RAT_FAMILY_GSM,
300            toggle_apm_after_setting=True)
301
302    def _phone_setup_1x(self, ad):
303        return ensure_network_rat(
304            self.log,
305            ad,
306            NETWORK_MODE_CDMA,
307            RAT_FAMILY_CDMA2000,
308            toggle_apm_after_setting=True)
309
310    def _phone_setup_airplane_mode(self, ad):
311        return toggle_airplane_mode_by_adb(self.log, ad, True)
312
313    def _phone_setup_volte_airplane_mode(self, ad):
314        toggle_volte(self.log, ad, True)
315        return toggle_airplane_mode_by_adb(self.log, ad, True)
316
317    def _phone_setup_volte(self, ad):
318        ad.droid.telephonyToggleDataConnection(True)
319        toggle_volte(self.log, ad, True)
320        return ensure_network_rat(
321            self.log,
322            ad,
323            NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA,
324            RAT_FAMILY_LTE,
325            toggle_apm_after_setting=True)
326
327    """ Tests Begin """
328
329    @test_tracker_info(uuid="bd014822-2c09-4503-9e01-594513ea6808")
330    @TelephonyBaseTest.tel_test_wrap
331    def test_volte_iperf_handover(self):
332        """ Test VoLTE to VoLTE Inter-Freq handover with iPerf data
333        Steps:
334        1. Setup CallBox for 2 LTE cells with 2 different bands.
335        2. Turn on DUT and enable VoLTE. Make an voice call to DEFAULT_CALL_NUMBER.
336        3. Check if VoLTE voice call connected successfully.
337        4. Start iPerf data transfer
338        5. Handover the call to BTS2 and check if the call is still up.
339        6. Check iPerf data throughput
340        7. Tear down the call.
341
342        Expected Results:
343        1. VoLTE Voice call is made successfully.
344        2. After handover, the call is not dropped.
345        3. Tear down call succeed.
346
347        Returns:
348            True if pass; False if fail
349        """
350        return self.active_handover(
351            set_system_model_lte_lte,
352            self._phone_setup_volte,
353            phone_idle_volte,
354            volte=True,
355            iperf=True)
356
357    @test_tracker_info(uuid="a5a15947-40eb-4a70-b652-0b52a548c3c1")
358    @TelephonyBaseTest.tel_test_wrap
359    def test_volte_handover(self):
360        """ Test VoLTE to VoLTE Inter-Freq handover without iPerf data
361        Steps:
362        1. Setup CallBox for 2 LTE cells with 2 different bands.
363        2. Turn on DUT and enable VoLTE. Make an voice call to DEFAULT_CALL_NUMBER.
364        3. Check if VoLTE voice call connected successfully.
365        4. Handover the call to BTS2 and check if the call is still up.
366        5. Tear down the call.
367
368        Expected Results:
369        1. VoLTE Voice call is made successfully.
370        2. After handover, the call is not dropped.
371        3. Tear down call succeed.
372
373        Returns:
374            True if pass; False if fail
375        """
376        return self.active_handover(
377            set_system_model_lte_lte,
378            self._phone_setup_volte,
379            phone_idle_volte,
380            volte=True,
381            iperf=False)
382
383    @test_tracker_info(uuid="382521d9-d991-49bc-8347-2e766ec0db74")
384    @TelephonyBaseTest.tel_test_wrap
385    def test_iperf_handover(self):
386        """ Test Inter-Freq handover with iPerf data
387        Steps:
388        1. Setup CallBox for 2 LTE cells with 2 different bands.
389        2. Turn on DUT and enable VoLTE.
390        3. Start iPerf data transfer
391        4. Handover the call to BTS2
392        5. Check iPerf data throughput
393
394        Expected Results:
395        1. Data call is made successfully.
396        2. After handover, the data is not dropped.
397
398        Returns:
399            True if pass; False if fail
400        """
401        return self.active_handover(
402            set_system_model_lte_lte,
403            self._phone_setup_volte,
404            phone_idle_volte,
405            volte=False,
406            iperf=True)
407
408    @test_tracker_info(uuid="d255a58b-8697-4d0a-9bc0-1e7ffa4cccaf")
409    @TelephonyBaseTest.tel_test_wrap
410    def test_volte_iperf_handover_wcdma(self):
411        """ Test VoLTE to WCDMA to LTE handover with iPerf data
412        Steps:
413        1. Setup CallBox for LTE and WCDMA simulation.
414        2. Turn on DUT and enable VoLTE. Make an voice call to DEFAULT_CALL_NUMBER.
415        3. Check if VoLTE voice call connected successfully.
416        4. Start iPerf data transfer
417        5. SRVCC to WCDMA and check if the call is still up.
418        6. Check iPerf data throughput
419        7. Tear down the call.
420        8. Handover back to LTE with iPerf
421
422        Expected Results:
423        1. VoLTE Voice call is made successfully.
424        2. After handover, the call is not dropped.
425        3. iPerf continue after handover
426
427        Returns:
428            True if pass; False if fail
429        """
430        return self.active_handover(
431            set_system_model_lte_wcdma,
432            self._phone_setup_volte,
433            phone_idle_volte,
434            volte=True,
435            iperf=True)
436
437    @test_tracker_info(uuid="28bc2e85-602e-4143-afe7-6dd442bef5c8")
438    @TelephonyBaseTest.tel_test_wrap
439    def test_volte_handover_wcdma(self):
440        """ Test VoLTE to WCDMA handover (SRVCC)
441        Steps:
442        1. Setup CallBox for LTE and WCDMA simulation.
443        2. Turn on DUT and enable VoLTE. Make an voice call to DEFAULT_CALL_NUMBER.
444        3. Check if VoLTE voice call connected successfully.
445        4. Start iPerf data transfer
446        5. Handover the call to BTS2 and check if the call is still up.
447        6. Check iPerf data throughput
448        7. Tear down the call.
449
450        Expected Results:
451        1. VoLTE Voice call is made successfully.
452        2. After handover, the call is not dropped.
453        3. Tear down call succeed.
454
455        Returns:
456            True if pass; False if fail
457        """
458        return self.active_handover(
459            set_system_model_lte_wcdma,
460            self._phone_setup_volte,
461            phone_idle_volte,
462            volte=True,
463            iperf=False)
464
465    @test_tracker_info(uuid="3ef15650-8e44-4b75-b809-8d7dec5a41e3")
466    @TelephonyBaseTest.tel_test_wrap
467    def test_iperf_handover_wcdma(self):
468        """ Test LTE to WCDMA to LTE handovers with iPerf data
469        Steps:
470        1. Setup CallBox for LTE and WCDMA simulation.
471        2. Turn on DUT and register on LTE BTS.
472        3. Start iPerf data transfer
473        4. Handover to WCDMA.
474        5. Stop and check iPerf data throughput
475        6. Start iPerf data transfer
476        7. Handover to WCDMA.
477        8. Stop and check iPerf data throughput
478
479
480        Expected Results:
481        1. Each handover is successful
482        2. After each handover, the iPerf continues successfully.
483
484        Returns:
485            True if pass; False if fail
486        """
487        return self.active_handover(
488            set_system_model_lte_wcdma,
489            self._phone_setup_volte,
490            phone_idle_volte,
491            volte=False,
492            iperf=True)
493
494    @test_tracker_info(uuid="2bfad82d-1797-474b-9bf7-c14602b061cd")
495    @TelephonyBaseTest.tel_test_wrap
496    def test_iperf_handover_wcdma_all_bands(self):
497        """ Test LTE->WCDMA->LTE handovers through all bands UE supports with iPerf data
498        Steps:
499        1. Setup CallBox for LTE and WCDMA simulation.
500        2. Turn on DUT and register on LTE BTS.
501        3. Query MD8475A for UE supported bands contained in UE Capability Information
502        4. Set target WCDMA band with first band in WCDMA supported band list
503        5. Start iPerf data transfer
504        6. Handover to WCDMA.
505        7. Stop and check iPerf data throughput
506        8. Set target LTE band with first band in LTE supported band list
507        9. Start iPerf data transfer
508        10. Handover to LTE.
509        11. Stop and check iPerf data throughput
510        12. Repeat step 4-11 with second WCDMA/LTE bands in supported band lists
511        13. Repeat step 12 until all bands are tested. Reuse the begining of the shorter list to match the longer list.
512
513        Expected Results:
514        1. Each handover is successful
515        2. After each handover, the iPerf continues successfully.
516
517        Returns:
518            True if pass; False if fail
519        """
520        return self.active_handover(
521            set_system_model_lte_wcdma,
522            self._phone_setup_volte,
523            phone_idle_volte,
524            volte=False,
525            iperf=True,
526            all_bands=True)
527
528    """ Tests End """
529