Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/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 | |
Ian Zerny | 019e778 | 2021-04-20 15:34:01 +0200 | [diff] [blame] | 10 | import archive_desugar_jdk_libs |
| 11 | import notify |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 12 | import optparse |
Ian Zerny | 5fffb0a | 2019-02-11 13:54:22 +0100 | [diff] [blame] | 13 | import os |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 14 | import shutil |
Rico Wind | f65a1d6 | 2017-06-30 09:41:56 +0200 | [diff] [blame] | 15 | import subprocess |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 16 | import sys |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 17 | import thread |
| 18 | import time |
Rico Wind | 06487ac | 2018-12-10 09:09:19 +0100 | [diff] [blame] | 19 | import uuid |
Ian Zerny | 5fffb0a | 2019-02-11 13:54:22 +0100 | [diff] [blame] | 20 | |
| 21 | import gradle |
Ian Zerny | 5fffb0a | 2019-02-11 13:54:22 +0100 | [diff] [blame] | 22 | import utils |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 23 | |
Søren Gjesse | fe7c011 | 2018-12-03 12:33:12 +0100 | [diff] [blame] | 24 | ALL_ART_VMS = [ |
| 25 | "default", |
clementbera | 97d5cce | 2019-11-22 15:09:27 +0100 | [diff] [blame] | 26 | "10.0.0", |
Søren Gjesse | fe7c011 | 2018-12-03 12:33:12 +0100 | [diff] [blame] | 27 | "9.0.0", |
| 28 | "8.1.0", |
| 29 | "7.0.0", |
| 30 | "6.0.1", |
| 31 | "5.1.1", |
| 32 | "4.4.4", |
| 33 | "4.0.4"] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 34 | |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 35 | # How often do we check for progress on the bots: |
| 36 | # Should be long enough that a normal run would always have med progress |
| 37 | # Should be short enough that we ensure that two calls are close enough |
| 38 | # to happen before bot times out. |
| 39 | # A false positiv, i.e., printing the stacks of non hanging processes |
| 40 | # is not a problem, no harm done except some logging in the stdout. |
| 41 | TIMEOUT_HANDLER_PERIOD = 60 * 18 |
| 42 | |
Rico Wind | 06487ac | 2018-12-10 09:09:19 +0100 | [diff] [blame] | 43 | BUCKET = 'r8-test-results' |
| 44 | |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 45 | NUMBER_OF_TEST_REPORTS = 5 |
| 46 | REPORTS_PATH = os.path.join(utils.BUILD, 'reports') |
| 47 | REPORT_INDEX = ['tests', 'test', 'index.html'] |
Ian Zerny | bcbd6c5 | 2019-10-29 15:27:04 +0100 | [diff] [blame] | 48 | VALID_RUNTIMES = [ |
| 49 | 'none', |
| 50 | 'jdk8', |
| 51 | 'jdk9', |
| 52 | 'jdk11', |
| 53 | ] + [ 'dex-%s' % dexvm for dexvm in ALL_ART_VMS ] |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 54 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 55 | def ParseOptions(): |
| 56 | result = optparse.OptionParser() |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 57 | result.add_option('--no-internal', '--no_internal', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 58 | help='Do not run Google internal tests.', |
| 59 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 60 | result.add_option('--archive-failures', '--archive_failures', |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 61 | help='Upload test results to cloud storage on failure.', |
| 62 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 63 | result.add_option('--only-internal', '--only_internal', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 64 | help='Only run Google internal tests.', |
| 65 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 66 | result.add_option('--all-tests', '--all_tests', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 67 | help='Run tests in all configurations.', |
| 68 | default=False, action='store_true') |
Christoffer Quist Adamsen | 748e466 | 2019-08-23 14:53:49 +0200 | [diff] [blame] | 69 | result.add_option('--slow-tests', '--slow_tests', |
| 70 | help='Also run slow tests.', |
| 71 | default=False, action='store_true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 72 | result.add_option('-v', '--verbose', |
| 73 | help='Print test stdout to, well, stdout.', |
| 74 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 75 | result.add_option('--dex-vm', '--dex_vm', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 76 | help='The android version of the vm to use. "all" will run the tests on ' |
| 77 | 'all art vm versions (stopping after first failed execution)', |
| 78 | default="default", |
| 79 | choices=ALL_ART_VMS + ["all"]) |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 80 | result.add_option('--dex-vm-kind', '--dex_vm_kind', |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 81 | help='Whether to use host or target version of runtime', |
| 82 | default="host", |
| 83 | nargs=1, |
| 84 | choices=["host", "target"]) |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 85 | result.add_option('--one-line-per-test', '--one_line_per_test', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 86 | help='Print a line before a tests starts and after it ends to stdout.', |
| 87 | default=False, action='store_true') |
| 88 | result.add_option('--tool', |
Tamas Kenez | cfb2c05 | 2018-10-12 11:03:57 +0200 | [diff] [blame] | 89 | help='Tool to run ART tests with: "r8" (default) or "d8" or "r8cf"' |
| 90 | ' (r8 w/CF-backend). Ignored if "--all_tests" enabled.', |
| 91 | default=None, choices=["r8", "d8", "r8cf"]) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 92 | result.add_option('--jctf', |
Tamas Kenez | cfb2c05 | 2018-10-12 11:03:57 +0200 | [diff] [blame] | 93 | help='Run JCTF tests with: "r8" (default) or "d8" or "r8cf".', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 94 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 95 | result.add_option('--only-jctf', '--only_jctf', |
Tamas Kenez | cfb2c05 | 2018-10-12 11:03:57 +0200 | [diff] [blame] | 96 | help='Run only JCTF tests with: "r8" (default) or "d8" or "r8cf".', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 97 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 98 | result.add_option('--jctf-compile-only', '--jctf_compile_only', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 99 | help="Don't run, only compile JCTF tests.", |
| 100 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 101 | result.add_option('--disable-assertions', '--disable_assertions', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 102 | help='Disable assertions when running tests.', |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 103 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 104 | result.add_option('--with-code-coverage', '--with_code_coverage', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 105 | help='Enable code coverage with Jacoco.', |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 106 | default=False, action='store_true') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 107 | result.add_option('--test-dir', '--test_dir', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 108 | help='Use a custom directory for the test artifacts instead of a' |
| 109 | ' temporary (which is automatically removed after the test).' |
| 110 | ' Note that the directory will not be cleared before the test.') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 111 | result.add_option('--java-home', '--java_home', |
Mikaël Peltier | 5c0a323 | 2017-10-18 09:14:40 +0200 | [diff] [blame] | 112 | help='Use a custom java version to run tests.') |
Ian Zerny | 5fffb0a | 2019-02-11 13:54:22 +0100 | [diff] [blame] | 113 | result.add_option('--java-max-memory-size', '--java_max_memory_size', |
Rico Wind | 97b0a99 | 2019-08-30 11:09:15 +0200 | [diff] [blame] | 114 | help='Set memory for running tests, default 4G', |
| 115 | default='4G') |
Rico Wind | ba15111 | 2020-10-01 08:16:33 +0200 | [diff] [blame] | 116 | result.add_option('--test-namespace', '--test_namespace', |
| 117 | help='Only run tests in this namespace. The namespace is relative to ' |
| 118 | 'com/android/tools/r8, e.g., desugar/desugaredlibrary', |
| 119 | default=None) |
Rico Wind | 8e2f7e4 | 2019-02-21 10:13:21 +0100 | [diff] [blame] | 120 | result.add_option('--shard-count', '--shard_count', |
| 121 | help='We are running this many shards.') |
| 122 | result.add_option('--shard-number', '--shard_number', |
| 123 | help='We are running this shard.') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 124 | result.add_option('--generate-golden-files-to', '--generate_golden_files_to', |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 125 | help='Store dex files produced by tests in the specified directory.' |
| 126 | ' It is aimed to be read on platforms with no host runtime available' |
| 127 | ' for comparison.') |
Søren Gjesse | 7752798 | 2018-10-05 12:58:49 +0200 | [diff] [blame] | 128 | result.add_option('--use-golden-files-in', '--use_golden_files_in', |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 129 | help='Download golden files hierarchy for this commit in the specified' |
| 130 | ' location and use them instead of executing on host runtime.') |
Søren Gjesse | 1956bdb | 2019-02-19 08:37:52 +0100 | [diff] [blame] | 131 | result.add_option('--no-r8lib', '--no_r8lib', |
| 132 | default=False, action='store_true', |
Morten Krogh-Jespersen | 2243b16 | 2019-01-14 08:40:53 +0100 | [diff] [blame] | 133 | help='Run the tests on R8 full with relocated dependencies.') |
Søren Gjesse | 1956bdb | 2019-02-19 08:37:52 +0100 | [diff] [blame] | 134 | result.add_option('--r8lib-no-deps', '--r8lib_no_deps', |
| 135 | default=False, action='store_true', |
Morten Krogh-Jespersen | 807b15f | 2018-12-17 14:24:22 +0100 | [diff] [blame] | 136 | help='Run the tests on r8lib without relocated dependencies.') |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 137 | result.add_option('--failed', |
| 138 | default=False, action='store_true', |
| 139 | help='Run the tests that failed last execution.') |
| 140 | result.add_option('--fail-fast', '--fail_fast', |
| 141 | default=False, action='store_true', |
| 142 | help='Stop on first failure. Passes --fail-fast to gradle test runner.') |
Morten Krogh-Jespersen | 89d005b | 2019-10-15 13:32:23 +0200 | [diff] [blame] | 143 | result.add_option('--worktree', |
| 144 | default=False, action='store_true', |
| 145 | help='Tests are run in worktree and should not use gradle user home.') |
Ian Zerny | bcbd6c5 | 2019-10-29 15:27:04 +0100 | [diff] [blame] | 146 | result.add_option('--runtimes', |
| 147 | default=None, |
| 148 | help='Test parameter runtimes to use, separated by : (eg, none:jdk9).' |
| 149 | ' Special values include: all (for all runtimes)' |
| 150 | ' and empty (for no runtimes).') |
Morten Krogh-Jespersen | dcb8d45 | 2020-07-09 15:07:50 +0200 | [diff] [blame] | 151 | result.add_option('--print-hanging-stacks', '--print_hanging_stacks', |
| 152 | default=-1, type="int", help='Print hanging stacks after timeout in seconds') |
Christoffer Quist Adamsen | 7bf6034 | 2020-11-09 14:00:27 +0100 | [diff] [blame] | 153 | result.add_option('--print-full-stacktraces', '--print_full_stacktraces', |
| 154 | default=False, action='store_true', |
| 155 | help='Print the full stacktraces without any filtering applied') |
| 156 | result.add_option( |
| 157 | '--print-obfuscated-stacktraces', '--print_obfuscated_stacktraces', |
| 158 | default=False, action='store_true', |
| 159 | help='Print the obfuscated stacktraces') |
Morten Krogh-Jespersen | 2d3aca6 | 2020-11-30 12:48:11 +0100 | [diff] [blame] | 160 | result.add_option( |
| 161 | '--debug-agent', '--debug_agent', |
| 162 | help='Enable Java debug agent and suspend compilation (default disabled)', |
| 163 | default=False, |
| 164 | action='store_true') |
Rico Wind | e139309 | 2021-03-21 12:57:01 +0100 | [diff] [blame] | 165 | result.add_option('--desugared-library-configuration', |
| 166 | '--desugared_library-configuration', |
Søren Gjesse | ef19577 | 2021-03-11 16:04:42 +0100 | [diff] [blame] | 167 | help='Use alternative desugared library configuration.') |
Søren Gjesse | 4a45f9b | 2021-02-11 14:05:29 +0100 | [diff] [blame] | 168 | result.add_option('--desugared-library', '--desugared_library', |
| 169 | help='Build and use desugared library from GitHub.') |
Rico Wind | f2f4c29 | 2021-04-23 07:06:13 +0200 | [diff] [blame] | 170 | result.add_option('--print-times', '--print_times', |
| 171 | help='Print the execution time of the slowest tests..', |
| 172 | default=False, action='store_true') |
Ian Zerny | 9a0e96a | 2021-04-28 12:35:49 +0200 | [diff] [blame] | 173 | result.add_option( |
Ian Zerny | 27ea4c7 | 2021-04-29 22:35:49 +0200 | [diff] [blame] | 174 | '--with-testing-state', |
| 175 | help='Run/resume tests using testing state.', |
| 176 | default=False, action='store_true') |
| 177 | result.add_option( |
| 178 | '--reset-testing-state', |
| 179 | help='Clean the testing state and rerun tests (implies --with-testing-state).', |
Ian Zerny | 9a0e96a | 2021-04-28 12:35:49 +0200 | [diff] [blame] | 180 | default=False, action='store_true') |
| 181 | result.add_option( |
| 182 | '--stacktrace', |
| 183 | help='Pass --stacktrace to the gradle run', |
| 184 | default=False, action='store_true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 185 | return result.parse_args() |
| 186 | |
Rico Wind | 06487ac | 2018-12-10 09:09:19 +0100 | [diff] [blame] | 187 | def archive_failures(): |
| 188 | upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests') |
| 189 | u_dir = uuid.uuid4() |
| 190 | destination = 'gs://%s/%s' % (BUCKET, u_dir) |
| 191 | utils.upload_dir_to_cloud_storage(upload_dir, destination, is_html=True) |
Rico Wind | 70d614f | 2020-01-31 08:45:21 +0100 | [diff] [blame] | 192 | url = 'https://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, u_dir) |
Rico Wind | 06487ac | 2018-12-10 09:09:19 +0100 | [diff] [blame] | 193 | print 'Test results available at: %s' % url |
| 194 | print '@@@STEP_LINK@Test failures@%s@@@' % url |
| 195 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 196 | def Main(): |
| 197 | (options, args) = ParseOptions() |
Rico Wind | 3f82c20 | 2019-11-25 07:19:23 +0100 | [diff] [blame] | 198 | |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 199 | if utils.is_bot(): |
Rico Wind | 22707fc | 2019-03-15 13:19:57 +0100 | [diff] [blame] | 200 | gradle.RunGradle(['--no-daemon', 'clean']) |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 201 | |
Søren Gjesse | ef19577 | 2021-03-11 16:04:42 +0100 | [diff] [blame] | 202 | desugar_jdk_json_dir = None |
| 203 | if options.desugared_library_configuration: |
| 204 | if options.desugared_library_configuration != 'jdk11': |
| 205 | print("Only value supported for --desugared-library is 'jdk11'") |
| 206 | exit(1) |
| 207 | desugar_jdk_json_dir = 'src/library_desugar/jdk11' |
| 208 | |
Søren Gjesse | 4a45f9b | 2021-02-11 14:05:29 +0100 | [diff] [blame] | 209 | desugar_jdk_libs = None |
| 210 | if options.desugared_library: |
| 211 | if options.desugared_library != 'HEAD': |
| 212 | print("Only value supported for --desugared-library is 'HEAD'") |
| 213 | exit(1) |
| 214 | desugar_jdk_libs_dir = 'build/desugar_jdk_libs' |
| 215 | shutil.rmtree(desugar_jdk_libs_dir, ignore_errors=True) |
| 216 | os.makedirs(desugar_jdk_libs_dir) |
| 217 | print('Building desugared library.') |
| 218 | with utils.TempDir() as checkout_dir: |
| 219 | archive_desugar_jdk_libs.CloneDesugaredLibrary('google', checkout_dir) |
Rico Wind | e4b43a3 | 2021-03-02 09:29:52 +0100 | [diff] [blame] | 220 | # Make sure bazel is extracted in third_party. |
| 221 | utils.DownloadFromGoogleCloudStorage(utils.BAZEL_SHA_FILE) |
| 222 | utils.DownloadFromGoogleCloudStorage(utils.JAVA8_SHA_FILE) |
Søren Gjesse | ef19577 | 2021-03-11 16:04:42 +0100 | [diff] [blame] | 223 | utils.DownloadFromGoogleCloudStorage(utils.JAVA11_SHA_FILE) |
| 224 | (library_jar, maven_zip) = archive_desugar_jdk_libs.BuildDesugaredLibrary(checkout_dir, 'jdk11' if options.desugared_library_configuration == 'jdk11' else 'jdk8') |
Søren Gjesse | 4a45f9b | 2021-02-11 14:05:29 +0100 | [diff] [blame] | 225 | desugar_jdk_libs = os.path.join(desugar_jdk_libs_dir, os.path.basename(library_jar)) |
| 226 | shutil.copyfile(library_jar, desugar_jdk_libs) |
| 227 | print('Desugared library for test in ' + desugar_jdk_libs) |
| 228 | |
Ian Zerny | 9a0e96a | 2021-04-28 12:35:49 +0200 | [diff] [blame] | 229 | gradle_args = [] |
| 230 | |
| 231 | if options.stacktrace or utils.is_bot(): |
| 232 | gradle_args.append('--stacktrace') |
| 233 | |
Rico Wind | 22707fc | 2019-03-15 13:19:57 +0100 | [diff] [blame] | 234 | if utils.is_bot(): |
Rico Wind | 24777b9 | 2020-06-19 22:44:14 +0200 | [diff] [blame] | 235 | # Bots don't like dangling processes. |
Rico Wind | 22707fc | 2019-03-15 13:19:57 +0100 | [diff] [blame] | 236 | gradle_args.append('--no-daemon') |
| 237 | |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 238 | # Set all necessary Gradle properties and options first. |
Rico Wind | 8e2f7e4 | 2019-02-21 10:13:21 +0100 | [diff] [blame] | 239 | if options.shard_count: |
| 240 | assert options.shard_number |
| 241 | gradle_args.append('-Pshard_count=%s' % options.shard_count) |
| 242 | gradle_args.append('-Pshard_number=%s' % options.shard_number) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 243 | if options.verbose: |
| 244 | gradle_args.append('-Pprint_test_stdout') |
| 245 | if options.no_internal: |
| 246 | gradle_args.append('-Pno_internal') |
| 247 | if options.only_internal: |
| 248 | gradle_args.append('-Ponly_internal') |
| 249 | if options.all_tests: |
| 250 | gradle_args.append('-Pall_tests') |
Christoffer Quist Adamsen | 748e466 | 2019-08-23 14:53:49 +0200 | [diff] [blame] | 251 | if options.slow_tests: |
| 252 | gradle_args.append('-Pslow_tests=1') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 253 | if options.tool: |
| 254 | gradle_args.append('-Ptool=%s' % options.tool) |
| 255 | if options.one_line_per_test: |
| 256 | gradle_args.append('-Pone_line_per_test') |
| 257 | if options.jctf: |
| 258 | gradle_args.append('-Pjctf') |
| 259 | if options.only_jctf: |
| 260 | gradle_args.append('-Ponly_jctf') |
Rico Wind | ba15111 | 2020-10-01 08:16:33 +0200 | [diff] [blame] | 261 | if options.test_namespace: |
| 262 | gradle_args.append('-Ptest_namespace=%s' % options.test_namespace) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 263 | if options.jctf_compile_only: |
| 264 | gradle_args.append('-Pjctf_compile_only') |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 265 | if options.disable_assertions: |
| 266 | gradle_args.append('-Pdisable_assertions') |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 267 | if options.with_code_coverage: |
| 268 | gradle_args.append('-Pwith_code_coverage') |
Christoffer Quist Adamsen | 7bf6034 | 2020-11-09 14:00:27 +0100 | [diff] [blame] | 269 | if options.print_full_stacktraces: |
| 270 | gradle_args.append('-Pprint_full_stacktraces') |
| 271 | if options.print_obfuscated_stacktraces: |
| 272 | gradle_args.append('-Pprint_obfuscated_stacktraces') |
Jean-Marie Henaff | 7b424e9 | 2017-06-15 11:02:56 +0200 | [diff] [blame] | 273 | if os.name == 'nt': |
| 274 | # temporary hack |
| 275 | gradle_args.append('-Pno_internal') |
| 276 | gradle_args.append('-x') |
| 277 | gradle_args.append('createJctfTests') |
| 278 | gradle_args.append('-x') |
| 279 | gradle_args.append('jctfCommonJar') |
| 280 | gradle_args.append('-x') |
| 281 | gradle_args.append('jctfTestsClasses') |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 282 | if options.test_dir: |
| 283 | gradle_args.append('-Ptest_dir=' + options.test_dir) |
| 284 | if not os.path.exists(options.test_dir): |
| 285 | os.makedirs(options.test_dir) |
Mikaël Peltier | 5c0a323 | 2017-10-18 09:14:40 +0200 | [diff] [blame] | 286 | if options.java_home: |
| 287 | gradle_args.append('-Dorg.gradle.java.home=' + options.java_home) |
Ian Zerny | 5fffb0a | 2019-02-11 13:54:22 +0100 | [diff] [blame] | 288 | if options.java_max_memory_size: |
Rico Wind | 97b0a99 | 2019-08-30 11:09:15 +0200 | [diff] [blame] | 289 | gradle_args.append('-Ptest_xmx=' + options.java_max_memory_size) |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 290 | if options.generate_golden_files_to: |
| 291 | gradle_args.append('-Pgenerate_golden_files_to=' + options.generate_golden_files_to) |
| 292 | if not os.path.exists(options.generate_golden_files_to): |
| 293 | os.makedirs(options.generate_golden_files_to) |
| 294 | gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1()) |
| 295 | if options.use_golden_files_in: |
| 296 | gradle_args.append('-Puse_golden_files_in=' + options.use_golden_files_in) |
| 297 | if not os.path.exists(options.use_golden_files_in): |
| 298 | os.makedirs(options.use_golden_files_in) |
| 299 | gradle_args.append('-PHEAD_sha1=' + utils.get_HEAD_sha1()) |
Morten Krogh-Jespersen | 432dd91 | 2019-01-14 13:26:35 +0100 | [diff] [blame] | 300 | if (not options.no_r8lib) and options.r8lib_no_deps: |
Morten Krogh-Jespersen | 2243b16 | 2019-01-14 08:40:53 +0100 | [diff] [blame] | 301 | print('Cannot run tests on r8lib with and without deps. R8lib is now default target.') |
Morten Krogh-Jespersen | 807b15f | 2018-12-17 14:24:22 +0100 | [diff] [blame] | 302 | exit(1) |
Morten Krogh-Jespersen | 2243b16 | 2019-01-14 08:40:53 +0100 | [diff] [blame] | 303 | if not options.no_r8lib: |
Morten Krogh-Jespersen | 807b15f | 2018-12-17 14:24:22 +0100 | [diff] [blame] | 304 | gradle_args.append('-Pr8lib') |
Morten Krogh-Jespersen | 54f196e | 2019-01-14 16:10:08 +0100 | [diff] [blame] | 305 | # Force gradle to build a version of r8lib without dependencies for |
| 306 | # BootstrapCurrentEqualityTest. |
| 307 | gradle_args.append('R8LibNoDeps') |
Morten Krogh-Jespersen | 0d7a96f | 2021-01-11 17:48:12 +0100 | [diff] [blame] | 308 | gradle_args.append('R8Retrace') |
Morten Krogh-Jespersen | 807b15f | 2018-12-17 14:24:22 +0100 | [diff] [blame] | 309 | if options.r8lib_no_deps: |
| 310 | gradle_args.append('-Pr8lib_no_deps') |
Morten Krogh-Jespersen | 89d005b | 2019-10-15 13:32:23 +0200 | [diff] [blame] | 311 | if options.worktree: |
| 312 | gradle_args.append('-g=' + os.path.join(utils.REPO_ROOT, ".gradle_user_home")) |
Ian Zerny | a97ccc4 | 2020-02-10 14:18:07 +0100 | [diff] [blame] | 313 | gradle_args.append('--no-daemon') |
Morten Krogh-Jespersen | 2d3aca6 | 2020-11-30 12:48:11 +0100 | [diff] [blame] | 314 | if options.debug_agent: |
| 315 | gradle_args.append('--no-daemon') |
Søren Gjesse | ef19577 | 2021-03-11 16:04:42 +0100 | [diff] [blame] | 316 | if desugar_jdk_json_dir: |
| 317 | gradle_args.append('-Pdesugar_jdk_json_dir=' + desugar_jdk_json_dir) |
Søren Gjesse | 4a45f9b | 2021-02-11 14:05:29 +0100 | [diff] [blame] | 318 | if desugar_jdk_libs: |
| 319 | gradle_args.append('-Pdesugar_jdk_libs=' + desugar_jdk_libs) |
Ian Zerny | 27ea4c7 | 2021-04-29 22:35:49 +0200 | [diff] [blame] | 320 | if options.reset_testing_state: |
| 321 | gradle_args.append('-Ptesting-state') |
| 322 | gradle_args.append('-Preset-testing-state') |
| 323 | elif options.with_testing_state: |
| 324 | gradle_args.append('-Ptesting-state') |
Morten Krogh-Jespersen | 807b15f | 2018-12-17 14:24:22 +0100 | [diff] [blame] | 325 | |
Morten Krogh-Jespersen | 54f196e | 2019-01-14 16:10:08 +0100 | [diff] [blame] | 326 | # Build an R8 with dependencies for bootstrapping tests before adding test sources. |
Morten Krogh-Jespersen | 47393d9 | 2020-05-01 12:39:38 +0200 | [diff] [blame] | 327 | gradle_args.append('r8WithDeps') |
| 328 | gradle_args.append('r8WithDeps11') |
Morten Krogh-Jespersen | 54f196e | 2019-01-14 16:10:08 +0100 | [diff] [blame] | 329 | gradle_args.append('r8WithRelocatedDeps') |
clementbera | 55e8482 | 2019-06-06 16:08:11 +0200 | [diff] [blame] | 330 | gradle_args.append('r8WithRelocatedDeps11') |
Morten Krogh-Jespersen | 54f196e | 2019-01-14 16:10:08 +0100 | [diff] [blame] | 331 | |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 332 | # Add Gradle tasks |
| 333 | gradle_args.append('cleanTest') |
| 334 | gradle_args.append('test') |
Morten Krogh-Jespersen | 2d3aca6 | 2020-11-30 12:48:11 +0100 | [diff] [blame] | 335 | if options.debug_agent: |
| 336 | gradle_args.append('--debug-jvm') |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 337 | if options.fail_fast: |
| 338 | gradle_args.append('--fail-fast') |
| 339 | if options.failed: |
| 340 | args = compute_failed_tests(args) |
| 341 | if args is None: |
| 342 | return 1 |
| 343 | if len(args) == 0: |
| 344 | print "No failing tests" |
| 345 | return 0 |
Sebastien Hertz | 0f4e7fb | 2017-10-02 11:33:45 +0200 | [diff] [blame] | 346 | # Test filtering. Must always follow the 'test' task. |
| 347 | for testFilter in args: |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 348 | gradle_args.append('--tests') |
Sebastien Hertz | 0f4e7fb | 2017-10-02 11:33:45 +0200 | [diff] [blame] | 349 | gradle_args.append(testFilter) |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 350 | if options.with_code_coverage: |
| 351 | # Create Jacoco report after tests. |
| 352 | gradle_args.append('jacocoTestReport') |
| 353 | |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 354 | if options.use_golden_files_in: |
| 355 | sha1 = '%s' % utils.get_HEAD_sha1() |
| 356 | with utils.ChangedWorkingDirectory(options.use_golden_files_in): |
| 357 | utils.download_file_from_cloud_storage( |
| 358 | 'gs://r8-test-results/golden-files/%s.tar.gz' % sha1, |
| 359 | '%s.tar.gz' % sha1) |
| 360 | utils.unpack_archive('%s.tar.gz' % sha1) |
| 361 | |
Morten Krogh-Jespersen | dcb8d45 | 2020-07-09 15:07:50 +0200 | [diff] [blame] | 362 | print_stacks_timeout = options.print_hanging_stacks |
| 363 | if (utils.is_bot() and not utils.IsWindows()) or print_stacks_timeout > -1: |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 364 | timestamp_file = os.path.join(utils.BUILD, 'last_test_time') |
| 365 | if os.path.exists(timestamp_file): |
| 366 | os.remove(timestamp_file) |
| 367 | gradle_args.append('-Pupdate_test_timestamp=' + timestamp_file) |
Morten Krogh-Jespersen | dcb8d45 | 2020-07-09 15:07:50 +0200 | [diff] [blame] | 368 | print_stacks_timeout = (print_stacks_timeout |
| 369 | if print_stacks_timeout != -1 |
| 370 | else TIMEOUT_HANDLER_PERIOD) |
| 371 | thread.start_new_thread(timeout_handler, (timestamp_file, print_stacks_timeout,)) |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 372 | rotate_test_reports() |
| 373 | |
Ian Zerny | 324d761 | 2019-03-20 10:52:28 +0100 | [diff] [blame] | 374 | if options.only_jctf: |
| 375 | # Note: not setting -Pruntimes will run with all available runtimes. |
| 376 | return_code = gradle.RunGradle(gradle_args, throw_on_failure=False) |
Ian Zerny | 1756136 | 2019-05-27 15:16:26 +0200 | [diff] [blame] | 377 | return archive_and_return(return_code, options) |
Ian Zerny | 324d761 | 2019-03-20 10:52:28 +0100 | [diff] [blame] | 378 | |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 379 | # Now run tests on selected runtime(s). |
Ian Zerny | bcbd6c5 | 2019-10-29 15:27:04 +0100 | [diff] [blame] | 380 | if options.runtimes: |
| 381 | if options.dex_vm != 'default': |
| 382 | print 'Unexpected runtimes and dex_vm argument: ' + options.dex_vm |
| 383 | sys.exit(1) |
| 384 | if options.runtimes == 'empty': |
| 385 | # Set runtimes with no content will configure no runtimes. |
| 386 | gradle_args.append('-Pruntimes=') |
| 387 | elif options.runtimes == 'all': |
| 388 | # An unset runtimes will configure all runtimes |
| 389 | pass |
| 390 | else: |
| 391 | prefixes = [prefix.strip() for prefix in options.runtimes.split(':')] |
| 392 | runtimes = [] |
| 393 | for prefix in prefixes: |
| 394 | matches = [ rt for rt in VALID_RUNTIMES if rt.startswith(prefix) ] |
| 395 | if len(matches) == 0: |
| 396 | print "Invalid runtime prefix '%s'." % prefix |
| 397 | print "Must be just 'all', 'empty'," \ |
| 398 | " or a prefix of %s" % ', '.join(VALID_RUNTIMES) |
| 399 | sys.exit(1) |
| 400 | runtimes.extend(matches) |
| 401 | gradle_args.append('-Pruntimes=%s' % ':'.join(runtimes)) |
| 402 | |
| 403 | return_code = gradle.RunGradle(gradle_args, throw_on_failure=False) |
| 404 | return archive_and_return(return_code, options) |
| 405 | |
| 406 | # Legacy testing populates the runtimes based on dex_vm. |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 407 | vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS |
Rico Wind | 124b271 | 2019-02-28 13:49:25 +0100 | [diff] [blame] | 408 | |
Rico Wind | f2f4c29 | 2021-04-23 07:06:13 +0200 | [diff] [blame] | 409 | if options.print_times: |
| 410 | gradle_args.append('-Pprint_times=true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 411 | for art_vm in vms_to_test: |
Ian Zerny | 4dfd5a5 | 2019-03-12 07:56:11 +0100 | [diff] [blame] | 412 | vm_suffix = "_" + options.dex_vm_kind if art_vm != "default" else "" |
Ian Zerny | 324d761 | 2019-03-20 10:52:28 +0100 | [diff] [blame] | 413 | runtimes = ['dex-' + art_vm] |
Ian Zerny | 019e778 | 2021-04-20 15:34:01 +0200 | [diff] [blame] | 414 | # Append the "none" runtime and default JVM if running the "default" DEX VM. |
Ian Zerny | 324d761 | 2019-03-20 10:52:28 +0100 | [diff] [blame] | 415 | if art_vm == "default": |
Morten Krogh-Jespersen | 6935894 | 2020-10-09 11:07:09 +0200 | [diff] [blame] | 416 | runtimes.extend(['jdk11', 'none']) |
Ian Zerny | 4dfd5a5 | 2019-03-12 07:56:11 +0100 | [diff] [blame] | 417 | return_code = gradle.RunGradle( |
| 418 | gradle_args + [ |
| 419 | '-Pdex_vm=%s' % art_vm + vm_suffix, |
Ian Zerny | 324d761 | 2019-03-20 10:52:28 +0100 | [diff] [blame] | 420 | '-Pruntimes=%s' % ':'.join(runtimes), |
| 421 | ], |
Ian Zerny | 4dfd5a5 | 2019-03-12 07:56:11 +0100 | [diff] [blame] | 422 | throw_on_failure=False) |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 423 | if options.generate_golden_files_to: |
| 424 | sha1 = '%s' % utils.get_HEAD_sha1() |
| 425 | with utils.ChangedWorkingDirectory(options.generate_golden_files_to): |
| 426 | archive = utils.create_archive(sha1) |
| 427 | utils.upload_file_to_cloud_storage(archive, |
| 428 | 'gs://r8-test-results/golden-files/' + archive) |
| 429 | |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 430 | if return_code != 0: |
Ian Zerny | 1756136 | 2019-05-27 15:16:26 +0200 | [diff] [blame] | 431 | return archive_and_return(return_code, options) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 432 | |
Jinseong Jeon | 9749d17 | 2017-09-19 00:25:01 -0700 | [diff] [blame] | 433 | return 0 |
| 434 | |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 435 | |
Ian Zerny | 1756136 | 2019-05-27 15:16:26 +0200 | [diff] [blame] | 436 | def archive_and_return(return_code, options): |
Rico Wind | c58a20e | 2019-05-23 09:43:19 +0200 | [diff] [blame] | 437 | if return_code != 0: |
| 438 | if options.archive_failures and os.name != 'nt': |
| 439 | archive_failures() |
| 440 | return return_code |
| 441 | |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 442 | def print_jstacks(): |
| 443 | processes = subprocess.check_output(['ps', 'aux']) |
| 444 | for l in processes.splitlines(): |
| 445 | if 'java' in l and 'openjdk' in l: |
| 446 | # Example line: |
| 447 | # ricow 184313 2.6 0.0 36839068 31808 ? Sl 09:53 0:00 /us.. |
| 448 | columns = l.split() |
| 449 | pid = columns[1] |
| 450 | return_value = subprocess.call(['jstack', pid]) |
| 451 | if return_value: |
| 452 | print('Could not jstack %s' % l) |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 453 | |
| 454 | def get_time_from_file(timestamp_file): |
| 455 | if os.path.exists(timestamp_file): |
| 456 | timestamp = os.stat(timestamp_file).st_mtime |
| 457 | print('TIMEOUT HANDLER timestamp: %s' % (timestamp)) |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 458 | sys.stdout.flush() |
| 459 | return timestamp |
| 460 | else: |
| 461 | print('TIMEOUT HANDLER no timestamp file yet') |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 462 | sys.stdout.flush() |
| 463 | return None |
| 464 | |
Morten Krogh-Jespersen | dcb8d45 | 2020-07-09 15:07:50 +0200 | [diff] [blame] | 465 | def timeout_handler(timestamp_file, timeout_handler_period): |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 466 | last_timestamp = None |
| 467 | while True: |
Morten Krogh-Jespersen | dcb8d45 | 2020-07-09 15:07:50 +0200 | [diff] [blame] | 468 | time.sleep(timeout_handler_period) |
Rico Wind | da6836e | 2018-12-07 12:32:03 +0100 | [diff] [blame] | 469 | new_timestamp = get_time_from_file(timestamp_file) |
| 470 | if last_timestamp and new_timestamp == last_timestamp: |
| 471 | print_jstacks() |
| 472 | last_timestamp = new_timestamp |
| 473 | |
Ian Zerny | 24398bc | 2019-02-22 11:59:18 +0100 | [diff] [blame] | 474 | def report_dir_path(index): |
| 475 | if index is 0: |
| 476 | return REPORTS_PATH |
| 477 | return '%s%d' % (REPORTS_PATH, index) |
| 478 | |
| 479 | def report_index_path(index): |
| 480 | return os.path.join(report_dir_path(index), *REPORT_INDEX) |
| 481 | |
| 482 | # Rotate test results so previous results are still accessible. |
| 483 | def rotate_test_reports(): |
| 484 | if not os.path.exists(report_dir_path(0)): |
| 485 | return |
| 486 | i = 1 |
| 487 | while i < NUMBER_OF_TEST_REPORTS and os.path.exists(report_dir_path(i)): |
| 488 | i += 1 |
| 489 | if i == NUMBER_OF_TEST_REPORTS and os.path.exists(report_dir_path(i)): |
| 490 | shutil.rmtree(report_dir_path(i)) |
| 491 | while i > 0: |
| 492 | shutil.move(report_dir_path(i - 1), report_dir_path(i)) |
| 493 | i -= 1 |
| 494 | |
| 495 | def compute_failed_tests(args): |
| 496 | if len(args) > 1: |
| 497 | print "Running with --failed can take an optional path to a report index (or report number)." |
| 498 | return None |
| 499 | report = report_index_path(0) |
| 500 | # If the default report does not exist, fall back to the previous report as it may be a failed |
| 501 | # gradle run which has already moved the report to report1, but did not produce a new report. |
| 502 | if not os.path.exists(report): |
| 503 | report1 = report_index_path(1) |
| 504 | if os.path.exists(report1): |
| 505 | report = report1 |
| 506 | if len(args) == 1: |
| 507 | try: |
| 508 | # try to parse the arg as a report index. |
| 509 | index = int(args[0]) |
| 510 | report = report_index_path(index) |
| 511 | except ValueError: |
| 512 | # if integer parsing failed assume it is a report file path. |
| 513 | report = args[0] |
| 514 | if not os.path.exists(report): |
| 515 | print "Can't re-run failing, no report at:", report |
| 516 | return None |
| 517 | print "Reading failed tests in", report |
| 518 | failing = set() |
| 519 | inFailedSection = False |
| 520 | for line in file(report): |
| 521 | l = line.strip() |
| 522 | if l == "<h2>Failed tests</h2>": |
| 523 | inFailedSection = True |
| 524 | elif l.startswith("<h2>"): |
| 525 | inFailedSection = False |
| 526 | prefix = '<a href="classes/' |
| 527 | if inFailedSection and l.startswith(prefix): |
| 528 | href = l[len(prefix):l.index('">')] |
| 529 | # Ignore enties ending with .html which are test classes, not test methods. |
| 530 | if not href.endswith('.html'): |
| 531 | # Remove the .html and anchor separateor, also, a classMethod test is the static |
| 532 | # setup failing so rerun the full class of tests. |
| 533 | test = href.replace('.html','').replace('#', '.').replace('.classMethod', '') |
| 534 | failing.add(test) |
| 535 | return list(failing) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 536 | if __name__ == '__main__': |
Stephan Herhut | d24b1b7 | 2017-08-24 15:09:36 +0200 | [diff] [blame] | 537 | return_code = Main() |
| 538 | if return_code != 0: |
| 539 | notify.notify("Tests failed.") |
| 540 | else: |
| 541 | notify.notify("Tests passed.") |
| 542 | sys.exit(return_code) |