Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import os |
| 8 | import subprocess |
| 9 | import sys |
| 10 | |
Ian Zerny | bf22d4e | 2022-04-07 12:31:21 +0200 | [diff] [blame] | 11 | import compiledump |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 12 | import gradle |
| 13 | import jdk |
| 14 | import utils |
| 15 | |
Søren Gjesse | 832a662 | 2023-10-12 13:51:24 +0200 | [diff] [blame] | 16 | GOLEM_BUILD_TARGETS_TESTS = [ |
| 17 | utils.GRADLE_TASK_ALL_TESTS_WITH_APPLY_MAPPING_JAR, |
Rico Wind | 9365e94 | 2024-03-27 12:58:05 +0100 | [diff] [blame] | 18 | utils.GRADLE_TASK_TESTBASE_WITH_APPLY_MAPPING_JAR, |
Søren Gjesse | 832a662 | 2023-10-12 13:51:24 +0200 | [diff] [blame] | 19 | utils.GRADLE_TASK_TEST_DEPS_JAR |
| 20 | ] |
| 21 | GOLEM_BUILD_TARGETS = [utils.GRADLE_TASK_R8LIB] + GOLEM_BUILD_TARGETS_TESTS |
| 22 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 23 | |
Ian Zerny | d5061b3 | 2022-02-02 13:24:30 +0100 | [diff] [blame] | 24 | def get_golem_resource_path(benchmark): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 25 | return os.path.join('benchmarks', benchmark) |
| 26 | |
Ian Zerny | d5061b3 | 2022-02-02 13:24:30 +0100 | [diff] [blame] | 27 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 28 | def get_jdk_home(options, benchmark): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 29 | if options.golem: |
| 30 | return os.path.join(get_golem_resource_path(benchmark), 'linux') |
| 31 | return None |
| 32 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 33 | |
| 34 | def parse_options(argv): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 35 | result = argparse.ArgumentParser(description='Run test-based benchmarks.') |
| 36 | result.add_argument('--golem', |
| 37 | help='Indicate this as a run on golem', |
| 38 | default=False, |
| 39 | action='store_true') |
| 40 | result.add_argument('--benchmark', |
| 41 | help='The test benchmark to run', |
| 42 | required=True) |
| 43 | result.add_argument( |
| 44 | '--target', |
| 45 | help='The test target to run', |
| 46 | required=True, |
| 47 | # These should 1:1 with benchmarks/BenchmarkTarget.java |
| 48 | choices=['d8', 'r8-full', 'r8-force', 'r8-compat']) |
| 49 | result.add_argument('--nolib', |
| 50 | '--no-lib', |
| 51 | '--no-r8lib', |
| 52 | help='Run the non-lib R8 build (default false)', |
| 53 | default=False, |
| 54 | action='store_true') |
| 55 | result.add_argument('--no-build', |
| 56 | '--no_build', |
| 57 | help='Run without building first (default false)', |
| 58 | default=False, |
| 59 | action='store_true') |
| 60 | result.add_argument('--enable-assertions', |
| 61 | '--enable_assertions', |
| 62 | '-ea', |
| 63 | help='Enable assertions when running', |
| 64 | default=False, |
| 65 | action='store_true') |
| 66 | result.add_argument('--print-times', |
| 67 | help='Print timing information from r8', |
| 68 | default=False, |
| 69 | action='store_true') |
| 70 | result.add_argument( |
| 71 | '--version', |
| 72 | '-v', |
| 73 | help='Use R8 version/hash for the run (default local build)', |
| 74 | default=None) |
| 75 | result.add_argument('--temp', |
| 76 | help='A directory to use for temporaries and outputs.', |
| 77 | default=None) |
| 78 | return result.parse_known_args(argv) |
| 79 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 80 | |
Ian Zerny | 171c6a6 | 2022-04-04 14:25:30 +0200 | [diff] [blame] | 81 | def main(argv, temp): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 82 | (options, args) = parse_options(argv) |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 83 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 84 | if options.temp: |
| 85 | temp = options.temp |
Ian Zerny | 171c6a6 | 2022-04-04 14:25:30 +0200 | [diff] [blame] | 86 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 87 | if options.golem: |
| 88 | options.no_build = True |
| 89 | if options.nolib: |
| 90 | print("Error: golem should always run r8lib") |
| 91 | return 1 |
| 92 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 93 | if options.nolib: |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 94 | testBuildTargets = [ |
| 95 | utils.GRADLE_TASK_TEST_JAR, utils.GRADLE_TASK_TEST_DEPS_JAR |
| 96 | ] |
| 97 | buildTargets = [utils.GRADLE_TASK_R8] + testBuildTargets |
| 98 | r8jar = utils.R8_JAR |
Rico Wind | 9365e94 | 2024-03-27 12:58:05 +0100 | [diff] [blame] | 99 | testjars = [utils.R8_TESTS_JAR, utils.R8_TESTS_DEPS_JAR, utils.R8_TESTBASE_JAR] |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 100 | else: |
| 101 | testBuildTargets = GOLEM_BUILD_TARGETS_TESTS |
| 102 | buildTargets = GOLEM_BUILD_TARGETS |
| 103 | r8jar = utils.R8LIB_JAR |
| 104 | testjars = [ |
| 105 | os.path.join(utils.R8LIB_TESTS_JAR), |
Rico Wind | 9365e94 | 2024-03-27 12:58:05 +0100 | [diff] [blame] | 106 | os.path.join(utils.R8LIB_TESTS_DEPS_JAR), |
| 107 | os.path.join(utils.R8LIB_TESTBASE_JAR) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 108 | ] |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 109 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 110 | if options.version: |
| 111 | # r8 is downloaded so only test jar needs to be built. |
| 112 | buildTargets = testBuildTargets |
| 113 | r8jar = compiledump.download_distribution(options.version, |
| 114 | options.nolib, temp) |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 115 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 116 | if not options.no_build: |
| 117 | gradle.RunGradle(buildTargets + ['-Pno_internal']) |
Ian Zerny | 171c6a6 | 2022-04-04 14:25:30 +0200 | [diff] [blame] | 118 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 119 | if not options.golem: |
| 120 | # When running locally, change the working directory to be in 'temp'. |
| 121 | # This is hard to do properly within the JVM so we do it here. |
| 122 | with utils.ChangedWorkingDirectory(temp): |
| 123 | return run(options, r8jar, testjars) |
| 124 | else: |
| 125 | return run(options, r8jar, testjars) |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 126 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 127 | |
| 128 | def run(options, r8jar, testjars): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 129 | jdkhome = get_jdk_home(options, options.benchmark) |
| 130 | cmd = [jdk.GetJavaExecutable(jdkhome)] |
| 131 | if options.enable_assertions: |
| 132 | cmd.append('-ea') |
| 133 | if options.print_times: |
| 134 | cmd.append('-Dcom.android.tools.r8.printtimes=1') |
| 135 | if not options.golem: |
| 136 | cmd.extend([ |
Ian Zerny | 1dd09cb | 2024-04-22 07:38:58 +0200 | [diff] [blame] | 137 | f'-DTEST_DATA_LOCATION={utils.REPO_ROOT}/d8_r8/test_modules/tests_java_8/build/classes/java/test', |
| 138 | f'-DTESTBASE_DATA_LOCATION={utils.REPO_ROOT}/d8_r8/test_modules/testbase/build/classes/java/main', |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 139 | ]) |
| 140 | cmd.extend(['-cp', ':'.join([r8jar] + testjars)]) |
Søren Gjesse | d54faae | 2023-10-12 09:07:54 +0200 | [diff] [blame] | 141 | cmd.extend([ |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 142 | 'com.android.tools.r8.benchmarks.BenchmarkMainEntryRunner', |
| 143 | options.benchmark, |
| 144 | options.target, |
| 145 | # When running locally the working directory is moved and we pass the |
| 146 | # repository root as an argument. The runner can then setup dependencies. |
| 147 | 'golem' if options.golem else utils.REPO_ROOT, |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 148 | ]) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 149 | return subprocess.check_call(cmd) |
| 150 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 151 | |
| 152 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 153 | with utils.TempDir() as temp: |
| 154 | sys.exit(main(sys.argv[1:], temp)) |