changeset 16419:7520833c6e7f

eliminate JUnitWrapper
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Mon, 07 Jul 2014 11:54:49 -0700
parents 434888b63a15
children e4ac25d4e13d
files graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java mx/JUnitWrapper.java mx/mx_graal.py
diffstat 3 files changed, 60 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- 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<String> 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<String> 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);
+            }
+        }
+    }
 }
--- 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<String> tests = new ArrayList<String>(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);
-    }
-}
--- 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)