Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventQueue/remove/remove001.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.EventQueue.remove;2425import com.sun.jdi.VirtualMachine;26import com.sun.jdi.request.EventRequest;27import com.sun.jdi.VMDisconnectedException;28import com.sun.jdi.event.*;2930import java.io.*;3132import nsk.share.*;33import nsk.share.jpda.*;34import nsk.share.jdi.*;3536/**37* The test checks that a VMDisconnectedException thrown by38* the JDI method <b>com.sun.jdi.request.EventQueue.remove()</b>39* will always be preceded by a <code>VMDisconnectEvent</code>40* when a debuggee part of the test normally exits.41*/42public class remove001 {43public static final int PASSED = 0;44public static final int FAILED = 2;45public static final int JCK_STATUS_BASE = 95;46static final String DEBUGGEE_CLASS =47"nsk.jdi.EventQueue.remove.remove001t";48static final String COMMAND_READY = "ready";49static final String COMMAND_QUIT = "quit";5051private ArgumentHandler argHandler;52private Log log;53private Debugee debuggee;54private int tot_res = FAILED;5556public static void main(String argv[]) {57System.exit(run(argv,System.out) + JCK_STATUS_BASE);58}5960public static int run(String argv[], PrintStream out) {61return new remove001().runIt(argv, out);62}6364private int runIt(String args[], PrintStream out) {65argHandler = new ArgumentHandler(args);66log = new Log(out, argHandler);67Binder binder = new Binder(argHandler, log);6869debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);70debuggee.redirectStderr(log, "remove001t.err> ");71// dummy IOPipe: just to avoid:72// "Pipe server socket listening error: java.net.SocketException"73IOPipe pipe = debuggee.createIOPipe();7475// Getting JDI events76checkEvents(debuggee.VM().eventQueue());7778debuggee.waitFor();79int debStat = debuggee.getStatus();80if (debStat != (JCK_STATUS_BASE + PASSED)) {81log.complain("TEST FAILED: debuggee's process finished with status: "82+ debStat);83tot_res = FAILED;84} else85log.display("Debuggee's process finished with status: "86+ debStat);8788return tot_res;89}9091private void checkEvents(EventQueue eventQ) {92boolean gotVMDisconnect = false; // VMDisconnectEvent is received93boolean gotVMDeath = false; // VMDeathEvent is received94EventSet eventSet = null;9596debuggee.resume();97while (true) {98try {99eventSet = eventQ.remove();100EventIterator eventIter = eventSet.eventIterator();101while (eventIter.hasNext()) {102Event event = eventIter.nextEvent();103if (event instanceof VMDisconnectEvent) {104gotVMDisconnect = true;105log.display("Got expected VMDisconnectEvent");106break;107} else if (event instanceof VMStartEvent) {108log.display("Got VMStartEvent");109} else if (event instanceof VMDeathEvent) {110gotVMDeath = true;111log.display("Got VMDeathEvent");112}113if (!gotVMDisconnect && !gotVMDeath &&114eventSet.suspendPolicy() !=115EventRequest.SUSPEND_NONE) {116log.display("Calling EventSet.resume() ...");117eventSet.resume();118}119}120} catch(InterruptedException e) {121log.complain("TEST INCOMPLETE: caught " + e);122tot_res = FAILED;123} catch(VMDisconnectedException e) {124if (gotVMDisconnect) {125log.display("\nCHECK PASSED: caught VMDisconnectedException preceded by a VMDisconnectEvent\n");126tot_res = PASSED;127} else {128log.complain("\nTEST FAILED: caught VMDisconnectedException without preceding VMDisconnectEvent\n");129e.printStackTrace();130tot_res = FAILED;131}132break;133}134}135log.display("Stopped JDI events processing");136}137}138139140