changeset 15907:7d1690e145ae

mx: option to force a GC after each unit test
author Roland Schatz <roland.schatz@oracle.com>
date Fri, 23 May 2014 11:44:18 +0200
parents 5f692474fba3
children 70bb8df01b6e
files graal/com.oracle.graal.test/src/com/oracle/graal/test/GCAfterTestDecorator.java graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java mx/mx_graal.py
diffstat 3 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GCAfterTestDecorator.java	Fri May 23 11:44:18 2014 +0200
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2014, 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 org.junit.runner.*;
+
+public class GCAfterTestDecorator extends GraalJUnitRunListenerDecorator {
+
+    public GCAfterTestDecorator(GraalJUnitRunListener l) {
+        super(l);
+    }
+
+    @Override
+    public void testFinished(Description description) {
+        System.gc();
+        super.testFinished(description);
+    }
+}
--- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Mon May 26 12:03:04 2014 +0200
+++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java	Fri May 23 11:44:18 2014 +0200
@@ -51,6 +51,7 @@
         boolean enableTiming = false;
         boolean color = false;
         boolean eagerStackTrace = false;
+        boolean gcAfterTest = false;
         for (String each : args) {
             if (each.charAt(0) == '-') {
                 // command line arguments
@@ -62,6 +63,8 @@
                     color = true;
                 } else if (each.contentEquals("-JUnitEagerStackTrace")) {
                     eagerStackTrace = true;
+                } else if (each.contentEquals("-JUnitGCAfterTest")) {
+                    gcAfterTest = true;
                 } else {
                     system.out().println("Unknown command line argument: " + each);
                 }
@@ -92,6 +95,9 @@
         if (eagerStackTrace) {
             graalListener = new EagerStackTraceDecorator(graalListener);
         }
+        if (gcAfterTest) {
+            graalListener = new GCAfterTestDecorator(graalListener);
+        }
         junitCore.addListener(GraalTextListener.createRunListener(graalListener));
         Result result = junitCore.run(classes.toArray(new Class[0]));
         for (Failure each : missingClasses) {
--- a/mx/mx_graal.py	Mon May 26 12:03:04 2014 +0200
+++ b/mx/mx_graal.py	Fri May 23 11:44:18 2014 +0200
@@ -976,7 +976,7 @@
         f_testfile.close()
         harness(projectscp, vmArgs)
 
-def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False, enable_timing=False, regex=None, color=False, eager_stacktrace=False):
+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')
@@ -999,6 +999,8 @@
         coreArgs.append('-JUnitColor')
     if eager_stacktrace:
         coreArgs.append('-JUnitEagerStackTrace')
+    if gc_after_test:
+        coreArgs.append('-JUnitGCAfterTest')
 
 
     def harness(projectscp, vmArgs):
@@ -1031,6 +1033,7 @@
       --regex <regex>        run only testcases matching a regular expression
       --color                enable colors output
       --eager-stacktrace     print stacktrace eagerly
+      --gc-after-test        force a GC after each test
 
     To avoid conflicts with VM options '--' can be used as delimiter.
 
@@ -1073,6 +1076,7 @@
     parser.add_argument('--regex', help='run only testcases matching a regular expression', metavar='<regex>')
     parser.add_argument('--color', help='enable color output', action='store_true')
     parser.add_argument('--eager-stacktrace', help='print stacktrace eagerly', action='store_true')
+    parser.add_argument('--gc-after-test', help='force a GC after each test', action='store_true')
 
     ut_args = []
     delimiter = False