Example #1
0
    def _stop_server(self):
        """Releases all the resources acquired in `start_server`.

    Raises:
      android_device_lib_errors.DeviceError: if the server exited with errors on
        the device side.
    """
        # Although killing the snippet server would abort this subprocess anyway, we
        # want to call stop_standing_subprocess() to perform a health check,
        # print the failure stack trace if there was any, and reap it from the
        # process table. Note that it's much more important to ensure releasing all
        # the allocated resources on the host side than on the remote device side.

        # Stop the standing server subprocess running on the host side.
        if self._proc:
            utils.stop_standing_subprocess(self._proc)
            self._proc = None

        # Send the stop signal to the server running on the device side.
        out = self._adb.shell(
            _STOP_CMD.format(
                snippet_package=self.package,
                user=self._get_user_command_string())).decode('utf-8')

        if 'OK (0 tests)' not in out:
            raise android_device_lib_errors.DeviceError(
                self._device,
                f'Failed to stop existing apk. Unexpected output: {out}.')
Example #2
0
 def stop_app(self):
     # Kill the pending 'adb shell am instrument -w' process if there is one.
     # Although killing the snippet apk would abort this process anyway, we
     # want to call stop_standing_subprocess() to perform a health check,
     # print the failure stack trace if there was any, and reap it from the
     # process table.
     self.log.debug('Stopping snippet apk %s', self.package)
     # Close the socket connection.
     self.disconnect()
     if self._proc:
         utils.stop_standing_subprocess(self._proc)
         self._proc = None
     out = self._adb.shell(
         _STOP_CMD.format(
             snippet_package=self.package,
             user=self._get_user_command_string())).decode('utf-8')
     if 'OK (0 tests)' not in out:
         raise errors.DeviceError(
             self._ad,
             'Failed to stop existing apk. Unexpected output: %s' % out)
Example #3
0
 def stop_app(self):
     # Kill the pending 'adb shell am instrument -w' process if there is one.
     # Although killing the snippet apk would abort this process anyway, we
     # want to call stop_standing_subprocess() to perform a health check,
     # print the failure stack trace if there was any, and reap it from the
     # process table.
     self.log.debug('Stopping snippet apk %s', self.package)
     try:
         # Close the socket connection.
         self.disconnect()
         if self._proc:
             utils.stop_standing_subprocess(self._proc)
         out = self._adb.shell(_STOP_CMD % self.package).decode('utf-8')
         if 'OK (0 tests)' not in out:
             raise errors.DeviceError(
                 self._ad,
                 'Failed to stop existing apk. Unexpected output: %s' % out)
     finally:
         # Always clean up the adb port
         if self.host_port:
             self._adb.forward(['--remove', 'tcp:%d' % self.host_port])
Example #4
0
 def test_device_error(self):
     device = mock.MagicMock()
     device.__repr__ = lambda _: '[MockDevice]'
     exception = errors.DeviceError(device, 'Some error message.')
     self.assertEqual(str(exception), '[MockDevice] Some error message.')