Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java
40951 views
/*1* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* @test26*27* @summary converted from VM Testbase nsk/jdb/untrace/untrace001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'untrace methods <thread id>' command.32* The debuggee program (untrace001a.java) creates an additional33* thread with name like "MyThread-1" and starts it. The jdb34* suspends the debuggee at a moment when the additional thread is35* waiting for notification for lock objects and then turns on method36* tracing for this thread by 'trace methods <thread id>' command.37* After expected notification the additional thread invokes checked38* debuggee's methods. Thus jdb output must have the trace messages of checked methods'39* entrance and exit.40* At second phase jdb suspends the debuggee and turns off tracing41* by checked command. After resuming the debuggee's additional42* thread invokes checked methods again. Tracing messages and debuggee's43* suspentions are not expected at this moment.44* The test passes if jdb output has one 'enter' messages and one 'exit'45* messages for every checked method.46* The test consists of two program:47* untrace001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,48* untrace001a.java - the debugged application.49* COMMENTS50* Modified due to fix of the bug:51* 4785781 TTY: debuggee hangs in jdb 'untrace001' test in Mantis52*53* @library /vmTestbase54* /test/lib55* @build nsk.jdb.untrace.untrace001.untrace001a56* @run main/othervm57* nsk.jdb.untrace.untrace001.untrace00158* -arch=${os.family}-${os.simpleArch}59* -waittime=560* -debugee.vmkind=java61* -transport.address=dynamic62* -jdb=${test.jdk}/bin/jdb63* -java.options="${test.vm.opts} ${test.java.opts}"64* -workdir=.65* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"66*/6768package nsk.jdb.untrace.untrace001;6970import nsk.share.*;71import nsk.share.jdb.*;7273import java.io.*;74import java.util.*;7576public class untrace001 extends JdbTest {7778public static void main (String argv[]) {79System.exit(run(argv, System.out) + JCK_STATUS_BASE);80}8182public static int run(String argv[], PrintStream out) {83debuggeeClass = DEBUGGEE_CLASS;84firstBreak = FIRST_BREAK;85lastBreak = LAST_BREAK;86return new untrace001().runTest(argv, out);87}8889static final String PACKAGE_NAME = "nsk.jdb.untrace.untrace001";90static final String TEST_CLASS = PACKAGE_NAME + ".untrace001";91static final String DEBUGGEE_CLASS = TEST_CLASS + "a";92static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";93static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";94static final String MYTHREAD = "MyThread";95static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;9697static final String[] CHECKED_METHODS = {"func1", "func2", "func3"};9899protected void runCases() {100String[] reply;101Paragrep grep;102int count;103Vector v;104String found;105String[] threads;106107jdb.setBreakpointInMethod(LAST_BREAK);108reply = jdb.receiveReplyFor(JdbCommand.cont);109110threads = jdb.getThreadIds(DEBUGGEE_THREAD);111112if (threads.length != 1) {113log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);114log.complain("Found: " + threads.length);115success = false;116}117118for (int i = 0; i < threads.length; i++) {119reply = jdb.receiveReplyFor(JdbCommand.trace + "methods " + threads[i]);120}121122// resumes debuggee suspended on method enter and exit until hit of the breakpoint123for (int i = 0; i < (CHECKED_METHODS.length*threads.length*2 + 1); i++) {124reply = jdb.receiveReplyFor(JdbCommand.cont);125}126127for (int i = 0; i < threads.length; i++) {128reply = jdb.receiveReplyFor(JdbCommand.untrace + "methods " + threads[i]);129}130131jdb.contToExit(CHECKED_METHODS.length*threads.length*2 + 2);132133reply = jdb.getTotalReply();134if (!checkTrace(CHECKED_METHODS, reply)) {135success = false;136}137}138139private boolean checkTrace (String[] checkedMethods, String[] reply) {140Paragrep grep;141String found;142int count;143Vector v = new Vector();144boolean result = true;145146grep = new Paragrep(reply);147for (int i = 0; i < checkedMethods.length; i++) {148v.removeAllElements();149v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);150v.add("Method entered");151count = grep.find(v);152if (count != 1) {153log.complain("Count of method enter is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);154log.complain("Should be 1 trace messages, found : " + count);155result= false;156}157158v.removeAllElements();159v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);160v.add("Method exited");161count = grep.find(v);162if (count != 1) {163log.complain("Count of method exit is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);164log.complain("Should be 1 trace messages, found : " + count);165result= false;166}167}168return result;169}170}171172173