Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume009.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 ThreadDeathEvent 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 ThreadDeathRequest, resumes60* the debuggee, and waits for the ThreadDeathEvent.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 resume009 extends TestDebuggerType1 {7576public static void main (String argv[]) {77System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);78}7980public static int run (String argv[], PrintStream out) {81debuggeeName = "nsk.jdi.EventSet.resume.resume009a";82return new resume009().runThis(argv, out);83}8485private String testedClassName = "nsk.jdi.EventSet.resume.TestClass";868788protected void testRun() {8990EventRequest eventRequest = null;9192final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;93final int SUSPEND_THREAD = EventRequest.SUSPEND_EVENT_THREAD;94final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;9596ReferenceType testClassReference = null;979899for (int i = 0; ; i++) {100101if (!shouldRunAfterBreakpoint()) {102vm.resume();103break;104}105106107display(":::::: case: # " + i);108109switch (i) {110111case 0:112eventRequest = settingThreadDeathRequest (113SUSPEND_NONE, "ThreadDeathRequest1");114break;115116case 1:117eventRequest = settingThreadDeathRequest (118SUSPEND_THREAD, "ThreadDeathRequest2");119break;120121case 2:122eventRequest = settingThreadDeathRequest (123SUSPEND_ALL, "ThreadDeathRequest3");124break;125126127default:128throw new Failure("** default case 2 **");129}130131display("......waiting for new ThreadDeathEvent : " + i);132EventSet eventSet = eventHandler.waitForRequestedEventSet(new EventRequest[]{eventRequest}, waitTime, true);133134EventIterator eventIterator = eventSet.eventIterator();135Event newEvent = eventIterator.nextEvent();136137if ( !(newEvent instanceof ThreadDeathEvent)) {138setFailedStatus("ERROR: new event is not ThreadDeathEvent");139} else {140141String property = (String) newEvent.request().getProperty("number");142display(" got new ThreadDeathEvent with propety 'number' == " + property);143144display("......checking up on EventSet.resume()");145display("......--> vm.suspend();");146vm.suspend();147148display(" getting : Map<String, Integer> suspendsCounts1");149150Map<String, Integer> suspendsCounts1 = new HashMap<String, Integer>();151for (ThreadReference threadReference : vm.allThreads()) {152suspendsCounts1.put(threadReference.name(), threadReference.suspendCount());153}154display(suspendsCounts1.toString());155156display(" eventSet.resume;");157eventSet.resume();158159display(" getting : Map<String, Integer> suspendsCounts2");160Map<String, Integer> suspendsCounts2 = new HashMap<String, Integer>();161for (ThreadReference threadReference : vm.allThreads()) {162suspendsCounts2.put(threadReference.name(), threadReference.suspendCount());163}164165display(" getting : int policy = eventSet.suspendPolicy();");166int policy = eventSet.suspendPolicy();167display(suspendsCounts2.toString());168169switch (policy) {170171case SUSPEND_NONE :172display(" case SUSPEND_NONE");173for (String threadName : suspendsCounts1.keySet()) {174display(" checking " + threadName);175if (!suspendsCounts2.containsKey(threadName)) {176complain("ERROR: couldn't get ThreadReference for " + threadName);177testExitCode = TEST_FAILED;178break;179}180int count1 = suspendsCounts1.get(threadName);181int count2 = suspendsCounts2.get(threadName);182if (count1 != count2) {183complain("ERROR: suspendCounts don't match for : " + threadName);184complain("before resuming : " + count1);185complain("after resuming : " + count2);186testExitCode = TEST_FAILED;187break;188}189}190break;191192case SUSPEND_THREAD :193display(" case SUSPEND_THREAD");194for (String threadName : suspendsCounts1.keySet()) {195display("checking " + threadName);196if (!suspendsCounts2.containsKey(threadName)) {197complain("ERROR: couldn't get ThreadReference for " + threadName);198testExitCode = TEST_FAILED;199break;200}201int count1 = suspendsCounts1.get(threadName);202int count2 = suspendsCounts2.get(threadName);203String eventThreadName = ((ThreadDeathEvent)newEvent).thread().name();204int expectedValue = count2 + (eventThreadName.equals(threadName) ? 1 : 0);205if (count1 != expectedValue) {206complain("ERROR: suspendCounts don't match for : " + threadName);207complain("before resuming : " + count1);208complain("after resuming : " + count2);209testExitCode = TEST_FAILED;210break;211}212}213break;214215case SUSPEND_ALL :216217display(" case SUSPEND_ALL");218for (String threadName : suspendsCounts1.keySet()) {219display("checking " + threadName);220221if (!newEvent.request().equals(eventRequest))222break;223if (!suspendsCounts2.containsKey(threadName)) {224complain("ERROR: couldn't get ThreadReference for " + threadName);225testExitCode = TEST_FAILED;226break;227}228int count1 = suspendsCounts1.get(threadName);229int count2 = suspendsCounts2.get(threadName);230if (count1 != count2 + 1) {231complain("ERROR: suspendCounts don't match for : " + threadName);232complain("before resuming : " + count1);233complain("after resuming : " + count2);234testExitCode = TEST_FAILED;235break;236}237}238break;239240default: throw new Failure("** default case 1 **");241}242informDebuggeeTestCase(i);243}244245display("......--> vm.resume()");246vm.resume();247}248return;249}250251private ThreadDeathRequest settingThreadDeathRequest(int suspendPolicy,252String property) {253try {254ThreadDeathRequest tsr = eventRManager.createThreadDeathRequest();255tsr.addCountFilter(1);256tsr.setSuspendPolicy(suspendPolicy);257tsr.putProperty("number", property);258return tsr;259} catch ( Exception e ) {260throw new Failure("** FAILURE to set up ThreadDeathRequest **");261}262}263/**264* Inform debuggee which thread test the debugger has completed.265* Used for synchronization, so the debuggee does not move too quickly.266* @param testCase index of just completed test267*/268void informDebuggeeTestCase(int testCase) {269try {270((ClassType)debuggeeClass)271.setValue(debuggeeClass.fieldByName("testCase"),272vm.mirrorOf(testCase));273} catch (InvalidTypeException ite) {274throw new Failure("** FAILURE setting testCase **");275} catch (ClassNotLoadedException cnle) {276throw new Failure("** FAILURE notifying debuggee **");277} catch (VMDisconnectedException e) {278throw new Failure("** FAILURE debuggee connection **");279}280}281}282283284