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