Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/singlethrd/tc02x001.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: TC241* Description: Line breakpoint & step over42* Steps: 1.Set breakpoint on line 1943* 2.Debug Main44* X. Stops on line 1945* 3.Run | Step over three times46* X. Stops on line 22 in Main.java47*48* When the test is starting debugee, debugger sets breakpoint at49* the 49th line (method "performTest").50* After the breakpoint is reached, debugger creates "step over" request51* and resumes debugee. For the third <code>StepEvent</code> debugger checks line52* number of one's location. It should be 52th line.53*54* In case, when line number of event is wrong, test fails.55*/5657public class tc02x001 {5859public final static String SGL_READY = "ready";60public final static String SGL_PERFORM = "perform";61public final static String SGL_QUIT = "quit";6263private final static String prefix = "nsk.jdi.BScenarios.singlethrd.";64private final static String debuggerName = prefix + "tc02x001";65private final static String debugeeName = debuggerName + "a";6667private static int exitStatus;68private static Log log;69private static Debugee debugee;70private static long waitTime;71private final static int expectedStepEventCount = 3;72private static int stepEventCount = 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;9192tc02x001 thisTest = new tc02x001();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);119120display("\nTEST BEGINS");121display("===========");122123display("Tested class\t:" + debugeeClass.name());124125EventSet eventSet = null;126EventIterator eventIterator = null;127Event event;128long totalTime = waitTime;129long tmp, begin = System.currentTimeMillis(),130delta = 0;131boolean exit = false;132EventRequestManager evm = debugee.getEventRequestManager();133StepRequest step = null;134135debugee.setBreakpoint(debugeeClass,136tc02x001a.brkpMethodName,137tc02x001a.brkpLineNumber);138debugee.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 BreakpointEvent) {160display(" event ===>>> " + event);161hitBreakpoint((BreakpointEvent )event);162step = evm.createStepRequest(((BreakpointEvent )event).thread(),163StepRequest.STEP_LINE,164StepRequest.STEP_OVER);165step.enable();166debugee.resume();167168} else if (event instanceof StepEvent) {169display(" event ===>>> " + event);170hitStepOver((StepEvent )event);171if (stepEventCount >= expectedStepEventCount) {172evm.deleteEventRequest(step);173}174debugee.resume();175176} else if (event instanceof VMDeathEvent) {177exit = true;178break;179} else if (event instanceof VMDisconnectEvent) {180exit = true;181break;182} // if183} // while184} // if185exit = exit || (stepEventCount == expectedStepEventCount);186tmp = System.currentTimeMillis();187delta = tmp - begin;188totalTime -= delta;189begin = tmp;190}191192if (stepEventCount < expectedStepEventCount) {193if (totalTime <= 0) {194complain("out of wait time...");195}196complain("expecting " + expectedStepEventCount197+ " step events, but "198+ stepEventCount + " events arrived.");199exitStatus = Consts.TEST_FAILED;200}201202display("=============");203display("TEST FINISHES\n");204}205206private void hitBreakpoint(BreakpointEvent event) {207display("BreakpointEvent arrived. Location - "208+ event.location().lineNumber() + " line");209display("");210}211212private void hitStepOver(StepEvent event) {213stepEventCount++;214215display("event info:");216display("\tthread\t- " + event.thread().name());217try {218display("\tsource\t- " + event.location().sourceName());219} catch (AbsentInformationException e) {220}221display("\tmethod\t- " + event.location().method().name());222display("\tline\t- " + event.location().lineNumber());223224if (stepEventCount == expectedStepEventCount) {225if (event.location().lineNumber() != tc02x001a.checkLastLine) {226complain("StepEvent steps to line " + event.location().lineNumber()227+ ", expected line number is "228+ tc02x001a.checkLastLine);229exitStatus = Consts.TEST_FAILED;230} else {231display("StepEvent steps to the expected line "232+ event.location().lineNumber());233}234}235display("");236}237}238239240