jdk/test/demo/jvmti/DemoRun.java
author duke
Wed, 05 Jul 2017 22:06:37 +0200
changeset 40471 ad45133ff99e
parent 31814 b8431927ad72
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31813
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     1
/*
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     2
 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     4
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     7
 * published by the Free Software Foundation.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     8
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    13
 * accompanied this code).
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    14
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    18
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    21
 * questions.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    22
 */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    23
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    24
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    25
/* DemoRun:
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    26
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    27
 * Support classes for java jvmti demo tests
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    28
 *
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    29
 */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    30
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    31
import java.io.InputStream;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    32
import java.io.IOException;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    33
import java.io.File;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    34
import java.io.BufferedInputStream;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    35
import java.io.PrintStream;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    36
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    37
/*
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    38
 * Helper class to direct process output to a StringBuffer
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    39
 */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    40
class MyInputStream implements Runnable {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    41
    private String              name;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    42
    private BufferedInputStream in;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    43
    private StringBuffer        buffer;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    44
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    45
    /* Create MyInputStream that saves all output to a StringBuffer */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    46
    MyInputStream(String name, InputStream in) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    47
        this.name = name;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    48
        this.in = new BufferedInputStream(in);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    49
        buffer = new StringBuffer(4096);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    50
        Thread thr = new Thread(this);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    51
        thr.setDaemon(true);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    52
        thr.start();
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    53
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    54
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    55
    /* Dump the buffer */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    56
    void dump(PrintStream x) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    57
        String str = buffer.toString();
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    58
        x.println("<beginning of " + name + " buffer>");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    59
        x.println(str);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    60
        x.println("<end of buffer>");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    61
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    62
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    63
    /* Check to see if a pattern is inside the output. */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    64
    boolean contains(String pattern) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    65
        String str = buffer.toString();
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    66
        return str.contains(pattern);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    67
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    68
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    69
    /* Runs as a separate thread capturing all output in a StringBuffer */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    70
    public void run() {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    71
        try {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    72
            byte b[] = new byte[100];
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    73
            for (;;) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    74
                int n = in.read(b);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    75
                String str;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    76
                if (n < 0) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    77
                    break;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    78
                }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    79
                str = new String(b, 0, n);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    80
                buffer.append(str);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    81
                System.out.print(str);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    82
            }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    83
        } catch (IOException ioe) { /* skip */ }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    84
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    85
}
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    86
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    87
/*
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    88
 * Main JVMTI Demo Run class.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    89
 */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    90
public class DemoRun {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    91
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    92
    private String        demo_name;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    93
    private String        demo_options;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    94
    private MyInputStream output;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    95
    private MyInputStream error;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    96
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    97
    /* Create a Demo run process */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    98
    public DemoRun(String name, String options)
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
    99
    {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   100
        demo_name    = name;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   101
        demo_options = options;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   102
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   103
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   104
    /*
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   105
     * Execute a process with an -agentpath or -agentlib command option
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   106
     */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   107
    public void runit(String class_name)
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   108
    {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   109
        runit(class_name, null);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   110
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   111
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   112
    /*
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   113
     * Execute a process with an -agentpath or -agentlib command option
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   114
     *    plus any set of other java options.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   115
     */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   116
    public void runit(String class_name, String vm_options[])
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   117
    {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   118
        String sdk_home  = System.getProperty("java.home");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   119
        String cdir      = System.getProperty("test.classes", ".");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   120
        String os_arch   = System.getProperty("os.arch");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   121
        String os_name   = System.getProperty("os.name");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   122
        String libprefix = os_name.contains("Windows")?"":"lib";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   123
        String libsuffix = os_name.contains("Windows")?".dll":
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   124
                                os_name.contains("OS X")?".dylib":".so";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   125
        String java      = sdk_home
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   126
                             + File.separator + "bin"
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   127
                             + File.separator + "java";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   128
        /* Array of strings to be passed in for exec:
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   129
         *   1. java
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   130
         *   2. -Dtest.classes=.
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   131
         *   3. -Xcheck:jni          (Just because it finds bugs)
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   132
         *   4. -Xverify:all         (Make sure verification is on full blast)
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   133
         *   5. -agent
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   134
         *       vm_options
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   135
         *   6+i. classname
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   136
         */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   137
        int nvm_options = 0;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   138
        if ( vm_options != null ) nvm_options = vm_options.length;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   139
        String cmd[]     = new String[1 + 7 + nvm_options];
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   140
        String cmdLine;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   141
        int exitStatus;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   142
        int i,j;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   143
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   144
        i = 0;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   145
        cmdLine = "";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   146
        cmdLine += (cmd[i++] = java);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   147
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   148
        cmdLine += (cmd[i++] = "-cp");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   149
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   150
        cmdLine += (cmd[i++] = cdir);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   151
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   152
        cmdLine += (cmd[i++] = "-Dtest.classes=" + cdir);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   153
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   154
        cmdLine += (cmd[i++] = "-Xcheck:jni");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   155
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   156
        cmdLine += (cmd[i++] = "-Xverify:all");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   157
        String libname = sdk_home
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   158
                + File.separator + "demo"
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   159
                + File.separator + "jvmti"
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   160
                + File.separator + demo_name
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   161
                + File.separator + "lib"
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   162
                + File.separator + libprefix + demo_name + libsuffix;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   163
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   164
        cmdLine += (cmd[i++] = "-agentpath:" + libname
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   165
                + (demo_options.equals("") ? "" : ("=" + demo_options)));
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   166
        /* Add any special VM options */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   167
        for ( j = 0; j < nvm_options; j++ ) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   168
            cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   169
            cmdLine += (cmd[i++] = vm_options[j]);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   170
        }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   171
        /* Add classname */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   172
        cmdLine += " ";
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   173
        cmdLine += (cmd[i++] = class_name);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   174
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   175
        /* Begin process */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   176
        Process p;
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   177
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   178
        System.out.println("Starting: " + cmdLine);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   179
        try {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   180
            p = Runtime.getRuntime().exec(cmd);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   181
        } catch ( IOException e ) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   182
            throw new RuntimeException("Test failed - exec got IO exception");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   183
        }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   184
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   185
        /* Save process output in StringBuffers */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   186
        output = new MyInputStream("Input Stream", p.getInputStream());
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   187
        error  = new MyInputStream("Error Stream", p.getErrorStream());
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   188
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   189
        /* Wait for process to complete, and if exit code is non-zero we fail */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   190
        try {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   191
            exitStatus = p.waitFor();
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   192
            if ( exitStatus != 0) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   193
                System.out.println("Exit code is " + exitStatus);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   194
                error.dump(System.out);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   195
                output.dump(System.out);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   196
                throw new RuntimeException("Test failed - " +
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   197
                                    "exit return code non-zero " +
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   198
                                    "(exitStatus==" + exitStatus + ")");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   199
            }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   200
        } catch ( InterruptedException e ) {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   201
            throw new RuntimeException("Test failed - process interrupted");
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   202
        }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   203
        System.out.println("Completed: " + cmdLine);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   204
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   205
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   206
    /* Does the pattern appear in the output of this process */
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   207
    public boolean output_contains(String pattern)
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   208
    {
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   209
        return output.contains(pattern) || error.contains(pattern);
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   210
    }
977744526c8d 8131328: Restore demo/jvmti tests
ykantser
parents:
diff changeset
   211
}