Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq001.java
41161 views
/*1* Copyright (c) 2001, 2019, 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.EventRequestManager.createStepRequest;2425import com.sun.jdi.ThreadReference;26import com.sun.jdi.VirtualMachine;27import com.sun.jdi.request.StepRequest;28import com.sun.jdi.request.EventRequestManager;29import com.sun.jdi.request.DuplicateRequestException;30import com.sun.jdi.ObjectCollectedException;31import com.sun.jdi.VMMismatchException;32import java.util.Iterator;33import java.util.LinkedList;34import java.util.List;35import java.io.*;36import nsk.share.*;37import nsk.share.jpda.*;38import nsk.share.jdi.*;394041/**42* The test checks that only one pending JDI step request is43* allowed per thread, i.e. the JDI method44* <code>com.sun.jdi.request.EventRequestManager.createStepRequest()</code>45* properly throws a <code>DuplicateRequestException</code> if there46* is already a pending step request for the specified thread.47*/48public class crstepreq001 {49public static final int PASSED = 0;50public static final int FAILED = 2;51public static final int JCK_STATUS_BASE = 95;52static final String DEBUGGEE_CLASS =53"nsk.jdi.EventRequestManager.createStepRequest.crstepreq001t";54static final String DEBUGGEE_THRD = "debuggee_thr";55static final String COMMAND_READY = "ready";56static final String COMMAND_QUIT = "quit";5758static final int RSTS_NUM = 6;59static final int RESTRICTIONS[][] = {60{StepRequest.STEP_MIN, StepRequest.STEP_INTO},61{StepRequest.STEP_MIN, StepRequest.STEP_OVER},62{StepRequest.STEP_MIN, StepRequest.STEP_OUT},63{StepRequest.STEP_LINE, StepRequest.STEP_INTO},64{StepRequest.STEP_LINE, StepRequest.STEP_OVER},65{StepRequest.STEP_LINE, StepRequest.STEP_OUT}66};6768private Log log;69private IOPipe pipe;70private Debugee debuggee;71private int tot_res = PASSED;7273public static void main (String argv[]) {74System.exit(run(argv,System.out) + JCK_STATUS_BASE);75}7677public static int run(String argv[], PrintStream out) {78return new crstepreq001().runIt(argv, out);79}8081private int runIt(String args[], PrintStream out) {82ArgumentHandler argHandler = new ArgumentHandler(args);83log = new Log(out, argHandler);84Binder binder = new Binder(argHandler, log);85ThreadReference thR = null;86List threads;87List<StepRequest> enabledStepRequests = new LinkedList<>();88String cmd;8990debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);91pipe = debuggee.createIOPipe();92debuggee.redirectStderr(log, "crstepreq001t.err> ");93VirtualMachine vm = debuggee.VM();94EventRequestManager erManager = vm.eventRequestManager();95debuggee.resume();96cmd = pipe.readln();97if (!cmd.equals(COMMAND_READY)) {98log.complain("TEST BUG: unknown debuggee's command: "99+ cmd);100return quitDebuggee(FAILED);101}102103try {104threads = vm.allThreads();105} catch (Exception e) {106log.complain("TEST FAILURE: allThreads: " + e);107return quitDebuggee(FAILED);108}109Iterator iter = threads.iterator();110while (iter.hasNext()) {111thR = (ThreadReference) iter.next();112if (thR.name().equals(DEBUGGEE_THRD)) {113log.display("\nCreating StepRequest for the debuggee's thread \""114+ thR.name() + "\"");115try {116StepRequest sReq = erManager.createStepRequest(thR,117RESTRICTIONS[0][0],RESTRICTIONS[0][1]);118sReq.enable();119enabledStepRequests.add(sReq);120} catch (DuplicateRequestException e) {121log.complain("TEST FAILURE: createStepRequest: caught " + e);122return quitDebuggee(FAILED);123} catch (ObjectCollectedException e) {124log.complain("TEST FAILURE: createStepRequest: caught " + e);125return quitDebuggee(FAILED);126} catch (VMMismatchException e) {127log.complain("TEST FAILURE: createStepRequest: caught " + e);128return quitDebuggee(FAILED);129}130break;131}132}133134// Check that createStepRequest() throws DuplicateRequestException135// to indicate a duplicate event request per thread136for(int i=0; i<RSTS_NUM; i++) {137log.display("\n" + (i+1)138+ ") Trying to create a duplicate StepRequest object\n\twith size="139+ RESTRICTIONS[i][0] + "; depth="140+ RESTRICTIONS[i][1] + " for the debuggee's thread \""141+ thR.name() + "\"");142try {143StepRequest sReq = erManager.createStepRequest(thR,144RESTRICTIONS[i][0], RESTRICTIONS[i][1]);145log.complain("TEST CASE #" + (i+1)146+ " FAILED: createStepRequest successfully done\n"147+ "\tfor a duplicate StepRequest object per the specified thread \""148+ thR.name() + "\"\n"149+ "\tbut it should throw DuplicateRequestException");150tot_res = FAILED;151} catch (DuplicateRequestException e) {152log.display("TEST CASE #" + (i+1)153+ " PASSED: createStepRequest: caught " + e);154} catch (ObjectCollectedException e) {155log.complain("TEST CASE #" + (i+1)156+ " FAILED: createStepRequest: caught " + e);157log.complain("\tbut it should throw DuplicateRequestException");158tot_res = FAILED;159} catch (VMMismatchException e) {160log.complain("TEST CASE #" + (i+1)161+ " FAILED: createStepRequest: caught " + e);162log.complain("\tbut it should throw DuplicateRequestException");163tot_res = FAILED;164}165}166167enabledStepRequests.forEach(s -> erManager.deleteEventRequest(s));168// There is a chance that a single step event had been posted after169// the step request was created and before it was deleted. In this170// case the debuggee VM is in the suspended state.171vm.resume();172return quitDebuggee(tot_res);173}174175private int quitDebuggee(int stat) {176pipe.println(COMMAND_QUIT);177debuggee.waitFor();178return stat;179}180}181182183