Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc03x001.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: TC341* Description: Exception breakpoint42* Steps: 1.Set caught exception breakpoint on class43* javax.sound.midi.MidiUnavailableException44* 2.Debug Main45* X. Stops on line 42 in Main.java46*47* When the test is starting debugee, debugger creates <code>ExceptionRequest</code>.48* After <code>ExceptionEvent</code> arrived, debugger checks line number of one's49* location. It should be 74th line, that is throwing <code>tc03x001aException</code>.50* Every thread must generate <code>ExceptionEvent</code>.51*52* In case, when at least one event doesn't arrive during waittime53* interval or line number of event is wrong, test fails.54*/5556public class tc03x001 {5758public final static String SGL_READY = "ready";59public final static String SGL_LOAD = "load";60public final static String SGL_PERFORM = "perform";61public final static String SGL_QUIT = "quit";6263private final static String prefix = "nsk.jdi.BScenarios.multithrd.";64private final static String debuggerName = prefix + "tc03x001";65private final static String debugeeName = debuggerName + "a";66private final static String exceptionName = debugeeName + "Exception";6768private static int exitStatus;69private static Log log;70private static Debugee debugee;71private static long waitTime;72private static int eventCount = 0;7374private EventRequestManager evm = null;75private ExceptionRequest exReq = null;76private volatile boolean exit = false;7778private static void display(String msg) {79log.display(msg);80}8182private static void complain(String msg) {83log.complain("debugger FAILURE> " + msg + "\n");84}8586public static void main(String argv[]) {87System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));88}8990public static int run(String argv[], PrintStream out) {9192exitStatus = Consts.TEST_PASSED;93tc03x001 thisTest = new tc03x001();9495ArgumentHandler argHandler = new ArgumentHandler(argv);96log = new Log(out, argHandler);97waitTime = argHandler.getWaitTime() * 60000;9899Binder binder = new Binder(argHandler, log);100debugee = binder.bindToDebugee(debugeeName);101IOPipe pipe = debugee.createIOPipe();102103try {104thisTest.execTest();105} catch (Throwable e) {106complain("Unexpected " + e);107exitStatus = Consts.TEST_FAILED;108e.printStackTrace();109} finally {110debugee.endDebugee();111}112display("Test finished. exitStatus = " + exitStatus);113114return exitStatus;115}116117private void execTest() throws Failure {118evm = debugee.getEventRequestManager();119120ClassPrepareRequest crq = evm.createClassPrepareRequest();121crq.addClassFilter(exceptionName);122crq.enable();123124// event handling thread125Thread eventHandler = new Thread() {126public void run() {127EventQueue eventQueue = debugee.VM().eventQueue();128EventSet eventSet = null;129while (!exit) {130try {131eventSet = eventQueue.remove(1000);132} catch (InterruptedException e) {133new Failure("Event handling thread interrupted:\n\t" + e);134}135if (eventSet == null) {136continue;137}138EventIterator eventIterator = eventSet.eventIterator();139while (eventIterator.hasNext()) {140Event event = eventIterator.nextEvent();141142if (event instanceof ClassPrepareEvent) {143exReq = evm.createExceptionRequest(144((ClassPrepareEvent )event).referenceType(),145true, false);146exReq.enable();147debugee.resume();148149} else if (event instanceof ExceptionEvent) {150hitEvent((ExceptionEvent )event);151debugee.resume();152153} else if (event instanceof VMDeathEvent) {154exit = true;155} else if (event instanceof VMDisconnectEvent) {156exit = true;157break;158} else {159throw new Failure("Unexpected event:\n\t" + event);160} // if161exit = exit || (eventCount >= tc03x001a.threadCount);162} // while163} // while164} // run()165}; // eventHadler166167display("Starting handling event");168eventHandler.start();169170debugee.resume();171debugee.receiveExpectedSignal(SGL_READY);172173display("\nTEST BEGINS");174display("===========");175debugee.sendSignal(SGL_LOAD);176177display("Waiting for all events received");178try {179eventHandler.join(waitTime);180} catch (InterruptedException e) {181throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"182+ e);183} finally {184crq.disable();185exReq.disable();186exit = true;187if (eventHandler.isAlive()) {188display("Interrupting event handling thread");189eventHandler.interrupt();190}191}192193if (eventCount < tc03x001a.threadCount) {194complain("expecting " + tc03x001a.threadCount195+ " ExceptionEvents, but "196+ eventCount + " events arrived.");197exitStatus = Consts.TEST_FAILED;198}199display("=============");200display("TEST FINISHES\n");201debugee.sendSignal(SGL_QUIT);202}203204private void hitEvent(ExceptionEvent event) {205ThreadReference thrd = event.thread();206207display("event info:");208display("\tthread\t- " + event.thread().name());209try {210display("\tsource\t- " + event.location().sourceName());211} catch (AbsentInformationException e) {212}213display("\tmethod\t- " + event.location().method().name());214display("\tline\t- " + event.location().lineNumber());215216if (event.location().lineNumber() == tc03x001a.checkExBrkpLine) {217display("ExceptionEvent occurs on the expected line "218+ event.location().lineNumber() + " in method "219+ event.location().method().name());220} else {221complain("ExceptionEvent occurs stops on line " + event.location().lineNumber()222+ " in method " + event.location().method().name()223+ ", expected line number is "224+ tc03x001a.checkExBrkpLine);225exitStatus = Consts.TEST_FAILED;226}227228display("");229230eventCount++;231}232}233234235