Search in sources :

Example 11 with OutputAnalyzer

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

the class TestJpsSanity method testJpsUsage.

private static void testJpsUsage() throws Exception {
    OutputAnalyzer output = JpsHelper.jps("-?");
    JpsHelper.verifyOutputAgainstFile(output);
    output = JpsHelper.jps("-help");
    JpsHelper.verifyOutputAgainstFile(output);
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 12 with OutputAnalyzer

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

the class TestJcmdSanity method testJcmdPidPerfCounterPrint.

/**
     * jcmd -J-XX:+UsePerfData pid PerfCounter.print
     */
private static void testJcmdPidPerfCounterPrint() throws Exception {
    OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS, new String[] { "PerfCounter.print" });
    output.shouldHaveExitValue(0);
    matchPerfCounters(output);
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 13 with OutputAnalyzer

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

the class RunUtil method runTest.

/**
     * Runs a test in a separate JVM.
     * command line like:
     * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
     *
     * {defaultopts} are the default java options set by the framework.
     * Default GC options in {defaultopts} may be removed.
     * This is used when the test specifies its own GC options.
     *
     * @param main Name of the main class.
     * @param clearGcOpts true if the default GC options should be removed.
     * @param testOpts java options specified by the test.
     */
private static void runTest(String main, boolean clearGcOpts, String... testOpts) throws Throwable {
    List<String> opts = new ArrayList<>();
    opts.add(JDKToolFinder.getJDKTool("java"));
    opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
    opts.add("-cp");
    opts.add(System.getProperty("test.class.path", "test.class.path"));
    opts.add("-XX:+PrintGCDetails");
    if (clearGcOpts) {
        opts = Utils.removeGcOpts(opts);
    }
    opts.addAll(Arrays.asList(testOpts));
    opts.add(main);
    OutputAnalyzer output = ProcessTools.executeProcess(opts.toArray(new String[0]));
    output.shouldHaveExitValue(0);
    if (output.getStdout().indexOf(successMessage) < 0) {
        throw new Exception("output missing '" + successMessage + "'");
    }
}
Also used : ArrayList(java.util.ArrayList) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 14 with OutputAnalyzer

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

the class RunnerUtil method stopApplication.

/**
     * Will stop the running Application.
     * First tries to shutdown nicely by connecting to the shut down port.
     * If that fails, the process will be killed hard with stopProcess().
     *
     * If the nice shutdown fails, then an Exception is thrown and the test should fail.
     *
     * @param port The shut down port.
     * @param processThread The process to stop.
     */
public static void stopApplication(int port, ProcessThread processThread) throws Throwable {
    if (processThread == null) {
        System.out.println("RunnerUtil.stopApplication ignored since proc is null");
        return;
    }
    try {
        System.out.println("RunnerUtil.stopApplication waiting to for shutdown");
        OutputAnalyzer output = ProcessTools.executeTestJvm("-classpath", System.getProperty("test.class.path", "."), "Shutdown", Integer.toString(port));
        // Verify that both the Shutdown command and the Application finished ok.
        output.shouldHaveExitValue(0);
        processThread.joinAndThrow();
        processThread.getOutput().shouldHaveExitValue(0);
    } catch (Throwable t) {
        System.out.println("RunnerUtil.stopApplication failed. Will kill it hard: " + t);
        processThread.stopProcess();
        throw t;
    }
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 15 with OutputAnalyzer

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

the class ChainNotValidatedTest method start.

private void start() throws Throwable {
    // create a jar file that contains one class file
    Utils.createFiles(FIRST_FILE);
    JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
    // create self-signed certificate whose BasicConstraints extension
    // is set to false, so the certificate may not be used
    // as a parent certificate (certpath validation should fail)
    ProcessTools.executeCommand(KEYTOOL, "-genkeypair", "-alias", CA_KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=CA", "-ext", "BasicConstraints:critical=ca:false", "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    // create a certificate that is signed by self-signed certificate
    // despite of it may not be used as a parent certificate
    // (certpath validation should fail)
    ProcessTools.executeCommand(KEYTOOL, "-genkeypair", "-alias", KEY_ALIAS, "-keyalg", KEY_ALG, "-keysize", Integer.toString(KEY_SIZE), "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-dname", "CN=Test", "-ext", "BasicConstraints:critical=ca:false", "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
    ProcessTools.executeCommand(KEYTOOL, "-certreq", "-alias", KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-file", CERT_REQUEST_FILENAME).shouldHaveExitValue(0);
    ProcessTools.executeCommand(KEYTOOL, "-gencert", "-alias", CA_KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-infile", CERT_REQUEST_FILENAME, "-validity", Integer.toString(VALIDITY), "-outfile", CERT_FILENAME).shouldHaveExitValue(0);
    ProcessTools.executeCommand(KEYTOOL, "-importcert", "-alias", KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-file", CERT_FILENAME).shouldHaveExitValue(0);
    ProcessBuilder pb = new ProcessBuilder(KEYTOOL, "-export", "-rfc", "-alias", KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD);
    pb.redirectOutput(ProcessBuilder.Redirect.appendTo(new File(CHAIN)));
    ProcessTools.executeCommand(pb).shouldHaveExitValue(0);
    pb = new ProcessBuilder(KEYTOOL, "-export", "-rfc", "-alias", CA_KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD);
    pb.redirectOutput(ProcessBuilder.Redirect.appendTo(new File(CHAIN)));
    ProcessTools.executeCommand(pb).shouldHaveExitValue(0);
    // remove CA certificate
    ProcessTools.executeCommand(KEYTOOL, "-delete", "-alias", CA_KEY_ALIAS, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD).shouldHaveExitValue(0);
    // sign jar
    OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER, "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-certchain", CHAIN, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, KEY_ALIAS);
    checkSigning(analyzer, CHAIN_NOT_VALIDATED_SIGNING_WARNING);
    // verify signed jar
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-certchain", CHAIN, SIGNED_JARFILE);
    checkVerifying(analyzer, 0, CHAIN_NOT_VALIDATED_VERIFYING_WARNING);
    // verify signed jar in strict mode
    analyzer = ProcessTools.executeCommand(JARSIGNER, "-verify", "-verbose", "-strict", "-keystore", KEYSTORE, "-storepass", PASSWORD, "-keypass", PASSWORD, "-certchain", CHAIN, SIGNED_JARFILE);
    checkVerifying(analyzer, CHAIN_NOT_VALIDATED_EXIT_CODE, CHAIN_NOT_VALIDATED_VERIFYING_WARNING);
    System.out.println("Test passed");
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer) File(java.io.File)

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