Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java
40951 views
/*1* Copyright (c) 2003, 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/methods/methods002.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DESCRIPTION31* This is a test for the 'methods' command.32* The test checks the following cases33* - class with various method modifiers,34* - class with various constructors,35* - class with various overloaded methods,36* - abstract class and interface,37* - implementing class,38* - class with inherited methods,39* - class with inherited and overrided methods.40* The test passes if signatures for all expected methods are listed41* in reply on command for every case.42* The test consists of two parts:43* methods002.java - test driver, i.e. launches jdb and debuggee,44* writes commands to jdb, reads the jdb output,45* methods002a.java - the debugged application.46* COMMENTS47* This test replaces the nsk/jdb/methods/methods001 one.48*49* @library /vmTestbase50* /test/lib51* @build nsk.jdb.methods.methods002.methods002a52* @run main/othervm53* nsk.jdb.methods.methods002.methods00254* -arch=${os.family}-${os.simpleArch}55* -waittime=556* -debugee.vmkind=java57* -transport.address=dynamic58* -jdb=${test.jdk}/bin/jdb59* -java.options="${test.vm.opts} ${test.java.opts}"60* -workdir=.61* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"62*/6364package nsk.jdb.methods.methods002;6566import nsk.share.*;67import nsk.share.jdb.*;6869import java.io.*;70import java.util.*;7172public class methods002 extends JdbTest {7374public static void main (String argv[]) {75System.exit(run(argv, System.out) + JCK_STATUS_BASE);76}7778public static int run(String argv[], PrintStream out) {79debuggeeClass = DEBUGGEE_CLASS;80firstBreak = FIRST_BREAK;81lastBreak = LAST_BREAK;82return new methods002().runTest(argv, out);83}8485static final String PACKAGE_NAME = "nsk.jdb.methods.methods002";86static final String TEST_CLASS = PACKAGE_NAME + ".methods002";87static final String DEBUGGEE_CLASS = TEST_CLASS + "a";88static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";89static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9091protected void runCases() {92String[] reply;93Paragrep grep;94int count;95Vector v;96String found;9798jdb.setBreakpointInMethod(LAST_BREAK);99reply = jdb.receiveReplyFor(JdbCommand.cont);100101// Case for class with method modifiers102String testedClass1 = TEST_CLASS + "a";103reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass1);104for (int i = 1; i <= 33; i++) {105checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass1 );106}107for (int i = 1; i <= 3; i++) {108checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass1 );109}110111// Case for class with many constructors112String testedClass2 = TEST_CLASS + "b";113reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass2);114String[] reply1 = toStringArray(reply); // on Windows reply is single string with embedded \r\n symbols115checkMethod( reply1, "<init>", 4, testedClass2, testedClass2 );116117// Case for class with overloaded methods118String testedClass3 = TEST_CLASS + "c";119reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass3);120reply1 = toStringArray(reply); // // on Windows reply is single string with embedded \r\n symbols121checkMethod( reply1, "m01", 3, testedClass3, testedClass3 );122123// Case for abstract class124String testedClass4 = TEST_CLASS + "d";125reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass4);126checkMethod( reply, "m01", 1, testedClass4, testedClass4 );127128// Case for interface129String testedClass5 = TEST_CLASS + "i";130reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass5);131checkMethod( reply, "i01", 1, testedClass5, testedClass5 );132133// Case for class with implemented method134String testedClass6 = TEST_CLASS + "e";135reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass6);136checkMethod( reply, "m01", 1, testedClass4, testedClass6 );137checkMethod( reply, "i01", 1, testedClass5, testedClass6 );138checkMethod( reply, "m01", 1, testedClass6, testedClass6 );139140// Case for class with inherited methods141String testedClass7 = TEST_CLASS + "f";142reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass7);143for (int i = 1; i <= 33; i++) {144checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass7 );145}146for (int i = 1; i <= 3; i++) {147checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass7 );148}149150// Case for class with inherited and overrided methods151String testedClass8 = TEST_CLASS + "g";152reply = jdb.receiveReplyFor(JdbCommand.methods + testedClass8);153for (int i = 1; i <= 33; i++) {154checkMethod( reply, "m" + intToString(i), 1, testedClass8, testedClass8 );155}156for (int i = 1; i <= 33; i++) {157checkMethod( reply, "m" + intToString(i), 1, testedClass1, testedClass8 );158}159for (int i = 1; i <= 3; i++) {160checkMethod( reply, "f" + intToString(i), 1, testedClass1, testedClass8 );161}162163jdb.contToExit(1);164}165166private void checkMethod (167String[] reply, /* reply on 'methods' command */168String methodName, /* method name */169int expOccur, /* expected number of occurences of the method */170String ownerClass, /* name of class defining method */171String testedClass /* name of tested class */172) {173174Paragrep grep = new Paragrep(reply);175Vector v = new Vector();176177v.add(ownerClass);178v.add(methodName);179int j = grep.find(v);180if (j != expOccur) {181failure("Wrong number of occurences of method " + methodName +182"\n\t of class " + ownerClass +183"\n\t in class " + testedClass +184"\n\t expected number: " + expOccur + " got: " + j);185}186}187188private String[] toStringArray (String[] arr) {189Vector v = new Vector();190for (int i = 0; i < arr.length; i++) {191StringTokenizer st = new StringTokenizer(arr[i], "\r\n");192while (st.hasMoreTokens()) {193v.add(st.nextToken());194}195}196Object[] objects = v.toArray();197String[] results = new String[objects.length];198for (int i = 0; i < objects.length; i++) {199results[i] = (String)objects[i];200}201return results;202}203204private String intToString (int i) {205String s = String.valueOf(i);206if (s.length()==1)207s = "0" + s;208return s;209}210}211212213