Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createExceptionRequest/crexreq010.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.createExceptionRequest;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.createExceptionRequest()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on the following assertion: <BR>45* - If neither caught exception nor uncaught exception is selected, <BR>46* that is, both notifyCaught and notifyUncaught arguments are false, <BR>47* returned value is null. <BR>48* Note. In condition of no Exception for such testcase is defined in <BR>49* the spec, null is the only reasonable returned value. <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 assertion, <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 a 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 check 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 crexreq010 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 crexreq010().runThis(argv, out);9293if (exitCode != PASSED) {94System.out.println("TEST FAILED");95}96return testExitCode;97}9899// ************************************************ test parameters100101private String debuggeeName =102"nsk.jdi.EventRequestManager.createExceptionRequest.crexreq010a";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 section254255String fieldName = "testField";256257ExceptionRequest exRequest = null;258259260log1(" TESTING BEGINS");261262for (int i = 0; ; i++) {263264vm.resume();265breakpointForCommunication();266267int instruction = ((IntegerValue)268(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();269270if (instruction == 0) {271vm.resume();272break;273}274275log1(":::::: case: # " + i);276277//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part278279ReferenceType refType = (ReferenceType)280debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName)).type();281282283try {284log2("......creating: exRequest = eventRManager.createExceptionRequest(refType, false, false);");285exRequest = eventRManager.createExceptionRequest(refType, false, false);286log2(" check on if returned value is null");287if (exRequest == null) {288log3("ERROR: returned value is null!");289testExitCode = FAILED;290}291} catch (Exception e) {292log3("ERROR: exception caught: " + e);293testExitCode = FAILED;294}295296//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~297}298log1(" TESTING ENDS");299return;300}301302}303304305