Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc04x001.java
41160 views
/*1* Copyright (c) 2002, 2018, 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*/2223package nsk.jdi.BScenarios.multithrd;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.request.*;31import com.sun.jdi.event.*;3233import java.util.*;34import java.io.*;3536/**37* This test is from the group of so-called Borland's scenarios and38* implements the following test case:39* Suite 2 - Breakpoints (multiple threads)40* Test case: TC441* Description: Exception breakpoint42* Steps: 1.Set method breakpoint on Main.foo()43* 2.Debug Main44* 3.Stops on line 27 in Main.java45*46* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.47* After <code>MethodEntryEvent</code> arrived, debugger checks method name and if48* the one corresponds to specified name, it checks line number of the49* event location. It should be 64th line, that is method <code>tc04x001a.foo</code>.50*51* In case, when at least one event doesn't arrive during waittime52* interval or line number of event is wrong, test fails.53*/5455public class tc04x001 {5657public final static String SGL_READY = "ready";58public final static String SGL_LOAD = "load";59public final static String SGL_PERFORM = "perform";60public final static String SGL_QUIT = "quit";6162private final static String prefix = "nsk.jdi.BScenarios.multithrd.";63private final static String debuggerName = prefix + "tc04x001";64private final static String debugeeName = debuggerName + "a";65private final static String methodName = "foo";6667private static int exitStatus;68private static Log log;69private static Debugee debugee;70private static long waitTime;71private static int brkpEventCount = 0;7273private ClassType debugeeClass;7475private static void display(String msg) {76log.display(msg);77}7879private static void complain(String msg) {80log.complain("debugger FAILURE> " + msg + "\n");81}8283public static void main(String argv[]) {84System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));85}8687public static int run(String argv[], PrintStream out) {8889exitStatus = Consts.TEST_PASSED;9091tc04x001 thisTest = new tc04x001();9293ArgumentHandler argHandler = new ArgumentHandler(argv);94log = new Log(out, argHandler);9596waitTime = argHandler.getWaitTime() * 60000;9798Binder binder = new Binder(argHandler, log);99debugee = binder.bindToDebugee(debugeeName);100101try {102thisTest.execTest();103} catch (Throwable e) {104complain("Unexpected " + e);105exitStatus = Consts.TEST_FAILED;106e.printStackTrace();107} finally {108debugee.resume();109}110display("Test finished. exitStatus = " + exitStatus);111112return exitStatus;113}114115private void execTest() throws Failure {116117display("\nTEST BEGINS");118display("===========");119120EventSet eventSet = null;121EventIterator eventIterator = null;122Event event;123long totalTime = waitTime;124long tmp, begin = System.currentTimeMillis(),125delta = 0;126boolean exit = false;127EventRequestManager evm = debugee.getEventRequestManager();128MethodEntryRequest mthdReq = evm.createMethodEntryRequest();129display("MethodEntryRequest created, expecting events "130+ "from method \"" + methodName + "\"");131display("---------------------------------------------"132+ "-----------");133mthdReq.addClassFilter(debugeeName);134mthdReq.enable();135136debugee.resume();137138while (totalTime > 0 && !exit) {139if (eventIterator == null || !eventIterator.hasNext()) {140try {141eventSet = debugee.VM().eventQueue().remove(totalTime);142} catch (InterruptedException e) {143new Failure(e);144}145if (eventSet != null) {146eventIterator = eventSet.eventIterator();147} else {148eventIterator = null;149}150}151if (eventIterator != null) {152while (eventIterator.hasNext()) {153event = eventIterator.nextEvent();154155if (event instanceof MethodEntryEvent) {156display(" event ===>>> " + " MethodEntryEvent arrived");157hitMethodBreakpoint((MethodEntryEvent )event);158debugee.resume();159160} else if (event instanceof VMDeathEvent) {161exit = true;162break;163} else if (event instanceof VMDisconnectEvent) {164exit = true;165break;166} // if167} // while168} // if169170tmp = System.currentTimeMillis();171delta = tmp - begin;172totalTime -= delta;173begin = tmp;174}175176if (totalTime <= 0) {177complain("out of wait time...");178exitStatus = Consts.TEST_FAILED;179}180if (brkpEventCount < tc04x001a.threadCount) {181complain("expecting " + tc04x001a.threadCount182+ " MethodBreakpoint events, but "183+ brkpEventCount + " events arrived.");184exitStatus = Consts.TEST_FAILED;185}186187display("=============");188display("TEST FINISHES\n");189}190191private void hitMethodBreakpoint(MethodEntryEvent event) {192ThreadReference thrd = event.thread();193194display("event info:");195display("\tthread\t- " + event.thread().name());196try {197display("\tsource\t- " + event.location().sourceName());198} catch (AbsentInformationException e) {199}200display("\tmethod\t- " + event.location().method().name());201display("\tline\t- " + event.location().lineNumber());202203if (!event.method().name().equals(methodName)) {204display("the event skipped, method - " + event.method().name() + "\n");205return;206}207208if (event.location().lineNumber() == tc04x001a.checkMethodBrkpLine) {209display("!!!MethodBreakpoint stops on the expected line "210+ event.location().lineNumber() + " in method "211+ "\"" + event.method().name() + "\"!!!");212} else {213complain("MethodBreakpoint stops on line " + event.location().lineNumber()214+ " in method " + event.method().name()215+ ", expected line number is "216+ tc04x001a.checkMethodBrkpLine);217exitStatus = Consts.TEST_FAILED;218}219220display("");221222brkpEventCount++;223}224}225226227