test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java
author dtitov
Mon, 08 Apr 2019 17:09:02 +0000
changeset 54460 6733a9176cce
parent 53707 67537bbafd7f
permissions -rw-r--r--
8221730: jcmd process name matching broken Reviewed-by: jcbeyler, dholmes, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53707
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     1
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     2
/*
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     3
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     5
 *
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     8
 * published by the Free Software Foundation.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
     9
 *
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    14
 * accompanied this code).
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    15
 *
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    19
 *
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    22
 * questions.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    23
 */
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    24
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    25
import nsk.share.*;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    26
import nsk.share.jpda.*;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    27
import nsk.share.jdi.*;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    28
54460
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    29
import java.nio.file.FileSystems;
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    30
import java.nio.file.Path;
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    31
53707
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    32
/**
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    33
 * Launches a new Java process that uses a communication pipe to interact
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    34
 * with the test.
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    35
 */
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    36
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    37
public class TestProcessLauncher {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    38
54460
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    39
    protected static final Path USER_DIR = FileSystems.getDefault().getPath(System.getProperty("user.dir", "."));
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    40
    protected static final Path TEST_CLASSES_DIR = FileSystems.getDefault().getPath(System.getProperty("test.classes"));
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    41
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    42
    protected final String className;
53707
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    43
    private final ArgumentHandler argHandler;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    44
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    45
    private IOPipe pipe;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    46
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    47
    public TestProcessLauncher(String className, ArgumentHandler argHandler) {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    48
        this.className = className;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    49
        this.argHandler = argHandler;
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    50
    }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    51
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    52
    public TestProcessLauncher(String className) {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    53
        this(className, new ArgumentHandler(new String[0]));
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    54
    }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    55
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    56
    public Process launch() {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    57
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    58
        String java = argHandler.getLaunchExecPath();
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    59
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    60
        Log log = new Log(System.out, argHandler);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    61
        Binder binder = new Binder(argHandler, log);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    62
        binder.prepareForPipeConnection(argHandler);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    63
54460
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    64
        String cmd = prepareLaunch(java, argHandler.getPipePort());
53707
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    65
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    66
        Debugee debuggee = binder.startLocalDebugee(cmd);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    67
        debuggee.redirectOutput(log);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    68
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    69
        pipe = new IOPipe(debuggee);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    70
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    71
        String line = pipe.readln();
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    72
        if (!"ready".equals(line)) {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    73
            System.out.println("Wrong reply received:" + line);
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    74
        }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    75
        return debuggee.getProcess();
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    76
    }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    77
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    78
    public void quit() {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    79
        if (pipe != null) {
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    80
            pipe.println("quit");
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    81
        }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    82
    }
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    83
54460
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    84
    protected String prepareLaunch(String javaExec, String pipePort) {
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    85
        return  javaExec + " " + className + " -pipe.port=" + pipePort;
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    86
    }
6733a9176cce 8221730: jcmd process name matching broken
dtitov
parents: 53707
diff changeset
    87
53707
67537bbafd7f 8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff changeset
    88
}