Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/deleteEventRequests/delevtreqs002.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.deleteEventRequests;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.deleteEventRequests()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on the following assertion: <BR>45* After invoking the tested method, <BR>46* the methods returning Lists of requests, <BR>47* such as EventRequestManager.accessWatchpointRequests(), <BR>48* return a List containing no eventRequests <BR>49* deleted by the tested method. <BR>50* Testcases include all subclasses of EventRequest. <BR>51* <BR>52* The test has three phases and works as follows. <BR>53* <BR>54* In first phase, <BR>55* upon launching debuggee's VM which will be suspended, <BR>56* a debugger waits for the VMStartEvent within a predefined <BR>57* time interval. If no the VMStartEvent received, the test is FAILED. <BR>58* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>59* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>60* and waits for the event within the predefined time interval. <BR>61* If no the ClassPrepareEvent received, the test is FAILED. <BR>62* Upon getting the ClassPrepareEvent, <BR>63* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>64* within debuggee's special methodForCommunication(). <BR>65* <BR>66* In second phase to check the assertion, <BR>67* the debugger and the debuggee perform the following. <BR>68* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>69* - The debuggee prepares testcases and invokes <BR>70* the methodForCommunication to be suspended and <BR>71* to inform the debugger with the event. <BR>72* - Upon getting the BreakpointEvent, <BR>73* the debugger performs the checks required. <BR>74* <BR>75* In third phase, at the end of the test, the debuggee changes <BR>76* the value of the "instruction" which the debugger and debuggee <BR>77* use to inform each other of needed actions, and both end. <BR>78* <BR>79*/8081public class delevtreqs002 extends JDIBase {8283public static void main (String argv[]) {8485int result = run(argv, System.out);8687System.exit(result + PASS_BASE);88}8990public static int run (String argv[], PrintStream out) {9192int exitCode = new delevtreqs002().runThis(argv, out);9394if (exitCode != PASSED) {95System.out.println("TEST FAILED");96}97return testExitCode;98}99100// ************************************************ test parameters101102private String debuggeeName =103"nsk.jdi.EventRequestManager.deleteEventRequests.delevtreqs002a";104105//====================================================== test program106107private int runThis (String argv[], PrintStream out) {108109argsHandler = new ArgumentHandler(argv);110logHandler = new Log(out, argsHandler);111Binder binder = new Binder(argsHandler, logHandler);112113waitTime = argsHandler.getWaitTime() * 60000;114115try {116log2("launching a debuggee :");117log2(" " + debuggeeName);118if (argsHandler.verbose()) {119debuggee = binder.bindToDebugee(debuggeeName + " -vbs");120} else {121debuggee = binder.bindToDebugee(debuggeeName);122}123if (debuggee == null) {124log3("ERROR: no debuggee launched");125return FAILED;126}127log2("debuggee launched");128} catch ( Exception e ) {129log3("ERROR: Exception : " + e);130log2(" test cancelled");131return FAILED;132}133134debuggee.redirectOutput(logHandler);135136vm = debuggee.VM();137138eventQueue = vm.eventQueue();139if (eventQueue == null) {140log3("ERROR: eventQueue == null : TEST ABORTED");141vm.exit(PASS_BASE);142return FAILED;143}144145log2("invocation of the method runTest()");146switch (runTest()) {147148case 0 : log2("test phase has finished normally");149log2(" waiting for the debuggee to finish ...");150debuggee.waitFor();151152log2("......getting the debuggee's exit status");153int status = debuggee.getStatus();154if (status != PASS_BASE) {155log3("ERROR: debuggee returned UNEXPECTED exit status: " +156status + " != PASS_BASE");157testExitCode = FAILED;158} else {159log2("......debuggee returned expected exit status: " +160status + " == PASS_BASE");161}162break;163164default : log3("ERROR: runTest() returned unexpected value");165166case 1 : log3("test phase has not finished normally: debuggee is still alive");167log2("......forcing: vm.exit();");168testExitCode = FAILED;169try {170vm.exit(PASS_BASE);171} catch ( Exception e ) {172log3("ERROR: Exception : " + e);173}174break;175176case 2 : log3("test cancelled due to VMDisconnectedException");177log2("......trying: vm.process().destroy();");178testExitCode = FAILED;179try {180Process vmProcess = vm.process();181if (vmProcess != null) {182vmProcess.destroy();183}184} catch ( Exception e ) {185log3("ERROR: Exception : " + e);186}187break;188}189190return testExitCode;191}192193194/*195* Return value: 0 - normal end of the test196* 1 - ubnormal end of the test197* 2 - VMDisconnectedException while test phase198*/199200private int runTest() {201202try {203testRun();204205log2("waiting for VMDeathEvent");206getEventSet();207if (eventIterator.nextEvent() instanceof VMDeathEvent)208return 0;209210log3("ERROR: last event is not the VMDeathEvent");211return 1;212} catch ( VMDisconnectedException e ) {213log3("ERROR: VMDisconnectedException : " + e);214return 2;215} catch ( Exception e ) {216log3("ERROR: Exception : " + e);217return 1;218}219220}221222private void testRun()223throws JDITestRuntimeException, Exception {224225eventRManager = vm.eventRequestManager();226227ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();228cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);229cpRequest.addClassFilter(debuggeeName);230231cpRequest.enable();232vm.resume();233getEventSet();234cpRequest.disable();235236ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();237debuggeeClass = event.referenceType();238239if (!debuggeeClass.name().equals(debuggeeName))240throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");241242log2(" received: ClassPrepareEvent for debuggeeClass");243244String bPointMethod = "methodForCommunication";245String lineForComm = "lineForComm";246247ThreadReference mainThread = debuggee.threadByNameOrThrow("main");248249BreakpointRequest bpRequest = settingBreakpoint(mainThread,250debuggeeClass,251bPointMethod, lineForComm, "zero");252bpRequest.enable();253254//------------------------------------------------------ testing section255256final int length1 = 10;257final int length2 = 12;258EventRequest requestArray[][] = new EventRequest[length1][length2];259260String fieldName1 = "testField1";261String fieldName2 = "testField2";262String fieldName3 = "testField3";263264List<EventRequest> requests = null;265ListIterator li = null;266267log1(" TESTING BEGINS");268269for (int i = 0; ; i++) {270271vm.resume();272breakpointForCommunication();273274int instruction = ((IntegerValue)275(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();276277if (instruction == 0) {278vm.resume();279break;280}281282log1(":::::: case: # " + i);283284//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part285286287Field field1 = debuggeeClass.fieldByName(fieldName1);288289ReferenceType refType = (ReferenceType)290debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2)).type();291292293log2("......creating EventRequests");294for (int i1 = 0; i1 < length1; i1++) {295296ThreadReference threadRef = (ThreadReference)297( (ArrayReference) debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName3))298).getValue(i1);299300requestArray[i1][0] = eventRManager.createAccessWatchpointRequest(field1);301requestArray[i1][1] = eventRManager.createModificationWatchpointRequest(field1);302requestArray[i1][2] = eventRManager.createBreakpointRequest(breakpLocation);303requestArray[i1][3] = eventRManager.createClassPrepareRequest();304requestArray[i1][4] = eventRManager.createClassUnloadRequest();305requestArray[i1][5] = eventRManager.createExceptionRequest(refType, false, false);306requestArray[i1][6] = eventRManager.createMethodEntryRequest();307requestArray[i1][7] = eventRManager.createMethodExitRequest();308requestArray[i1][8] = eventRManager.createStepRequest(threadRef, StepRequest.STEP_MIN, StepRequest.STEP_OUT);309requestArray[i1][9] = eventRManager.createThreadDeathRequest();310requestArray[i1][10] = eventRManager.createThreadStartRequest();311requestArray[i1][11] = eventRManager.createVMDeathRequest();312}313for ( int ii1 = 0; ii1 < length1; ii1++) {314for ( int ii2 = 0; ii2 < length2; ii2++) {315requestArray[ii1][ii2].putProperty("number", "request " + ii1 + " " + ii2);316}317}318319320log2("......deleting Requests and checking up on Lists");321for (int i2 = 0; i2 < length1; i2++) {322323EventRequest awRequest = requestArray[i2][0];324EventRequest mwRequest = requestArray[i2][1];325EventRequest bp1Request = requestArray[i2][2];326EventRequest cp1Request = requestArray[i2][3];327EventRequest cuRequest = requestArray[i2][4];328EventRequest exRequest = requestArray[i2][5];329EventRequest menRequest = requestArray[i2][6];330EventRequest mexRequest = requestArray[i2][7];331EventRequest stRequest = requestArray[i2][8];332EventRequest tdRequest = requestArray[i2][9];333EventRequest tsRequest = requestArray[i2][10];334EventRequest vmdRequest = requestArray[i2][11];335336requests = new LinkedList<EventRequest>();337338try {339requests.add(awRequest);340requests.add(mwRequest);341requests.add(bp1Request);342requests.add(cp1Request);343requests.add(cuRequest);344requests.add(exRequest);345requests.add(menRequest);346requests.add(mexRequest);347requests.add(stRequest);348requests.add(tdRequest);349requests.add(tsRequest);350requests.add(vmdRequest);351} catch ( UnsupportedOperationException e ) {352testExitCode = FAILED;353log3("ERROR: unexpected UnsupportedOperationException");354break;355}356357eventRManager.deleteEventRequests(requests);358359for (EventRequest er : eventRManager.accessWatchpointRequests()) {360if ( er.equals(awRequest) ) {361testExitCode = FAILED;362log3("ERROR: deleted AccessWatchpointRequest is in the List :: " + er.getProperty("number") );363}364}365366for (EventRequest er : eventRManager.modificationWatchpointRequests()) {367if ( er.equals(mwRequest) ) {368testExitCode = FAILED;369log3("ERROR: deleted ModificationWatchpointRequest is in the List :: " + er.getProperty("number") );370}371}372373for (EventRequest er : eventRManager.breakpointRequests()) {374if ( er.equals(bp1Request) ) {375testExitCode = FAILED;376log3("ERROR: deleted BreakpointRequest is in the List :: " + er.getProperty("number") );377}378}379380for (EventRequest er : eventRManager.classPrepareRequests()) {381if ( er.equals(cp1Request) ) {382testExitCode = FAILED;383log3("ERROR: deleted ClassPrepareRequest is in the List :: " + er.getProperty("number") );384}385}386387for (EventRequest er : eventRManager.classUnloadRequests()) {388if ( er.equals(cuRequest) ) {389testExitCode = FAILED;390log3("ERROR: deleted ClassUnloadRequest is in the List :: " + er.getProperty("number") );391}392}393394for (EventRequest er : eventRManager.exceptionRequests()) {395if ( er.equals(exRequest) ) {396testExitCode = FAILED;397log3("ERROR: deleted ExceptionRequest is in the List :: " + er.getProperty("number") );398}399}400401for (EventRequest er : eventRManager.methodEntryRequests()) {402if ( er.equals(menRequest) ) {403testExitCode = FAILED;404log3("ERROR: deleted MethodEntryRequest is in the List :: " + er.getProperty("number") );405}406}407408for (EventRequest er : eventRManager.methodExitRequests()) {409if ( er.equals(mexRequest) ) {410testExitCode = FAILED;411log3("ERROR: deleted MethodExitRequest is in the List :: " + er.getProperty("number") );412}413}414415for (EventRequest er : eventRManager.stepRequests()) {416if ( er.equals(stRequest) ) {417testExitCode = FAILED;418log3("ERROR: deleted StepRequest is in the List :: " + er.getProperty("number") );419}420}421422for (EventRequest er : eventRManager.threadDeathRequests()) {423if ( er.equals(tdRequest) ) {424testExitCode = FAILED;425log3("ERROR: deleted ThreadDeathRequest is in the List :: " + er.getProperty("number") );426}427}428429for (EventRequest er : eventRManager.threadStartRequests()) {430if ( er.equals(tsRequest) ) {431testExitCode = FAILED;432log3("ERROR: deleted ThreadStartRequest is in the List :: " + er.getProperty("number") );433}434}435436for (EventRequest er : eventRManager.vmDeathRequests()) {437if ( er.equals(vmdRequest) ) {438testExitCode = FAILED;439log3("ERROR: deleted VMDeathRequest is in the List :: " + er.getProperty("number") );440}441}442}443//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~444}445log1(" TESTING ENDS");446return;447}448449}450451452