test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
author jgeorge
Mon, 14 Jan 2019 09:30:43 +0530
changeset 53267 0b6d6db878b6
parent 49896 ec2dd30adbc1
child 53596 bb40a5303c84
permissions -rw-r--r--
8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5 Summary: Check if 'sudo' privileges can be added for executing macOS tests, and if so, add these privileges before executing the tests Reviewed-by: jcbeyler, phh, sballal
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     1
/*
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     4
 *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     8
 *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    13
 * accompanied this code).
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    14
 *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    18
 *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    21
 * questions.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    22
 */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    23
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    24
import java.io.IOException;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    25
import java.io.OutputStream;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    26
import java.util.List;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    27
import java.util.Map;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    28
import java.util.Arrays;
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    29
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    30
import jdk.test.lib.apps.LingeredApp;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    31
import jdk.test.lib.Platform;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    32
import jdk.test.lib.JDKToolLauncher;
49896
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    33
import jdk.test.lib.JDKToolFinder;
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    34
import jdk.test.lib.process.OutputAnalyzer;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    35
import jdk.test.lib.SA.SATestUtils;
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    36
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    37
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    38
/**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    39
 * This is a framework to run 'jhsdb clhsdb' commands.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    40
 * See open/test/hotspot/jtreg/serviceability/sa/ClhsdbLongConstant.java for
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    41
 * an example of how to write a test.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    42
 */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    43
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    44
public class ClhsdbLauncher {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    45
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    46
    private Process toolProcess;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    47
    private boolean needPrivileges;
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    48
48949
d2a860bc50a3 8175384: SA: clhsdb 'printall' throws ClassCastException while printing out the bytecodes
jgeorge
parents: 48160
diff changeset
    49
    public ClhsdbLauncher() {
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    50
        toolProcess = null;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    51
        needPrivileges = false;
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    52
    }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    53
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    54
    /**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    55
     *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    56
     * Launches 'jhsdb clhsdb' and attaches to the Lingered App process.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    57
     * @param lingeredAppPid  - pid of the Lingered App or one its sub-classes.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    58
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    59
    private void attach(long lingeredAppPid)
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    60
        throws IOException {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    61
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    62
        launcher.addToolArg("clhsdb");
48160
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    63
        if (lingeredAppPid != -1) {
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    64
            launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    65
            System.out.println("Starting clhsdb against " + lingeredAppPid);
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    66
        }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    67
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    68
        List<String> cmdStringList = Arrays.asList(launcher.getCommand());
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    69
        if (needPrivileges) {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    70
            cmdStringList = SATestUtils.addPrivileges(cmdStringList);
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    71
        }
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    72
        ProcessBuilder processBuilder = new ProcessBuilder(cmdStringList);
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    73
        processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    74
        toolProcess = processBuilder.start();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    75
    }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    76
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    77
    /**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    78
     *
49896
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    79
     * Launches 'jhsdb clhsdb' and loads a core file.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    80
     * @param coreFileName - Name of the corefile to be loaded.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    81
     */
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    82
    private void loadCore(String coreFileName)
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    83
        throws IOException {
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    84
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    85
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    86
        launcher.addToolArg("clhsdb");
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    87
        launcher.addToolArg("--core=" + coreFileName);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    88
        launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    89
        System.out.println("Starting clhsdb against corefile " + coreFileName +
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    90
                           " and exe " + JDKToolFinder.getTestJDKTool("java"));
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    91
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    92
        ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    93
        processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    94
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    95
        toolProcess = processBuilder.start();
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    96
    }
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    97
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    98
    /**
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    99
     *
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   100
     * Runs 'jhsdb clhsdb' commands and checks for expected and unexpected strings.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   101
     * @param commands  - clhsdb commands to execute.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   102
     * @param expectedStrMap - Map of expected strings per command which need to
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   103
     *                         be checked in the output of the command.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   104
     * @param unExpectedStrMap - Map of unexpected strings per command which should
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   105
     *                           not be present in the output of the command.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   106
     * @return Output of the commands as a String.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   107
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   108
    private String runCmd(List<String> commands,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   109
                          Map<String, List<String>> expectedStrMap,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   110
                          Map<String, List<String>> unExpectedStrMap)
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   111
        throws IOException, InterruptedException {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   112
        String output;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   113
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   114
        if (commands == null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   115
            throw new RuntimeException("CLHSDB command must be provided\n");
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   116
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   117
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   118
        try (OutputStream out = toolProcess.getOutputStream()) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   119
            for (String cmd : commands) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   120
                out.write((cmd + "\n").getBytes());
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   121
            }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   122
            out.write("quit\n".getBytes());
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   123
            out.flush();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   124
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   125
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   126
        OutputAnalyzer oa = new OutputAnalyzer(toolProcess);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   127
        try {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   128
            toolProcess.waitFor();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   129
        } catch (InterruptedException ie) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   130
            toolProcess.destroyForcibly();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   131
            throw new Error("Problem awaiting the child process: " + ie);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   132
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   133
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   134
        oa.shouldHaveExitValue(0);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   135
        output = oa.getOutput();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   136
        System.out.println(output);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   137
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   138
        String[] parts = output.split("hsdb>");
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   139
        for (String cmd : commands) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   140
            int index = commands.indexOf(cmd) + 1;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   141
            OutputAnalyzer out = new OutputAnalyzer(parts[index]);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   142
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   143
            if (expectedStrMap != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   144
                List<String> expectedStr = expectedStrMap.get(cmd);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   145
                if (expectedStr != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   146
                    for (String exp : expectedStr) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   147
                        out.shouldContain(exp);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   148
                    }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   149
                }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   150
            }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   151
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   152
            if (unExpectedStrMap != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   153
                List<String> unExpectedStr = unExpectedStrMap.get(cmd);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   154
                if (unExpectedStr != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   155
                    for (String unExp : unExpectedStr) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   156
                        out.shouldNotContain(unExp);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   157
                    }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   158
                }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   159
            }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   160
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   161
        return output;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   162
    }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   163
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   164
    /**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   165
     *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   166
     * Launches 'jhsdb clhsdb', attaches to the Lingered App, executes the commands,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   167
     * checks for expected and unexpected strings.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   168
     * @param lingeredAppPid  - pid of the Lingered App or one its sub-classes.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   169
     * @param commands  - clhsdb commands to execute.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   170
     * @param expectedStrMap - Map of expected strings per command which need to
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   171
     *                         be checked in the output of the command.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   172
     * @param unExpectedStrMap - Map of unexpected strings per command which should
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   173
     *                           not be present in the output of the command.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   174
     * @return Output of the commands as a String.
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   175
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   176
    public String run(long lingeredAppPid,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   177
                      List<String> commands,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   178
                      Map<String, List<String>> expectedStrMap,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   179
                      Map<String, List<String>> unExpectedStrMap)
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   180
        throws IOException, InterruptedException {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   181
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   182
        if (!Platform.shouldSAAttach()) {
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   183
            if (Platform.isOSX()) {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   184
                if (!SATestUtils.canAddPrivileges()) {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   185
                   // Skip the test if we don't have enough permissions to attach
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   186
                   // and cannot add privileges.
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   187
                   System.out.println("SA attach not expected to work - test skipped.");
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   188
                   return null;
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   189
               } else {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   190
                   needPrivileges = true;
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   191
               }
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   192
            } else {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   193
                System.out.println("SA attach not expected to work. Insufficient privileges.");
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   194
                throw new Error("Cannot attach.");
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   195
            }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   196
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   197
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   198
        attach(lingeredAppPid);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   199
        return runCmd(commands, expectedStrMap, unExpectedStrMap);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   200
    }
49896
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   201
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   202
    /**
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   203
     *
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   204
     * Launches 'jhsdb clhsdb', loads a core file, executes the commands,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   205
     * checks for expected and unexpected strings.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   206
     * @param coreFileName - Name of the core file to be debugged.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   207
     * @param commands  - clhsdb commands to execute.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   208
     * @param expectedStrMap - Map of expected strings per command which need to
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   209
     *                         be checked in the output of the command.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   210
     * @param unExpectedStrMap - Map of unexpected strings per command which should
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   211
     *                           not be present in the output of the command.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   212
     * @return Output of the commands as a String.
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   213
     */
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   214
    public String runOnCore(String coreFileName,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   215
                            List<String> commands,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   216
                            Map<String, List<String>> expectedStrMap,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   217
                            Map<String, List<String>> unExpectedStrMap)
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   218
        throws IOException, InterruptedException {
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   219
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   220
        loadCore(coreFileName);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   221
        return runCmd(commands, expectedStrMap, unExpectedStrMap);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   222
    }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   223
}