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.h4654;
19:
20: import java.io.File;
21: import java.io.InputStreamReader;
22: import java.io.BufferedReader;
23: import junit.framework.TestCase;
24:
25: /**
26: * Tests that VM doesn't crash in printStackTrace() for OOME.
27: * Runs VM in child process for the 'TestClass' and checks that it doesn't
28: * crash and returns zero exitValue.
29: * Child process for the test application is required because crash didn't
30: * reproduce in junit test (main class derived from junit.framework.TestCase).
31: */
32: public class Test extends TestCase {
33:
34: final static String testClass = "org.apache.harmony.drlvm.tests.regression.h4654.OOMEPrintStackTrace";
35:
36: public static void main(String[] args) {
37: (new Test()).test();
38: }
39:
40: public void test() {
41: ProcessBuilder pb = new ProcessBuilder(System
42: .getProperty("java.home")
43: + File.separator + "bin" + File.separator + "java",
44: "-XX:vm.assert_dialog=false", "-cp", System
45: .getProperty("java.class.path"), testClass);
46:
47: // merge stderr adn stdout for child VM process
48: pb.redirectErrorStream(true);
49:
50: System.out.println("Command line for child VM:");
51:
52: for (String arg : pb.command()) {
53: System.out.println(" " + arg);
54: }
55:
56: int exitValue = -1;
57:
58: try {
59: System.out.println("Launching child VM...");
60: Process p = pb.start();
61: System.out.println("Child VM started.");
62:
63: BufferedReader childOut = new BufferedReader(
64: new InputStreamReader(p.getInputStream()));
65:
66: BufferedReader childErr = new BufferedReader(
67: new InputStreamReader(p.getErrorStream()));
68:
69: String outLine;
70:
71: while (null != (outLine = childOut.readLine())) {
72: System.out.println("child-out> " + outLine);
73: }
74:
75: System.out
76: .println("Waiting for child VM process to finish...");
77:
78: exitValue = p.waitFor();
79: System.out.println("Child VM finished. Exit value = "
80: + exitValue);
81: } catch (Throwable exc) {
82: exc.printStackTrace();
83: }
84:
85: assertTrue(exitValue == 0);
86: }
87: }
|