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 5import logging 6 7from autotest_lib.client.bin import test 8from autotest_lib.client.bin import utils 9from autotest_lib.client.common_lib import error 10 11from autotest_lib.client.cros.cellular import mm1_constants 12from autotest_lib.client.cros.cellular import test_environment 13from autotest_lib.client.cros.networking import cellular_proxy 14from autotest_lib.client.cros.networking import pm_proxy 15from autotest_lib.client.cros.networking import shill_context 16 17SHORT_TIMEOUT = 10 18 19 20class cellular_OutOfCreditsSubscriptionState(test.test): 21 """ 22 This test verifies that shill out-of-credits behavior works properly based 23 on the modem subscription state. 24 25 """ 26 version = 1 27 28 def _initialize_modem(self, subscription_state): 29 # Simulate an Altair 3100 modem since that modem supports subscription 30 # state information. 31 self.test_env.shill.disable_modem_for_test_setup() 32 # TODO(thieule): Set the modem model using the pseudomodem testing 33 # interface (crbug.com/343258). 34 self.modem.iface_properties.Set( 35 mm1_constants.I_MODEM, 36 mm1_constants.MM_MODEM_PROPERTY_NAME_PLUGIN, 37 'Altair LTE') 38 self.pseudomm.iface_testing.SetSubscriptionState( 39 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNKNOWN, 40 subscription_state) 41 self.test_env.shill.manager.EnableTechnology( 42 cellular_proxy.CellularProxy.TECHNOLOGY_CELLULAR) 43 # Wait for a registered state. 44 self.modem.wait_for_states([mm1_constants.MM_MODEM_STATE_REGISTERED, 45 mm1_constants.MM_MODEM_STATE_CONNECTED]) 46 47 48 def _is_out_of_credits(self, cellular_service): 49 properties = cellular_service.GetProperties(utf8_strings=True) 50 return properties[cellular_proxy.CellularProxy. 51 DEVICE_PROPERTY_OUT_OF_CREDITS] 52 53 54 def _test_provisioned(self): 55 logging.info('Initialize modem with provisioned state') 56 self._initialize_modem( 57 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_PROVISIONED) 58 logging.info('Verify out-of-credits is not set in cellular service') 59 cellular_service = \ 60 self.test_env.shill.wait_for_cellular_service_object() 61 if self._is_out_of_credits(cellular_service): 62 error_msg = 'Service marked as out-of-credits when it ' \ 63 'should not be.' 64 logging.error(error_msg) 65 raise error.TestFail(error_msg) 66 67 68 def _test_out_of_credits_at_start(self): 69 logging.info('Initialize modem with out-of-credits state') 70 self._initialize_modem( 71 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_OUT_OF_DATA) 72 logging.info('Verify out-of-credits is set in cellular service') 73 cellular_service = \ 74 self.test_env.shill.wait_for_cellular_service_object() 75 if not self._is_out_of_credits(cellular_service): 76 error_msg = 'Service not marked out-of-credits when it ' \ 77 'should be.' 78 logging.error(error_msg) 79 raise error.TestFail(error_msg) 80 81 82 def _test_out_of_credits_while_connected(self): 83 logging.info('Initialize modem with provisioned state') 84 self._initialize_modem( 85 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_PROVISIONED) 86 cellular_service = \ 87 self.test_env.shill.wait_for_cellular_service_object() 88 logging.info('Mark modem as out-of-credits') 89 self.pseudomm.iface_testing.SetSubscriptionState( 90 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNKNOWN, 91 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_OUT_OF_DATA) 92 logging.info('Verify out-of-credits set in cellular service') 93 try: 94 utils.poll_for_condition( 95 lambda: self._is_out_of_credits(cellular_service), 96 exception=error.TestFail('Service failed to be marked as ' 97 'out-of-credits.'), 98 timeout=SHORT_TIMEOUT) 99 except error.TestFail as e: 100 logging.error(repr(e)) 101 raise e 102 103 104 def run_once(self): 105 """Calls by autotest to run this test.""" 106 self.test_env = test_environment.CellularPseudoMMTestEnvironment( 107 pseudomm_args=({'family': '3GPP'},)) 108 with self.test_env, shill_context.ServiceAutoConnectContext( 109 self.test_env.shill.wait_for_cellular_service_object, False): 110 self.pseudomm = pm_proxy.PseudoMMProxy.get_proxy() 111 self.modem = self.pseudomm.get_modem() 112 113 self._test_provisioned() 114 self._test_out_of_credits_at_start() 115 self._test_out_of_credits_while_connected() 116