comparison mx/mx_graal.py @ 15502:a26be2c9b81b

Add command line support for JUnit.
author Josef Eisl <josef.eisl@jku.at>
date Mon, 05 May 2014 16:07:20 +0200
parents f2132fab8a6f
children c62e120e8cd9
comparison
equal deleted inserted replaced
15501:008a8c905d7e 15502:a26be2c9b81b
944 for c in classes: 944 for c in classes:
945 f_testfile.write(c + '\n') 945 f_testfile.write(c + '\n')
946 f_testfile.close() 946 f_testfile.close()
947 harness(projectscp, vmArgs) 947 harness(projectscp, vmArgs)
948 948
949 def _unittest(args, annotations, prefixcp="", whitelist=None): 949 def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False):
950 mxdir = dirname(__file__) 950 mxdir = dirname(__file__)
951 name = 'JUnitWrapper' 951 name = 'JUnitWrapper'
952 javaSource = join(mxdir, name + '.java') 952 javaSource = join(mxdir, name + '.java')
953 javaClass = join(mxdir, name + '.class') 953 javaClass = join(mxdir, name + '.class')
954 testfile = os.environ.get('MX_TESTFILE', None) 954 testfile = os.environ.get('MX_TESTFILE', None)
955 if testfile is None: 955 if testfile is None:
956 (_, testfile) = tempfile.mkstemp(".testclasses", "graal") 956 (_, testfile) = tempfile.mkstemp(".testclasses", "graal")
957 os.close(_) 957 os.close(_)
958 corecp = mx.classpath(['com.oracle.graal.test']) 958 corecp = mx.classpath(['com.oracle.graal.test'])
959 coreArgs = ['-JUnitVerbose'] if verbose else []
959 960
960 def harness(projectscp, vmArgs): 961 def harness(projectscp, vmArgs):
961 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): 962 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
962 subprocess.check_call([mx.java().javac, '-cp', projectscp, '-d', mxdir, javaSource]) 963 subprocess.check_call([mx.java().javac, '-cp', projectscp, '-d', mxdir, javaSource])
963 if _get_vm() != 'graal': 964 if _get_vm() != 'graal':
967 with open(testfile) as fp: 968 with open(testfile) as fp:
968 testclasses = [l.rstrip() for l in fp.readlines()] 969 testclasses = [l.rstrip() for l in fp.readlines()]
969 if len(testclasses) == 1: 970 if len(testclasses) == 1:
970 # Execute Junit directly when one test is being run. This simplifies 971 # Execute Junit directly when one test is being run. This simplifies
971 # replaying the VM execution in a native debugger (e.g., gdb). 972 # replaying the VM execution in a native debugger (e.g., gdb).
972 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp, 'com.oracle.graal.test.GraalJUnitCore'] + testclasses) 973 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses)
973 else: 974 else:
974 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp + os.pathsep + mxdir, name] + [testfile]) 975 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp + os.pathsep + mxdir, name] + [testfile] + coreArgs)
975 976
976 try: 977 try:
977 _run_tests(args, harness, annotations, testfile, whitelist) 978 _run_tests(args, harness, annotations, testfile, whitelist)
978 finally: 979 finally:
979 if os.environ.get('MX_TESTFILE') is None: 980 if os.environ.get('MX_TESTFILE') is None:
982 _unittestHelpSuffix = """ 983 _unittestHelpSuffix = """
983 Unittest options: 984 Unittest options:
984 985
985 --whitelist run only testcases which are included 986 --whitelist run only testcases which are included
986 in the given whitelist 987 in the given whitelist
988 --verbose enable verbose JUnit output
987 989
988 To avoid conflicts with VM options '--' can be used as delimiter. 990 To avoid conflicts with VM options '--' can be used as delimiter.
989 991
990 If filters are supplied, only tests whose fully qualified name 992 If filters are supplied, only tests whose fully qualified name
991 includes a filter as a substring are run. 993 includes a filter as a substring are run.
1019 add_help=False, 1021 add_help=False,
1020 formatter_class=RawDescriptionHelpFormatter, 1022 formatter_class=RawDescriptionHelpFormatter,
1021 epilog=_unittestHelpSuffix, 1023 epilog=_unittestHelpSuffix,
1022 ) 1024 )
1023 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') 1025 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>')
1026 parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true')
1024 1027
1025 ut_args = [] 1028 ut_args = []
1026 delimiter = False 1029 delimiter = False
1027 # check for delimiter 1030 # check for delimiter
1028 while len(args) > 0: 1031 while len(args) > 0:
1045 with open(join(_graal_home, parsed_args.whitelist)) as fp: 1048 with open(join(_graal_home, parsed_args.whitelist)) as fp:
1046 whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] 1049 whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')]
1047 except IOError: 1050 except IOError:
1048 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) 1051 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist)
1049 1052
1050 _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist) 1053 _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist, verbose=parsed_args.verbose)
1051 1054
1052 def shortunittest(args): 1055 def shortunittest(args):
1053 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" 1056 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}"""
1054 1057
1055 args = ['--whitelist', 'test/whitelist_shortunittest.txt'] + args 1058 args = ['--whitelist', 'test/whitelist_shortunittest.txt'] + args