test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java
changeset 50220 31361382634b
equal deleted inserted replaced
50219:4ab066d71956 50220:31361382634b
       
     1 /*
       
     2  * Copyright (c) 2002, 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 
       
    25 /*
       
    26  * @test
       
    27  *
       
    28  * @summary converted from VM Testbase nsk/jdb/untrace/untrace001.
       
    29  * VM Testbase keywords: [jpda, jdb]
       
    30  * VM Testbase readme:
       
    31  * DECSRIPTION
       
    32  * A positive test case for the 'untrace methods <thread id>' command.
       
    33  * The debuggee program (untrace001a.java) creates an additional
       
    34  * thread with name like "MyThread-1" and starts it. The jdb
       
    35  * suspends the debuggee at a moment when the additional thread is
       
    36  * waiting for notification for lock objects and then turns on method
       
    37  * tracing for this thread by 'trace methods <thread id>' command.
       
    38  * After expected notification the additional thread invokes checked
       
    39  * debuggee's methods. Thus jdb output must have the trace messages of checked methods'
       
    40  * entrance and exit.
       
    41  * At second phase jdb suspends the debuggee and turns off tracing
       
    42  * by checked command. After resuming the debuggee's additional
       
    43  * thread invokes checked methods again. Tracing messages and debuggee's
       
    44  * suspentions are not expected at this moment.
       
    45  * The test passes if jdb output has one 'enter' messages and one 'exit'
       
    46  * messages for every checked method.
       
    47  * The test consists of two program:
       
    48  *   untrace001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,
       
    49  *   untrace001a.java - the debugged application.
       
    50  * COMMENTS
       
    51  * Modified due to fix of the bug:
       
    52  *  4785781 TTY: debuggee hangs in jdb 'untrace001' test in Mantis
       
    53  *
       
    54  * @library /vmTestbase
       
    55  *          /test/lib
       
    56  * @run driver jdk.test.lib.FileInstaller . .
       
    57  * @build nsk.jdb.untrace.untrace001.untrace001
       
    58  *        nsk.jdb.untrace.untrace001.untrace001a
       
    59  * @run main/othervm PropertyResolvingWrapper nsk.jdb.untrace.untrace001.untrace001
       
    60  *      -arch=${os.family}-${os.simpleArch}
       
    61  *      -waittime=5
       
    62  *      -debugee.vmkind=java
       
    63  *      -transport.address=dynamic
       
    64  *      -jdb=${test.jdk}/bin/jdb
       
    65  *      -java.options="${test.vm.opts} ${test.java.opts}"
       
    66  *      -workdir=.
       
    67  *      -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"
       
    68  */
       
    69 
       
    70 package nsk.jdb.untrace.untrace001;
       
    71 
       
    72 import nsk.share.*;
       
    73 import nsk.share.jdb.*;
       
    74 
       
    75 import java.io.*;
       
    76 import java.util.*;
       
    77 
       
    78 public class untrace001 extends JdbTest {
       
    79 
       
    80     public static void main (String argv[]) {
       
    81         System.exit(run(argv, System.out) + JCK_STATUS_BASE);
       
    82     }
       
    83 
       
    84     public static int run(String argv[], PrintStream out) {
       
    85         debuggeeClass =  DEBUGGEE_CLASS;
       
    86         firstBreak = FIRST_BREAK;
       
    87         lastBreak = LAST_BREAK;
       
    88         return new untrace001().runTest(argv, out);
       
    89     }
       
    90 
       
    91     static final String PACKAGE_NAME    = "nsk.jdb.untrace.untrace001";
       
    92     static final String TEST_CLASS      = PACKAGE_NAME + ".untrace001";
       
    93     static final String DEBUGGEE_CLASS  = TEST_CLASS + "a";
       
    94     static final String FIRST_BREAK     = DEBUGGEE_CLASS + ".main";
       
    95     static final String LAST_BREAK      = DEBUGGEE_CLASS + ".breakHere";
       
    96     static final String MYTHREAD        = "MyThread";
       
    97     static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;
       
    98 
       
    99     static final String[] CHECKED_METHODS = {"func1", "func2", "func3"};
       
   100 
       
   101     protected void runCases() {
       
   102         String[] reply;
       
   103         Paragrep grep;
       
   104         int count;
       
   105         Vector v;
       
   106         String found;
       
   107         String[] threads;
       
   108 
       
   109         jdb.setBreakpointInMethod(LAST_BREAK);
       
   110         reply = jdb.receiveReplyFor(JdbCommand.cont);
       
   111 
       
   112         threads = jdb.getThreadIds(DEBUGGEE_THREAD);
       
   113 
       
   114         if (threads.length != 1) {
       
   115             log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);
       
   116             log.complain("Found: " + threads.length);
       
   117             success = false;
       
   118         }
       
   119 
       
   120         for (int i = 0; i < threads.length; i++) {
       
   121             reply = jdb.receiveReplyFor(JdbCommand.trace + "methods " + threads[i]);
       
   122         }
       
   123 
       
   124         // resumes debuggee suspended on method enter and exit until hit of the breakpoint
       
   125         for (int i = 0; i < (CHECKED_METHODS.length*threads.length*2 + 1); i++) {
       
   126             reply = jdb.receiveReplyFor(JdbCommand.cont);
       
   127         }
       
   128 
       
   129         for (int i = 0; i < threads.length; i++) {
       
   130             reply = jdb.receiveReplyFor(JdbCommand.untrace + "methods " + threads[i]);
       
   131         }
       
   132 
       
   133         jdb.contToExit(CHECKED_METHODS.length*threads.length*2 + 2);
       
   134 
       
   135         reply = jdb.getTotalReply();
       
   136         if (!checkTrace(CHECKED_METHODS, reply)) {
       
   137             success = false;
       
   138         }
       
   139     }
       
   140 
       
   141     private boolean checkTrace (String[] checkedMethods, String[] reply) {
       
   142         Paragrep grep;
       
   143         String found;
       
   144         int count;
       
   145         Vector v = new Vector();
       
   146         boolean result = true;
       
   147 
       
   148         grep = new Paragrep(reply);
       
   149         for (int i = 0; i < checkedMethods.length; i++) {
       
   150             v.removeAllElements();
       
   151             v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);
       
   152             v.add("Method entered");
       
   153             count = grep.find(v);
       
   154             if (count != 1) {
       
   155                 log.complain("Count of method enter is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);
       
   156                 log.complain("Should be 1 trace messages, found : " + count);
       
   157                 result= false;
       
   158             }
       
   159 
       
   160             v.removeAllElements();
       
   161             v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);
       
   162             v.add("Method exited");
       
   163             count = grep.find(v);
       
   164             if (count != 1) {
       
   165                 log.complain("Count of method exit is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);
       
   166                 log.complain("Should be 1 trace messages, found : " + count);
       
   167                 result= false;
       
   168             }
       
   169         }
       
   170         return result;
       
   171     }
       
   172 }