Home | History | Annotate | Download | only in cellular_DeferredRegistration
      1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import dbus
      6 import logging
      7 import time
      8 
      9 from autotest_lib.client.bin import test
     10 from autotest_lib.client.common_lib import error
     11 
     12 from autotest_lib.client.cros.cellular import mm1_constants
     13 from autotest_lib.client.cros.cellular import test_environment
     14 from autotest_lib.client.cros.networking import pm_proxy
     15 
     16 class cellular_DeferredRegistration(test.test):
     17     """
     18     Tests that shill can handle temporary registration loss without
     19     disconnecting the service because some modems periodically go searching for
     20     a better signal while still connected to the network.  Conversely, make
     21     sure that shill still disconnects a service that has suffered a
     22     registration loss for an extended period of time (>15s).
     23 
     24     """
     25     version = 1
     26 
     27     DEFERRED_REGISTRATION_TIMEOUT_SECONDS = 15
     28 
     29     def _init(self):
     30         self.pseudomm = pm_proxy.PseudoMMProxy.get_proxy()
     31         service = self.test_env.shill.find_cellular_service_object()
     32         self.test_env.shill.connect_service_synchronous(
     33                 service,
     34                 timeout_seconds=self.test_env.shill.SERVICE_CONNECT_TIMEOUT)
     35 
     36 
     37     def _set_modem_registration_state(self, state):
     38         self.pseudomm.get_modem().iface_properties.Set(
     39                 mm1_constants.I_MODEM_3GPP,
     40                 'RegistrationState',
     41                 dbus.types.UInt32(state))
     42 
     43 
     44     def _test_temporary_registration_loss(self):
     45         logging.info('Verifying temporary loss of registration behavior')
     46         self._set_modem_registration_state(
     47                 mm1_constants.MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING)
     48         time.sleep(self.DEFERRED_REGISTRATION_TIMEOUT_SECONDS / 2)
     49         self._set_modem_registration_state(
     50                 mm1_constants.MM_MODEM_3GPP_REGISTRATION_STATE_HOME)
     51         time.sleep(self.DEFERRED_REGISTRATION_TIMEOUT_SECONDS * 2)
     52         if self.test_env.shill.find_cellular_service_object() is None:
     53             raise error.TestFail('Cellular service should not have been '
     54                                  'destroyed after temporary registration loss.')
     55         logging.info('Successfully verified temporary loss of registration '
     56                      'behavior')
     57 
     58 
     59     def _test_permanent_registration_loss(self):
     60         logging.info('Verifying permanent loss of registration behavior')
     61         self._set_modem_registration_state(
     62                 mm1_constants.MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING)
     63         time.sleep(self.DEFERRED_REGISTRATION_TIMEOUT_SECONDS * 2)
     64         if self.test_env.shill.find_cellular_service_object() is not None:
     65             raise error.TestFail('Cellular service should have been destroyed '
     66                                  'after permanent registration loss.')
     67         logging.info('Successfully verified permanent loss of registration '
     68                      'behavior')
     69 
     70 
     71     def run_once(self):
     72         """Called by autotest to run this test."""
     73 
     74         with test_environment.CellularPseudoMMTestEnvironment(
     75                 pseudomm_args=({'family': '3GPP'},)) as self.test_env:
     76             self._init()
     77 
     78             tests = [self._test_temporary_registration_loss,
     79                      self._test_permanent_registration_loss]
     80 
     81             for test in tests:
     82                 test()
     83