test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/description/description001.java
changeset 50018 3ba0d8631f24
child 53869 34906de6c017
equal deleted inserted replaced
50017:88cc95780b6e 50018:3ba0d8631f24
       
     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.jdi.VirtualMachine.description;
       
    25 
       
    26 import nsk.share.*;
       
    27 import nsk.share.jpda.*;
       
    28 import nsk.share.jdi.*;
       
    29 
       
    30 import com.sun.jdi.*;
       
    31 import java.util.*;
       
    32 import java.io.*;
       
    33 
       
    34 /**
       
    35  * The test for the implementation of an object of the type     <BR>
       
    36  * VirtualMachine.                                              <BR>
       
    37  *                                                              <BR>
       
    38  * The test checks up that results of the method                <BR>
       
    39  * <code>com.sun.jdi.VirtualMachine.description()</code>        <BR>
       
    40  * complies with its specification.                             <BR>
       
    41  */
       
    42 
       
    43 public class description001 {
       
    44 
       
    45     //----------------------------------------------------- templete section
       
    46     static final int PASSED = 0;
       
    47     static final int FAILED = 2;
       
    48     static final int PASS_BASE = 95;
       
    49 
       
    50     //----------------------------------------------------- templete parameters
       
    51     static final String
       
    52     sHeader1 = "\n==> nsk/jdi/VirtualMachine/description/description001  ",
       
    53     sHeader2 = "--> debugger: ",
       
    54     sHeader3 = "##> debugger: ";
       
    55 
       
    56     //----------------------------------------------------- main method
       
    57 
       
    58     public static void main (String argv[]) {
       
    59         int result = run(argv, System.out);
       
    60         System.exit(result + PASS_BASE);
       
    61     }
       
    62 
       
    63     public static int run (String argv[], PrintStream out) {
       
    64         return new description001().runThis(argv, out);
       
    65     }
       
    66 
       
    67     //--------------------------------------------------   log procedures
       
    68 
       
    69     private static Log  logHandler;
       
    70 
       
    71     private static void log1(String message) {
       
    72         logHandler.display(sHeader1 + message);
       
    73     }
       
    74     private static void log2(String message) {
       
    75         logHandler.display(sHeader2 + message);
       
    76     }
       
    77     private static void log3(String message) {
       
    78         logHandler.complain(sHeader3 + message);
       
    79     }
       
    80 
       
    81     //  ************************************************    test parameters
       
    82 
       
    83     private String debuggeeName =
       
    84         "nsk.jdi.VirtualMachine.description.description001a";
       
    85 
       
    86     //String mName = "nsk.jdi.VirtualMachine.description";
       
    87 
       
    88     //====================================================== test program
       
    89     //------------------------------------------------------ common section
       
    90 
       
    91     static ArgumentHandler      argsHandler;
       
    92 
       
    93     static int waitTime;
       
    94 
       
    95     static VirtualMachine  vm = null;
       
    96 
       
    97     static int  testExitCode = PASSED;
       
    98 
       
    99     static final int returnCode0 = 0;
       
   100     static final int returnCode1 = 1;
       
   101     static final int returnCode2 = 2;
       
   102     static final int returnCode3 = 3;
       
   103     static final int returnCode4 = 4;
       
   104 
       
   105     //------------------------------------------------------ methods
       
   106 
       
   107     private int runThis (String argv[], PrintStream out) {
       
   108 
       
   109         Debugee debuggee;
       
   110 
       
   111         argsHandler     = new ArgumentHandler(argv);
       
   112         logHandler      = new Log(out, argsHandler);
       
   113         Binder binder   = new Binder(argsHandler, logHandler);
       
   114 
       
   115         if (argsHandler.verbose()) {
       
   116             debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
       
   117         } else {
       
   118             debuggee = binder.bindToDebugee(debuggeeName);
       
   119         }
       
   120 
       
   121         waitTime = argsHandler.getWaitTime();
       
   122 
       
   123 
       
   124         IOPipe pipe     = new IOPipe(debuggee);
       
   125 
       
   126         debuggee.redirectStderr(out);
       
   127         log2("issuspended002a debuggee launched");
       
   128         debuggee.resume();
       
   129 
       
   130         String line = pipe.readln();
       
   131         if ((line == null) || !line.equals("ready")) {
       
   132             log3("signal received is not 'ready' but: " + line);
       
   133             return FAILED;
       
   134         } else {
       
   135             log2("'ready' recieved");
       
   136         }
       
   137 
       
   138         vm = debuggee.VM();
       
   139 
       
   140     //------------------------------------------------------  testing section
       
   141         log1("      TESTING BEGINS");
       
   142 
       
   143         for (int i = 0; ; i++) {
       
   144 
       
   145             pipe.println("newcheck");
       
   146             line = pipe.readln();
       
   147 
       
   148             if (line.equals("checkend")) {
       
   149                 log2("     : returned string is 'checkend'");
       
   150                 break ;
       
   151             } else if (!line.equals("checkready")) {
       
   152                 log3("ERROR: returned string is not 'checkready'");
       
   153                 testExitCode = FAILED;
       
   154                 break ;
       
   155             }
       
   156 
       
   157             log1("new checkready: #" + i);
       
   158 
       
   159             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
       
   160 
       
   161             int expresult = returnCode0;
       
   162 
       
   163             String description = vm.description();
       
   164             if (description == null) {
       
   165                 log3("ERROR: description == null");
       
   166                 expresult = returnCode1;
       
   167             } else
       
   168                 log2("     description == " + description);
       
   169 
       
   170             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   171             log2("     the end of testing");
       
   172             if (expresult != returnCode0)
       
   173                 testExitCode = FAILED;
       
   174         }
       
   175         log1("      TESTING ENDS");
       
   176 
       
   177     //--------------------------------------------------   test summary section
       
   178     //-------------------------------------------------    standard end section
       
   179 
       
   180         pipe.println("quit");
       
   181         log2("waiting for the debuggee to finish ...");
       
   182         debuggee.waitFor();
       
   183 
       
   184         int status = debuggee.getStatus();
       
   185         if (status != PASSED + PASS_BASE) {
       
   186             log3("debuggee returned UNEXPECTED exit status: " +
       
   187                     status + " != PASS_BASE");
       
   188             testExitCode = FAILED;
       
   189         } else {
       
   190             log2("debuggee returned expected exit status: " +
       
   191                     status + " == PASS_BASE");
       
   192         }
       
   193 
       
   194         if (testExitCode != PASSED) {
       
   195             logHandler.complain("TEST FAILED");
       
   196         }
       
   197         return testExitCode;
       
   198     }
       
   199 }