test/com/sun/jdi/OptionTest.java

Print this page




  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       OptionTest
  26  *   @bug        5095072
  27  *   @summary    Test for misc jdwp options, just that the option is parsed
  28  *   @author     Kelly O'Hair (copied from Tim Bell's NoLaunchOptionTest)
  29  *
  30  *  @run compile -g OptionTest.java
  31  *  @run compile -g HelloWorld.java
  32  *  @run compile -g VMConnection.java
  33  *  @run main/othervm OptionTest
  34  */



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


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






 125         String javaExe = System.getProperty("java.home") +
 126             java.io.File.separator + "bin" +
 127             java.io.File.separator + "java";
 128         String targetClass = "HelloWorld";
 129         String baseOptions = "transport=dt_socket" +
 130                               ",address=8000" +
 131                               ",server=y" +
 132                               ",suspend=n";
 133 
 134         /* Option combinations to try (combos faster, fewer exec's) */
 135         String options[] =  {
 136                 "timeout=0,mutf8=y,quiet=y,stdalloc=y,strict=n",
 137                 "timeout=200000,mutf8=n,quiet=n,stdalloc=n,strict=y"
 138                 };
 139 
 140         for ( String option : options) {
 141             String cmds [] = {javaExe,
 142                               "-agentlib:jdwp=" + baseOptions + "," + option,
 143                               targetClass};
 144             OptionTest myTest = new OptionTest();
 145             String results [] = myTest.run(VMConnection.insertDebuggeeVMOptions(cmds));
 146             if (!(results[RETSTAT].equals("0")) ||
 147                 (results[STDERR].startsWith("ERROR:"))) {
 148                 throw new Exception("Test failed: jdwp doesn't like " + cmds[1]);
 149             }
 150         }


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


 108             System.err.println("IO error: " + ex);
 109         }
 110         String[] result =
 111             new String[] {
 112                 Integer.toString(subprocessStatus),
 113                 stdoutBuffer.toString(),
 114                 stderrBuffer.toString()
 115         };
 116 
 117         System.out.println(CR + "--- Return code was: " +
 118                            CR + result[RETSTAT]);
 119         System.out.println(CR + "--- Return stdout was: " +
 120                            CR + result[STDOUT]);
 121         System.out.println(CR + "--- Return stderr was: " +
 122                            CR + result[STDERR]);
 123 
 124         return result;
 125     }
 126 
 127     public static void main(String[] args) throws Exception {
 128         // find a free port
 129         ServerSocket ss = new ServerSocket(0);
 130         int port = ss.getLocalPort();
 131         ss.close();
 132         String address = String.valueOf(port);
 133 
 134         String javaExe = System.getProperty("java.home") +
 135             java.io.File.separator + "bin" +
 136             java.io.File.separator + "java";
 137         String targetClass = "HelloWorld";
 138         String baseOptions = "transport=dt_socket" +
 139                               ",address=" + address +
 140                               ",server=y" +
 141                               ",suspend=n";
 142 
 143         /* Option combinations to try (combos faster, fewer exec's) */
 144         String options[] =  {
 145                 "timeout=0,mutf8=y,quiet=y,stdalloc=y,strict=n",
 146                 "timeout=200000,mutf8=n,quiet=n,stdalloc=n,strict=y"
 147                 };
 148 
 149         for ( String option : options) {
 150             String cmds [] = {javaExe,
 151                               "-agentlib:jdwp=" + baseOptions + "," + option,
 152                               targetClass};
 153             OptionTest myTest = new OptionTest();
 154             String results [] = myTest.run(VMConnection.insertDebuggeeVMOptions(cmds));
 155             if (!(results[RETSTAT].equals("0")) ||
 156                 (results[STDERR].startsWith("ERROR:"))) {
 157                 throw new Exception("Test failed: jdwp doesn't like " + cmds[1]);
 158             }
 159         }