blob: 904b509194223bb5585351ef6120a7e3f5fbc81f [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
11import gradle
12import jdk
13import utils
Ian Zerny171c6a62022-04-04 14:25:30 +020014import compiledump
Ian Zerny161ff742022-01-20 12:39:40 +010015
16NONLIB_BUILD_TARGET = 'R8WithRelocatedDeps'
17NONLIB_TEST_BUILD_TARGETS = [utils.R8_TESTS_TARGET, utils.R8_TESTS_DEPS_TARGET]
18
19R8LIB_BUILD_TARGET = utils.R8LIB
20R8LIB_TEST_BUILD_TARGETS = [utils.R8LIB_TESTS_TARGET, utils.R8LIB_TESTS_DEPS_TARGET]
21
22# The r8lib target is always the golem target.
23GOLEM_BUILD_TARGETS = [R8LIB_BUILD_TARGET] + R8LIB_TEST_BUILD_TARGETS
24
Ian Zernyd5061b32022-02-02 13:24:30 +010025def get_golem_resource_path(benchmark):
Ian Zernyfa776422022-03-09 07:15:29 +010026 return os.path.join('benchmarks', benchmark)
Ian Zernyd5061b32022-02-02 13:24:30 +010027
Ian Zerny161ff742022-01-20 12:39:40 +010028def get_jdk_home(options, benchmark):
29 if options.golem:
Ian Zernyd5061b32022-02-02 13:24:30 +010030 return os.path.join(get_golem_resource_path(benchmark), 'linux')
Ian Zerny161ff742022-01-20 12:39:40 +010031 return None
32
33def parse_options(argv):
34 result = argparse.ArgumentParser(description = 'Run test-based benchmarks.')
35 result.add_argument('--golem',
36 help='Indicate this as a run on golem',
37 default=False,
38 action='store_true')
39 result.add_argument('--benchmark',
40 help='The test benchmark to run',
41 required=True)
42 result.add_argument('--target',
43 help='The test target to run',
44 required=True,
Ian Zerny221a99b2022-03-09 15:08:26 +010045 # These should 1:1 with benchmarks/BenchmarkTarget.java
46 choices=['d8', 'r8-full', 'r8-force', 'r8-compat'])
Ian Zerny161ff742022-01-20 12:39:40 +010047 result.add_argument('--nolib', '--no-lib', '--no-r8lib',
48 help='Run the non-lib R8 build (default false)',
49 default=False,
50 action='store_true')
51 result.add_argument('--no-build', '--no_build',
52 help='Run without building first (default false)',
53 default=False,
54 action='store_true')
55 result.add_argument('--enable-assertions', '--enable_assertions', '-ea',
56 help='Enable assertions when running',
57 default=False,
58 action='store_true')
59 result.add_argument('--print-times',
60 help='Print timing information from r8',
61 default=False,
62 action='store_true')
Ian Zerny171c6a62022-04-04 14:25:30 +020063 result.add_argument('--version', '-v',
64 help='Use R8 version/hash for the run (default local build)',
65 default=None)
Ian Zerny161ff742022-01-20 12:39:40 +010066 result.add_argument('--temp',
67 help='A directory to use for temporaries and outputs.',
68 default=None)
69 return result.parse_known_args(argv)
70
Ian Zerny171c6a62022-04-04 14:25:30 +020071def main(argv, temp):
Ian Zerny161ff742022-01-20 12:39:40 +010072 (options, args) = parse_options(argv)
73
Ian Zerny171c6a62022-04-04 14:25:30 +020074 if options.temp:
75 temp = options.temp
76
Ian Zerny161ff742022-01-20 12:39:40 +010077 if options.golem:
78 options.no_build = True
79 if options.nolib:
80 print("Error: golem should always run r8lib")
81 return 1
82
83 if options.nolib:
Ian Zerny171c6a62022-04-04 14:25:30 +020084 testBuildTargets = NONLIB_TEST_BUILD_TARGETS
Ian Zerny161ff742022-01-20 12:39:40 +010085 buildTargets = [NONLIB_BUILD_TARGET] + NONLIB_TEST_BUILD_TARGETS
86 r8jar = utils.R8_WITH_RELOCATED_DEPS_JAR
87 testjars = [utils.R8_TESTS_DEPS_JAR, utils.R8_TESTS_JAR]
88 else:
Ian Zerny171c6a62022-04-04 14:25:30 +020089 testBuildTargets = R8LIB_TEST_BUILD_TARGETS
Ian Zerny161ff742022-01-20 12:39:40 +010090 buildTargets = GOLEM_BUILD_TARGETS
91 r8jar = utils.R8LIB_JAR
92 testjars = [utils.R8LIB_TESTS_DEPS_JAR, utils.R8LIB_TESTS_JAR]
93
Ian Zerny171c6a62022-04-04 14:25:30 +020094 if options.version:
95 # r8 is downloaded so only test jar needs to be built.
96 buildTargets = testBuildTargets
97 r8jar = compiledump.download_distribution(options.version, options.nolib, temp)
98
Ian Zerny161ff742022-01-20 12:39:40 +010099 if not options.no_build:
100 gradle.RunGradle(buildTargets + ['-Pno_internal'])
101
102 return run(options, r8jar, testjars)
103
104def run(options, r8jar, testjars):
105 jdkhome = get_jdk_home(options, options.benchmark)
106 cmd = [jdk.GetJavaExecutable(jdkhome)]
107 if options.enable_assertions:
108 cmd.append('-ea')
109 if options.print_times:
110 cmd.append('-Dcom.android.tools.r8.printtimes=1')
111 cmd.extend(['-cp', ':'.join([r8jar] + testjars)])
112 cmd.extend([
113 'com.android.tools.r8.benchmarks.BenchmarkMainEntryRunner',
114 options.benchmark,
115 options.target,
Ian Zerny14f956b2022-02-24 13:57:55 +0100116 'golem' if options.golem else 'local',
Ian Zerny161ff742022-01-20 12:39:40 +0100117 ])
118 return subprocess.check_call(cmd)
119
120if __name__ == '__main__':
Ian Zerny171c6a62022-04-04 14:25:30 +0200121 with utils.TempDir() as temp:
122 sys.exit(main(sys.argv[1:], temp))