/hg/icedtea6: Corrected JTreg harness - this tool now accepts "p...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Tue Nov 23 02:36:38 PST 2010
changeset 4aef376b7123 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=4aef376b7123
author: ptisnovs
date: Tue Nov 23 11:39:48 2010 +0100
Corrected JTreg harness - this tool now accepts "process" flag for
"compile" tag and also correctly sets properties during the
"compile" phase.
diffstat:
7 files changed, 345 insertions(+), 22 deletions(-)
ChangeLog | 13
test/jtreg/README | 6
test/jtreg/com/sun/javatest/regtest/Action.java | 20 +
test/jtreg/com/sun/javatest/regtest/CompileAction.java | 147 +++++++-
test/jtreg/com/sun/javatest/regtest/Path.java | 164 ++++++++++
test/jtreg/com/sun/javatest/regtest/RegressionScript.java | 15
test/jtreg/com/sun/javatest/regtest/RegressionSecurityManager.java | 2
diffs (truncated from 562 to 500 lines):
diff -r 789ec2d452bd -r 4aef376b7123 ChangeLog
--- a/ChangeLog Mon Nov 22 04:51:01 2010 +0100
+++ b/ChangeLog Tue Nov 23 11:39:48 2010 +0100
@@ -1,3 +1,16 @@ 2010-11-22 Matthias Klose <doko at ubuntu
+2010-11-23 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * test/jtreg/README:
+ Updated.
+ * test/jtreg/com/sun/javatest/regtest/Path.java:
+ * test/jtreg/com/sun/javatest/regtest/Action.java:
+ * test/jtreg/com/sun/javatest/regtest/CompileAction.java:
+ * test/jtreg/com/sun/javatest/regtest/RegressionScript.java:
+ * test/jtreg/com/sun/javatest/regtest/RegressionSecurityManager.java:
+ Corrected JTreg harness - this tool now accepts "process" flag for
+ "compile" tag and also correctly sets properties during "compile"
+ phase.
+
2010-11-22 Matthias Klose <doko at ubuntu.com>
* Makefile.am (stamps/add-zero.stamp): Add shark alias when building
diff -r 789ec2d452bd -r 4aef376b7123 test/jtreg/README
--- a/test/jtreg/README Mon Nov 22 04:51:01 2010 +0100
+++ b/test/jtreg/README Tue Nov 23 11:39:48 2010 +0100
@@ -20,7 +20,11 @@ This version is based on:
This version is based on:
- jtharness-oss-4_1_3a-dev
-- jtreg-4_0-src-b02-15_oct_2008
+- jtreg-4_0-src-b02-15_oct_2008 with two changes backported from
+ jtreg-4.1-src-b02_21_may_2010.zip. The first change adds support for
+ option named "process" which can be used along with tag "compile". The
+ second change corrects the setting of system properties when the
+ "compile" phase is started.
IcedJTReg is distrubuted under the GPLv2.0, like jtreg and jtharness.
See the documents in the legal directory included in this release.
diff -r 789ec2d452bd -r 4aef376b7123 test/jtreg/com/sun/javatest/regtest/Action.java
--- a/test/jtreg/com/sun/javatest/regtest/Action.java Mon Nov 22 04:51:01 2010 +0100
+++ b/test/jtreg/com/sun/javatest/regtest/Action.java Tue Nov 23 11:39:48 2010 +0100
@@ -300,6 +300,8 @@ public abstract class Action
section.setStatus(status);
} // endAction()
+ //----------workarounds-------------------------------------------------------
+
/**
* This method pushes the full, constructed command for the action to the
* log. The constructed command contains the the action and its arguments
@@ -425,6 +427,13 @@ public abstract class Action
EXEC_ERROR_CLEANUP = "Error while cleaning up threads after test",
CHECK_PASS = "Test description appears acceptable",
+ // used in: compile, main
+ SAMEVM_CANT_RESET_SECMGR= "Cannot reset security manager",
+ SAMEVM_CANT_RESET_PROPS = "Cannot reset system properties",
+
+ // used in:compile, main
+ AGENTVM_CANT_GET_VM = "Cannot get VM for test",
+
UNEXPECT_SYS_EXIT = "Unexpected exit from test",
CANT_FIND_SRC = "Can't file source file: ",
@@ -454,6 +463,8 @@ public abstract class Action
BUILD_UP_TO_DATE = "All files up to date",
BUILD_SUCC = "Build successful",
BUILD_LIB_LIST = " in directory-list: ",
+ BUILD_FUTURE_SOURCE = "WARNING: file %s has a modification time in the future: %s",
+ BUILD_FUTURE_SOURCE_2 = "Unexpected results may occur",
// clean
CLEAN_SUCC = "Clean successful",
@@ -478,6 +489,8 @@ public abstract class Action
COMPILE_PASS = "Compilation successful",
COMPILE_FAIL_EXPECT = "Compilation failed as expected",
COMPILE_FAIL = "Compilation failed",
+ COMPILE_CANT_RESET_SECMGR= "Cannot reset security manager",
+ COMPILE_CANT_RESET_PROPS = "Cannot reset system properties",
// ignore
IGNORE_UNEXPECT_OPTS = "Unexpected option(s) for `ignore'",
@@ -485,6 +498,11 @@ public abstract class Action
IGNORE_TEST_IGNORED_C = "Test ignored: ",
IGNORE_TEST_SUPPRESSED = "@ignore suppressed by command line option",
IGNORE_TEST_SUPPRESSED_C = "@ignore suppressed by command line option: ",
+
+ // junit
+ JUNIT_NO_DRIVER = "No JUnit 4 driver (install junit.jar next to jtreg.jar)",
+ JUNIT_NO_CLASSNAME = "No class provided for `junit'",
+ JUNIT_BAD_MAIN_ARG = "Bad argument provided for class in `junit'",
// main
MAIN_NO_CLASSNAME = "No class provided for `main'",
@@ -500,6 +518,8 @@ public abstract class Action
MAIN_UNEXPECT_VMOPT = ": vm option(s) found, need to specify /othervm",
MAIN_POLICY_WRITE_PROB= "Problems writing new policy file: ",
MAIN_POLICY_SM_PROB = "Unable to create new policy file: ",
+ MAIN_CANT_RESET_SECMGR= "Cannot reset security manager",
+ MAIN_CANT_RESET_PROPS = "Cannot reset system properties",
// runOtherJVM
MAIN_CANT_WRITE_ARGS = "Can't write `main' argument file",
diff -r 789ec2d452bd -r 4aef376b7123 test/jtreg/com/sun/javatest/regtest/CompileAction.java
--- a/test/jtreg/com/sun/javatest/regtest/CompileAction.java Mon Nov 22 04:51:01 2010 +0100
+++ b/test/jtreg/com/sun/javatest/regtest/CompileAction.java Tue Nov 23 11:39:48 2010 +0100
@@ -37,6 +37,12 @@ import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import com.sun.javatest.Status;
import com.sun.javatest.TestResult;
@@ -111,6 +117,8 @@ public class CompileAction extends Actio
timeout = parseTimeout(optValue);
} else if (optName.equals("ref")) {
ref = parseRef(optValue);
+ } else if (optName.equals("process")) {
+ process = true;
} else {
throw new ParseException(COMPILE_BAD_OPT + optName);
}
@@ -133,7 +141,7 @@ public class CompileAction extends Actio
if (!sourceFile.isAbsolute())
// User must have used @compile, so file must be
// in the same directory as the defining file.
- args[i] = script.absTestSrcDir() + FILESEP + currArg;
+ args[i] = new File(script.absTestSrcDir(), currArg).getPath();
// if (!sourceFile.exists())
// throw new ParseException(CANT_FIND_SRC);
@@ -152,10 +160,11 @@ public class CompileAction extends Actio
// assume the next element provides the classpath, add
// test.classes and test.src and lib-list to it
if (script.hasEnv()) {
- args[i+1] = addPath(args[i+1],
- script.absTestClsDir() + PATHSEP +
- script.absTestSrcDir() + PATHSEP +
- script.absClsLibListStr());
+ Path p = new Path(args[i+1])
+ .append(script.absTestClsDir())
+ .append(script.absTestSrcDir())
+ .append(script.absClsLibListStr());
+ args[i+1] = p.toString();
}
args[i+1] = singleQuoteString(args[i+1]);
}
@@ -169,22 +178,28 @@ public class CompileAction extends Actio
sourcepathp = true;
// assume the next element provides the sourcepath, add test.src
// and lib-list to it
- args[i+1] = addPath(args[i+1],
- script.absTestSrcDir() + PATHSEP +
- script.absSrcLibListStr());
+ Path p = new Path(args[i+1])
+ .append(script.absTestSrcDir())
+ .append(script.absSrcLibListStr());
+ args[i+1] = p.toString();
args[i+1] = singleQuoteString(args[i+1]);
}
+ }
+
+ // If we didn't set the destination directory, then we must not have
+ // found something ending with ".java" to compile.
+ if (script.hasEnv() && destDir == null) {
+ if (process) {
+ destDir = script.absTestClsDir();
+ if (!destDir.exists())
+ destDir.mkdirs();
+ } else
+ throw new ParseException(COMPILE_NO_DOT_JAVA);
}
} catch (RegressionScript.TestClassException e) {
throw new ParseException(e.getMessage());
}
-
- // If we didn't set the destination directory, then we must not have
- // found something ending with ".java" to compile.
- if (script.hasEnv() && destDir == null) {
- throw new ParseException(COMPILE_NO_DOT_JAVA);
- }
-
+
this.args = args;
} // init()
@@ -267,8 +282,9 @@ public class CompileAction extends Actio
List<String> javacOpts = new ArrayList<String>();
// Why JavaTest?
+ Path cp = new Path(script.getJavaTestClassPath(), script.testClassPath());
if (useCLASSPATHEnv) {
- javacOpts.add("CLASSPATH=" + script.getJavaTestClassPath() + PATHSEP + script.testClassPath());
+ javacOpts.add("CLASSPATH=" + cp);
}
javacOpts.add(script.getJavacProg());
@@ -283,7 +299,7 @@ public class CompileAction extends Actio
// JavaTest added, to match CLASSPATH, but not sure why JavaTest required at all
if (!classpathp && useClassPathOpt) {
javacOpts.add("-classpath");
- javacOpts.add(script.getJavaTestClassPath() + PATHSEP + script.testClassPath());
+ javacOpts.add(cp.toString());
}
if (!sourcepathp && useSourcePathOpt) {
@@ -291,6 +307,11 @@ public class CompileAction extends Actio
javacOpts.add(script.testSourcePath());
}
+ // Set test.src and test.classes for the benefit of annotation processors
+ for (Map.Entry<String,String> e: script.getTestProperties().entrySet()) {
+ javacOpts.add("-J-D" + e.getKey() + "=" + e.getValue());
+ }
+
String[] envVars = script.getEnvVars();
String[] jcOpts = javacOpts.toArray(new String[javacOpts.size()]);
String[] cmdArgs = StringArray.append(envVars, jcOpts);
@@ -365,7 +386,30 @@ public class CompileAction extends Actio
return status;
} // runOtherJVM()
+ final SecurityManager secMgr = System.getSecurityManager();
+
+ protected static Hashtable<?,?> copyProperties(Properties p) {
+ Hashtable<Object,Object> h = new Hashtable<Object,Object>();
+ for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements(); ) {
+ Object key = e.nextElement();
+ h.put(key, p.get(key));
+ }
+ return h;
+ }
+
+ protected static Properties newProperties(Hashtable<?,?> h) {
+ Properties p = new Properties();
+ p.putAll(h);
+ return p;
+ }
+
private Status runSameJVM() throws TestRunException {
+ // TAG-SPEC: "The source and class directories of a test are made
+ // available to main and applet actions via the system properties
+ // "test.src" and "test.classes", respectively"
+ Map<String,String> props = script.getTestProperties();
+ Hashtable sysProps = null;
+
Status status;
// CONSTRUCT THE COMMAND LINE
@@ -373,8 +417,10 @@ public class CompileAction extends Actio
javacOpts.addAll(script.getTestCompilerOptions());
- javacOpts.add("-d");
- javacOpts.add(destDir.toString());
+ if (destDir != null) {
+ javacOpts.add("-d");
+ javacOpts.add(destDir.toString());
+ }
if (!classpathp) {
javacOpts.add("-classpath");
@@ -391,7 +437,29 @@ public class CompileAction extends Actio
if (showCmd)
JTCmd("compile", cmdArgs, section);
-
+
+ if (secMgr instanceof RegressionSecurityManager) {
+ RegressionSecurityManager rsm = (RegressionSecurityManager) secMgr;
+ rsm.setAllowPropertiesAccess(true);
+ rsm.resetPropertiesAccessed();
+ sysProps = copyProperties(System.getProperties());
+
+ Properties p = System.getProperties();
+ for (Map.Entry<String,String> e: props.entrySet()) {
+ String name = e.getKey();
+ String value = e.getValue();
+ if (name.equals("test.class.path.prefix")) {
+ System.err.println("*** java.class.path" + System.getProperty("java.class.path"));
+ Path cp = new Path(value, System.getProperty("java.class.path"));
+ p.put("java.class.path", cp.toString());
+ } else {
+ System.err.println("prop: " + e.getKey() + "\t" + e.getValue());
+ p.put(e.getKey(), e.getValue());
+ }
+ }
+ System.setProperties(p);
+ }
+
// RUN THE COMPILER
// for direct use with JavaCompileCommand
@@ -503,7 +571,43 @@ public class CompileAction extends Actio
File refFile = new File(script.absTestSrcDir(), ref);
throw new TestRunException(COMPILE_CANT_FIND_REF + refFile);
}
-
+ finally
+ {
+ if (System.getSecurityManager() != secMgr) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ System.setSecurityManager(secMgr);
+ return null;
+ }
+ });
+ //System.setSecurityManager(secMgr);
+ }
+
+ // we just reset important props that were written in the test setup
+ boolean resetAllSysProps;
+ SecurityManager sm = System.getSecurityManager();
+ if (sm instanceof RegressionSecurityManager) {
+ resetAllSysProps = ((RegressionSecurityManager) sm).isPropertiesAccessed();
+ } else {
+ resetAllSysProps = true;
+ }
+ System.err.println("resetAllSysProps: " + resetAllSysProps);
+ try {
+ if (sysProps != null)
+ {
+ if (resetAllSysProps) {
+ System.setProperties(newProperties(sysProps));
+ // System.err.println("reset properties");
+ } else {
+ System.setProperty("java.class.path", (String) sysProps.get("java.class.path"));
+ // System.err.println("no need to reset properties");
+ }
+ }
+ } catch (SecurityException e) {
+ System.err.println(SAMEVM_CANT_RESET_PROPS + ": " + e);
+ }
+ }
+
return status;
} // runSameJVM()
@@ -596,6 +700,7 @@ public class CompileAction extends Actio
private int timeout = -1;
private boolean classpathp = false;
private boolean sourcepathp = false;
+ private boolean process = false;
private TestResult.Section section;
}
diff -r 789ec2d452bd -r 4aef376b7123 test/jtreg/com/sun/javatest/regtest/Path.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jtreg/com/sun/javatest/regtest/Path.java Tue Nov 23 11:39:48 2010 +0100
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.javatest.regtest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A path, as in a sequence of file system locations, such as directories,
+ * zip files and jar files.
+ */
+public class Path {
+ /**
+ * Create an empty path.
+ */
+ Path() {
+ }
+
+ /**
+ * Create a path containing the concatenation of a series of files.
+ * Equivalent to {@code new Path().append(files)}.
+ * @param files
+ */
+ Path(File... files) {
+ append(files);
+ }
+
+ /**
+ * Create a path containing the concatenation of a series of paths.
+ * Equivalent to {@code new Path().append(paths)}.
+ * @param paths
+ */
+ Path(Path... paths) {
+ append(paths);
+ }
+
+ /**
+ * Create a path containing the concatenation of a series of paths.
+ * Equivalent to {@code new Path().append(paths)}.
+ * @param paths
+ */
+ Path(String... paths) {
+ append(paths);
+ }
+
+ /**
+ * Append a series of files to the path. Files that do not exist
+ * are ignored.
+ * @param files files to be added to the path
+ * @return the path itself
+ */
+ Path append(File... files) {
+ for (File f: files) {
+ if (f.exists()) {
+ if (value.length() > 0)
+ value += PATHSEP;
+ value += f.getPath();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Append a series of paths to the path.
+ * @param paths paths to be added to the path
+ * @return the path itself
+ */
+ Path append(Path... paths) {
+ for (Path p: paths) {
+ if (p.value.length() > 0) {
+ if (value.length() > 0)
+ value += PATHSEP;
+ value += p.value;
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Append a series of paths to the path.
+ * @param paths paths to be added to the path
+ * @return the path itself
+ */
+ Path append(String... paths) {
+ for (String p: paths) {
+ if (p.length() > 0) {
+ if (value.length() > 0)
+ value += PATHSEP;
+ value += p;
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Return the series of files that are currently on the path.
+ * @return the files on the path
+ */
+ File[] split() {
+ List<File> v = new ArrayList<File>();
+ for (String s: StringArray.splitSeparator(PATHSEP, value)) {
+ if (s.length() > 0) {
+ v.add(new File(s));
+ }
+ }
+ return v.toArray(new File[v.size()]);
+ }
+
+ /**
+ * Check if this path contains a subpath.
+ * @param path the subpath to be checked
+ * @return true if this path contains the subpath
+ */
+ boolean contains(Path path) {
+ return value.equals(path.value)
+ || value.startsWith(path.value + PATHSEP)
+ || value.endsWith(PATHSEP + path.value)
+ || value.contains(PATHSEP + path.value + PATHSEP);
+ }
+
+ /**
+ * Check if this path is empty.
More information about the distro-pkg-dev
mailing list