Exemple #1
0
    def waitForBootComplete(self, wait_time=120):
        """Waits for targeted device's bootcomplete flag to be set.

        Args:
            wait_time: time in seconds to wait

        Raises:
            WaitForResponseTimedOutError if wait_time elapses and pm still does not
            respond.
        """
        logger.Log("Waiting for boot complete...")
        self.sendCommand("wait-for-device")
        # Now the device is there, but may not be running.
        # Query the package manager with a basic command
        boot_complete = False
        attempts = 0
        wait_period = 5
        while not boot_complete and (attempts * wait_period) < wait_time:
            output = self.sendShellCommand("getprop dev.bootcomplete",
                                           retry_count=1)
            output = output.strip()
            if output == "1":
                boot_complete = True
            else:
                time.sleep(wait_period)
                attempts += 1
        if not boot_complete:
            raise WaitForResponseTimedOutError(
                "dev.bootcomplete flag was not set after %s seconds" %
                wait_time)
Exemple #2
0
    def waitForProcessEnd(self, name, wait_time=120):
        """Wait until a process is no longer running on the device.

        Args:
            name: the process name as it appears in `ps`
            wait_time: time in seconds to wait

        Raises:
            WaitForResponseTimedOutError if wait_time elapses and the process is
                    still running
        """
        logger.Log("Waiting for process %s to end" % name)
        self._waitForShellCommandContents("ps", name, wait_time, invert=True)
 def EnableAdbRoot(self):
   """Enable adb root on device."""
   output = self.SendCommand("root")
   if "adbd is already running as root" in output:
     return True
   elif "restarting adbd as root" in output:
     # device will disappear from adb, wait for it to come back
     time.sleep(2)
     self.SendCommand("wait-for-device")
     return True
   else:
     logger.Log("Unrecognized output from adb root: %s" % output)
     return False
Exemple #4
0
    def waitForProcess(self, name, wait_time=120):
        """Wait until a process is running on the device.

        Args:
            name: the process name as it appears in `ps`
            wait_time: time in seconds to wait

        Raises:
            WaitForResponseTimedOutError if wait_time elapses and the process is
                    still not running
        """
        logger.Log("Waiting for process %s" % name)
        self.sendCommand("wait-for-device")
        self._waitForShellCommandContents("ps", name, wait_time)
  def StartInstrumentationNoResults(
      self, package_name, runner_name, no_window_animation=False,
      raw_mode=False, instrumentation_args={}):
    """Runs instrumentation and dumps output to stdout.

    Equivalent to StartInstrumentation, but will dump instrumentation
    'normal' output to stdout, instead of parsing return results. Command will
    never timeout.
    """
    adb_command_string = self.PreviewInstrumentationCommand(
        package_name, runner_name, no_window_animation=no_window_animation,
        raw_mode=raw_mode, instrumentation_args=instrumentation_args)
    logger.Log(adb_command_string)
    run_command.RunCommand(adb_command_string, return_output=False)
Exemple #6
0
    def waitForDevicePm(self, wait_time=120):
        """Waits for targeted device's package manager to be up.

        Args:
            wait_time: time in seconds to wait

        Raises:
            WaitForResponseTimedOutError if wait_time elapses and pm still does not
            respond.
        """
        logger.Log("Waiting for device package manager...")
        self.sendCommand("wait-for-device")
        # Now the device is there, but may not be running.
        # Query the package manager with a basic command
        try:
            self._waitForShellCommandContents("pm path android", "package:",
                                              wait_time)
        except WaitForResponseTimedOutError:
            raise WaitForResponseTimedOutError(
                "Package manager did not respond after %s seconds" % wait_time)
  def Pull(self, src, dest):
    """Pulls the file src on the device onto dest on the host.

    Args:
      src: absolute file path of file on device to pull
      dest: destination file path on host

    Returns:
      True if success and False otherwise.
    """
    # Create the base dir if it doesn't exist already
    if not os.path.exists(os.path.dirname(dest)):
      os.makedirs(os.path.dirname(dest))

    if self.DoesFileExist(src):
      self.SendCommand("pull %s %s" % (src, dest), timeout_time=60)
      return True
    else:
      logger.Log("ADB Pull Failed: Source file %s does not exist." % src)
      return False
Exemple #8
0
        if runtime_restart:
            self.sendShellCommand("setprop ro.test_harness 1",
                                  retry_count=retry_count)
            # manual rest bootcomplete flag
            self.sendShellCommand("setprop dev.bootcomplete 0",
                                  retry_count=retry_count)
            self.sendShellCommand("stop", retry_count=retry_count)

        try:
            output = self.sendCommand("sync", retry_count=retry_count)
        except AbortError, e:
            error = e
            output = e.msg
        if "Read-only file system" in output:
            logger.SilentLog(output)
            logger.Log("Remounting read-only filesystem")
            self.sendCommand("remount")
            output = self.sendCommand("sync", retry_count=retry_count)
        elif "No space left on device" in output:
            logger.SilentLog(output)
            logger.Log("Restarting device runtime")
            self.sendShellCommand("stop", retry_count=retry_count)
            output = self.sendCommand("sync", retry_count=retry_count)
            self.sendShellCommand("start", retry_count=retry_count)
        elif error is not None:
            # exception occurred that cannot be recovered from
            raise error
        logger.SilentLog(output)
        if runtime_restart:
            # start runtime and wait till boot complete flag is set
            self.sendShellCommand("start", retry_count=retry_count)
  def StartInstrumentation(
      self, instrumentation_path, timeout_time=60*10, no_window_animation=False,
      profile=False, instrumentation_args={}):

    """Runs an instrumentation class on the target.

    Returns a dictionary containing the key value pairs from the
    instrumentations result bundle and a list of TestResults. Also handles the
    interpreting of error output from the device and raises the necessary
    exceptions.

    Args:
      instrumentation_path: string. It should be the fully classified package
      name, and instrumentation test runner, separated by "/"
        e.g. com.android.globaltimelaunch/.GlobalTimeLaunch
      timeout_time: Timeout value for the am command.
      no_window_animation: boolean, Whether you want window animations enabled
        or disabled
      profile: If True, profiling will be turned on for the instrumentation.
      instrumentation_args: Dictionary of key value bundle arguments to pass to
      instrumentation.

    Returns:
      (test_results, inst_finished_bundle)

      test_results: a list of TestResults
      inst_finished_bundle (dict): Key/value pairs contained in the bundle that
        is passed into ActivityManager.finishInstrumentation(). Included in this
        bundle is the return code of the Instrumentation process, any error
        codes reported by the activity manager, and any results explicitly added
        by the instrumentation code.

     Raises:
       WaitForResponseTimedOutError: if timeout occurred while waiting for
         response to adb instrument command
       DeviceUnresponsiveError: if device system process is not responding
       InstrumentationError: if instrumentation failed to run
    """

    command_string = self._BuildInstrumentationCommandPath(
        instrumentation_path, no_window_animation=no_window_animation,
        profile=profile, raw_mode=True,
        instrumentation_args=instrumentation_args)
    logger.Log(command_string)
    (test_results, inst_finished_bundle) = (
        am_instrument_parser.ParseAmInstrumentOutput(
            self.SendShellCommand(command_string, timeout_time=timeout_time,
                                  retry_count=2)))

    if "code" not in inst_finished_bundle:
      raise errors.InstrumentationError("no test results... device setup "
                                        "correctly?")

    if inst_finished_bundle["code"] == "0":
      short_msg_result = "no error message"
      if "shortMsg" in inst_finished_bundle:
        short_msg_result = inst_finished_bundle["shortMsg"]
        logger.Log("Error! Test run failed: %s" % short_msg_result)
      raise errors.InstrumentationError(short_msg_result)

    if "INSTRUMENTATION_ABORTED" in inst_finished_bundle:
      logger.Log("INSTRUMENTATION ABORTED!")
      raise errors.DeviceUnresponsiveError

    return (test_results, inst_finished_bundle)