jdk.test.lib.process.ProcessTools Java Examples

The following examples show how to use jdk.test.lib.process.ProcessTools. 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: TestAESIntrinsicsOnSupportedConfig.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test checks following situation: <br/>
 * UseAES flag is set to true, TestAESMain is executed <br/>
 * Expected result: UseAESIntrinsics flag is set to true <br/>
 * If vm type is server then output should contain intrinsics usage <br/>
 *
 * @throws Throwable
 */
private void testUseAES() throws Throwable {
    OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
            prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
                    .USE_AES, true)));
    final String errorMessage = "Case testUseAES failed";
    if (Platform.isServer() && !Platform.isEmulatedClient()) {
        verifyOutput(new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
                AESIntrinsicsBase.AES_INTRINSIC}, null, errorMessage,
                outputAnalyzer);
    } else {
        verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
                AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,
                outputAnalyzer);
    }
    verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
            outputAnalyzer);
    verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "true",
            errorMessage, outputAnalyzer);
}
 
Example #2
Source File: SpaceUtilizationCheck.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:+UnlockDiagnosticVMOptions",
       "-XX:SharedArchiveFile=./SpaceUtilizationCheck.jsa",
       "-Xshare:dump");

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    String stdout = output.getStdout();
    ArrayList<String> utilization = findUtilization(stdout);

    if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
        throw new RuntimeException("The output format of sharing summary has changed");

    for(String str : utilization) {
        int value = Integer.parseInt(str);
        if (value < MIN_UTILIZATION) {
            System.out.println(stdout);
            throw new RuntimeException("Utilization for one of the regions" +
                "is below a threshold of " + MIN_UTILIZATION + "%");
        }
    }
}
 
Example #3
Source File: DefineClass.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void loadInstrumentationAgent(String myName, byte[] buf) throws Exception {
    // Create agent jar file on the fly
    Manifest m = new Manifest();
    m.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    m.getMainAttributes().put(new Attributes.Name("Agent-Class"), myName);
    m.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true");
    File jarFile = File.createTempFile("agent", ".jar");
    jarFile.deleteOnExit();
    JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarFile), m);
    jar.putNextEntry(new JarEntry(myName.replace('.', '/') + ".class"));
    jar.write(buf);
    jar.close();
    String pid = Long.toString(ProcessTools.getProcessId());
    System.out.println("Our pid is = " + pid);
    VirtualMachine vm = VirtualMachine.attach(pid);
    vm.loadAgent(jarFile.getAbsolutePath());
}
 
Example #4
Source File: TestInitialTenuringThreshold.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(
    // some value below the default value of InitialTenuringThreshold of 7
    "-XX:MaxTenuringThreshold=1",
    "-version"
    );

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldHaveExitValue(0);
  // successful tests
  runWithThresholds(0, 10, false);
  runWithThresholds(5, 5, false);
  runWithThresholds(8, 16, false);
  // failing tests
  runWithThresholds(10, 0, true);
  runWithThresholds(9, 8, true);
  runWithThresholds(-1, 8, true);
  runWithThresholds(0, -1, true);
  runWithThresholds(8, -1, true);
  runWithThresholds(16, 8, true);
  runWithThresholds(8, 17, true);
}
 
Example #5
Source File: TestCMSClassUnloadingEnabledHWM.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    "-Xbootclasspath/a:.",
    "-XX:+UnlockDiagnosticVMOptions",
    "-XX:+WhiteBoxAPI",
    "-Xmx128m",
    "-XX:CMSMaxAbortablePrecleanTime=1",
    "-XX:CMSWaitDuration=50",
    "-XX:MetaspaceSize=" + MetaspaceSize,
    "-Xmn" + YoungGenSize,
    "-XX:+UseConcMarkSweepGC",
    "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled",
    "-Xlog:gc",
    TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(),
    "" + MetaspaceSize);
  return new OutputAnalyzer(pb.start());
}
 
Example #6
Source File: TestNumWorkerOutput.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",
        "-XX:+PrintGCDetails",
        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();

    checkPatternOnce(".*[info.*].*[gc,task.*].*GC\\(0\\) .*Using \\d+ workers of \\d+ for evacuation.*", stdout);
}
 
Example #7
Source File: DebugOutputTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void test() {
    for (TestCaseData testCase : TestCaseData.values()) {
        System.out.println(testCase);
        OutputAnalyzer oa;
        try {
            oa = ProcessTools.executeTestJvmAllArgs(
                    "-XX:+UnlockExperimentalVMOptions",
                    "-XX:+EnableJVMCI",
                    "-Xbootclasspath/a:.",
                    DebugOutputTest.Worker.class.getName(),
                    testCase.name());
           } catch (Throwable e) {
            e.printStackTrace();
            throw new Error("Problems running child process", e);
        }
        if (testCase.expectedException != null) {
            oa.shouldHaveExitValue(1);
            oa.shouldContain(testCase.expectedException.getName());
        } else {
            oa.shouldHaveExitValue(0);
            oa.shouldContain(new String(testCase.getExpected()));
        }
    }
}
 
Example #8
Source File: GuardShrinkWarning.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(
      "-showversion",
      "-XX:+UseConcMarkSweepGC",
      "-XX:+ExplicitGCInvokesConcurrent",
      "GuardShrinkWarning$SystemGCCaller"
      );

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

    output.shouldNotContain("Shrinking of CMS not yet implemented");

    output.shouldNotContain("error");

    output.shouldHaveExitValue(0);
  }
 
Example #9
Source File: TestInstrumentation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void launchTest() throws Throwable {
    final String slash = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + slash + "lib" + slash + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + slash;

    String[] args = {
        "-Xbootclasspath/a:" + testClassDir + "InstrumentationCallback.jar",
       /* "--add-exports", "java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED",*/
        "-classpath", classpath,
        "-javaagent:" + testClassDir + "TestInstrumentation.jar",
        "jdk.jfr.event.io.TestInstrumentation$TestMain" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example #10
Source File: PatchModuleJavaBase.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 {
    String source = "package java.lang; "                       +
                    "public class NewClass { "                  +
                    "    static { "                             +
                    "        System.out.println(\"I pass!\"); " +
                    "    } "                                    +
                    "}";

    ClassFileInstaller.writeClassToDisk("java/lang/NewClass",
         InMemoryJavaCompiler.compile("java.lang.NewClass", source, "-Xmodule:java.base"),
         "mods/java.base");

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("--patch-module=java.base=mods/java.base",
         "PatchModuleMain", "java.lang.NewClass");

    new OutputAnalyzer(pb.start())
        .shouldContain("I pass!")
        .shouldHaveExitValue(0);
}
 
Example #11
Source File: TestSmallHeap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
    long minMaxHeap = 4 * 1024 * 1024;
    LinkedList<String> vmOptions = new LinkedList<>();
    vmOptions.add(gc);
    vmOptions.add("-Xmx" + minMaxHeap);
    vmOptions.add("-XX:+PrintFlagsFinal");
    vmOptions.add(VerifyHeapSize.class.getName());

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[0]));
    OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
    analyzer.shouldHaveExitValue(0);

    expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap);
    long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1));
    long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1));
    Asserts.assertEQ(maxHeapSize, expectedMaxHeap);
    Asserts.assertLessThanOrEqual(actualHeapSize, maxHeapSize);
}
 
Example #12
Source File: AssertSafepointCheckConsistency4.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 {
    if (args.length > 0) {
        WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, false);
    }
    if (Platform.isDebugBuild()){
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
           "-Xbootclasspath/a:.",
           "-XX:+UnlockDiagnosticVMOptions",
           "-XX:+WhiteBoxAPI",
           "-XX:-TransmitErrorReport",
           "-XX:-CreateCoredumpOnCrash",
           "-Xmx32m",
           "AssertSafepointCheckConsistency4",
           "test");

        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        output.shouldNotContain("assert");
        output.shouldNotContain("never");
        output.shouldNotContain("always");
    }
}
 
Example #13
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 #14
Source File: TestMaxMinHeapFreeRatioFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verify that heap size will be changed to conform
 * min and max heap free ratios.
 *
 * @param minRatio value of MinHeapFreeRatio option
 * @param useXminf used Xminf option instead of MinHeapFreeRatio
 * @param maxRatio value of MaxHeapFreeRatio option
 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio
 * @param options additional options for JVM
 */
public static void positiveTest(int minRatio, boolean useXminf,
        int maxRatio, boolean useXmaxf, boolean shrinkHeapInSteps,
        LinkedList<String> options) throws Exception {

    LinkedList<String> vmOptions = new LinkedList<>(options);
    Collections.addAll(vmOptions,
            (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
            (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
            "-Xmx" + MAX_HEAP_SIZE,
            "-Xms" + HEAP_SIZE,
            "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
            "-XX:NewSize=" + NEW_SIZE,
            "-XX:MaxNewSize=" + MAX_NEW_SIZE,
            "-XX:" + (shrinkHeapInSteps ? '+' : '-') + "ShrinkHeapInSteps",
            RatioVerifier.class.getName(),
            Integer.toString(minRatio),
            Integer.toString(maxRatio),
            Boolean.toString(shrinkHeapInSteps)
    );

    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
    OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
    analyzer.shouldHaveExitValue(0);
}
 
Example #15
Source File: TestMaxMinHeapFreeRatioFlags.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verify that VM will fail to start with specified ratios.
 *
 * @param minRatio value of MinHeapFreeRatio option
 * @param useXminf used Xminf option instead of MinHeapFreeRatio
 * @param maxRatio value of MaxHeapFreeRatio option
 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio
 * @param options additional options for JVM
 */
public static void negativeTest(int minRatio, boolean useXminf,
        int maxRatio, boolean useXmaxf,
        LinkedList<String> options) throws Exception {

    LinkedList<String> vmOptions = new LinkedList<>(options);
    Collections.addAll(vmOptions,
            (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
            (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
            "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
            "-version"
    );
    ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
    OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
    analyzer.shouldHaveExitValue(1);
    analyzer.shouldContain("Error: Could not create the Java Virtual Machine.");
}
 
Example #16
Source File: CompressedOopsTest.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:+UseCompressedOops",
                                               "-Xlog:gc+heap+coops=info",
                                               InnerClass.class.getName());
    analyzeOutputOn(pb);

    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseCompressedOops",
                                               "-XX:+PrintCompressedOopsMode",
                                               InnerClass.class.getName());
    analyzeOutputOn(pb);

    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseCompressedOops",
                                               "-XX:+PrintCompressedOopsMode",
                                               "-Xlog:gc+heap+coops=off",
                                               InnerClass.class.getName());
    analyzeOutputOff(pb);

    pb = ProcessTools.createJavaProcessBuilder("-XX:+UseCompressedOops",
                                               "-Xlog:gc+heap+coops=info",
                                               "-XX:-PrintCompressedOopsMode",
                                               InnerClass.class.getName());
    analyzeOutputOff(pb);
}
 
Example #17
Source File: CDSTestUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static OutputAnalyzer runWithArchive(CDSOptions opts)
    throws Exception {

    ArrayList<String> cmd = new ArrayList<String>();

    for (String p : opts.prefix) cmd.add(p);

    cmd.add("-Xshare:" + opts.xShareMode);
    cmd.add("-Dtest.timeout.factor=" + TestTimeoutFactor);

    if (opts.archiveName == null)
        opts.archiveName = getDefaultArchiveName();
    cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);

    if (opts.useVersion)
        cmd.add("-version");

    for (String s : opts.suffix) cmd.add(s);

    String[] cmdLine = cmd.toArray(new String[cmd.size()]);
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
    return executeAndLog(pb, "exec");
}
 
Example #18
Source File: RangeCheck.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 {
    if (!Platform.isDebugBuild()) {
        System.out.println("Testing assert which requires a debug build. Passing silently.");
        return;
    }

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
            true,
            "-Xmx32m",
            "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
            "-XX:-TransmitErrorReport",
            "-XX:-CreateCoredumpOnCrash",
            "-XX:-InlineUnsafeOps", // The compiler intrinsics doesn't have the assert
            DummyClassWithMainRangeCheck.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldMatch("assert\\(byte_offset < p_size\\) failed: Unsafe access: offset \\d+ > object's size \\d+");
}
 
Example #19
Source File: AdaptiveGCBoundary.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(
      "-showversion",
      "-XX:+UseParallelGC",
      "-XX:+UseAdaptiveGCBoundary",
      "-XX:+PrintCommandLineFlags",
      SystemGCCaller.class.getName()
      );

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

    output.shouldContain("+UseAdaptiveGCBoundary");

    output.shouldNotContain("error");

    output.shouldHaveExitValue(0);
  }
 
Example #20
Source File: TestVerifyDuringStartup.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 {
  ArrayList<String> vmOpts = new ArrayList();

  String testVmOptsStr = System.getProperty("test.java.opts");
  if (!testVmOptsStr.isEmpty()) {
    String[] testVmOpts = testVmOptsStr.split(" ");
    Collections.addAll(vmOpts, testVmOpts);
  }
  Collections.addAll(vmOpts, new String[] {"-XX:-UseTLAB",
                                           "-XX:+UnlockDiagnosticVMOptions",
                                           "-XX:+VerifyDuringStartup",
                                           "-Xlog:gc+verify=debug",
                                           "-version"});

  System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
  for (int i = 0; i < vmOpts.size(); i += 1) {
    System.out.print(" " + vmOpts.get(i));
  }
  System.out.println();

  ProcessBuilder pb =
    ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());

  System.out.println("Output:\n" + output.getOutput());

  output.shouldContain("Verifying");
  output.shouldHaveExitValue(0);
}
 
Example #21
Source File: TestMaxNewSize.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkIncompatibleNewSize(String[] flags) throws Exception {
  ArrayList<String> finalargs = new ArrayList<String>();
  finalargs.addAll(Arrays.asList(flags));
  finalargs.add("-version");

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("Initial young gen size set larger than the maximum young gen size");
}
 
Example #22
Source File: PrintNMTStatistics.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:+UnlockDiagnosticVMOptions",
      "-XX:+PrintNMTStatistics",
      "-XX:NativeMemoryTracking=detail",
      "-version");

    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
    output_detail.shouldContain("Virtual memory map:");
    output_detail.shouldContain("Details:");
    output_detail.shouldNotContain("error");
    output_detail.shouldHaveExitValue(0);

    // Make sure memory reserved for Module processing is recorded.
    output_detail.shouldContain(" Module (reserved=");

    ProcessBuilder pb1 = ProcessTools.createJavaProcessBuilder(
      "-XX:+UnlockDiagnosticVMOptions",
      "-XX:+PrintNMTStatistics",
      "-XX:NativeMemoryTracking=summary",
      "-version");

    OutputAnalyzer output_summary = new OutputAnalyzer(pb1.start());
    output_summary.shouldContain("Java Heap (reserved=");
    output_summary.shouldNotContain("Virtual memory map:");
    output_summary.shouldNotContain("Details:");
    output_summary.shouldNotContain("error");
    output_summary.shouldHaveExitValue(0);
    }
 
Example #23
Source File: TestHumongousAllocNearlyFullRegion.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:+UseG1GC",
        "-Xms" + heapSize + "m",
        "-Xmx" + heapSize + "m",
        "-XX:G1HeapRegionSize=" + heapRegionSize + "m",
        "-Xlog:gc",
        HumongousObjectAllocator.class.getName());

    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    output.shouldContain("Pause Initial Mark (G1 Humongous Allocation)");
    output.shouldHaveExitValue(0);
}
 
Example #24
Source File: TestLogging.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method spawns MixedGCProvoker with addition flags set
 *
 * @parameter extraFlags -flags to be added to the common options set
 */
private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
        throws Exception {
    List<String> testOpts = new ArrayList<>();
    Collections.addAll(testOpts, COMMON_OPTIONS);
    Collections.addAll(testOpts, extraFlags);
    testOpts.add(MixedGCProvoker.class.getName());
    System.out.println(testOpts);
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
            testOpts.toArray(new String[testOpts.size()]));
    return new OutputAnalyzer(pb.start());
}
 
Example #25
Source File: PatchModuleDupJavaBase.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(
    "--patch-module=java.base=javabase_dir",
    "--patch-module=java.base=javabase_dir",
    "-version");
  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  output.shouldContain("Cannot specify java.base more than once to --patch-module");
  output.shouldHaveExitValue(1);
}
 
Example #26
Source File: TestAESIntrinsicsOnUnsupportedConfig.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test checks following situation: <br/>
 * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
 * Expected result: UseAES flag is set to false <br/>
 * UseAES flag is set to false <br/>
 * Output shouldn't contain intrinsics usage <br/>
 * Output should contain message about AES unavailability <br/>
 * @throws Throwable
 */
private void testUseAES() throws Throwable {
    OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
            AESIntrinsicsBase.prepareArguments(prepareBooleanFlag
                    (AESIntrinsicsBase.USE_AES, true)));
    final String errorMessage = "Case testUseAES failed";
    verifyOutput(new String[] {AES_NOT_AVAILABLE_MSG},
            new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
            AESIntrinsicsBase.AES_INTRINSIC}, errorMessage, outputAnalyzer);
    verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
            errorMessage, outputAnalyzer);
    verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
            outputAnalyzer);
}
 
Example #27
Source File: ModuleStressGC.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compile two module definitions used by the test, jdk.test and jdk.translet.
 */
public static void main(String[] args) throws Exception {

    boolean compiled;
    // Compile module jdk.test declaration
    compiled = CompilerUtils.compile(
        SRC_DIR.resolve("jdk.test"),
        MODS_DIR.resolve("jdk.test"));
    if (!compiled) {
        throw new RuntimeException("Test failed to compile module jdk.test");
    }

    // Compile module jdk.translet declaration
    compiled = CompilerUtils.compile(
        SRC_DIR.resolve("jdk.translet"),
        MODS_DIR.resolve("jdk.translet"),
        "--add-exports=jdk.test/test=jdk.translet",
        "-p", MODS_DIR.toString());
    if (!compiled) {
        throw new RuntimeException("Test failed to compile module jdk.translet");
    }

    // Sanity check that the test, jdk.test/test/MainGC.java,
    // correctly walks module jdk.test's reads list and package
    // test's, defined to module jdk.translet, export list at
    // GC safepoints.
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xlog:module=trace",
        "-p", MODS_DIR.toString(),
        "-m", "jdk.test/test.MainGC");
    OutputAnalyzer oa = new OutputAnalyzer(pb.start());
    oa.shouldContain("package test defined in module jdk.test, exports list being walked")
      .shouldContain("module jdk.test reads list being walked")
      .shouldHaveExitValue(0);
}
 
Example #28
Source File: CommandLineOptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies that value of specified JVM option is the same as
 * expected value.
 * This method filter out option with {@code optionName}
 * name from test java options.
 *
 * @param optionName a name of tested option.
 * @param expectedValue expected value of tested option.
 * @param addTestVmOptions if {@code true}, then test VM options
 *                         will be used.
 * @param optionErrorString message will be shown if option value is not as
 *                         expected.
 * @param additionalVMOpts additional options that should be
 *                         passed to JVM.
 * @throws Throwable if verification fails or some other issues
 *                          occur.
 */
public static void verifyOptionValue(String optionName,
        String expectedValue, String optionErrorString,
        boolean addTestVmOptions, String... additionalVMOpts)
                throws Throwable {
    List<String> vmOpts = new ArrayList<>();

    if (addTestVmOptions) {
        Collections.addAll(vmOpts,
                           Utils.getFilteredTestJavaOpts(optionName));
    }
    Collections.addAll(vmOpts, additionalVMOpts);
    Collections.addAll(vmOpts, "-XX:+PrintFlagsFinal", "-version");

    ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
            vmOpts.toArray(new String[vmOpts.size()]));

    OutputAnalyzer outputAnalyzer
            = new OutputAnalyzer(processBuilder.start());

    try {
        outputAnalyzer.shouldHaveExitValue(0);
    } catch (RuntimeException e) {
        String errorMessage = String.format(
                "JVM should start with option '%s' without errors.",
                optionName);
        throw new AssertionError(errorMessage, e);
    }
    verifyOptionValue(optionName, expectedValue, optionErrorString,
            outputAnalyzer);
}
 
Example #29
Source File: Xprof.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("-minimal", "-Xprof", "-version");
    new OutputAnalyzer(pb.start())
            .shouldContain("Flat profiling is not supported in this VM.")
            .shouldHaveExitValue(1);

}
 
Example #30
Source File: TestShutdownEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void runSubtest(int subTestIndex) throws Exception {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
                            "-XX:+LogJFR",
                            "-XX:-CreateMinidumpOnCrash",
                            "-XX:StartFlightRecording=filename=./dumped.jfr,dumponexit=true,settings=default",
                            "jdk.jfr.event.runtime.TestShutdownEvent$TestMain",
                            String.valueOf(subTestIndex));
    OutputAnalyzer output = ProcessTools.executeProcess(pb);
    System.out.println(output.getOutput());
    int exitCode = output.getExitValue();
    System.out.println("Exit code: " + exitCode);

    String recordingName = output.firstMatch("emergency jfr file: (.*.jfr)", 1);
    if (recordingName == null) {
        recordingName = "./dumped.jfr";
    }

    List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(recordingName));
    List<RecordedEvent> filteredEvents = events.stream()
        .filter(e -> e.getEventType().getName().equals(EventNames.Shutdown))
        .sorted(Comparator.comparing(RecordedEvent::getStartTime))
        .collect(Collectors.toList());

    Asserts.assertEquals(filteredEvents.size(), 1);
    RecordedEvent event = filteredEvents.get(0);
    subTests[subTestIndex].verifyEvents(event, exitCode);
}