8008582: jtreg failures after conversion of shell tests to Java

Reviewed-by: jjg
This commit is contained in:
Vicente Romero 2013-03-14 08:30:16 +00:00
parent 52954e063d
commit 4ef6ef5d0f
10 changed files with 199 additions and 113 deletions

View File

@ -85,17 +85,4 @@ public class ArrayUtils {
} }
} }
public static <T> T[] concat(T[] anArr, T[] anotherArr) {
int newLength = anArr.length + anotherArr.length;
@SuppressWarnings("unchecked")
T[] result = (T[]) Array.newInstance(anArr.getClass().getComponentType(), newLength);
System.arraycopy(anArr, 0, result, 0, anArr.length);
System.arraycopy(anotherArr, 0, result, anArr.length, anotherArr.length);
return result;
}
@SuppressWarnings("unchecked")
public static <T> T[] concatOpen(T[] anArr, T... anotherArr) {
return concat(anArr, anotherArr);
}
} }

View File

@ -34,9 +34,7 @@ import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import com.sun.tools.javac.util.ArrayUtils;
//original test: test/tools/javac/4846262/Test.sh
public class CheckEBCDICLocaleTest { public class CheckEBCDICLocaleTest {
private static final String TestSrc = private static final String TestSrc =
@ -46,11 +44,11 @@ public class CheckEBCDICLocaleTest {
" }\n" + " }\n" +
"}"; "}";
private static final String TestOut = private static final String TestOutTemplate =
"output/Test.java:3: error: not a statement\n" + "output%1$sTest.java:3: error: not a statement\n" +
" abcdefg\n" + " abcdefg\n" +
" ^\n" + " ^\n" +
"output/Test.java:3: error: ';' expected\n" + "output%1$sTest.java:3: error: ';' expected\n" +
" abcdefg\n" + " abcdefg\n" +
" ^\n" + " ^\n" +
"2 errors\n"; "2 errors\n";
@ -62,38 +60,37 @@ public class CheckEBCDICLocaleTest {
public void test() throws Exception { public void test() throws Exception {
String native2asciiBinary = Paths.get( String native2asciiBinary = Paths.get(
System.getProperty("test.jdk"),"bin", "native2ascii").toString(); System.getProperty("test.jdk"),"bin", "native2ascii").toString();
String testVMOpts = System.getProperty("test.tool.vm.opts");
String[] mainArgs = ToolBox.getJavacBin();
ToolBox.createJavaFileFromSource(TestSrc); ToolBox.createJavaFileFromSource(TestSrc);
Files.createDirectory(Paths.get("output")); Files.createDirectory(Paths.get("output"));
//"${TESTJAVA}${FS}bin${FS}native2ascii" ${TESTTOOLVMOPTS} -reverse -encoding IBM1047 ${TESTSRC}${FS}Test.java Test.java
ToolBox.AnyToolArgs nativeCmdParams = ToolBox.AnyToolArgs nativeCmdParams =
new ToolBox.AnyToolArgs() new ToolBox.AnyToolArgs()
.setAllArgs(native2asciiBinary, testVMOpts, .appendArgs(native2asciiBinary)
"-reverse", "-encoding", "IBM1047", .appendArgs(ToolBox.testToolVMOpts)
"Test.java", "output/Test.java"); .appendArgs("-reverse", "-encoding", "IBM1047", "Test.java",
"output/Test.java");
ToolBox.executeCommand(nativeCmdParams); ToolBox.executeCommand(nativeCmdParams);
//"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -J-Duser.language=en -J-Duser.region=US -J-Dfile.encoding=IBM1047 Test.java 2>Test.tmp
ToolBox.AnyToolArgs javacParams = ToolBox.AnyToolArgs javacParams =
new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.setAllArgs(ArrayUtils.concatOpen(mainArgs, "-J-Duser.language=en", .appendArgs(ToolBox.javacBinary)
.appendArgs(ToolBox.testToolVMOpts)
.appendArgs("-J-Duser.language=en",
"-J-Duser.region=US", "-J-Dfile.encoding=IBM1047", "-J-Duser.region=US", "-J-Dfile.encoding=IBM1047",
"output/Test.java")) "output/Test.java")
.setErrOutput(new File("Test.tmp")); .setErrOutput(new File("Test.tmp"));
ToolBox.executeCommand(javacParams); ToolBox.executeCommand(javacParams);
//"${TESTJAVA}${FS}bin${FS}native2ascii" ${TESTTOOLVMOPTS} -encoding IBM1047 Test.tmp Test.out nativeCmdParams = new ToolBox.AnyToolArgs()
nativeCmdParams.setAllArgs(native2asciiBinary, "-encoding", "IBM1047", .appendArgs(native2asciiBinary)
"Test.tmp", "Test.out"); .appendArgs(ToolBox.testToolVMOpts)
.appendArgs("-encoding", "IBM1047", "Test.tmp", "Test.out");
ToolBox.executeCommand(nativeCmdParams); ToolBox.executeCommand(nativeCmdParams);
//diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out String goldenFile = String.format(TestOutTemplate, File.separator);
ToolBox.compareLines(Paths.get("Test.out"), ToolBox.compareLines(Paths.get("Test.out"),
Arrays.asList(TestOut.split("\n")), null); Arrays.asList(goldenFile.split("\n")), null, true);
} }
} }

View File

@ -31,9 +31,11 @@
*/ */
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import com.sun.tools.javac.util.ArrayUtils;
//original test: test/tools/javac/ClassPathTest/ClassPathTest.sh //original test: test/tools/javac/ClassPathTest/ClassPathTest.sh
public class ClassPathTest { public class ClassPathTest {
@ -92,24 +94,31 @@ public class ClassPathTest {
} }
void checkCompileCommands() throws Exception { void checkCompileCommands() throws Exception {
String[] mainArgs = ToolBox.getJavacBin();
// Without the -cp . parameter the command will fail seems like when called // Without the -cp . parameter the command will fail seems like when called
// from the command line, the current dir is added to the classpath // from the command line, the current dir is added to the classpath
// automatically but this is not happening when called using ProcessBuilder // automatically but this is not happening when called using ProcessBuilder
// testJavac success ClassPathTest3.java // testJavac success ClassPathTest3.java
String[] commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", "."); List<String> mainArgs = new ArrayList<>();
mainArgs.add(ToolBox.javacBinary.toString());
if (ToolBox.testToolVMOpts != null) {
mainArgs.addAll(ToolBox.testToolVMOpts);
}
ToolBox.AnyToolArgs successParams = List<String> commonArgs = new ArrayList<>();
new ToolBox.AnyToolArgs() commonArgs.addAll(mainArgs);
.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java")); commonArgs.addAll(Arrays.asList("-cp", "."));
ToolBox.AnyToolArgs successParams = new ToolBox.AnyToolArgs()
.appendArgs(commonArgs)
.appendArgs("ClassPathTest3.java");
ToolBox.executeCommand(successParams); ToolBox.executeCommand(successParams);
// testJavac failure ClassPathTest1.java // testJavac failure ClassPathTest1.java
ToolBox.AnyToolArgs failParams = ToolBox.AnyToolArgs failParams =
new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java")); .appendArgs(commonArgs)
.appendArgs("ClassPathTest1.java");
ToolBox.executeCommand(failParams); ToolBox.executeCommand(failParams);
// This is done inside the executeCommand method // This is done inside the executeCommand method
@ -119,29 +128,50 @@ public class ClassPathTest {
extVars.put("CLASSPATH", "bar"); extVars.put("CLASSPATH", "bar");
// testJavac success ClassPathTest2.java // testJavac success ClassPathTest2.java
successParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest2.java")).set(extVars); successParams = new ToolBox.AnyToolArgs()
.appendArgs(mainArgs)
.appendArgs("ClassPathTest2.java")
.set(extVars);
ToolBox.executeCommand(successParams); ToolBox.executeCommand(successParams);
// testJavac failure ClassPathTest1.java // testJavac failure ClassPathTest1.java
failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest1.java")).set(extVars); failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.appendArgs(mainArgs)
.appendArgs("ClassPathTest1.java")
.set(extVars);
ToolBox.executeCommand(failParams); ToolBox.executeCommand(failParams);
// testJavac failure ClassPathTest3.java // testJavac failure ClassPathTest3.java
failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest3.java")); failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.appendArgs(mainArgs)
.appendArgs("ClassPathTest3.java")
.set(extVars);
ToolBox.executeCommand(failParams); ToolBox.executeCommand(failParams);
// testJavac success -classpath foo ClassPathTest1.java // testJavac success -classpath foo ClassPathTest1.java
commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", "foo"); commonArgs.clear();
successParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java")); commonArgs.addAll(mainArgs);
commonArgs.addAll(Arrays.asList("-cp", "foo"));
successParams = new ToolBox.AnyToolArgs()
.appendArgs(commonArgs)
.appendArgs("ClassPathTest1.java")
.set(extVars);
ToolBox.executeCommand(successParams); ToolBox.executeCommand(successParams);
// testJavac failure -classpath foo ClassPathTest2.java // testJavac failure -classpath foo ClassPathTest2.java
failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest2.java")); failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.appendArgs(commonArgs)
.appendArgs("ClassPathTest2.java")
.set(extVars);
ToolBox.executeCommand(failParams); ToolBox.executeCommand(failParams);
// testJavac failure -classpath foo ClassPathTest3.java // testJavac failure -classpath foo ClassPathTest3.java
failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java")); failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.appendArgs(commonArgs)
.appendArgs("ClassPathTest3.java")
.set(extVars);
ToolBox.executeCommand(failParams); ToolBox.executeCommand(failParams);
} }

View File

@ -91,7 +91,9 @@ public class ProtectedInnerClassesTest {
//"${TESTJAVA}${FS}bin${FS}java" ${TESTVMOPTS} -classpath "${CLASSPATH}${PS}${TESTCLASSES}" p2.ProtectedInnerClass2 //"${TESTJAVA}${FS}bin${FS}java" ${TESTVMOPTS} -classpath "${CLASSPATH}${PS}${TESTCLASSES}" p2.ProtectedInnerClass2
ToolBox.AnyToolArgs javaParams = ToolBox.AnyToolArgs javaParams =
new ToolBox.AnyToolArgs() new ToolBox.AnyToolArgs()
.setAllArgs(ToolBox.javaBinary, "-classpath", System.getProperty("user.dir"), .appendArgs(ToolBox.javaBinary)
.appendArgs(ToolBox.testVMOpts)
.appendArgs("-classpath", System.getProperty("user.dir"),
"p2.ProtectedInnerClass2"); "p2.ProtectedInnerClass2");
ToolBox.executeCommand(javaParams); ToolBox.executeCommand(javaParams);
} }
@ -101,14 +103,15 @@ public class ProtectedInnerClassesTest {
//@run compile p1/ProtectedInnerClass1.java //@run compile p1/ProtectedInnerClass1.java
ToolBox.JavaToolArgs javacParams = ToolBox.JavaToolArgs javacParams =
new ToolBox.JavaToolArgs() new ToolBox.JavaToolArgs()
.setOptions("-d", ".") .appendArgs("-d", ".")
.setSources(protectedInnerClass1Src); .setSources(protectedInnerClass1Src);
ToolBox.javac(javacParams); ToolBox.javac(javacParams);
//@run compile/fail p2/ProtectedInnerClass3.java //@run compile/fail p2/ProtectedInnerClass3.java
javacParams.setSources(protectedInnerClass3Src) javacParams = new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
.set(ToolBox.Expect.FAIL); .appendArgs("-d", ".")
.setSources(protectedInnerClass3Src);
ToolBox.javac(javacParams); ToolBox.javac(javacParams);
} }

View File

@ -38,6 +38,7 @@ import java.nio.file.StandardOpenOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -65,15 +66,32 @@ public class ToolBox {
public static final String lineSeparator = System.getProperty("line.separator"); public static final String lineSeparator = System.getProperty("line.separator");
public static final String jdkUnderTest = System.getProperty("test.jdk"); public static final String jdkUnderTest = System.getProperty("test.jdk");
public static final String testVMOpts = System.getProperty("test.tool.vm.opts"); public static final Path javaBinary = Paths.get(jdkUnderTest, "bin", "java");
public static final String javaBinary = Paths.get(jdkUnderTest, "bin", "java").toString(); public static final Path javacBinary = Paths.get(jdkUnderTest, "bin", "javac");
//why this one private. Because the function which provide also the test options should be used
private static final String javacBinary = Paths.get(jdkUnderTest, "bin", "javac").toString(); public static final List<String> testToolVMOpts;
public static final List<String> testVMOpts;
private static final Charset defaultCharset = Charset.defaultCharset(); private static final Charset defaultCharset = Charset.defaultCharset();
static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
static {
String sysProp = System.getProperty("test.tool.vm.opts");
if (sysProp != null && sysProp.length() > 0) {
testToolVMOpts = Arrays.asList(sysProp.split("\\s+"));
} else {
testToolVMOpts = Collections.<String>emptyList();
}
sysProp = System.getProperty("test.vm.opts");
if (sysProp != null && sysProp.length() > 0) {
testVMOpts = Arrays.asList(sysProp.split("\\s+"));
} else {
testVMOpts = Collections.<String>emptyList();
}
}
/** /**
* The expected result of command-like method execution. * The expected result of command-like method execution.
*/ */
@ -199,8 +217,8 @@ public class ToolBox {
protected Expect whatToExpect; protected Expect whatToExpect;
protected WriterHelper stdOutput; protected WriterHelper stdOutput;
protected WriterHelper errOutput; protected WriterHelper errOutput;
protected List<String> options; protected List<String> args = new ArrayList<>();
protected String[] optionsArr; protected String[] argsArr;
protected GenericArgs() { protected GenericArgs() {
set(Expect.SUCCESS); set(Expect.SUCCESS);
@ -238,19 +256,50 @@ public class ToolBox {
public T setAllArgs(String... args) { public T setAllArgs(String... args) {
currentParams.add(AcceptedParams.OPTIONS); currentParams.add(AcceptedParams.OPTIONS);
this.optionsArr = args; this.argsArr = args;
return (T) this;
}
public T appendArgs(String... args) {
appendArgs(Arrays.asList(args));
return (T)this;
}
public T appendArgs(Path... args) {
if (args != null) {
List<String> list = new ArrayList<>();
for (int i = 0; i < args.length; i++) {
if (args[i] != null) {
list.add(args[i].toString());
}
}
appendArgs(list);
}
return (T)this;
}
public T appendArgs(List<String> args) {
if (args != null && args.size() > 0) {
currentParams.add(AcceptedParams.OPTIONS);
for (int i = 0; i < args.size(); i++) {
if (args.get(i) != null) {
this.args.add(args.get(i));
}
}
}
return (T)this; return (T)this;
} }
public T setOptions(List<String> options) { public T setOptions(List<String> options) {
currentParams.add(AcceptedParams.OPTIONS); currentParams.add(AcceptedParams.OPTIONS);
this.options = options; this.args = options;
return (T)this; return (T)this;
} }
public T setOptions(String... options) { public T setOptions(String... options) {
currentParams.add(AcceptedParams.OPTIONS); currentParams.add(AcceptedParams.OPTIONS);
this.options = Arrays.asList(options); this.args = Arrays.asList(options);
return (T)this; return (T)this;
} }
@ -365,8 +414,12 @@ public class ToolBox {
* Custom exception for not equal resources. * Custom exception for not equal resources.
*/ */
public static class ResourcesNotEqualException extends Exception { public static class ResourcesNotEqualException extends Exception {
public ResourcesNotEqualException() { public ResourcesNotEqualException(List<String> res1, List<String> res2) {
super("The resources provided for comparison are different"); super(createMessage(res1, res2));
}
public ResourcesNotEqualException(String line1, String line2) {
super(createMessage(line1, line2));
} }
public ResourcesNotEqualException(Path path1, Path path2) { public ResourcesNotEqualException(Path path1, Path path2) {
@ -379,15 +432,20 @@ public class ToolBox {
.append(path1.toString()).append(" and \n") .append(path1.toString()).append(" and \n")
.append(path2.toString()).append("are different").toString(); .append(path2.toString()).append("are different").toString();
} }
}
/** private static String createMessage(String line1, String line2) {
* Method to get the a path to the javac command available at the jdk being return new StringBuilder()
* tested along with the test vm options. .append("The resources provided for comparison are different at lines: \n")
* @return a String[] with the two components mentioned. .append(line1).append(" and \n")
*/ .append(line2).toString();
public static String[] getJavacBin() { }
return new String[]{javacBinary, testVMOpts};
private static String createMessage(List<String> res1, List<String> res2) {
return new StringBuilder()
.append("The resources provided for comparison are different: \n")
.append("Resource 1 is: ").append(res1).append("\n and \n")
.append("Resource 2 is: ").append(res2).append("\n").toString();
}
} }
/** /**
@ -396,7 +454,7 @@ public class ToolBox {
public static int javac(JavaToolArgs params) public static int javac(JavaToolArgs params)
throws CommandExecutionException, IOException { throws CommandExecutionException, IOException {
if (params.hasMinParams()) { if (params.hasMinParams()) {
if (params.optionsArr != null) { if (params.argsArr != null) {
return genericJavaCMD(JavaCMD.JAVAC, params); return genericJavaCMD(JavaCMD.JAVAC, params);
} else { } else {
return genericJavaCMD(JavaCMD.JAVAC_API, params); return genericJavaCMD(JavaCMD.JAVAC_API, params);
@ -437,14 +495,14 @@ public class ToolBox {
JAVAC { JAVAC {
@Override @Override
int run(JavaToolArgs params, PrintWriter pw) { int run(JavaToolArgs params, PrintWriter pw) {
return com.sun.tools.javac.Main.compile(params.optionsArr, pw); return com.sun.tools.javac.Main.compile(params.argsArr, pw);
} }
}, },
JAVAC_API { JAVAC_API {
@Override @Override
int run(JavaToolArgs params, PrintWriter pw) { int run(JavaToolArgs params, PrintWriter pw) {
JavacTask ct = (JavacTask)comp.getTask(pw, null, null, JavacTask ct = (JavacTask)comp.getTask(pw, null, null,
params.options, null, params.sources); params.args, null, params.sources);
return ((JavacTaskImpl)ct).doCall().exitCode; return ((JavacTaskImpl)ct).doCall().exitCode;
} }
@ -467,13 +525,13 @@ public class ToolBox {
JAVAH { JAVAH {
@Override @Override
int run(JavaToolArgs params, PrintWriter pw) { int run(JavaToolArgs params, PrintWriter pw) {
return com.sun.tools.javah.Main.run(params.optionsArr, pw); return com.sun.tools.javah.Main.run(params.argsArr, pw);
} }
}, },
JAVAP { JAVAP {
@Override @Override
int run(JavaToolArgs params, PrintWriter pw) { int run(JavaToolArgs params, PrintWriter pw) {
return com.sun.tools.javap.Main.run(params.optionsArr, pw); return com.sun.tools.javap.Main.run(params.argsArr, pw);
} }
}; };
@ -486,9 +544,9 @@ public class ToolBox {
List<String> getExceptionMsgContent(JavaToolArgs params) { List<String> getExceptionMsgContent(JavaToolArgs params) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
result.add(getName()); result.add(getName());
result.addAll(params.optionsArr != null ? result.addAll(params.argsArr != null ?
Arrays.asList(params.optionsArr) : Arrays.asList(params.argsArr) :
params.options); params.args);
return result; return result;
} }
} }
@ -509,7 +567,7 @@ public class ToolBox {
String out = (sw == null) ? null : sw.toString(); String out = (sw == null) ? null : sw.toString();
if (params.errOutput != null && (out != null) && !out.isEmpty()) { if (params.errOutput != null && (out != null) && !out.isEmpty()) {
params.errOutput.addAll(splitLines(out)); params.errOutput.addAll(splitLines(out, lineSeparator));
} }
if ( (rc == 0 && params.whatToExpect == Expect.SUCCESS) || if ( (rc == 0 && params.whatToExpect == Expect.SUCCESS) ||
@ -542,9 +600,9 @@ public class ToolBox {
public static int executeCommand(AnyToolArgs params) public static int executeCommand(AnyToolArgs params)
throws CommandExecutionException, IOException, InterruptedException { throws CommandExecutionException, IOException, InterruptedException {
if (params.hasMinParams()) { if (params.hasMinParams()) {
List<String> cmd = (params.options != null) ? List<String> cmd = (params.args != null) ?
params.options : params.args :
Arrays.asList(params.optionsArr); Arrays.asList(params.argsArr);
return executeCommand(cmd, params.extraEnv, params.stdOutput, return executeCommand(cmd, params.extraEnv, params.stdOutput,
params.errOutput, params.whatToExpect); params.errOutput, params.whatToExpect);
} }
@ -630,7 +688,7 @@ public class ToolBox {
List<String> list2, boolean trim) throws ResourcesNotEqualException { List<String> list2, boolean trim) throws ResourcesNotEqualException {
if ((list1 == list2) || (list1 == null && list2 == null)) return; if ((list1 == list2) || (list1 == null && list2 == null)) return;
if (list1.size() != list2.size()) if (list1.size() != list2.size())
throw new ResourcesNotEqualException(); throw new ResourcesNotEqualException(list1, list2);
int i = 0; int i = 0;
int j = 0; int j = 0;
while (i < list1.size() && while (i < list1.size() &&
@ -639,7 +697,7 @@ public class ToolBox {
i++; j++; i++; j++;
} }
if (!(i == list1.size() && j == list2.size())) if (!(i == list1.size() && j == list2.size()))
throw new ResourcesNotEqualException(); throw new ResourcesNotEqualException(list1, list2);
} }
private static boolean equals(String s1, String s2, boolean trim) { private static boolean equals(String s1, String s2, boolean trim) {
@ -652,8 +710,8 @@ public class ToolBox {
* and later the regExpr is seek in every split line. If a match is found, * and later the regExpr is seek in every split line. If a match is found,
* the whole line is added to the result. * the whole line is added to the result.
*/ */
public static List<String> grep(String regExpr, String text) { public static List<String> grep(String regExpr, String text, String sep) {
return grep(regExpr, splitLines(text)); return grep(regExpr, splitLines(text, sep));
} }
public static List<String> grep(String regExpr, List<String> text) { public static List<String> grep(String regExpr, List<String> text) {
@ -865,8 +923,8 @@ public class ToolBox {
/** /**
* Splits a String using the System's line separator character as splitting point. * Splits a String using the System's line separator character as splitting point.
*/ */
public static List<String> splitLines(String lines) { public static List<String> splitLines(String lines, String sep) {
return Arrays.asList(lines.split(lineSeparator)); return Arrays.asList(lines.split(sep));
} }
/** /**
@ -881,6 +939,14 @@ public class ToolBox {
return sb.toString(); return sb.toString();
} }
/**
* Returns true if the OS is a Windows version.
*/
public static boolean isWindows() {
String osName = System.getProperty("os.name");
return osName.toUpperCase().startsWith("WINDOWS");
}
/** /**
* Class representing an in-memory java source file. It is able to extract * Class representing an in-memory java source file. It is able to extract
* the file name from simple source codes using regular expressions. * the file name from simple source codes using regular expressions.

View File

@ -50,14 +50,17 @@ public class LinksTest {
// cp ${TESTSRC}/b/B.java tmp // cp ${TESTSRC}/b/B.java tmp
ToolBox.writeFile(Paths.get("tmp", "B.java"), BSrc); ToolBox.writeFile(Paths.get("tmp", "B.java"), BSrc);
try {
// ln -s `pwd`/tmp "${TESTCLASSES}/a" // ln -s `pwd`/tmp "${TESTCLASSES}/a"
Files.createSymbolicLink(Paths.get("a"), Paths.get("tmp")); Files.createSymbolicLink(Paths.get("a"), Paths.get("tmp"));
// ////"${TESTJAVA}/bin/javac" ${TESTTOOLVMOPTS} -sourcepath "${TESTCLASSES}" -d "${TESTCLASSES}/classes" "${TESTSRC}/T.java" 2>&1
////"${TESTJAVA}/bin/javac" ${TESTTOOLVMOPTS} -sourcepath "${TESTCLASSES}" -d "${TESTCLASSES}/classes" "${TESTSRC}/T.java" 2>&1 ToolBox.JavaToolArgs javacArgs =
ToolBox.JavaToolArgs javacArgs = new ToolBox.JavaToolArgs()
new ToolBox.JavaToolArgs() .setOptions("-sourcepath", ".", "-d", ".").setSources(TSrc);
.setOptions("-sourcepath", ".", "-d", ".").setSources(TSrc); ToolBox.javac(javacArgs);
ToolBox.javac(javacArgs); } catch (UnsupportedOperationException e) {
System.err.println("Symbolic links not supported on this system. The test can't finish");
}
} }
} }

View File

@ -34,19 +34,18 @@ import java.io.File;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.List; import java.util.List;
import com.sun.tools.javac.util.ArrayUtils;
//original test: test/tools/javac/newlines/Newlines.sh //original test: test/tools/javac/newlines/Newlines.sh
public class NewLineTest { public class NewLineTest {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
String[] mainArgs = ToolBox.getJavacBin();
// "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -J-Dline.separator='@' > ${TMP1} 2>&1 // "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -J-Dline.separator='@' > ${TMP1} 2>&1
File javacErrOutput = new File("output.txt"); File javacErrOutput = new File("output.txt");
ToolBox.AnyToolArgs cmdArgs = ToolBox.AnyToolArgs cmdArgs =
new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
.setAllArgs(ArrayUtils.concatOpen(mainArgs, "-J-Dline.separator='@'")) .appendArgs(ToolBox.javacBinary)
.appendArgs(ToolBox.testToolVMOpts)
.appendArgs("-J-Dline.separator='@'")
.setErrOutput(javacErrOutput); .setErrOutput(javacErrOutput);
ToolBox.executeCommand(cmdArgs); ToolBox.executeCommand(cmdArgs);

View File

@ -32,7 +32,6 @@
import java.nio.file.Paths; import java.nio.file.Paths;
//original test: test/tools/javah/6257087/foo.sh
public class T6257087 { public class T6257087 {
private static final String fooBarGoldenFile = private static final String fooBarGoldenFile =
@ -59,17 +58,13 @@ public class T6257087 {
"#endif"; "#endif";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d "${TC}" "${TS}${FS}foo.java"
// "${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} -classpath "${TC}" -d "${TC}" foo
ToolBox.JavaToolArgs javahArgs = ToolBox.JavaToolArgs javahArgs =
new ToolBox.JavaToolArgs() new ToolBox.JavaToolArgs()
.setAllArgs("-cp", System.getProperty("test.classes"), "foo"); .setAllArgs("-cp", System.getProperty("test.classes"), "foo");
ToolBox.javah(javahArgs); ToolBox.javah(javahArgs);
// diff ${DIFFOPTS} -c "${TS}${FS}foo_bar.h" "${TC}${FS}foo_bar.h"
ToolBox.compareLines(Paths.get("foo_bar.h"), ToolBox.compareLines(Paths.get("foo_bar.h"),
ToolBox.splitLines(fooBarGoldenFile), null); ToolBox.splitLines(fooBarGoldenFile, "\n"), null, true);
} }
} }

View File

@ -38,7 +38,7 @@ import java.nio.file.Paths;
//original test: test/tools/javah/ConstMacroTest.sh //original test: test/tools/javah/ConstMacroTest.sh
public class ConstMacroTest { public class ConstMacroTest {
private static final String SubClassConstsGoldenFile = private static final String subClassConstsGoldenFileTemplate =
"/* DO NOT EDIT THIS FILE - it is machine generated */\n" + "/* DO NOT EDIT THIS FILE - it is machine generated */\n" +
"#include <jni.h>\n" + "#include <jni.h>\n" +
"/* Header for class SubClassConsts */\n" + "/* Header for class SubClassConsts */\n" +
@ -49,7 +49,7 @@ public class ConstMacroTest {
"extern \"C\" {\n" + "extern \"C\" {\n" +
"#endif\n" + "#endif\n" +
"#undef SubClassConsts_serialVersionUID\n" + "#undef SubClassConsts_serialVersionUID\n" +
"#define SubClassConsts_serialVersionUID 6733861379283244755LL\n" + "#define SubClassConsts_serialVersionUID 6733861379283244755%s\n" +
"#undef SubClassConsts_SUPER_INT_CONSTANT\n" + "#undef SubClassConsts_SUPER_INT_CONSTANT\n" +
"#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" + "#define SubClassConsts_SUPER_INT_CONSTANT 3L\n" +
"#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" + "#undef SubClassConsts_SUPER_FLOAT_CONSTANT\n" +
@ -71,6 +71,9 @@ public class ConstMacroTest {
"#endif\n" + "#endif\n" +
"#endif"; "#endif";
private static final String serialVersionUIDSuffix =
ToolBox.isWindows() ? "i64" : "LL"; ;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
//first steps are now done by jtreg //first steps are now done by jtreg
// cp "${TESTSRC}${FS}SuperClassConsts.java" . // cp "${TESTSRC}${FS}SuperClassConsts.java" .
@ -85,8 +88,10 @@ public class ConstMacroTest {
ToolBox.javah(successParams); ToolBox.javah(successParams);
// diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}" // diff ${DIFFOPTS} "${TESTSRC}${FS}${EXPECTED_JAVAH_OUT_FILE}" "${GENERATED_HEADER_FILE}"
String subClassConstGoldenFile = String.format(subClassConstsGoldenFileTemplate,
serialVersionUIDSuffix);
ToolBox.compareLines(Paths.get("SubClassConsts.h"), ToolBox.compareLines(Paths.get("SubClassConsts.h"),
ToolBox.splitLines(SubClassConstsGoldenFile), null); ToolBox.splitLines(subClassConstGoldenFile, "\n"), null, true);
} }
} }

View File

@ -84,10 +84,11 @@ public class StackmapTest {
new ToolBox.JavaToolArgs() new ToolBox.JavaToolArgs()
.setAllArgs("-v", "Test.class"); .setAllArgs("-v", "Test.class");
String out = ToolBox.javap(javapParams); String out = ToolBox.javap(javapParams);
List<String> grepResult = ToolBox.grep("frame_type", out); List<String> grepResult = ToolBox.grep("frame_type", out,
grepResult.addAll(ToolBox.grep("offset_delta", out)); ToolBox.lineSeparator);
grepResult.addAll(ToolBox.grep("stack = ", out)); grepResult.addAll(ToolBox.grep("offset_delta", out, ToolBox.lineSeparator));
grepResult.addAll(ToolBox.grep("locals = ", out)); grepResult.addAll(ToolBox.grep("stack = ", out, ToolBox.lineSeparator));
grepResult.addAll(ToolBox.grep("locals = ", out, ToolBox.lineSeparator));
List<String> goldenList = Arrays.asList(goldenOut.split("\n")); List<String> goldenList = Arrays.asList(goldenOut.split("\n"));
// diff -w "${OUTFILE}" "${TESTSRC}${FS}T6271292.out" // diff -w "${OUTFILE}" "${TESTSRC}${FS}T6271292.out"