Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/read/read001/read001.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/read/read001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DESCRIPTION31* A positive test for the 'read <filename>' command.32* The jdb stops the debugged application on enter in read001a.lastBreak()33* method. Then the tested command is called for the 'jdb.scenario' file.34* The test passes if correct replies for all commands containing in35* 'jdb.scenario' are found in jdb stdout stream.36* The test consists of two program:37* read001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,38* read001a.java - the debugged application.39* COMMENTS40* Only limited number of commands is used in 'jdb.scenario' file because41* the jdb does not wait until end of reply for current command and42* immediatly executes the next command from 'jdb.scenario'.43* Fixed test according to test bug:44* 4665075 TTY: error messages for commands from scenario file of 'read' command45*46* @library /vmTestbase47* /test/lib48* @build nsk.jdb.read.read001.read00149*50* @comment make sure read001a is compiled w/ full debug info51* @clean nsk.jdb.read.read001.read001a52* @compile -g:lines,source,vars read001a.java53*54* @run main/othervm55* nsk.jdb.read.read001.read00156* -arch=${os.family}-${os.simpleArch}57* -waittime=558* -debugee.vmkind=java59* -transport.address=dynamic60* -jdb=${test.jdk}/bin/jdb61* -java.options="${test.vm.opts} ${test.java.opts}"62* -workdir=.63* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"64*/6566package nsk.jdb.read.read001;6768import nsk.share.*;69import nsk.share.jdb.*;70import jdk.test.lib.Utils;7172import java.io.*;73import java.util.*;7475public class read001 extends JdbTest {7677public static void main (String argv[]) {78System.exit(run(argv, System.out) + JCK_STATUS_BASE);79}8081public static int run(String argv[], PrintStream out) {82debuggeeClass = DEBUGGEE_CLASS;83firstBreak = FIRST_BREAK;84lastBreak = LAST_BREAK;85return new read001().runTest(argv, out);86}8788static final String PACKAGE_NAME = "nsk.jdb.read.read001";89static final String TEST_CLASS = PACKAGE_NAME + ".read001";90static final String DEBUGGEE_CLASS = TEST_CLASS + "a";91static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";92static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9394static final String SCENARIO_FILE = "jdb.scenario";95static final int SCENARIO_COMMANDS_COUNT = 5;9697protected void runCases() {98String[] reply;99String srcdir = Utils.TEST_SRC;100101// stop in lastBreak() method102jdb.setBreakpointInMethod(LAST_BREAK);103reply = jdb.receiveReplyFor(JdbCommand.cont);104105// return to testedInstanceMethod()106reply = jdb.receiveReplyFor(JdbCommand.step);107108String command = JdbCommand.read + srcdir + File.separator + SCENARIO_FILE;109int count = SCENARIO_COMMANDS_COUNT + 1;110reply = jdb.receiveReplyFor(command, true, count);111112if (!checkCommands(reply)) {113success = false;114}115116jdb.contToExit(1);117}118119private boolean checkCommands(String[] reply) {120Paragrep grep;121String found;122Vector v = new Vector();123boolean result = true;124int count;125126grep = new Paragrep(reply);127128// check 'threads'129log.display("Check reply for command: classes");130if ((count = grep.find("nsk.jdb.read.read001.read001aTestedClass")) != 1) {131log.complain("Wrong number of execution of command: classes");132log.complain(" Expected: 1; found: " + count);133result = false;134}135136// check 'threads'137log.display("Check reply for command: threads");138if ((count = grep.find("TestedThreadInstance")) != 1) {139log.complain("Wrong number of execution of command: threads");140log.complain(" Expected: 1; found: " + count);141result = false;142}143144// check 'methods'145log.display("Check reply for command: methods");146if ((count = grep.find("testedInstanceMethod()")) != 1) {147log.complain("Wrong number of execution of command: methods nsk.jdb.read.read001a");148log.complain(" Expected: 1; found: " + count);149result = false;150}151152// check 'fields'153log.display("Check reply for command: fields");154if ((count = grep.find("testedStaticFieldBoolean")) != 1) {155log.complain("Wrong number of execution of command: fields nsk.jdb.read.read001.presentedInstance");156log.complain(" Expected: 1; found: " + count);157result = false;158}159160// check 'locals'161log.display("Check reply for command: locals");162if ((count = grep.find("testedLocalVarInt")) != 1) {163log.complain("Wrong number of execution of command: locals");164log.complain(" Expected: 1; found: " + count);165result = false;166}167168/*169// check 'eval'170log.display("Check reply for command: eval");171if ((count = grep.find("556600")) != 1) {172log.complain("Wrong number of execution of command: "173+ "eval nsk.jdb.read.read001a.staticInt+instanceInt*3");174log.complain(" Expected: 1; found: " + count);175result = false;176}177178// check 'print'179log.display("Check reply for command: print");180if ((count = grep.find("staticString = \"static string of read001a class\"")) != 1) {181log.complain("Wrong number of execution of command: "182+ "print nsk.jdb.read.read001.read001a.staticString"183);184log.complain(" Expected: 1; found: " + count);185result = false;186}187188// check 'dump'189log.display("Check reply for command: dump");190if ((count = grep.find("instance of nsk.jdb.read.read001.read001a")) != 1) {191log.complain("Wrong number of execution of command: "192+ "dump nsk.jdb.read.read001.read001a._read001a");193log.complain(" Expected: 1; found: " + count);194result = false;195}196*/197198return result;199}200}201202203