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