Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001.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/suspend/suspend001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DESCRIPTION31* A positive test case for the 'suspend <thread id>' command.32* The debugged application (suspend001a.java) creates two addional threads.33* First thead is of Suspended class, second one is of MyThread class.34* The jdb stops debuggee at a moment after addional thread have started and35* before their completion. Then jdb calls 'suspend' command with id of36* the Suspended thread and resumes debuggee. The suspended thread should37* not modify special int 'notSuspended' variable of the suspend001a class.38* The test passes if suspend001a.notSuspended variable equals to 1, i.e.39* only not-suspended MyThread thread had modified it.40* The test consists of two program:41* suspend001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,42* suspend001a.java - the debugged application.43* COMMENTS44*45* @library /vmTestbase46* /test/lib47* @build nsk.jdb.suspend.suspend001.suspend001a48* @run main/othervm49* nsk.jdb.suspend.suspend001.suspend00150* -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.suspend.suspend001;6162import nsk.share.*;63import nsk.share.jdb.*;6465import java.io.*;66import java.util.*;6768public class suspend001 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 suspend001().runTest(argv, out);79}8081static final String PACKAGE_NAME = "nsk.jdb.suspend.suspend001";82static final String TEST_CLASS = PACKAGE_NAME + ".suspend001";83static final String DEBUGGEE_CLASS = TEST_CLASS + "a";84static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";85static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";8687static final String SUSPENDED = "Suspended";88static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + SUSPENDED;89static final String DEBUGGEE_RESULT = DEBUGGEE_CLASS + ".notSuspended";9091protected void runCases() {92String[] reply;93Paragrep grep;94int count;95Vector v;96String found;97String[] threads;9899jdb.setBreakpointInMethod(LAST_BREAK);100reply = jdb.receiveReplyFor(JdbCommand.cont);101while (true) {102threads = jdb.getThreadIds(DEBUGGEE_THREAD);103if (threads.length != 1) {104log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);105log.complain("Found: " + threads.length);106success = false;107break;108}109110reply = jdb.receiveReplyFor(JdbCommand.suspend + threads[0]);111112reply = jdb.receiveReplyFor(JdbCommand.cont);113if (!jdb.isAtBreakpoint(reply)) {114log.complain("Debugge does not reached second breakHere breakpoint");115success = false;116break;117}118119reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_RESULT);120grep = new Paragrep(reply);121found = grep.findFirst(DEBUGGEE_RESULT + " =" );122if (found.length() > 0 && found.indexOf(DEBUGGEE_RESULT + " = null") < 0) {123if (found.indexOf(DEBUGGEE_RESULT + " = 1") < 0) {124log.complain("Wrong value of " + DEBUGGEE_RESULT);125log.complain(found);126success = false;127}128} else {129log.complain("TEST BUG: not found value for " + DEBUGGEE_RESULT);130success = false;131}132133break;134}135136jdb.contToExit(2);137}138}139140141