test.py revision af1c5e208527c5e1edc58c78eebcef328d5c90db
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
10import gradle
11import optparse
12import sys
13
14ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1"]
15
16def ParseOptions():
17  result = optparse.OptionParser()
18  result.add_option('--no_internal',
19      help='Do not run Google internal tests.',
20      default=False, action='store_true')
21  result.add_option('--only_internal',
22      help='Only run Google internal tests.',
23      default=False, action='store_true')
24  result.add_option('--all_tests',
25      help='Run tests in all configurations.',
26      default=False, action='store_true')
27  result.add_option('-v', '--verbose',
28      help='Print test stdout to, well, stdout.',
29      default=False, action='store_true')
30  result.add_option('--dex_vm',
31      help='The android version of the vm to use. "all" will run the tests on '
32           'all art vm versions (stopping after first failed execution)',
33      default="default",
34      choices=ALL_ART_VMS + ["all"])
35  result.add_option('--one_line_per_test',
36      help='Print a line before a tests starts and after it ends to stdout.',
37      default=False, action='store_true')
38  result.add_option('--tool',
39      help='Tool to run ART tests with: "r8" (default) or "d8". Ignored if "--all_tests" enabled.',
40      default=None, choices=["r8", "d8"])
41  result.add_option('--jctf',
42      help='Run JCTF tests with: "r8" (default) or "d8".',
43      default=False, action='store_true')
44  result.add_option('--only_jctf',
45      help='Run only JCTF tests with: "r8" (default) or "d8".',
46      default=False, action='store_true')
47  result.add_option('--jctf_compile_only',
48      help="Don't run, only compile JCTF tests.",
49      default=False, action='store_true')
50  result.add_option('--disable_assertions',
51      help="Disable assertions when running tests.",
52      default=False, action='store_true')
53
54  return result.parse_args()
55
56def Main():
57  (options, args) = ParseOptions()
58  gradle_args = ['cleanTest', 'test']
59  if len(args) > 1:
60    print("test.py takes at most one argument, the pattern for tests to run")
61    return -1
62  if options.verbose:
63    gradle_args.append('-Pprint_test_stdout')
64  if options.no_internal:
65    gradle_args.append('-Pno_internal')
66  if options.only_internal:
67    gradle_args.append('-Ponly_internal')
68  if options.all_tests:
69    gradle_args.append('-Pall_tests')
70  if options.tool:
71    gradle_args.append('-Ptool=%s' % options.tool)
72  if options.one_line_per_test:
73    gradle_args.append('-Pone_line_per_test')
74  if options.jctf:
75    gradle_args.append('-Pjctf')
76  if options.only_jctf:
77    gradle_args.append('-Ponly_jctf')
78  if options.jctf_compile_only:
79    gradle_args.append('-Pjctf_compile_only')
80  if options.disable_assertions:
81    gradle_args.append('-Pdisable_assertions')
82  if len(args) > 0:
83    gradle_args.append('--tests')
84    gradle_args.append(args[0])
85
86  vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS
87  for art_vm in vms_to_test:
88    gradle.RunGradle(gradle_args + ['-Pdex_vm=%s' % art_vm])
89
90if __name__ == '__main__':
91  sys.exit(Main())
92