blob: 545ac5aa989854cf2af6d929e66a6eefd0bdc4d6 [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
14
15NONLIB_BUILD_TARGET = 'R8WithRelocatedDeps'
16NONLIB_TEST_BUILD_TARGETS = [utils.R8_TESTS_TARGET, utils.R8_TESTS_DEPS_TARGET]
17
18R8LIB_BUILD_TARGET = utils.R8LIB
19R8LIB_TEST_BUILD_TARGETS = [utils.R8LIB_TESTS_TARGET, utils.R8LIB_TESTS_DEPS_TARGET]
20
21# The r8lib target is always the golem target.
22GOLEM_BUILD_TARGETS = [R8LIB_BUILD_TARGET] + R8LIB_TEST_BUILD_TARGETS
23
Ian Zernyd5061b32022-02-02 13:24:30 +010024def get_golem_resource_path(benchmark):
Ian Zernyfa776422022-03-09 07:15:29 +010025 return os.path.join('benchmarks', benchmark)
Ian Zernyd5061b32022-02-02 13:24:30 +010026
Ian Zerny161ff742022-01-20 12:39:40 +010027def get_jdk_home(options, benchmark):
28 if options.golem:
Ian Zernyd5061b32022-02-02 13:24:30 +010029 return os.path.join(get_golem_resource_path(benchmark), 'linux')
Ian Zerny161ff742022-01-20 12:39:40 +010030 return None
31
32def parse_options(argv):
33 result = argparse.ArgumentParser(description = 'Run test-based benchmarks.')
34 result.add_argument('--golem',
35 help='Indicate this as a run on golem',
36 default=False,
37 action='store_true')
38 result.add_argument('--benchmark',
39 help='The test benchmark to run',
40 required=True)
41 result.add_argument('--target',
42 help='The test target to run',
43 required=True,
Ian Zerny221a99b2022-03-09 15:08:26 +010044 # These should 1:1 with benchmarks/BenchmarkTarget.java
45 choices=['d8', 'r8-full', 'r8-force', 'r8-compat'])
Ian Zerny161ff742022-01-20 12:39:40 +010046 result.add_argument('--nolib', '--no-lib', '--no-r8lib',
47 help='Run the non-lib R8 build (default false)',
48 default=False,
49 action='store_true')
50 result.add_argument('--no-build', '--no_build',
51 help='Run without building first (default false)',
52 default=False,
53 action='store_true')
54 result.add_argument('--enable-assertions', '--enable_assertions', '-ea',
55 help='Enable assertions when running',
56 default=False,
57 action='store_true')
58 result.add_argument('--print-times',
59 help='Print timing information from r8',
60 default=False,
61 action='store_true')
62 result.add_argument('--temp',
63 help='A directory to use for temporaries and outputs.',
64 default=None)
65 return result.parse_known_args(argv)
66
67def main(argv):
68 (options, args) = parse_options(argv)
69
70 if options.golem:
71 options.no_build = True
72 if options.nolib:
73 print("Error: golem should always run r8lib")
74 return 1
75
76 if options.nolib:
77 buildTargets = [NONLIB_BUILD_TARGET] + NONLIB_TEST_BUILD_TARGETS
78 r8jar = utils.R8_WITH_RELOCATED_DEPS_JAR
79 testjars = [utils.R8_TESTS_DEPS_JAR, utils.R8_TESTS_JAR]
80 else:
81 buildTargets = GOLEM_BUILD_TARGETS
82 r8jar = utils.R8LIB_JAR
83 testjars = [utils.R8LIB_TESTS_DEPS_JAR, utils.R8LIB_TESTS_JAR]
84
85 if not options.no_build:
86 gradle.RunGradle(buildTargets + ['-Pno_internal'])
87
88 return run(options, r8jar, testjars)
89
90def run(options, r8jar, testjars):
91 jdkhome = get_jdk_home(options, options.benchmark)
92 cmd = [jdk.GetJavaExecutable(jdkhome)]
93 if options.enable_assertions:
94 cmd.append('-ea')
95 if options.print_times:
96 cmd.append('-Dcom.android.tools.r8.printtimes=1')
97 cmd.extend(['-cp', ':'.join([r8jar] + testjars)])
98 cmd.extend([
99 'com.android.tools.r8.benchmarks.BenchmarkMainEntryRunner',
100 options.benchmark,
101 options.target,
Ian Zerny14f956b2022-02-24 13:57:55 +0100102 'golem' if options.golem else 'local',
Ian Zerny161ff742022-01-20 12:39:40 +0100103 ])
104 return subprocess.check_call(cmd)
105
106if __name__ == '__main__':
107 sys.exit(main(sys.argv[1:]))