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