Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/next/next001/next001.java
40955 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/next/next001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test for the 'next' command.32* The debuggee program (next001a.java) creates two additional33* threads of MyThread type and starts them. The jdb sets up breakpoint34* inside the method 'func2' which is invoked in these addional threads.35* When breakpoint is hitted the checked command is called at the line36* in which debuggee's method ('func3') is invoked. After this,37* the stack trace of the current method is checked by 'where' command.38* The test passes if only calling method ('func2') presents in stack39* trace, but not the called method ('func3').40* The test consists of two program:41* next001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,42* next001a.java - the debugged application.43* COMMENTS44*45* @library /vmTestbase46* /test/lib47* @build nsk.jdb.next.next001.next001a48* @run main/othervm49* nsk.jdb.next.next001.next00150* -arch=${os.family}-${os.simpleArch}51* -waittime=552* -debugee.vmkind=java53* -transport.address=dynamic54* -jdb=${test.jdk}/bin/jdb55* -java.options="${test.vm.opts} ${test.java.opts}"56* -workdir=.57* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"58*/5960package nsk.jdb.next.next001;6162import nsk.share.*;63import nsk.share.jdb.*;6465import java.io.*;66import java.util.*;6768public class next001 extends JdbTest {6970public static void main (String argv[]) {71System.exit(run(argv, System.out) + JCK_STATUS_BASE);72}7374public static int run(String argv[], PrintStream out) {75debuggeeClass = DEBUGGEE_CLASS;76firstBreak = FIRST_BREAK;77lastBreak = LAST_BREAK;78return new next001().runTest(argv, out);79}8081static final String PACKAGE_NAME = "nsk.jdb.next.next001";82static final String TEST_CLASS = PACKAGE_NAME + ".next001";83static final String DEBUGGEE_CLASS = TEST_CLASS + "a";84static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";85static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";86static final String MYTHREAD = "MyThread";87static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;8889static final String[] checkedMethods = {"func1", "func2", "func3"};9091protected void runCases() {92String[] reply;93Paragrep grep;94int count;95Vector v;96String found;97String[] threads;9899jdb.setBreakpointInMethod(LAST_BREAK);100101int breakCount = 0;102int nextCount = 0;103for (int i = 0; i < next001a.numThreads; i++) {104reply = jdb.receiveReplyFor(JdbCommand.cont);105if (jdb.isAtBreakpoint(reply, LAST_BREAK)) {106breakCount++;107reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak;108109reply = jdb.receiveReplyFor(JdbCommand.next);110if (!checkNext()) {111success = false;112} else {113nextCount++;114}115}116}117118jdb.contToExit(1);119120if (nextCount != next001a.numThreads) {121log.complain("Wrong number of 'next' events: " + nextCount);122log.complain("Must be equal to : " + next001a.numThreads);123success = false;124}125}126127128private boolean checkNext () {129Paragrep grep;130String found;131int count;132boolean result = true;133String[] reply;134135reply = jdb.receiveReplyFor(JdbCommand.where);136137grep = new Paragrep(reply);138count = grep.find(DEBUGGEE_THREAD + "." + checkedMethods[2]);139if (count > 0) {140log.complain("Debuggee is suspended in wrong method after 'next' command: " + DEBUGGEE_THREAD + "." + checkedMethods[2]);141result= false;142}143144count = grep.find(DEBUGGEE_THREAD + "." + checkedMethods[1]);145if (count != 1) {146log.complain("Checked method does not exist in thread stack trace: " + DEBUGGEE_THREAD + "." + checkedMethods[1]);147result= false;148}149150return result;151}152}153154155