Exemplo n.º 1
0
def main():
  parser = argparse.ArgumentParser(description="A test runner for application "
                                               "tests.")

  parser.add_argument("--verbose", help="be verbose (multiple times for more)",
                      default=0, dest="verbose_count", action="count")
  parser.add_argument("test_list_file", type=str,
                      help="a file listing apptests to run")
  parser.add_argument("build_dir", type=str,
                      help="the build output directory")
  args = parser.parse_args()

  InitLogging(args.verbose_count)
  config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
  paths = Paths(config)
  command_line = [os.path.join(os.path.dirname(__file__), os.path.pardir,
                               "devtools", "common", "mojo_test"),
                  str(args.test_list_file)]

  if config.target_os == Config.OS_ANDROID:
    command_line.append("--android")
    command_line.append("--adb-path=" + paths.adb_path)
    command_line.append("--origin=" + paths.build_dir)

  command_line.append("--shell-path=" + paths.target_mojo_shell_path)
  if args.verbose_count:
    command_line.append("--verbose")

  gtest.set_color()
  print "Running " + str(command_line)
  ret = subprocess.call(command_line)
  return ret
Exemplo n.º 2
0
def main():
  parser = argparse.ArgumentParser(description="A test runner for application "
                                               "tests.")

  parser.add_argument("--verbose", help="be verbose (multiple times for more)",
                      default=0, dest="verbose_count", action="count")
  parser.add_argument("test_list_file", type=file,
                      help="a file listing apptests to run")
  parser.add_argument("build_dir", type=str,
                      help="the build output directory")
  args = parser.parse_args()

  InitLogging(args.verbose_count)
  config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
  paths = Paths(config)
  extra_args = []
  if config.target_os == Config.OS_ANDROID:
    shell = AndroidShell(paths.adb_path)
    device_status, error = shell.CheckDevice()
    if not device_status:
      print 'Device check failed: ' + error
      return 1
    shell.InstallApk(paths.target_mojo_shell_path)
    extra_args.extend(shell_arguments.ConfigureLocalOrigin(
        shell, paths.build_dir, fixed_port=True))
  else:
    shell = LinuxShell(paths.mojo_shell_path)

  gtest.set_color()

  test_list_globals = {"config": config}
  exec args.test_list_file in test_list_globals
  apptests_result = run_apptests(shell, extra_args, test_list_globals["tests"])
  return 0 if apptests_result else 1
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(
        description="A test runner for application "
        "tests.")

    parser.add_argument("--verbose",
                        help="be verbose (multiple times for more)",
                        default=0,
                        dest="verbose_count",
                        action="count")
    parser.add_argument("test_list_file",
                        type=file,
                        help="a file listing apptests to run")
    parser.add_argument("build_dir",
                        type=str,
                        help="the build output directory")
    args = parser.parse_args()

    InitLogging(args.verbose_count)
    config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
    paths = Paths(config)
    extra_args = []
    if config.target_os == Config.OS_ANDROID:
        shell = AndroidShell(paths.adb_path)
        device_status, error = shell.CheckDevice()
        if not device_status:
            print 'Device check failed: ' + error
            return 1
        shell.InstallApk(paths.target_mojo_shell_path)
        extra_args.extend(
            shell_arguments.ConfigureLocalOrigin(shell,
                                                 paths.build_dir,
                                                 fixed_port=True))
    else:
        shell = LinuxShell(paths.mojo_shell_path)

    gtest.set_color()

    test_list_globals = {"config": config}
    exec args.test_list_file in test_list_globals
    apptests_result = run_apptests(shell, extra_args,
                                   test_list_globals["tests"])
    return 0 if apptests_result else 1
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description="A test runner for application "
        "tests.")

    parser.add_argument("--verbose",
                        help="be verbose (multiple times for more)",
                        default=0,
                        dest="verbose_count",
                        action="count")
    parser.add_argument("test_list_file",
                        type=str,
                        help="a file listing apptests to run")
    parser.add_argument("build_dir",
                        type=str,
                        help="the build output directory")
    args = parser.parse_args()

    InitLogging(args.verbose_count)
    config = ConfigForGNArgs(ParseGNConfig(args.build_dir))
    paths = Paths(config)
    command_line = [
        os.path.join(os.path.dirname(__file__), os.path.pardir, "devtools",
                     "common", "mojo_test"),
        str(args.test_list_file)
    ]

    if config.target_os == Config.OS_ANDROID:
        command_line.append("--android")
        command_line.append("--adb-path=" + paths.adb_path)
        command_line.append("--origin=" + paths.build_dir)

    command_line.append("--shell-path=" + paths.target_mojo_shell_path)
    if args.verbose_count:
        command_line.append("--verbose")

    gtest.set_color()
    print "Running " + str(command_line)
    ret = subprocess.call(command_line)
    return ret
Exemplo n.º 5
0
def main():
  parser = argparse.ArgumentParser(description='An application test runner.')
  parser.add_argument('build_dir', type=str, help='The build output directory.')
  parser.add_argument('--verbose', default=False, action='store_true',
                      help='Print additional logging information.')
  parser.add_argument('--repeat-count', default=1, metavar='INT',
                      action='store', type=int,
                      help='The number of times to repeat the set of tests.')
  parser.add_argument('--write-full-results-to', metavar='FILENAME',
                      help='The path to write the JSON list of full results.')
  parser.add_argument('--test-list-file', metavar='FILENAME', type=file,
                      default=APPTESTS, help='The file listing tests to run.')
  args = parser.parse_args()

  gtest.set_color()
  logger = logging.getLogger()
  logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s')
  logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
  logger.debug('Initialized logging: level=%s' % logger.level)

  logger.debug('Test list file: %s', args.test_list_file)
  config = Config(args.build_dir, is_verbose=args.verbose,
                  apk_name='MojoRunnerApptests.apk')
  execution_globals = {'config': config}
  exec args.test_list_file in execution_globals
  test_list = execution_globals['tests']
  logger.debug('Test list: %s' % test_list)

  shell = None
  if config.target_os == Config.OS_ANDROID:
    from mopy.android import AndroidShell
    shell = AndroidShell(config)
    result = shell.InitShell()
    if result != 0:
      return result

  tests = []
  failed = []
  failed_suites = 0
  for _ in range(args.repeat_count):
    for test_dict in test_list:
      test = test_dict['test']
      test_name = test_dict.get('name', test)
      test_type = test_dict.get('type', 'gtest')
      test_args = test_dict.get('args', [])

      print 'Running %s...%s' % (test_name, ('\n' if args.verbose else '')),
      sys.stdout.flush()

      assert test_type in ('gtest', 'gtest_isolated')
      isolate = test_type == 'gtest_isolated'
      (test, fail) = gtest.run_apptest(config, shell, test_args, test, isolate)
      tests.extend(test)
      failed.extend(fail)
      result = test and not fail
      print '[  PASSED  ]' if result else '[  FAILED  ]',
      print test_name if args.verbose or not result else ''
      # Abort when 3 apptest suites, or a tenth of all, have failed.
      # base::TestLauncher does this for timeouts and unknown results.
      failed_suites += 0 if result else 1
      if failed_suites >= max(3, len(test_list) / 10):
        print 'Too many failing suites (%d), exiting now.' % failed_suites
        failed.append('Test runner aborted for excessive failures.')
        break;

    if failed:
      break;

  print '[==========] %d tests ran.' % len(tests)
  print '[  PASSED  ] %d tests.' % (len(tests) - len(failed))
  if failed:
    print '[  FAILED  ] %d tests, listed below:' % len(failed)
    for failure in failed:
      print '[  FAILED  ] %s' % failure

  if args.write_full_results_to:
    _WriteJSONResults(tests, failed, args.write_full_results_to)

  return 1 if failed else 0
Exemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser(description="An application test runner.")
    parser.add_argument("build_dir",
                        type=str,
                        help="The build output directory.")
    parser.add_argument("--verbose",
                        default=False,
                        action='store_true',
                        help="Print additional logging information.")
    parser.add_argument('--repeat-count',
                        default=1,
                        metavar='INT',
                        action='store',
                        type=int,
                        help="The number of times to repeat the set of tests.")
    parser.add_argument(
        '--write-full-results-to',
        metavar='FILENAME',
        help='The path to write the JSON list of full results.')
    parser.add_argument("--test-list-file",
                        metavar='FILENAME',
                        type=file,
                        default=os.path.abspath(
                            os.path.join(__file__, os.pardir, "data",
                                         "apptests")),
                        help="The file listing apptests to run.")
    args = parser.parse_args()

    gtest.set_color()
    logger = logging.getLogger()
    logging.basicConfig(stream=sys.stdout, format="%(levelname)s:%(message)s")
    logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
    logger.debug("Initialized logging: level=%s" % logger.level)

    logger.debug("Test list file: %s", args.test_list_file)
    config = Config(args.build_dir)
    execution_globals = {"config": config}
    exec args.test_list_file in execution_globals
    test_list = execution_globals["tests"]
    logger.debug("Test list: %s" % test_list)

    shell = None
    if config.target_os == Config.OS_ANDROID:
        from mopy.android import AndroidShell
        shell = AndroidShell(config)
        result = shell.InitShell()
        if result != 0:
            return result

    tests = []
    failed = []
    failed_suites = 0
    for _ in range(args.repeat_count):
        for test_dict in test_list:
            test = test_dict["test"]
            test_name = test_dict.get("name", test)
            test_type = test_dict.get("type", "gtest")
            test_args = test_dict.get("args", [])

            print "Running %s...%s" % (test_name,
                                       ("\n" if args.verbose else "")),
            sys.stdout.flush()

            assert test_type in ("gtest", "gtest_isolated")
            isolate = test_type == "gtest_isolated"
            (test, fail) = gtest.run_apptest(config, shell, test_args, test,
                                             isolate)
            tests.extend(test)
            failed.extend(fail)
            result = test and not fail
            print "[  PASSED  ]" if result else "[  FAILED  ]",
            print test_name if args.verbose or not result else ""
            # Abort when 3 apptest suites, or a tenth of all, have failed.
            # base::TestLauncher does this for timeouts and unknown results.
            failed_suites += 0 if result else 1
            if failed_suites >= max(3, len(test_list) / 10):
                print "Too many failing suites (%d), exiting now." % failed_suites
                failed.append("Test runner aborted for excessive failures.")
                break

        if failed:
            break

    print "[==========] %d tests ran." % len(tests)
    print "[  PASSED  ] %d tests." % (len(tests) - len(failed))
    if failed:
        print "[  FAILED  ] %d tests, listed below:" % len(failed)
        for failure in failed:
            print "[  FAILED  ] %s" % failure

    if args.write_full_results_to:
        _WriteJSONResults(tests, failed, args.write_full_results_to)

    return 1 if failed else 0
Exemplo n.º 7
0
def main():
  parser = argparse.ArgumentParser(description="A test runner for application "
                                               "tests.")

  parser.add_argument("--verbose", help="be verbose (multiple times for more)",
                      default=0, dest="verbose_count", action="count")
  parser.add_argument("test_list_file", type=file,
                      help="a file listing apptests to run")
  parser.add_argument("build_dir", type=str,
                      help="the build output directory")
  args = parser.parse_args()

  InitLogging(args.verbose_count)
  config = ConfigForGNArgs(ParseGNConfig(args.build_dir))

  _logger.debug("Test list file: %s", args.test_list_file)
  execution_globals = {"config": config}
  exec args.test_list_file in execution_globals
  test_list = execution_globals["tests"]
  _logger.debug("Test list: %s" % test_list)

  extra_args = []
  if config.target_os == Config.OS_ANDROID:
    paths = Paths(config)
    shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir,
                         paths.adb_path)
    extra_args.extend(shell.PrepareShellRun(fixed_port=False))
  else:
    shell = None

  gtest.set_color()

  exit_code = 0
  for test_dict in test_list:
    test = test_dict["test"]
    test_name = test_dict.get("name", test)
    test_type = test_dict.get("type", "gtest")
    test_args = test_dict.get("test-args", [])
    shell_args = test_dict.get("shell-args", []) + extra_args

    _logger.info("Will start: %s" % test_name)
    print "Running %s...." % test_name,
    sys.stdout.flush()

    if test_type == "dart":
      apptest_result = dart_apptest.run_test(config, shell, test_dict,
                                             shell_args, {test: test_args})
    elif test_type == "gtest":
      apptest_result = gtest.run_fixtures(config, shell, test_dict,
                                          test, False,
                                          test_args, shell_args)
    elif test_type == "gtest_isolated":
      apptest_result = gtest.run_fixtures(config, shell, test_dict,
                                          test, True, test_args, shell_args)
    else:
      apptest_result = "Invalid test type in %r" % test_dict

    if apptest_result != "Succeeded":
      exit_code = 1
    print apptest_result
    _logger.info("Completed: %s" % test_name)

  return exit_code
Exemplo n.º 8
0
def main():
  parser = argparse.ArgumentParser(description="An application test runner.")
  parser.add_argument("build_dir", type=str, help="The build output directory.")
  parser.add_argument("--verbose", default=False, action='store_true',
                      help="Print additional logging information.")
  parser.add_argument('--repeat-count', default=1, metavar='INT',
                      action='store', type=int,
                      help="The number of times to repeat the set of tests.")
  parser.add_argument('--write-full-results-to', metavar='FILENAME',
                      help='The path to write the JSON list of full results.')
  parser.add_argument("--test-list-file", metavar='FILENAME', type=file,
                      default=os.path.abspath(os.path.join(__file__, os.pardir,
                                                           "data", "apptests")),
                      help="The file listing apptests to run.")
  args = parser.parse_args()

  gtest.set_color()
  logger = logging.getLogger()
  logging.basicConfig(stream=sys.stdout, format="%(levelname)s:%(message)s")
  logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
  logger.debug("Initialized logging: level=%s" % logger.level)

  logger.debug("Test list file: %s", args.test_list_file)
  config = Config(args.build_dir)
  execution_globals = {"config": config}
  exec args.test_list_file in execution_globals
  test_list = execution_globals["tests"]
  logger.debug("Test list: %s" % test_list)

  shell = None
  if config.target_os == Config.OS_ANDROID:
    from mopy.android import AndroidShell
    shell = AndroidShell(config)
    result = shell.InitShell()
    if result != 0:
      return result

  tests = []
  failed = []
  failed_suites = 0
  for _ in range(args.repeat_count):
    for test_dict in test_list:
      test = test_dict["test"]
      test_name = test_dict.get("name", test)
      test_type = test_dict.get("type", "gtest")
      test_args = test_dict.get("args", [])

      print "Running %s...%s" % (test_name, ("\n" if args.verbose else "")),
      sys.stdout.flush()

      assert test_type in ("gtest", "gtest_isolated")
      isolate = test_type == "gtest_isolated"
      (test, fail) = gtest.run_apptest(config, shell, test_args, test, isolate)
      tests.extend(test)
      failed.extend(fail)
      result = test and not fail
      print "[  PASSED  ]" if result else "[  FAILED  ]",
      print test_name if args.verbose or not result else ""
      # Abort when 3 apptest suites, or a tenth of all, have failed.
      # base::TestLauncher does this for timeouts and unknown results.
      failed_suites += 0 if result else 1
      if failed_suites >= max(3, len(test_list) / 10):
        print "Too many failing suites (%d), exiting now." % failed_suites
        failed.append("Test runner aborted for excessive failures.")
        break;

    if failed:
      break;

  print "[==========] %d tests ran." % len(tests)
  print "[  PASSED  ] %d tests." % (len(tests) - len(failed))
  if failed:
    print "[  FAILED  ] %d tests, listed below:" % len(failed)
    for failure in failed:
      print "[  FAILED  ] %s" % failure

  if args.write_full_results_to:
    _WriteJSONResults(tests, failed, args.write_full_results_to)

  return 1 if failed else 0
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser(description='An application test runner.')
    parser.add_argument('build_dir',
                        type=str,
                        help='The build output directory.')
    parser.add_argument('--verbose',
                        default=False,
                        action='store_true',
                        help='Print additional logging information.')
    parser.add_argument('--repeat-count',
                        default=1,
                        metavar='INT',
                        action='store',
                        type=int,
                        help='The number of times to repeat the set of tests.')
    parser.add_argument(
        '--write-full-results-to',
        metavar='FILENAME',
        help='The path to write the JSON list of full results.')
    parser.add_argument('--test-list-file',
                        metavar='FILENAME',
                        type=file,
                        default=APPTESTS,
                        help='The file listing tests to run.')
    args = parser.parse_args()

    gtest.set_color()
    logger = logging.getLogger()
    logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s')
    logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
    logger.debug('Initialized logging: level=%s' % logger.level)

    logger.debug('Test list file: %s', args.test_list_file)
    config = Config(args.build_dir,
                    is_verbose=args.verbose,
                    apk_name='MojoRunnerApptests.apk')
    execution_globals = {'config': config}
    exec args.test_list_file in execution_globals
    test_list = execution_globals['tests']
    logger.debug('Test list: %s' % test_list)

    shell = None
    if config.target_os == Config.OS_ANDROID:
        from mopy.android import AndroidShell
        shell = AndroidShell(config)
        result = shell.InitShell()
        if result != 0:
            return result

    tests = []
    failed = []
    failed_suites = 0
    for _ in range(args.repeat_count):
        for test_dict in test_list:
            test = test_dict['test']
            test_name = test_dict.get('name', test)
            test_type = test_dict.get('type', 'gtest')
            test_args = test_dict.get('args', [])

            print 'Running %s...%s' % (test_name,
                                       ('\n' if args.verbose else '')),
            sys.stdout.flush()

            assert test_type in ('gtest', 'gtest_isolated')
            isolate = test_type == 'gtest_isolated'
            (test, fail) = gtest.run_apptest(config, shell, test_args, test,
                                             isolate)
            tests.extend(test)
            failed.extend(fail)
            result = test and not fail
            print '[  PASSED  ]' if result else '[  FAILED  ]',
            print test_name if args.verbose or not result else ''
            # Abort when 3 apptest suites, or a tenth of all, have failed.
            # base::TestLauncher does this for timeouts and unknown results.
            failed_suites += 0 if result else 1
            if failed_suites >= max(3, len(test_list) / 10):
                print 'Too many failing suites (%d), exiting now.' % failed_suites
                failed.append('Test runner aborted for excessive failures.')
                break

        if failed:
            break

    print '[==========] %d tests ran.' % len(tests)
    print '[  PASSED  ] %d tests.' % (len(tests) - len(failed))
    if failed:
        print '[  FAILED  ] %d tests, listed below:' % len(failed)
        for failure in failed:
            print '[  FAILED  ] %s' % failure

    if args.write_full_results_to:
        _WriteJSONResults(tests, failed, args.write_full_results_to)

    return 1 if failed else 0
Exemplo n.º 10
0
def main():
  parser = argparse.ArgumentParser(
      description="A 'smart' test runner for gtest unit tests (that caches "
                  "successes).")

  parser.add_argument("--verbose", help="be verbose (multiple times for more)",
                      default=0, dest="verbose_count", action="count")
  parser.add_argument("--successes-cache",
                      help="the file caching test results (empty to not cache)",
                      default="mojob_test_successes")
  parser.add_argument("test_list_file",
                      help="the file containing the tests to run", type=file)
  parser.add_argument("root_dir", help="the build directory")
  args = parser.parse_args()

  InitLogging(args.verbose_count)
  config = ConfigForGNArgs(ParseGNConfig(args.root_dir))

  _logger.debug("Test list file: %s", args.test_list_file)
  execution_globals = {"config": config}
  exec args.test_list_file in execution_globals
  test_list = execution_globals["tests"]
  _logger.debug("Test list: %s" % test_list)

  print "Running tests in directory: %s" % args.root_dir
  os.chdir(args.root_dir)

  if args.successes_cache:
    print "Successes cache file: %s" % args.successes_cache
  else:
    print "No successes cache file (will run all tests unconditionally)"

  if args.successes_cache:
    # This file simply contains a list of transitive hashes of tests that
    # succeeded.
    try:
      _logger.debug("Trying to read successes cache file: %s",
                     args.successes_cache)
      with open(args.successes_cache, 'rb') as f:
        successes = set([x.strip() for x in f.readlines()])
      _logger.debug("Successes: %s", successes)
    except IOError:
      # Just assume that it didn't exist, or whatever.
      print ("Failed to read successes cache file %s (will create)" %
             args.successes_cache)
      successes = set()

  gtest.set_color()

  exit_code = 0
  successes_cache_file = (open(args.successes_cache, "ab")
      if args.successes_cache else None)
  for test_dict in test_list:
    test = test_dict["test"]
    test_name = test_dict.get("name", test)
    # TODO(vtl): Add type.
    cacheable = test_dict.get("cacheable", True)
    if not cacheable:
      _logger.debug("%s is marked as non-cacheable" % test_name)

    gtest_file = test
    if config.target_os == Config.OS_ANDROID:
      gtest_file = test + "_apk/" + test + "-debug.apk"

    if successes_cache_file and cacheable:
      _logger.debug("Getting transitive hash for %s ... " % test_name)
      try:
        if config.target_os == Config.OS_ANDROID:
          gtest_hash = file_hash(gtest_file)
        else:
          gtest_hash = transitive_hash(gtest_file)
      except subprocess.CalledProcessError:
        print "Failed to get transitive hash for %s" % test_name
        exit_code = 1
        continue
      _logger.debug("  Transitive hash: %s" % gtest_hash)

      if gtest_hash in successes:
        print "Skipping %s (previously succeeded)" % test_name
        continue

    _logger.info("Will start: %s" % test_name)
    print "Running %s...." % test_name,
    sys.stdout.flush()
    try:
      if config.target_os == Config.OS_ANDROID:
        command = [
            "python",
            os.path.join(_paths.src_root, "build", "android", "test_runner.py"),
            "gtest",
            "--output-directory",
            args.root_dir,
            "-s",
            test,
        ]
      else:
        command = ["./" + test]
      _logger.debug("Command: %s" % command)
      subprocess.check_output(command, stderr=subprocess.STDOUT)
      print "Succeeded"
      # Record success.
      if args.successes_cache and cacheable:
        successes.add(gtest_hash)
        successes_cache_file.write(gtest_hash + "\n")
        successes_cache_file.flush()
    except subprocess.CalledProcessError as e:
      print "Failed with exit code %d and output:" % e.returncode
      print 72 * "-"
      print e.output
      print 72 * "-"
      exit_code = 1
      continue
    except OSError as e:
      print "  Failed to start test"
      exit_code = 1
      continue
    _logger.info("Completed: %s" % test_name)
  if exit_code == 0:
    print "All tests succeeded"
  if successes_cache_file:
    successes_cache_file.close()

  return exit_code
Exemplo n.º 11
0
def main():
    parser = argparse.ArgumentParser(
        description="A test runner for application "
        "tests.")

    parser.add_argument("--verbose",
                        help="be verbose (multiple times for more)",
                        default=0,
                        dest="verbose_count",
                        action="count")
    parser.add_argument("test_list_file",
                        type=file,
                        help="a file listing apptests to run")
    parser.add_argument("build_dir",
                        type=str,
                        help="the build output directory")
    args = parser.parse_args()

    InitLogging(args.verbose_count)
    config = ConfigForGNArgs(ParseGNConfig(args.build_dir))

    _logger.debug("Test list file: %s", args.test_list_file)
    execution_globals = {"config": config}
    exec args.test_list_file in execution_globals
    test_list = execution_globals["tests"]
    _logger.debug("Test list: %s" % test_list)

    extra_args = []
    if config.target_os == Config.OS_ANDROID:
        paths = Paths(config)
        shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir,
                             paths.adb_path)
        extra_args.extend(shell.PrepareShellRun('localhost'))
    else:
        shell = None

    gtest.set_color()

    exit_code = 0
    for test_dict in test_list:
        test = test_dict["test"]
        test_name = test_dict.get("name", test)
        test_type = test_dict.get("type", "gtest")
        test_args = test_dict.get("test-args", [])
        shell_args = test_dict.get("shell-args", []) + extra_args

        _logger.info("Will start: %s" % test_name)
        print "Running %s...." % test_name,
        sys.stdout.flush()

        if test_type == "dart":
            apptest_result = dart_apptest.run_test(config, shell, test_dict,
                                                   shell_args,
                                                   {test: test_args})
        elif test_type == "gtest":
            apptest_result = gtest.run_fixtures(config, shell, test_dict, test,
                                                False, test_args, shell_args)
        elif test_type == "gtest_isolated":
            apptest_result = gtest.run_fixtures(config, shell, test_dict, test,
                                                True, test_args, shell_args)
        else:
            apptest_result = "Invalid test type in %r" % test_dict

        if apptest_result != "Succeeded":
            exit_code = 1
        print apptest_result
        _logger.info("Completed: %s" % test_name)

    return exit_code
Exemplo n.º 12
0
def main():
    logging.basicConfig()
    # Uncomment to debug:
    #_logging.setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser(description='A test runner for gtest '
                                     'application tests.')

    parser.add_argument('apptest_list_file',
                        type=file,
                        help='A file listing apptests to run.')
    parser.add_argument('build_dir',
                        type=str,
                        help='The build output directory.')
    args = parser.parse_args()

    config = ConfigForGNArgs(ParseGNConfig(args.build_dir))

    execution_globals = {
        "config": config,
    }
    exec args.apptest_list_file in execution_globals
    apptest_list = execution_globals["tests"]
    _logging.debug("Test list: %s" % apptest_list)

    is_android = (config.target_os == Config.OS_ANDROID)
    android_context = android.PrepareShellRun(config) if is_android else None

    gtest.set_color()
    mojo_paths = Paths(config)

    exit_code = 0
    for apptest_dict in apptest_list:
        apptest = apptest_dict["test"]
        apptest_args = apptest_dict.get("test-args", [])
        shell_args = apptest_dict.get("shell-args", [])
        launched_services = apptest_dict.get("launched-services", [])

        print "Running " + apptest + "...",
        sys.stdout.flush()

        # List the apptest fixtures so they can be run independently for isolation.
        # TODO(msw): Run some apptests without fixture isolation?
        fixtures = gtest.get_fixtures(config, apptest, android_context)

        if not fixtures:
            print "Failed with no tests found."
            exit_code = 1
            continue

        if any(not mojo_paths.IsValidAppUrl(url) for url in launched_services):
            print "Failed with malformed launched-services: %r" % launched_services
            exit_code = 1
            continue

        apptest_result = "Succeeded"
        for fixture in fixtures:
            args_for_apptest = apptest_args + ["--gtest_filter=%s" % fixture]
            if launched_services:
                success = RunApptestInLauncher(config, mojo_paths, apptest,
                                               args_for_apptest, shell_args,
                                               launched_services)
            else:
                success = RunApptestInShell(config, apptest, args_for_apptest,
                                            shell_args, android_context)

            if not success:
                apptest_result = "Failed test(s) in %r" % apptest_dict
                exit_code = 1

        print apptest_result

    return exit_code
Exemplo n.º 13
0
def main():
    parser = argparse.ArgumentParser(
        description="A 'smart' test runner for gtest unit tests (that caches "
        "successes).")

    parser.add_argument("--verbose",
                        help="be verbose (multiple times for more)",
                        default=0,
                        dest="verbose_count",
                        action="count")
    parser.add_argument(
        "--successes-cache",
        help="the file caching test results (empty to not cache)",
        default="mojob_test_successes")
    parser.add_argument("test_list_file",
                        help="the file containing the tests to run",
                        type=file)
    parser.add_argument("root_dir", help="the build directory")
    args = parser.parse_args()

    InitLogging(args.verbose_count)
    config = ConfigForGNArgs(ParseGNConfig(args.root_dir))

    _logger.debug("Test list file: %s", args.test_list_file)
    execution_globals = {"config": config}
    exec args.test_list_file in execution_globals
    test_list = execution_globals["tests"]
    _logger.debug("Test list: %s" % test_list)

    print "Running tests in directory: %s" % args.root_dir
    os.chdir(args.root_dir)

    if args.successes_cache:
        print "Successes cache file: %s" % args.successes_cache
    else:
        print "No successes cache file (will run all tests unconditionally)"

    if args.successes_cache:
        # This file simply contains a list of transitive hashes of tests that
        # succeeded.
        try:
            _logger.debug("Trying to read successes cache file: %s",
                          args.successes_cache)
            with open(args.successes_cache, 'rb') as f:
                successes = set([x.strip() for x in f.readlines()])
            _logger.debug("Successes: %s", successes)
        except IOError:
            # Just assume that it didn't exist, or whatever.
            print("Failed to read successes cache file %s (will create)" %
                  args.successes_cache)
            successes = set()

    gtest.set_color()

    exit_code = 0
    successes_cache_file = (open(args.successes_cache, "ab")
                            if args.successes_cache else None)
    for test_dict in test_list:
        test = test_dict["test"]
        test_name = test_dict.get("name", test)
        # TODO(vtl): Add type.
        cacheable = test_dict.get("cacheable", True)
        if not cacheable:
            _logger.debug("%s is marked as non-cacheable" % test_name)

        gtest_file = test
        if config.target_os == Config.OS_ANDROID:
            gtest_file = test + "_apk/" + test + "-debug.apk"

        if successes_cache_file and cacheable:
            _logger.debug("Getting transitive hash for %s ... " % test_name)
            try:
                if config.target_os == Config.OS_ANDROID:
                    gtest_hash = file_hash(gtest_file)
                else:
                    gtest_hash = transitive_hash(gtest_file)
            except subprocess.CalledProcessError:
                print "Failed to get transitive hash for %s" % test_name
                exit_code = 1
                continue
            _logger.debug("  Transitive hash: %s" % gtest_hash)

            if gtest_hash in successes:
                print "Skipping %s (previously succeeded)" % test_name
                continue

        _logger.info("Will start: %s" % test_name)
        print "Running %s...." % test_name,
        sys.stdout.flush()
        try:
            if config.target_os == Config.OS_ANDROID:
                command = [
                    "python",
                    os.path.join(_paths.src_root, "build", "android",
                                 "test_runner.py"),
                    "gtest",
                    "--output-directory",
                    args.root_dir,
                    "-s",
                    test,
                ]
            else:
                command = ["./" + test]
            _logger.debug("Command: %s" % command)
            subprocess.check_output(command, stderr=subprocess.STDOUT)
            print "Succeeded"
            # Record success.
            if args.successes_cache and cacheable:
                successes.add(gtest_hash)
                successes_cache_file.write(gtest_hash + "\n")
                successes_cache_file.flush()
        except subprocess.CalledProcessError as e:
            print "Failed with exit code %d and output:" % e.returncode
            print 72 * "-"
            print e.output
            print 72 * "-"
            exit_code = 1
            continue
        except OSError as e:
            print "  Failed to start test"
            exit_code = 1
            continue
        _logger.info("Completed: %s" % test_name)
    if exit_code == 0:
        print "All tests succeeded"
    if successes_cache_file:
        successes_cache_file.close()

    return exit_code
Exemplo n.º 14
0
def main():
  logging.basicConfig()
  # Uncomment to debug:
  #_logging.setLevel(logging.DEBUG)

  parser = argparse.ArgumentParser(description='A test runner for gtest '
                                   'application tests.')

  parser.add_argument('apptest_list_file', type=file,
                      help='A file listing apptests to run.')
  parser.add_argument('build_dir', type=str,
                      help='The build output directory.')
  args = parser.parse_args()

  config = ConfigForGNArgs(ParseGNConfig(args.build_dir))

  execution_globals = {
      "config": config,
  }
  exec args.apptest_list_file in execution_globals
  apptest_list = execution_globals["tests"]
  _logging.debug("Test list: %s" % apptest_list)

  is_android = (config.target_os == Config.OS_ANDROID)
  android_context = android.PrepareShellRun(config) if is_android else None

  gtest.set_color()
  mojo_paths = Paths(config)

  exit_code = 0
  for apptest_dict in apptest_list:
    apptest = apptest_dict["test"]
    apptest_args = apptest_dict.get("test-args", [])
    shell_args = apptest_dict.get("shell-args", [])
    launched_services = apptest_dict.get("launched-services", [])

    print "Running " + apptest + "...",
    sys.stdout.flush()

    # List the apptest fixtures so they can be run independently for isolation.
    # TODO(msw): Run some apptests without fixture isolation?
    fixtures = gtest.get_fixtures(config, apptest, android_context)

    if not fixtures:
      print "Failed with no tests found."
      exit_code = 1
      continue

    if any(not mojo_paths.IsValidAppUrl(url) for url in launched_services):
      print "Failed with malformed launched-services: %r" % launched_services
      exit_code = 1
      continue

    apptest_result = "Succeeded"
    for fixture in fixtures:
      args_for_apptest = apptest_args + ["--gtest_filter=%s" % fixture]
      if launched_services:
        success = RunApptestInLauncher(config, mojo_paths, apptest,
                                       args_for_apptest, shell_args,
                                       launched_services)
      else:
        success = RunApptestInShell(config, apptest, args_for_apptest,
                                    shell_args, android_context)

      if not success:
        apptest_result = "Failed test(s) in %r" % apptest_dict
        exit_code = 1

    print apptest_result

  return exit_code