Search in sources :

Example 1 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class DynamicLauncher method run.

protected void run() throws Exception {
    OutputAnalyzer out;
    int retries = 1;
    boolean tryAgain;
    do {
        tryAgain = false;
        jmxPort = Utils.getFreePort();
        out = runVM();
        try {
            out.shouldNotContain("Port already in use");
        } catch (RuntimeException e) {
            if (retries < 3) {
                retries++;
                tryAgain = true;
            }
        }
    } while (tryAgain);
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 2 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class NativeErrors method executeCmd.

private static String executeCmd(String... toolArgs) throws Throwable {
    JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
    for (String s : toolArgs) {
        cmd.addToolArg(s);
    }
    OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
    if (output == null || output.getStdout() == null) {
        throw new Exception("Output was null. Process did not finish correctly.");
    }
    if (output.getExitValue() == 0) {
        throw new Exception("Process exit code was 0, but error was expected.");
    }
    return output.getStdout();
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer) MissingResourceException(java.util.MissingResourceException)

Example 3 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class JpsBase method main.

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:
                    // 30673 JpsBase monkey ...
                    for (String arg : args) {
                        pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
                        output.shouldMatch(pattern);
                    }
                    break;
                case v:
                    // 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);
            }
        }
    }
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer) List(java.util.List)

Example 4 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class JpsHelper method jps.

/**
     * Start jps utility with VM args and tool arguments
     */
public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
    if (vmArgs != null) {
        for (String vmArg : vmArgs) {
            launcher.addVMArg(vmArg);
        }
    }
    if (toolArgs != null) {
        for (String toolArg : toolArgs) {
            launcher.addToolArg(toolArg);
        }
    }
    ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
    System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    System.out.println(output.getOutput());
    return output;
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 5 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class JstatdTest method runJps.

/**
     * Depending on test settings command line can look like:
     *
     * jps -J-XX:+UsePerfData hostname
     * jps -J-XX:+UsePerfData hostname:port
     * jps -J-XX:+UsePerfData hostname/serverName
     * jps -J-XX:+UsePerfData hostname:port/serverName
     */
private OutputAnalyzer runJps() throws Exception {
    JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
    launcher.addVMArg("-XX:+UsePerfData");
    // Run jps with -v flag to obtain -Dparent.pid.<pid>
    launcher.addToolArg("-v");
    launcher.addToolArg(getDestination());
    String[] cmd = launcher.getCommand();
    log("Start jps", cmd);
    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    OutputAnalyzer output = new OutputAnalyzer(processBuilder.start());
    System.out.println(output.getOutput());
    return output;
}
Also used : JDKToolLauncher(jdk.testlibrary.JDKToolLauncher) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Aggregations

OutputAnalyzer (jdk.testlibrary.OutputAnalyzer)54 File (java.io.File)5 JDKToolLauncher (jdk.testlibrary.JDKToolLauncher)5 ArrayList (java.util.ArrayList)4 PortUnreachableException (java.net.PortUnreachableException)1 LocateRegistry (java.rmi.registry.LocateRegistry)1 Registry (java.rmi.registry.Registry)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 ProcessThread (jdk.testlibrary.ProcessThread)1