Java Code Examples for jdk.testlibrary.OutputAnalyzer#shouldContain()

The following examples show how to use jdk.testlibrary.OutputAnalyzer#shouldContain() . 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: TestSummary.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
    String file = f.toAbsolutePath().toString();

    OutputAnalyzer output = ExecuteHelper.run("summary");
    output.shouldContain("Missing file");

    output = ExecuteHelper.run("summary", "--wrongOption", file);
    output.shouldContain("Too many arguments");

    output = ExecuteHelper.run("summary", file);
    try (RecordingFile rf = new RecordingFile(f)) {
        for (EventType t : rf.readEventTypes()) {
            output.shouldContain(t.getName());
        }
    }
    output.shouldContain("Version");
}
 
Example 2
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void checkVerifying(OutputAnalyzer analyzer, int expectedExitCode,
        String... warnings) {
    analyzer.shouldHaveExitValue(expectedExitCode);
    int count = 0;
    for (String warning : warnings) {
        if (warning.startsWith("!")) {
            analyzer.shouldNotContain(warning.substring(1));
        } else {
            count++;
            analyzer.shouldContain(warning);
        }
    }
    if (count > 0) {
        analyzer.shouldMatch(WARNING_OR_ERROR);
    }
    if (expectedExitCode == 0) {
        analyzer.shouldContain(JAR_VERIFIED);
    } else {
        analyzer.shouldContain(JAR_VERIFIED_WITH_SIGNER_ERRORS);
    }
}
 
Example 3
Source File: KinitConfPlusProps.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean checkTicketFlags() {
    String[] command = new String[] {KLIST, "-f", "-c", CC_FILENAME};

    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(0);
        out.shouldContain("FORWARDABLE");
        out.shouldContain("PROXIABLE");
    } catch(Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        return false;
    }

    return true;
}
 
Example 4
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void checkVerifying(OutputAnalyzer analyzer, int expectedExitCode,
        String... warnings) {
    analyzer.shouldHaveExitValue(expectedExitCode);
    for (String warning : warnings) {
        analyzer.shouldContain(warning);
    }
    if (warnings.length > 0) {
        analyzer.shouldContain(WARNING);
    }
    if (expectedExitCode == 0) {
        analyzer.shouldContain(JAR_VERIFIED);
    } else {
        analyzer.shouldContain(JAR_VERIFIED_WITH_SIGNER_ERRORS);
    }
}
 
Example 5
Source File: TestJcmdSanity.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that it possible send a file over 1024 bytes large via jcmd -f.
 *
 * jcmd -J-XX:+UsePerfData pid -f dcmd-big-script.txt
 */
private static void testJcmdPidBigScript() throws Exception {
    File scrpitFile = new File(TEST_SRC, "dcmd-big-script.txt");
    OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS,
            new String[] {"-f", scrpitFile.getAbsolutePath()});

    output.shouldHaveExitValue(0);
    output.shouldNotContain("Exception");
    output.shouldContain(System.getProperty("java.vm.name").trim());
}
 
Example 6
Source File: PortAlreadyInUseTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void go() throws Exception {
    jmxPort = Utils.getFreePort();
    occupyPort();

    log.info("Attempting to start a VM using the same port.");
    OutputAnalyzer out = this.runVM();
    out.shouldContain("Port already in use");
    log.info("Failed as expected.");

    log.info("Trying again using retries.");
    this.run();
}
 
Example 7
Source File: TestJstatdUsage.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testUsage(String option) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
    launcher.addToolArg(option);
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());

    output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]");
    output.shouldHaveExitValue(1);
}
 
Example 8
Source File: TestJstatdUsage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testUsage(String option) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
    launcher.addToolArg(option);
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());

    output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]");
    output.shouldHaveExitValue(1);
}
 
Example 9
Source File: PortAlreadyInUseTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void go() throws Exception {
    jmxPort = Utils.getFreePort();
    occupyPort();

    log.info("Attempting to start a VM using the same port.");
    OutputAnalyzer out = this.runVM();
    out.shouldContain("Port already in use");
    log.info("Failed as expected.");

    log.info("Trying again using retries.");
    this.run();
}
 
Example 10
Source File: DeadlockDetectionTest.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 {
    System.out.println("Starting DeadlockDetectionTest");

    if (!Platform.shouldSAAttach()) {
        // Silently skip the test if we don't have enough permissions to attach
        System.err.println("Error! Insufficient permissions to attach.");
        return;
    }

    if (!LingeredApp.isLastModifiedWorking()) {
        // Exact behaviour of the test depends on operating system and the test nature,
        // so just print the warning and continue
        System.err.println("Warning! Last modified time doesn't work.");
    }

    try {
        List<String> vmArgs = new ArrayList<String>();
        vmArgs.add("-XX:+UsePerfData");
        vmArgs.addAll(Utils.getVmOptions());

        theApp = new LingeredAppWithDeadlock();
        LingeredApp.startApp(vmArgs, theApp);
        OutputAnalyzer output = jstack(Long.toString(theApp.getPid()));
        System.out.println(output.getOutput());

        if (output.getExitValue() == 3) {
            System.out.println("Test can't run for some reason. Skipping");
        }
        else {
            output.shouldHaveExitValue(0);
            output.shouldContain("Found 1 deadlock.");
        }

    } finally {
        LingeredApp.stopApp(theApp);
    }
}
 
Example 11
Source File: TestJstatdUsage.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testUsage(String option) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
    launcher.addToolArg(option);
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());

    output.shouldContain("usage: jstatd [-nr] [-p port] [-n rminame]");
    output.shouldHaveExitValue(1);
}
 
Example 12
Source File: KeytoolWriteP12Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void keytoolListTest(String keyStore, Algorithm algorithm,
        String ...optionalArgs) {
    final String keyStoreName = WORKING_DIRECTORY + File.separator
            + keyStore;
    final String[] command = new String[]{"-debug", "-list", "-v", "-alias",
        ALIAS, "-keystore", keyStoreName, "-storetype", "pkcs12",
        "-storepass", Utils.DEFAULT_PASSWD};
    deleteKeyStoreFile(keyStoreName);
    Utils.createKeyStore(DNAME, PKCS12, keyStoreName, ALIAS,
            algorithm.name(), optionalArgs);
    OutputAnalyzer output = Utils.executeKeytoolCommand(command);
    output.shouldContain(DNAME);
}
 
Example 13
Source File: BasicJInfoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJinfoNoArgs() throws Exception {
    OutputAnalyzer output = jinfo();
    output.shouldContain("-XX");
    output.shouldContain("test.jdk=");
    output.shouldHaveExitValue(0);
}
 
Example 14
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertDurationAtLeast1s(OutputAnalyzer output) {
    output.shouldContain("Could not start recording, duration must be at least 1 second.");
}
 
Example 15
Source File: BasicJInfoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJinfoProps() throws Exception {
    OutputAnalyzer output = jinfo("-props");
    output.shouldContain("test.jdk=");
    output.shouldHaveExitValue(0);
}
 
Example 16
Source File: JpsBase.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 {
    int pid = ProcessTools.getProcessId();

    List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
    for (List<JpsHelper.JpsArg> combination : combinations) {
        OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
        output.shouldHaveExitValue(0);

        boolean isQuiet = false;
        boolean isFull = false;
        String pattern;
        for (JpsHelper.JpsArg jpsArg : combination) {
            switch (jpsArg) {
            case q:
                // If '-q' is specified output should contain only a list of local VM identifiers:
                // 30673
                isQuiet = true;
                JpsHelper.verifyJpsOutput(output, "^\\d+$");
                output.shouldContain(Integer.toString(pid));
                break;
            case l:
                // If '-l' is specified output should contain the full package name for the application's main class
                // or the full path name to the application's JAR file:
                // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                isFull = true;
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                output.shouldMatch(pattern);
                break;
            case m:
                // If '-m' is specified output should contain the arguments passed to the main method:
                // 30673 JpsBase monkey ...
                for (String arg : args) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case v:
                // If '-v' is specified output should contain VM arguments:
                // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
                for (String vmArg : JpsHelper.getVmArgs()) {
                    pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
                    output.shouldMatch(pattern);
                }
                break;
            case V:
                // If '-V' is specified output should contain VM flags:
                // 30673 JpsBase +DisableExplicitGC ...
                pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
                output.shouldMatch(pattern);
                break;
            }

            if (isQuiet) {
                break;
            }
        }

        if (!isQuiet) {
            // Verify output line by line.
            // Output should only contain lines with pids after the first line with pid.
            JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
            if (!isFull) {
                pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                if (combination.isEmpty()) {
                    // If no arguments are specified output should only contain
                    // pid and process name
                    pattern += "$";
                } else {
                    pattern += ".*";
                }
                output.shouldMatch(pattern);
            }
        }
    }
}
 
Example 17
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertDelayAtLeast1s(OutputAnalyzer output) {
    output.shouldContain("Could not start recording, delay must be at least 1 second.");
}
 
Example 18
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertCommercialLocked(OutputAnalyzer output) {
    output.shouldContain("Flight Recorder not enabled");
    output.shouldContain("Use VM.unlock_commercial_features to enable");
}
 
Example 19
Source File: JcmdAsserts.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertNotAbleToWriteToFile(OutputAnalyzer output) {
    output.shouldContain("Could not start recording, not able to write to file");
}
 
Example 20
Source File: TestJpsSanity.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testJpsVersion() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-version");
    Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
    Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
    output.shouldContain("illegal argument: -version");
}