Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createClassUnloadRequest/cureg001.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.createClassUnloadRequest;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.createClassUnloadRequest()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on the following assertion: <BR>45* - Creates a new disabled ClassUnloadRequest. <BR>46* <BR>47* The test has three phases and works as follows. <BR>48* <BR>49* In first phase, <BR>50* upon launching debuggee's VM which will be suspended, <BR>51* a debugger waits for the VMStartEvent within a predefined <BR>52* time interval. If no the VMStartEvent received, the test is FAILED. <BR>53* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>54* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>55* and waits for the event within the predefined time interval. <BR>56* If no the ClassPrepareEvent received, the test is FAILED. <BR>57* Upon getting the ClassPrepareEvent, <BR>58* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>59* within debuggee's special methodForCommunication(). <BR>60* <BR>61* In second phase to check the assertion, <BR>62* the debugger and the debuggee perform the following. <BR>63* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>64* - The debuggee prepares new check case and invokes <BR>65* the methodForCommunication to be suspended and <BR>66* to inform the debugger with the event. <BR>67* - Upon getting the BreakpointEvent, <BR>68* the debugger performs the check required. <BR>69* <BR>70* In third phase, at the end of the test, the debuggee changes <BR>71* the value of the "instruction" which the debugger and debuggee <BR>72* use to inform each other of needed actions, and both end. <BR>73* <BR>74*/7576public class cureg001 extends JDIBase {7778public static void main (String argv[]) {7980int result = run(argv, System.out);8182System.exit(result + PASS_BASE);83}8485public static int run (String argv[], PrintStream out) {8687int exitCode = new cureg001().runThis(argv, out);8889if (exitCode != PASSED) {90System.out.println("TEST FAILED");91}92return testExitCode;93}9495// ************************************************ test parameters9697private String debuggeeName =98"nsk.jdi.EventRequestManager.createClassUnloadRequest.cureg001a";99100//====================================================== test program101102private int runThis (String argv[], PrintStream out) {103104argsHandler = new ArgumentHandler(argv);105logHandler = new Log(out, argsHandler);106Binder binder = new Binder(argsHandler, logHandler);107108waitTime = argsHandler.getWaitTime() * 60000;109110try {111log2("launching a debuggee :");112log2(" " + debuggeeName);113if (argsHandler.verbose()) {114debuggee = binder.bindToDebugee(debuggeeName + " -vbs");115} else {116debuggee = binder.bindToDebugee(debuggeeName);117}118if (debuggee == null) {119log3("ERROR: no debuggee launched");120return FAILED;121}122log2("debuggee launched");123} catch ( Exception e ) {124log3("ERROR: Exception : " + e);125log2(" test cancelled");126return FAILED;127}128129debuggee.redirectOutput(logHandler);130131vm = debuggee.VM();132133eventQueue = vm.eventQueue();134if (eventQueue == null) {135log3("ERROR: eventQueue == null : TEST ABORTED");136vm.exit(PASS_BASE);137return FAILED;138}139140log2("invocation of the method runTest()");141switch (runTest()) {142143case 0 : log2("test phase has finished normally");144log2(" waiting for the debuggee to finish ...");145debuggee.waitFor();146147log2("......getting the debuggee's exit status");148int status = debuggee.getStatus();149if (status != PASS_BASE) {150log3("ERROR: debuggee returned UNEXPECTED exit status: " +151status + " != PASS_BASE");152testExitCode = FAILED;153} else {154log2("......debuggee returned expected exit status: " +155status + " == PASS_BASE");156}157break;158159default : log3("ERROR: runTest() returned unexpected value");160161case 1 : log3("test phase has not finished normally: debuggee is still alive");162log2("......forcing: vm.exit();");163testExitCode = FAILED;164try {165vm.exit(PASS_BASE);166} catch ( Exception e ) {167log3("ERROR: Exception : " + e);168}169break;170171case 2 : log3("test cancelled due to VMDisconnectedException");172log2("......trying: vm.process().destroy();");173testExitCode = FAILED;174try {175Process vmProcess = vm.process();176if (vmProcess != null) {177vmProcess.destroy();178}179} catch ( Exception e ) {180log3("ERROR: Exception : " + e);181}182break;183}184185return testExitCode;186}187188189/*190* Return value: 0 - normal end of the test191* 1 - ubnormal end of the test192* 2 - VMDisconnectedException while test phase193*/194195private int runTest() {196197try {198testRun();199200log2("waiting for VMDeathEvent");201getEventSet();202if (eventIterator.nextEvent() instanceof VMDeathEvent)203return 0;204205log3("ERROR: last event is not the VMDeathEvent");206return 1;207} catch ( VMDisconnectedException e ) {208log3("ERROR: VMDisconnectedException : " + e);209return 2;210} catch ( Exception e ) {211log3("ERROR: Exception : " + e);212return 1;213}214215}216217private void testRun()218throws JDITestRuntimeException, Exception {219220eventRManager = vm.eventRequestManager();221222ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();223cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);224cpRequest.addClassFilter(debuggeeName);225226cpRequest.enable();227vm.resume();228getEventSet();229cpRequest.disable();230231ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();232debuggeeClass = event.referenceType();233234if (!debuggeeClass.name().equals(debuggeeName))235throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");236237log2(" received: ClassPrepareEvent for debuggeeClass");238239String bPointMethod = "methodForCommunication";240String lineForComm = "lineForComm";241242ThreadReference mainThread = debuggee.threadByNameOrThrow("main");243244BreakpointRequest bpRequest = settingBreakpoint(mainThread,245debuggeeClass,246bPointMethod, lineForComm, "zero");247bpRequest.enable();248249//------------------------------------------------------ testing section250251ClassUnloadRequest cuRequest1 = null;252253254log1(" TESTING BEGINS");255256for (int i = 0; ; i++) {257258vm.resume();259breakpointForCommunication();260261int instruction = ((IntegerValue)262(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();263264if (instruction == 0) {265vm.resume();266break;267}268269log1(":::::: case: # " + i);270271//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part272273log2("......creating: cuRequest1 = eventRManager.createClassUnloadRequest();");274cuRequest1 = eventRManager.createClassUnloadRequest();275log2(" checking up on if request is disabled");276if (cuRequest1.isEnabled()) {277testExitCode = FAILED;278log3("ERROR: request is not disabled");279}280281//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~282}283log1(" TESTING ENDS");284return;285}286287}288289290