Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume011.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.EventSet.resume;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* EventSet. <BR>39* <BR>40* The test checks that results of the method <BR>41* <code>com.sun.jdi.EventSet.resume()</code> <BR>42* complies with its spec. <BR>43* <BR>44* Test case includes SUSPEND_NONE for a VMDeathEvent set. <BR>45* <BR>46* The test has three phases and works as follows. <BR>47* <BR>48* Upon launching debuggee's VM which will be suspended, <BR>49* a debugger waits for the VMStartEvent within a predefined <BR>50* time interval. If no the VMStartEvent received, the test is FAILED. <BR>51* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>52* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>53* and waits for the event within the predefined time interval. <BR>54* If no the ClassPrepareEvent received, the test is FAILED. <BR>55* Upon getting the ClassPrepareEvent, <BR>56* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>57* within debuggee's special methodForCommunication(). <BR>58* <BR>59* Then to check the above, <BR>60* the debugger and the debuggee perform the following. <BR>61* - The debugger sets up a VMDeathRequest, resumes <BR>62* the debuggee, and waits for the VMDeathEvent. <BR>63* - The debuggee ends to be resulting in the VMDeathEvent. <BR>64* - Upon getting the event, the debugger performs the check. <BR>65* <BR>66* Note. To inform each other of needed actions, the debugger and <BR>67* and the debuggee use debuggee's variable "instruction". <BR>68* <BR>69*/7071public class resume011 extends JDIBase {7273public static void main (String argv[]) {7475int result = run(argv, System.out);7677System.exit(result + PASS_BASE);78}7980public static int run (String argv[], PrintStream out) {8182int exitCode = new resume011().runThis(argv, out);8384if (exitCode != PASSED) {85System.out.println("TEST FAILED");86}87return testExitCode;88}8990// ************************************************ test parameters9192private String debuggeeName =93"nsk.jdi.EventSet.resume.resume011a";9495private String testedClassName =96"nsk.jdi.EventSet.resume.TestClass";9798//====================================================== test program99100private int runThis (String argv[], PrintStream out) {101102argsHandler = new ArgumentHandler(argv);103logHandler = new Log(out, argsHandler);104Binder binder = new Binder(argsHandler, logHandler);105106waitTime = argsHandler.getWaitTime() * 60000;107108try {109log2("launching a debuggee :");110log2(" " + debuggeeName);111if (argsHandler.verbose()) {112debuggee = binder.bindToDebugee(debuggeeName + " -vbs");113} else {114debuggee = binder.bindToDebugee(debuggeeName);115}116if (debuggee == null) {117log3("ERROR: no debuggee launched");118return FAILED;119}120log2("debuggee launched");121} catch ( Exception e ) {122log3("ERROR: Exception : " + e);123log2(" test cancelled");124return FAILED;125}126127debuggee.redirectOutput(logHandler);128129vm = debuggee.VM();130131eventQueue = vm.eventQueue();132if (eventQueue == null) {133log3("ERROR: eventQueue == null : TEST ABORTED");134vm.exit(PASS_BASE);135return FAILED;136}137138log2("invocation of the method runTest()");139switch (runTest()) {140141case 0 : log2("test phase has finished normally");142log2(" waiting for the debuggee to finish ...");143debuggee.waitFor();144145log2("......getting the debuggee's exit status");146int status = debuggee.getStatus();147if (status != PASS_BASE) {148log3("ERROR: debuggee returned UNEXPECTED exit status: " +149status + " != PASS_BASE");150testExitCode = FAILED;151} else {152log2("......debuggee returned expected exit status: " +153status + " == PASS_BASE");154}155break;156157default : log3("ERROR: runTest() returned unexpected value");158159case 1 : log3("test phase has not finished normally: debuggee is still alive");160log2("......forcing: vm.exit();");161testExitCode = FAILED;162try {163vm.exit(PASS_BASE);164} catch ( Exception e ) {165log3("ERROR: Exception : e");166}167break;168169case 2 : log3("test cancelled due to VMDisconnectedException");170log2("......trying: vm.process().destroy();");171testExitCode = FAILED;172try {173Process vmProcess = vm.process();174if (vmProcess != null) {175vmProcess.destroy();176}177} catch ( Exception e ) {178log3("ERROR: Exception : e");179}180break;181}182183return testExitCode;184}185186187/*188* Return value: 0 - normal end of the test189* 1 - ubnormal end of the test190* 2 - VMDisconnectedException while test phase191*/192193private int runTest() {194195try {196testRun();197198log2("waiting for VMDeathEvent");199getEventSet();200if ( !(eventIterator.nextEvent() instanceof VMDeathEvent) ) {201log3("ERROR: last event is not the VMDeathEvent");202return 1;203}204check();205206log2("waiting for VMDisconnectEvent");207getEventSet();208if ( !(eventIterator.nextEvent() instanceof VMDisconnectEvent) ) {209log3("ERROR: last event is not the VMDisconnectEvent");210return 1;211}212213return 0;214215} catch ( VMDisconnectedException e ) {216log3("ERROR: VMDisconnectedException : " + e);217return 2;218} catch ( Exception e ) {219log3("ERROR: Exception : " + e);220return 1;221}222223}224225private void testRun()226throws JDITestRuntimeException, Exception {227228if ( !vm.canRequestVMDeathEvent() ) {229log2("......vm.canRequestVMDeathEvent == false :: test cancelled");230vm.exit(PASS_BASE);231return;232}233234235eventRManager = vm.eventRequestManager();236237ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();238cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);239cpRequest.addClassFilter(debuggeeName);240241cpRequest.enable();242vm.resume();243getEventSet();244cpRequest.disable();245246ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();247debuggeeClass = event.referenceType();248249if (!debuggeeClass.name().equals(debuggeeName))250throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");251252log2(" received: ClassPrepareEvent for debuggeeClass");253254String bPointMethod = "methodForCommunication";255String lineForComm = "lineForComm";256BreakpointRequest bpRequest;257ThreadReference mainThread = debuggee.threadByNameOrThrow("main");258bpRequest = settingBreakpoint(mainThread,259debuggeeClass,260bPointMethod, lineForComm, "zero");261bpRequest.enable();262263vm.resume();264265//------------------------------------------------------ testing section266267log1(" TESTING BEGINS");268269EventRequest eventRequest1 = null;270// EventRequest eventRequest2 = null;271// EventRequest eventRequest3 = null;272273final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;274final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;275final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;276277278279breakpointForCommunication();280281//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part282283eventRequest1 = settingVMDeathRequest ( SUSPEND_NONE, "VMDeathRequest1");284eventRequest1.enable();285286mainThread.resume();287288//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~289290log1(" TESTING ENDS");291return;292}293294// ============================== test's additional methods295296private VMDeathRequest settingVMDeathRequest( int suspendPolicy,297String property )298throws JDITestRuntimeException {299try {300log2("......setting up VMDeathRequest:");301log2(" suspendPolicy: " + suspendPolicy + "; property: " + property);302303VMDeathRequest304vmdr = eventRManager.createVMDeathRequest();305vmdr.putProperty("number", property);306vmdr.setSuspendPolicy(suspendPolicy);307308return vmdr;309} catch ( Exception e ) {310log3("ERROR: ATTENTION: Exception within settingVMDeathRequest() : " + e);311log3(" VMDeathRequest HAS NOT BEEN SET UP");312throw new JDITestRuntimeException("** FAILURE to set up a VMDeathRequest **");313}314}315316void check() {317log2("......checking up on eventSet.resume()");318try {319log2(" eventSet.resume(); :: no Exception expected");320eventSet.resume();321} catch ( Exception e ) {322log3("ERROR: Exception : " + e);323testExitCode = FAILED;324}325}326327}328329330