Java Code Examples for jdk.testlibrary.OutputAnalyzer#shouldHaveExitValue()
The following examples show how to use
jdk.testlibrary.OutputAnalyzer#shouldHaveExitValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Runs the actual tests in the nested class TestMain. * We need to run the tests in a separate process, * because we need to add to the classpath. */ private static void runTests() throws Throwable { final String sep = File.separator; String testClassPath = System.getProperty("test.class.path", ""); String testClasses = System.getProperty("test.classes", "") + sep; String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep; // Need to add SimpleProvider.jar and tools.jar to classpath. String classpath = testClassPath + File.pathSeparator + testClasses + "SimpleProvider.jar" + File.pathSeparator + jdkLib + "tools.jar"; String[] args = { "-classpath", classpath, "ProviderTest$TestMain" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 2
Source File: TestJpsJarRelative.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { String testJdk = System.getProperty("test.jdk", "?"); String testSrc = System.getProperty("test.src", "?"); File jar = JpsHelper.buildJar("JpsBase"); List<String> cmd = new ArrayList<>(); cmd.addAll(JpsHelper.getVmArgs()); cmd.add("-Dtest.jdk=" + testJdk); cmd.add("-Dtest.src=" + testSrc); cmd.add("-jar"); cmd.add("." + File.separator + jar.getName()); cmd.add("monkey"); ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()])); OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); System.out.println(output.getOutput()); output.shouldHaveExitValue(0); }
Example 3
Source File: TestJpsClass.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { String testJdk = System.getProperty("test.jdk", "?"); String testSrc = System.getProperty("test.src", "?"); String testClassPath = System.getProperty("test.class.path", "?"); List<String> cmd = new ArrayList<>(); cmd.addAll(JpsHelper.getVmArgs()); cmd.add("-Dtest.jdk=" + testJdk); cmd.add("-Dtest.src=" + testSrc); cmd.add("-cp"); cmd.add(testClassPath); cmd.add("JpsBase"); cmd.add("monkey"); ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(cmd.toArray(new String[cmd.size()])); OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); System.out.println(output.getOutput()); output.shouldHaveExitValue(0); }
Example 4
Source File: PremainClassTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] a) throws Exception { String testArgs = String.format( "-javaagent:%s/Agent.jar -classpath %s DummyMain", System.getProperty("test.src"), System.getProperty("test.classes", ".")); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( Utils.addTestJavaOpts(testArgs.split("\\s+"))); System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb)); OutputAnalyzer output = new OutputAnalyzer(pb.start()); System.out.println("testjvm.stdout:" + output.getStdout()); System.out.println("testjvm.stderr:" + output.getStderr()); output.shouldHaveExitValue(0); output.stdoutShouldContain("premain running"); output.stdoutShouldContain("Hello from DummyMain!"); }
Example 5
Source File: TempDirTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Runs the actual tests in nested class TestMain. * The reason for running the tests in a separate process * is that we need to modify the class path and * the -Djava.io.tmpdir property. */ private static void launchTests(long pid, Path clientTmpDir) throws Throwable { final String sep = File.separator; String classpath = System.getProperty("test.class.path", ""); String[] tmpDirArg = null; if (clientTmpDir != null) { tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir}; } // Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid String[] args = RunnerUtil.concat( tmpDirArg, new String[] { "-classpath", classpath, "TempDirTest$TestMain", Long.toString(pid) }); OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 6
Source File: ProviderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Runs the actual tests in the nested class TestMain. * We need to run the tests in a separate process, * because we need to add to the classpath. */ private static void runTests() throws Throwable { final String sep = File.separator; String testClassPath = System.getProperty("test.class.path", ""); String testClasses = System.getProperty("test.classes", "") + sep; String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep; // Need to add SimpleProvider.jar to classpath. String classpath = testClassPath + File.pathSeparator + testClasses + "SimpleProvider.jar"; String[] args = { "-classpath", classpath, "ProviderTest$TestMain" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 7
Source File: ProviderTest.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Runs the actual tests in the nested class TestMain. * We need to run the tests in a separate process, * because we need to add to the classpath. */ private static void runTests() throws Throwable { final String sep = File.separator; String testClassPath = System.getProperty("test.class.path", ""); String testClasses = System.getProperty("test.classes", "") + sep; String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep; // Need to add SimpleProvider.jar and tools.jar to classpath. String classpath = testClassPath + File.pathSeparator + testClasses + "SimpleProvider.jar" + File.pathSeparator + jdkLib + "tools.jar"; String[] args = { "-classpath", classpath, "ProviderTest$TestMain" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 8
Source File: Test.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
protected void checkSigning(OutputAnalyzer analyzer, String... warnings) { analyzer.shouldHaveExitValue(0); int count = 0; for (String warning : warnings) { if (warning.startsWith("!")) { analyzer.shouldNotContain(warning.substring(1)); } else { count++; analyzer.shouldContain(warning); } } if (count > 0) { analyzer.shouldMatch(WARNING_OR_ERROR); } analyzer.shouldContain(JAR_SIGNED); }
Example 9
Source File: JstatdTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Verifies output form jps contains pids and programs' name information. * The function will discard any lines that come before the first line with pid. * This can happen if the JVM outputs a warning message for some reason * before running jps. * * The output can look like: * 35536 Jstatd * 35417 Main * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar */ private void verifyJpsOutput(OutputAnalyzer output) throws Exception { output.shouldHaveExitValue(0); assertFalse(output.getOutput().isEmpty(), "Output should not be empty"); boolean foundFirstLineWithPid = false; String[] lines = output.getOutput().split(Utils.NEW_LINE); for (String line : lines) { if (!foundFirstLineWithPid) { foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX); continue; } assertTrue(line.matches(JPS_OUTPUT_REGEX), "Output does not match the pattern" + Utils.NEW_LINE + line); } assertTrue(foundFirstLineWithPid, "Invalid output"); }
Example 10
Source File: TestJstatdUsage.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void testUsage(String option) throws Exception { JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd"); launcher.addToolArg(option); ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand()); OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]"); output.shouldHaveExitValue(1); }
Example 11
Source File: PermissionTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Runs the actual test the nested class TestMain. * The test is run in a separate process because we need to add to the classpath. */ private static void runTests(int pid) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. String classpath = System.getProperty("test.class.path", "") + File.pathSeparator + System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar"; String testSrc = System.getProperty("test.src", "") + sep; // Use a policy that will NOT allow attach. Test will verify exception. String[] args = { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.deny", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "true" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); // Use a policy that will allow attach. args = new String[] { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.allow", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "false" }; output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 12
Source File: PermissionTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Runs the actual test the nested class TestMain. * The test is run in a separate process because we need to add to the classpath. */ private static void runTests(int pid) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. String classpath = System.getProperty("test.class.path", "") + File.pathSeparator + System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar"; String testSrc = System.getProperty("test.src", "") + sep; // Use a policy that will NOT allow attach. Test will verify exception. String[] args = { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.deny", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "true" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); // Use a policy that will allow attach. args = new String[] { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.allow", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "false" }; output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 13
Source File: TestJstatdUsage.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private static void testUsage(String option) throws Exception { JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd"); launcher.addToolArg(option); ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand()); OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]"); output.shouldHaveExitValue(1); }
Example 14
Source File: TestJcmdSanity.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * jcmd -J-XX:+UsePerfData pid PerfCounter.print */ private static void testJcmdPidPerfCounterPrint() throws Exception { OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS, new String[] {"PerfCounter.print"}); output.shouldHaveExitValue(0); matchPerfCounters(output); }
Example 15
Source File: TestJcmdSanity.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Tests that it possible send a file over 1024 bytes large via jcmd -f. * * jcmd -J-XX:+UsePerfData pid -f dcmd-big-script.txt */ private static void testJcmdPidBigScript() throws Exception { File scrpitFile = new File(TEST_SRC, "dcmd-big-script.txt"); OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS, new String[] {"-f", scrpitFile.getAbsolutePath()}); output.shouldHaveExitValue(0); output.shouldNotContain("Exception"); output.shouldContain(System.getProperty("java.vm.name").trim()); }
Example 16
Source File: PermissionTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Runs the actual test the nested class TestMain. * The test is run in a separate process because we need to add to the classpath. */ private static void runTests(int pid) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. String classpath = System.getProperty("test.class.path", "") + File.pathSeparator + System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar"; String testSrc = System.getProperty("test.src", "") + sep; // Use a policy that will NOT allow attach. Test will verify exception. String[] args = { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.deny", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "true" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); // Use a policy that will allow attach. args = new String[] { "-classpath", classpath, "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.allow", testSrc), "PermissionTest$TestMain", Integer.toString(pid), "false" }; output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); }
Example 17
Source File: TestJcmdSanity.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * jcmd -J-XX:+UsePerfData pid help */ private static void testJcmdPidHelp() throws Exception { OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS, new String[] {"help"}); output.shouldHaveExitValue(0); output.shouldNotContain("Exception"); output.shouldContain(Integer.toString(ProcessTools.getProcessId()) + ":"); matchJcmdCommands(output); output.shouldContain("For more information about a specific command use 'help <command>'."); }
Example 18
Source File: TestJcmdSanity.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * jcmd -J-XX:+UsePerfData pid help */ private static void testJcmdPidHelp() throws Exception { OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS, new String[] {"help"}); output.shouldHaveExitValue(0); output.shouldNotContain("Exception"); output.shouldContain(Integer.toString(ProcessTools.getProcessId()) + ":"); matchJcmdCommands(output); output.shouldContain("For more information about a specific command use 'help <command>'."); }
Example 19
Source File: JpsBase.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { int pid = ProcessTools.getProcessId(); List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations(); for (List<JpsHelper.JpsArg> combination : combinations) { OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination)); output.shouldHaveExitValue(0); boolean isQuiet = false; boolean isFull = false; String pattern; for (JpsHelper.JpsArg jpsArg : combination) { switch (jpsArg) { case q: // If '-q' is specified output should contain only a list of local VM identifiers: // 30673 isQuiet = true; JpsHelper.verifyJpsOutput(output, "^\\d+$"); output.shouldContain(Integer.toString(pid)); break; case l: // If '-l' is specified output should contain the full package name for the application's main class // or the full path name to the application's JAR file: // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ... isFull = true; pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*"; output.shouldMatch(pattern); break; case m: // If '-m' is specified output should contain the arguments passed to the main method: // 30673 JpsBase monkey ... for (String arg : args) { pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*"; output.shouldMatch(pattern); } break; case v: // If '-v' is specified output should contain VM arguments: // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ... for (String vmArg : JpsHelper.getVmArgs()) { pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*"; output.shouldMatch(pattern); } break; case V: // If '-V' is specified output should contain VM flags: // 30673 JpsBase +DisableExplicitGC ... pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*"; output.shouldMatch(pattern); break; } if (isQuiet) { break; } } if (!isQuiet) { // Verify output line by line. // Output should only contain lines with pids after the first line with pid. JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*"); if (!isFull) { pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName); if (combination.isEmpty()) { // If no arguments are specified output should only contain // pid and process name pattern += "$"; } else { pattern += ".*"; } output.shouldMatch(pattern); } } } }
Example 20
Source File: BasicJInfoTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testJinfoProps() throws Exception { OutputAnalyzer output = jinfo("-props"); output.shouldContain("test.jdk="); output.shouldHaveExitValue(0); }