01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h4706;
19:
20: import java.io.File;
21: import java.io.InputStreamReader;
22: import java.io.BufferedReader;
23: import junit.framework.TestCase;
24:
25: /**
26: * Runs VM in child process for the 'TestClass' and checks that it doesn't
27: * crash and returns zero exitValue.
28: * Child process for the test application is required because the crash doesn't
29: * reproduce in junit test.
30: */
31: public class Test extends TestCase {
32:
33: final static String testClass = "org.apache.harmony.drlvm.tests.regression.h4706.ThreadArrayInterrupt";
34:
35: public static void main(String[] args) {
36: (new Test()).test();
37: }
38:
39: public void test() {
40: ProcessBuilder pb = new ProcessBuilder(System
41: .getProperty("java.home")
42: + File.separator + "bin" + File.separator + "java",
43: "-XX:vm.assert_dialog=false", "-cp", System
44: .getProperty("java.class.path"), testClass);
45:
46: // merge stderr adn stdout for child VM process
47: pb.redirectErrorStream(true);
48:
49: System.out.println("Command line for child VM:");
50:
51: for (String arg : pb.command()) {
52: System.out.println(" " + arg);
53: }
54:
55: int exitValue = -1;
56:
57: try {
58: System.out.println("Launching child VM...");
59: Process p = pb.start();
60: System.out.println("Child VM started.");
61:
62: BufferedReader childOut = new BufferedReader(
63: new InputStreamReader(p.getInputStream()));
64:
65: BufferedReader childErr = new BufferedReader(
66: new InputStreamReader(p.getErrorStream()));
67:
68: String outLine;
69:
70: while (null != (outLine = childOut.readLine())) {
71: System.out.println("child-out> " + outLine);
72: }
73:
74: System.out
75: .println("Waiting for child VM process to finish...");
76:
77: exitValue = p.waitFor();
78: System.out.println("Child VM finished. Exit value = "
79: + exitValue);
80: } catch (Throwable exc) {
81: exc.printStackTrace();
82: }
83:
84: assertTrue(exitValue == 0);
85: }
86: }
|