Beispiel #1
0
 def _CheckInstrumentationInstalled(self, adb):
   if not adb.IsInstrumentationInstalled(self.GetPackageName(),
                                         self.GetRunnerName()):
     msg=("Could not find instrumentation %s/%s on device. Try forcing a "
          "rebuild by updating a source file, and re-executing runtest." %
          (self.GetPackageName(), self.GetRunnerName()))
     raise errors.AbortError(msg=msg)
Beispiel #2
0
 def GetCoverageTarget(self, name):
     """Find the CoverageTarget for given name"""
     target = self._targets_manifest.GetTarget(name)
     if target is None:
         msg = ["Error: test references undefined target %s." % name]
         msg.append(" Ensure target is defined in %s" %
                    self._TARGET_DEF_FILE)
         raise errors.AbortError(msg)
     return target
Beispiel #3
0
 def GetCoverageTargetForPath(self, path):
     """Find the CoverageTarget for given file system path"""
     android_mk_path = os.path.join(path, "Android.mk")
     if os.path.exists(android_mk_path):
         android_mk_parser = android_mk.CreateAndroidMK(path)
         target = coverage_target.CoverageTarget()
         target.SetBuildPath(os.path.join(path, "src"))
         target.SetName(
             android_mk_parser.GetVariable(android_mk_parser.PACKAGE_NAME))
         target.SetType("APPS")
         return target
     else:
         msg = "No Android.mk found at %s" % path
         raise errors.AbortError(msg)
Beispiel #4
0
    def AddPath(self, path):
        """Adds make directory path to tree.

    Will have no effect if path is already included in make set.

    Args:
      path: filesystem path to directory to build, relative to build root.
    """
        path = os.path.normpath(path)
        mk_path = os.path.join(android_build.GetTop(), path, "Android.mk")
        if not os.path.isfile(mk_path):
            raise errors.AbortError("%s does not exist" % mk_path)
        path_segs = path.split(os.sep)
        child = self._AddPath(path_segs)
        child._SetLeaf(True)
Beispiel #5
0
    def Run(self, options, adb_interface):
        """Runs the host test.

    Results will be displayed on stdout. Assumes 'java' is on system path.

    Args:
      options: command line options for running host tests. Expected member
        fields:
        host_lib_path: path to directory that contains host library files
        test_data_path: path to directory that contains test data files
        preview: if true, do not execute, display commands only
      adb_interface: reference to device under test

    Raises:
      errors.AbortError: if fatal error occurs
    """
        # get the serial number of the device under test, so it can be passed to
        # hosttestlib.
        serial_number = adb_interface.GetSerialNumber()
        self._lib_names.append(self.GetJarName())
        # gather all the host jars that are needed to run tests
        full_lib_paths = []
        for lib in self._lib_names:
            path = os.path.join(options.host_lib_path, lib)
            # make sure jar file exists on host
            if not os.path.exists(path):
                raise errors.AbortError(msg="Could not find jar %s" % path)
            full_lib_paths.append(path)

        # java -cp <libs> <runner class> <test suite class> -s <device serial>
        # -p <test data path>
        cmd = "java -cp %s %s %s -s %s -p %s" % (
            ":".join(full_lib_paths), self._TEST_RUNNER, self.GetClassName(),
            serial_number, options.test_data_path)
        logger.Log(cmd)
        if not options.preview:
            run_command.RunOnce(cmd, return_output=False)
                and time.time() > start_time + timeout_time):
            try:
                os.kill(pid[0], signal.SIGKILL)
            except OSError:
                # process already dead. No action required.
                pass

            logger.SilentLog("about to raise a timeout for: %s" % cmd)
            raise errors.WaitForResponseTimedOutError
        if not break_loop:
            time.sleep(0.1)

    t.join()
    output = "".join(so)
    if _abort_on_error and error_occurred:
        raise errors.AbortError(msg=output)

    return "".join(so)


def RunHostCommand(binary, valgrind=False):
    """Run a command on the host (opt using valgrind).

  Runs the host binary and returns the exit code.
  If successfull, the output (stdout and stderr) are discarded,
  but printed in case of error.
  The command can be run under valgrind in which case all the
  output are always discarded.

  Args:
    binary: full path of the file to be run.