jdk/test/sun/tools/jhsdb/BasicLauncherTest.java
author cjplummer
Thu, 29 Oct 2015 12:02:53 -0700
changeset 33832 7dde7a271492
parent 32217 56f5aebb508e
child 37314 341fa2e9011f
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32019
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     1
/*
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     4
 *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     8
 *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    14
 *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    18
 *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    21
 * questions.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    22
 */
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    23
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    24
/*
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    25
 * @test
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    26
 * @summary Basic test for jhsdb launcher
33832
7dde7a271492 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 32217
diff changeset
    27
 * @library /test/lib/share/classes
32019
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    28
 * @library /lib/testlibrary
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    29
 * @build jdk.testlibrary.*
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    30
 * @build jdk.test.lib.apps.*
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    31
 * @run main BasicLauncherTest
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    32
 */
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    33
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    34
import java.io.BufferedReader;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    35
import java.io.IOException;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    36
import java.io.InputStreamReader;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    37
import java.util.ArrayList;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    38
import java.util.List;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    39
import java.util.Arrays;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    40
import jdk.testlibrary.JDKToolLauncher;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    41
import jdk.testlibrary.Utils;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    42
import jdk.testlibrary.OutputAnalyzer;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    43
import jdk.testlibrary.ProcessTools;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    44
import jdk.test.lib.apps.LingeredApp;
32217
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
    45
import jdk.testlibrary.Platform;
32019
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    46
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    47
public class BasicLauncherTest {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    48
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    49
    private final static String toolName = "jhsdb";
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    50
    private static LingeredApp theApp = null;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    51
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    52
    /**
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    53
     *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    54
     * @return exit code of tool
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    55
     */
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    56
    public static int launchCLHSDB()
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    57
        throws IOException {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    58
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    59
        System.out.println("Starting LingeredApp");
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    60
        try {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    61
            theApp = LingeredApp.startApp();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    62
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    63
            System.out.println("Starting clhsdb against " + theApp.getPid());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    64
            JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    65
            launcher.addToolArg("clhsdb");
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    66
            launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    67
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    68
            ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    69
            processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    70
            Process toolProcess = processBuilder.start();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    71
            toolProcess.getOutputStream().write("quit\n".getBytes());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    72
            toolProcess.getOutputStream().close();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    73
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    74
            // By default child process output stream redirected to pipe, so we are reading it in foreground.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    75
            BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    76
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    77
            String line;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    78
            while ((line = reader.readLine()) != null) {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    79
                System.out.println(line.trim());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    80
            }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    81
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    82
            toolProcess.waitFor();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    83
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    84
            return toolProcess.exitValue();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    85
        } catch (Exception ex) {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    86
            throw new RuntimeException("Test ERROR " + ex, ex);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    87
        } finally {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    88
            LingeredApp.stopApp(theApp);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    89
        }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    90
    }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    91
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    92
    /**
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    93
     *
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    94
     * @param vmArgs  - vm and java arguments to launch test app
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    95
     * @return exit code of tool
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    96
     */
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    97
    public static void launch(String expectedMessage, List<String> toolArgs)
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    98
        throws IOException {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
    99
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   100
        System.out.println("Starting LingeredApp");
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   101
        try {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   102
            theApp = LingeredApp.startApp();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   103
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   104
            System.out.println("Starting " + toolName + " " + toolArgs.get(0) + " against " + theApp.getPid());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   105
            JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   106
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   107
            for (String cmd : toolArgs) {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   108
                launcher.addToolArg(cmd);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   109
            }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   110
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   111
            launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   112
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   113
            ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   114
            processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   115
            OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);;
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   116
            output.shouldContain(expectedMessage);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   117
            output.shouldHaveExitValue(0);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   118
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   119
        } catch (Exception ex) {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   120
            throw new RuntimeException("Test ERROR " + ex, ex);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   121
        } finally {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   122
            LingeredApp.stopApp(theApp);
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   123
        }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   124
    }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   125
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   126
    public static void launch(String expectedMessage, String... toolArgs)
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   127
        throws IOException {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   128
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   129
        launch(expectedMessage, Arrays.asList(toolArgs));
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   130
    }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   131
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   132
    public static void main(String[] args)
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   133
        throws IOException {
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   134
32217
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   135
        if (!Platform.shouldSAAttach()) {
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   136
            // Silently skip the test if we don't have enough permissions to attach
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   137
            System.err.println("Error! Insufficient permissions to attach.");
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   138
            return;
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   139
        }
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   140
32019
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   141
        launchCLHSDB();
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   142
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   143
        launch("No deadlocks found", "jstack");
32217
56f5aebb508e 8132648: sun/tools/jhsdb/BasicLauncherTest fails with java.lang.RuntimeException
dsamersoff
parents: 32019
diff changeset
   144
        launch("compiler detected", "jmap");
32019
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   145
        launch("Java System Properties", "jinfo");
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   146
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   147
        // The test throws RuntimeException on error.
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   148
        // IOException is thrown if LingeredApp can't start because of some bad
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   149
        // environment condition
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   150
        System.out.println("Test PASSED");
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   151
    }
6e305dc99cc8 8059038: Create new launcher for SA tools
dsamersoff
parents:
diff changeset
   152
}