• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 os
11import gradle
12import optparse
13import subprocess
14import sys
15import utils
16import uuid
17
18ALL_ART_VMS = ["default", "7.0.0", "6.0.1", "5.1.1"]
19BUCKET = 'r8-test-results'
20
21def ParseOptions():
22  result = optparse.OptionParser()
23  result.add_option('--no_internal',
24      help='Do not run Google internal tests.',
25      default=False, action='store_true')
26  result.add_option('--archive_failures',
27      help='Upload test results to cloud storage on failure.',
28      default=False, action='store_true')
29  result.add_option('--only_internal',
30      help='Only run Google internal tests.',
31      default=False, action='store_true')
32  result.add_option('--all_tests',
33      help='Run tests in all configurations.',
34      default=False, action='store_true')
35  result.add_option('-v', '--verbose',
36      help='Print test stdout to, well, stdout.',
37      default=False, action='store_true')
38  result.add_option('--dex_vm',
39      help='The android version of the vm to use. "all" will run the tests on '
40           'all art vm versions (stopping after first failed execution)',
41      default="default",
42      choices=ALL_ART_VMS + ["all"])
43  result.add_option('--one_line_per_test',
44      help='Print a line before a tests starts and after it ends to stdout.',
45      default=False, action='store_true')
46  result.add_option('--tool',
47      help='Tool to run ART tests with: "r8" (default) or "d8". Ignored if "--all_tests" enabled.',
48      default=None, choices=["r8", "d8"])
49  result.add_option('--jctf',
50      help='Run JCTF tests with: "r8" (default) or "d8".',
51      default=False, action='store_true')
52  result.add_option('--only_jctf',
53      help='Run only JCTF tests with: "r8" (default) or "d8".',
54      default=False, action='store_true')
55  result.add_option('--jctf_compile_only',
56      help="Don't run, only compile JCTF tests.",
57      default=False, action='store_true')
58  result.add_option('--disable_assertions',
59      help="Disable assertions when running tests.",
60      default=False, action='store_true')
61
62  return result.parse_args()
63
64def archive_failures():
65  upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests')
66  u_dir = uuid.uuid4()
67  destination = 'gs://%s/%s' % (BUCKET, u_dir)
68  utils.upload_html_to_cloud_storage(upload_dir, destination)
69  url = 'http://storage.googleapis.com/%s/%s/index.html' % (BUCKET, u_dir)
70  print 'Test results available at: %s' % url
71
72def Main():
73  (options, args) = ParseOptions()
74  gradle_args = ['cleanTest', 'test']
75  if len(args) > 1:
76    print("test.py takes at most one argument, the pattern for tests to run")
77    return -1
78  if options.verbose:
79    gradle_args.append('-Pprint_test_stdout')
80  if options.no_internal:
81    gradle_args.append('-Pno_internal')
82  if options.only_internal:
83    gradle_args.append('-Ponly_internal')
84  if options.all_tests:
85    gradle_args.append('-Pall_tests')
86  if options.tool:
87    gradle_args.append('-Ptool=%s' % options.tool)
88  if options.one_line_per_test:
89    gradle_args.append('-Pone_line_per_test')
90  if options.jctf:
91    gradle_args.append('-Pjctf')
92  if options.only_jctf:
93    gradle_args.append('-Ponly_jctf')
94  if options.jctf_compile_only:
95    gradle_args.append('-Pjctf_compile_only')
96  if options.disable_assertions:
97    gradle_args.append('-Pdisable_assertions')
98  if len(args) > 0:
99    gradle_args.append('--tests')
100    gradle_args.append(args[0])
101  if os.name == 'nt':
102    # temporary hack
103    gradle_args.append('-Pno_internal')
104    gradle_args.append('-x')
105    gradle_args.append('createJctfTests')
106    gradle_args.append('-x')
107    gradle_args.append('jctfCommonJar')
108    gradle_args.append('-x')
109    gradle_args.append('jctfTestsClasses')
110  vms_to_test = [options.dex_vm] if options.dex_vm != "all" else ALL_ART_VMS
111  for art_vm in vms_to_test:
112    return_code = gradle.RunGradle(gradle_args + ['-Pdex_vm=%s' % art_vm],
113                                   throw_on_failure=False)
114    if return_code != 0:
115      if options.archive_failures:
116        archive_failures()
117      return return_code
118
119if __name__ == '__main__':
120  sys.exit(Main())
121