Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.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/pop/pop001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DESCRIPTION31* A positive test case for the 'pop' command.32* The debugged application (pop001a.java) starts additional thread of MyThread33* class. The 'run()' method of the this class invokes recursively a number of34* int methods. The jdb sets breakpoint in the last called 'func5()' method35* to suspend the debugged VM when all the methods, i.e. from 'func1()' to36* 'func5()', are in MyThread's stack. Then jdb steps up three frame on stack37* by 'up 3' command. At this moment frame with 'func2()' is current.38* Then the 'pop' command is called. The test passes if after execution of39* tested command the 'func1()' frame becomes current and jdb correctly reports40* the thread stack and local variable(s) of the current frame.41* The test consists of two program:42* pop001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,43* pop001a.java - the debugged application.44* COMMENTS45*46* @library /vmTestbase47* /test/lib48* @build nsk.jdb.pop.pop001.pop001a49* @run main/othervm50* nsk.jdb.pop.pop001.pop00151* -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.pop.pop001;6263import nsk.share.*;64import nsk.share.jdb.*;6566import java.io.*;67import java.util.*;6869public class pop001 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 pop001().runTest(argv, out);80}8182static final String PACKAGE_NAME = "nsk.jdb.pop.pop001";83static final String TEST_CLASS = PACKAGE_NAME + ".pop001";84static final String DEBUGGEE_CLASS = TEST_CLASS + "a";85static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";86static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";8788static final String MYTHREAD = "MyThread";89static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;90static final String[] CHECKED_METHODS = {"func1", "func2", "func3", "func4", "func5"};9192protected void runCases() {93String[] reply;94Paragrep grep;95int count;96Vector v;97String found;9899jdb.setBreakpointInMethod(LAST_BREAK);100reply = jdb.receiveReplyFor(JdbCommand.cont);101102while (true) {103String[] threads = jdb.getThreadIds(DEBUGGEE_THREAD);104if (threads.length != 1) {105log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);106log.complain("Found: " + threads.length);107success = false;108break;109}110111reply = jdb.receiveReplyFor(JdbCommand.thread + threads[0]);112113reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak()114115reply = jdb.receiveReplyFor(JdbCommand.where);116if (!checkStack(reply, "func5", "[1]", "lastBreak", false)) {117success = false;118}119reply = jdb.receiveReplyFor(JdbCommand.up + " 3");120121reply = jdb.receiveReplyFor(JdbCommand.where);122if (!checkStack(reply, "func2", "[4]", "func3", false)) {123success = false;124}125126reply = jdb.receiveReplyFor(JdbCommand.pop);127128reply = jdb.receiveReplyFor(JdbCommand.where);129if (!checkStack(reply, "func1", "[1]", "func2", true)) {130success = false;131}132133reply = jdb.receiveReplyFor(JdbCommand.locals);134grep = new Paragrep(reply);135if (grep.find("Internal exception") > 0) {136log.complain("Internal exception was thrown while 'locals' command");137for (int i = 0; i < reply.length; i++) {138log.complain(reply[i]);139}140success = false;141}142143break;144}145146jdb.contToExit(2);147}148149private boolean checkStack (String[] reply, String shouldBe, String frameNum, String shouldNotBe, boolean pop ) {150Paragrep grep;151String found;152Vector v = new Vector();153boolean result = true;154int count;155156grep = new Paragrep(reply);157v.add(frameNum);158v.add(DEBUGGEE_THREAD + "." + shouldBe);159if ((count = grep.find(v)) != 1) {160log.complain("Contents of stack trace is incorrect " + ( pop? "after 'pop' command": ""));161log.complain("Searched for: " + DEBUGGEE_THREAD + "." + shouldBe);162log.complain("Count : " + count);163result = false;164}165166if (grep.find(DEBUGGEE_THREAD + "." + shouldNotBe) > 0) {167log.complain("Contents of stack trace is incorrect " + ( pop? "after 'pop' command": ""));168log.complain("Found wrong frame: " + DEBUGGEE_THREAD + "." + shouldNotBe);169result = false;170}171172return result;173}174}175176177