Beispiel #1
0
def _build(config):
  """Builds for the given config."""

  _logger.debug('_build()')

  out_dir = _get_out_dir(config)
  gn_args = ParseGNConfig(out_dir)
  print 'Building in %s ...' % out_dir
  if gn_args.get('use_goma'):
    # Use the configured goma directory.
    local_goma_dir = gn_args.get('goma_dir')
    print 'Ensuring goma (in %s) started ...' % local_goma_dir
    command = ['python',
               os.path.join(local_goma_dir, 'goma_ctl.py'),
               'ensure_start']
    exit_code = subprocess.call(command)
    if exit_code:
      return exit_code

    # Goma allows us to run many more jobs in parallel, say 32 per core/thread
    # (= 1024 on a 16-core, 32-thread Z620). Limit the load average to 4 per
    # core/thread (= 128 on said Z620).
    jobs = cpu_count() * 32
    limit = cpu_count() * 4
    return subprocess.call(['ninja', '-j', str(jobs), '-l', str(limit),
                            '-C', out_dir])
  else:
    return subprocess.call(['ninja', '-C', out_dir])
Beispiel #2
0
def _build(config):
    """Builds for the given config."""

    _logger.debug('_build()')

    out_dir = _get_out_dir(config)
    gn_args = ParseGNConfig(out_dir)
    print 'Building in %s ...' % out_dir
    if gn_args.get('use_goma'):
        # Use the configured goma directory.
        local_goma_dir = gn_args.get('goma_dir')
        print 'Ensuring goma (in %s) started ...' % local_goma_dir
        command = [
            'python',
            os.path.join(local_goma_dir, 'goma_ctl.py'), 'ensure_start'
        ]
        exit_code = subprocess.call(command)
        if exit_code:
            return exit_code

        # Goma allows us to run many more jobs in parallel, say 32 per core/thread
        # (= 1024 on a 16-core, 32-thread Z620). Limit the load average to 4 per
        # core/thread (= 128 on said Z620).
        jobs = cpu_count() * 32
        limit = cpu_count() * 4
        return subprocess.call(
            ['ninja', '-j',
             str(jobs), '-l',
             str(limit), '-C', out_dir])
    else:
        return subprocess.call(['ninja', '-C', out_dir])
Beispiel #3
0
def build(config):
  out_dir = _get_out_dir(config)
  gn_args = ParseGNConfig(out_dir)
  print 'Building in %s ...' % out_dir
  if gn_args.get('use_goma'):
    # Use the configured goma directory.
    local_goma_dir = gn_args.get('goma_dir')
    print 'Ensuring goma (in %s) started ...' % local_goma_dir
    command = ['python',
               os.path.join(local_goma_dir, 'goma_ctl.py'),
               'ensure_start']
    exit_code = subprocess.call(command)
    if exit_code:
      return exit_code

    return subprocess.call(['ninja', '-j', '1000', '-l', '100', '-C', out_dir])
  else:
    return subprocess.call(['ninja', '-C', out_dir])
Beispiel #4
0
def build(config):
  out_dir = _get_out_dir(config)
  gn_args = ParseGNConfig(out_dir)
  print 'Building in %s ...' % out_dir
  if gn_args.get('use_goma'):
    # Use the configured goma directory.
    local_goma_dir = gn_args.get('goma_dir')
    print 'Ensuring goma (in %s) started ...' % local_goma_dir
    command = ['python',
               os.path.join(local_goma_dir, 'goma_ctl.py'),
               'ensure_start']
    exit_code = subprocess.call(command)
    if exit_code:
      return exit_code

    return subprocess.call(['ninja', '-j', '1000', '-l', '100', '-C', out_dir])
  else:
    return subprocess.call(['ninja', '-C', out_dir])
Beispiel #5
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
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
Beispiel #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('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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
def main():
    logging.basicConfig()
    # Uncomment to debug:
    # _logging.setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser(
        description="A 'smart' test runner for gtest unit tests (that caches "
        "successes).")

    parser.add_argument("gtest_list_file",
                        help="The file containing the tests to run.",
                        type=file)
    parser.add_argument("root_dir", help="The build directory.")
    parser.add_argument("successes_cache_filename",
                        help="The file caching test results.",
                        default=None,
                        nargs='?')
    args = parser.parse_args()

    config = ConfigForGNArgs(ParseGNConfig(args.root_dir))

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

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

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

    if args.successes_cache_filename:
        # This file simply contains a list of transitive hashes of tests that
        # succeeded.
        try:
            _logging.debug("Trying to read successes cache file: %s",
                           args.successes_cache_filename)
            with open(args.successes_cache_filename, 'rb') as f:
                successes = set([x.strip() for x in f.readlines()])
            _logging.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_filename)
            successes = set()

    mopy.gtest.set_color()

    # TODO(vtl): We may not close this file on failure.
    successes_cache_file = open(args.successes_cache_filename, 'ab') \
        if args.successes_cache_filename else None
    for gtest_dict in gtest_list:
        gtest = gtest_dict["test"]
        cacheable = gtest_dict.get("cacheable", True)
        if not cacheable:
            _logging.debug("%s is marked as non-cacheable" % gtest)

        gtest_file = gtest
        if platform.system() == 'Windows':
            gtest_file += ".exe"
        if config.target_os == Config.OS_ANDROID:
            gtest_file = gtest + "_apk/" + gtest + "-debug.apk"

        if successes_cache_file and cacheable:
            _logging.debug("Getting transitive hash for %s ... " % gtest)
            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" % gtest
                return 1
            _logging.debug("  Transitive hash: %s" % gtest_hash)

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

        print "Running %s...." % gtest,
        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",
                    gtest,
                ]
            else:
                command = ["./" + gtest]
            subprocess.check_output(command, stderr=subprocess.STDOUT)
            print "Succeeded"
            # Record success.
            if args.successes_cache_filename 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 * '-'
            return 1
        except OSError as e:
            print "  Failed to start test"
            return 1
    print "All tests succeeded"
    if successes_cache_file:
        successes_cache_file.close()

    return 0