blob: 8c47219c3e9810e54a4b1dd47dcba6085516d5d8 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/usr/bin/env python
2# Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Convenience script for running tests. If no argument is given run all tests,
7# if an argument is given, run only tests with that pattern. This script will
8# force the tests to run, even if no input changed.
9
Jean-Marie Henaff7b424e92017-06-15 11:02:56 +020010import os
Mads Ager418d1ca2017-05-22 09:35:49 +020011import gradle
12import optparse
Rico Windf65a1d62017-06-30 09:41:56 +020013import subprocess
Mads Ager418d1ca2017-05-22 09:35:49 +020014import sys
Rico Winda94f01c2017-06-27 10:32:34 +020015import utils
16import uuid
Stephan Herhutd24b1b72017-08-24 15:09:36 +020017import notify
Mads Ager418d1ca2017-05-22 09:35:49 +020018
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020019
ager539203f2017-09-19 07:46:50 +020020ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1", "4.4.4"]
Rico Winda94f01c2017-06-27 10:32:34 +020021BUCKET = 'r8-test-results'
Mads Ager418d1ca2017-05-22 09:35:49 +020022
23def 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 Winda94f01c2017-06-27 10:32:34 +020028 result.add_option('--archive_failures',
29 help='Upload test results to cloud storage on failure.',
30 default=False, action='store_true')
Mads Ager418d1ca2017-05-22 09:35:49 +020031 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 Henaffce162f32017-10-04 10:39:27 +020045 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 Ager418d1ca2017-05-22 09:35:49 +020050 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 Kenezb77b7d82017-08-17 14:05:16 +020054 help='Tool to run ART tests with: "r8" (default) or "d8". Ignored if'
55 ' "--all_tests" enabled.',
Mads Ager418d1ca2017-05-22 09:35:49 +020056 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 Kenez0cad51c2017-08-21 14:42:01 +020066 result.add_option('--aosp_jar',
67 help='Run aosp_jar test.',
68 default=False, action='store_true')
Søren Gjesseaf1c5e22017-06-15 12:24:03 +020069 result.add_option('--disable_assertions',
Tamas Kenezb77b7d82017-08-17 14:05:16 +020070 help='Disable assertions when running tests.',
Søren Gjesseaf1c5e22017-06-15 12:24:03 +020071 default=False, action='store_true')
Sebastien Hertze2687b62017-07-25 11:16:04 +020072 result.add_option('--with_code_coverage',
Tamas Kenezb77b7d82017-08-17 14:05:16 +020073 help='Enable code coverage with Jacoco.',
Sebastien Hertze2687b62017-07-25 11:16:04 +020074 default=False, action='store_true')
Tamas Kenezb77b7d82017-08-17 14:05:16 +020075 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 Peltier5c0a3232017-10-18 09:14:40 +020079 result.add_option('--java_home',
80 help='Use a custom java version to run tests.')
Mads Ager418d1ca2017-05-22 09:35:49 +020081
82 return result.parse_args()
83
Rico Winda94f01c2017-06-27 10:32:34 +020084def 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 Windb4621c12017-08-28 12:48:53 +020088 utils.upload_dir_to_cloud_storage(upload_dir, destination)
Rico Wind8c4a0a22017-08-05 07:02:07 +020089 url = 'http://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, u_dir)
Rico Winda94f01c2017-06-27 10:32:34 +020090 print 'Test results available at: %s' % url
Rico Wind1f1a71a2017-08-15 09:27:13 +020091 print '@@@STEP_LINK@Test failures@%s@@@' % url
Rico Winda94f01c2017-06-27 10:32:34 +020092
Mads Ager418d1ca2017-05-22 09:35:49 +020093def Main():
94 (options, args) = ParseOptions()
Sebastien Hertze2687b62017-07-25 11:16:04 +020095
96 gradle_args = []
97 # Set all necessary Gradle properties and options first.
Mads Ager418d1ca2017-05-22 09:35:49 +020098 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 Kenez0cad51c2017-08-21 14:42:01 +0200116 if options.aosp_jar:
117 gradle_args.append('-Paosp_jar')
Søren Gjesseaf1c5e22017-06-15 12:24:03 +0200118 if options.disable_assertions:
119 gradle_args.append('-Pdisable_assertions')
Sebastien Hertze2687b62017-07-25 11:16:04 +0200120 if options.with_code_coverage:
121 gradle_args.append('-Pwith_code_coverage')
Jean-Marie Henaff7b424e92017-06-15 11:02:56 +0200122 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 Kenezb77b7d82017-08-17 14:05:16 +0200131 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 Peltier5c0a3232017-10-18 09:14:40 +0200135 if options.java_home:
136 gradle_args.append('-Dorg.gradle.java.home=' + options.java_home)
Sebastien Hertze2687b62017-07-25 11:16:04 +0200137
138 # Add Gradle tasks
139 gradle_args.append('cleanTest')
140 gradle_args.append('test')
Sebastien Hertz0f4e7fb2017-10-02 11:33:45 +0200141 # Test filtering. Must always follow the 'test' task.
142 for testFilter in args:
Sebastien Hertze2687b62017-07-25 11:16:04 +0200143 gradle_args.append('--tests')
Sebastien Hertz0f4e7fb2017-10-02 11:33:45 +0200144 gradle_args.append(testFilter)
Sebastien Hertze2687b62017-07-25 11:16:04 +0200145 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 Ager418d1ca2017-05-22 09:35:49 +0200150 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 Henaffce162f32017-10-04 10:39:27 +0200152 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 Winda94f01c2017-06-27 10:32:34 +0200154 throw_on_failure=False)
155 if return_code != 0:
Rico Winddce9c872017-08-14 14:49:04 +0200156 if options.archive_failures and os.name != 'nt':
Rico Winda94f01c2017-06-27 10:32:34 +0200157 archive_failures()
158 return return_code
Mads Ager418d1ca2017-05-22 09:35:49 +0200159
Jinseong Jeon9749d172017-09-19 00:25:01 -0700160 return 0
161
Mads Ager418d1ca2017-05-22 09:35:49 +0200162if __name__ == '__main__':
Stephan Herhutd24b1b72017-08-24 15:09:36 +0200163 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 Jeon9749d172017-09-19 00:25:01 -0700169