test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
author fmatte
Fri, 04 Oct 2019 07:54:57 +0100
changeset 58460 13f29c43b6c7
parent 53635 247e5ca412f5
permissions -rw-r--r--
8216352: SA: ClhsdbLauncher should throw errors on Unrecognized commands Reviewed-by: cjplummer, sspitsyn
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;
53596
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
    36
import jtreg.SkippedException;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    37
47899
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
/**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    40
 * 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
    41
 * 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
    42
 * 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
    43
 */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    44
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    45
public class ClhsdbLauncher {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    46
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    47
    private Process toolProcess;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    48
    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
    49
48949
d2a860bc50a3 8175384: SA: clhsdb 'printall' throws ClassCastException while printing out the bytecodes
jgeorge
parents: 48160
diff changeset
    50
    public ClhsdbLauncher() {
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    51
        toolProcess = null;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    52
        needPrivileges = false;
47899
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
     *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    57
     * 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
    58
     * @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
    59
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    60
    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
    61
        throws IOException {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    62
        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
    63
        launcher.addToolArg("clhsdb");
48160
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    64
        if (lingeredAppPid != -1) {
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    65
            launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    66
            System.out.println("Starting clhsdb against " + lingeredAppPid);
599f67f3c6d6 8191658: SA: Testcases for attach, detach, reattach and Jhisto commands
sballal
parents: 47899
diff changeset
    67
        }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    68
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    69
        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
    70
        if (needPrivileges) {
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    71
            cmdStringList = SATestUtils.addPrivileges(cmdStringList);
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    72
        }
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
    73
        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
    74
        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
    75
        toolProcess = processBuilder.start();
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
    /**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
    79
     *
49896
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    80
     * 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
    81
     * @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
    82
     */
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    83
    private void loadCore(String coreFileName)
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    84
        throws IOException {
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    85
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    86
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    87
        launcher.addToolArg("clhsdb");
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    88
        launcher.addToolArg("--core=" + coreFileName);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    89
        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
    90
        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
    91
                           " and exe " + JDKToolFinder.getTestJDKTool("java"));
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    92
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    93
        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
    94
        processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    95
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
    96
        toolProcess = processBuilder.start();
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
    /**
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   100
     *
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   101
     * 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
   102
     * @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
   103
     * @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
   104
     *                         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
   105
     * @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
   106
     *                           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
   107
     * @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
   108
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   109
    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
   110
                          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
   111
                          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
   112
        throws IOException, InterruptedException {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   113
        String output;
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   114
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   115
        if (commands == null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   116
            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
   117
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   118
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   119
        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
   120
            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
   121
                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
   122
            }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   123
            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
   124
            out.flush();
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
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   127
        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
   128
        try {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   129
            toolProcess.waitFor();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   130
        } catch (InterruptedException ie) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   131
            toolProcess.destroyForcibly();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   132
            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
   133
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   134
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   135
        oa.shouldHaveExitValue(0);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   136
        output = oa.getOutput();
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   137
        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
   138
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   139
        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
   140
        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
   141
            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
   142
            OutputAnalyzer out = new OutputAnalyzer(parts[index]);
58460
13f29c43b6c7 8216352: SA: ClhsdbLauncher should throw errors on Unrecognized commands
fmatte
parents: 53635
diff changeset
   143
            out.shouldNotMatch("Unrecognized command.");
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   144
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   145
            if (expectedStrMap != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   146
                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
   147
                if (expectedStr != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   148
                    for (String exp : expectedStr) {
53635
247e5ca412f5 8215568: Refactor SA clhsdb tests to use ClhsdbLauncher
jgeorge
parents: 53596
diff changeset
   149
                        out.shouldMatch(exp);
47899
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
            }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   153
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   154
            if (unExpectedStrMap != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   155
                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
   156
                if (unExpectedStr != null) {
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   157
                    for (String unExp : unExpectedStr) {
53635
247e5ca412f5 8215568: Refactor SA clhsdb tests to use ClhsdbLauncher
jgeorge
parents: 53596
diff changeset
   158
                        out.shouldNotMatch(unExp);
47899
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
            }
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
        return output;
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
    /**
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   167
     *
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   168
     * 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
   169
     * 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
   170
     * @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
   171
     * @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
   172
     * @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
   173
     *                         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
   174
     * @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
   175
     *                           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
   176
     * @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
   177
     */
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   178
    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
   179
                      List<String> commands,
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   180
                      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
   181
                      Map<String, List<String>> unExpectedStrMap)
53596
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   182
        throws Exception {
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   183
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   184
        if (!Platform.shouldSAAttach()) {
53596
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   185
            if (Platform.isOSX() && SATestUtils.canAddPrivileges()) {
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   186
                needPrivileges = true;
53267
0b6d6db878b6 8215544: SA: Modify ClhsdbLauncher to add sudo privileges to enable MacOS tests on Mach5
jgeorge
parents: 49896
diff changeset
   187
            }
53596
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   188
            else {
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   189
               // Skip the test if we don't have enough permissions to attach
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   190
               // and cannot add privileges.
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   191
               throw new SkippedException(
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   192
                   "SA attach not expected to work. Insufficient privileges.");
bb40a5303c84 8217473: SA: Tests using ClhsdbLauncher fail on SAP docker containers
jgeorge
parents: 53267
diff changeset
   193
           }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   194
        }
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   195
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   196
        attach(lingeredAppPid);
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   197
        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
   198
    }
49896
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   199
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   200
    /**
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
     * 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
   203
     * 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
   204
     * @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
   205
     * @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
   206
     * @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
   207
     *                         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
   208
     * @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
   209
     *                           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
   210
     * @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
   211
     */
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   212
    public String runOnCore(String coreFileName,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   213
                            List<String> commands,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   214
                            Map<String, List<String>> expectedStrMap,
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   215
                            Map<String, List<String>> unExpectedStrMap)
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   216
        throws IOException, InterruptedException {
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   217
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   218
        loadCore(coreFileName);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   219
        return runCmd(commands, expectedStrMap, unExpectedStrMap);
ec2dd30adbc1 8174994: SA: clhsdb printmdo throws WrongTypeException when attached to a process with CDS
jgeorge
parents: 48949
diff changeset
   220
    }
47899
f113d1ef7bed 8190198: SA: Framework for writing 'jhsdb clhsdb' commands tests and testcases for some of the commands
sballal
parents:
diff changeset
   221
}