Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/disable/disable002.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.EventRequest.disable;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* EventRequest. <BR>39* <BR>40* The test checks that results of the method <BR>41* <code>com.sun.jdi.EventRequest.disable()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on the following assertion: <BR>45* Throws: InvalidRequestStateException - <BR>46* if this request has been deleted. <BR>47* The cases to test include all sub-types of EventRequest. <BR>48* <BR>49* The test has three phases and works as follows. <BR>50* <BR>51* In first phase, <BR>52* upon launching debuggee's VM which will be suspended, <BR>53* a debugger waits for the VMStartEvent within a predefined <BR>54* time interval. If no the VMStartEvent received, the test is FAILED. <BR>55* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>56* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>57* and waits for the event within the predefined time interval. <BR>58* If no the ClassPrepareEvent received, the test is FAILED. <BR>59* Upon getting the ClassPrepareEvent, <BR>60* the debugger sets up the breakpoint with SUSPEND_ALL <BR>61* within debuggee's special methodForCommunication(). <BR>62* <BR>63* In second phase to check the assertion, <BR>64* the debugger and the debuggee perform the following loop. <BR>65* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>66* - The debuggee prepares new check case (as if) and invokes <BR>67* the methodForCommunication to be suspended and <BR>68* to inform the debugger with the event. <BR>69* - Upon getting the BreakpointEvent, <BR>70* the debugger performs the check case required. <BR>71* <BR>72* In third phase, at the end of the test, the debuggee changes <BR>73* the value of the "instruction" which the debugger and debuggee <BR>74* use to inform each other of needed actions, and both end. <BR>75* <BR>76*/7778public class disable002 extends JDIBase {7980public static void main (String argv[]) {8182int result = run(argv, System.out);8384System.exit(result + PASS_BASE);85}8687public static int run (String argv[], PrintStream out) {8889int exitCode = new disable002().runThis(argv, out);9091if (exitCode != PASSED) {92System.out.println("TEST FAILED");93}94return testExitCode;95}9697// ************************************************ test parameters9899private String debuggeeName =100"nsk.jdi.EventRequest.disable.disable002a";101102private String testedClassName =103"nsk.jdi.EventRequest.disable.disable002aTestClass11";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 section255256257EventRequest eventRequest1 = null;258259String fieldName1 = "var101";260String fieldName2 = "excObj";261262ThreadReference thread1 = null;263String threadName1 = "thread1";264265ReferenceType testClassReference = null;266267268log1(" TESTING BEGINS");269270for (int i = 0; ; i++) {271272vm.resume();273breakpointForCommunication();274275int instruction = ((IntegerValue)276(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();277278if (instruction == 0) {279vm.resume();280break;281}282283log1(":::::: case: # " + i);284285//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part286287288switch (i) {289290case 0:291thread1 = debuggee.threadByNameOrThrow(threadName1);292293log2("......setting up StepRequest");294eventRequest1 = eventRManager.createStepRequest295(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);296break;297298case 1:299testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);300301log2("......setting up AccessWatchpointRequest");302eventRequest1 = eventRManager.createAccessWatchpointRequest303(testClassReference.fieldByName(fieldName1));304break;305306case 2:307log2(".....setting up ModificationWatchpointRequest");308eventRequest1 = eventRManager.createModificationWatchpointRequest309(testClassReference.fieldByName(fieldName1));310break;311312case 3:313log2(".....setting up ClassPrepareRequest");314eventRequest1 = eventRManager.createClassPrepareRequest();315break;316317case 4:318log2(".....setting up ClassUnloadRequest");319eventRequest1 = eventRManager.createClassUnloadRequest();320break;321322case 5:323log2(".....setting up MethodEntryRequest");324eventRequest1 = eventRManager.createMethodEntryRequest();325break;326327case 6:328log2(".....setting up MethodExitRequest");329eventRequest1 = eventRManager.createMethodExitRequest();330break;331332case 7:333log2(".....setting up ThreadDeathRequest");334eventRequest1 = eventRManager.createThreadDeathRequest();335break;336337case 8:338log2(".....setting up ThreadStartRequest");339eventRequest1 = eventRManager.createThreadStartRequest();340break;341342case 9:343log2(".....setting up VMDeathRequest");344eventRequest1 = eventRManager.createVMDeathRequest();345break;346347case 10:348log2(".....setting up ExceptionRequest");349eventRequest1 = eventRManager.createExceptionRequest(350(ReferenceType)351(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),352true, true );353break;354355case 11:356log2(".....setting up BreakpointRequest");357eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);358break;359360361default:362throw new JDITestRuntimeException("** default case 2 **");363}364365log2("......eventRManager.deleteEventRequest(eventRequest1);");366eventRManager.deleteEventRequest(eventRequest1);367try {368log2("......eventRequest1.enable(); InvalidRequestStateException is expected");369eventRequest1.disable();370testExitCode = FAILED;371log3("ERROR: NO InvalidRequestStateException");372} catch ( InvalidRequestStateException e ) {373log2(" InvalidRequestStateException");374}375376//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~377}378log1(" TESTING ENDS");379return;380}381382383}384385386