Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002.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/thread/thread002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* This is a test for jdb 'thread <thread id>' command.32* The debugee starts 5 'MyThreads' that are all suspended on the lock33* that the main thread posseses. The 'threads' command is issued34* at this point to obtain ids' od auxiliary threads. Then for each id35* the 'thread' command is issued. The test checks that jdb correctly36* switches between threads using 'eval <expr>' command. The expression37* must return a string containing the name of current thread.38* COMMENTS39* This test functionally equals to nsk/jdb/threads/threads001 test40* and replaces it.41*42* @library /vmTestbase43* /test/lib44* @build nsk.jdb.thread.thread002.thread002a45* @run main/othervm46* nsk.jdb.thread.thread002.thread00247* -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.thread.thread002;5859import nsk.share.*;60import nsk.share.jdb.*;6162import java.io.*;63import java.util.*;6465public class thread002 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;74lastBreak = LAST_BREAK;75return new thread002().runTest(argv, out);76}7778static final String PACKAGE_NAME = "nsk.jdb.thread.thread002";79static final String TEST_CLASS = PACKAGE_NAME + ".thread002";80static final String DEBUGGEE_CLASS = TEST_CLASS + "a";81static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";82static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";8384static final String THREAD_NAME = "MyThread";8586protected void runCases() {87String[] reply;88Paragrep grep;89int count;90Vector v;91String found;9293jdb.setBreakpointInMethod(LAST_BREAK);94jdb.receiveReplyFor(JdbCommand.cont);9596String[] threadIds = jdb.getThreadIds(PACKAGE_NAME + "." + THREAD_NAME);9798for (int i = 0; i < thread002a.numThreads; i++) {99jdb.receiveReplyFor(JdbCommand.thread + threadIds[i]);100jdb.receiveReplyFor(JdbCommand.print + DEBUGGEE_CLASS + ".holder[" + i + "].name");101}102103jdb.contToExit(1);104105reply = jdb.getTotalReply();106grep = new Paragrep(reply);107for (int i = 0; i < threadIds.length; i++) {108count = grep.find(THREAD_NAME + "#" + i);109if (count != 1) {110failure("jdb failed to switch to thread: " + threadIds[i]);111}112}113}114}115116117