Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq002.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.createStepRequest;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.createStepRequest()</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 StepRequest. <BR>46* - STEP_MIN, STEP_LINE, STEP_INTO, STEP_OVER, STEP_OUT are valid <BR>47* arguments, that is, they don't throw IllegalArgumentException. <BR>48* - Values larger and lesser corresponding above are invalid arguments,<BR>49* that is, they do throw IllegalArgumentException. <BR>50* <BR>51* The test has three phases and works as follows. <BR>52* <BR>53* In first phase, <BR>54* upon launching debuggee's VM which will be suspended, <BR>55* a debugger waits for the VMStartEvent within a predefined <BR>56* time interval. If no the VMStartEvent received, the test is FAILED. <BR>57* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>58* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>59* and waits for the event within the predefined time interval. <BR>60* If no the ClassPrepareEvent received, the test is FAILED. <BR>61* Upon getting the ClassPrepareEvent, <BR>62* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>63* within debuggee's special methodForCommunication(). <BR>64* <BR>65* In second phase to check the assertions, <BR>66* the debugger and the debuggee perform the following. <BR>67* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>68* - The debuggee prepares new testcase and invokes <BR>69* the methodForCommunication to be suspended and <BR>70* to inform the debugger with the event. <BR>71* - Upon getting the BreakpointEvent, <BR>72* the debugger performs the checks required. <BR>73* <BR>74* In third phase, at the end of the test, the debuggee changes <BR>75* the value of the "instruction" which the debugger and debuggee <BR>76* use to inform each other of needed actions, and both end. <BR>77* <BR>78*/7980public class crstepreq002 extends JDIBase {8182public static void main (String argv[]) {8384int result = run(argv, System.out);8586System.exit(result + PASS_BASE);87}8889public static int run (String argv[], PrintStream out) {9091int exitCode = new crstepreq002().runThis(argv, out);9293if (exitCode != PASSED) {94System.out.println("TEST FAILED");95}96return testExitCode;97}9899// ************************************************ test parameters100101private String debuggeeName =102"nsk.jdi.EventRequestManager.createStepRequest.crstepreq002a";103104//====================================================== test program105106private int runThis (String argv[], PrintStream out) {107108argsHandler = new ArgumentHandler(argv);109logHandler = new Log(out, argsHandler);110Binder binder = new Binder(argsHandler, logHandler);111112waitTime = argsHandler.getWaitTime() * 60000;113114try {115log2("launching a debuggee :");116log2(" " + debuggeeName);117if (argsHandler.verbose()) {118debuggee = binder.bindToDebugee(debuggeeName + " -vbs");119} else {120debuggee = binder.bindToDebugee(debuggeeName);121}122if (debuggee == null) {123log3("ERROR: no debuggee launched");124return FAILED;125}126log2("debuggee launched");127} catch ( Exception e ) {128log3("ERROR: Exception : " + e);129log2(" test cancelled");130return FAILED;131}132133debuggee.redirectOutput(logHandler);134135vm = debuggee.VM();136137eventQueue = vm.eventQueue();138if (eventQueue == null) {139log3("ERROR: eventQueue == null : TEST ABORTED");140vm.exit(PASS_BASE);141return FAILED;142}143144log2("invocation of the method runTest()");145switch (runTest()) {146147case 0 : log2("test phase has finished normally");148log2(" waiting for the debuggee to finish ...");149debuggee.waitFor();150151log2("......getting the debuggee's exit status");152int status = debuggee.getStatus();153if (status != PASS_BASE) {154log3("ERROR: debuggee returned UNEXPECTED exit status: " +155status + " != PASS_BASE");156testExitCode = FAILED;157} else {158log2("......debuggee returned expected exit status: " +159status + " == PASS_BASE");160}161break;162163default : log3("ERROR: runTest() returned unexpected value");164165case 1 : log3("test phase has not finished normally: debuggee is still alive");166log2("......forcing: vm.exit();");167testExitCode = FAILED;168try {169vm.exit(PASS_BASE);170} catch ( Exception e ) {171log3("ERROR: Exception : " + e);172}173break;174175case 2 : log3("test cancelled due to VMDisconnectedException");176log2("......trying: vm.process().destroy();");177testExitCode = FAILED;178try {179Process vmProcess = vm.process();180if (vmProcess != null) {181vmProcess.destroy();182}183} catch ( Exception e ) {184log3("ERROR: Exception : " + e);185}186break;187}188189return testExitCode;190}191192193/*194* Return value: 0 - normal end of the test195* 1 - ubnormal end of the test196* 2 - VMDisconnectedException while test phase197*/198199private int runTest() {200201try {202testRun();203204log2("waiting for VMDeathEvent");205getEventSet();206if (eventIterator.nextEvent() instanceof VMDeathEvent)207return 0;208209log3("ERROR: last event is not the VMDeathEvent");210return 1;211} catch ( VMDisconnectedException e ) {212log3("ERROR: VMDisconnectedException : " + e);213return 2;214} catch ( Exception e ) {215log3("ERROR: Exception : " + e);216return 1;217}218219}220221private void testRun()222throws JDITestRuntimeException, Exception {223224eventRManager = vm.eventRequestManager();225226ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();227cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);228cpRequest.addClassFilter(debuggeeName);229230cpRequest.enable();231vm.resume();232getEventSet();233cpRequest.disable();234235ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();236debuggeeClass = event.referenceType();237238if (!debuggeeClass.name().equals(debuggeeName))239throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");240241log2(" received: ClassPrepareEvent for debuggeeClass");242243String bPointMethod = "methodForCommunication";244String lineForComm = "lineForComm";245246ThreadReference mainThread = debuggee.threadByNameOrThrow("main");247248BreakpointRequest bpRequest = settingBreakpoint(mainThread,249debuggeeClass,250bPointMethod, lineForComm, "zero");251bpRequest.enable();252253//------------------------------------------------------ testing section254255ThreadReference thread = null;256String threadName = "thread1";257258StepRequest stRequest = null;259260int minDepth, maxDepth;261int minSize, maxSize;262263264log1(" TESTING BEGINS");265266for (int i = 0; ; i++) {267268vm.resume();269breakpointForCommunication();270271int instruction = ((IntegerValue)272(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();273274if (instruction == 0) {275vm.resume();276break;277}278279log1(":::::: case: # " + i);280281//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part282283thread = debuggee.threadByNameOrThrow(threadName);284285if (StepRequest.STEP_MIN > StepRequest.STEP_LINE) {286maxSize = StepRequest.STEP_MIN;287minSize = StepRequest.STEP_LINE;288} else {289minSize = StepRequest.STEP_MIN;290maxSize = StepRequest.STEP_LINE;291}292293if ( (StepRequest.STEP_INTO > StepRequest.STEP_OVER) &&294(StepRequest.STEP_INTO > StepRequest.STEP_OUT) )295maxDepth = StepRequest.STEP_INTO;296297if ( (StepRequest.STEP_OVER > StepRequest.STEP_INTO) &&298(StepRequest.STEP_OVER > StepRequest.STEP_OUT) )299maxDepth = StepRequest.STEP_OVER;300301if ( (StepRequest.STEP_OUT > StepRequest.STEP_OVER) &&302(StepRequest.STEP_OUT > StepRequest.STEP_INTO) )303maxDepth = StepRequest.STEP_OUT;304305if ( (StepRequest.STEP_INTO < StepRequest.STEP_OVER) &&306(StepRequest.STEP_INTO < StepRequest.STEP_OUT) )307minDepth = StepRequest.STEP_INTO;308309if ( (StepRequest.STEP_OVER < StepRequest.STEP_INTO) &&310(StepRequest.STEP_OVER < StepRequest.STEP_OUT) )311minDepth = StepRequest.STEP_OVER;312313if ( (StepRequest.STEP_OUT < StepRequest.STEP_OVER) &&314(StepRequest.STEP_OUT < StepRequest.STEP_INTO) )315minDepth = StepRequest.STEP_OUT;316317try {318log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);");319stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);320log2(" checking up on if request is disabled");321if (stRequest.isEnabled()) {322testExitCode = FAILED;323log3("ERROR: request is enabled");324}325} catch ( IllegalArgumentException e ) {326testExitCode = FAILED;327log3("ERROR: IllegalArgumentException for STEP_MIN - STEP_INTO");328}329eventRManager.deleteEventRequest(stRequest);330try {331log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);");332stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);333log2(" checking up on if request is disabled");334if (stRequest.isEnabled()) {335testExitCode = FAILED;336log3("ERROR: request is enabled");337}338} catch ( IllegalArgumentException e ) {339testExitCode = FAILED;340log3("ERROR: IllegalArgumentException for STEP_LINE - STEP_OVER");341}342eventRManager.deleteEventRequest(stRequest);343try {344log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);");345stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT);346log2(" checking up on if request is disabled");347if (stRequest.isEnabled()) {348testExitCode = FAILED;349log3("ERROR: request is enabled");350}351} catch ( IllegalArgumentException e ) {352testExitCode = FAILED;353log3("ERROR: IllegalArgumentException for STEP_LINE - STEP_OUT");354}355eventRManager.deleteEventRequest(stRequest);356log2("......creating: eventRManager.createStepRequest(thread, minSize -1, StepRequest.STEP_OUT);");357log2(" IllegalArgumentException is expected");358try {359stRequest = eventRManager.createStepRequest(thread, minSize -1, StepRequest.STEP_OUT);360testExitCode = FAILED;361log3("ERROR: no IllegalArgumentException thrown");362} catch ( IllegalArgumentException e ) {363}364eventRManager.deleteEventRequest(stRequest);365log2("......creating: eventRManager.createStepRequest(thread, maxSize +1, StepRequest.STEP_OUT);");366log2(" IllegalArgumentException is expected");367try {368stRequest = eventRManager.createStepRequest(thread, maxSize +1, StepRequest.STEP_OUT);369testExitCode = FAILED;370log3("ERROR: no IllegalArgumentException thrown");371} catch ( IllegalArgumentException e ) {372}373eventRManager.deleteEventRequest(stRequest);374log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, minDepth -1);");375log2(" IllegalArgumentException is expected");376try {377stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, minDepth -1);378testExitCode = FAILED;379log3("ERROR: no IllegalArgumentException thrown");380} catch ( IllegalArgumentException e ) {381}382eventRManager.deleteEventRequest(stRequest);383log2("......creating: eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, maxDepth +1);");384log2(" IllegalArgumentException is expected");385try {386stRequest = eventRManager.createStepRequest(thread, StepRequest.STEP_LINE, maxDepth +1);387testExitCode = FAILED;388log3("ERROR: no IllegalArgumentException thrown");389} catch ( IllegalArgumentException e ) {390}391392//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~393}394log1(" TESTING ENDS");395return;396}397398}399400401