def test_user_initiated_cellular_scan(self):
        """
        Test that the |ProposeScan| DBus method exported by shill cellular
        object correctly updates the cellular object |Scanning| property while
        the scan is in progress.
        """
        with pseudomodem_context.PseudoModemManagerContext(
                True, {
                    'test-module': TEST_MODEMS_MODULE_PATH,
                    'test-modem-class': 'AsyncScanModem'
                }):
            self._cellular_proxy = cellular_proxy.CellularProxy.get_proxy()
            self._bus = dbus.SystemBus()
            self._cellular_proxy.set_logging_for_cellular_test()

            logging.info('Sanity check initial values')
            utils.poll_for_condition(
                self._cellular_proxy.find_cellular_device_object,
                exception=error.TestFail(
                    'Bad initial state: Failed to obtain a cellular '
                    'device in pseudomodem context.'),
                timeout=SHORT_TIMEOUT_SECONDS)
            device = self._cellular_proxy.find_cellular_device_object()
            try:
                self._itesting_machine(STATE_MACHINE_SCAN, 0)
                raise error.TestFail('Bad initial state: scan machine created '
                                     'by pseudomodem before scan is proposed.')
            except utils.TimeoutError:
                pass

            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, False,
                False)

            logging.info('Test actions and checks')
            device.ProposeScan()
            try:
                itesting_scan_machine = self._itesting_machine(
                    STATE_MACHINE_SCAN)
            except utils.TimeoutError:
                raise error.TestFail('Pseudomodem failed to launch %s' %
                                     STATE_MACHINE_SCAN)
            utils.poll_for_condition(itesting_scan_machine.IsWaiting,
                                     exception=error.TestFail(
                                         'Scan machine failed to enter '
                                         'scan state'),
                                     timeout=SHORT_TIMEOUT_SECONDS)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, False,
                True)

            itesting_scan_machine.Advance()
            utils.poll_for_condition(
                lambda: not itesting_scan_machine.IsWaiting(),
                exception=error.TestFail('Scan machine failed to exit '
                                         'scan state'),
                timeout=SHORT_TIMEOUT_SECONDS)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, True,
                False)
    def __init__(self, pseudomm_args=None, **kwargs):
        """
        @param pseudomm_args: Tuple of arguments passed to the pseudomodem, see
                pseudomodem_context.py for description of each argument in the
                tuple: (flags_map, block_output, bus)

        """
        super(CellularPseudoMMTestEnvironment, self).__init__(**kwargs)
        self._context_managers.append(
            pseudomodem_context.PseudoModemManagerContext(True,
                                                          bus=self.bus,
                                                          *pseudomm_args))
Esempio n. 3
0
    def run_once(self, family):
        with pseudomodem_context.PseudoModemManagerContext(
                True,
                {'family' : family}):
            with cntc.ChromeNetworkingTestContext() as test_context:
                networks = test_context.find_cellular_networks()
                if len(networks) != 1:
                    raise error.TestFail(
                            'Expected 1 cellular network, found ' +
                            str(len(networks)))

                network = networks[0]
                if network["Type"] != test_context.CHROME_NETWORK_TYPE_CELLULAR:
                    raise error.TestFail(
                            'Expected network of type "Cellular", found ' +
                            network["Type"])

                if not network["Name"].startswith(
                        pm_constants.DEFAULT_TEST_NETWORK_PREFIX):
                    raise error.TestFail('Network name is incorrect: ' +
                                         network["Name"])
    def test_activated_service_states(self):
        """
        Test that shill |Scanning| property is updated correctly when an
        activated 3GPP service connects.
        """
        with pseudomodem_context.PseudoModemManagerContext(
                True, {
                    'test-module':
                    TEST_MODEMS_MODULE_PATH,
                    'test-state-machine-factory-class':
                    'InteractiveStateMachineFactory'
                }):
            self._cellular_proxy = cellular_proxy.CellularProxy.get_proxy()
            self._bus = dbus.SystemBus()
            self._cellular_proxy.set_logging_for_cellular_test()

            logging.info('Sanity check initial values')
            enable_machine = self._itesting_machine(
                pm_constants.STATE_MACHINE_ENABLE)
            utils.poll_for_condition(
                enable_machine.IsWaiting,
                exception=error.TestFail(
                    'Bad initial state: Pseudomodem did not launch '
                    'Enable machine'),
                timeout=SHORT_TIMEOUT_SECONDS)
            utils.poll_for_condition(
                self._cellular_proxy.find_cellular_device_object,
                exception=error.TestFail(
                    'Bad initial state: Failed to obtain a cellular '
                    'device in pseudomodem context.'),
                timeout=SHORT_TIMEOUT_SECONDS)
            device = self._cellular_proxy.find_cellular_device_object()
            mm_modem = self._find_mm_modem()

            logging.info('Test Connect sequence')
            self._check_mm_state(mm_modem,
                                 mm1_constants.MM_MODEM_STATE_DISABLED)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_POWERED, False,
                False)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, False,
                False)
            logging.info('Expectation met: |Scanning| is False in MM state '
                         'Disabled')
            enable_machine.Advance()

            # MM state: Enabling
            utils.poll_for_condition(enable_machine.IsWaiting,
                                     exception=error.TestFail(
                                         'EnableMachine failed to wait in '
                                         'Enabling state'),
                                     timeout=SHORT_TIMEOUT_SECONDS)
            self._check_mm_state(mm_modem,
                                 mm1_constants.MM_MODEM_STATE_ENABLING)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, False,
                True)
            logging.info('Expectation met: |Scanning| is True in MM state '
                         'Enabling')
            enable_machine.Advance()

            # MM state: Enabled
            utils.poll_for_condition(enable_machine.IsWaiting,
                                     exception=error.TestFail(
                                         'EnableMachine failed to wait in '
                                         'Enabled state'),
                                     timeout=SHORT_TIMEOUT_SECONDS)
            # Finish the enable call.
            enable_machine.Advance()

            self._check_mm_state(mm_modem,
                                 mm1_constants.MM_MODEM_STATE_ENABLED)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_POWERED, False,
                True)
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, True,
                True)

            register_machine = self._itesting_machine(
                pm_constants.STATE_MACHINE_REGISTER)
            utils.poll_for_condition(register_machine.IsWaiting,
                                     exception=error.TestFail(
                                         'SearchingMachine failed to wait '
                                         'in Enabled state'),
                                     timeout=SHORT_TIMEOUT_SECONDS)
            logging.info('Expectation met: |Scanning| is True in MM state '
                         'Enabled')
            register_machine.Advance()

            # MM state: Searching
            utils.poll_for_condition(register_machine.IsWaiting,
                                     exception=error.TestFail(
                                         'SearchingMachine failed to wait '
                                         'in Searching state'),
                                     timeout=SHORT_TIMEOUT_SECONDS)
            self._check_mm_state(mm_modem,
                                 mm1_constants.MM_MODEM_STATE_SEARCHING)
            enable_machine.Advance()
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, True,
                True)
            logging.info('Expectation met: |Scanning| is True in MM state '
                         'Searching')
            register_machine.Advance()

            # MM state: >= Registered
            utils.poll_for_condition(
                self._cellular_proxy.find_cellular_service_object,
                error.TestFail('Failed to create Cellular Service for a '
                               'registered modem'),
                timeout=SHORT_TIMEOUT_SECONDS)
            self._check_mm_state(mm_modem, [
                mm1_constants.MM_MODEM_STATE_REGISTERED,
                mm1_constants.MM_MODEM_STATE_CONNECTING,
                mm1_constants.MM_MODEM_STATE_CONNECTED
            ])
            self._check_shill_property_update(
                device, self._cellular_proxy.DEVICE_PROPERTY_SCANNING, True,
                False)
            logging.info('Expectation met: |Scanning| is False in MM state '
                         'Registered')