Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc01x001.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 48th 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>addClassFilter</code>. For the third <code>StepEvent</code> debugger53* 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 tc01x001 {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 + "tc01x001";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;9293tc01x001 thisTest = new tc01x001();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,137tc01x001a.brkpMethodName,138tc01x001a.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.addClassFilter(prefix + "*");167step.enable();168debugee.resume();169170} else if (event instanceof StepEvent) {171display(" event ===>>> " + event);172hitStepInto((StepEvent )event);173if (stepEventCount >= expectedStepEventCount) {174evm.deleteEventRequest(step);175}176debugee.resume();177178} else if (event instanceof VMDeathEvent) {179exit = true;180break;181} else if (event instanceof VMDisconnectEvent) {182exit = true;183break;184} // if185} // while186} // if187exit = exit || (stepEventCount == expectedStepEventCount);188tmp = System.currentTimeMillis();189delta = tmp - begin;190totalTime -= delta;191begin = tmp;192}193194if (stepEventCount < expectedStepEventCount) {195if (totalTime <= 0) {196complain("out of wait time...");197}198complain("expecting " + expectedStepEventCount199+ " step events, but "200+ stepEventCount + " events arrived.");201exitStatus = Consts.TEST_FAILED;202}203204display("=============");205display("TEST FINISHES\n");206}207208private void hitBreakpoint(BreakpointEvent event) {209display("BreakpointEvent arrived. Location - "210+ event.location().lineNumber() + " line");211display("");212}213214private void hitStepInto(StepEvent event) {215stepEventCount++;216217display("event info:");218display("\tthread\t- " + event.thread().name());219try {220display("\tsource\t- " + event.location().sourceName());221} catch (AbsentInformationException e) {222}223display("\tmethod\t- " + event.location().method().name());224display("\tline\t- " + event.location().lineNumber());225226if (stepEventCount == expectedStepEventCount) {227if (event.location().lineNumber() != tc01x001a.checkLastLine) {228complain("StepEvent steps to line " + event.location().lineNumber()229+ ", expected line number is "230+ tc01x001a.checkLastLine);231exitStatus = Consts.TEST_FAILED;232} else {233display("StepEvent steps to the expected line "234+ event.location().lineNumber());235}236}237display("");238}239}240241242