Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createExceptionRequest/crexreq009.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* - Creates a new disabled ExceptionRequest. <BR>46* - A specific exception type and its subclasses <BR>47* can be selected for exception events. <BR>48* - Caught exceptions, uncaught exceptions, or both can be selected. <BR>49* <BR>50* The test has three phases and works as follows. <BR>51* <BR>52* In first phase, <BR>53* upon launching debuggee's VM which will be suspended, <BR>54* a debugger waits for the VMStartEvent within a predefined <BR>55* time interval. If no the VMStartEvent received, the test is FAILED. <BR>56* Upon getting the VMStartEvent, it makes the request for debuggee's <BR>57* ClassPrepareEvent with SUSPEND_EVENT_THREAD, resumes the VM, <BR>58* and waits for the event within the predefined time interval. <BR>59* If no the ClassPrepareEvent received, the test is FAILED. <BR>60* Upon getting the ClassPrepareEvent, <BR>61* the debugger sets up the breakpoint with SUSPEND_EVENT_THREAD <BR>62* within debuggee's special methodForCommunication(). <BR>63* <BR>64* In second phase to check the assertion, <BR>65* the debugger and the debuggee perform the following. <BR>66* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>67* - The debuggee prepares new testcase and invokes <BR>68* the methodForCommunication to be suspended and <BR>69* to inform the debugger with the event. <BR>70* - Upon getting the BreakpointEvent, <BR>71* the debugger performs the checks required. <BR>72* <BR>73* In third phase, at the end of the test, the debuggee changes <BR>74* the value of the "instruction" which the debugger and debuggee <BR>75* use to inform each other of needed actions, and both end. <BR>76* <BR>77*/7879public class crexreq009 extends JDIBase {8081public static void main (String argv[]) {8283int result = run(argv, System.out);8485System.exit(result + PASS_BASE);86}8788public static int run (String argv[], PrintStream out) {8990int exitCode = new crexreq009().runThis(argv, out);9192if (exitCode != PASSED) {93System.out.println("TEST FAILED");94}95return testExitCode;96}9798// ************************************************ test parameters99100private String debuggeeName =101"nsk.jdi.EventRequestManager.createExceptionRequest.crexreq009a";102103//====================================================== test program104105private int runThis (String argv[], PrintStream out) {106107argsHandler = new ArgumentHandler(argv);108logHandler = new Log(out, argsHandler);109Binder binder = new Binder(argsHandler, logHandler);110111waitTime = argsHandler.getWaitTime() * 60000;112113try {114log2("launching a debuggee :");115log2(" " + debuggeeName);116if (argsHandler.verbose()) {117debuggee = binder.bindToDebugee(debuggeeName + " -vbs");118} else {119debuggee = binder.bindToDebugee(debuggeeName);120}121if (debuggee == null) {122log3("ERROR: no debuggee launched");123return FAILED;124}125log2("debuggee launched");126} catch ( Exception e ) {127log3("ERROR: Exception : " + e);128log2(" test cancelled");129return FAILED;130}131132debuggee.redirectOutput(logHandler);133134vm = debuggee.VM();135136eventQueue = vm.eventQueue();137if (eventQueue == null) {138log3("ERROR: eventQueue == null : TEST ABORTED");139vm.exit(PASS_BASE);140return FAILED;141}142143log2("invocation of the method runTest()");144switch (runTest()) {145146case 0 : log2("test phase has finished normally");147log2(" waiting for the debuggee to finish ...");148debuggee.waitFor();149150log2("......getting the debuggee's exit status");151int status = debuggee.getStatus();152if (status != PASS_BASE) {153log3("ERROR: debuggee returned UNEXPECTED exit status: " +154status + " != PASS_BASE");155testExitCode = FAILED;156} else {157log2("......debuggee returned expected exit status: " +158status + " == PASS_BASE");159}160break;161162default : log3("ERROR: runTest() returned unexpected value");163164case 1 : log3("test phase has not finished normally: debuggee is still alive");165log2("......forcing: vm.exit();");166testExitCode = FAILED;167try {168vm.exit(PASS_BASE);169} catch ( Exception e ) {170log3("ERROR: Exception : " + e);171}172break;173174case 2 : log3("test cancelled due to VMDisconnectedException");175log2("......trying: vm.process().destroy();");176testExitCode = FAILED;177try {178Process vmProcess = vm.process();179if (vmProcess != null) {180vmProcess.destroy();181}182} catch ( Exception e ) {183log3("ERROR: Exception : " + e);184}185break;186}187188return testExitCode;189}190191192/*193* Return value: 0 - normal end of the test194* 1 - ubnormal end of the test195* 2 - VMDisconnectedException while test phase196*/197198private int runTest() {199200try {201testRun();202203log2("waiting for VMDeathEvent");204getEventSet();205if (eventIterator.nextEvent() instanceof VMDeathEvent)206return 0;207208log3("ERROR: last event is not the VMDeathEvent");209return 1;210} catch ( VMDisconnectedException e ) {211log3("ERROR: VMDisconnectedException : " + e);212return 2;213} catch ( Exception e ) {214log3("ERROR: Exception : " + e);215return 1;216}217218}219220private void testRun()221throws JDITestRuntimeException, Exception {222223eventRManager = vm.eventRequestManager();224225ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();226cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);227cpRequest.addClassFilter(debuggeeName);228229cpRequest.enable();230vm.resume();231getEventSet();232cpRequest.disable();233234ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();235debuggeeClass = event.referenceType();236237if (!debuggeeClass.name().equals(debuggeeName))238throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");239240log2(" received: ClassPrepareEvent for debuggeeClass");241242String bPointMethod = "methodForCommunication";243String lineForComm = "lineForComm";244245ThreadReference mainThread = debuggee.threadByNameOrThrow("main");246247BreakpointRequest bpRequest = settingBreakpoint(mainThread,248debuggeeClass,249bPointMethod, lineForComm, "zero");250bpRequest.enable();251252//------------------------------------------------------ testing section253254String fieldName = "testField";255256ExceptionRequest exRequest = null;257258259log1(" TESTING BEGINS");260261for (int i = 0; ; i++) {262263vm.resume();264breakpointForCommunication();265266int instruction = ((IntegerValue)267(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();268269if (instruction == 0) {270vm.resume();271break;272}273274log1(":::::: case: # " + i);275276//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part277278ReferenceType refType = (ReferenceType)279debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName)).type();280281log2("......creating: exRequest = eventRManager.createExceptionRequest(refType, false, true);");282exRequest = eventRManager.createExceptionRequest(refType, false, true);283log2(" check on if request is disabled");284if (exRequest.isEnabled()) {285log3("ERROR: request is enabled");286testExitCode = FAILED;287}288289log2("......creating: exRequest = eventRManager.createExceptionRequest(null, true, false);");290exRequest = eventRManager.createExceptionRequest(null, true, false);291log2(" check on if request is disabled");292if (exRequest.isEnabled()) {293log3("ERROR: request is enabled");294testExitCode = FAILED;295}296297log2("......creating: exRequest = eventRManager.createExceptionRequest(null, true, true);");298exRequest = eventRManager.createExceptionRequest(null, true, true);299log2(" check on if request is disabled");300if (exRequest.isEnabled()) {301log3("ERROR: request is enabled");302testExitCode = FAILED;303}304305//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~306}307log1(" TESTING ENDS");308return;309}310311}312313314