Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc05x001.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>tc05x001aClass1</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 tc05x001 {5657public final static String SGL_READY = "ready";58public final static String SGL_PERFORM = "perform";59public final static String SGL_QUIT = "quit";6061private final static String prefix = "nsk.jdi.BScenarios.singlethrd.";62private final static String debuggerName = prefix + "tc05x001";63private final static String debugeeName = debuggerName + "a";64private final static String testedClassName = debugeeName + "Class1";65private final static String methodName = "bar";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 ClassType debugeeClass;7576private static void display(String msg) {77log.display(msg);78}7980private static void complain(String msg) {81log.complain("debugger FAILURE> " + msg + "\n");82}8384public static void main(String argv[]) {85System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));86}8788public static int run(String argv[], PrintStream out) {8990exitStatus = Consts.TEST_PASSED;9192tc05x001 thisTest = new tc05x001();9394ArgumentHandler argHandler = new ArgumentHandler(argv);95log = new Log(out, argHandler);9697waitTime = argHandler.getWaitTime() * 60000;9899debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);100101try {102thisTest.execTest();103} catch (Throwable e) {104complain("Unexpected " + e);105exitStatus = Consts.TEST_FAILED;106e.printStackTrace();107} finally {108debugee.resume();109debugee.quit();110}111display("Test finished. exitStatus = " + exitStatus);112113return exitStatus;114}115116private void execTest() throws Failure {117118debugeeClass = (ClassType)debugee.classByName(debugeeName);119display("Tested class\t:" + debugeeClass.name());120121display("\nTEST BEGINS");122display("===========");123124EventSet eventSet = null;125EventIterator eventIterator = null;126Event event;127long totalTime = waitTime;128long tmp, begin = System.currentTimeMillis(),129delta = 0;130boolean exit = false;131EventRequestManager evm = debugee.getEventRequestManager();132MethodEntryRequest mthdReq = null;133134mthdReq = evm.createMethodEntryRequest();135mthdReq.addClassFilter(testedClassName);136mthdReq.enable();137138debugee.resume();139debugee.sendSignal(SGL_PERFORM);140141while (totalTime > 0 && !exit) {142if (eventIterator == null || !eventIterator.hasNext()) {143try {144eventSet = debugee.VM().eventQueue().remove(totalTime);145} catch (InterruptedException e) {146new Failure(e);147}148if (eventSet != null) {149eventIterator = eventSet.eventIterator();150} else {151eventIterator = null;152}153}154if (eventIterator != null) {155while (eventIterator.hasNext()) {156event = eventIterator.nextEvent();157// display(" event ===>>> " + event);158159if (event instanceof MethodEntryEvent) {160display(" event ===>>> " + event);161hitMethodBreakpoint((MethodEntryEvent )event);162if (eventCount > 0) {163exit = true;164evm.deleteEventRequest(mthdReq);165}166debugee.resume();167168} else if (event instanceof VMDeathEvent) {169exit = true;170break;171} else if (event instanceof VMDisconnectEvent) {172exit = true;173break;174} // if175} // while176} // if177tmp = System.currentTimeMillis();178delta = tmp - begin;179totalTime -= delta;180begin = tmp;181}182183if (totalTime <= 0 && !exit) {184complain("out of wait time...");185exitStatus = Consts.TEST_FAILED;186}187if (eventCount < expectedEventCount) {188complain("expecting " + expectedEventCount189+ " breakpoint events, but "190+ eventCount + " events arrived.");191exitStatus = Consts.TEST_FAILED;192}193194display("=============");195display("TEST FINISHES\n");196}197198private void hitMethodBreakpoint(MethodEntryEvent event) {199ThreadReference thrd = event.thread();200201display("event info:");202display("\tthread\t- " + event.thread().name());203try {204display("\tsource\t- " + event.location().sourceName());205} catch (AbsentInformationException e) {206}207display("\tmethod\t- " + event.location().method().name());208display("\tline\t- " + event.location().lineNumber());209210if (!event.method().name().equals(methodName)) {211display("the event skipped, method - " + event.method().name());212} else {213if (event.location().lineNumber() == tc05x001a.checkLastLine) {214display("MethodBreakpoint stops on the expected line "215+ event.location().lineNumber() + " in method "216+ event.method().name());217} else {218complain("MethodBreakpoint stops on line " + event.location().lineNumber()219+ " in method " + event.method().name()220+ ", expected line number is "221+ tc05x001a.checkLastLine);222exitStatus = Consts.TEST_FAILED;223}224eventCount++;225}226display("");227228}229}230231232