Home | History | Annotate | Download | only in live
      1 #/usr/bin/env python3.4
      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 """
     17 Sanity tests for connectivity tests in telephony
     18 """
     19 
     20 import time
     21 
     22 from acts.controllers.anritsu_lib.md8475a import BtsServiceState
     23 from acts.controllers.anritsu_lib.md8475a import BtsTechnology
     24 from acts.controllers.anritsu_lib.md8475a import MD8475A
     25 from acts.controllers.anritsu_lib.md8475a import ProcessingStatus
     26 from acts.controllers.anritsu_lib.md8475a import TriggerMessageIDs
     27 from acts.controllers.anritsu_lib.md8475a import TriggerMessageReply
     28 from acts.test_utils.tel import tel_test_utils
     29 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     30 
     31 
     32 class TelephonyConnectivitySanityTest(TelephonyBaseTest):
     33     def __init__(self, controllers):
     34         TelephonyBaseTest.__init__(self, controllers)
     35         self.anritsu = MD8475A(tel_test_utils.MD8475A_IP_ADDRESS)
     36 
     37     def setup_test(self):
     38         self.lte_bts, self.wcdma_bts = tel_test_utils.set_system_model(
     39             self.anritsu, "LTE_WCDMA")
     40         tel_test_utils.init_phone(self.droid, self.ed)
     41         self.droid.telephonyStartTrackingServiceStateChange()
     42         self.droid.telephonyStartTrackingDataConnectionStateChange()
     43         self.log.info("Starting Simulation")
     44         self.anritsu.start_simulation()
     45         return True
     46 
     47     def teardown_test(self):
     48         self.droid.telephonyStopTrackingServiceStateChange()
     49         self.droid.telephonyStopTrackingDataConnectionStateChange()
     50         self.log.info("Stopping Simulation")
     51         self.anritsu.stop_simulation()
     52         # turn off modem
     53         tel_test_utils.turn_off_modem(self.droid)
     54 
     55     def teardown_class(self):
     56         self.anritsu.disconnect()
     57 
     58     """ Tests Begin """
     59 
     60     @TelephonyBaseTest.tel_test_wrap
     61     def test_network_registration(self):
     62         '''
     63         Test ID: TEL-CO-01
     64         Checks the Network service state  after bootup. Verifies the
     65         network registration
     66 
     67         Steps
     68         -----
     69         1. The device is in airplane mode
     70         2. Turn off the airplane mode (This simulates the Boot up for modem)
     71         3. check for the service state. expecting IN SERVICE
     72         '''
     73         test_status = "failed"
     74         # turn on modem to start registration
     75         tel_test_utils.turn_on_modem(self.droid)
     76         self.log.info("Waiting for Network registration")
     77         test_status, event = tel_test_utils.wait_for_network_registration(
     78             self.ed, self.anritsu, self.log)
     79 
     80         if test_status == "passed":
     81             self.log.info(
     82                 "TEL-CO-01:Network registration verification: Passed")
     83             return True
     84         else:
     85             self.log.info(
     86                 "TEL-CO-01:Network registration verification: Failed")
     87             return False
     88 
     89     @TelephonyBaseTest.tel_test_wrap
     90     def test_network_params_verification(self):
     91         '''
     92         Test ID: TEL-CO-02
     93         verifies the network registration parameters
     94 
     95         Steps
     96         -----
     97         1. The device is in airplane mode
     98         2. Turn off the airplane mode (This simulates the Boot up for modem)
     99         3. check for the service state. expecting IN SERVICE
    100         4. verifies the values for different parameters
    101         '''
    102         test_status = "failed"
    103         # turn on modem to start registration
    104         tel_test_utils.turn_on_modem(self.droid)
    105         self.log.info("Waiting for Network registration")
    106         test_status, event = tel_test_utils.wait_for_network_registration(
    107             self.ed, self.anritsu, self.log)
    108 
    109         if test_status == "passed":
    110             self.log.info("Verifying the NW Service Parameters")
    111             expected_voice_nwtype = None
    112             operator_name = None
    113             mcc = None
    114             mnc = None
    115 
    116             bts_number, rat_info = self.anritsu.get_camping_cell()
    117             if rat_info == BtsTechnology.WCDMA.value:
    118                 expected_voice_nwtype = "UMTS"
    119                 operator_name = tel_test_utils.WCDMA_NW_NAME
    120                 mcc = tel_test_utils.NW_MCC
    121                 mnc = tel_test_utils.NW_MNC
    122             elif rat_info == BtsTechnology.LTE.value:
    123                 expected_voice_nwtype = "LTE"
    124                 operator_name = tel_test_utils.LTE_NW_NAME
    125                 mcc = tel_test_utils.NW_MCC
    126                 mnc = tel_test_utils.NW_MNC
    127 
    128             self.log.info("VoiceNwState :{}".format(event['data'][
    129                 'VoiceRegState']))
    130             self.log.info("VoiceNetworkType :{}".format(event['data'][
    131                 'VoiceNetworkType']))
    132             self.log.info("DataRegState :{}".format(event['data'][
    133                 'DataRegState']))
    134             self.log.info("DataNetworkType :{}".format(event['data'][
    135                 'DataNetworkType']))
    136             self.log.info("OperatorName :{}".format(event['data'][
    137                 'OperatorName']))
    138             self.log.info("OperatorId :{}".format(event['data']['OperatorId']))
    139             self.log.info("Roaming :{}".format(event['data']['Roaming']))
    140 
    141             if event['data']['VoiceNetworkType'] != expected_voice_nwtype:
    142                 test_status = "failed"
    143                 self.log.info("Error:Expected NW Type is not received")
    144             if event['data']['OperatorId'][:3] != mcc:
    145                 test_status = "failed"
    146                 self.log.info("Error:Expected MNC is not received")
    147             if event['data']['OperatorId'][3:] != mnc:
    148                 test_status = "failed"
    149                 self.log.info("Error:Expected MCC is not received")
    150 
    151         # proceed with next step only if previous step is success
    152         if test_status == "passed":
    153             self.log.info("Waiting for data state: DATA_CONNECTED")
    154             test_status, event = tel_test_utils.wait_for_data_state(
    155                 self.ed, self.log, "DATA_CONNECTED", 120)
    156 
    157         if test_status == "passed":
    158             self.log.info("TEL-CO-02: Network registration parameters"
    159                           " verification: Passed")
    160             return True
    161         else:
    162             self.log.info("TEL-CO-02: Network registration parameters"
    163                           " verification: Failed")
    164             return False
    165 
    166     @TelephonyBaseTest.tel_test_wrap
    167     def test_network_deregistration(self):
    168         '''
    169         Test ID: TEL-CO-03
    170         verifies the network de registration
    171 
    172         Steps
    173         -----
    174         1. The device is in airplane mode
    175         2. Turn off the airplane mode (This simulates the Boot up for modem)
    176         3. check for the service state. expecting IN SERVICE
    177         4. Turn on Airplane mode (This simulates network de registration)
    178         5. check for the service state. expecting POWER_OFF
    179         '''
    180         test_status = "failed"
    181         # turn on modem to start registration
    182         tel_test_utils.turn_on_modem(self.droid)
    183         self.log.info("Waiting for Network registration")
    184         test_status, event = tel_test_utils.wait_for_network_registration(
    185             self.ed, self.anritsu, self.log)
    186 
    187         # proceed with next step only if previous step is success
    188         if test_status == "passed":
    189             test_status = "failed"
    190             self.ed.clear_all_events()
    191             self.log.info("Making device to detach from network")
    192             self.droid.connectivityToggleAirplaneMode(True)
    193             self.log.info("Waiting for service state: POWER_OFF")
    194             test_status, event = tel_test_utils.wait_for_network_state(
    195                 self.ed, self.log, "POWER_OFF", 60)
    196 
    197         if test_status == "passed":
    198             self.log.info("TEL-CO-03: Network de-registration"
    199                           " verification: Passed")
    200             return True
    201         else:
    202             self.log.info("TEL-CO-03: Network de-registration"
    203                           " verification: Failed")
    204             return False
    205 
    206     @TelephonyBaseTest.tel_test_wrap
    207     def test_network_out_of_service(self):
    208         '''
    209         Test ID: TEL-CO-04
    210         verifies the network out of state
    211 
    212         Steps
    213         -----
    214         1. The device is in airplane mode
    215         2. Turn off the airplane mode (This simulates the Boot up for modem)
    216         3. check for the service state. expecting IN SERVICE
    217         4. Make network out of service
    218         5. check for the service state. expecting OUT_OF_SERVICE
    219         '''
    220 
    221         test_status = "failed"
    222         # turn on modem to start registration
    223         tel_test_utils.turn_on_modem(self.droid)
    224         self.log.info("Waiting for Network registration")
    225         test_status, event = tel_test_utils.wait_for_network_registration(
    226             self.ed, self.anritsu, self.log)
    227 
    228         # proceed with next step only if previous step is success
    229         if test_status == "passed":
    230             test_status = "failed"
    231             self.ed.clear_all_events()
    232             # This sleep is required.Sometimes Anritsu box doesn't behave as
    233             # expected in executing the commands send to it without this delay.
    234             # May be it is in state transition.so the test doesn't proceed.
    235             # hence introduced this delay.
    236             time.sleep(5)
    237             bts_number, rat_info = self.anritsu.get_camping_cell()
    238             self.log.info("Making the attached NW as OUT_OF_STATE")
    239             if rat_info == BtsTechnology.LTE.value:
    240                 self.lte_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    241             else:
    242                 self.wcdma_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    243             self.log.info("Waiting for service state: OUT_OF_SERVICE")
    244             test_status, event = tel_test_utils.wait_for_network_state(
    245                 self.ed, self.log, "OUT_OF_SERVICE", 90)
    246 
    247         if test_status == "passed":
    248             self.log.info("TEL-CO-04: Network out-of-service"
    249                           " verification: Passed")
    250             return True
    251         else:
    252             self.log.info("TEL-CO-04: Network out-of-service"
    253                           " verification: Failed")
    254             return False
    255 
    256     @TelephonyBaseTest.tel_test_wrap
    257     def test_network_return_inservice(self):
    258         '''
    259         Test ID: TEL-CO-06
    260         verifies the network returns to IN_SERVICE from OUT_OF_SERVICE
    261 
    262         Steps
    263         -----
    264         1. The device is in airplane mode
    265         2. Turn off the airplane mode (This simulates the Boot up for modem)
    266         3. check for the service state. expecting IN SERVICE
    267         4. Make the network out of service
    268         5. check for the service state. expecting OUT_OF_SERVICE
    269         6. Bring back the device to IN_SERVICE
    270         7. check for the service state. expecting IN_SERVICE
    271         '''
    272         test_status = "failed"
    273         # turn on modem to start registration
    274         tel_test_utils.turn_on_modem(self.droid)
    275         self.log.info("Waiting for Network registration")
    276         test_status, event = tel_test_utils.wait_for_network_registration(
    277             self.ed, self.anritsu, self.log)
    278         self.log.info("Waiting for data state: DATA_CONNECTED")
    279         test_status, event = tel_test_utils.wait_for_data_state(
    280             self.ed, self.log, "DATA_CONNECTED", 120)
    281 
    282         # proceed with next step only if previous step is success
    283         if test_status == "passed":
    284             test_status = "failed"
    285             self.ed.clear_all_events()
    286             # This sleep is required.Sometimes Anritsu box doesn't behave as
    287             # expected in executing the commands send to it without this delay.
    288             # May be it is in state transition.so the test doesn't proceed.
    289             # hence introduced this delay.
    290             time.sleep(5)
    291             bts_number, rat_info = self.anritsu.get_camping_cell()
    292             self.log.info("Making the attached NW as OUT_OF_STATE")
    293             if rat_info == BtsTechnology.LTE.value:
    294                 self.lte_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    295             else:
    296                 self.wcdma_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    297             self.log.info("Waiting for service state: OUT_OF_SERVICE")
    298             test_status, event = tel_test_utils.wait_for_network_state(
    299                 self.ed, self.log, "OUT_OF_SERVICE", 120)
    300 
    301         # proceed with next step only if previous step is success
    302         if test_status == "passed":
    303             test_status = "failed"
    304             self.log.info("Waiting for Network registration")
    305             test_status, event = tel_test_utils.wait_for_network_registration(
    306                 self.ed, self.anritsu, self.log)
    307             self.log.info("Waiting for data state: DATA_CONNECTED")
    308             test_status, event = tel_test_utils.wait_for_data_state(
    309                 self.ed, self.log, "DATA_CONNECTED", 120)
    310 
    311         # proceed with next step only if previous step is success
    312         if test_status == "passed":
    313             test_status = "failed"
    314             self.ed.clear_all_events()
    315             # This sleep is required.Sometimes Anritsu box doesn't behave as
    316             #  expected in executing the commands send to it without this delay.
    317             # May be it is in state transition.so the test doesn't proceed.
    318             # hence introduced this delay.
    319             time.sleep(5)
    320             bts_number, rat_info = self.anritsu.get_camping_cell()
    321             self.log.info("Making the attached NW as OUT_OF_STATE")
    322             if rat_info == BtsTechnology.LTE.value:
    323                 self.lte_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    324             else:
    325                 self.wcdma_bts.service_state = BtsServiceState.SERVICE_STATE_OUT
    326             self.log.info("Waiting for service state: OUT_OF_SERVICE")
    327             test_status, event = tel_test_utils.wait_for_network_state(
    328                 self.ed, self.log, "OUT_OF_SERVICE", 120)
    329 
    330         # proceed with next step only if previous step is success
    331         if test_status == "passed":
    332             test_status = "failed"
    333             self.ed.clear_all_events()
    334             # This sleep is required.Sometimes Anritsu box doesn't behave as
    335             # expected in executing the commands send to it without this delay.
    336             # May be it is in state transition.so the test doesn't proceed.
    337             # hence introduced this delay.
    338             time.sleep(5)
    339             self.log.info("Making the NW service IN_SERVICE")
    340             self.lte_bts.service_state = BtsServiceState.SERVICE_STATE_IN
    341             self.log.info("Waiting for Network registration")
    342             test_status, event = tel_test_utils.wait_for_network_registration(
    343                 self.ed, self.anritsu, self.log)
    344             self.log.info("Waiting for data state: DATA_CONNECTED")
    345             test_status, event = tel_test_utils.wait_for_data_state(
    346                 self.ed, self.log, "DATA_CONNECTED", 120)
    347 
    348         if test_status == "passed":
    349             self.log.info("TEL-CO-06: Network returning to IN_SERVICE"
    350                           " verification: Passed")
    351             return True
    352         else:
    353             self.log.info("TEL-CO-06: Network returning to IN_SERVICE"
    354                           " verification: Failed")
    355             return False
    356 
    357     @TelephonyBaseTest.tel_test_wrap
    358     def test_set_preferred_network(self):
    359         '''
    360         Test ID: TEL-CO-07
    361         verifies the network is registered on Preferred network
    362 
    363         Steps
    364         -----
    365         1. The device is in airplane mode
    366         2. Turn off the airplane mode (This simulates the Boot up for modem)
    367         3. check for the service state. expecting IN SERVICE
    368         4. Set the preferred network type
    369         5. check for the service state  and registered network
    370         '''
    371         test_status = "failed"
    372         # turn on modem to start registration
    373         tel_test_utils.turn_on_modem(self.droid)
    374         self.log.info("Waiting for Network registration")
    375         test_status, event = tel_test_utils.wait_for_network_registration(
    376             self.ed, self.anritsu, self.log)
    377 
    378         # proceed with next step only if previous step is success
    379         if test_status == "passed":
    380             test_status = "failed"
    381             pref_nwtype = 0
    382             expected_nwtype = ""
    383             bts_number, rat_info = self.anritsu.get_camping_cell()
    384             if rat_info == BtsTechnology.WCDMA.value:
    385                 pref_nwtype = tel_test_utils.NETWORK_MODE_LTE_ONLY
    386                 expected_nwtype = "LTE"
    387             elif rat_info == BtsTechnology.LTE.value:
    388                 pref_nwtype = tel_test_utils.NETWORK_MODE_WCDMA_ONLY
    389                 expected_nwtype = "UMTS"
    390             else:
    391                 raise ValueError("Incorrect value of RAT returned by MD8475A")
    392             self.log.info("Setting preferred Network to " + expected_nwtype)
    393             self.droid.telephonySetPreferredNetwork(pref_nwtype)
    394             self.log.info("Waiting for service state: IN_SERVICE in " +
    395                           expected_nwtype)
    396             test_status, event = tel_test_utils.wait_for_network_registration(
    397                 self.ed, self.anritsu, self.log, expected_nwtype)
    398 
    399         # proceed with next step only if previous step is success
    400         if test_status == "passed":
    401             test_status = "failed"
    402             pref_nwtype = 0
    403             expected_nwtype = ""
    404             bts_number, rat_info = self.anritsu.get_camping_cell()
    405             if rat_info == BtsTechnology.WCDMA.value:
    406                 pref_nwtype = tel_test_utils.NETWORK_MODE_LTE_ONLY
    407                 expected_nwtype = "LTE"
    408             elif rat_info == BtsTechnology.LTE.value:
    409                 pref_nwtype = tel_test_utils.NETWORK_MODE_WCDMA_ONLY
    410                 expected_nwtype = "UMTS"
    411             else:
    412                 raise ValueError("Incorrect value of RAT returned by MD8475A")
    413             self.log.info("Setting preferred Network to " + expected_nwtype)
    414             self.droid.telephonySetPreferredNetwork(pref_nwtype)
    415             self.log.info("Waiting for service state: IN_SERVICE in " +
    416                           expected_nwtype)
    417             test_status, event = tel_test_utils.wait_for_network_registration(
    418                 self.ed, self.anritsu, self.log, expected_nwtype)
    419         # setting the preferred network type to default
    420         self.droid.telephonySetPreferredNetwork(
    421             tel_test_utils.NETWORK_MODE_LTE_GSM_WCDMA)
    422 
    423         if test_status == "passed":
    424             self.log.info("TEL-CO-07: Setting preferred Network"
    425                           "verification: Passed")
    426             return True
    427         else:
    428             self.log.info("TEL-CO-07: Setting preferred Network"
    429                           "verification: Failed")
    430             return False
    431 
    432     @TelephonyBaseTest.tel_test_wrap
    433     def test_network_emergency(self):
    434         '''
    435         Test ID: TEL-CO-05
    436         verifies the network state - emergency
    437 
    438         Steps
    439         -----
    440         1. The device is in airplane mode
    441         2. Turn off the airplane mode (This simulates the Boot up for modem)
    442         3. check for the service state. expecting IN SERVICE
    443         4. Make the device emergency only
    444         5. check for the service state. expecting EMERGENCY_ONLY
    445         '''
    446         test_status = "failed"
    447         CAUSE_LA_NOTALLOWED = 12
    448         CAUSE_EPS_NOTALLOWED = 7
    449         triggermessage = self.anritsu.get_TriggerMessage()
    450         triggermessage.set_reply_type(TriggerMessageIDs.ATTACH_REQ,
    451                                       TriggerMessageReply.REJECT)
    452         triggermessage.set_reject_cause(TriggerMessageIDs.ATTACH_REQ,
    453                                         CAUSE_EPS_NOTALLOWED)
    454         # This sleep is required.Sometimes Anritsu box doesn't behave as
    455         # expected in executing the commands send to it without this delay.
    456         # May be it is in state transition.so the test doesn't proceed.
    457         # hence introduced this delay.
    458         time.sleep(5)
    459         triggermessage.set_reply_type(TriggerMessageIDs.MM_LOC_UPDATE_REQ,
    460                                       TriggerMessageReply.REJECT)
    461         triggermessage.set_reject_cause(TriggerMessageIDs.MM_LOC_UPDATE_REQ,
    462                                         CAUSE_LA_NOTALLOWED)
    463 
    464         # turn on modem to start registration
    465         tel_test_utils.turn_on_modem(self.droid)
    466         self.log.info("Waiting for service state: emergency")
    467         test_status, event = tel_test_utils.wait_for_network_state(
    468             self.ed, self.log, "EMERGENCY_ONLY", 300)
    469 
    470         if test_status == "passed":
    471             self.droid.connectivityToggleAirplaneMode(True)
    472             time_to_wait = 60
    473             sleep_interval = 1
    474             # Waiting for POWER OFF state in Anritsu
    475             start_time = time.time()
    476             end_time = start_time + time_to_wait
    477             while True:
    478                 ue_status = self.anritsu.get_ue_status()
    479                 if ue_status == ProcessingStatus.PROCESS_STATUS_POWEROFF:
    480                     break
    481 
    482                 if time.time() <= end_time:
    483                     time.sleep(sleep_interval)
    484                     time_to_wait = end_time - time.time()
    485                 else:
    486                     self.log.info("MD8475A has not come to POWEROFF state")
    487                     break
    488 
    489             # This sleep is required.Sometimes Anritsu box doesn't behave as
    490             # expected in executing the commands send to it without this delay.
    491             # May be it is in state transition.so the test doesn't proceed.
    492             # hence introduced this delay.
    493             time.sleep(10)
    494             triggermessage.set_reply_type(TriggerMessageIDs.ATTACH_REQ,
    495                                           TriggerMessageReply.ACCEPT)
    496             triggermessage.set_reply_type(TriggerMessageIDs.MM_LOC_UPDATE_REQ,
    497                                           TriggerMessageReply.ACCEPT)
    498             self.droid.connectivityToggleAirplaneMode(False)
    499             tel_test_utils.wait_for_network_registration(self.ed, self.anritsu,
    500                                                          self.log)
    501 
    502         if test_status == "passed":
    503             self.log.info("TEL-CO-05: Network emergency state"
    504                           " verification: Passed")
    505             return True
    506         else:
    507             self.log.info("TEL-CO-05: Network emergency state"
    508                           " verification: Failed")
    509 
    510             return False
    511 
    512     @TelephonyBaseTest.tel_test_wrap
    513     def test_manual_operator_selection(self):
    514         '''
    515         verifies the Manual Operator Selection
    516 
    517         Steps
    518         -----
    519         1. The device is in airplane mode
    520         2. Turn off the airplane mode (This simulates the Boot up for modem)
    521         3. check for the service state. expecting IN SERVICE
    522         4. search for NW operators and manually select a non-subscribed operator
    523         5. search for NW operators and manually select the subscribed operator
    524         6. verify the device is camped on subscribed operator
    525         '''
    526         # Android public APIs not available for this operation
    527         pass
    528 
    529     @TelephonyBaseTest.tel_test_wrap
    530     def test_auto_operator_selection(self):
    531         '''
    532         verifies the Automatic Operator Selection
    533 
    534         Steps
    535         -----
    536         1. The device is in airplane mode
    537         2. Turn off the airplane mode (This simulates the Boot up for modem)
    538         3. check for the service state. expecting IN SERVICE
    539         4. search for NW operators and manually select a non-subscribed operator
    540         5. select the the subscribed operator automatically
    541         6. verify the device is camped on subscribed operator
    542         '''
    543         # Android public APIs not available for this operation
    544         pass
    545 
    546     """ Tests End """
    547