Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/deleteEventRequest/delevtreq002.java
41161 views
/*1* Copyright (c) 2001, 2020, 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.EventRequestManager.deleteEventRequest;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.event.*;31import com.sun.jdi.request.*;3233import java.util.*;34import java.io.*;3536/**37* The test for the implementation of an object of the type <BR>38* EventRequestManager. <BR>39* <BR>40* The test checks that results of the method <BR>41* <code>com.sun.jdi.EventRequestManager.deleteEventRequest()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on the following assertion: <BR>45* Once the eventRequest is deleted, no operations <BR>46* (for example, EventRequest.setEnabled(boolean)) are permitted - <BR>47* attempts to do so will generally cause <BR>48* an InvalidRequestStateException. <BR>49* Note: only operations specified to throw InvalidRequestStateException <BR>50* are not permitted. <BR>51* Testcases unclude all 12 subclasses of EventRequest created by <BR>52* EventRequestManager. <BR>53* <BR>54* The test has three phases and works as follows. <BR>55* <BR>56* In first phase, <BR>57* upon launching debuggee's VM which will be suspended, <BR>58* a debugger waits for the VMStartEvent within a predefined <BR>59* time interval. If no the VMStartEvent received, the test is FAILED. <BR>60* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>61* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>62* and waits for the event within the predefined time interval. <BR>63* If no the ClassPrepareEvent received, the test is FAILED. <BR>64* Upon getting the ClassPrepareEvent, <BR>65* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>66* within debuggee's special methodForCommunication(). <BR>67* <BR>68* In second phase to check the assertion, <BR>69* the debugger and the debuggee perform the following. <BR>70* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>71* - The debuggee prepares testcases and invokes <BR>72* the methodForCommunication to be suspended and <BR>73* to inform the debugger with the event. <BR>74* - Upon getting the BreakpointEvent, <BR>75* the debugger performs the checks required. <BR>76* <BR>77* In third phase, at the end of the test, the debuggee changes <BR>78* the value of the "instruction" which the debugger and debuggee <BR>79* use to inform each other of needed actions, and both end. <BR>80* <BR>81*/8283public class delevtreq002 extends JDIBase {8485public static void main (String argv[]) {8687int result = run(argv, System.out);8889System.exit(result + PASS_BASE);90}9192public static int run (String argv[], PrintStream out) {9394int exitCode = new delevtreq002().runThis(argv, out);9596if (exitCode != PASSED) {97System.out.println("TEST FAILED");98}99return testExitCode;100}101102// ************************************************ test parameters103104private String debuggeeName =105"nsk.jdi.EventRequestManager.deleteEventRequest.delevtreq002a";106107//====================================================== test program108109private int runThis (String argv[], PrintStream out) {110111argsHandler = new ArgumentHandler(argv);112logHandler = new Log(out, argsHandler);113Binder binder = new Binder(argsHandler, logHandler);114115waitTime = argsHandler.getWaitTime() * 60000;116117try {118log2("launching a debuggee :");119log2(" " + debuggeeName);120if (argsHandler.verbose()) {121debuggee = binder.bindToDebugee(debuggeeName + " -vbs");122} else {123debuggee = binder.bindToDebugee(debuggeeName);124}125if (debuggee == null) {126log3("ERROR: no debuggee launched");127return FAILED;128}129log2("debuggee launched");130} catch ( Exception e ) {131log3("ERROR: Exception : " + e);132log2(" test cancelled");133return FAILED;134}135136debuggee.redirectOutput(logHandler);137138vm = debuggee.VM();139140eventQueue = vm.eventQueue();141if (eventQueue == null) {142log3("ERROR: eventQueue == null : TEST ABORTED");143vm.exit(PASS_BASE);144return FAILED;145}146147log2("invocation of the method runTest()");148switch (runTest()) {149150case 0 : log2("test phase has finished normally");151log2(" waiting for the debuggee to finish ...");152debuggee.waitFor();153154log2("......getting the debuggee's exit status");155int status = debuggee.getStatus();156if (status != PASS_BASE) {157log3("ERROR: debuggee returned UNEXPECTED exit status: " +158status + " != PASS_BASE");159testExitCode = FAILED;160} else {161log2("......debuggee returned expected exit status: " +162status + " == PASS_BASE");163}164break;165166default : log3("ERROR: runTest() returned unexpected value");167168case 1 : log3("test phase has not finished normally: debuggee is still alive");169log2("......forcing: vm.exit();");170testExitCode = FAILED;171try {172vm.exit(PASS_BASE);173} catch ( Exception e ) {174log3("ERROR: Exception : " + e);175}176break;177178case 2 : log3("test cancelled due to VMDisconnectedException");179log2("......trying: vm.process().destroy();");180testExitCode = FAILED;181try {182Process vmProcess = vm.process();183if (vmProcess != null) {184vmProcess.destroy();185}186} catch ( Exception e ) {187log3("ERROR: Exception : " + e);188}189break;190}191192return testExitCode;193}194195196/*197* Return value: 0 - normal end of the test198* 1 - ubnormal end of the test199* 2 - VMDisconnectedException while test phase200*/201202private int runTest() {203204try {205testRun();206207log2("waiting for VMDeathEvent");208getEventSet();209if (eventIterator.nextEvent() instanceof VMDeathEvent)210return 0;211212log3("ERROR: last event is not the VMDeathEvent");213return 1;214} catch ( VMDisconnectedException e ) {215log3("ERROR: VMDisconnectedException : " + e);216return 2;217} catch ( Exception e ) {218log3("ERROR: Exception : " + e);219return 1;220}221222}223224private void testRun()225throws JDITestRuntimeException, Exception {226227eventRManager = vm.eventRequestManager();228229ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();230cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);231cpRequest.addClassFilter(debuggeeName);232233cpRequest.enable();234vm.resume();235getEventSet();236cpRequest.disable();237238ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();239debuggeeClass = event.referenceType();240241if (!debuggeeClass.name().equals(debuggeeName))242throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");243244log2(" received: ClassPrepareEvent for debuggeeClass");245246String bPointMethod = "methodForCommunication";247String lineForComm = "lineForComm";248249ThreadReference mainThread = debuggee.threadByNameOrThrow("main");250251BreakpointRequest bpRequest = settingBreakpoint(mainThread,252debuggeeClass,253bPointMethod, lineForComm, "zero");254bpRequest.enable();255256//------------------------------------------------------ testing section257258EventRequest requestArray[] = new EventRequest[12];259260String fieldName1 = "testField1";261String fieldName2 = "testField2";262String fieldName3 = "testField3";263264265log1(" TESTING BEGINS");266267for (int i = 0; ; i++) {268269vm.resume();270breakpointForCommunication();271272int instruction = ((IntegerValue)273(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();274275if (instruction == 0) {276vm.resume();277break;278}279280log1(":::::: case: # " + i);281282//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part283284285Field field1 = debuggeeClass.fieldByName(fieldName1);286287ReferenceType refType = (ReferenceType)288debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2)).type();289290ThreadReference threadRef = (ThreadReference)291debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName3));292293String requests[] = { "AccessWatchpoint", "ModificationWatchpoint",294"Breakpoint", "ClassPrepare",295"ClassUnload", "Exception",296"MethodEntry", "MethodExit",297"Step", "ThreadDeath",298"ThreadStart", "VMDeath" };299300requestArray[0] = eventRManager.createAccessWatchpointRequest(field1);301requestArray[1] = eventRManager.createModificationWatchpointRequest(field1);302requestArray[2] = eventRManager.createBreakpointRequest(breakpLocation);303requestArray[3] = eventRManager.createClassPrepareRequest();304requestArray[4] = eventRManager.createClassUnloadRequest();305requestArray[5] = eventRManager.createExceptionRequest(refType, false, false);306requestArray[6] = eventRManager.createMethodEntryRequest();307requestArray[7] = eventRManager.createMethodExitRequest();308requestArray[8] = eventRManager.createStepRequest(threadRef, StepRequest.STEP_MIN, StepRequest.STEP_OUT);309requestArray[9] = eventRManager.createThreadDeathRequest();310requestArray[10] = eventRManager.createThreadStartRequest();311requestArray[11] = eventRManager.createVMDeathRequest();312313for (int i1 = 0; i1 < requestArray.length; i1++) {314315log2("......eventRManager.deleteEventRequest(requestArray[i1]); :: " + requests[i1]);316eventRManager.deleteEventRequest(requestArray[i1]);317318try {319requestArray[i1].addCountFilter(1);320testExitCode = FAILED;321log3("ERROR: NO InvalidRequestStateException for addCountFilter(1);");322} catch ( InvalidRequestStateException e ) {323}324try {325requestArray[i1].disable();326testExitCode = FAILED;327log3("ERROR: NO InvalidRequestStateException for disable();");328} catch ( InvalidRequestStateException e ) {329}330try {331requestArray[i1].enable();332testExitCode = FAILED;333log3("ERROR: NO InvalidRequestStateException for enable();");334} catch ( InvalidRequestStateException e ) {335}336try {337requestArray[i1].getProperty("number");338} catch ( InvalidRequestStateException e ) {339testExitCode = FAILED;340log3("ERROR: InvalidRequestStateException for getProperty('number');");341}342try {343requestArray[i1].isEnabled();344} catch ( InvalidRequestStateException e ) {345testExitCode = FAILED;346log3("ERROR: InvalidRequestStateException for isEnabled();");347}348try {349requestArray[i1].putProperty("number", "request" + i1);350} catch ( InvalidRequestStateException e ) {351testExitCode = FAILED;352log3("ERROR: InvalidRequestStateException for putProperty('number', 'request' + i1);");353}354try {355requestArray[i1].setEnabled(true);356testExitCode = FAILED;357log3("ERROR: NO InvalidRequestStateException for setEnabled(true);");358} catch ( InvalidRequestStateException e ) {359}360try {361requestArray[i1].setSuspendPolicy(EventRequest.SUSPEND_NONE);362testExitCode = FAILED;363log3("ERROR: NO InvalidRequestStateException for setSuspendPolicy(EventRequest.SUSPEND_NONE);");364} catch ( InvalidRequestStateException e ) {365}366try {367requestArray[i1].suspendPolicy();368} catch ( InvalidRequestStateException e ) {369testExitCode = FAILED;370log3("ERROR: InvalidRequestStateException for suspendPolicy();");371}372}373374//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~375}376log1(" TESTING ENDS");377return;378}379380}381382383