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