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