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