Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc01x002.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:39* Suite 1 - Breakpoints (single threads)40* Test case: TC141* Description: Line breakpoint & step into42* Steps: 1.Set breakpoint on line 1943* 2.Debug Main44* X. Stops on line 1945* 3.Run | Step into three times46* X. Steps into Class1 constructor47*48* When the test is starting debugee, debugger sets breakpoint at49* the 49th line (method <code>performTest</code>).50* After the breakpoint is reached, debugger creates "step into" request51* and resumes debugee. <code>StepRequest</code> is created with specified52* <code>addClassExclusionFilter</code>. For the third <code>StepEvent</code>53* debugger checks line number of one's location. It should be 56th line.54*55* In case, when line number of event is wrong, test fails.56*/5758public class tc01x002 {5960public final static String SGL_READY = "ready";61public final static String SGL_PERFORM = "perform";62public final static String SGL_QUIT = "quit";6364private final static String prefix = "nsk.jdi.BScenarios.singlethrd.";65private final static String debuggerName = prefix + "tc01x002";66private final static String debugeeName = debuggerName + "a";6768private static int exitStatus;69private static Log log;70private static Debugee debugee;71private static long waitTime;72private final static int expectedStepEventCount = 3;73private static int stepEventCount = 0;7475private ClassType debugeeClass;7677private static void display(String msg) {78log.display(msg);79}8081private static void complain(String msg) {82log.complain("debugger FAILURE> " + msg + "\n");83}8485public static void main(String argv[]) {86System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));87}8889public static int run(String argv[], PrintStream out) {9091exitStatus = Consts.TEST_PASSED;9293tc01x002 thisTest = new tc01x002();9495ArgumentHandler argHandler = new ArgumentHandler(argv);96log = new Log(out, argHandler);9798waitTime = argHandler.getWaitTime() * 60000;99100debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);101102try {103thisTest.execTest();104} catch (Throwable e) {105complain("Unexpected " + e);106exitStatus = Consts.TEST_FAILED;107e.printStackTrace();108} finally {109debugee.resume();110debugee.quit();111}112display("Test finished. exitStatus = " + exitStatus);113114return exitStatus;115}116117private void execTest() throws Failure {118119debugeeClass = (ClassType)debugee.classByName(debugeeName);120121display("\nTEST BEGINS");122display("===========");123124display("Tested class\t:" + debugeeClass.name());125126EventSet eventSet = null;127EventIterator eventIterator = null;128Event event;129long totalTime = waitTime;130long tmp, begin = System.currentTimeMillis(),131delta = 0;132boolean exit = false;133EventRequestManager evm = debugee.getEventRequestManager();134StepRequest step = null;135136debugee.setBreakpoint(debugeeClass,137tc01x002a.brkpMethodName,138tc01x002a.brkpLineNumber);139debugee.resume();140debugee.sendSignal(SGL_PERFORM);141142while (totalTime > 0 && !exit) {143if (eventIterator == null || !eventIterator.hasNext()) {144try {145eventSet = debugee.VM().eventQueue().remove(totalTime);146} catch (InterruptedException e) {147new Failure(e);148}149if (eventSet != null) {150eventIterator = eventSet.eventIterator();151} else {152eventIterator = null;153}154}155if (eventIterator != null) {156while (eventIterator.hasNext()) {157event = eventIterator.nextEvent();158// display(" event ===>>> " + event);159160if (event instanceof BreakpointEvent) {161display(" event ===>>> " + event);162hitBreakpoint((BreakpointEvent )event);163step = evm.createStepRequest(((BreakpointEvent )event).thread(),164StepRequest.STEP_LINE,165StepRequest.STEP_INTO);166step.addClassExclusionFilter("nsk.share.*");167step.addClassExclusionFilter("java.*");168step.addClassExclusionFilter("sun.*");169step.addClassExclusionFilter("oracle.*");170step.addClassExclusionFilter("jdk.jfr.*");171step.addClassExclusionFilter("com.oracle.*");172step.addClassExclusionFilter("jdk.internal.*");173step.enable();174debugee.resume();175176} else if (event instanceof StepEvent) {177display(" event ===>>> " + event);178hitStepInto((StepEvent )event);179if (stepEventCount >= expectedStepEventCount) {180evm.deleteEventRequest(step);181}182debugee.resume();183184} else if (event instanceof VMDeathEvent) {185exit = true;186break;187} else if (event instanceof VMDisconnectEvent) {188exit = true;189break;190} // if191} // while192} // if193exit = exit || (stepEventCount == expectedStepEventCount);194tmp = System.currentTimeMillis();195delta = tmp - begin;196totalTime -= delta;197begin = tmp;198}199200if (stepEventCount < expectedStepEventCount) {201if (totalTime <= 0) {202complain("out of wait time...");203}204complain("expecting " + expectedStepEventCount205+ " step events, but "206+ stepEventCount + " events arrived.");207exitStatus = Consts.TEST_FAILED;208}209210display("=============");211display("TEST FINISHES\n");212}213214private void hitBreakpoint(BreakpointEvent event) {215display("BreakpointEvent arrived. Location - "216+ event.location().lineNumber() + " line");217display("");218}219220private void hitStepInto(StepEvent event) {221stepEventCount++;222223display("event info:");224display("\tthread\t- " + event.thread().name());225try {226display("\tsource\t- " + event.location().sourceName());227} catch (AbsentInformationException e) {228}229display("\tmethod\t- " + event.location().method().name());230display("\tline\t- " + event.location().lineNumber());231232if (stepEventCount == expectedStepEventCount) {233if (event.location().lineNumber() != tc01x002a.checkLastLine) {234complain("StepEvent steps to line " + event.location().lineNumber()235+ ", expected line number is "236+ tc01x002a.checkLastLine);237exitStatus = Consts.TEST_FAILED;238} else {239display("StepEvent steps to the expected line "240+ event.location().lineNumber());241}242}243display("");244}245}246247248