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 | |
Jean-Marie Henaff | 7b424e9 | 2017-06-15 11:02:56 +0200 | [diff] [blame] | 10 | import os |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 11 | import gradle |
| 12 | import optparse |
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 | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 15 | import utils |
| 16 | import uuid |
Stephan Herhut | d24b1b7 | 2017-08-24 15:09:36 +0200 | [diff] [blame] | 17 | import notify |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 18 | |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 19 | |
ager | 539203f | 2017-09-19 07:46:50 +0200 | [diff] [blame] | 20 | ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1", "4.4.4"] |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 21 | BUCKET = 'r8-test-results' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 22 | |
| 23 | def ParseOptions(): |
| 24 | result = optparse.OptionParser() |
| 25 | result.add_option('--no_internal', |
| 26 | help='Do not run Google internal tests.', |
| 27 | default=False, action='store_true') |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 28 | result.add_option('--archive_failures', |
| 29 | help='Upload test results to cloud storage on failure.', |
| 30 | default=False, action='store_true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 31 | result.add_option('--only_internal', |
| 32 | help='Only run Google internal tests.', |
| 33 | default=False, action='store_true') |
| 34 | result.add_option('--all_tests', |
| 35 | help='Run tests in all configurations.', |
| 36 | default=False, action='store_true') |
| 37 | result.add_option('-v', '--verbose', |
| 38 | help='Print test stdout to, well, stdout.', |
| 39 | default=False, action='store_true') |
| 40 | result.add_option('--dex_vm', |
| 41 | help='The android version of the vm to use. "all" will run the tests on ' |
| 42 | 'all art vm versions (stopping after first failed execution)', |
| 43 | default="default", |
| 44 | choices=ALL_ART_VMS + ["all"]) |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 45 | result.add_option('--dex_vm_kind', |
| 46 | help='Whether to use host or target version of runtime', |
| 47 | default="host", |
| 48 | nargs=1, |
| 49 | choices=["host", "target"]) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 50 | result.add_option('--one_line_per_test', |
| 51 | help='Print a line before a tests starts and after it ends to stdout.', |
| 52 | default=False, action='store_true') |
| 53 | result.add_option('--tool', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 54 | help='Tool to run ART tests with: "r8" (default) or "d8". Ignored if' |
| 55 | ' "--all_tests" enabled.', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 56 | default=None, choices=["r8", "d8"]) |
| 57 | result.add_option('--jctf', |
| 58 | help='Run JCTF tests with: "r8" (default) or "d8".', |
| 59 | default=False, action='store_true') |
| 60 | result.add_option('--only_jctf', |
| 61 | help='Run only JCTF tests with: "r8" (default) or "d8".', |
| 62 | default=False, action='store_true') |
| 63 | result.add_option('--jctf_compile_only', |
| 64 | help="Don't run, only compile JCTF tests.", |
| 65 | default=False, action='store_true') |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 66 | result.add_option('--aosp_jar', |
| 67 | help='Run aosp_jar test.', |
| 68 | default=False, action='store_true') |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 69 | result.add_option('--disable_assertions', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 70 | help='Disable assertions when running tests.', |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 71 | default=False, action='store_true') |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 72 | result.add_option('--with_code_coverage', |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 73 | help='Enable code coverage with Jacoco.', |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 74 | default=False, action='store_true') |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 75 | result.add_option('--test_dir', |
| 76 | help='Use a custom directory for the test artifacts instead of a' |
| 77 | ' temporary (which is automatically removed after the test).' |
| 78 | ' Note that the directory will not be cleared before the test.') |
Mikaël Peltier | 5c0a323 | 2017-10-18 09:14:40 +0200 | [diff] [blame] | 79 | result.add_option('--java_home', |
| 80 | help='Use a custom java version to run tests.') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 81 | |
| 82 | return result.parse_args() |
| 83 | |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 84 | def archive_failures(): |
| 85 | upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests') |
| 86 | u_dir = uuid.uuid4() |
| 87 | destination = 'gs://%s/%s' % (BUCKET, u_dir) |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 88 | utils.upload_dir_to_cloud_storage(upload_dir, destination) |
Rico Wind | 8c4a0a2 | 2017-08-05 07:02:07 +0200 | [diff] [blame] | 89 | url = 'http://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, u_dir) |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 90 | print 'Test results available at: %s' % url |
Rico Wind | 1f1a71a | 2017-08-15 09:27:13 +0200 | [diff] [blame] | 91 | print '@@@STEP_LINK@Test failures@%s@@@' % url |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 92 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 93 | def Main(): |
| 94 | (options, args) = ParseOptions() |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 95 | |
| 96 | gradle_args = [] |
| 97 | # Set all necessary Gradle properties and options first. |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 98 | if options.verbose: |
| 99 | gradle_args.append('-Pprint_test_stdout') |
| 100 | if options.no_internal: |
| 101 | gradle_args.append('-Pno_internal') |
| 102 | if options.only_internal: |
| 103 | gradle_args.append('-Ponly_internal') |
| 104 | if options.all_tests: |
| 105 | gradle_args.append('-Pall_tests') |
| 106 | if options.tool: |
| 107 | gradle_args.append('-Ptool=%s' % options.tool) |
| 108 | if options.one_line_per_test: |
| 109 | gradle_args.append('-Pone_line_per_test') |
| 110 | if options.jctf: |
| 111 | gradle_args.append('-Pjctf') |
| 112 | if options.only_jctf: |
| 113 | gradle_args.append('-Ponly_jctf') |
| 114 | if options.jctf_compile_only: |
| 115 | gradle_args.append('-Pjctf_compile_only') |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 116 | if options.aosp_jar: |
| 117 | gradle_args.append('-Paosp_jar') |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 118 | if options.disable_assertions: |
| 119 | gradle_args.append('-Pdisable_assertions') |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 120 | if options.with_code_coverage: |
| 121 | gradle_args.append('-Pwith_code_coverage') |
Jean-Marie Henaff | 7b424e9 | 2017-06-15 11:02:56 +0200 | [diff] [blame] | 122 | if os.name == 'nt': |
| 123 | # temporary hack |
| 124 | gradle_args.append('-Pno_internal') |
| 125 | gradle_args.append('-x') |
| 126 | gradle_args.append('createJctfTests') |
| 127 | gradle_args.append('-x') |
| 128 | gradle_args.append('jctfCommonJar') |
| 129 | gradle_args.append('-x') |
| 130 | gradle_args.append('jctfTestsClasses') |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 131 | if options.test_dir: |
| 132 | gradle_args.append('-Ptest_dir=' + options.test_dir) |
| 133 | if not os.path.exists(options.test_dir): |
| 134 | os.makedirs(options.test_dir) |
Mikaël Peltier | 5c0a323 | 2017-10-18 09:14:40 +0200 | [diff] [blame] | 135 | if options.java_home: |
| 136 | gradle_args.append('-Dorg.gradle.java.home=' + options.java_home) |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 137 | |
| 138 | # Add Gradle tasks |
| 139 | gradle_args.append('cleanTest') |
| 140 | gradle_args.append('test') |
Sebastien Hertz | 0f4e7fb | 2017-10-02 11:33:45 +0200 | [diff] [blame] | 141 | # Test filtering. Must always follow the 'test' task. |
| 142 | for testFilter in args: |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 143 | gradle_args.append('--tests') |
Sebastien Hertz | 0f4e7fb | 2017-10-02 11:33:45 +0200 | [diff] [blame] | 144 | gradle_args.append(testFilter) |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 145 | if options.with_code_coverage: |
| 146 | # Create Jacoco report after tests. |
| 147 | gradle_args.append('jacocoTestReport') |
| 148 | |
| 149 | # Now run tests on selected runtime(s). |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 150 | vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS |
| 151 | for art_vm in vms_to_test: |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 152 | vm_kind_to_test = "_" + options.dex_vm_kind if art_vm != "default" else "" |
| 153 | return_code = gradle.RunGradle(gradle_args + ['-Pdex_vm=%s' % (art_vm + vm_kind_to_test)], |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 154 | throw_on_failure=False) |
| 155 | if return_code != 0: |
Rico Wind | dce9c87 | 2017-08-14 14:49:04 +0200 | [diff] [blame] | 156 | if options.archive_failures and os.name != 'nt': |
Rico Wind | a94f01c | 2017-06-27 10:32:34 +0200 | [diff] [blame] | 157 | archive_failures() |
| 158 | return return_code |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 159 | |
Jinseong Jeon | 9749d17 | 2017-09-19 00:25:01 -0700 | [diff] [blame] | 160 | return 0 |
| 161 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 162 | if __name__ == '__main__': |
Stephan Herhut | d24b1b7 | 2017-08-24 15:09:36 +0200 | [diff] [blame] | 163 | return_code = Main() |
| 164 | if return_code != 0: |
| 165 | notify.notify("Tests failed.") |
| 166 | else: |
| 167 | notify.notify("Tests passed.") |
| 168 | sys.exit(return_code) |
Jinseong Jeon | 9749d17 | 2017-09-19 00:25:01 -0700 | [diff] [blame] | 169 | |