Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.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/kill/kill002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test case for the 'kill <thread id> <expr>' command.32* The debuggee program (kill002a.java) creates a number of additional33* threads with name like "MyThread-<number>" and starts them. The jdb34* suspends debuggee at moment when additional threads are35* waiting for notification for lock objects and then tries to kill them.36* If these threads are killed then a value of the special37* "notKilled" variable should not be modified.38* Value of "notKilled" variable is checked by "eval <expr>" command.39* The test passes if the value is equal to 0 and fails otherwise..40* COMMENTS41*42* @library /vmTestbase43* /test/lib44* @build nsk.jdb.kill.kill002.kill002a45* @run main/othervm46* nsk.jdb.kill.kill002.kill00247* -arch=${os.family}-${os.simpleArch}48* -waittime=549* -debugee.vmkind=java50* -transport.address=dynamic51* -jdb=${test.jdk}/bin/jdb52* -java.options="${test.vm.opts} ${test.java.opts}"53* -workdir=.54* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"55*/5657package nsk.jdb.kill.kill002;5859import nsk.share.*;60import nsk.share.jdb.*;6162import java.io.*;63import java.util.*;6465public class kill002 extends JdbTest {6667public static void main (String argv[]) {68System.exit(run(argv, System.out) + JCK_STATUS_BASE);69}7071public static int run(String argv[], PrintStream out) {72debuggeeClass = DEBUGGEE_CLASS;73firstBreak = FIRST_BREAK;74return new kill002().runTest(argv, out);75}7677static final String PACKAGE_NAME = "nsk.jdb.kill.kill002";78static final String TEST_CLASS = PACKAGE_NAME + ".kill002";79static final String DEBUGGEE_CLASS = TEST_CLASS + "a";80static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";81static final String LAST_BREAK = DEBUGGEE_CLASS + ".breakHere";82static final String MYTHREAD = "MyThread";83static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;84static final String DEBUGGEE_RESULT = DEBUGGEE_CLASS + ".notKilled";85static final String DEBUGGEE_EXCEPTIONS = DEBUGGEE_CLASS + ".exceptions";8687static int numThreads = nsk.jdb.kill.kill002.kill002a.numThreads;8889protected void runCases() {90String[] reply;91Paragrep grep;92int count;93Vector v;94String found;95String[] threads;9697jdb.setBreakpointInMethod(LAST_BREAK);98reply = jdb.receiveReplyFor(JdbCommand.cont);99100threads = jdb.getThreadIds(DEBUGGEE_THREAD);101102if (threads.length != numThreads) {103log.complain("jdb should report " + numThreads + " instance of " + DEBUGGEE_THREAD);104log.complain("Found: " + threads.length);105success = false;106}107108for (int i = 0; i < threads.length; i++) {109reply = jdb.receiveReplyForWithMessageWait(JdbCommand.kill + threads[i] + " " +110DEBUGGEE_EXCEPTIONS + "[" + i + "]",111"killed");112}113reply = jdb.receiveReplyFor(JdbCommand.threads);114reply = jdb.receiveReplyFor(JdbCommand.cont);115116// make sure the debugger is at a breakpoint117if (!jdb.isAtBreakpoint(reply, LAST_BREAK)) {118log.display("Expected breakpoint has not been hit yet");119jdb.waitForMessage(0, LAST_BREAK);120}121log.display("Breakpoint has been hit");122123reply = jdb.receiveReplyForWithMessageWait(JdbCommand.eval + DEBUGGEE_RESULT,124DEBUGGEE_RESULT + " =");125grep = new Paragrep(reply);126found = grep.findFirst(DEBUGGEE_RESULT + " =" );127if (found.length() > 0) {128if (found.indexOf(DEBUGGEE_RESULT + " = 0") < 0) {129log.complain("Not all " + MYTHREAD + "s were killed. " + found + " remaining");130success = false;131}132} else {133log.complain("Value for " + DEBUGGEE_RESULT + " is not found.");134success = false;135}136137jdb.contToExit(numThreads + 1);138}139}140141142