Exemplo n.º 1
0
  def _RunHostCommand(self, 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: basename of the file to be run. It is expected to be under
            out/host/<os>-<arch>/bin.
      valgrind: If True the command will be run under valgrind.

    Returns:
      The command exit code (int)
    """
    full_path = os.path.join(android_build.GetHostBin(), binary)
    return run_command.RunHostCommand(full_path, valgrind=valgrind)
Exemplo n.º 2
0
  def Run(self, options, adb):
    """Run the provided *native* test suite.

    The test_suite must contain a build path where the native test
    files are. Subdirectories are automatically scanned as well.

    Each test's name must have a .cc or .cpp extension and match one
    of the following patterns:
      - test_*
      - *_test.[cc|cpp]
      - *_unittest.[cc|cpp]
    A successful test must return 0. Any other value will be considered
    as an error.

    Args:
      options: command line options
      adb: adb interface
    """
    # find all test files, convert unicode names to ascii, take the basename
    # and drop the .cc/.cpp  extension.
    source_list = []
    build_path = os.path.join(android_build.GetTop(), self.GetBuildPath())
    os.path.walk(build_path, self._CollectTestSources, source_list)
    logger.SilentLog("Tests source %s" % source_list)

    # Host tests are under out/host/<os>-<arch>/bin.
    host_list = self._FilterOutMissing(android_build.GetHostBin(), source_list)
    logger.SilentLog("Host tests %s" % host_list)

    # Target tests are under $ANDROID_PRODUCT_OUT/system/bin.
    target_list = self._FilterOutMissing(android_build.GetTargetSystemBin(),
                                         source_list)
    logger.SilentLog("Target tests %s" % target_list)

    # Run on the host
    logger.Log("\nRunning on host")
    for f in host_list:
      if run_command.RunHostCommand(f) != 0:
        logger.Log("%s... failed" % f)
      else:
        if run_command.HasValgrind():
          if run_command.RunHostCommand(f, valgrind=True) == 0:
            logger.Log("%s... ok\t\t[valgrind: ok]" % f)
          else:
            logger.Log("%s... ok\t\t[valgrind: failed]" % f)
        else:
          logger.Log("%s... ok\t\t[valgrind: missing]" % f)

    # Run on the device
    logger.Log("\nRunning on target")
    for f in target_list:
      full_path = os.path.join(os.sep, "system", "bin", f)

      # Single quotes are needed to prevent the shell splitting it.
      output = adb.SendShellCommand("'%s 2>&1;echo -n exit code:$?'" %
                                    "(cd /sdcard;%s)" % full_path,
                                    int(options.timeout))
      success = output.endswith("exit code:0")
      logger.Log("%s... %s" % (f, success and "ok" or "failed"))
      # Print the captured output when the test failed.
      if not success or options.verbose:
        pos = output.rfind("exit code")
        output = output[0:pos]
        logger.Log(output)

      # Cleanup
      adb.SendShellCommand("rm %s" % full_path)