Esempio n. 1
0
    def ConfirmLaunch(self, wait_for_boot=False):
        """Confirm the emulator launched properly.

    Loop on a wait-for-device with a very small timeout.  On each
    timeout, check the emulator process is still alive.
    After confirming a wait-for-device can be successful, make sure
    it returns the right answer.
    """
        seconds_waited = 0
        number_of_waits = 2  # Make sure we can wfd twice
        adb_cmd = "adb -s %s %s" % (self.device, 'wait-for-device')
        while seconds_waited < self._LAUNCH_TIMEOUT:
            try:
                run_command.RunCommand(
                    adb_cmd,
                    timeout_time=self._WAITFORDEVICE_TIMEOUT,
                    retry_count=1)
                number_of_waits -= 1
                if not number_of_waits:
                    break
            except errors.WaitForResponseTimedOutError as e:
                seconds_waited += self._WAITFORDEVICE_TIMEOUT
                adb_cmd = "adb -s %s %s" % (self.device, 'kill-server')
                run_command.RunCommand(adb_cmd)
            self.popen.poll()
            if self.popen.returncode != None:
                raise EmulatorLaunchException('EMULATOR DIED')
        if seconds_waited >= self._LAUNCH_TIMEOUT:
            raise EmulatorLaunchException('TIMEOUT with wait-for-device')
        logging.info('Seconds waited on wait-for-device: %d', seconds_waited)
        if wait_for_boot:
            # Now that we checked for obvious problems, wait for a boot complete.
            # Waiting for the package manager is sometimes problematic.
            a = android_commands.AndroidCommands(self.device)
            a.WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT)
Esempio n. 2
0
  def _DoBuild(self):
    logger.SilentLog("Building tests...")

    tests = self._GetTestsToRun()
    # turn off dalvik verifier if necessary
    self._TurnOffVerifier(tests)
    self._DoFullBuild(tests)

    target_set = []

    extra_args_set = []
    for test_suite in tests:
      self._AddBuildTarget(test_suite, target_set, extra_args_set)

    if not self._options.preview:
      self._adb.EnableAdbRoot()
    else:
      logger.Log("adb root")
    rebuild_libcore = False
    if target_set:
      if self._options.coverage:
        coverage.EnableCoverageBuild()
        # hack to remove core library intermediates
        # hack is needed because:
        # 1. EMMA_INSTRUMENT changes what source files to include in libcore
        #    but it does not trigger a rebuild
        # 2. there's no target (like "clear-intermediates") to remove the files
        #    decently
        rebuild_libcore = not coverage.TestDeviceCoverageSupport(self._adb)
        if rebuild_libcore:
          cmd = "rm -rf %s" % os.path.join(
              self._root_path,
              "out/target/common/obj/JAVA_LIBRARIES/core_intermediates/")
          logger.Log(cmd)
          run_command.RunCommand(cmd, return_output=False)

      target_build_string = " ".join(target_set)
      extra_args_string = " ".join(extra_args_set)

      # mmm cannot be used from python, so perform a similar operation using
      # ONE_SHOT_MAKEFILE
      cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" all_modules %s' % (
          target_build_string, self._options.make_jobs, self._root_path,
          extra_args_string)
      logger.Log(cmd)

      if self._options.preview:
        # in preview mode, just display to the user what command would have been
        # run
        logger.Log("adb sync")
      else:
        # set timeout for build to 10 minutes, since libcore may need to
        # be rebuilt
        run_command.RunCommand(cmd, return_output=False, timeout_time=600)
        logger.Log("Syncing to device...")
        self._adb.Sync(runtime_restart=rebuild_libcore)
Esempio n. 3
0
    def _DoFullBuild(self, tests, test_requires_permissions):
        """If necessary, run a full 'make' command for the tests that need it."""
        extra_args_set = Set()

        for test in tests:
            if test.IsFullMake() and test.IsGrantedPermissions(
            ) == test_requires_permissions:
                if test.GetExtraBuildArgs():
                    # extra args contains the args to pass to 'make'
                    extra_args_set.add(test.GetExtraBuildArgs())
                else:
                    logger.Log(
                        "Warning: test %s needs a full build but does not specify"
                        " extra_build_args" % test.GetName())

        # check if there is actually any tests that required a full build
        if extra_args_set:
            cmd = ('make -j%s %s' %
                   (self._options.make_jobs, ' '.join(list(extra_args_set))))
            logger.Log(cmd)
            if not self._options.preview:
                old_dir = os.getcwd()
                os.chdir(self._root_path)
                output = run_command.RunCommand(cmd, return_output=True)
                logger.SilentLog(output)
                os.chdir(old_dir)
                self._DoInstall(output, test_requires_permissions)
Esempio n. 4
0
    def _DoFullBuild(self, tests):
        """If necessary, run a full 'make' command for the tests that need it."""
        extra_args_set = Set()

        # hack to build cts dependencies
        # TODO: remove this when cts dependencies are removed
        if self._IsCtsTests(tests):
            # need to use make since these fail building with ONE_SHOT_MAKEFILE
            extra_args_set.add('CtsTestStubs')
            extra_args_set.add('android.core.tests.runner')
        for test in tests:
            if test.IsFullMake():
                if test.GetExtraBuildArgs():
                    # extra args contains the args to pass to 'make'
                    extra_args_set.add(test.GetExtraBuildArgs())
                else:
                    logger.Log(
                        "Warning: test %s needs a full build but does not specify"
                        " extra_build_args" % test.GetName())

        # check if there is actually any tests that required a full build
        if extra_args_set:
            cmd = ('make -j%s %s' %
                   (self._options.make_jobs, ' '.join(list(extra_args_set))))
            logger.Log(cmd)
            if not self._options.preview:
                old_dir = os.getcwd()
                os.chdir(self._root_path)
                output = run_command.RunCommand(cmd, return_output=True)
                os.chdir(old_dir)
                self._DoInstall(output)
Esempio n. 5
0
    def Run(self, options, adb):
        """Run the provided gtest test suite.

    Args:
      options: command line options
      adb: adb interface
    """

        test_class = "*"
        test_method = "*"
        if options.test_class is not None:
            test_class = options.test_class.lstrip()
        if options.test_method is not None:
            test_method = options.test_method.lstrip()
        filter_arg = ""
        if test_class != "*" or test_method != "*":
            filter_arg = "--gtest_filter=%s.%s" % (test_class, test_method)

        shell_cmd = adb.PreviewShellCommand(" ".join(
            (self.GetTargetExecPath(), filter_arg)))
        logger.Log(shell_cmd)
        if not options.preview:
            # gtest will log to test results to stdout, so no need to do any
            # extra processing
            run_command.RunCommand(shell_cmd, return_output=False)
Esempio n. 6
0
  def _DoBuild(self):
    logger.SilentLog("Building tests...")
    target_set = Set()
    extra_args_set = Set()
    tests = self._GetTestsToRun()
    for test_suite in tests:
      self._AddBuildTarget(test_suite, target_set, extra_args_set)

    if target_set:
      if self._options.coverage:
        coverage.EnableCoverageBuild()

      # hack to build cts dependencies
      # TODO: remove this when build dependency support added to runtest or
      # cts dependencies are removed
      if self._IsCtsTests(tests):
        # need to use make since these fail building with ONE_SHOT_MAKEFILE
        cmd = ('make -j%s CtsTestStubs android.core.tests.runner' %
               self._options.make_jobs)
        logger.Log(cmd)
        if not self._options.preview:
          old_dir = os.getcwd()
          os.chdir(self._root_path)
          run_command.RunCommand(cmd, return_output=False)
          os.chdir(old_dir)
      target_build_string = " ".join(list(target_set))
      extra_args_string = " ".join(list(extra_args_set))
      # mmm cannot be used from python, so perform a similar operation using
      # ONE_SHOT_MAKEFILE
      cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" files %s' % (
          target_build_string, self._options.make_jobs, self._root_path,
          extra_args_string)
      logger.Log(cmd)

      if self._options.preview:
        # in preview mode, just display to the user what command would have been
        # run
        logger.Log("adb sync")
      else:
        run_command.RunCommand(cmd, return_output=False)
        logger.Log("Syncing to device...")
        self._adb.Sync()
Esempio n. 7
0
    def Run(self, options, adb):
        """Run the provided gtest test suite.

    Args:
      options: command line options
      adb: adb interface
    """
        shell_cmd = adb.PreviewShellCommand(self.GetTargetExecPath())
        logger.Log(shell_cmd)
        if not options.preview:
            # gtest will log to test results to stdout, so no need to do any
            # extra processing
            run_command.RunCommand(shell_cmd, return_output=False)
Esempio n. 8
0
  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)
Esempio n. 9
0
 def SendCommand(self, command_string, timeout_time=1, retry_count=3):
     """
     发送adb命令行
      args:
     - command_string -: 命令字符串
     - timeout_time -: 延迟
     - retry_count -: 重试次数
      usage: SendCommand("devices")
     """
     adb_cmd = "adb %s %s" % (self._target_arg, command_string)
     logger.SilentLog("about to run %s" % adb_cmd)
     return run_command.RunCommand(adb_cmd,
                                   timeout_time=timeout_time,
                                   retry_count=retry_count)
Esempio n. 10
0
  def SendCommand(self, command_string, timeout_time=60, retry_count=3):
    """Send a command via adb.

    Args:
      command_string: adb command to run
      timeout_time: number of seconds to wait for command to respond before
        retrying
      retry_count: number of times to retry command before raising
        WaitForResponseTimedOutError
    Returns:
      string output of command

    Raises:
      WaitForResponseTimedOutError if device does not respond to command within time
    """
    adb_cmd = "adb %s %s" % (self._target_arg, command_string)
    logger.SilentLog("about to run %s" % adb_cmd)
    return run_command.RunCommand(adb_cmd, timeout_time=timeout_time,
                                  retry_count=retry_count)
Esempio n. 11
0
    def _DoBuild(self):
        logger.SilentLog("Building tests...")

        tests = self._GetTestsToRun()
        # turn off dalvik verifier if necessary
        self._TurnOffVerifier(tests)
        self._DoFullBuild(tests)

        target_tree = make_tree.MakeTree()

        extra_args_set = []
        for test_suite in tests:
            self._AddBuildTarget(test_suite, target_tree, extra_args_set)

        if not self._options.preview:
            self._adb.EnableAdbRoot()
        else:
            logger.Log("adb root")

        if not target_tree.IsEmpty():
            if self._options.coverage:
                coverage.EnableCoverageBuild()
                target_tree.AddPath("external/emma")

            target_list = target_tree.GetPrunedMakeList()
            target_build_string = " ".join(target_list)
            extra_args_string = " ".join(extra_args_set)

            # mmm cannot be used from python, so perform a similar operation using
            # ONE_SHOT_MAKEFILE
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" GET-INSTALL-PATH all_modules %s' % (
                target_build_string, self._options.make_jobs, self._root_path,
                extra_args_string)
            logger.Log(cmd)
            if not self._options.preview:
                output = run_command.RunCommand(cmd,
                                                return_output=True,
                                                timeout_time=600)
                logger.SilentLog(output)
                self._DoInstall(output)
Esempio n. 12
0
    def _DoBuild(self):
        logger.SilentLog("Building tests...")
        target_set = Set()
        for test_suite in self._GetTestsToRun():
            self._AddBuildTarget(test_suite.GetBuildPath(), target_set)

        if target_set:
            if self._options.coverage:
                self._coverage_gen.EnableCoverageBuild()
                self._AddBuildTarget(self._coverage_gen.GetEmmaBuildPath(),
                                     target_set)
            target_build_string = " ".join(list(target_set))
            logger.Log("mmm %s" % target_build_string)
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -C "%s" files' % (
                target_build_string, self._root_path)
            if self._options.preview:
                # in preview mode, just display to the user what command would have been
                # run
                logger.Log("adb sync")
            else:
                run_command.RunCommand(cmd, return_output=False)
                logger.Log("Syncing to device...")
                self._adb.Sync()
Esempio n. 13
0
    def _DoPermissionAwareBuild(self, tests, test_requires_permissions):
        # turn off dalvik verifier if necessary
        # TODO: skip turning off verifier for now, since it puts device in bad
        # state b/14088982
        #self._TurnOffVerifier(tests)
        self._DoFullBuild(tests, test_requires_permissions)

        target_tree = make_tree.MakeTree()

        extra_args_set = []
        for test_suite in tests:
            if test_suite.IsGrantedPermissions() == test_requires_permissions:
                self._AddBuildTarget(test_suite, target_tree, extra_args_set)

        if not self._options.preview:
            self._adb.EnableAdbRoot()
        else:
            logger.Log("adb root")

        if not target_tree.IsEmpty():
            if self._options.coverage:
                coverage.EnableCoverageBuild()
                target_tree.AddPath("external/emma")

            target_list = target_tree.GetPrunedMakeList()
            target_dir_list = [
                re.sub(r'Android[.]mk$', r'', i) for i in target_list
            ]
            target_build_string = " ".join(target_list)
            target_dir_build_string = " ".join(target_dir_list)
            extra_args_string = " ".join(extra_args_set)

            install_path_goals = []
            mmma_goals = []
            for d in target_dir_list:
                if d.startswith("./"):
                    d = d[2:]
                if d.endswith("/"):
                    d = d[:-1]
                install_path_goals.append("GET-INSTALL-PATH-IN-" +
                                          d.replace("/", "-"))
                mmma_goals.append("MODULES-IN-" + d.replace("/", "-"))
            # mmm cannot be used from python, so perform a similar operation using
            # ONE_SHOT_MAKEFILE
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" %s %s %s' % (
                target_build_string, self._options.make_jobs, self._root_path,
                " ".join(install_path_goals), " ".join(mmma_goals),
                extra_args_string)
            # mmma cannot be used from python, so perform a similar operation
            alt_cmd = 'make -j%s -C "%s" -f build/core/main.mk %s %s' % (
                self._options.make_jobs, self._root_path, extra_args_string,
                " ".join(mmma_goals))

            logger.Log(cmd)
            if not self._options.preview:
                run_command.SetAbortOnError()
                try:
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                    ## Chances are this failed because it didn't build the dependencies
                except errors.AbortError:
                    logger.Log(
                        "make failed. Trying to rebuild all dependencies.")
                    logger.Log(
                        "mmma -j%s %s" %
                        (self._options.make_jobs, target_dir_build_string))
                    # Try again with mma equivalent, which will build the dependencies
                    run_command.RunCommand(alt_cmd,
                                           return_output=False,
                                           timeout_time=600)
                    # Run mmm again to get the install paths only
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                run_command.SetAbortOnError(False)
                logger.SilentLog(output)
                self._DoInstall(output, test_requires_permissions)
Esempio n. 14
0
 def _RunCmd(self, cmd):
     """Runs and logs the given os command."""
     run_command.RunCommand(cmd, return_output=False)
Esempio n. 15
0
    def _DoBuild(self):
        logger.SilentLog("Building tests...")

        tests = self._GetTestsToRun()
        # turn off dalvik verifier if necessary
        # TODO: skip turning off verifier for now, since it puts device in bad
        # state b/14088982
        #self._TurnOffVerifier(tests)
        self._DoFullBuild(tests)

        target_tree = make_tree.MakeTree()

        extra_args_set = []
        for test_suite in tests:
            self._AddBuildTarget(test_suite, target_tree, extra_args_set)

        if not self._options.preview:
            self._adb.EnableAdbRoot()
        else:
            logger.Log("adb root")

        if not target_tree.IsEmpty():
            if self._options.coverage:
                coverage.EnableCoverageBuild()
                target_tree.AddPath("external/emma")

            target_list = target_tree.GetPrunedMakeList()
            target_dir_list = [
                re.sub(r'Android[.]mk$', r'', i) for i in target_list
            ]
            target_build_string = " ".join(target_list)
            target_dir_build_string = " ".join(target_dir_list)
            extra_args_string = " ".join(extra_args_set)

            # mmm cannot be used from python, so perform a similar operation using
            # ONE_SHOT_MAKEFILE
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" GET-INSTALL-PATH all_modules %s' % (
                target_build_string, self._options.make_jobs, self._root_path,
                extra_args_string)
            # mmma equivalent, used when regular mmm fails
            alt_cmd = 'make -j%s -C "%s" -f build/core/main.mk %s all_modules BUILD_MODULES_IN_PATHS="%s"' % (
                self._options.make_jobs, self._root_path, extra_args_string,
                target_dir_build_string)

            logger.Log(cmd)
            if not self._options.preview:
                run_command.SetAbortOnError()
                try:
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                    ## Chances are this failed because it didn't build the dependencies
                except errors.AbortError:
                    logger.Log(
                        "make failed. Trying to rebuild all dependencies.")
                    logger.Log(
                        "mmma -j%s %s" %
                        (self._options.make_jobs, target_dir_build_string))
                    # Try again with mma equivalent, which will build the dependencies
                    run_command.RunCommand(alt_cmd,
                                           return_output=False,
                                           timeout_time=600)
                    # Run mmm again to get the install paths only
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                run_command.SetAbortOnError(False)
                logger.SilentLog(output)
                self._DoInstall(output)