# HG changeset patch # User Tom Rodriguez # Date 1404759289 25200 # Node ID 7520833c6e7f03d915a623d8316ad982e95332e9 # Parent 434888b63a155966429231760a1cc8eb2b1535a0 eliminate JUnitWrapper diff -r 434888b63a15 -r 7520833c6e7f graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java --- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java Mon Jul 07 11:53:25 2014 -0700 +++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java Mon Jul 07 11:54:49 2014 -0700 @@ -22,6 +22,7 @@ */ package com.oracle.graal.test; +import java.io.*; import java.util.*; import junit.runner.*; @@ -54,7 +55,7 @@ boolean color = false; boolean eagerStackTrace = false; boolean gcAfterTest = false; - for (String each : args) { + for (String each : expandArgs(args)) { if (each.charAt(0) == '-') { // command line arguments if (each.contentEquals("-JUnitVerbose")) { @@ -134,4 +135,60 @@ } System.exit(result.wasSuccessful() ? 0 : 1); } + + /** + * Expand any arguments starting with @ and return the resulting argument array. + * + * @param args + * @return the expanded argument array + */ + private static String[] expandArgs(String[] args) { + List result = null; + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (arg.length() > 0 && arg.charAt(0) == '@') { + if (result == null) { + result = new ArrayList<>(); + for (int j = 0; j < i; j++) { + result.add(args[j]); + } + expandArg(arg.substring(1), result); + } + } else if (result != null) { + result.add(arg); + } + } + return result != null ? result.toArray(new String[0]) : args; + } + + /** + * Add each line from {@code filename} to the list {@code args}. + * + * @param filename + * @param args + */ + private static void expandArg(String filename, List args) { + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(filename)); + + String buf; + while ((buf = br.readLine()) != null) { + args.add(buf); + } + br.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + System.exit(2); + } finally { + try { + if (br != null) { + br.close(); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + System.exit(3); + } + } + } } diff -r 434888b63a15 -r 7520833c6e7f mx/JUnitWrapper.java --- a/mx/JUnitWrapper.java Mon Jul 07 11:53:25 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -/* Execute testcases by reading names from a given file, due to limits of - * the operating system regarding command line size (windows: 32k, - * linux [depending on the settings]: ~2097k) - * see http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx - */ -import com.oracle.graal.test.*; -import java.io.*; -import java.util.*; - -public class JUnitWrapper { - - /** - * @param args - * args[0] is the path where to read the names of the testclasses. - */ - public static void main(String[] args) { - if (args.length == 0) { - System.err.printf("wrong usage. provide a filename\n"); - System.exit(1); - } - ArrayList tests = new ArrayList(1000); - // add JUnit command line arguments - for (int i = 1; i < args.length; i++) { - tests.add(args[i]); - } - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(args[0])); - - String buf; - while ((buf = br.readLine()) != null) { - tests.add(buf); - } - } catch (IOException ioe) { - ioe.printStackTrace(); - System.exit(2); - } finally { - try { - if (br != null) { - br.close(); - } - } catch (IOException ioe) { - ioe.printStackTrace(); - System.exit(3); - } - } - - String[] strargs = tests.toArray(new String[tests.size()]); - if (strargs.length == 1) { - System.out.printf("executing junit test now... (%s)\n", strargs[0]); - } else { - System.out.printf("executing junit tests now... (%d test classes)\n", strargs.length); - } - GraalJUnitCore.main(strargs); - } -} diff -r 434888b63a15 -r 7520833c6e7f mx/mx_graal.py --- a/mx/mx_graal.py Mon Jul 07 11:53:25 2014 -0700 +++ b/mx/mx_graal.py Mon Jul 07 11:54:49 2014 -0700 @@ -27,7 +27,7 @@ # ---------------------------------------------------------------------------------------------------- import os, stat, errno, sys, shutil, zipfile, tarfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, StringIO, socket -from os.path import join, exists, dirname, basename, getmtime +from os.path import join, exists, dirname, basename from argparse import ArgumentParser, RawDescriptionHelpFormatter, REMAINDER from outputparser import OutputParser, ValuesMatcher import mx @@ -985,7 +985,6 @@ for c, p in candidates.iteritems(): if t in c: found = True - # this code assumes a single test will be handled by GraalJUnitCore classes.append(c + '#' + method) projs.add(p.name) if not found: @@ -1018,19 +1017,12 @@ harness(projectsCp, vmArgs) def _unittest(args, annotations, prefixCp="", whitelist=None, verbose=False, enable_timing=False, regex=None, color=False, eager_stacktrace=False, gc_after_test=False): - mxdir = dirname(__file__) - name = 'JUnitWrapper' - javaSource = join(mxdir, name + '.java') - javaClass = join(mxdir, name + '.class') testfile = os.environ.get('MX_TESTFILE', None) if testfile is None: (_, testfile) = tempfile.mkstemp(".testclasses", "graal") os.close(_) coreCp = mx.classpath(['com.oracle.graal.test']) - if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): - subprocess.check_call([mx.java().javac, '-cp', coreCp, '-d', mxdir, javaSource]) - coreArgs = [] if verbose: coreArgs.append('-JUnitVerbose') @@ -1069,7 +1061,7 @@ # replaying the VM execution in a native debugger (e.g., gdb). vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses) else: - vm(prefixArgs + vmArgs + ['-cp', cp + os.pathsep + mxdir, name] + [testfile] + coreArgs) + vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + ['@' + testfile]) try: _run_tests(args, harness, annotations, testfile, whitelist, regex)