Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/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.multithrd;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* TC1 <br>41* Description: Line breakpoint & step <br>42* Steps: 1.Set breakpoint on line 32 <br>43* 2.Debug Main <br>44* X. Stops on line 32 <br>45* 3.Run | Step over <br>46* X. Steps to line 33 <br>47*48* When the test is starting debugee, debugger sets breakpoint at the 69th49* line (method "foo"). After the breakpoint is reached, debugger creates50* "step over" request and resumes debugee. For every hit event debugger51* checks line number of one's location. It should be 69th line for Breakpoint52* or 70th line for Step.53*54* In case, when at least one event doesn't arrive during waittime55* interval or 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.multithrd.";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 static int brkpEventCount = 0;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) {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;132133debugee.setBreakpoint(debugeeClass,134tc01x001a.brkpMethodName,135tc01x001a.brkpLineNumber);136debugee.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 BreakpointEvent) {158display(" event ===>>> " + event);159hitBreakpoint((BreakpointEvent )event);160debugee.resume();161162} else if (event instanceof StepEvent) {163display(" event ===>>> " + event);164hitStepOver((StepEvent )event);165debugee.resume();166167} else if (event instanceof VMDeathEvent) {168exit = true;169break;170} else if (event instanceof VMDisconnectEvent) {171exit = true;172break;173} // if174} // while175} // if176exit = exit || (brkpEventCount == tc01x001a.threadCount &&177stepEventCount == tc01x001a.threadCount);178tmp = System.currentTimeMillis();179delta = tmp - begin;180totalTime -= delta;181begin = tmp;182}183184if (brkpEventCount < tc01x001a.threadCount) {185if (totalTime <= 0) {186complain("out of wait time...");187}188complain("expecting " + tc01x001a.threadCount189+ " MethodBreakpoint events, but "190+ brkpEventCount + " events arrived.");191exitStatus = Consts.TEST_FAILED;192}193194display("=============");195display("TEST FINISHES\n");196}197198private void hitBreakpoint(BreakpointEvent event) {199EventRequestManager evm = debugee.getEventRequestManager();200ThreadReference thrd = event.thread();201202display("event info:");203display("\tthread\t- " + event.thread().name());204try {205display("\tsource\t- " + event.location().sourceName());206} catch (AbsentInformationException e) {207}208display("\tmethod\t- " + event.location().method().name());209display("\tline\t- " + event.location().lineNumber());210211if (event.location().lineNumber() != tc01x001a.checkBrkpLine) {212complain("BreakpointEvent stops on line " + event.location().lineNumber()213+ ", expected line number is " + tc01x001a.checkBrkpLine);214exitStatus = Consts.TEST_FAILED;215} else {216display("BreakpointEvent stops on the expected line "217+ event.location().lineNumber());218}219220display("");221StepRequest step = evm.createStepRequest(thrd, StepRequest.STEP_LINE,222StepRequest.STEP_OVER);223brkpEventCount++;224step.enable();225}226227private void hitStepOver(StepEvent event) {228EventRequestManager evm = debugee.getEventRequestManager();229230display("event info:");231display("\tthread\t- " + event.thread().name());232try {233display("\tsource\t- " + event.location().sourceName());234} catch (AbsentInformationException e) {235}236display("\tmethod\t- " + event.location().method().name());237display("\tline\t- " + event.location().lineNumber());238239if (event.location().lineNumber() != tc01x001a.checkStepLine) {240complain("StepEvent steps to line " + event.location().lineNumber()241+ ", expected line number is " + tc01x001a.checkStepLine);242exitStatus = Consts.TEST_FAILED;243} else {244display("StepEvent steps to the expected line "245+ event.location().lineNumber());246}247display("");248249evm.deleteEventRequest(event.request());250stepEventCount++;251}252}253254255