Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006.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/where/where006.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A test to exercise the functionality of the 'where <thread_id>'32* and the 'where all' commands.33* The debugee creates 5 threads that are all suspended on locks34* that the main thread posseses. The 'where <thread_id>' command35* is used to get stack traces of all 5 suspended threads. The test36* passes if contents of the stack trace match to expected output.37* COMMENTS38* This test functionally equals to nsk/jdb/where/where003 test39* and replaces it.40*41* @library /vmTestbase42* /test/lib43* @build nsk.jdb.where.where006.where006a44* @run main/othervm45* nsk.jdb.where.where006.where00646* -arch=${os.family}-${os.simpleArch}47* -waittime=548* -debugee.vmkind=java49* -transport.address=dynamic50* -jdb=${test.jdk}/bin/jdb51* -java.options="${test.vm.opts} ${test.java.opts}"52* -workdir=.53* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"54*/5556package nsk.jdb.where.where006;5758import nsk.share.*;59import nsk.share.jdb.*;6061import java.io.*;62import java.util.*;6364public class where006 extends JdbTest {6566public static void main (String argv[]) {67System.exit(run(argv, System.out) + JCK_STATUS_BASE);68}6970public static int run(String argv[], PrintStream out) {71debuggeeClass = DEBUGGEE_CLASS;72firstBreak = FIRST_BREAK;73lastBreak = LAST_BREAK;74return new where006().runTest(argv, out);75}7677static final String PACKAGE_NAME = "nsk.jdb.where.where006";78static final String TEST_CLASS = PACKAGE_NAME + ".where006";79static final String DEBUGGEE_CLASS = TEST_CLASS + "a";80static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";81static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";8283static final String[][] FRAMES = new String[][] {84{PACKAGE_NAME + ".MyThread.func5", "111"},85{PACKAGE_NAME + ".MyThread.func4", "103"},86{PACKAGE_NAME + ".MyThread.func3", "99"},87{PACKAGE_NAME + ".MyThread.func2", "95"},88{PACKAGE_NAME + ".MyThread.func1", "91"},89{PACKAGE_NAME + ".MyThread.run", "85"},90};91protected void runCases() {92String[] reply;93Paragrep grep;94int count;95Vector v;96String found;9798jdb.setBreakpointInMethod(LAST_BREAK);99jdb.receiveReplyFor(JdbCommand.cont);100101String[] threadIds = jdb.getThreadIds(PACKAGE_NAME + ".MyThread");102reply = jdb.receiveReplyFor(JdbCommand.where + "all");103for (int i = 0; i < where006a.numThreads; i++) {104checkFrames(threadIds[i], reply, 5);105}106107for (int i = 0; i < where006a.numThreads; i++) {108reply = jdb.receiveReplyFor(JdbCommand.where + threadIds[i]);109checkFrames(threadIds[i], reply, 1);110}111112jdb.contToExit(1);113}114115void checkFrames (String threadId, String[] reply, int expectedVal) {116Paragrep grep;117int count;118Vector v;119String found;120121grep = new Paragrep(reply);122for (int j = 0; j < FRAMES.length; j++) {123count = grep.find(FRAMES[j][0]);124if (count != expectedVal) {125failure("Unexpected number of occurencies of the stack frame: " + FRAMES[j][0] +126" for thread " + threadId +127"\n\t Expected number of occurence: " + expectedVal +", got : " + count);128if (count > 0) {129found = grep.findFirst(FRAMES[j][0]);130if (found.indexOf(FRAMES[j][1]) < 0) {131failure("Unexpected location in the stack frame: " + FRAMES[j][0] +132" for thread " + threadId +133"\n\t Expected location: " + FRAMES[j][1] + ", got :\n\t" + found);134}135}136}137}138}139}140141142