Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/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.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* Test case: TC2 <br>41* Description: Class breakpoint <br>42* Steps: 1.Add class breakpoint: singlethread.Class1 <br>43* 2.Debug Main <br>44* X. Stops on line 13 in Class1.java <br>45*46* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.47* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's48* location. It should be 73th line, that is constructor of <code>tc02x001aClass1</code>49* class. Every thread must generate <code>MethodEntryEvent</code>.50*51* In case, when at least one event doesn't arrive during waittime52* interval or line number of event is wrong, test fails.53*/5455public class tc02x001 {5657public final static String SGL_READY = "ready";58public final static String SGL_PERFORM = "perform";59public final static String SGL_QUIT = "quit";6061private final static String prefix = "nsk.jdi.BScenarios.multithrd.";62private final static String debuggerName = prefix + "tc02x001";63private final static String debugeeName = debuggerName + "a";64private final static String testedClassName = debugeeName + "Class1";6566private static int exitStatus;67private static Log log;68private static Debugee debugee;69private static long waitTime;70private static int brkpEventCount = 0;7172private ClassType debugeeClass;7374private static void display(String msg) {75log.display(msg);76}7778private static void complain(String msg) {79log.complain("debugger FAILURE> " + msg + "\n");80}8182public static void main(String argv[]) {83System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));84}8586public static int run(String argv[], PrintStream out) {8788exitStatus = Consts.TEST_PASSED;8990tc02x001 thisTest = new tc02x001();9192ArgumentHandler argHandler = new ArgumentHandler(argv);93log = new Log(out, argHandler);9495waitTime = argHandler.getWaitTime() * 60000;9697debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);9899try {100thisTest.execTest();101} catch (Throwable e) {102complain("Unexpected " + e);103exitStatus = Consts.TEST_FAILED;104e.printStackTrace();105} finally {106debugee.resume();107debugee.quit();108}109display("Test finished. exitStatus = " + exitStatus);110111return exitStatus;112}113114private void execTest() throws Failure {115116debugeeClass = (ClassType)debugee.classByName(debugeeName);117display("Tested class\t:" + debugeeClass.name());118119display("\nTEST BEGINS");120display("===========");121122EventSet eventSet = null;123EventIterator eventIterator = null;124Event event;125long totalTime = waitTime;126long tmp, begin = System.currentTimeMillis(),127delta = 0;128boolean exit = false;129130EventRequestManager evm = debugee.getEventRequestManager();131MethodEntryRequest mthdReq = evm.createMethodEntryRequest();132mthdReq.addClassFilter(testedClassName);133mthdReq.enable();134135debugee.resume();136debugee.sendSignal(SGL_PERFORM);137138while (totalTime > 0 && !exit) {139if (eventIterator == null || !eventIterator.hasNext()) {140try {141eventSet = debugee.VM().eventQueue().remove(totalTime);142} catch (InterruptedException e) {143new Failure(e);144}145if (eventSet != null) {146eventIterator = eventSet.eventIterator();147} else {148eventIterator = null;149}150}151if (eventIterator != null) {152while (eventIterator.hasNext()) {153event = eventIterator.nextEvent();154155if (event instanceof MethodEntryEvent) {156hitClassBreakpoint((MethodEntryEvent )event);157display(" event ===>>> " + (brkpEventCount+1) + " MethodEntryEvent arrived");158debugee.resume();159160} else if (event instanceof VMDeathEvent) {161exit = true;162break;163} else if (event instanceof VMDisconnectEvent) {164exit = true;165break;166} // if167} // while168} // if169exit = exit || (brkpEventCount == tc02x001a.threadCount);170tmp = System.currentTimeMillis();171delta = tmp - begin;172totalTime -= delta;173begin = tmp;174}175176if (brkpEventCount < tc02x001a.threadCount) {177if (totalTime <= 0) {178complain("out of wait time...");179}180complain("expecting " + tc02x001a.threadCount181+ " MethodBreakpoint events, but "182+ brkpEventCount + " events arrived.");183exitStatus = Consts.TEST_FAILED;184}185186display("=============");187display("TEST FINISHES\n");188}189190private void hitClassBreakpoint(MethodEntryEvent event) {191ThreadReference thrd = event.thread();192193display("event info:");194display("\tthread\t- " + event.thread().name());195try {196display("\tsource\t- " + event.location().sourceName());197} catch (AbsentInformationException e) {198}199display("\tmethod\t- " + event.location().method().name());200display("\tline\t- " + event.location().lineNumber());201202if (event.location().lineNumber() == tc02x001a.checkClassBrkpLine) {203display("ClassBreakpoint stops on the expected line "204+ event.location().lineNumber() + " in method "205+ event.method().name());206} else {207complain("ClassBreakpoint stops on line " + event.location().lineNumber()208+ " in method " + event.method().name()209+ ", expected line number is "210+ tc02x001a.checkClassBrkpLine);211exitStatus = Consts.TEST_FAILED;212}213214display("");215216brkpEventCount++;217}218}219220221