Java Code Examples for jdk.test.lib.process.OutputAnalyzer#shouldHaveExitValue()

The following examples show how to use jdk.test.lib.process.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: Launcher.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception  {
    try (PrintWriter pw = new PrintWriter(MANIFEST)) {
        pw.println("Agent-Class: " + Agent.class.getName());
        pw.println("Can-Retransform-Classes: true");
    }

    JDKToolLauncher jar = JDKToolLauncher.create("jar")
            .addToolArg("cmf")
            .addToolArg(MANIFEST)
            .addToolArg(Agent.AGENT_JAR)
            .addToolArg(Agent.class.getName().replace('.', File.separatorChar) + ".class");

    ProcessBuilder pb = new ProcessBuilder(jar.getCommand());
    try {
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldHaveExitValue(0);
    } catch (IOException ex) {
        throw new Error("TESTBUG: jar failed.", ex);
    }
}
 
Example 2
Source File: TestPrintPreciseRTMLockingStatistics.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyNoStatistics(AbortType abortProvokerType,
        String... vmOpts) throws Throwable {
    AbortProvoker provoker = abortProvokerType.provoker();
    List<String> finalVMOpts = new LinkedList<>();
    Collections.addAll(finalVMOpts, vmOpts);
    Collections.addAll(finalVMOpts, AbortProvoker.class.getName(),
            abortProvokerType.toString());

    OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(provoker,
            finalVMOpts.toArray(new String[finalVMOpts.size()]));

    outputAnalyzer.shouldHaveExitValue(0);

    List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
            outputAnalyzer.getOutput());

    Asserts.assertEQ(statistics.size(), 0, "VM output should not contain "
            + "any RTM locking statistics");
}
 
Example 3
Source File: MHInlineTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
            "-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
            "-XX:-TieredCompilation", "-Xbatch",
            "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
            "-XX:CompileCommand=dontinline,compiler.jsr292.MHInlineTest::test*",
                Launcher.class.getName());

    OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());

    analyzer.shouldHaveExitValue(0);

    // The test is applicable only to C2 (present in Server VM).
    if (analyzer.getStderr().contains("Server VM")) {
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::public_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::protected_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::package_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$A::package_final_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::private_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::private_static_x (3 bytes)   inline (hot)");
        analyzer.shouldContain("compiler.jsr292.MHInlineTest$A::package_static_x (3 bytes)   inline (hot)");
    }
}
 
Example 4
Source File: TestAgeOutput.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void runTest(String gcArg) throws Exception {
    final String[] arguments = {
        "-Xbootclasspath/a:.",
        "-XX:+UnlockExperimentalVMOptions",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:+" + gcArg,
        "-Xmx10M",
        "-Xlog:gc+age=trace",
        GCTest.class.getName()
        };

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldHaveExitValue(0);

    System.out.println(output.getStdout());

    String stdout = output.getStdout();

    checkPattern(".*GC\\(0\\) .*Desired survivor size.*", stdout);
    checkPattern(".*GC\\(0\\) .*Age table with threshold.*", stdout);
    checkPattern(".*GC\\(0\\) .*- age   1:.*", stdout);
}
 
Example 5
Source File: ExecuteOOMApp.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Executes OOM application with JFR recording and returns true if OOM error happened in the
 * test thread. Adds -XX:-UseGCOverheadLimit option to avoid "java.lang.OutOfMemoryError: GC overhead limit exceeded".
 *
 * @param settings JFR settings file
 * @param jfrFilename JFR resulting recording filename
 * @param additionalVmFlags additional VM flags passed to the java
 * @param bytesToAllocate number of bytes to allocate in new object every cycle in OOM application
 * @return true - OOM application is finished as expected,i.e. OOM happened in the test thead
 *         false - OOM application is finished with OOM error which happened in the non test thread
 */
public static boolean execute(String settings, String jfrFilename, String[] additionalVmFlags, int bytesToAllocate) throws Exception {
    List<String> additionalVmFlagsList = new ArrayList<>(Arrays.asList(additionalVmFlags));
    additionalVmFlagsList.add("-XX:-UseGCOverheadLimit");

    OutputAnalyzer out = AppExecutorHelper.executeAndRecord(settings, jfrFilename, additionalVmFlagsList.toArray(new String[0]),
                                                            OOMApp.class.getName(), String.valueOf(bytesToAllocate));

    if ((out.getExitValue() == 1 && out.getOutput().contains("Exception: java.lang.OutOfMemoryError"))) {
        return false;
    }

    out.shouldHaveExitValue(0);
    System.out.println(out.getOutput());

    return true;
}
 
Example 6
Source File: CommandLineOptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies that JVM startup behavior matches our expectations.
 *
 * @param expectedMessages an array of patterns that should occur
 *                         in JVM output. If {@code null} then
 *                         JVM output could be empty.
 * @param unexpectedMessages an array of patterns that should not
 *                           occur in JVM output. If {@code null} then
 *                           JVM output could be empty.
 * @param exitErrorMessage message that will be shown if exit code is not
 *                           as expected.
 * @param wrongWarningMessage message that will be shown if warning
 *                           messages are not as expected.
 * @param exitCode expected exit code.
 * @param addTestVMOptions if {@code true} then test VM options will be
 *                         passed to VM.
 * @param options options that should be passed to VM in addition to mode
 *                flag.
 * @throws Throwable if verification fails or some other issues occur.
 */
public static void verifyJVMStartup(String expectedMessages[],
        String unexpectedMessages[], String exitErrorMessage,
        String wrongWarningMessage, ExitCode exitCode,
        boolean addTestVMOptions, String... options)
                throws Throwable {
    List<String> finalOptions = new ArrayList<>();
    if (addTestVMOptions) {
        Collections.addAll(finalOptions, InputArguments.getVmInputArgs());
        Collections.addAll(finalOptions, Utils.getTestJavaOpts());
    }
    Collections.addAll(finalOptions, options);
    finalOptions.add("-version");

    ProcessBuilder processBuilder
            = ProcessTools.createJavaProcessBuilder(finalOptions.toArray(
            new String[finalOptions.size()]));
    OutputAnalyzer outputAnalyzer
            = new OutputAnalyzer(processBuilder.start());

    try {
            outputAnalyzer.shouldHaveExitValue(exitCode.value);
    } catch (RuntimeException e) {
        String errorMessage = String.format(
                "JVM process should have exit value '%d'.%n%s",
                exitCode.value, exitErrorMessage);
        throw new AssertionError(errorMessage, e);
    }

    verifyOutput(expectedMessages, unexpectedMessages,
            wrongWarningMessage, outputAnalyzer);
}
 
Example 7
Source File: TestParNewSerialOld.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParNewGC", "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("It is not possible to combine the ParNew young collector with any collector other than CMS.");
  output.shouldContain("Error");
  output.shouldHaveExitValue(1);
}
 
Example 8
Source File: JcmdHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static OutputAnalyzer jcmd(int expectedExitValue, String... args) {
    String argsString = Arrays.stream(args).collect(Collectors.joining(" "));
    CommandExecutor executor = new PidJcmdExecutor();
    OutputAnalyzer oa = executor.execute(argsString);
    oa.shouldHaveExitValue(expectedExitValue);
    return oa;
}
 
Example 9
Source File: TestMaxHeapSizeTools.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  shouldContainOrNot(output, hasWarning, "Warning");
  shouldContainOrNot(output, hasError, "Error");
  output.shouldHaveExitValue(errorcode);
}
 
Example 10
Source File: CompileJarTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    createJar();
    OutputAnalyzer oa = JaotcTestHelper.compileLibrary("--jar", JAR_NAME);
    oa.shouldHaveExitValue(0);
    File compiledLibrary = new File(JaotcTestHelper.DEFAULT_LIB_PATH);
    Asserts.assertTrue(compiledLibrary.exists(), "Compiled library file missing");
    Asserts.assertGT(compiledLibrary.length(), 0L, "Unexpected compiled library size");
    JaotcTestHelper.checkLibraryUsage(HelloWorldOne.class.getName());
    JaotcTestHelper.checkLibraryUsage(HelloWorldTwo.class.getName());
}
 
Example 11
Source File: ClassLoadUnloadTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void checkAbsent(String... outputStrings) throws Exception {
    out = new OutputAnalyzer(pb.start());
    for (String s: outputStrings) {
        out.shouldNotContain(s);
    }
    out.shouldHaveExitValue(0);
}
 
Example 12
Source File: TestStartName.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testName(String recordingName, boolean validName) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
        "-XX:StartFlightRecording=name=" + recordingName, TestName.class.getName(), recordingName);
    OutputAnalyzer out = ProcessTools.executeProcess(pb);

    if (validName) {
        out.shouldHaveExitValue(0);
    } else {
        out.shouldHaveExitValue(1);
        out.shouldContain("Name of recording can't be numeric");
    }
}
 
Example 13
Source File: IgnoreModulePropertiesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void testProperty(String prop, String value) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-D" + prop + "=" + value, "-version");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain(" version ");
    output.shouldHaveExitValue(0);

    // Ensure that the property and its value aren't available.
    if (System.getProperty(prop) != null) {
        throw new RuntimeException(
            "Unexpected non-null value for property " + prop);
    }
}
 
Example 14
Source File: CompressedClassPointers.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void largePagesTest() throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-Xmx128m",
        "-XX:+UseLargePages",
        "-Xlog:gc+metaspace=trace",
        "-XX:+VerifyBeforeGC", "-version");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("Narrow klass base:");
    output.shouldHaveExitValue(0);
}
 
Example 15
Source File: SASymbolTableTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void createArchive()  throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:SharedArchiveFile=" + jsaName,
        "-Xshare:dump");

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("Loading classes to share");
    output.shouldHaveExitValue(0);
}
 
Example 16
Source File: LoadClassNegative.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  String bootCP = "-Xbootclasspath/a:" + System.getProperty("test.src")
                     + File.separator + "dummy.jar";
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
      bootCP,
      "TestForName");

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("ClassNotFoundException");
  output.shouldHaveExitValue(0);
}
 
Example 17
Source File: TestExplicitGCInvokesConcurrentAndUnloadsClasses.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ProcessBuilder pb =
        ProcessTools.createJavaProcessBuilder("-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses",
                                              "-Xlog:gc",
                                              "-version");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("ExplicitGCInvokesConcurrentAndUnloadsClasses was deprecated");
    output.shouldHaveExitValue(0);
}
 
Example 18
Source File: StartupTimeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void analyzeModulesOutputOn(ProcessBuilder pb) throws Exception {
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldMatch("(Phase2 initialization, [0-9]+.[0-9]+ secs)");
    output.shouldHaveExitValue(0);
}
 
Example 19
Source File: TestInstanceKlassSize.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void startMeWithArgs() throws Exception {

        LingeredApp app = null;
        OutputAnalyzer output = null;
        try {
            List<String> vmArgs = new ArrayList<String>();
            vmArgs.add("-XX:+UsePerfData");
            vmArgs.addAll(Utils.getVmOptions());
            app = LingeredApp.startApp(vmArgs);
            System.out.println ("Started LingeredApp with pid " + app.getPid());
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        try {
            String[] instanceKlassNames = new String[] {
                                              " java.lang.Object",
                                              " java.util.Vector",
                                              " sun.util.PreHashedMap",
                                              " java.lang.String",
                                              " java.lang.Thread",
                                              " java.lang.Byte",
                                          };
            String[] toolArgs = {
                "--add-modules=jdk.hotspot.agent",
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
                "TestInstanceKlassSize",
                Long.toString(app.getPid())
            };

            OutputAnalyzer jcmdOutput = jcmd(
                           app.getPid(),
                           "GC.class_stats", "VTab,ITab,OopMap,KlassBytes");
            ProcessBuilder processBuilder = ProcessTools
                                            .createJavaProcessBuilder(toolArgs);
            output = ProcessTools.executeProcess(processBuilder);
            System.out.println(output.getOutput());
            output.shouldHaveExitValue(0);

            // Check whether the size matches that which jcmd outputs
            for (String instanceKlassName : instanceKlassNames) {
                System.out.println ("Trying to match for" + instanceKlassName);
                String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
                                                      jcmdOutput,
                                                      instanceKlassName);
                Asserts.assertNotNull(jcmdInstanceKlassSize,
                    "Could not get the instance klass size from the jcmd output");
                for (String s : output.asLines()) {
                    if (s.contains(instanceKlassName)) {
                       Asserts.assertTrue(
                          s.contains(jcmdInstanceKlassSize),
                          "The size computed by SA for" +
                          instanceKlassName + " does not match.");
                    }
                }
            }
        } finally {
            LingeredApp.stopApp(app);
        }
    }
 
Example 20
Source File: TestDynamicNumberOfGCThreads.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output) {
  output.shouldHaveExitValue(0); // test should run succesfully
  output.shouldContain("new_active_workers");
}