changeset 8340:d9d883aeb96f

unittest: seperate target `longunittest' and `shortunittest' There are some unittests which took a quite long time, e.g. Test6850611 takes about 16seconds on my machine. We want them to shift into a seperate mx target. In order to move a testcase to `longunittest' you have to replace all `@Test' with `@LongTest' in the testclass. `@Test' belongs to `shortunittest'. The target `unittest` executes both, `@Test' and `@LongTest'. Note: Mixing `@Test' and `@LongTest' in a testclass, causes that each testmethod is executed for both, `shortunittest' and `longunittest', mx targets.
author Bernhard Urban <bernhard.urban@jku.at>
date Thu, 14 Mar 2013 19:07:42 +0100
parents 338e4adafa71
children c38d2870439e
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/hotspot/Test6850611.java graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalLongUnitTest.java graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java graal/com.oracle.graal.test/src/com/oracle/graal/test/LongTest.java mx/commands.py
diffstat 5 files changed, 122 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/hotspot/Test6850611.java	Mon Mar 18 00:36:23 2013 +0100
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/hotspot/Test6850611.java	Thu Mar 14 19:07:42 2013 +0100
@@ -22,8 +22,8 @@
  */
 package com.oracle.graal.jtt.hotspot;
 
+import com.oracle.graal.test.*;
 import com.oracle.graal.jtt.*;
-import org.junit.*;
 
 //@formatter:off
 
@@ -50,7 +50,7 @@
         return 95;
     }
 
-    @Test
+    @LongTest
     public void run0() throws Throwable {
         runTest("test");
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalLongUnitTest.java	Thu Mar 14 19:07:42 2013 +0100
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package com.oracle.graal.test;
+
+import java.util.*;
+
+import org.junit.*;
+import org.junit.runners.*;
+import org.junit.runners.model.*;
+
+public class GraalLongUnitTest extends BlockJUnit4ClassRunner {
+
+    public GraalLongUnitTest(Class<?> klass) throws InitializationError {
+        super(klass);
+    }
+
+    @Override
+    protected List<FrameworkMethod> computeTestMethods() {
+        List<FrameworkMethod> methods = new ArrayList<>(5);
+        methods.addAll(getTestClass().getAnnotatedMethods(Test.class));
+        methods.addAll(getTestClass().getAnnotatedMethods(LongTest.class));
+        return methods;
+    }
+}
--- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java	Mon Mar 18 00:36:23 2013 +0100
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java	Thu Mar 14 19:07:42 2013 +0100
@@ -25,12 +25,14 @@
 import java.lang.reflect.*;
 
 import org.junit.*;
+import org.junit.runner.*;
 
 /**
  * Base class for Graal tests.
  * <p>
  * This contains common utility methods that are used in multiple test projects.
  */
+@RunWith(GraalLongUnitTest.class)
 public class GraalTest {
 
     protected Method getMethod(String methodName) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/LongTest.java	Thu Mar 14 19:07:42 2013 +0100
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package com.oracle.graal.test;
+
+import java.lang.annotation.*;
+
+/* copy of org.junit.Test */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+public @interface LongTest {
+
+    static final class None extends Throwable {
+
+        private static final long serialVersionUID = 1L;
+
+        private None() {
+        }
+    }
+
+    Class<? extends Throwable> expected() default None.class;
+
+    long timeout() default 0L;
+}
--- a/mx/commands.py	Mon Mar 18 00:36:23 2013 +0100
+++ b/mx/commands.py	Thu Mar 14 19:07:42 2013 +0100
@@ -719,7 +719,7 @@
     matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0
     return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses)
 
-def _run_tests(args, harness):
+def _run_tests(args, harness, annotations):
     pos = [a for a in args if a[0] != '-' and a[0] != '@' ]
     neg = [a[1:] for a in args if a[0] == '-']
     vmArgs = [a[1:] for a in args if a[0] == '@']
@@ -731,7 +731,7 @@
         return False
 
     for p in mx.projects():
-        classes = _find_classes_with_annotations(p, None, ['@Test'])
+        classes = _find_classes_with_annotations(p, None, annotations)
 
         if len(pos) != 0:
             classes = [c for c in classes if containsAny(c, pos)]
@@ -742,17 +742,38 @@
             mx.log('running tests in ' + p.name)
             harness(p, vmArgs, classes)
 
+def _unittest(args, annotations):
+    def harness(p, vmArgs, classes):
+        prefixArgs = ['-XX:-BootstrapGraal', '-esa', '-ea']
+        vm(prefixArgs + vmArgs + ['-cp', mx.classpath(p.name), 'org.junit.runner.JUnitCore'] + classes)
+    _run_tests(args, harness, annotations)
+
 def unittest(args):
-    """run the JUnit tests
+    """run the JUnit tests (all testcases)
 
     If filters are supplied, only tests whose fully qualified name
     include a filter as a substring are run. Negative filters are
     those with a '-' prefix. VM args should have a @ prefix."""
 
-    def harness(p, vmArgs, classes):
-        prefixArgs = ['-XX:-BootstrapGraal', '-esa', '-ea']
-        vm(prefixArgs + vmArgs + ['-cp', mx.classpath(p.name), 'org.junit.runner.JUnitCore'] + classes)
-    _run_tests(args, harness)
+    _unittest(args, ['@Test', '@LongTest'])
+
+def shortunittest(args):
+    """run the JUnit tests (short testcases only)
+
+    If filters are supplied, only tests whose fully qualified name
+    include a filter as a substring are run. Negative filters are
+    those with a '-' prefix. VM args should have a @ prefix."""
+
+    _unittest(args, ['@Test'])
+
+def longunittest(args):
+    """run the JUnit tests (long testcases only)
+
+    If filters are supplied, only tests whose fully qualified name
+    include a filter as a substring are run. Negative filters are
+    those with a '-' prefix. VM args should have a @ prefix."""
+
+    _unittest(args, ['@LongTest'])
 
 def buildvms(args):
     """build one or more VMs in various configurations"""
@@ -872,7 +893,7 @@
         t = Task('BootstrapWithRegisterPressure:product')
         vm(['-G:RegisterPressure=rbx,r11,r14,xmm3,xmm11,xmm14', '-esa', '-version'])
         tasks.append(t.stop())
-        
+
         originalVm = _vm
         _vm = 'server' # hosted mode
         t = Task('UnitTests:hosted-product')
@@ -1193,6 +1214,8 @@
         'gv' : [gv, ''],
         'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'],
         'unittest' : [unittest, '[filters...]'],
+        'longunittest' : [longunittest, '[filters...]'],
+        'shortunittest' : [shortunittest, '[filters...]'],
         'jacocoreport' : [jacocoreport, '[output directory]'],
         'site' : [site, '[-options]'],
         'vm': [vm, '[-options] class [args...]'],