コード例 #1
0
ファイル: voc_test.py プロジェクト: aalborov/cut_dataset
 def test_output_exists_customized_1st_image_size7(self):
     """The first image index is 2, 7 images in the output archive."""
     output_size = 7
     first_image = 2
     unarchive(self.source_archive_dir, self.output_folder_dir)
     voc_data = cut_voc(output_size, self.output_folder_dir, first_image)
     file_exists = create_archive(voc_data, self.output_archive_dir,
                                  self.output_archive_name,
                                  self.output_folder_dir)
     self.assertTrue(file_exists)
コード例 #2
0
ファイル: voc_test.py プロジェクト: aalborov/cut_dataset
 def test_output_exists_default_1st_image_size4(self):
     """Default first image value, 4 images in the output archive."""
     output_size = 4
     first_image = 0
     unarchive(self.source_archive_dir, self.output_folder_dir)
     voc_data = cut_voc(output_size, self.output_folder_dir, first_image)
     file_exists = create_archive(voc_data, self.output_archive_dir,
                                  self.output_archive_name,
                                  self.output_folder_dir)
     self.assertTrue(file_exists)
コード例 #3
0
ファイル: imagenet_test.py プロジェクト: aalborov/cut_dataset
 def test_output_exists_customized_1st_image_size98(self):
     """First image index is 1, 98 images in the output archive."""
     output_size = 98
     first_image = 1
     unarchive(self.source_archive_dir, self.output_folder_dir)
     imagenet_data = cut_imagenet(output_size, self.output_folder_dir,
                                  first_image)
     file_exists = create_archive(imagenet_data, self.output_archive_dir,
                                  self.output_archive_name,
                                  self.output_folder_dir)
     self.assertTrue(file_exists)
コード例 #4
0
ファイル: coco_test.py プロジェクト: aalborov/cut_dataset
 def test_output_exists_customized_1st_image_size4(self):
     """The first image index is 1, 4 images in the output archive."""
     output_size = 4
     first_image = 1
     unarchive(self.source_images_archive_dir, self.output_folder_dir)
     unarchive(self.source_annotations_archive_dir, self.output_folder_dir)
     coco_data = cut_coco(output_size, self.output_folder_dir, first_image)
     file_exists = create_archive(coco_data, self.output_archive_dir,
                                  self.output_archive_name,
                                  self.output_folder_dir)
     self.assertTrue(file_exists)
コード例 #5
0
def Main():
    (options, args) = parse_options()
    assert len(args) == 1
    name = args[0]
    print 'Creating archive for %s' % name
    if not name in os.listdir('.'):
        print 'You must be standing directly below the directory you are uploading'
        return 1
    filename = utils.create_archive(name)
    sha1 = utils.get_sha1(filename)
    dest = os.path.join(GMSCORE_DEPS, sha1)
    uploadFile(filename, dest)
    sha1_file = '%s.sha1' % filename
    with open(sha1_file, 'w') as output:
        output.write(sha1)
    print 'Sha (%s) written to: %s' % (sha1, sha1_file)
コード例 #6
0
def main():
  # We need prodaccess to upload to x20
  utils.check_prodacces()

  working_dir = run_on_as_app.WORKING_DIR

  print 'Removing directories that do not match checked out revision'
  with utils.ChangedWorkingDirectory(working_dir):
    for repo in run_on_as_app.APP_REPOSITORIES:
      repo_dir = os.path.join(working_dir, repo.name)
      if os.path.exists(repo_dir) \
          and utils.get_HEAD_sha1_for_checkout(repo_dir) != repo.revision:
        print 'Removing %s' % repo_dir
        shutil.rmtree(repo_dir)

  print 'Downloading all missing apps'
  run_on_as_app.clone_repositories(quiet=False)

  # Package all files as x20 dependency
  parent_dir = os.path.dirname(working_dir)
  with utils.ChangedWorkingDirectory(parent_dir):
    print 'Creating archive for opensource_apps (this may take some time)'
    working_dir_name = os.path.basename(working_dir)
    repo_dirs = [working_dir_name + '/' + repo.name
                 for repo in run_on_as_app.APP_REPOSITORIES]
    filename = utils.create_archive("opensource_apps", repo_dirs)
    sha1 = utils.get_sha1(filename)
    dest = os.path.join(upload_to_x20.GMSCORE_DEPS, sha1)
    upload_to_x20.uploadFile(filename, dest)
    sha1_file = '%s.sha1' % filename
    with open(sha1_file, 'w') as output:
      output.write(sha1)
    shutil.move(sha1_file,
                os.path.join(utils.THIRD_PARTY, 'opensource_apps.tar.gz.sha1'))

  print 'To have apps benchmarked on Golem, the updated apps have to be ' \
        'downloaded to the runners by ssh\'ing into each runner and do:\n' \
        'cd ../golem\n' \
        'update_dependencies.sh\n'
コード例 #7
0
ファイル: test.py プロジェクト: singhaditya28/r8
def Main():
    (options, args) = ParseOptions()
    if utils.is_bot():
        gradle.RunGradle(['--no-daemon', 'clean'])

    gradle_args = ['--stacktrace']
    if utils.is_bot():
        # Bots don't like dangling processes
        gradle_args.append('--no-daemon')

    # Set all necessary Gradle properties and options first.
    if options.shard_count:
        assert options.shard_number
        gradle_args.append('-Pshard_count=%s' % options.shard_count)
        gradle_args.append('-Pshard_number=%s' % options.shard_number)
    if options.verbose:
        gradle_args.append('-Pprint_test_stdout')
    if options.no_internal:
        gradle_args.append('-Pno_internal')
    if options.only_internal:
        gradle_args.append('-Ponly_internal')
    if options.all_tests:
        gradle_args.append('-Pall_tests')
    if options.tool:
        gradle_args.append('-Ptool=%s' % options.tool)
    if options.one_line_per_test:
        gradle_args.append('-Pone_line_per_test')
    if options.jctf:
        gradle_args.append('-Pjctf')
    if options.only_jctf:
        gradle_args.append('-Ponly_jctf')
    if options.jctf_compile_only:
        gradle_args.append('-Pjctf_compile_only')
    if options.disable_assertions:
        gradle_args.append('-Pdisable_assertions')
    if options.with_code_coverage:
        gradle_args.append('-Pwith_code_coverage')
    if os.name == 'nt':
        # temporary hack
        gradle_args.append('-Pno_internal')
        gradle_args.append('-x')
        gradle_args.append('createJctfTests')
        gradle_args.append('-x')
        gradle_args.append('jctfCommonJar')
        gradle_args.append('-x')
        gradle_args.append('jctfTestsClasses')
    if options.test_dir:
        gradle_args.append('-Ptest_dir=' + options.test_dir)
        if not os.path.exists(options.test_dir):
            os.makedirs(options.test_dir)
    if options.java_home:
        gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
    if options.java_max_memory_size:
        gradle_args.append('-Dorg.gradle.jvmargs=-Xmx' +
                           options.java_max_memory_size)
    if options.generate_golden_files_to:
        gradle_args.append('-Pgenerate_golden_files_to=' +
                           options.generate_golden_files_to)
        if not os.path.exists(options.generate_golden_files_to):
            os.makedirs(options.generate_golden_files_to)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if options.use_golden_files_in:
        gradle_args.append('-Puse_golden_files_in=' +
                           options.use_golden_files_in)
        if not os.path.exists(options.use_golden_files_in):
            os.makedirs(options.use_golden_files_in)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if options.alternative_frontend:
        gradle_args.append('-Palternative_frontend')
    if (not options.no_r8lib) and options.r8lib_no_deps:
        print(
            'Cannot run tests on r8lib with and without deps. R8lib is now default target.'
        )
        exit(1)
    if not options.no_r8lib:
        gradle_args.append('-Pr8lib')
        # Force gradle to build a version of r8lib without dependencies for
        # BootstrapCurrentEqualityTest.
        gradle_args.append('R8LibNoDeps')
    if options.r8lib_no_deps:
        gradle_args.append('-Pr8lib_no_deps')

    # Build an R8 with dependencies for bootstrapping tests before adding test sources.
    gradle_args.append('r8WithRelocatedDeps')
    gradle_args.append('r8WithRelocatedDeps11')

    # Add Gradle tasks
    gradle_args.append('cleanTest')
    gradle_args.append('test')
    if options.fail_fast:
        gradle_args.append('--fail-fast')
    if options.failed:
        args = compute_failed_tests(args)
        if args is None:
            return 1
        if len(args) == 0:
            print "No failing tests"
            return 0
    # Test filtering. Must always follow the 'test' task.
    for testFilter in args:
        gradle_args.append('--tests')
        gradle_args.append(testFilter)
    if options.with_code_coverage:
        # Create Jacoco report after tests.
        gradle_args.append('jacocoTestReport')

    if options.use_golden_files_in:
        sha1 = '%s' % utils.get_HEAD_sha1()
        with utils.ChangedWorkingDirectory(options.use_golden_files_in):
            utils.download_file_from_cloud_storage(
                'gs://r8-test-results/golden-files/%s.tar.gz' % sha1,
                '%s.tar.gz' % sha1)
            utils.unpack_archive('%s.tar.gz' % sha1)

    if utils.is_bot() and not utils.IsWindows():
        timestamp_file = os.path.join(utils.BUILD, 'last_test_time')
        if os.path.exists(timestamp_file):
            os.remove(timestamp_file)
        gradle_args.append('-Pupdate_test_timestamp=' + timestamp_file)
        thread.start_new_thread(timeout_handler, (timestamp_file, ))

    rotate_test_reports()

    if options.only_jctf:
        # Note: not setting -Pruntimes will run with all available runtimes.
        return_code = gradle.RunGradle(gradle_args, throw_on_failure=False)
        return archive_and_return(return_code, options)

    # Now run tests on selected runtime(s).
    vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS

    for art_vm in vms_to_test:
        vm_suffix = "_" + options.dex_vm_kind if art_vm != "default" else ""
        runtimes = ['dex-' + art_vm]
        # Only append the "none" runtime and JVMs if running on the "default" DEX VM.
        if art_vm == "default":
            runtimes.extend(['jdk8', 'jdk9', 'jdk11', 'none'])
        return_code = gradle.RunGradle(gradle_args + [
            '-Pdex_vm=%s' % art_vm + vm_suffix,
            '-Pruntimes=%s' % ':'.join(runtimes),
        ],
                                       throw_on_failure=False)
        if options.generate_golden_files_to:
            sha1 = '%s' % utils.get_HEAD_sha1()
            with utils.ChangedWorkingDirectory(
                    options.generate_golden_files_to):
                archive = utils.create_archive(sha1)
                utils.upload_file_to_cloud_storage(
                    archive, 'gs://r8-test-results/golden-files/' + archive)

        if return_code != 0:
            return archive_and_return(return_code, options)

    return 0
コード例 #8
0
ファイル: test.py プロジェクト: newBoomer/r8
def Main():
    (options, args) = ParseOptions()
    if 'BUILDBOT_BUILDERNAME' in os.environ:
        gradle.RunGradle(['clean'])

    # Build R8lib with dependencies for bootstrapping tests before adding test sources
    gradle.RunGradle(['r8libwithdeps'])

    gradle_args = ['--stacktrace']
    # Set all necessary Gradle properties and options first.
    if options.verbose:
        gradle_args.append('-Pprint_test_stdout')
    if options.no_internal:
        gradle_args.append('-Pno_internal')
    if options.only_internal:
        gradle_args.append('-Ponly_internal')
    if options.all_tests:
        gradle_args.append('-Pall_tests')
    if options.tool:
        gradle_args.append('-Ptool=%s' % options.tool)
    if options.one_line_per_test:
        gradle_args.append('-Pone_line_per_test')
    if options.jctf:
        gradle_args.append('-Pjctf')
    if options.only_jctf:
        gradle_args.append('-Ponly_jctf')
    if options.jctf_compile_only:
        gradle_args.append('-Pjctf_compile_only')
    if options.aosp_jar:
        gradle_args.append('-Paosp_jar')
    if options.disable_assertions:
        gradle_args.append('-Pdisable_assertions')
    if options.with_code_coverage:
        gradle_args.append('-Pwith_code_coverage')
    if os.name == 'nt':
        # temporary hack
        gradle_args.append('-Pno_internal')
        gradle_args.append('-x')
        gradle_args.append('createJctfTests')
        gradle_args.append('-x')
        gradle_args.append('jctfCommonJar')
        gradle_args.append('-x')
        gradle_args.append('jctfTestsClasses')
    if options.test_dir:
        gradle_args.append('-Ptest_dir=' + options.test_dir)
        if not os.path.exists(options.test_dir):
            os.makedirs(options.test_dir)
    if options.java_home:
        gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
    if options.generate_golden_files_to:
        gradle_args.append('-Pgenerate_golden_files_to=' +
                           options.generate_golden_files_to)
        if not os.path.exists(options.generate_golden_files_to):
            os.makedirs(options.generate_golden_files_to)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if options.use_golden_files_in:
        gradle_args.append('-Puse_golden_files_in=' +
                           options.use_golden_files_in)
        if not os.path.exists(options.use_golden_files_in):
            os.makedirs(options.use_golden_files_in)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    # Add Gradle tasks
    gradle_args.append('cleanTest')
    gradle_args.append('test')
    # Test filtering. Must always follow the 'test' task.
    for testFilter in args:
        gradle_args.append('--tests')
        gradle_args.append(testFilter)
    if options.with_code_coverage:
        # Create Jacoco report after tests.
        gradle_args.append('jacocoTestReport')

    if options.use_golden_files_in:
        sha1 = '%s' % utils.get_HEAD_sha1()
        with utils.ChangedWorkingDirectory(options.use_golden_files_in):
            utils.download_file_from_cloud_storage(
                'gs://r8-test-results/golden-files/%s.tar.gz' % sha1,
                '%s.tar.gz' % sha1)
            utils.unpack_archive('%s.tar.gz' % sha1)

    # Now run tests on selected runtime(s).
    vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS
    for art_vm in vms_to_test:
        vm_kind_to_test = "_" + options.dex_vm_kind if art_vm != "default" else ""
        return_code = gradle.RunGradle(
            gradle_args + ['-Pdex_vm=%s' % (art_vm + vm_kind_to_test)],
            throw_on_failure=False)

        if options.generate_golden_files_to:
            sha1 = '%s' % utils.get_HEAD_sha1()
            with utils.ChangedWorkingDirectory(
                    options.generate_golden_files_to):
                archive = utils.create_archive(sha1)
                utils.upload_file_to_cloud_storage(
                    archive, 'gs://r8-test-results/golden-files/' + archive)

        if return_code != 0:
            if options.archive_failures and os.name != 'nt':
                archive_failures()
            return return_code

    return 0
コード例 #9
0
ファイル: test.py プロジェクト: Yinkozi/R8
def Main():
    (options, args) = ParseOptions()

    if utils.is_bot():
        gradle.RunGradle(['--no-daemon', 'clean'])

    gradle_args = ['--stacktrace']
    if utils.is_bot():
        # Bots don't like dangling processes.
        gradle_args.append('--no-daemon')

    # Set all necessary Gradle properties and options first.
    if options.shard_count:
        assert options.shard_number
        gradle_args.append('-Pshard_count=%s' % options.shard_count)
        gradle_args.append('-Pshard_number=%s' % options.shard_number)
    if options.verbose:
        gradle_args.append('-Pprint_test_stdout')
    if options.no_internal:
        gradle_args.append('-Pno_internal')
    if options.only_internal:
        gradle_args.append('-Ponly_internal')
    if options.all_tests:
        gradle_args.append('-Pall_tests')
    if options.slow_tests:
        gradle_args.append('-Pslow_tests=1')
    if options.tool:
        gradle_args.append('-Ptool=%s' % options.tool)
    if options.one_line_per_test:
        gradle_args.append('-Pone_line_per_test')
    if options.jctf:
        gradle_args.append('-Pjctf')
    if options.only_jctf:
        gradle_args.append('-Ponly_jctf')
    if options.test_namespace:
        gradle_args.append('-Ptest_namespace=%s' % options.test_namespace)
    if options.jctf_compile_only:
        gradle_args.append('-Pjctf_compile_only')
    if options.disable_assertions:
        gradle_args.append('-Pdisable_assertions')
    if options.with_code_coverage:
        gradle_args.append('-Pwith_code_coverage')
    if os.name == 'nt':
        # temporary hack
        gradle_args.append('-Pno_internal')
        gradle_args.append('-x')
        gradle_args.append('createJctfTests')
        gradle_args.append('-x')
        gradle_args.append('jctfCommonJar')
        gradle_args.append('-x')
        gradle_args.append('jctfTestsClasses')
    if options.test_dir:
        gradle_args.append('-Ptest_dir=' + options.test_dir)
        if not os.path.exists(options.test_dir):
            os.makedirs(options.test_dir)
    if options.java_home:
        gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
    if options.java_max_memory_size:
        gradle_args.append('-Ptest_xmx=' + options.java_max_memory_size)
    if options.generate_golden_files_to:
        gradle_args.append('-Pgenerate_golden_files_to=' +
                           options.generate_golden_files_to)
        if not os.path.exists(options.generate_golden_files_to):
            os.makedirs(options.generate_golden_files_to)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if options.use_golden_files_in:
        gradle_args.append('-Puse_golden_files_in=' +
                           options.use_golden_files_in)
        if not os.path.exists(options.use_golden_files_in):
            os.makedirs(options.use_golden_files_in)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if (not options.no_r8lib) and options.r8lib_no_deps:
        print(
            'Cannot run tests on r8lib with and without deps. R8lib is now default target.'
        )
        exit(1)
    if not options.no_r8lib:
        gradle_args.append('-Pr8lib')
        # Force gradle to build a version of r8lib without dependencies for
        # BootstrapCurrentEqualityTest.
        gradle_args.append('R8LibNoDeps')
    if options.r8lib_no_deps:
        gradle_args.append('-Pr8lib_no_deps')
    if options.worktree:
        gradle_args.append('-g=' +
                           os.path.join(utils.REPO_ROOT, ".gradle_user_home"))
        gradle_args.append('--no-daemon')

    # Build an R8 with dependencies for bootstrapping tests before adding test sources.
    gradle_args.append('r8WithDeps')
    gradle_args.append('r8WithDeps11')
    gradle_args.append('r8WithRelocatedDeps')
    gradle_args.append('r8WithRelocatedDeps11')

    # Add Gradle tasks
    gradle_args.append('cleanTest')
    gradle_args.append('test')
    if options.fail_fast:
        gradle_args.append('--fail-fast')
    if options.failed:
        args = compute_failed_tests(args)
        if args is None:
            return 1
        if len(args) == 0:
            print "No failing tests"
            return 0
    # Test filtering. Must always follow the 'test' task.
    for testFilter in args:
        gradle_args.append('--tests')
        gradle_args.append(testFilter)
    if options.with_code_coverage:
        # Create Jacoco report after tests.
        gradle_args.append('jacocoTestReport')

    if options.use_golden_files_in:
        sha1 = '%s' % utils.get_HEAD_sha1()
        with utils.ChangedWorkingDirectory(options.use_golden_files_in):
            utils.download_file_from_cloud_storage(
                'gs://r8-test-results/golden-files/%s.tar.gz' % sha1,
                '%s.tar.gz' % sha1)
            utils.unpack_archive('%s.tar.gz' % sha1)

    print_stacks_timeout = options.print_hanging_stacks
    if (utils.is_bot() and not utils.IsWindows()) or print_stacks_timeout > -1:
        timestamp_file = os.path.join(utils.BUILD, 'last_test_time')
        if os.path.exists(timestamp_file):
            os.remove(timestamp_file)
        gradle_args.append('-Pupdate_test_timestamp=' + timestamp_file)
        print_stacks_timeout = (print_stacks_timeout
                                if print_stacks_timeout != -1 else
                                TIMEOUT_HANDLER_PERIOD)
        thread.start_new_thread(timeout_handler, (
            timestamp_file,
            print_stacks_timeout,
        ))
    rotate_test_reports()

    if options.only_jctf:
        # Note: not setting -Pruntimes will run with all available runtimes.
        return_code = gradle.RunGradle(gradle_args, throw_on_failure=False)
        return archive_and_return(return_code, options)

    if options.horizontal_class_merging:
        gradle_args.append('-PhorizontalClassMerging')

    # Now run tests on selected runtime(s).
    if options.runtimes:
        if options.dex_vm != 'default':
            print 'Unexpected runtimes and dex_vm argument: ' + options.dex_vm
            sys.exit(1)
        if options.runtimes == 'empty':
            # Set runtimes with no content will configure no runtimes.
            gradle_args.append('-Pruntimes=')
        elif options.runtimes == 'all':
            # An unset runtimes will configure all runtimes
            pass
        else:
            prefixes = [
                prefix.strip() for prefix in options.runtimes.split(':')
            ]
            runtimes = []
            for prefix in prefixes:
                matches = [
                    rt for rt in VALID_RUNTIMES if rt.startswith(prefix)
                ]
                if len(matches) == 0:
                    print "Invalid runtime prefix '%s'." % prefix
                    print "Must be just 'all', 'empty'," \
                          " or a prefix of %s" % ', '.join(VALID_RUNTIMES)
                    sys.exit(1)
                runtimes.extend(matches)
            gradle_args.append('-Pruntimes=%s' % ':'.join(runtimes))

        return_code = gradle.RunGradle(gradle_args, throw_on_failure=False)
        return archive_and_return(return_code, options)

    # Legacy testing populates the runtimes based on dex_vm.
    vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS

    for art_vm in vms_to_test:
        vm_suffix = "_" + options.dex_vm_kind if art_vm != "default" else ""
        runtimes = ['dex-' + art_vm]
        # Only append the "none" runtime and JVMs if running on the "default" DEX VM.
        if art_vm == "default":
            # TODO(b/170454076): Remove special casing for bot when rex-script has
            #  been migrated to account for runtimes.
            if utils.is_bot():
                runtimes.extend(['jdk11', 'none'])
            else:
                runtimes.extend(['jdk8', 'jdk9', 'jdk11', 'none'])
        return_code = gradle.RunGradle(gradle_args + [
            '-Pdex_vm=%s' % art_vm + vm_suffix,
            '-Pruntimes=%s' % ':'.join(runtimes),
        ],
                                       throw_on_failure=False)
        if options.generate_golden_files_to:
            sha1 = '%s' % utils.get_HEAD_sha1()
            with utils.ChangedWorkingDirectory(
                    options.generate_golden_files_to):
                archive = utils.create_archive(sha1)
                utils.upload_file_to_cloud_storage(
                    archive, 'gs://r8-test-results/golden-files/' + archive)

        if return_code != 0:
            return archive_and_return(return_code, options)

    return 0
コード例 #10
0
def Main():
    (options, args) = ParseOptions()
    if utils.is_bot():
        print "Result of 'java -version':"
        print subprocess.check_output(['java', '-version'])
        gradle.RunGradle(['clean'])

    gradle_args = ['--stacktrace']
    # Set all necessary Gradle properties and options first.
    if options.verbose:
        gradle_args.append('-Pprint_test_stdout')
    if options.no_internal:
        gradle_args.append('-Pno_internal')
    if options.only_internal:
        gradle_args.append('-Ponly_internal')
    if options.all_tests:
        gradle_args.append('-Pall_tests')
    if options.tool:
        gradle_args.append('-Ptool=%s' % options.tool)
    if options.one_line_per_test:
        gradle_args.append('-Pone_line_per_test')
    if options.jctf:
        gradle_args.append('-Pjctf')
    if options.only_jctf:
        gradle_args.append('-Ponly_jctf')
    if options.jctf_compile_only:
        gradle_args.append('-Pjctf_compile_only')
    if options.aosp_jar:
        gradle_args.append('-Paosp_jar')
    if options.disable_assertions:
        gradle_args.append('-Pdisable_assertions')
    if options.with_code_coverage:
        gradle_args.append('-Pwith_code_coverage')
    if os.name == 'nt':
        # temporary hack
        gradle_args.append('-Pno_internal')
        gradle_args.append('-x')
        gradle_args.append('createJctfTests')
        gradle_args.append('-x')
        gradle_args.append('jctfCommonJar')
        gradle_args.append('-x')
        gradle_args.append('jctfTestsClasses')
    if options.test_dir:
        gradle_args.append('-Ptest_dir=' + options.test_dir)
        if not os.path.exists(options.test_dir):
            os.makedirs(options.test_dir)
    if options.java_home:
        gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
    if options.generate_golden_files_to:
        gradle_args.append('-Pgenerate_golden_files_to=' +
                           options.generate_golden_files_to)
        if not os.path.exists(options.generate_golden_files_to):
            os.makedirs(options.generate_golden_files_to)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if options.use_golden_files_in:
        gradle_args.append('-Puse_golden_files_in=' +
                           options.use_golden_files_in)
        if not os.path.exists(options.use_golden_files_in):
            os.makedirs(options.use_golden_files_in)
        gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
    if (not options.no_r8lib) and options.r8lib_no_deps:
        print(
            'Cannot run tests on r8lib with and without deps. R8lib is now default target.'
        )
        exit(1)
    if not options.no_r8lib:
        gradle_args.append('-Pr8lib')
        # Force gradle to build a version of r8lib without dependencies for
        # BootstrapCurrentEqualityTest.
        gradle_args.append('R8LibNoDeps')
    if options.r8lib_no_deps:
        gradle_args.append('-Pr8lib_no_deps')

    # Build an R8 with dependencies for bootstrapping tests before adding test sources.
    gradle_args.append('r8WithRelocatedDeps')

    # Add Gradle tasks
    gradle_args.append('cleanTest')
    gradle_args.append('test')
    # Test filtering. Must always follow the 'test' task.
    for testFilter in args:
        gradle_args.append('--tests')
        gradle_args.append(testFilter)
    if options.with_code_coverage:
        # Create Jacoco report after tests.
        gradle_args.append('jacocoTestReport')

    if options.use_golden_files_in:
        sha1 = '%s' % utils.get_HEAD_sha1()
        with utils.ChangedWorkingDirectory(options.use_golden_files_in):
            utils.download_file_from_cloud_storage(
                'gs://r8-test-results/golden-files/%s.tar.gz' % sha1,
                '%s.tar.gz' % sha1)
            utils.unpack_archive('%s.tar.gz' % sha1)

    if utils.is_bot() and not utils.IsWindows():
        timestamp_file = os.path.join(utils.BUILD, 'last_test_time')
        if os.path.exists(timestamp_file):
            os.remove(timestamp_file)
        gradle_args.append('-Pupdate_test_timestamp=' + timestamp_file)
        thread.start_new_thread(timeout_handler, (timestamp_file, ))

    # Now run tests on selected runtime(s).
    vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS
    for art_vm in vms_to_test:
        vm_kind_to_test = "_" + options.dex_vm_kind if art_vm != "default" else ""
        return_code = gradle.RunGradle(
            gradle_args + ['-Pdex_vm=%s' % (art_vm + vm_kind_to_test)],
            throw_on_failure=False)

        if options.generate_golden_files_to:
            sha1 = '%s' % utils.get_HEAD_sha1()
            with utils.ChangedWorkingDirectory(
                    options.generate_golden_files_to):
                archive = utils.create_archive(sha1)
                utils.upload_file_to_cloud_storage(
                    archive, 'gs://r8-test-results/golden-files/' + archive)

        if return_code != 0:
            if options.archive_failures and os.name != 'nt':
                archive_failures()
            return return_code

    return 0