1 /* 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. 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 * 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. 22 */ 23 24 /** 25 * @test 26 * @bug 4500906 4433599 4740097 27 * @summary vmexec= debug java fails for SunCommandLineLauncher 28 * 29 * @author jjh 30 * 31 * @modules jdk.jdi 32 * @run build TestScaffold VMConnection TargetListener TargetAdapter 33 * @run compile -g Java_gTest.java 34 * @run driver Java_gTest 35 */ 36 import com.sun.jdi.*; 37 import com.sun.jdi.event.*; 38 import com.sun.jdi.request.*; 39 40 import java.util.*; 41 import java.io.File; 42 43 /********** target program **********/ 44 45 class Java_gTarg { 46 public static void main(String[] args){ 47 System.out.println("Howdy!"); 48 System.out.println("Goodbye from Java_gTarg!"); 49 } 50 } 51 52 /********** test program **********/ 53 54 public class Java_gTest extends TestScaffold { 55 ReferenceType targetClass; 56 ThreadReference mainThread; 57 58 Java_gTest (String args[]) { 59 super(args); 60 } 61 62 public static void main(String[] args) throws Exception { 63 /* 64 * On Windows, this test needs msvcrtd.dll which is installed 65 * as part of Vis C++. We don't want this test to fail 66 * if msvcrtd.dll is not present 67 */ 68 String mslibName = System.mapLibraryName("msvcrtd"); 69 if (mslibName.equals("msvcrtd.dll")) { 70 try { 71 System.loadLibrary("msvcrtd"); 72 } catch (Throwable ee) { 73 // If it isn't there, just pass 74 System.out.println("Exception looking for msvcrtd.dll: " + ee); 75 System.out.println("msvcrtd.dll does not exist. Let the test pass"); 76 return; 77 } 78 } 79 80 /* 81 * This test would like to run the debug (java) executable. 82 * If java is not found, we don't want a spurious test failure, 83 * so check before attempting to run. 84 * 85 * We can't catch the IOException because it is thrown 86 * on a separate thread (com.sun.tools.jdi.AbstractLauncher$Helper), 87 * so check for the expected executable before attempting to launch. 88 */ 89 90 String specialExec = "java"; 91 String sep = System.getProperty("file.separator"); 92 String jhome = System.getProperty("java.home"); 93 String jbin = jhome + sep + "bin"; 94 File binDir = new File(jbin); 95 if ((new File(binDir, specialExec).exists()) || 96 (new File(binDir, specialExec + ".exe").exists())) { 97 /* 98 * A java executable does in fact exist in the 99 * expected location. Run the real test. 100 */ 101 args = new String[2]; 102 args[0] = "-connect"; 103 args[1] = "com.sun.jdi.CommandLineLaunch:vmexec=" + specialExec; 104 new Java_gTest(args).startTests(); 105 } else { 106 System.out.println("No java executable exists. Let the test pass."); 107 } 108 } 109 110 /********** event handlers **********/ 111 112 /********** test core **********/ 113 114 protected void runTests() throws Exception { 115 /* 116 * Get to the top of main() 117 * to determine targetClass and mainThread 118 */ 119 BreakpointEvent bpe = startToMain("Java_gTarg"); 120 listenUntilVMDisconnect(); 121 122 /* 123 * deal with results of test 124 * if anything has called failure("foo") testFailed will be true 125 */ 126 if (!testFailed) { 127 println("Java_gTest: passed"); 128 } else { 129 throw new Exception("Java_gTest: failed"); 130 } 131 } 132 }