blob: 3a1efbf012a84d970dc01f799fc506dd31672e55 [file] [log] [blame]
Ian Zerny161ff742022-01-20 12:39:40 +01001#!/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
6import argparse
7import os
8import subprocess
9import sys
10
Ian Zernybf22d4e2022-04-07 12:31:21 +020011import compiledump
Ian Zerny161ff742022-01-20 12:39:40 +010012import gradle
13import jdk
14import utils
15
Søren Gjesse832a6622023-10-12 13:51:24 +020016GOLEM_BUILD_TARGETS_TESTS = [
17 utils.GRADLE_TASK_ALL_TESTS_WITH_APPLY_MAPPING_JAR,
Rico Wind9365e942024-03-27 12:58:05 +010018 utils.GRADLE_TASK_TESTBASE_WITH_APPLY_MAPPING_JAR,
Søren Gjesse832a6622023-10-12 13:51:24 +020019 utils.GRADLE_TASK_TEST_DEPS_JAR
20]
21GOLEM_BUILD_TARGETS = [utils.GRADLE_TASK_R8LIB] + GOLEM_BUILD_TARGETS_TESTS
22
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020023
Ian Zernyd5061b32022-02-02 13:24:30 +010024def get_golem_resource_path(benchmark):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020025 return os.path.join('benchmarks', benchmark)
26
Ian Zernyd5061b32022-02-02 13:24:30 +010027
Ian Zerny161ff742022-01-20 12:39:40 +010028def get_jdk_home(options, benchmark):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020029 if options.golem:
30 return os.path.join(get_golem_resource_path(benchmark), 'linux')
31 return None
32
Ian Zerny161ff742022-01-20 12:39:40 +010033
34def parse_options(argv):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020035 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 Zerny161ff742022-01-20 12:39:40 +010080
Ian Zerny171c6a62022-04-04 14:25:30 +020081def main(argv, temp):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020082 (options, args) = parse_options(argv)
Ian Zerny161ff742022-01-20 12:39:40 +010083
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020084 if options.temp:
85 temp = options.temp
Ian Zerny171c6a62022-04-04 14:25:30 +020086
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020087 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 Zerny161ff742022-01-20 12:39:40 +010093 if options.nolib:
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020094 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 Wind9365e942024-03-27 12:58:05 +010099 testjars = [utils.R8_TESTS_JAR, utils.R8_TESTS_DEPS_JAR, utils.R8_TESTBASE_JAR]
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200100 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 Wind9365e942024-03-27 12:58:05 +0100106 os.path.join(utils.R8LIB_TESTS_DEPS_JAR),
107 os.path.join(utils.R8LIB_TESTBASE_JAR)
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200108 ]
Ian Zerny161ff742022-01-20 12:39:40 +0100109
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200110 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 Zerny161ff742022-01-20 12:39:40 +0100115
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200116 if not options.no_build:
117 gradle.RunGradle(buildTargets + ['-Pno_internal'])
Ian Zerny171c6a62022-04-04 14:25:30 +0200118
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200119 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 Zerny161ff742022-01-20 12:39:40 +0100126
Ian Zerny161ff742022-01-20 12:39:40 +0100127
128def run(options, r8jar, testjars):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200129 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 Zerny1dd09cb2024-04-22 07:38:58 +0200137 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 Adamsen2434a4d2023-10-16 11:29:03 +0200139 ])
140 cmd.extend(['-cp', ':'.join([r8jar] + testjars)])
Søren Gjessed54faae2023-10-12 09:07:54 +0200141 cmd.extend([
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200142 '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 Zerny161ff742022-01-20 12:39:40 +0100148 ])
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200149 return subprocess.check_call(cmd)
150
Ian Zerny161ff742022-01-20 12:39:40 +0100151
152if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200153 with utils.TempDir() as temp:
154 sys.exit(main(sys.argv[1:], temp))