test/com/sun/jdi/NoLaunchOptionTest.java

Print this page




  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       NoLaunchOptionTest.java
  26  *   @bug        4554734 4724714
  27  *   @summary    Test for -Xrunjdwp:[onthrow,onuncaught] suboptions require launch suboption
  28  *   @author     Tim Bell
  29  *
  30  *  @run compile -g NoLaunchOptionTest.java
  31  *  @build VMConnection
  32  *  @run main/othervm NoLaunchOptionTest
  33  */



  34 public class NoLaunchOptionTest extends Object {
  35     private Process subprocess;
  36     private int subprocessStatus;
  37     private static final String CR = System.getProperty("line.separator");
  38     private static final int BUFFERSIZE = 4096;
  39     public static final int RETSTAT = 0;
  40     public static final int STDOUT = 1;
  41     public static final int STDERR = 2;
  42 
  43     /**
  44      * Run an arbitrary command and return the results to caller.
  45      *
  46      * @param an array of String containing the command
  47      *        to run and any flags or parameters to the command.
  48      *
  49      * @return completion status, stderr and stdout as array of String
  50      *  Look for:
  51      *    return status in result[NoLaunchOptionTest.RETSTAT]
  52      *    standard out in result[NoLaunchOptionTest.STDOUT]
  53      *    standard err in result[NoLaunchOptionTest.STDERR]


 104             System.err.println("IO error: " + ex);
 105         }
 106         String[] result =
 107             new String[] {
 108                 Integer.toString(subprocessStatus),
 109                 stdoutBuffer.toString(),
 110                 stderrBuffer.toString()
 111         };
 112 
 113         System.out.println(CR + "--- Return code was: " +
 114                            CR + result[RETSTAT]);
 115         System.out.println(CR + "--- Return stdout was: " +
 116                            CR + result[STDOUT]);
 117         System.out.println(CR + "--- Return stderr was: " +
 118                            CR + result[STDERR]);
 119 
 120         return result;
 121     }
 122 
 123     public static void main(String[] args) throws Exception {






 124         String javaExe = System.getProperty("java.home") +
 125             java.io.File.separator + "bin" +
 126             java.io.File.separator + "java";
 127         String targetClass = "NotAClass";
 128         String cmds [] = {javaExe,
 129                           "-agentlib:jdwp=transport=dt_socket,address=8000," +

 130                           "onthrow=java.lang.ClassNotFoundException,suspend=n",
 131                           targetClass};
 132         NoLaunchOptionTest myTest = new NoLaunchOptionTest();
 133         String results [] = myTest.run(VMConnection.insertDebuggeeVMOptions(cmds));
 134         if ((results[RETSTAT].equals("1")) &&
 135             (results[STDERR].startsWith("ERROR:"))) {
 136             System.out.println("Test passed: status = 1 with warning messages " +
 137                                "is expected and normal for this test");
 138         } else {
 139             throw new Exception("Test failed: unspecified test failure");
 140         }
 141     }
 142 
 143 }


  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       NoLaunchOptionTest.java
  26  *   @bug        4554734 4724714
  27  *   @summary    Test for -Xrunjdwp:[onthrow,onuncaught] suboptions require launch suboption
  28  *   @author     Tim Bell
  29  *
  30  *  @run compile -g NoLaunchOptionTest.java
  31  *  @build VMConnection
  32  *  @run main/othervm NoLaunchOptionTest
  33  */
  34 
  35 import java.net.ServerSocket;
  36 
  37 public class NoLaunchOptionTest extends Object {
  38     private Process subprocess;
  39     private int subprocessStatus;
  40     private static final String CR = System.getProperty("line.separator");
  41     private static final int BUFFERSIZE = 4096;
  42     public static final int RETSTAT = 0;
  43     public static final int STDOUT = 1;
  44     public static final int STDERR = 2;
  45 
  46     /**
  47      * Run an arbitrary command and return the results to caller.
  48      *
  49      * @param an array of String containing the command
  50      *        to run and any flags or parameters to the command.
  51      *
  52      * @return completion status, stderr and stdout as array of String
  53      *  Look for:
  54      *    return status in result[NoLaunchOptionTest.RETSTAT]
  55      *    standard out in result[NoLaunchOptionTest.STDOUT]
  56      *    standard err in result[NoLaunchOptionTest.STDERR]


 107             System.err.println("IO error: " + ex);
 108         }
 109         String[] result =
 110             new String[] {
 111                 Integer.toString(subprocessStatus),
 112                 stdoutBuffer.toString(),
 113                 stderrBuffer.toString()
 114         };
 115 
 116         System.out.println(CR + "--- Return code was: " +
 117                            CR + result[RETSTAT]);
 118         System.out.println(CR + "--- Return stdout was: " +
 119                            CR + result[STDOUT]);
 120         System.out.println(CR + "--- Return stderr was: " +
 121                            CR + result[STDERR]);
 122 
 123         return result;
 124     }
 125 
 126     public static void main(String[] args) throws Exception {
 127         // find a free port
 128         ServerSocket ss = new ServerSocket(0);
 129         int port = ss.getLocalPort();
 130         ss.close();
 131         String address = String.valueOf(port);
 132 
 133         String javaExe = System.getProperty("java.home") +
 134             java.io.File.separator + "bin" +
 135             java.io.File.separator + "java";
 136         String targetClass = "NotAClass";
 137         String cmds [] = {javaExe,
 138                           "-agentlib:jdwp=transport=dt_socket,address=" + 
 139                           address + "," +
 140                           "onthrow=java.lang.ClassNotFoundException,suspend=n",
 141                           targetClass};
 142         NoLaunchOptionTest myTest = new NoLaunchOptionTest();
 143         String results [] = myTest.run(VMConnection.insertDebuggeeVMOptions(cmds));
 144         if ((results[RETSTAT].equals("1")) &&
 145             (results[STDERR].startsWith("ERROR:"))) {
 146             System.out.println("Test passed: status = 1 with warning messages " +
 147                                "is expected and normal for this test");
 148         } else {
 149             throw new Exception("Test failed: unspecified test failure");
 150         }
 151     }
 152 
 153 }