Java Code Examples for com.oracle.java.testlibrary.OutputAnalyzer#getExitValue()

The following examples show how to use com.oracle.java.testlibrary.OutputAnalyzer#getExitValue() . 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: TransitionsTestExecutor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void executeTestFor(int compilationPolicy, String testName) throws Throwable {
    String policy = "-XX:CompilationPolicyChoice=" + compilationPolicy;

    // Get runtime arguments including VM options given to this executor
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    List<String> vmArgs = runtime.getInputArguments();

    // Construct execution command with compilation policy choice and test name
    List<String> args = new ArrayList<>(vmArgs);
    Collections.addAll(args, policy, testName);

    OutputAnalyzer out = ProcessTools.executeTestJvm(args.toArray(new String[args.size()]));
    int exitCode = out.getExitValue();
    if (exitCode != 0) {
        throw new Error("Test execution failed with exit code " + exitCode);
    }
}
 
Example 2
Source File: TransitionsTestExecutor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void executeTestFor(int compilationPolicy, String testName) throws Throwable {
    String policy = "-XX:CompilationPolicyChoice=" + compilationPolicy;

    // Get runtime arguments including VM options given to this executor
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    List<String> vmArgs = runtime.getInputArguments();

    // Construct execution command with compilation policy choice and test name
    List<String> args = new ArrayList<>(vmArgs);
    Collections.addAll(args, policy, testName);

    OutputAnalyzer out = ProcessTools.executeTestJvm(args.toArray(new String[args.size()]));
    int exitCode = out.getExitValue();
    if (exitCode != 0) {
        throw new Error("Test execution failed with exit code " + exitCode);
    }
}
 
Example 3
Source File: TestCrashOnOutOfMemoryError.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        try {
            Object[] oa = new Object[Integer.MAX_VALUE];
            throw new Error("OOME not triggered");
        } catch (OutOfMemoryError err) {
            throw new Error("OOME didn't abort JVM!");
        }
    }
    // else this is the main test
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
            "-Xmx64m", TestCrashOnOutOfMemoryError.class.getName(),"throwOOME");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    int exitValue = output.getExitValue();
    if (0 == exitValue) {
        //expecting a non zero value
        throw new Error("Expected to get non zero exit value");
    }

    /* Output should look something like this. The actual text will depend on the OS and its core dump processing.
       Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       # To suppress the following error report, specify this argument
       # after -XX: or in .hotspotrc:  SuppressErrorAt=/debug.cpp:303
       #
       # A fatal error has been detected by the Java Runtime Environment:
       #
       #  Internal Error (/home/cheleswer/Desktop/jdk9/dev/hotspot/src/share/vm/utilities/debug.cpp:303), pid=6212, tid=6213
       #  fatal error: OutOfMemory encountered: Requested array size exceeds VM limit
       #
       # JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00)
       # Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
       # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to
         /home/cheleswer/Desktop/core.6212)
       #
       # An error report file with more information is saved as:
       # /home/cheleswer/Desktop/hs_err_pid6212.log
       #
       # If you would like to submit a bug report, please visit:
       #   http://bugreport.java.com/bugreport/crash.jsp
       #
       Current thread is 6213
       Dumping core ...
       Aborted (core dumped)
    */
    output.shouldContain("Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
    // extract hs-err file
    String hs_err_file = output.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
        throw new Error("Did not find hs-err file in output.\n");
    }

    /*
     * Check if hs_err files exist or not
     */
    File f = new File(hs_err_file);
    if (!f.exists()) {
        throw new Error("hs-err file missing at "+ f.getAbsolutePath() + ".\n");
    }

    System.out.println("PASSED");
}
 
Example 4
Source File: TestCrashOnOutOfMemoryError.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        try {
            Object[] oa = new Object[Integer.MAX_VALUE];
            throw new Error("OOME not triggered");
        } catch (OutOfMemoryError err) {
            throw new Error("OOME didn't abort JVM!");
        }
    }
    // else this is the main test
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
            "-Xmx64m", TestCrashOnOutOfMemoryError.class.getName(),"throwOOME");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    int exitValue = output.getExitValue();
    if (0 == exitValue) {
        //expecting a non zero value
        throw new Error("Expected to get non zero exit value");
    }

    /* Output should look something like this. The actual text will depend on the OS and its core dump processing.
       Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       # To suppress the following error report, specify this argument
       # after -XX: or in .hotspotrc:  SuppressErrorAt=/debug.cpp:303
       #
       # A fatal error has been detected by the Java Runtime Environment:
       #
       #  Internal Error (/home/cheleswer/Desktop/jdk9/dev/hotspot/src/share/vm/utilities/debug.cpp:303), pid=6212, tid=6213
       #  fatal error: OutOfMemory encountered: Requested array size exceeds VM limit
       #
       # JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00)
       # Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
       # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to
         /home/cheleswer/Desktop/core.6212)
       #
       # An error report file with more information is saved as:
       # /home/cheleswer/Desktop/hs_err_pid6212.log
       #
       # If you would like to submit a bug report, please visit:
       #   http://bugreport.java.com/bugreport/crash.jsp
       #
       Current thread is 6213
       Dumping core ...
       Aborted (core dumped)
    */
    output.shouldContain("Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
    // extract hs-err file
    String hs_err_file = output.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
        throw new Error("Did not find hs-err file in output.\n");
    }

    /*
     * Check if hs_err files exist or not
     */
    File f = new File(hs_err_file);
    if (!f.exists()) {
        throw new Error("hs-err file missing at "+ f.getAbsolutePath() + ".\n");
    }

    System.out.println("PASSED");
}
 
Example 5
Source File: TestCrashOnOutOfMemoryError.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        try {
            Object[] oa = new Object[Integer.MAX_VALUE];
            throw new Error("OOME not triggered");
        } catch (OutOfMemoryError err) {
            throw new Error("OOME didn't abort JVM!");
        }
    }
    // else this is the main test
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
            "-Xmx64m", TestCrashOnOutOfMemoryError.class.getName(),"throwOOME");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    int exitValue = output.getExitValue();
    if (0 == exitValue) {
        //expecting a non zero value
        throw new Error("Expected to get non zero exit value");
    }

    /* Output should look something like this. The actual text will depend on the OS and its core dump processing.
       Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       # To suppress the following error report, specify this argument
       # after -XX: or in .hotspotrc:  SuppressErrorAt=/debug.cpp:303
       #
       # A fatal error has been detected by the Java Runtime Environment:
       #
       #  Internal Error (/home/cheleswer/Desktop/jdk9/dev/hotspot/src/share/vm/utilities/debug.cpp:303), pid=6212, tid=6213
       #  fatal error: OutOfMemory encountered: Requested array size exceeds VM limit
       #
       # JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00)
       # Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
       # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to
         /home/cheleswer/Desktop/core.6212)
       #
       # An error report file with more information is saved as:
       # /home/cheleswer/Desktop/hs_err_pid6212.log
       #
       # If you would like to submit a bug report, please visit:
       #   http://bugreport.java.com/bugreport/crash.jsp
       #
       Current thread is 6213
       Dumping core ...
       Aborted (core dumped)
    */
    output.shouldContain("Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
    // extract hs-err file
    String hs_err_file = output.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
        throw new Error("Did not find hs-err file in output.\n");
    }

    /*
     * Check if hs_err files exist or not
     */
    File f = new File(hs_err_file);
    if (!f.exists()) {
        throw new Error("hs-err file missing at "+ f.getAbsolutePath() + ".\n");
    }

    System.out.println("PASSED");
}
 
Example 6
Source File: TestCrashOnOutOfMemoryError.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length == 1) {
        // This should guarantee to throw:
        // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
        try {
            Object[] oa = new Object[Integer.MAX_VALUE];
            throw new Error("OOME not triggered");
        } catch (OutOfMemoryError err) {
            throw new Error("OOME didn't abort JVM!");
        }
    }
    // else this is the main test
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
            "-Xmx64m", TestCrashOnOutOfMemoryError.class.getName(),"throwOOME");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    int exitValue = output.getExitValue();
    if (0 == exitValue) {
        //expecting a non zero value
        throw new Error("Expected to get non zero exit value");
    }

    /* Output should look something like this. The actual text will depend on the OS and its core dump processing.
       Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
       # To suppress the following error report, specify this argument
       # after -XX: or in .hotspotrc:  SuppressErrorAt=/debug.cpp:303
       #
       # A fatal error has been detected by the Java Runtime Environment:
       #
       #  Internal Error (/home/cheleswer/Desktop/jdk9/dev/hotspot/src/share/vm/utilities/debug.cpp:303), pid=6212, tid=6213
       #  fatal error: OutOfMemory encountered: Requested array size exceeds VM limit
       #
       # JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00)
       # Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
       # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to
         /home/cheleswer/Desktop/core.6212)
       #
       # An error report file with more information is saved as:
       # /home/cheleswer/Desktop/hs_err_pid6212.log
       #
       # If you would like to submit a bug report, please visit:
       #   http://bugreport.java.com/bugreport/crash.jsp
       #
       Current thread is 6213
       Dumping core ...
       Aborted (core dumped)
    */
    output.shouldContain("Aborting due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
    // extract hs-err file
    String hs_err_file = output.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
        throw new Error("Did not find hs-err file in output.\n");
    }

    /*
     * Check if hs_err files exist or not
     */
    File f = new File(hs_err_file);
    if (!f.exists()) {
        throw new Error("hs-err file missing at "+ f.getAbsolutePath() + ".\n");
    }

    System.out.println("PASSED");
}