Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001.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.jdwp.VirtualMachine.Resume;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class resume001 {33static final int JCK_STATUS_BASE = 95;34static final int PASSED = 0;35static final int FAILED = 2;36static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.Resume";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "resume001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.Resume";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Resume;4243public static void main (String argv[]) {44System.exit(run(argv,System.out) + JCK_STATUS_BASE);45}4647public static int run(String argv[], PrintStream out) {48return new resume001().runIt(argv, out);49}5051public int runIt(String argv[], PrintStream out) {5253boolean success = true;5455try {56ArgumentHandler argumentHandler = new ArgumentHandler(argv);57final Log log = new Log(out, argumentHandler);58long timeout = argumentHandler.getWaitTime() * 60 * 1000; // milliseconds5960try {6162Binder binder = new Binder(argumentHandler, log);63log.display("Start debugee VM");64Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);65Transport transport = debugee.getTransport();66final IOPipe pipe = debugee.createIOPipe();6768log.display("Waiting for VM_INIT event");69debugee.waitForVMInit();7071log.display("Querying for IDSizes");72debugee.queryForIDSizes();7374// begin test of JDWP command7576try {77CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);7879log.display("Sending command packet:\n" + command);80transport.write(command);8182log.display("Waiting for reply packet");83ReplyPacket reply = new ReplyPacket();84transport.read(reply);85log.display("Reply packet received:\n" + reply);8687log.display("Checking reply packet header");88reply.checkHeader(command.getPacketID());8990log.display("Parsing reply packet:");91reply.resetPosition();9293if (! reply.isParsed()) {94log.complain("Extra bytes in reply packet at: " + reply.currentPosition());95success = false;96}9798} catch (Exception e) {99log.complain("Caught exception: " + e);100success = false;101}102103// check if debugee has been actually resumed104105if (success) {106log.display("Waiting for debugee continues execution or timeout exceeds");107108// separate thread for waiting for reply from debuggee109class TimeoutHandler extends Thread {110boolean success = false;111public void run() {112log.display("Waiting for command: " + "ready");113String cmd = pipe.readln();114log.display("Received command: " + cmd);115if (cmd.equals("ready")) {116success = true;117log.display("Debugee was resumed successfully");118} else {119log.complain("Unexpected command received: " + cmd);120}121}122}123124// start separate thread125TimeoutHandler timeoutHandler = new TimeoutHandler();126timeoutHandler.start();127128// wait for thread finished or timeout exceeds129try {130timeoutHandler.join(timeout);131if (timeoutHandler.isAlive()) {132log.display("Interrupting thread because timeout exceeds");133timeoutHandler.interrupt();134}135} catch (InterruptedException e) {136throw new Failure("Main thread interrupted: " + e);137}138139// check resuts140if (!timeoutHandler.success) {141log.complain("Debugee has not been resumed by command");142success = false;143}144}145146// end test of JDWP command147148log.display("Sending command: " + "quit");149pipe.println("quit");150151log.display("Waiting for debugee exits");152int code = debugee.waitFor();153if (code == JCK_STATUS_BASE + PASSED) {154log.display("Debugee PASSED: " + code);155} else {156log.complain("Debugee FAILED: " + code);157success = false;158}159160} catch (Exception e) {161log.complain("Unexpected exception: " + e);162e.printStackTrace(out);163success = false;164}165166if (!success) {167log.complain("TEST FAILED");168return FAILED;169}170171} catch (Exception e) {172out.println("Unexpected exception: " + e);173e.printStackTrace(out);174out.println("TEST FAILED");175return FAILED;176}177178out.println("TEST PASSED");179return PASSED;180181}182183}184185186