8242009: Review setting test.java/vm.opts in jcmd/jhsdb and debugger in serviceability tests

Reviewed-by: cjplummer
This commit is contained in:
Daniil Titov 2020-05-12 09:45:24 -07:00
parent e686fb6bf6
commit a726aca6de
36 changed files with 161 additions and 109 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.AttachNotSupportedException;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
@ -80,6 +81,7 @@ public class ConcAttachTest implements Runnable {
private static void checkAttachListenerThread() throws InterruptedException, IOException {
JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
jcmd.addVMArgs(Utils.getTestJavaOpts());
jcmd.addToolArg(strPID);
jcmd.addToolArg("Thread.print");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -32,6 +32,7 @@
import java.io.IOException;
import java.nio.file.Path;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.process.OutputAnalyzer;
@ -40,6 +41,7 @@ public class RemovingUnixDomainSocketTest {
private static void runJCmd(long pid) throws InterruptedException, IOException {
JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
jcmd.addVMArgs(Utils.getTestJavaOpts());
jcmd.addToolArg(Long.toString(pid));
jcmd.addToolArg("VM.version");
@ -53,7 +55,7 @@ public class RemovingUnixDomainSocketTest {
System.out.println(out.getStdout());
System.err.println(out.getStderr());
out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
}
public static void main(String... args) throws Exception {

View File

@ -30,9 +30,9 @@
* @run main/othervm/timeout=2400 CDSJMapClstats
*/
import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;
import jdk.test.lib.Utils;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.apps.LingeredApp;
@ -46,6 +46,7 @@ public class CDSJMapClstats {
private static void runClstats(long lingeredAppPid) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--clstats");
launcher.addToolArg("--pid");

View File

@ -27,11 +27,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jtreg.SkippedException;
/**
@ -70,6 +69,7 @@ public class ClhsdbDumpclass {
// Run javap on the generated class file to make sure it's valid.
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javap");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg(APP_DOT_CLASSNAME);
System.out.println("> javap " + APP_DOT_CLASSNAME);
List<String> cmdStringList = Arrays.asList(launcher.getCommand());

View File

@ -22,11 +22,8 @@
* questions.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jdk.test.lib.JDKToolLauncher;
@ -61,6 +58,7 @@ public class ClhsdbJstackXcompStress {
for (int i = 0; i < MAX_ITERATIONS; i++) {
JDKToolLauncher launcher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));
@ -76,7 +74,7 @@ public class ClhsdbJstackXcompStress {
System.err.println(out.getStderr());
}
out.stderrShouldBeEmpty(); // NPE's are reported on the err stream
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.stdoutShouldNotContain("Error occurred during stack walking:");
out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);
List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));

View File

@ -25,10 +25,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
@ -56,6 +54,7 @@ public class ClhsdbLauncher {
private void attach(long lingeredAppPid)
throws IOException {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("clhsdb");
if (lingeredAppPid != -1) {
launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
@ -75,6 +74,7 @@ public class ClhsdbLauncher {
throws IOException {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("clhsdb");
launcher.addToolArg("--core=" + coreFileName);
launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));

View File

@ -31,8 +31,6 @@
* @run main DeadlockDetectionTest
*/
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import jdk.test.lib.apps.LingeredApp;
@ -51,6 +49,7 @@ public class DeadlockDetectionTest {
private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
if (toolArgs != null) {
for (String toolArg : toolArgs) {

View File

@ -21,14 +21,8 @@
* questions.
*/
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
@ -50,6 +44,7 @@ public class JhsdbThreadInfoTest {
System.out.println("Started LingeredApp with pid " + app.getPid());
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
jhsdbLauncher.addToolArg("jstack");
jhsdbLauncher.addToolArg("--pid");
@ -73,17 +68,7 @@ public class JhsdbThreadInfoTest {
out.shouldNotContain(" prio=0 ");
out.shouldNotContain(" java.lang.Thread.State: UNKNOWN");
// stderr should be empty except for VM warnings.
if (!out.getStderr().isEmpty()) {
List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
Pattern p = Pattern.compile(".*VM warning.*");
for (String line : lines) {
Matcher m = p.matcher(line);
if (!m.matches()) {
throw new RuntimeException("Stderr has output other than VM warnings");
}
}
}
out.stderrShouldBeEmptyIgnoreVMWarnings();
System.out.println("Test Completed");
} catch (Exception ex) {

View File

@ -21,28 +21,20 @@
* questions.
*/
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.nio.file.Files;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.util.stream.Collectors;
import java.io.FileInputStream;
import sun.jvm.hotspot.HotSpotAgent;
import sun.jvm.hotspot.debugger.*;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
import jdk.test.lib.hprof.HprofParser;
import jdk.test.lib.hprof.parser.HprofReader;
import jdk.test.lib.hprof.parser.PositionDataInputStream;
import jdk.test.lib.hprof.model.Snapshot;
@ -91,6 +83,7 @@ public class TestHeapDumpForInvokeDynamic {
long lingeredAppPid) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--binaryheap");
launcher.addToolArg("--dumpfile");

View File

@ -21,20 +21,9 @@
* questions.
*/
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
@ -57,6 +46,7 @@ public class TestJhsdbJstackLock {
System.out.println ("Started LingeredApp with pid " + app.getPid());
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));
@ -75,18 +65,7 @@ public class TestJhsdbJstackLock {
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$");
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$");
// stderr should be empty except for VM warnings.
if (!out.getStderr().isEmpty()) {
List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
Pattern p = Pattern.compile(".*VM warning.*");
for (String line : lines) {
Matcher m = p.matcher(line);
if (!m.matches()) {
throw new RuntimeException("Stderr has output other than VM warnings");
}
}
}
out.stderrShouldBeEmptyIgnoreVMWarnings();
System.out.println("Test Completed");
} finally {

View File

@ -132,6 +132,7 @@ public class TestJhsdbJstackMixed {
for (int i = 0; i < MAX_ITERATIONS; i++) {
JDKToolLauncher launcher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
launcher.addToolArg("--mixed");
launcher.addToolArg("--pid");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
@ -120,6 +120,7 @@ public class TestJmapCore {
File dumpFile = new File("heap.hprof");
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--binaryheap");
launcher.addToolArg("--dumpfile=" + dumpFile);

View File

@ -21,10 +21,10 @@
* questions.
*/
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
@ -58,7 +58,9 @@ public class TestSysProps {
public static void countProps(String[] propLines, int expectedCount, String cmdName) {
int numProps = 0;
for (String propLine : propLines) {
if (propLine.indexOf("=") != -1) {
// Ignore the debug output lines (they start with '[' and printed
// in the output when the test is run with -Xlog VM option).
if (!propLine.startsWith("[") && propLine.indexOf("=") != -1) {
numProps++;
}
}
@ -79,6 +81,7 @@ public class TestSysProps {
// Get properties using the SA version of jinfo
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
jhsdbLauncher.addToolArg("jinfo");
jhsdbLauncher.addToolArg("--sysprops");
jhsdbLauncher.addToolArg("--pid");
@ -99,6 +102,7 @@ public class TestSysProps {
// Get the properties using the Attach API version of jinfo
JDKToolLauncher jinfoLauncher = JDKToolLauncher.createUsingTestJDK("jinfo");
jinfoLauncher.addVMArgs(Utils.getTestJavaOpts());
jinfoLauncher.addToolArg("-sysprops");
jinfoLauncher.addToolArg(Long.toString(app.getPid()));

View File

@ -33,7 +33,7 @@ import java.util.Scanner;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
@ -98,6 +98,7 @@ public class JMapHProfLargeHeapTest {
JDKToolLauncher jMapLauncher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
jMapLauncher.addVMArgs(Utils.getTestJavaOpts());
jMapLauncher.addToolArg("jmap");
jMapLauncher.addToolArg("--binaryheap");
jMapLauncher.addToolArg("--pid");

View File

@ -37,6 +37,7 @@ import java.io.IOException;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.process.OutputAnalyzer;
@ -45,6 +46,7 @@ public class DebugdConnectTest {
private static OutputAnalyzer runJHSDB(String command, String id) throws IOException, InterruptedException {
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
jhsdbLauncher.addToolArg(command);
jhsdbLauncher.addToolArg("--connect");
if (id != null) {
@ -68,7 +70,7 @@ public class DebugdConnectTest {
OutputAnalyzer out = runJHSDB("jstack", id);
out.shouldContain("LingeredApp");
out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.shouldHaveExitValue(0);
}
@ -76,7 +78,7 @@ public class DebugdConnectTest {
OutputAnalyzer out = runJHSDB("jmap", id);
out.shouldContain("JVM version is");
out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.shouldHaveExitValue(0);
}
@ -84,7 +86,7 @@ public class DebugdConnectTest {
OutputAnalyzer out = runJHSDB("jinfo", id);
out.shouldContain("Java System Properties:");
out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.shouldHaveExitValue(0);
}
@ -92,7 +94,7 @@ public class DebugdConnectTest {
OutputAnalyzer out = runJHSDB("jsnap", id);
out.shouldContain("java.vm.name=");
out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.shouldHaveExitValue(0);
}
@ -128,5 +130,4 @@ public class DebugdConnectTest {
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -26,6 +26,7 @@ import java.io.InputStreamReader;
import java.io.IOException;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
public class DebugdUtils {
@ -43,6 +44,7 @@ public class DebugdUtils {
public void attach(long pid) throws IOException {
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
jhsdbLauncher.addToolArg("debugd");
jhsdbLauncher.addToolArg("--pid");
jhsdbLauncher.addToolArg(Long.toString(pid));

View File

@ -94,6 +94,7 @@ public class SADebugDTest {
testResult = false;
portInUse = false;
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
jhsdbLauncher.addToolArg("debugd");
jhsdbLauncher.addToolArg("--pid");
jhsdbLauncher.addToolArg(Long.toString(app.getPid()));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
@ -69,6 +69,7 @@ public class JstackThreadTest {
thread.start();
ProcessBuilder processBuilder = new ProcessBuilder();
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
launcher.addVMArgs(jdk.test.lib.Utils.getTestJavaOpts());
launcher.addToolArg("-l");
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
processBuilder.command(launcher.getCommand());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
@ -23,6 +23,7 @@
import java.util.Arrays;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
@ -95,6 +96,7 @@ public final class JcmdBase {
private static final OutputAnalyzer jcmd(boolean requestToCurrentProcess,
String[] vmArgs, String[] jcmdArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
launcher.addVMArgs(Utils.getTestJavaOpts());
if (vmArgs != null) {
for (String vmArg : vmArgs) {
launcher.addVMArg(vmArg);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -25,6 +25,7 @@ import java.util.Arrays;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
@ -48,6 +49,7 @@ public class JcmdOutputEncodingTest {
Thread.currentThread().setName(marker);
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addVMArg("-Dfile.encoding=" + cs);
launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
launcher.addToolArg("Thread.print");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, 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
@ -90,7 +90,7 @@ public class TestJcmdDefaults {
* @param output The generated output from the jcmd.
*/
private static void matchListedProcesses(OutputAnalyzer output) {
output.shouldMatchByLine(JCMD_LIST_REGEX);
output.shouldMatchByLineIgnoreVMWarnings(JCMD_LIST_REGEX);
}
private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, 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
@ -152,7 +152,7 @@ public class TestJcmdSanity {
* @throws Exception
*/
private static void matchPerfCounters(OutputAnalyzer output) {
output.shouldMatchByLineFrom(PERF_COUNTER_REGEX,
output.shouldMatchByLineIgnoreVMWarnings(PERF_COUNTER_REGEX, null,
PERF_COUNTER_REGEX);
}

View File

@ -63,7 +63,7 @@ public class BasicLauncherTest {
else {
launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
}
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
return launcher;
}

View File

@ -38,6 +38,7 @@ import java.io.File;
import java.util.List;
import java.util.Arrays;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.hprof.parser.HprofReader;
import jdk.test.lib.JDKToolLauncher;
@ -65,6 +66,7 @@ public class HeapDumpTest {
System.out.println(theApp.\u00CB);
System.out.println("Starting " + toolArgs.get(0) + " against " + theApp.getPid());
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
for (String cmd : toolArgs) {
launcher.addToolArg(cmd);

View File

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Arrays;
import java.util.Map;
import jdk.test.lib.Utils;
import jdk.test.lib.hprof.parser.HprofReader;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
@ -61,6 +62,7 @@ public class JShellHeapDumpTest {
System.out.println("Starting " + toolArgs.get(0) + " against " + jShellPID);
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
for (String cmd : toolArgs) {
launcher.addToolArg(cmd);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, 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
@ -24,6 +24,7 @@
import java.util.Arrays;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
@ -70,6 +71,7 @@ public class BasicJInfoTest {
private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
launcher.addVMArgs(Utils.getTestJavaOpts());
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);

View File

@ -29,6 +29,7 @@ import java.util.regex.Pattern;
import java.io.IOException;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.apps.LingeredApp;
@ -114,6 +115,7 @@ public class JInfoTest {
private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
launcher.addVMArgs(Utils.getTestJavaOpts());
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, 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
@ -28,6 +28,7 @@ import java.io.File;
import java.util.Arrays;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.hprof.HprofParser;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
@ -179,6 +180,7 @@ public class BasicJMapTest {
private static OutputAnalyzer jmap(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
launcher.addVMArgs(Utils.getTestJavaOpts());
if (toolArgs != null) {
for (String toolArg : toolArgs) {
launcher.addToolArg(toolArg);

View File

@ -152,6 +152,7 @@ public final class JpsHelper {
*/
public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
launcher.addVMArg("-XX:+UsePerfData");
if (vmArgs != null) {
for (String vmArg : vmArgs) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, 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
@ -25,6 +25,7 @@ import java.util.Arrays;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
@ -70,6 +71,7 @@ public class BasicJStackTest {
Charset cs = StandardCharsets.UTF_8;
Thread.currentThread().setName(marker);
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
launcher.addVMArg("-XX:+UsePerfData");
launcher.addVMArg("-Dfile.encoding=" + cs);
if (toolArgs != null) {

View File

@ -50,6 +50,7 @@ public class DeadlockDetectionTest {
private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
launcher.addVMArg("-XX:+UsePerfData");
if (toolArgs != null) {
for (String toolArg : toolArgs) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
@ -34,6 +34,7 @@
*/
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;
import java.util.concurrent.TimeUnit;
@ -87,6 +88,7 @@ public class JStatInterval {
String pidStr = String.valueOf(app.pid());
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat");
l.addVMArgs(Utils.getTestJavaOpts());
l.addToolArg("-compiler");
l.addToolArg(pidStr);
l.addToolArg("100");

View File

@ -27,6 +27,7 @@ import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Arrays;
import java.util.List;
import static jdk.test.lib.Asserts.*;
import jdk.test.lib.Utils;
@ -127,6 +128,7 @@ public final class JstatdTest {
*/
private OutputAnalyzer runJps() throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
launcher.addVMArg("-XX:+UsePerfData");
launcher.addToolArg(getDestination());
@ -156,7 +158,7 @@ public final class JstatdTest {
assertFalse(output.getOutput().isEmpty(), "Output should not be empty");
boolean foundFirstLineWithPid = false;
String[] lines = output.getOutput().split(Utils.NEW_LINE);
List<String> lines = output.asLinesWithoutVMWarnings();
for (String line : lines) {
if (!foundFirstLineWithPid) {
foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
@ -353,9 +355,7 @@ public final class JstatdTest {
// Verify output from jstatd
OutputAnalyzer output = jstatdThread.getOutput();
assertTrue(output.getOutput().isEmpty(),
"jstatd should get an empty output, got: "
+ Utils.NEW_LINE + output.getOutput());
output.shouldBeEmptyIgnoreVMWarnings();
assertNotEquals(output.getExitValue(), 0,
"jstatd process exited with unexpected exit code");
}

View File

@ -22,6 +22,7 @@
*/
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
@ -42,6 +43,7 @@ public class TestJstatdUsage {
private static void testUsage(String option) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg(option);
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
@ -25,6 +25,7 @@ package jdk.test.lib;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* A utility for constructing command lines for starting JDK tool processes.
@ -102,6 +103,24 @@ public class JDKToolLauncher {
return this;
}
/**
* Adds arguments to the JVM running the tool.
*
* The JVM arguments are passed to the underlying JVM running the tool.
* Arguments will automatically be prepended with "-J".
*
* Any platform specific arguments required for running the tool are
* automatically added.
*
* @param args
* The arguments to VM running the tool
* @return The JDKToolLauncher instance
*/
public JDKToolLauncher addVMArgs(String[] args) {
Stream.of(args).forEach(vmArgs::add);
return this;
}
/**
* Adds an argument to the tool.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
@ -38,6 +38,15 @@ import java.util.regex.Pattern;
public final class OutputAnalyzer {
private static final String JVM_WARNING_MSG = ".* VM warning:.*";
private static final String JAVA_VERSION_MSG = "^java version .*|^Java\\(TM\\).*|^Java HotSpot\\(TM\\).*|" +
"^openjdk version .*|^OpenJDK .*";
private static final String JAVA_WARNINGS_AND_VERSION = JVM_WARNING_MSG + "|" + JAVA_VERSION_MSG;
private static final Pattern JAVA_WARNINGS_AND_VERSION_PATTERN =
Pattern.compile(JAVA_WARNINGS_AND_VERSION.replaceAll("\\|", "\\\\R|") + "\\R",
Pattern.MULTILINE);
private final OutputBuffer buffer;
/**
* Create an OutputAnalyzer, a utility class for verifying output and exit
@ -132,13 +141,13 @@ public final class OutputAnalyzer {
/**
* Verify that the stderr contents of output buffer is empty,
* after filtering out the Hotspot warning messages
* after filtering out the HotSpot warning and Java version messages.
*
* @throws RuntimeException
* If stderr was not empty
*/
public OutputAnalyzer stderrShouldBeEmptyIgnoreVMWarnings() {
if (!getStderr().replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
if (!JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
@ -561,12 +570,15 @@ public final class OutputAnalyzer {
return Arrays.asList(buffer.split("\\R"));
}
private static final String jvmwarningmsg = ".* VM warning:.*";
private List<String> asLinesWithoutVMWarnings(String buffer) {
return Arrays.stream(buffer.split("\\R"))
.filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* Verifies that the stdout and stderr contents of output buffer are empty, after
* filtering out the HotSpot warning messages.
* filtering out the HotSpot warning and Java version messages.
*
* @throws RuntimeException If the stdout and stderr are not empty
*/
@ -577,22 +589,19 @@ public final class OutputAnalyzer {
reportDiagnosticSummary();
throw new RuntimeException("stdout was not empty");
}
if (!stderr.replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
reportDiagnosticSummary();
throw new RuntimeException("stderr was not empty");
}
stderrShouldBeEmptyIgnoreVMWarnings();
return this;
}
/**
* Verify that the stderr contents of output buffer matches the pattern,
* after filtering out the Hotespot warning messages
* after filtering out the HotSpot warning and Java version messages.
*
* @param pattern
* @throws RuntimeException If the pattern was not found
*/
public OutputAnalyzer stderrShouldMatchIgnoreVMWarnings(String pattern) {
String stderr = getStderr().replaceAll(jvmwarningmsg + "\\R", "");
String stderr = JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("");
Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
if (!matcher.find()) {
reportDiagnosticSummary();
@ -604,16 +613,28 @@ public final class OutputAnalyzer {
/**
* Returns the contents of the output buffer (stdout and stderr), without those
* JVM warning msgs, as list of strings. Output is split by newlines.
* JVM warning and Java version messages, 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.stream(getOutput().split("\\R"))
.filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
.filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line ignoring HotSpot warning and version messages.
*
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String pattern) {
return shouldMatchByLine(getOutput(), null, null, pattern, true);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
@ -657,7 +678,25 @@ public final class OutputAnalyzer {
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern);
return shouldMatchByLine(getOutput(), from, to, pattern, false);
}
/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line ignoring HotSpot warnings and version messages.
* The whole output could be matched or just a subset of it.
*
* @param from
* The line (excluded) from where output will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where output will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern, true);
}
/**
@ -675,11 +714,12 @@ public final class OutputAnalyzer {
* Matching pattern
*/
public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getStdout(), from, to, pattern);
return shouldMatchByLine(getStdout(), from, to, pattern, false);
}
private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
List<String> lines = asLines(buffer);
private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern,
boolean ignoreVMWarnings) {
List<String> lines = ignoreVMWarnings ? asLinesWithoutVMWarnings() : asLines(buffer);
int fromIndex = 0;
if (from != null) {