Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001.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/trace/trace001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'trace methods <thread id>' command.32* The debuggee program (trace001a.java) creates two of additional33* threads with name like "MyThread-<number>" and starts them. The jdb34* suspends the debuggee at a moment when the additional threads are35* waiting for notification for lock objects and then turns on method36* tracing for these threads by checked command. After expected37* notification the additional threads invoke checked debuggee's methods.38* Thus jdb output must have the trace messages of checked methods'39* entrance and exit. The test passes if jdb output has two 'enter' messages40* and two 'exit' messages for every checked method.41* The test consists of two program:42* trace001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,43* trace001a.java - the debugged application.44* COMMENTS45*46* @library /vmTestbase47* /test/lib48* @build nsk.jdb.trace.trace001.trace001a49* @run main/othervm50* nsk.jdb.trace.trace001.trace00151* -arch=${os.family}-${os.simpleArch}52* -waittime=553* -debugee.vmkind=java54* -transport.address=dynamic55* -jdb=${test.jdk}/bin/jdb56* -java.options="${test.vm.opts} ${test.java.opts}"57* -workdir=.58* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"59*/6061package nsk.jdb.trace.trace001;6263import nsk.share.*;64import nsk.share.jdb.*;6566import java.io.*;67import java.util.*;6869public class trace001 extends JdbTest {7071public static void main (String argv[]) {72System.exit(run(argv, System.out) + JCK_STATUS_BASE);73}7475public static int run(String argv[], PrintStream out) {76debuggeeClass = DEBUGGEE_CLASS;77firstBreak = FIRST_BREAK;78lastBreak = LAST_BREAK;79return new trace001().runTest(argv, out);80}8182static final String PACKAGE_NAME = "nsk.jdb.trace.trace001";83static final String TEST_CLASS = PACKAGE_NAME + ".trace001";84static final String DEBUGGEE_CLASS = TEST_CLASS + "a";85static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";86static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";87static final String MYTHREAD = "MyThread";88static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;8990static final String[] CHECKED_METHODS = {"func1", "func2", "func3"};9192protected void runCases() {93String[] reply;94Paragrep grep;95int count;96Vector v;97String found;98String[] threads;99100jdb.setBreakpointInMethod(LAST_BREAK);101reply = jdb.receiveReplyFor(JdbCommand.cont);102103threads = jdb.getThreadIds(DEBUGGEE_THREAD);104105if (threads.length != 2) {106log.complain("jdb should report 2 instance of " + DEBUGGEE_THREAD);107log.complain("Found: " + threads.length);108success = false;109}110111for (int i = 0; i < threads.length; i++) {112reply = jdb.receiveReplyFor(JdbCommand.trace + "methods " + threads[i]);113}114115jdb.contToExit(CHECKED_METHODS.length*threads.length*2 + 3);116117reply = jdb.getTotalReply();118if (!checkTrace(CHECKED_METHODS, reply)) {119success = false;120}121}122123private boolean checkTrace (String[] checkedMethods, String[] reply) {124Paragrep grep;125String found;126int count;127Vector v = new Vector();128boolean result = true;129130grep = new Paragrep(reply);131for (int i = 0; i < checkedMethods.length; i++) {132v.removeAllElements();133v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);134v.add("Method entered");135count = grep.find(v);136if (count != 2) {137log.complain("Count of method enter is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);138log.complain("Should be 2 trace messages, found : " + count);139result= false;140}141142v.removeAllElements();143v.add(DEBUGGEE_THREAD + "." + checkedMethods[i]);144v.add("Method exited");145count = grep.find(v);146if (count != 2) {147log.complain("Count of method exit is incorrect for the method : " + DEBUGGEE_THREAD + "." + checkedMethods[i]);148log.complain("Should be 2 trace messages, found : " + count);149result= false;150}151}152return result;153}154}155156157