8196748: tools/jar tests need to tolerate unrelated warnings
Reviewed-by: dholmes
--- a/test/jdk/tools/jar/LeadingGarbage.java Mon Mar 12 20:47:21 2018 -0700
+++ b/test/jdk/tools/jar/LeadingGarbage.java Tue Mar 13 00:22:14 2018 -0700
@@ -30,23 +30,28 @@
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
-import jdk.testlibrary.OutputAnalyzer;
-import jdk.testlibrary.ProcessTools;
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.Utils;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
import org.testng.annotations.Test;
/**
* @test
- * @bug 8058520
+ * @bug 8058520 8196748
* @summary jar tf and jar xf should work on zip files with leading garbage
- * @library /lib/testlibrary
+ * @library /test/lib
* @run testng LeadingGarbage
*/
@Test
public class LeadingGarbage {
- final String jar =
- Paths.get(System.getProperty("java.home"), "bin", "jar").toString();
+
final File[] files = { new File("a"), new File("b") };
final File normalZip = new File("normal.zip");
final File leadingGarbageZip = new File("leadingGarbage.zip");
@@ -74,12 +79,10 @@
void createNormalZip() throws Throwable {
createFiles();
- String[] cmd = { jar, "c0Mf", "normal.zip", "a", "b" };
- ProcessBuilder pb = new ProcessBuilder(cmd);
- OutputAnalyzer a = ProcessTools.executeProcess(pb);
+ OutputAnalyzer a = jar("c0Mf", "normal.zip", "a", "b");
a.shouldHaveExitValue(0);
a.stdoutShouldMatch("\\A\\Z");
- a.stderrShouldMatch("\\A\\Z");
+ a.stderrShouldMatchIgnoreVMWarnings("\\A\\Z");
deleteFiles();
}
@@ -104,15 +107,13 @@
}
void assertCanList(String zipFileName) throws Throwable {
- String[] cmd = { jar, "tf", zipFileName };
- ProcessBuilder pb = new ProcessBuilder(cmd);
- OutputAnalyzer a = ProcessTools.executeProcess(pb);
+ OutputAnalyzer a = jar("tf", zipFileName);
a.shouldHaveExitValue(0);
StringBuilder expected = new StringBuilder();
for (File file : files)
expected.append(file.getName()).append(System.lineSeparator());
a.stdoutShouldMatch(expected.toString());
- a.stderrShouldMatch("\\A\\Z");
+ a.stderrShouldMatchIgnoreVMWarnings("\\A\\Z");
}
public void test_canExtract() throws Throwable {
@@ -126,13 +127,20 @@
}
void assertCanExtract(String zipFileName) throws Throwable {
- String[] cmd = { jar, "xf", zipFileName };
- ProcessBuilder pb = new ProcessBuilder(cmd);
- OutputAnalyzer a = ProcessTools.executeProcess(pb);
+ OutputAnalyzer a = jar("xf", zipFileName);
a.shouldHaveExitValue(0);
a.stdoutShouldMatch("\\A\\Z");
- a.stderrShouldMatch("\\A\\Z");
+ a.stderrShouldMatchIgnoreVMWarnings("\\A\\Z");
assertFilesExist();
}
+ OutputAnalyzer jar(String... args) throws Throwable {
+ String jar = JDKToolFinder.getJDKTool("jar");
+ List<String> cmds = new ArrayList<>();
+ cmds.add(jar);
+ cmds.addAll(Utils.getForwardVmOptions());
+ Stream.of(args).forEach(x -> cmds.add(x));
+ ProcessBuilder p = new ProcessBuilder(cmds);
+ return ProcessTools.executeCommand(p);
+ }
}
--- a/test/jdk/tools/jar/modularJar/Basic.java Mon Mar 12 20:47:21 2018 -0700
+++ b/test/jdk/tools/jar/modularJar/Basic.java Tue Mar 13 00:22:14 2018 -0700
@@ -46,7 +46,7 @@
/*
* @test
- * @bug 8167328 8171830 8165640 8174248 8176772
+ * @bug 8167328 8171830 8165640 8174248 8176772 8196748
* @library /lib/testlibrary /test/lib
* @modules jdk.compiler
* jdk.jartool
@@ -155,6 +155,8 @@
} else if (line.startsWith("contains:")) {
line = line.substring("contains:".length());
conceals = stringToSet(line);
+ } else if (line.contains("VM warning:")) {
+ continue; // ignore server vm warning see#8196748
} else {
throw new AssertionError("Unknown value " + line);
}
--- a/test/jdk/tools/jar/multiRelease/ApiValidatorTest.java Mon Mar 12 20:47:21 2018 -0700
+++ b/test/jdk/tools/jar/multiRelease/ApiValidatorTest.java Tue Mar 13 00:22:14 2018 -0700
@@ -23,6 +23,7 @@
/*
* @test
+ # @bug 8196748
* @summary Tests for API validator.
* @library /test/lib
* @modules java.base/jdk.internal.misc
@@ -86,7 +87,7 @@
".");
if (isAcceptable) {
result.shouldHaveExitValue(SUCCESS)
- .shouldBeEmpty();
+ .shouldBeEmptyIgnoreVMWarnings();
} else {
result.shouldNotHaveExitValue(SUCCESS)
.shouldContain("contains a class with different api from earlier version");
@@ -417,4 +418,3 @@
javac(classes, sourceFiles);
}
}
-
--- a/test/jdk/tools/jar/multiRelease/Basic.java Mon Mar 12 20:47:21 2018 -0700
+++ b/test/jdk/tools/jar/multiRelease/Basic.java Tue Mar 13 00:22:14 2018 -0700
@@ -23,7 +23,7 @@
/*
* @test
- # @bug 8186087
+ # @bug 8186087 8196748
* @library /test/lib
* @modules java.base/jdk.internal.misc
* jdk.compiler
@@ -127,7 +127,7 @@
jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
"--release", release, "-C", classes.resolve("v10").toString(), ".")
.shouldHaveExitValue(SUCCESS)
- .shouldBeEmpty();
+ .shouldBeEmptyIgnoreVMWarnings();
}
// invalid
for (String release : List.of("9.0", "8", "v9",
@@ -335,7 +335,7 @@
jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
"--release", "9", "-C", classes.resolve("v9").toString(), ".")
.shouldHaveExitValue(SUCCESS)
- .shouldBeEmpty();
+ .shouldBeEmptyIgnoreVMWarnings();
jar("uf", jarfile,
"--release", "10", "-C", classes.resolve("v9").toString(), ".")
.shouldHaveExitValue(SUCCESS)
@@ -417,7 +417,7 @@
"-C", classes.resolve("base").toString(), ".",
"--release", "9", "-C", classes.resolve("v9").toString(), ".")
.shouldNotHaveExitValue(SUCCESS)
- .asLines();
+ .asLinesWithoutVMWarnings();
/* "META-INF/versions/9/version/Nested$nested.class" is really NOT isolated
assertTrue(output.size() == 4);
@@ -516,7 +516,7 @@
"-C", classes.resolve("base").toString(), ".",
"--release", "10", "-C", classes.resolve("v10").toString(), ".")
.shouldHaveExitValue(SUCCESS)
- .shouldBeEmpty();
+ .shouldBeEmptyIgnoreVMWarnings();
try (JarFile jf = new JarFile(new File(jarfile), true,
ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
--- a/test/lib/jdk/test/lib/process/OutputAnalyzer.java Mon Mar 12 20:47:21 2018 -0700
+++ b/test/lib/jdk/test/lib/process/OutputAnalyzer.java Tue Mar 13 00:22:14 2018 -0700
@@ -27,6 +27,7 @@
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -184,9 +185,9 @@
}
/**
- * Verify that the stdout and stderr contents of output buffer does not contain the string
+ * Verify that the stdout and stderr contents of output buffer are empty
*
- * @throws RuntimeException If the string was found
+ * @throws RuntimeException If the stdout and stderr are not empty
*/
public OutputAnalyzer shouldBeEmpty() {
if (!stdout.isEmpty()) {
@@ -271,6 +272,7 @@
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stderrShouldMatch(String pattern) {
+
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
if (!matcher.find()) {
reportDiagnosticSummary();
@@ -485,4 +487,57 @@
private List<String> asLines(String buffer) {
return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)"));
}
+
+
+ private static final String jvmwarningmsg = ".* VM warning:.*";
+
+ /**
+ * Verifies that the stdout and stderr contents of output buffer are empty, after
+ * filtering out the HotSpot warning messages.
+ *
+ * @throws RuntimeException If the stdout and stderr are not empty
+ */
+ public OutputAnalyzer shouldBeEmptyIgnoreVMWarnings() {
+ if (!stdout.isEmpty()) {
+ reportDiagnosticSummary();
+ throw new RuntimeException("stdout was not empty");
+ }
+ if (!stderr.replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
+ reportDiagnosticSummary();
+ throw new RuntimeException("stderr was not empty");
+ }
+ return this;
+ }
+
+ /**
+ * Verify that the stderr contents of output buffer matches the pattern,
+ * after filtering out the Hotespot warning messages
+ *
+ * @param pattern
+ * @throws RuntimeException If the pattern was not found
+ */
+ public OutputAnalyzer stderrShouldMatchIgnoreVMWarnings(String pattern) {
+ String stderr = this.stderr.replaceAll(jvmwarningmsg + "\\R", "");
+ Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
+ if (!matcher.find()) {
+ reportDiagnosticSummary();
+ throw new RuntimeException("'" + pattern
+ + "' missing from stderr \n");
+ }
+ return this;
+ }
+
+ /**
+ * Returns the contents of the output buffer (stdout and stderr), without those
+ * JVM warning msgs, as list of strings. Output is split by newlines.
+ *
+ * @return Contents of the output buffer as list of strings
+ */
+ public List<String> asLinesWithoutVMWarnings() {
+ return Arrays.asList(getOutput().split("\\R"))
+ .stream()
+ .filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
+ .collect(Collectors.toList());
+ }
+
}