Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume008.java
41161 views
/*1* Copyright (c) 2001, 2018, 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.*;3536import static nsk.share.Consts.TEST_FAILED;3738/**39* The test for the implementation of an object of the type40* EventSet.41*42* The test checks that results of the method43* <code>com.sun.jdi.EventSet.resume()</code>44* complies with its spec.45*46* Test cases include all three possible suspensions, NONE,47* EVENT_THREAD, and ALL, for ThreadStartEvent sets.48*49* To check up on the method, a debugger,50* upon getting new set for the EventSet,51* suspends VM with the method VirtualMachine.suspend(),52* gets the List of debuggee's threads calling VM.allThreads(),53* invokes the method EventSet.resume(), and54* gets another List of debuggee's threads.55* The debugger then compares values of56* each thread's suspendCount from first and second Lists.57*58* The test works as follows.59* - The debugger sets up a ThreadStartRequest, resumes60* the debuggee, and waits for the ThreadStartEvent.61* - The debuggee creates and starts new thread62* to be resulting in the event.63* - Upon getting new event, the debugger64* performs the check corresponding to the event.65* - The debugger informs the debuggee when it completes66* each test case, so it will wait before hitting67* communication breakpoints.68* This prevents the breakpoint SUSPEND_ALL policy69* disrupting the first test case check for70* SUSPEND_NONE, if the debuggee gets ahead of71* the debugger processing.72*/7374public class resume008 extends TestDebuggerType1 {757677public static void main (String argv[]) {78System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);79}8081public static int run (String argv[], PrintStream out) {82debuggeeName = "nsk.jdi.EventSet.resume.resume008a";83return new resume008().runThis(argv, out);84}8586private String testedClassName = "nsk.jdi.EventSet.resume.TestClass";878889protected void testRun() {9091EventRequest eventRequest = null;9293final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;94final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;95final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;9697ReferenceType testClassReference = null;9899100for (int i = 0; ; i++) {101102if (!shouldRunAfterBreakpoint()) {103vm.resume();104break;105}106107108display(":::::: case: # " + i);109110switch (i) {111112case 0:113eventRequest = settingThreadStartRequest (114SUSPEND_NONE, "ThreadStartRequest1");115break;116117case 1:118eventRequest = settingThreadStartRequest (119SUSPEND_THREAD, "ThreadStartRequest2");120break;121122case 2:123eventRequest = settingThreadStartRequest (124SUSPEND_ALL, "ThreadStartRequest3");125break;126127128default:129throw new Failure("** default case 2 **");130}131132display("......waiting for new ThreadStartEvent : " + i);133EventSet eventSet = eventHandler134.waitForRequestedEventSet(new EventRequest[]{eventRequest},135waitTime, true);136137EventIterator eventIterator = eventSet.eventIterator();138Event newEvent = eventIterator.nextEvent();139140if ( !(newEvent instanceof ThreadStartEvent)) {141setFailedStatus("ERROR: new event is not ThreadStartEvent");142} else {143144String property = (String) newEvent.request().getProperty("number");145display(" got new ThreadStartEvent with propety 'number' == "146+ property);147148display("......checking up on EventSet.resume()");149display("......--> vm.suspend();");150vm.suspend();151152display(" getting : Map<String, Integer> suspendsCounts1");153154Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();155for (ThreadReference threadReference : vm.allThreads()) {156suspendsCounts1.put(threadReference.name(),157threadReference.suspendCount());158}159display(suspendsCounts1.toString());160161display(" eventSet.resume;");162eventSet.resume();163164display(" getting : Map<String, Integer> suspendsCounts2");165Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();166for (ThreadReference threadReference : vm.allThreads()) {167suspendsCounts2.put(threadReference.name(),168threadReference.suspendCount());169}170display(suspendsCounts2.toString());171172display(" getting : int policy = eventSet.suspendPolicy();");173int policy = eventSet.suspendPolicy();174175switch (policy) {176177case SUSPEND_NONE :178display(" case SUSPEND_NONE");179for (String threadName : suspendsCounts1.keySet()) {180display(" checking " + threadName);181if (!suspendsCounts2.containsKey(threadName)) {182complain("ERROR: couldn't get ThreadReference for "183+ threadName);184testExitCode = TEST_FAILED;185break;186}187int count1 = suspendsCounts1.get(threadName);188int count2 = suspendsCounts2.get(threadName);189if (count1 != count2) {190complain("ERROR: suspendCounts don't match for : "191+ threadName);192complain("before resuming : " + count1);193complain("after resuming : " + count2);194testExitCode = TEST_FAILED;195break;196}197}198break;199200case SUSPEND_THREAD :201display(" case SUSPEND_THREAD");202for (String threadName : suspendsCounts1.keySet()) {203display("checking " + threadName);204if (!suspendsCounts2.containsKey(threadName)) {205complain("ERROR: couldn't get ThreadReference for "206+ threadName);207testExitCode = TEST_FAILED;208break;209}210int count1 = suspendsCounts1.get(threadName);211int count2 = suspendsCounts2.get(threadName);212String eventThreadName = ((ThreadStartEvent)newEvent)213.thread().name();214int expectedValue = count2 +215(eventThreadName.equals(threadName) ? 1 : 0);216if (count1 != expectedValue) {217complain("ERROR: suspendCounts don't match for : "218+ threadName);219complain("before resuming : " + count1);220complain("after resuming : " + count2);221testExitCode = TEST_FAILED;222break;223}224}225break;226227case SUSPEND_ALL :228display(" case SUSPEND_ALL");229for (String threadName : suspendsCounts1.keySet()) {230display("checking " + threadName);231if (!newEvent.request().equals(eventRequest))232break;233if (!suspendsCounts2.containsKey(threadName)) {234complain("ERROR: couldn't get ThreadReference for "235+ threadName);236testExitCode = TEST_FAILED;237break;238}239int count1 = suspendsCounts1.get(threadName);240int count2 = suspendsCounts2.get(threadName);241if (count1 != count2 + 1) {242complain("ERROR: suspendCounts don't match for : "243+ threadName);244complain("before resuming : " + count1);245complain("after resuming : " + count2);246testExitCode = TEST_FAILED;247break;248}249}250break;251default: throw new Failure("** default case 1 **");252}253informDebuggeeTestCase(i);254255}256display("......--> vm.resume()");257vm.resume();258}259return;260}261private ThreadStartRequest settingThreadStartRequest(int suspendPolicy,262String property) {263try {264ThreadStartRequest tsr = eventRManager.createThreadStartRequest();265tsr.addCountFilter(1);266tsr.setSuspendPolicy(suspendPolicy);267tsr.putProperty("number", property);268return tsr;269} catch ( Exception e ) {270throw new Failure("** FAILURE to set up ThreadStartRequest **");271}272}273/**274* Inform debuggee which thread test the debugger has completed.275* Used for synchronization, so the debuggee does not move too quickly.276* @param testCase index of just completed test277*/278void informDebuggeeTestCase(int testCase) {279try {280((ClassType)debuggeeClass)281.setValue(debuggeeClass.fieldByName("testCase"),282vm.mirrorOf(testCase));283} catch (InvalidTypeException ite) {284throw new Failure("** FAILURE setting testCase **");285} catch (ClassNotLoadedException cnle) {286throw new Failure("** FAILURE notifying debuggee **");287} catch (VMDisconnectedException e) {288throw new Failure("** FAILURE debuggee connection **");289}290}291}292293294