Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc03x002.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>tc03x002aClass1</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 tc03x002 {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 + "tc03x002";64private final static String debugeeName = debuggerName + "a";65private final static String testedClassName = debugeeName + "Class1";6667private static int exitStatus;68private static Log log;69private static Debugee debugee;70private static long waitTime;71private static int eventCount = 0;72private final static int expectedEventCount = 2;7374private EventRequestManager evm = null;75private MethodEntryRequest mthdReq = 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;93tc03x002 thisTest = new tc03x002();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 (Exception 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(testedClassName);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) {143display(" event ===>>> " + event);144mthdReq = evm.createMethodEntryRequest();145mthdReq.addClassFilter(testedClassName);146mthdReq.enable();147debugee.resume();148149} else if (event instanceof MethodEntryEvent) {150display(" event ===>>> " + event);151hitEvent((MethodEntryEvent )event);152debugee.resume();153154} else if (event instanceof VMDeathEvent) {155exit = true;156break;157} else if (event instanceof VMDisconnectEvent) {158exit = true;159break;160} else {161throw new Failure("Unexpected event:\n\t" + event);162} // if163exit = exit || (eventCount >= expectedEventCount);164} // while165} // while166} // run()167}; // eventHadler168169display("Starting handling event");170eventHandler.start();171172debugee.resume();173debugee.receiveExpectedSignal(SGL_READY);174175display("\nTEST BEGINS");176display("===========");177debugee.sendSignal(SGL_LOAD);178179display("Waiting for all events received");180try {181eventHandler.join(waitTime);182} catch (InterruptedException e) {183throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"184+ e);185} finally {186crq.disable();187mthdReq.disable();188exit = true;189if (eventHandler.isAlive()) {190display("Interrupting event handling thread");191eventHandler.interrupt();192}193}194195if (eventCount < expectedEventCount) {196complain("Expecting " + expectedEventCount197+ " MethodEntryEvents, but "198+ eventCount + " events arrived.");199exitStatus = Consts.TEST_FAILED;200}201202display("=============");203display("TEST FINISHES\n");204debugee.sendSignal(SGL_QUIT);205}206207private void hitEvent(MethodEntryEvent event) {208ThreadReference thrd = event.thread();209210display("event info:");211display("\tthread\t- " + event.thread().name());212try {213display("\tsource\t- " + event.location().sourceName());214} catch (AbsentInformationException e) {215}216display("\tmethod\t- " + event.location().method().name());217display("\tline\t- " + event.location().lineNumber());218219eventCount++;220if (event.location().lineNumber() == tc03x002a.checkLastLine1 ||221event.location().lineNumber() == tc03x002a.checkLastLine2) {222display("MethodEntryEvent occurs on the expected line "223+ event.location().lineNumber() + " in method "224+ event.method().name());225} else {226complain("MethodEntryEvent occurs on line " + event.location().lineNumber()227+ " in method " + event.method().name()228+ ", expected line numbers are "229+ tc03x002a.checkLastLine1 + " or "230+ tc03x002a.checkLastLine2);231exitStatus = Consts.TEST_FAILED;232}233234display("");235}236}237238239