blob: cd9b70f6bc0d6046f53f8b2fcad265ea40f13062 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/usr/bin/env python
2# Copyright (c) 2016, 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# Convenience script for running tests. If no argument is given run all tests,
7# if an argument is given, run only tests with that pattern. This script will
8# force the tests to run, even if no input changed.
9
Jean-Marie Henaff7b424e92017-06-15 11:02:56 +020010import os
Mads Ager418d1ca2017-05-22 09:35:49 +020011import gradle
12import optparse
Rico Windf65a1d62017-06-30 09:41:56 +020013import subprocess
Mads Ager418d1ca2017-05-22 09:35:49 +020014import sys
Rico Winda94f01c2017-06-27 10:32:34 +020015import utils
16import uuid
Stephan Herhutd24b1b72017-08-24 15:09:36 +020017import notify
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020018import upload_to_x20
Mads Ager418d1ca2017-05-22 09:35:49 +020019
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020020
Stephan Herhut02f0f9d2018-01-04 10:27:31 +010021ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1", "4.4.4", "4.0.4"]
Rico Winda94f01c2017-06-27 10:32:34 +020022BUCKET = 'r8-test-results'
Mads Ager418d1ca2017-05-22 09:35:49 +020023
24def ParseOptions():
25 result = optparse.OptionParser()
Søren Gjesse77527982018-10-05 12:58:49 +020026 result.add_option('--no-internal', '--no_internal',
Mads Ager418d1ca2017-05-22 09:35:49 +020027 help='Do not run Google internal tests.',
28 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020029 result.add_option('--archive-failures', '--archive_failures',
Rico Winda94f01c2017-06-27 10:32:34 +020030 help='Upload test results to cloud storage on failure.',
31 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020032 result.add_option('--only-internal', '--only_internal',
Mads Ager418d1ca2017-05-22 09:35:49 +020033 help='Only run Google internal tests.',
34 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020035 result.add_option('--all-tests', '--all_tests',
Mads Ager418d1ca2017-05-22 09:35:49 +020036 help='Run tests in all configurations.',
37 default=False, action='store_true')
38 result.add_option('-v', '--verbose',
39 help='Print test stdout to, well, stdout.',
40 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020041 result.add_option('--dex-vm', '--dex_vm',
Mads Ager418d1ca2017-05-22 09:35:49 +020042 help='The android version of the vm to use. "all" will run the tests on '
43 'all art vm versions (stopping after first failed execution)',
44 default="default",
45 choices=ALL_ART_VMS + ["all"])
Søren Gjesse77527982018-10-05 12:58:49 +020046 result.add_option('--dex-vm-kind', '--dex_vm_kind',
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020047 help='Whether to use host or target version of runtime',
48 default="host",
49 nargs=1,
50 choices=["host", "target"])
Søren Gjesse77527982018-10-05 12:58:49 +020051 result.add_option('--one-line-per-test', '--one_line_per_test',
Mads Ager418d1ca2017-05-22 09:35:49 +020052 help='Print a line before a tests starts and after it ends to stdout.',
53 default=False, action='store_true')
54 result.add_option('--tool',
Tamas Kenezcfb2c052018-10-12 11:03:57 +020055 help='Tool to run ART tests with: "r8" (default) or "d8" or "r8cf"'
56 ' (r8 w/CF-backend). Ignored if "--all_tests" enabled.',
57 default=None, choices=["r8", "d8", "r8cf"])
Mads Ager418d1ca2017-05-22 09:35:49 +020058 result.add_option('--jctf',
Tamas Kenezcfb2c052018-10-12 11:03:57 +020059 help='Run JCTF tests with: "r8" (default) or "d8" or "r8cf".',
Mads Ager418d1ca2017-05-22 09:35:49 +020060 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020061 result.add_option('--only-jctf', '--only_jctf',
Tamas Kenezcfb2c052018-10-12 11:03:57 +020062 help='Run only JCTF tests with: "r8" (default) or "d8" or "r8cf".',
Mads Ager418d1ca2017-05-22 09:35:49 +020063 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020064 result.add_option('--jctf-compile-only', '--jctf_compile_only',
Mads Ager418d1ca2017-05-22 09:35:49 +020065 help="Don't run, only compile JCTF tests.",
66 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020067 result.add_option('--aosp-jar', '--aosp_jar',
Tamas Kenez0cad51c2017-08-21 14:42:01 +020068 help='Run aosp_jar test.',
69 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020070 result.add_option('--disable-assertions', '--disable_assertions',
Tamas Kenezb77b7d82017-08-17 14:05:16 +020071 help='Disable assertions when running tests.',
Søren Gjesseaf1c5e22017-06-15 12:24:03 +020072 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020073 result.add_option('--with-code-coverage', '--with_code_coverage',
Tamas Kenezb77b7d82017-08-17 14:05:16 +020074 help='Enable code coverage with Jacoco.',
Sebastien Hertze2687b62017-07-25 11:16:04 +020075 default=False, action='store_true')
Søren Gjesse77527982018-10-05 12:58:49 +020076 result.add_option('--test-dir', '--test_dir',
Tamas Kenezb77b7d82017-08-17 14:05:16 +020077 help='Use a custom directory for the test artifacts instead of a'
78 ' temporary (which is automatically removed after the test).'
79 ' Note that the directory will not be cleared before the test.')
Søren Gjesse77527982018-10-05 12:58:49 +020080 result.add_option('--java-home', '--java_home',
Mikaël Peltier5c0a3232017-10-18 09:14:40 +020081 help='Use a custom java version to run tests.')
Søren Gjesse77527982018-10-05 12:58:49 +020082 result.add_option('--generate-golden-files-to', '--generate_golden_files_to',
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020083 help='Store dex files produced by tests in the specified directory.'
84 ' It is aimed to be read on platforms with no host runtime available'
85 ' for comparison.')
Søren Gjesse77527982018-10-05 12:58:49 +020086 result.add_option('--use-golden-files-in', '--use_golden_files_in',
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020087 help='Download golden files hierarchy for this commit in the specified'
88 ' location and use them instead of executing on host runtime.')
Mads Ager418d1ca2017-05-22 09:35:49 +020089
90 return result.parse_args()
91
Rico Winda94f01c2017-06-27 10:32:34 +020092def archive_failures():
93 upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests')
94 u_dir = uuid.uuid4()
95 destination = 'gs://%s/%s' % (BUCKET, u_dir)
Rico Windd0d88cf2018-02-09 09:46:11 +010096 utils.upload_dir_to_cloud_storage(upload_dir, destination, is_html=True)
Rico Wind8c4a0a22017-08-05 07:02:07 +020097 url = 'http://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, u_dir)
Rico Winda94f01c2017-06-27 10:32:34 +020098 print 'Test results available at: %s' % url
Rico Wind1f1a71a2017-08-15 09:27:13 +020099 print '@@@STEP_LINK@Test failures@%s@@@' % url
Rico Winda94f01c2017-06-27 10:32:34 +0200100
Mads Ager418d1ca2017-05-22 09:35:49 +0200101def Main():
102 (options, args) = ParseOptions()
Rico Windd7c47312018-09-27 10:07:38 +0200103 if 'BUILDBOT_BUILDERNAME' in os.environ:
104 gradle.RunGradle(['clean'])
Sebastien Hertze2687b62017-07-25 11:16:04 +0200105
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +0200106 gradle_args = ['--stacktrace']
Sebastien Hertze2687b62017-07-25 11:16:04 +0200107 # Set all necessary Gradle properties and options first.
Mads Ager418d1ca2017-05-22 09:35:49 +0200108 if options.verbose:
109 gradle_args.append('-Pprint_test_stdout')
110 if options.no_internal:
111 gradle_args.append('-Pno_internal')
112 if options.only_internal:
113 gradle_args.append('-Ponly_internal')
114 if options.all_tests:
115 gradle_args.append('-Pall_tests')
116 if options.tool:
117 gradle_args.append('-Ptool=%s' % options.tool)
118 if options.one_line_per_test:
119 gradle_args.append('-Pone_line_per_test')
120 if options.jctf:
121 gradle_args.append('-Pjctf')
122 if options.only_jctf:
123 gradle_args.append('-Ponly_jctf')
124 if options.jctf_compile_only:
125 gradle_args.append('-Pjctf_compile_only')
Tamas Kenez0cad51c2017-08-21 14:42:01 +0200126 if options.aosp_jar:
127 gradle_args.append('-Paosp_jar')
Søren Gjesseaf1c5e22017-06-15 12:24:03 +0200128 if options.disable_assertions:
129 gradle_args.append('-Pdisable_assertions')
Sebastien Hertze2687b62017-07-25 11:16:04 +0200130 if options.with_code_coverage:
131 gradle_args.append('-Pwith_code_coverage')
Jean-Marie Henaff7b424e92017-06-15 11:02:56 +0200132 if os.name == 'nt':
133 # temporary hack
134 gradle_args.append('-Pno_internal')
135 gradle_args.append('-x')
136 gradle_args.append('createJctfTests')
137 gradle_args.append('-x')
138 gradle_args.append('jctfCommonJar')
139 gradle_args.append('-x')
140 gradle_args.append('jctfTestsClasses')
Tamas Kenezb77b7d82017-08-17 14:05:16 +0200141 if options.test_dir:
142 gradle_args.append('-Ptest_dir=' + options.test_dir)
143 if not os.path.exists(options.test_dir):
144 os.makedirs(options.test_dir)
Mikaël Peltier5c0a3232017-10-18 09:14:40 +0200145 if options.java_home:
146 gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +0200147 if options.generate_golden_files_to:
148 gradle_args.append('-Pgenerate_golden_files_to=' + options.generate_golden_files_to)
149 if not os.path.exists(options.generate_golden_files_to):
150 os.makedirs(options.generate_golden_files_to)
151 gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
152 if options.use_golden_files_in:
153 gradle_args.append('-Puse_golden_files_in=' + options.use_golden_files_in)
154 if not os.path.exists(options.use_golden_files_in):
155 os.makedirs(options.use_golden_files_in)
156 gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1())
Sebastien Hertze2687b62017-07-25 11:16:04 +0200157 # Add Gradle tasks
158 gradle_args.append('cleanTest')
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200159 # Build R8lib with dependencies for bootstrapping tests.
160 gradle_args.append('r8libWithDeps')
Sebastien Hertze2687b62017-07-25 11:16:04 +0200161 gradle_args.append('test')
Sebastien Hertz0f4e7fb2017-10-02 11:33:45 +0200162 # Test filtering. Must always follow the 'test' task.
163 for testFilter in args:
Sebastien Hertze2687b62017-07-25 11:16:04 +0200164 gradle_args.append('--tests')
Sebastien Hertz0f4e7fb2017-10-02 11:33:45 +0200165 gradle_args.append(testFilter)
Sebastien Hertze2687b62017-07-25 11:16:04 +0200166 if options.with_code_coverage:
167 # Create Jacoco report after tests.
168 gradle_args.append('jacocoTestReport')
169
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +0200170 if options.use_golden_files_in:
171 sha1 = '%s' % utils.get_HEAD_sha1()
172 with utils.ChangedWorkingDirectory(options.use_golden_files_in):
173 utils.download_file_from_cloud_storage(
174 'gs://r8-test-results/golden-files/%s.tar.gz' % sha1,
175 '%s.tar.gz' % sha1)
176 utils.unpack_archive('%s.tar.gz' % sha1)
177
178
Sebastien Hertze2687b62017-07-25 11:16:04 +0200179 # Now run tests on selected runtime(s).
Mads Ager418d1ca2017-05-22 09:35:49 +0200180 vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS
181 for art_vm in vms_to_test:
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200182 vm_kind_to_test = "_" + options.dex_vm_kind if art_vm != "default" else ""
183 return_code = gradle.RunGradle(gradle_args + ['-Pdex_vm=%s' % (art_vm + vm_kind_to_test)],
Rico Winda94f01c2017-06-27 10:32:34 +0200184 throw_on_failure=False)
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +0200185
186 if options.generate_golden_files_to:
187 sha1 = '%s' % utils.get_HEAD_sha1()
188 with utils.ChangedWorkingDirectory(options.generate_golden_files_to):
189 archive = utils.create_archive(sha1)
190 utils.upload_file_to_cloud_storage(archive,
191 'gs://r8-test-results/golden-files/' + archive)
192
Rico Winda94f01c2017-06-27 10:32:34 +0200193 if return_code != 0:
Rico Winddce9c872017-08-14 14:49:04 +0200194 if options.archive_failures and os.name != 'nt':
Rico Winda94f01c2017-06-27 10:32:34 +0200195 archive_failures()
196 return return_code
Mads Ager418d1ca2017-05-22 09:35:49 +0200197
Jinseong Jeon9749d172017-09-19 00:25:01 -0700198 return 0
199
Mads Ager418d1ca2017-05-22 09:35:49 +0200200if __name__ == '__main__':
Stephan Herhutd24b1b72017-08-24 15:09:36 +0200201 return_code = Main()
202 if return_code != 0:
203 notify.notify("Tests failed.")
204 else:
205 notify.notify("Tests passed.")
206 sys.exit(return_code)