Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc02x004.java
41160 views
/*1* Copyright (c) 2002, 2019, 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 jdk.test.lib.Utils;26import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import com.sun.jdi.request.*;32import com.sun.jdi.event.*;3334import java.util.*;35import java.io.*;3637/**38* This test is from the group of so-called Borland's scenarios and39* implements the following test case: <br>40* Suite 2 - Breakpoints (multiple threads) <br>41* Test case: TC2 <br>42* Description: Class breakpoint <br>43* Steps: 1.Add class breakpoint: singlethread.Class1 <br>44* 2.Debug Main <br>45* X. Stops on line 13 in Class1.java <br>46*47* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.48* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's49* location. It should be 73th line, that is constructor of <code>tc02x004aClass1</code>50* class. Every thread must generate <code>MethodEntryEvent</code>.51*52* In case, when at least one event doesn't arrive during waittime53* interval or line number of event is wrong, test fails.54*/5556public class tc02x004 {5758public final static String SGL_READY = "ready";59public final static String SGL_PERFORM = "perform";60public final static String SGL_QUIT = "quit";6162private final static String prefix = "nsk.jdi.BScenarios.multithrd.";63private final static String debuggerName = prefix + "tc02x004";64private final static String debugeeName = debuggerName + "a";65private final static String testedClassName = debugeeName + "Class1";6667private static int exitStatus;68private static Log log;69private static Debugee debugee;70private static long waitTime;71private static int brkpEventCount = 0;72MethodEntryRequest mthdReq;73EventRequestManager evm;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;9293tc02x004 thisTest = new tc02x004();9495ArgumentHandler argHandler = new ArgumentHandler(argv);96log = new Log(out, argHandler);9798waitTime = Utils.adjustTimeout(argHandler.getWaitTime() * 60000);99100Binder binder = new Binder(argHandler, log);101debugee = binder.bindToDebugee(debugeeName);102debugee.redirectStderr(log.getOutStream());103thisTest.evm = debugee.getEventRequestManager();104105try {106thisTest.execTest();107} catch (Throwable e) {108complain("Unexpected " + e);109exitStatus = Consts.TEST_FAILED;110e.printStackTrace();111thisTest.evm.deleteEventRequest(thisTest.mthdReq);112} finally {113debugee.resume();114}115display("Test finished. exitStatus = " + exitStatus);116117debugee.endDebugee();118return exitStatus;119}120121private void execTest() throws Failure {122123display("\nTEST BEGINS");124display("===========");125debugee.resume();126127EventSet eventSet = null;128EventIterator eventIterator = null;129Event event;130long totalTime = waitTime;131long tmp, begin = System.currentTimeMillis(),132delta = 0;133boolean exit = false;134135mthdReq = evm.createMethodEntryRequest();136mthdReq.addClassFilter(testedClassName);137mthdReq.enable();138debugee.resume();139140while (totalTime > 0 && !exit) {141if (eventIterator == null || !eventIterator.hasNext()) {142try {143eventSet = debugee.VM().eventQueue().remove(totalTime);144} catch (InterruptedException e) {145new Failure(e);146}147if (eventSet != null) {148eventIterator = eventSet.eventIterator();149} else {150eventIterator = null;151}152}153if (eventIterator != null) {154while (eventIterator.hasNext()) {155event = eventIterator.nextEvent();156157if (event instanceof MethodEntryEvent) {158display(" event ===>>> " + (brkpEventCount+1) + " MethodEntryEvent arrived");159hitClassBreakpoint((MethodEntryEvent )event);160debugee.resume();161162} else if (event instanceof VMDeathEvent) {163exit = true;164break;165} else if (event instanceof VMDisconnectEvent) {166exit = true;167break;168} // if169} // while170} // if171exit = exit || (brkpEventCount == tc02x004a.threadCount);172tmp = System.currentTimeMillis();173delta = tmp - begin;174totalTime -= delta;175begin = tmp;176}177178if (totalTime <= 0) {179complain("out of wait time...");180exitStatus = Consts.TEST_FAILED;181}182if (brkpEventCount < tc02x004a.threadCount) {183complain("expecting " + tc02x004a.threadCount184+ " breakpoint events, but "185+ brkpEventCount + " events arrived.");186exitStatus = Consts.TEST_FAILED;187}188189display("=============");190display("TEST FINISHES\n");191}192193private void hitClassBreakpoint(MethodEntryEvent event) {194ThreadReference thrd = event.thread();195196display("event info:");197display("\tthread\t- " + event.thread().name());198try {199display("\tsource\t- " + event.location().sourceName());200} catch (AbsentInformationException e) {201}202display("\tmethod\t- " + event.location().method().name());203display("\tline\t- " + event.location().lineNumber());204205display("thread:\t" + event.thread().name());206try {207display("source:\t" + event.location().sourceName());208} catch (AbsentInformationException e) {209}210display("method:\t" + event.location().method().name());211display("line:\t" + event.location().lineNumber());212if (event.location().lineNumber() == tc02x004a.checkClassBrkpLine) {213display("ClassBreakpoint stops on the expected line "214+ event.location().lineNumber() + " in method "215+ event.method().name());216} else {217complain("ClassBreakpoint stops on line " + event.location().lineNumber()218+ " in method " + event.method().name()219+ ", expected line number is "220+ tc02x004a.checkClassBrkpLine);221exitStatus = Consts.TEST_FAILED;222}223224display("");225226brkpEventCount++;227}228}229230231