jdk.test.lib.process.OutputAnalyzer.asLines() - java examples

Here are the examples of the java api jdk.test.lib.process.OutputAnalyzer.asLines() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

19 View Complete Implementation : CompilerDirectivesDCMDTest.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public static int find(Outputreplacedyzer output, String find) {
    int count = 0;
    for (String line : output.asLines()) {
        if (line.startsWith(find)) {
            count++;
        }
    }
    return count;
}

19 View Complete Implementation : TestInstanceKlassSizeForInterface.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private static String getJcmdInstanceKlreplacedSize(Outputreplacedyzer output, String instanceKlreplacedName) {
    for (String s : output.asLines()) {
        if (s.contains(instanceKlreplacedName)) {
            String[] tokens;
            System.out.println(s);
            tokens = s.split("\\s+");
            return tokens[3];
        }
    }
    return null;
}

18 View Complete Implementation : TestDriver.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private List<String> executeApplication() throws Throwable {
    Outputreplacedyzer outputreplacedyzer = ProcessTools.executeTestJvmAllArgs("-Xbatch", "-XX:-TieredCompilation", "-XX:+PrintCompilation", "-XX:+TraceNewVectors", TestIntVect.clreplaced.getName());
    outputreplacedyzer.shouldHaveExitValue(0);
    return outputreplacedyzer.asLines();
}

18 View Complete Implementation : IhopUtils.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Finds strings which contains patterns for finding.
 *
 * @param outputreplacedyzer List of string for IHOP messages extraction
 * @param stringsToFind Strings which is checked for matching with Outputreplacedyzer content
 * @return List of strings which were matched.
 */
private static List<String> findInLog(Outputreplacedyzer outputreplacedyzer, String... stringsToFind) {
    return outputreplacedyzer.asLines().stream().filter(string -> {
        return Stream.of(stringsToFind).filter(find -> string.contains(find)).findAny().isPresent();
    }).collect(Collectors.toList());
}

18 View Complete Implementation : TestPLABEvacuationFailure.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private static List<Long> getGcIdPlabEvacFailures(Outputreplacedyzer out) {
    return out.asLines().stream().filter(line -> line.contains("Evacuation Failure")).map(line -> LogParser.getGcIdFromLine(line, GC_ID_PATTERN)).collect(Collectors.toList());
}

18 View Complete Implementation : TestCheckedJniExceptionCheck.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
// Check warnings appear where they should, with start/end statements in output...
static void checkOuputForCorrectWarnings(Outputreplacedyzer oa) throws RuntimeException {
    List<String> lines = oa.asLines();
    int expectedWarnings = 0;
    int warningCount = 0;
    int lineNo = 0;
    boolean testStartLine = false;
    for (String line : lines) {
        lineNo++;
        if (!testStartLine) {
            // Skip any warning before the actual test itself
            testStartLine = line.startsWith(TEST_START);
            continue;
        }
        if (line.startsWith(JNI_CHECK_EXCEPTION)) {
            if (expectedWarnings == 0) {
                oa.reportDiagnosticSummary();
                throw new RuntimeException("Unexpected warning at line " + lineNo);
            }
            warningCount++;
            if (warningCount > expectedWarnings) {
                oa.reportDiagnosticSummary();
                throw new RuntimeException("Unexpected warning at line " + lineNo);
            }
        } else if (line.startsWith(EXPECT_WARNING_START)) {
            String countStr = line.substring(EXPECT_WARNING_START.length() + 1);
            expectedWarnings = Integer.parseInt(countStr);
        } else if (line.startsWith(EXPECT_WARNING_END)) {
            if (warningCount != expectedWarnings) {
                oa.reportDiagnosticSummary();
                throw new RuntimeException("Missing warning at line " + lineNo);
            }
            warningCount = 0;
            expectedWarnings = 0;
        }
    }
/*
        System.out.println("Output looks good...");
        oa.reportDiagnosticSummary();
        */
}

18 View Complete Implementation : TestDriver.java
Copyright GNU General Public License v2.0
Author : hzio
private List<String> executeApplication() throws Throwable {
    Outputreplacedyzer outputreplacedyzer = ProcessTools.executeTestJvm("-Xbatch", "-XX:-TieredCompilation", "-XX:+PrintCompilation", "-XX:+TraceNewVectors", TestIntVect.clreplaced.getName());
    outputreplacedyzer.shouldHaveExitValue(0);
    return outputreplacedyzer.asLines();
}

16 View Complete Implementation : CommandProcessor.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
@Override
public void accept(Outputreplacedyzer outputreplacedyzer) {
    try {
        outputreplacedyzer.asLines().stream().filter(s -> s.startsWith("CompileCommand:")).forEachOrdered(this::check);
    } catch (Exception e) {
        System.err.println(outputreplacedyzer.getOutput());
        throw e;
    }
}

16 View Complete Implementation : PrintDirectivesProcessor.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private List<String> getDirectives(Outputreplacedyzer outputreplacedyzer) {
    List<String> directives = new ArrayList<>();
    List<String> inputStrings = outputreplacedyzer.asLines();
    Iterator<String> iterator = inputStrings.iterator();
    while (iterator.hasNext()) {
        String input = iterator.next();
        if (input.equals("Directive:")) {
            replacederts.replacedertTrue(iterator.hasNext(), "inconsistent directive" + "printed into the output");
            String matchString = iterator.next();
            Matcher matcher = MATCH_PATTERN.matcher(matchString);
            replacederts.replacedertTrue(matcher.matches(), "Incorrect matching " + "string in directive");
            directives.add(matcher.group(1));
        }
    }
    return directives;
}

15 View Complete Implementation : PrintProcessor.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
@Override
public void accept(Outputreplacedyzer outputreplacedyzer) {
    boolean wizardMode = false;
    try {
        wizardMode = Boolean.parseBoolean(ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.clreplaced).getVMOption("WizardMode").getValue());
    } catch (IllegalArgumentException e) {
    // ignore exception because WizardMode exists in debug only builds
    }
    if (wizardMode) {
        System.out.println("SKIP: WizardMode's output are not supported");
        return;
    }
    for (String line : outputreplacedyzer.asLines()) {
        Matcher matcher = COMPILED_METHOD.matcher(line);
        if (matcher.matches()) {
            String method = normalize(matcher.group("name"));
            if (!printMethods.contains(normalize(method)) && testMethods.contains(method)) {
                System.out.println(outputreplacedyzer.getOutput());
                throw new replacedertionError("FAILED: wrong method " + "was printed: " + method + " LINE: " + line);
            }
        }
    }
}

15 View Complete Implementation : CompilerQueueTest.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void run(CommandExecutor executor) {
    TestCase[] testcases = { new TestCase(1, "testcaseMethod1"), new TestCase(2, "testcaseMethod2"), new TestCase(3, "testcaseMethod3"), new TestCase(4, "testcaseMethod4") };
    // Lock compilation makes all compiles stay in queue or compile thread before completion
    WB.lockCompilation();
    // Enqueue one test method for each available level
    int[] complevels = CompilerUtils.getAvailableCompilationLevels();
    for (int level : complevels) {
        TestCase testcase = testcases[level - 1];
        boolean added = WB.enqueueMethodForCompilation(testcase.method, testcase.level);
        // Set results to false for those methods we must to find
        // We will also replacedert if we find any test method we don't expect
        replacedert.replacedertEquals(added, WB.isMethodQueuedForCompilation(testcase.method));
        testcase.check = false;
    }
    // Get output from dcmd (diagnostic command)
    Outputreplacedyzer output = executor.execute("Compiler.queue");
    Iterator<String> lines = output.asLines().iterator();
    // Loop over output set result for all found methods
    while (lines.hasNext()) {
        String str = lines.next();
        // Fast check for common part of method name
        if (str.contains("testcaseMethod")) {
            for (TestCase testcase : testcases) {
                if (str.contains(testcase.methodName)) {
                    replacedert.replacedertFalse(testcase.check, "Must not be found or already found.");
                    testcase.check = true;
                }
            }
        }
    }
    for (TestCase testcase : testcases) {
        if (!testcase.check) {
            // If this method wasn't found it must have been removed by policy,
            // verify that it is now removed from the queue
            replacedert.replacedertFalse(WB.isMethodQueuedForCompilation(testcase.method), "Must be found or not in queue");
        }
    // Otherwise all good.
    }
    // Enable compilations again
    WB.unlockCompilation();
}

15 View Complete Implementation : ClassLoaderStatsTest.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void run(CommandExecutor executor) throws ClreplacedNotFoundException {
    // create a clreplacedloader and load our special clreplaced
    dummyloader = new DummyClreplacedLoader();
    Clreplaced<?> c = Clreplaced.forName("TestClreplaced", true, dummyloader);
    if (c.getClreplacedLoader() != dummyloader) {
        replacedert.fail("TestClreplaced defined by wrong clreplacedloader: " + c.getClreplacedLoader());
    }
    Outputreplacedyzer output = executor.execute("VM.clreplacedloader_stats");
    Iterator<String> lines = output.asLines().iterator();
    while (lines.hasNext()) {
        String line = lines.next();
        Matcher m = clLine.matcher(line);
        if (m.matches()) {
            // verify that DummyClreplacedLoader has loaded 1 clreplaced and 1 anonymous clreplaced
            if (m.group(4).equals("ClreplacedLoaderStatsTest$DummyClreplacedLoader")) {
                System.out.println("line: " + line);
                if (!m.group(1).equals("1")) {
                    replacedert.fail("Should have loaded 1 clreplaced: " + line);
                }
                checkPositiveInt(m.group(2));
                checkPositiveInt(m.group(3));
                String next = lines.next();
                System.out.println("next: " + next);
                Matcher m1 = anonLine.matcher(next);
                m1.matches();
                if (!m1.group(1).equals("1")) {
                    replacedert.fail("Should have loaded 1 anonymous clreplaced, but found : " + m1.group(1));
                }
                checkPositiveInt(m1.group(2));
                checkPositiveInt(m1.group(3));
            }
        }
    }
}

15 View Complete Implementation : TestInstanceKlassSizeForInterface.java
Copyright GNU General Public License v2.0
Author : netroby
private static void createAnotherToAttach(String[] instanceKlreplacedNames) throws Exception {
    ProcessBuilder pb = new ProcessBuilder();
    // Grab the pid from the current java process and preplaced it
    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", "TestInstanceKlreplacedSizeForInterface", Long.toString(ProcessTools.getProcessId()) };
    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), Long.toString(ProcessTools.getProcessId()), "GC.clreplaced_stats", "VTab,ITab,OopMap,KlreplacedBytes" });
    // Start a new process to attach to the current process
    ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(toolArgs);
    Outputreplacedyzer SAOutput = ProcessTools.executeProcess(processBuilder);
    System.out.println(SAOutput.getOutput());
    Outputreplacedyzer jcmdOutput = new Outputreplacedyzer(pb.start());
    System.out.println(jcmdOutput.getOutput());
    // Match the sizes from both the output streams
    for (String instanceKlreplacedName : instanceKlreplacedNames) {
        System.out.println("Trying to match for " + instanceKlreplacedName);
        String jcmdInstanceKlreplacedSize = getJcmdInstanceKlreplacedSize(jcmdOutput, instanceKlreplacedName);
        replacederts.replacedertNotNull(jcmdInstanceKlreplacedSize, "Could not get the instance klreplaced size from the jcmd output");
        for (String s : SAOutput.asLines()) {
            if (s.contains(instanceKlreplacedName)) {
                replacederts.replacedertTrue(s.contains(jcmdInstanceKlreplacedSize), "The size computed by SA for " + instanceKlreplacedName + " does not match.");
            }
        }
    }
}

14 View Complete Implementation : PrintTouchedMethods.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public static void main(String[] args) throws Exception {
    String[] javaArgs1 = { "-XX:-UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods" };
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs1);
    // UnlockDiagnostic turned off, should fail
    Outputreplacedyzer output = new Outputreplacedyzer(pb.start());
    output.shouldContain("Error: VM option 'LogTouchedMethods' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
    output.shouldContain("Error: Could not create the Java Virtual Machine.");
    String[] javaArgs2 = { "-XX:+UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods" };
    pb = ProcessTools.createJavaProcessBuilder(javaArgs2);
    output = new Outputreplacedyzer(pb.start());
    // check order:
    // 1 "# Method::print_touched_methods version 1" is the first in first line
    // 2 should contain TestLogMethods.methodA:()V
    // 3 should not contain TestLogMethods.methodB:()V
    // Repeat above for another run with -Xint
    List<String> lines = output.asLines();
    if (lines.size() < 1) {
        throw new Exception("Empty output");
    }
    String first = lines.get(0);
    if (!first.equals("# Method::print_touched_methods version 1")) {
        throw new Exception("First line mismatch");
    }
    output.shouldContain("TestLogTouchedMethods.methodA:()V");
    output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
    output.shouldHaveExitValue(0);
    String[] javaArgs3 = { "-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods" };
    pb = ProcessTools.createJavaProcessBuilder(javaArgs3);
    output = new Outputreplacedyzer(pb.start());
    lines = output.asLines();
    if (lines.size() < 1) {
        throw new Exception("Empty output");
    }
    first = lines.get(0);
    if (!first.equals("# Method::print_touched_methods version 1")) {
        throw new Exception("First line mismatch");
    }
    output.shouldContain("TestLogTouchedMethods.methodA:()V");
    output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
    output.shouldHaveExitValue(0);
    String[] javaArgs4 = { "-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "-XX:-TieredCompilation", "TestLogTouchedMethods" };
    pb = ProcessTools.createJavaProcessBuilder(javaArgs4);
    output = new Outputreplacedyzer(pb.start());
    lines = output.asLines();
    if (lines.size() < 1) {
        throw new Exception("Empty output");
    }
    first = lines.get(0);
    if (!first.equals("# Method::print_touched_methods version 1")) {
        throw new Exception("First line mismatch");
    }
    output.shouldContain("TestLogTouchedMethods.methodA:()V");
    output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
    output.shouldHaveExitValue(0);
    // Test jcmd PrintTouchedMethods VM.print_touched_methods
    String pid = Long.toString(ProcessTools.getProcessId());
    pb = new ProcessBuilder();
    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.print_touched_methods" });
    output = new Outputreplacedyzer(pb.start());
    try {
        output.shouldContain("PrintTouchedMethods.main:([Ljava/lang/String;)V");
    } catch (RuntimeException e) {
        output.shouldContain("Unknown diagnostic command");
    }
}

14 View Complete Implementation : CodeCacheTest.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void run(CommandExecutor executor) {
    // Get number of code cache segments
    int segmentsCount = 0;
    String flags = executor.execute("VM.flags -all").getOutput();
    if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
        // No segmentation
        segmentsCount = 1;
    } else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
        // Tiered compilation: use all segments
        segmentsCount = 3;
    } else {
        // No TieredCompilation: only non-nmethod and non-profiled segment
        segmentsCount = 2;
    }
    // Get output from dcmd (diagnostic command)
    Outputreplacedyzer output = executor.execute("Compiler.codecache");
    Iterator<String> lines = output.asLines().iterator();
    // Validate code cache segments
    String line;
    Matcher m;
    int matchedCount = 0;
    while (true) {
        // Validate first line
        line = lines.next();
        m = line1.matcher(line);
        if (m.matches()) {
            for (int i = 2; i <= 5; i++) {
                int val = Integer.parseInt(m.group(i));
                if (val < 0) {
                    replacedert.fail("Failed parsing dcmd codecache output");
                }
            }
        } else {
            break;
        }
        // Validate second line
        line = lines.next();
        m = line2.matcher(line);
        if (m.matches()) {
            String start = m.group(1);
            String mark = m.group(2);
            String top = m.group(3);
            // Lexical compare of hex numbers to check that they look sane.
            if (start.compareTo(mark) > 1) {
                replacedert.fail("Failed parsing dcmd codecache output");
            }
            if (mark.compareTo(top) > 1) {
                replacedert.fail("Failed parsing dcmd codecache output");
            }
        } else {
            replacedert.fail("Regexp 2 failed to match line: " + line);
        }
        ++matchedCount;
    }
    // Because of CodeCacheExtensions, we could match more than expected
    if (matchedCount < segmentsCount) {
        replacedert.fail("Fewer segments matched (" + matchedCount + ") than expected (" + segmentsCount + ")");
    }
    // Validate third line
    m = line3.matcher(line);
    if (m.matches()) {
        int blobs = Integer.parseInt(m.group(1));
        if (blobs <= 0) {
            replacedert.fail("Failed parsing dcmd codecache output");
        }
        int nmethods = Integer.parseInt(m.group(2));
        if (nmethods < 0) {
            replacedert.fail("Failed parsing dcmd codecache output");
        }
        int adapters = Integer.parseInt(m.group(3));
        if (adapters <= 0) {
            replacedert.fail("Failed parsing dcmd codecache output");
        }
        if (blobs < (nmethods + adapters)) {
            replacedert.fail("Failed parsing dcmd codecache output");
        }
    } else {
        replacedert.fail("Regexp 3 failed to match line: " + line);
    }
    // Validate fourth line
    line = lines.next();
    m = line4.matcher(line);
    if (!m.matches()) {
        replacedert.fail("Regexp 4 failed to match line: " + line);
    }
}

14 View Complete Implementation : TestInstanceKlassSizeForInterface.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private static void createAnotherToAttach(String[] instanceKlreplacedNames, int lingeredAppPid) throws Exception {
    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", "TestInstanceKlreplacedSizeForInterface", Integer.toString(lingeredAppPid) };
    // Start a new process to attach to the LingeredApp process
    ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(toolArgs);
    Outputreplacedyzer SAOutput = ProcessTools.executeProcess(processBuilder);
    SAOutput.shouldHaveExitValue(0);
    System.out.println(SAOutput.getOutput());
    // Run jcmd on the LingeredApp process
    ProcessBuilder pb = new ProcessBuilder();
    pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), Long.toString(lingeredAppPid), "GC.clreplaced_stats", "VTab,ITab,OopMap,KlreplacedBytes" });
    Outputreplacedyzer jcmdOutput = new Outputreplacedyzer(pb.start());
    System.out.println(jcmdOutput.getOutput());
    // Match the sizes from both the output streams
    for (String instanceKlreplacedName : instanceKlreplacedNames) {
        System.out.println("Trying to match for " + instanceKlreplacedName);
        String jcmdInstanceKlreplacedSize = getJcmdInstanceKlreplacedSize(jcmdOutput, instanceKlreplacedName);
        replacederts.replacedertNotNull(jcmdInstanceKlreplacedSize, "Could not get the instance klreplaced size from the jcmd output");
        for (String s : SAOutput.asLines()) {
            if (s.contains(instanceKlreplacedName)) {
                replacederts.replacedertTrue(s.contains(jcmdInstanceKlreplacedSize), "The size computed by SA for " + instanceKlreplacedName + " does not match.");
            }
        }
    }
}

13 View Complete Implementation : CodelistTest.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void run(CommandExecutor executor) {
    TestCase[] testcases = { new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE, "testcaseMethod1"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE, "testcaseMethod2"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE, "testcaseMethod3"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "testcaseMethod4") };
    String directive = "{ match: \"CodelistTest.testcaseMethod*\", " + "BackgroundCompilation: false }";
    replacedert.replacedertTrue(WB.addCompilerDirective(directive) == 1, "Must succeed");
    try {
        // Enqueue one test method for each available level
        int[] complevels = CompilerUtils.getAvailableCompilationLevels();
        for (int level : complevels) {
            // Only test comp level 1 and 4 - level 1, 2 and 3 may interfere with each other
            if (level == 1 || level == 4) {
                TestCase testcase = testcases[level - 1];
                WB.enqueueMethodForCompilation(testcase.method, testcase.level);
                // Set results to false for those methods we must to find
                // We will also replacedert if we find any test method we don't expect
                testcase.check = false;
            }
        }
    } finally {
        WB.removeCompilerDirective(1);
    }
    // Get output from dcmd (diagnostic command)
    Outputreplacedyzer output = executor.execute("Compiler.codelist");
    Iterator<String> lines = output.asLines().iterator();
    // Loop over output set result for all found methods
    while (lines.hasNext()) {
        String line = lines.next();
        // Fast check for common part of method name
        if (line.contains("CodelistTest.testcaseMethod")) {
            String[] parts = line.split(" ");
            int compileID = Integer.parseInt(parts[0]);
            int compileLevel = Integer.parseInt(parts[1]);
            String str = parts[2];
            for (TestCase testcase : testcases) {
                if (str.contains(testcase.methodName)) {
                    replacedert.replacedertFalse(testcase.check, "Must not be found or already found.");
                    replacedert.replacedertTrue(testcase.level == compileLevel, "Must have correct level");
                    testcase.check = true;
                }
            }
        }
    }
    // Check all testcases that was run
    for (TestCase testcase : testcases) {
        replacedert.replacedertTrue(testcase.check, "Missing testcase " + testcase.methodName);
    }
}

13 View Complete Implementation : CodelistTest.java
Copyright GNU General Public License v2.0
Author : hzio
public void run(CommandExecutor executor) {
    TestCase[] testcases = { new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE, "testcaseMethod1"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE, "testcaseMethod2"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE, "testcaseMethod3"), new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "testcaseMethod4") };
    String directive = "{ match: \"CodelistTest.testcaseMethod*\", " + "BackgroundCompilation: false }";
    replacedert.replacedertTrue(WB.addCompilerDirective(directive) == 1, "Must succeed");
    try {
        // Enqueue one test method for each available level
        int[] complevels = CompilerUtils.getAvailableCompilationLevels();
        for (int level : complevels) {
            // Only test comp level 1 and 4 - level 1, 2 and 3 may interfere with each other
            if (level == 1 || level == 4) {
                TestCase testcase = testcases[level - 1];
                WB.enqueueMethodForCompilation(testcase.method, testcase.level);
                // Set results to false for those methods we must to find
                // We will also replacedert if we find any test method we don't expect
                testcase.check = false;
            }
        }
    } finally {
        WB.removeCompilerDirective(1);
    }
    // Get output from dcmd (diagnostic command)
    Outputreplacedyzer output = executor.execute("Compiler.codelist");
    Iterator<String> lines = output.asLines().iterator();
    // Loop over output set result for all found methods
    while (lines.hasNext()) {
        String line = lines.next();
        // Fast check for common part of method name
        if (line.contains("CodelistTest.testcaseMethod")) {
            String[] parts = line.split(" ");
            int compileID = Integer.parseInt(parts[0]);
            replacedert.replacedertTrue(compileID > 0, "CompileID must be positive");
            int compileLevel = Integer.parseInt(parts[1]);
            replacedert.replacedertTrue(compileLevel >= -1, "CompileLevel must be at least -1 (AOT)");
            replacedert.replacedertTrue(compileLevel <= 4, "CompileLevel must be at most 4 (C2)");
            int codeState = Integer.parseInt(parts[2]);
            replacedert.replacedertTrue(codeState >= 0, "CodeState must be at least 0 (In Use)");
            replacedert.replacedertTrue(codeState <= 4, "CodeState must be at most 4 (Unloaded)");
            String str = parts[3];
            for (TestCase testcase : testcases) {
                if (str.contains(testcase.methodName)) {
                    replacedert.replacedertFalse(testcase.check, "Must not be found or already found.");
                    replacedert.replacedertTrue(testcase.level == compileLevel, "Must have correct level");
                    testcase.check = true;
                }
            }
        }
    }
    // Check all testcases that was run
    for (TestCase testcase : testcases) {
        replacedert.replacedertTrue(testcase.check, "Missing testcase " + testcase.methodName);
    }
}

8 View Complete Implementation : TestInstanceKlassSize.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private static void startMeWithArgs() throws Exception {
    LingeredApp app = null;
    Outputreplacedyzer 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[] instanceKlreplacedNames = 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", "TestInstanceKlreplacedSize", Long.toString(app.getPid()) };
        Outputreplacedyzer jcmdOutput = jcmd(app.getPid(), "GC.clreplaced_stats", "VTab,ITab,OopMap,KlreplacedBytes");
        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 instanceKlreplacedName : instanceKlreplacedNames) {
            System.out.println("Trying to match for" + instanceKlreplacedName);
            String jcmdInstanceKlreplacedSize = getJcmdInstanceKlreplacedSize(jcmdOutput, instanceKlreplacedName);
            replacederts.replacedertNotNull(jcmdInstanceKlreplacedSize, "Could not get the instance klreplaced size from the jcmd output");
            for (String s : output.asLines()) {
                if (s.contains(instanceKlreplacedName)) {
                    replacederts.replacedertTrue(s.contains(jcmdInstanceKlreplacedSize), "The size computed by SA for" + instanceKlreplacedName + " does not match.");
                }
            }
        }
    } finally {
        LingeredApp.stopApp(app);
    }
}