test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001.java
changeset 50317 cf71bff5f533
equal deleted inserted replaced
50316:60ebcc705421 50317:cf71bff5f533
       
     1 /*
       
     2  * Copyright (c) 2001, 2018, 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 package nsk.jdwp.VirtualMachine.CapabilitiesNew;
       
    25 
       
    26 import nsk.share.*;
       
    27 import nsk.share.jpda.*;
       
    28 import nsk.share.jdwp.*;
       
    29 
       
    30 import java.io.*;
       
    31 import java.util.*;
       
    32 
       
    33 public class capabilitiesnew001 {
       
    34     static final int JCK_STATUS_BASE = 95;
       
    35     static final int PASSED = 0;
       
    36     static final int FAILED = 2;
       
    37     static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.CapabilitiesNew";
       
    38     static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "capabilitiesnew001";
       
    39     static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";
       
    40 
       
    41     static final String JDWP_COMMAND_NAME = "VirtualMachine.CapabilitiesNew";
       
    42     static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.CapabilitiesNew;
       
    43 
       
    44     public static void main (String argv[]) {
       
    45         System.exit(run(argv,System.out) + JCK_STATUS_BASE);
       
    46     }
       
    47 
       
    48     public static int run(String argv[], PrintStream out) {
       
    49         return new capabilitiesnew001().runIt(argv, out);
       
    50     }
       
    51 
       
    52     public int runIt(String argv[], PrintStream out) {
       
    53 
       
    54         boolean success = true;
       
    55 
       
    56         try {
       
    57             ArgumentHandler argumentHandler = new ArgumentHandler(argv);
       
    58             Log log = new Log(out, argumentHandler);
       
    59 
       
    60             try {
       
    61 
       
    62                 Binder binder = new Binder(argumentHandler, log);
       
    63                 log.display("Start debugee VM");
       
    64                 Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);
       
    65                 Transport transport = debugee.getTransport();
       
    66                 IOPipe pipe = debugee.createIOPipe();
       
    67 
       
    68                 log.display("Waiting for VM_INIT event");
       
    69                 debugee.waitForVMInit();
       
    70 
       
    71                 log.display("Querying for IDSizes");
       
    72                 debugee.queryForIDSizes();
       
    73 
       
    74                 log.display("Resume debugee VM");
       
    75                 debugee.resume();
       
    76 
       
    77                 log.display("Waiting for command: " + "ready");
       
    78                 String cmd = pipe.readln();
       
    79                 log.display("Received command: " + cmd);
       
    80 
       
    81                 // begin test of JDWP command
       
    82 
       
    83                 try {
       
    84                     CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);
       
    85 
       
    86                     log.display("Sending command packet:\n" + command);
       
    87                     transport.write(command);
       
    88 
       
    89                     log.display("Waiting for reply packet");
       
    90                     ReplyPacket reply = new ReplyPacket();
       
    91                     transport.read(reply);
       
    92                     log.display("Reply packet received:\n" + reply);
       
    93 
       
    94                     log.display("Checking reply packet header");
       
    95                     reply.checkHeader(command.getPacketID());
       
    96 
       
    97                     log.display("Parsing reply packet:");
       
    98                     reply.resetPosition();
       
    99 
       
   100                     byte canWatchFieldModification = reply.getByte();
       
   101                     log.display("  canWatchFieldModification:        "
       
   102                                     + canWatchFieldModification);
       
   103 
       
   104                     byte canWatchFieldAction = reply.getByte();
       
   105                     log.display("  canWatchFieldAction:              "
       
   106                                     + canWatchFieldAction);
       
   107 
       
   108                     byte canGetBytecodes = reply.getByte();
       
   109                     log.display("  canGetBytecodes:                  "
       
   110                                     + canGetBytecodes);
       
   111 
       
   112                     byte canGetSyntheticAttribute = reply.getByte();
       
   113                     log.display("  canGetSyntheticAttribute:         "
       
   114                                     + canGetSyntheticAttribute);
       
   115 
       
   116                     byte canGetOwnedMonitorInfo = reply.getByte();
       
   117                     log.display("  canGetOwnedMonitorInfo:           "
       
   118                                     + canGetOwnedMonitorInfo);
       
   119 
       
   120                     byte canGetCurrentContendedMonitor = reply.getByte();
       
   121                     log.display("  canGetCurrentContendedMonitor:    "
       
   122                                     + canGetCurrentContendedMonitor);
       
   123 
       
   124                     byte canGetMonitorInfo = reply.getByte();
       
   125                     log.display("  canGetMonitorInfo:                "
       
   126                                     + canGetMonitorInfo);
       
   127 
       
   128                     byte canRedefineClasses = reply.getByte();
       
   129                     log.display("  canRedefineClasses:               "
       
   130                                     + canRedefineClasses);
       
   131 
       
   132                     byte canAddMethod = reply.getByte();
       
   133                     log.display("  canAddMethod:                     "
       
   134                                     + canAddMethod);
       
   135 
       
   136                     byte canUnrestrictedlyRedefineClasses = reply.getByte();
       
   137                     log.display("  canUnrestrictedlyRedefineClasses: "
       
   138                                     + canUnrestrictedlyRedefineClasses);
       
   139 
       
   140                     byte canPopFrames = reply.getByte();
       
   141                     log.display("  canPopFrames:                     "
       
   142                                     + canPopFrames);
       
   143 
       
   144                     byte canUseInstanceFilters = reply.getByte();
       
   145                     log.display("  canUseInstanceFilters:            "
       
   146                                     + canUseInstanceFilters);
       
   147 
       
   148                     byte canGetSourceDebugExtension = reply.getByte();
       
   149                     log.display("  canGetSourceDebugExtension:       "
       
   150                                     + canGetSourceDebugExtension);
       
   151 
       
   152                     byte canRequestVMDeathEvent = reply.getByte();
       
   153                     log.display("  canRequestVMDeathEvent:           "
       
   154                                     + canRequestVMDeathEvent);
       
   155 
       
   156                     byte canSetDefaultStratum = reply.getByte();
       
   157                     log.display("  canSetDefaultStratum:             "
       
   158                                     + canSetDefaultStratum);
       
   159 
       
   160                     for (int i = 16; i <=32; i++) {
       
   161                         byte reserved = reply.getByte();
       
   162                         log.display("  reserved" + i + ":                       "
       
   163                                     + reserved);
       
   164                     }
       
   165 
       
   166                     if (! reply.isParsed()) {
       
   167                         log.complain("Extra bytes in reply packet at: "
       
   168                                     + reply.currentPosition());
       
   169                         success = false;
       
   170                     }
       
   171 
       
   172                 } catch (Exception e) {
       
   173                     log.complain("Exception catched: " + e);
       
   174                     success = false;
       
   175                 }
       
   176 
       
   177                 // end test of JDWP command
       
   178 
       
   179                 log.display("Sending command: " + "quit");
       
   180                 pipe.println("quit");
       
   181 
       
   182                 log.display("Waiting for debugee exits");
       
   183                 int code = debugee.waitFor();
       
   184                 if (code == JCK_STATUS_BASE + PASSED) {
       
   185                     log.display("Debugee PASSED: " + code);
       
   186                 } else {
       
   187                     log.complain("Debugee FAILED: " + code);
       
   188                     success = false;
       
   189                 }
       
   190 
       
   191             } catch (Exception e) {
       
   192                 log.complain("Unexpected exception: " + e);
       
   193                 e.printStackTrace(out);
       
   194                 success = false;
       
   195             }
       
   196 
       
   197             if (!success) {
       
   198                 log.complain("TEST FAILED");
       
   199                 return FAILED;
       
   200             }
       
   201 
       
   202         } catch (Exception e) {
       
   203             out.println("Unexpected exception: " + e);
       
   204             e.printStackTrace(out);
       
   205             out.println("TEST FAILED");
       
   206             return FAILED;
       
   207         }
       
   208 
       
   209         out.println("TEST PASSED");
       
   210         return PASSED;
       
   211 
       
   212     }
       
   213 
       
   214 }