Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/putProperty/putproperty001.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.EventRequest.putProperty;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* EventRequest. <BR>39* <BR>40* The test checks that results of the method <BR>41* <code>com.sun.jdi.EventRequest.putProperty()</code> <BR>42* complies with its spec. <BR>43* <BR>44* The test checks up on following assertions: <BR>45* - a value of property is equal to one assigned by <BR>46* last method putProperty(key, value); <BR>47* - after calling putProperty(key, null) <BR>48* the value of the property 'key' is also null. <BR>49* The cases to check include Requests of all sub-types. <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_ALL <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 loop. <BR>67* - The debugger resumes the debuggee and waits for the BreakpointEvent.<BR>68* - The debuggee prepares new check case (as if) 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 case 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 putproperty001 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 putproperty001().runThis(argv, out);9293if (exitCode != PASSED) {94System.out.println("TEST FAILED");95}96return testExitCode;97}9899// ************************************************ test parameters100101private String debuggeeName =102"nsk.jdi.EventRequest.putProperty.putproperty001a";103104private String testedClassName =105"nsk.jdi.EventRequest.putProperty.TestClass11";106107//====================================================== test program108109private int runThis (String argv[], PrintStream out) {110111argsHandler = new ArgumentHandler(argv);112logHandler = new Log(out, argsHandler);113Binder binder = new Binder(argsHandler, logHandler);114115waitTime = argsHandler.getWaitTime() * 60000;116117try {118log2("launching a debuggee :");119log2(" " + debuggeeName);120if (argsHandler.verbose()) {121debuggee = binder.bindToDebugee(debuggeeName + " -vbs");122} else {123debuggee = binder.bindToDebugee(debuggeeName);124}125if (debuggee == null) {126log3("ERROR: no debuggee launched");127return FAILED;128}129log2("debuggee launched");130} catch ( Exception e ) {131log3("ERROR: Exception : " + e);132log2(" test cancelled");133return FAILED;134}135136debuggee.redirectOutput(logHandler);137138vm = debuggee.VM();139140eventQueue = vm.eventQueue();141if (eventQueue == null) {142log3("ERROR: eventQueue == null : TEST ABORTED");143vm.exit(PASS_BASE);144return FAILED;145}146147log2("invocation of the method runTest()");148switch (runTest()) {149150case 0 : log2("test phase has finished normally");151log2(" waiting for the debuggee to finish ...");152debuggee.waitFor();153154log2("......getting the debuggee's exit status");155int status = debuggee.getStatus();156if (status != PASS_BASE) {157log3("ERROR: debuggee returned UNEXPECTED exit status: " +158status + " != PASS_BASE");159testExitCode = FAILED;160} else {161log2("......debuggee returned expected exit status: " +162status + " == PASS_BASE");163}164break;165166default : log3("ERROR: runTest() returned unexpected value");167168case 1 : log3("test phase has not finished normally: debuggee is still alive");169log2("......forcing: vm.exit();");170testExitCode = FAILED;171try {172vm.exit(PASS_BASE);173} catch ( Exception e ) {174log3("ERROR: Exception : " + e);175}176break;177178case 2 : log3("test cancelled due to VMDisconnectedException");179log2("......trying: vm.process().destroy();");180testExitCode = FAILED;181try {182Process vmProcess = vm.process();183if (vmProcess != null) {184vmProcess.destroy();185}186} catch ( Exception e ) {187log3("ERROR: Exception : " + e);188}189break;190}191192return testExitCode;193}194195196/*197* Return value: 0 - normal end of the test198* 1 - ubnormal end of the test199* 2 - VMDisconnectedException while test phase200*/201202private int runTest() {203204try {205testRun();206207log2("waiting for VMDeathEvent");208getEventSet();209if (eventIterator.nextEvent() instanceof VMDeathEvent)210return 0;211212log3("ERROR: last event is not the VMDeathEvent");213return 1;214} catch ( VMDisconnectedException e ) {215log3("ERROR: VMDisconnectedException : " + e);216return 2;217} catch ( Exception e ) {218log3("ERROR: Exception : " + e);219return 1;220}221222}223224private void testRun()225throws JDITestRuntimeException, Exception {226227eventRManager = vm.eventRequestManager();228229ClassPrepareRequest cpRequest = eventRManager.createClassPrepareRequest();230cpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD);231cpRequest.addClassFilter(debuggeeName);232233cpRequest.enable();234vm.resume();235getEventSet();236cpRequest.disable();237238ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();239debuggeeClass = event.referenceType();240241if (!debuggeeClass.name().equals(debuggeeName))242throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");243244log2(" received: ClassPrepareEvent for debuggeeClass");245246String bPointMethod = "methodForCommunication";247String lineForComm = "lineForComm";248249ThreadReference mainThread = debuggee.threadByNameOrThrow("main");250251BreakpointRequest bpRequest = settingBreakpoint(mainThread,252debuggeeClass,253bPointMethod, lineForComm, "zero");254bpRequest.enable();255256//------------------------------------------------------ testing section257258259EventRequest eventRequest1 = null;260261String fieldName1 = "var101";262String fieldName2 = "excObj";263264ThreadReference thread1 = null;265String threadName1 = "thread1";266267ReferenceType testClassReference = null;268269String propertyName = "name";270String propertyValue1 = "value1";271String propertyValue2 = "value2";272273274log1(" TESTING BEGINS");275276for (int i = 0; ; i++) {277278vm.resume();279breakpointForCommunication();280281int instruction = ((IntegerValue)282(debuggeeClass.getValue(debuggeeClass.fieldByName("instruction")))).value();283284if (instruction == 0) {285vm.resume();286break;287}288289log1(":::::: case: # " + i);290291//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part292293294switch (i) {295296case 0:297thread1 = debuggee.threadByNameOrThrow(threadName1);298299log2("......setting up StepRequest");300eventRequest1 = eventRManager.createStepRequest301(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);302break;303304case 1:305testClassReference = (ReferenceType) vm.classesByName(testedClassName).get(0);306307log2("......setting up AccessWatchpointRequest");308eventRequest1 = eventRManager.createAccessWatchpointRequest309(testClassReference.fieldByName(fieldName1));310break;311312case 2:313log2(".....setting up ModificationWatchpointRequest");314eventRequest1 = eventRManager.createModificationWatchpointRequest315(testClassReference.fieldByName(fieldName1));316break;317318case 3:319log2(".....setting up ClassPrepareRequest");320eventRequest1 = eventRManager.createClassPrepareRequest();321break;322323case 4:324log2(".....setting up ClassUnloadRequest");325eventRequest1 = eventRManager.createClassUnloadRequest();326break;327328case 5:329log2(".....setting up MethodEntryRequest");330eventRequest1 = eventRManager.createMethodEntryRequest();331break;332333case 6:334log2(".....setting up MethodExitRequest");335eventRequest1 = eventRManager.createMethodExitRequest();336break;337338case 7:339log2(".....setting up ThreadDeathRequest");340eventRequest1 = eventRManager.createThreadDeathRequest();341break;342343case 8:344log2(".....setting up ThreadStartRequest");345eventRequest1 = eventRManager.createThreadStartRequest();346break;347348case 9:349log2(".....setting up VMDeathRequest");350eventRequest1 = eventRManager.createVMDeathRequest();351break;352353case 10:354log2(".....setting up ExceptionRequest");355eventRequest1 = eventRManager.createExceptionRequest(356(ReferenceType)357(debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName2))).type(),358true, true );359break;360361case 11:362log2(".....setting up BreakpointRequest");363eventRequest1 = eventRManager.createBreakpointRequest(breakpLocation);364break;365366367default:368throw new JDITestRuntimeException("** default case 2 **");369}370371log2("......eventRequest1.putProperty(propertyName, propertyValue1);");372eventRequest1.putProperty(propertyName, propertyValue1);373log2(" eventRequest1.putProperty(propertyName, propertyValue2);");374eventRequest1.putProperty(propertyName, propertyValue2);375376log2(" checking up on eventRequest1");377if ( !eventRequest1.getProperty(propertyName).equals(propertyValue2) ) {378testExitCode = FAILED;379log3("ERROR: property is not expected");380}381382log2("......eventRequest1.putProperty(propertyName, null);");383eventRequest1.putProperty(propertyName, null);384385log2(" checking up on eventRequest1");386if ( eventRequest1.getProperty(propertyName)!= null ) {387testExitCode = FAILED;388log3("ERROR: property is not the null");389}390391eventRequest1.setEnabled(false);392393//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~394}395log1(" TESTING ENDS");396return;397}398399}400401402