Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/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.singlethrd;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: <br>39* Suite 2 - Breakpoints (multiple threads) <br>40* Test case: TC2 <br>41* Description: Class breakpoint <br>42* Steps: 1.Add class breakpoint: singlethread.Class1 <br>43* 2.Debug Main <br>44* X. Stops on line 13 in Class1.java <br>45*46* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.47* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's48* location. It should be 73th line, that is constructor of <code>tc04x001aClass1</code>49* class. Every thread must generate <code>MethodEntryEvent</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.singlethrd.";63private final static String debuggerName = prefix + "tc04x001";64private final static String debugeeName = debuggerName + "a";65private final static String exceptionName = debugeeName + "Exception";6667private static int exitStatus;68private static Log log;69private static Debugee debugee;70private static long waitTime;71private final static int expectedEventCount = 1;72private static int eventCount = 0;7374private EventRequestManager evm = null;75private ExceptionRequest exReq = null;76private volatile boolean exit = false;777879private static void display(String msg) {80log.display(msg);81}8283private static void complain(String msg) {84log.complain("debugger FAILURE> " + msg + "\n");85}8687public static void main(String argv[]) {88System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));89}9091public static int run(String argv[], PrintStream out) {9293exitStatus = Consts.TEST_PASSED;94tc04x001 thisTest = new tc04x001();9596ArgumentHandler argHandler = new ArgumentHandler(argv);97log = new Log(out, argHandler);98waitTime = argHandler.getWaitTime() * 60000;99100Binder binder = new Binder(argHandler, log);101debugee = binder.bindToDebugee(debugeeName);102IOPipe pipe = debugee.createIOPipe();103104try {105thisTest.execTest();106} catch (Throwable e) {107complain("Unexpected " + e);108exitStatus = Consts.TEST_FAILED;109e.printStackTrace();110} finally {111debugee.endDebugee();112}113display("Test finished. exitStatus = " + exitStatus);114115return exitStatus;116}117118private void execTest() throws Failure {119evm = debugee.getEventRequestManager();120121ClassPrepareRequest crq = evm.createClassPrepareRequest();122crq.addClassFilter(exceptionName);123crq.enable();124125// separate thread to handle event126Thread eventHandler = new Thread() {127public void run() {128EventQueue eventQueue = debugee.VM().eventQueue();129while (!exit) {130EventSet eventSet = null;131try {132eventSet = eventQueue.remove(1000);133} catch (InterruptedException e) {134new Failure("Event handling thread interrupted:\n\t" + e);135}136if (eventSet == null) {137continue;138}139EventIterator eventIterator = eventSet.eventIterator();140while (eventIterator.hasNext()) {141Event event = eventIterator.nextEvent();142143if (event instanceof ClassPrepareEvent) {144display(" event ===>>> " + event);145exReq = evm.createExceptionRequest(146((ClassPrepareEvent )event).referenceType(),147true, false);148exReq.enable();149debugee.resume();150151} else if (event instanceof ExceptionEvent) {152display(" event ===>>> " + event);153hitEvent((ExceptionEvent )event);154exReq.disable();155debugee.resume();156exit = true;157158} else if (event instanceof VMDeathEvent) {159exit = true;160break;161} else if (event instanceof VMDisconnectEvent) {162exit = true;163break;164} else {165throw new Failure("Unexpected event received:\n\t" + event);166} // if167} // while168} // while169} // run()170}; // eventHandler171172display("Starting handling event");173eventHandler.start();174175debugee.resume();176debugee.receiveExpectedSignal(SGL_READY);177178display("\nTEST BEGINS");179display("===========");180debugee.sendSignal(SGL_LOAD);181182display("Waiting for all events received");183try {184eventHandler.join(waitTime);185} catch (InterruptedException e) {186throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"187+ e);188} finally {189crq.disable();190exReq.disable();191exit = true;192if (eventHandler.isAlive()) {193display("Interrupting event handling thread");194eventHandler.interrupt();195}196}197198if (eventCount < expectedEventCount) {199complain("expecting " + expectedEventCount200+ " breakpoint events, but "201+ eventCount + " events arrived.");202exitStatus = Consts.TEST_FAILED;203}204205display("=============");206display("TEST FINISHES\n");207debugee.sendSignal(SGL_QUIT);208}209210private void hitEvent(ExceptionEvent event) {211ThreadReference thrd = event.thread();212213display("event info:");214display("\tthread\t- " + event.thread().name());215try {216display("\tsource\t- " + event.location().sourceName());217} catch (AbsentInformationException e) {218}219display("\tmethod\t- " + event.location().method().name());220display("\tline\t- " + event.location().lineNumber());221222if (event.location().lineNumber() == tc04x001a.checkExBrkpLine) {223display("ExceptionEvent occurs on the expected line "224+ event.location().lineNumber() + " in method "225+ event.location().method().name());226} else {227complain("ExceptionEvent occurs on line " + event.location().lineNumber()228+ " in method " + event.location().method().name()229+ ", expected line number is "230+ tc04x001a.checkExBrkpLine);231exitStatus = Consts.TEST_FAILED;232}233234eventCount++;235display("");236}237}238239240