Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/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.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>tc03x001aClass1</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 tc03x001 {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 + "tc03x001";63private final static String debugeeName = debuggerName + "a";64private final static String testedClassName = debugeeName + "Class1";6566private static int exitStatus;67private static Log log;68private static Debugee debugee;69private static long waitTime;70private final static int expectedEventCount = 1;71private static int eventCount = 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;9091tc03x001 thisTest = new tc03x001();9293ArgumentHandler argHandler = new ArgumentHandler(argv);94log = new Log(out, argHandler);9596waitTime = argHandler.getWaitTime() * 60000;9798debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);99100try {101thisTest.execTest();102} catch (Throwable e) {103complain("Unexpected " + e);104exitStatus = Consts.TEST_FAILED;105e.printStackTrace();106} finally {107debugee.resume();108debugee.quit();109}110display("Test finished. exitStatus = " + exitStatus);111112return exitStatus;113}114115private void execTest() throws Failure {116117debugeeClass = (ClassType)debugee.classByName(debugeeName);118display("Tested class\t:" + debugeeClass.name());119120display("\nTEST BEGINS");121display("===========");122123EventSet eventSet = null;124EventIterator eventIterator = null;125Event event;126long totalTime = waitTime;127long tmp, begin = System.currentTimeMillis(),128delta = 0;129boolean exit = false;130131EventRequestManager evm = debugee.getEventRequestManager();132MethodEntryRequest mthdReq = evm.createMethodEntryRequest();133mthdReq.addClassFilter(testedClassName);134mthdReq.enable();135136debugee.resume();137debugee.sendSignal(SGL_PERFORM);138139while (totalTime > 0 && !exit) {140if (eventIterator == null || !eventIterator.hasNext()) {141try {142eventSet = debugee.VM().eventQueue().remove(totalTime);143} catch (InterruptedException e) {144new Failure(e);145}146if (eventSet != null) {147eventIterator = eventSet.eventIterator();148} else {149eventIterator = null;150}151}152if (eventIterator != null) {153while (eventIterator.hasNext()) {154event = eventIterator.nextEvent();155// display(" event ===>>> " + event);156157if (event instanceof MethodEntryEvent) {158display(" event ===>>> " + event);159hitClassBreakpoint((MethodEntryEvent )event);160debugee.resume();161exit = true;162163} else if (event instanceof VMDeathEvent) {164exit = true;165break;166} else if (event instanceof VMDisconnectEvent) {167exit = true;168break;169} // if170} // while171} // if172tmp = System.currentTimeMillis();173delta = tmp - begin;174totalTime -= delta;175begin = tmp;176}177178if (eventCount < expectedEventCount) {179if (totalTime <= 0) {180complain("out of wait time...");181}182complain("expecting " + expectedEventCount183+ " breakpoint events, but "184+ eventCount + " events arrived.");185exitStatus = Consts.TEST_FAILED;186}187188display("=============");189display("TEST FINISHES\n");190}191192private void hitClassBreakpoint(MethodEntryEvent event) {193ThreadReference thrd = event.thread();194195display("event info:");196display("\tthread\t- " + event.thread().name());197try {198display("\tsource\t- " + event.location().sourceName());199} catch (AbsentInformationException e) {200}201display("\tmethod\t- " + event.location().method().name());202display("\tline\t- " + event.location().lineNumber());203204if (event.location().lineNumber() == tc03x001a.checkLastLine) {205display("ClassBreakpoint stops on the expected line "206+ event.location().lineNumber() + " in method "207+ event.method().name());208} else {209complain("ClassBreakpoint stops on line " + event.location().lineNumber()210+ " in method " + event.method().name()211+ ", expected line number is "212+ tc03x001a.checkLastLine);213exitStatus = Consts.TEST_FAILED;214}215216eventCount++;217218display("");219220}221}222223224