Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/SerialExecutionDebuggee.java
41161 views
/*1* Copyright (c) 2006, 2020, 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*/22package nsk.share.jdi;2324import java.io.IOException;25import java.io.StreamTokenizer;26import java.io.StringReader;27import nsk.share.Consts;28import sun.hotspot.WhiteBox;2930/*31* This class is intended for execution several JDI tests in single VM and used together with nsk.share.jdi.SerialExecutionDebugger32*33* SerialExecutionDebuggee handles 2 commands:34* - COMMAND_EXECUTE_DEBUGGEE:<debuggee_class_name> :35* initialize 'currentDebuggee' with instance of class 'debuggee_class_name'(this class should36* be subclass of nsk.share.jpda.AbstractDebugeeTest) and execute it's method doTest()37*38* - COMMAND_CLEAR_DEBUGGEE39* set 'currentDebuggee' to null40*41* For more detailed description of serial test execution see SerialExecutionDebugger42*/43public class SerialExecutionDebuggee extends AbstractJDIDebuggee {44private final WhiteBox WB = WhiteBox.getWhiteBox();4546public static void main(String args[]) {47new SerialExecutionDebuggee().doTest(args);48}4950// command:<debuggee_class_name>[ debugee_parameters]51public static final String COMMAND_EXECUTE_DEBUGGEE = "COMMAND_EXECUTE_DEBUGGEE";5253public static final String COMMAND_CLEAR_DEBUGGEE = "COMMAND_CLEAR_DEBUGGEE";5455private AbstractJDIDebuggee currentDebuggee;5657public boolean parseCommand(String command) {58if (super.parseCommand(command))59return true;6061if (command.startsWith(COMMAND_EXECUTE_DEBUGGEE)) {62String debuggeeClassName = null;6364try {65StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command));66tokenizer.resetSyntax();67tokenizer.wordChars(Integer.MIN_VALUE, Integer.MAX_VALUE);68tokenizer.whitespaceChars(':', ':');6970tokenizer.nextToken();7172if (tokenizer.nextToken() != StreamTokenizer.TT_WORD) {73log.complain("Invalid command format: " + command);74System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);75}7677debuggeeClassName = tokenizer.sval;78} catch (IOException e) {79log.complain("Invalid command format: " + command);80System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);81}8283try {84// parse debuggee parameters85String[] debuggeeParameters = {};8687int index = debuggeeClassName.indexOf(' ');8889if (index > 0) {90debuggeeParameters = debuggeeClassName.substring(index).split(" ");91log.display("Debuggee parameters: " + debuggeeClassName.substring(index));92debuggeeClassName = debuggeeClassName.substring(0, index);93}9495// create debuggee object96Class debuggeeClass = Class.forName(debuggeeClassName);9798if (!AbstractJDIDebuggee.class.isAssignableFrom(debuggeeClass)) {99log.complain("Invalid debugee class: " + debuggeeClass);100System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);101}102103currentDebuggee = (AbstractJDIDebuggee) debuggeeClass.newInstance();104105// pass to the current debuggee already created objects:106// argHandler, log, pipe107currentDebuggee.initDebuggee(argHandler, log, pipe, debuggeeParameters, false);108} catch (Exception e) {109log.complain("Unexpected exception during debuggee initialization: " + e);110e.printStackTrace(log.getOutStream());111System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);112}113114try {115// current debuggee performs test116currentDebuggee.doTest();117118if (currentDebuggee.getSuccess()) {119log.display("Debuggee " + currentDebuggee + " finished successfully");120} else {121setSuccess(false);122log.complain("Debuggee " + currentDebuggee + "finished with errors");123}124125return true;126} catch (Exception e) {127log.complain("Unexpected exception during debuggee execution: " + e);128e.printStackTrace(log.getOutStream());129System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);130}131} else if (command.equals(COMMAND_CLEAR_DEBUGGEE)) {132currentDebuggee = null;133134// The debuggee can intentionally create inflated monitors.135// With async deflation, this can pin a StateTestThread object136// until the next deflation cycle. This can confuse tests run137// by nsk/jdi/stress/serial/mixed002/TestDescription.java that138// expect only one StateTestThread object to exist in each139// of the debugger tests that mixed002 runs serially in the140// same VM.141WB.deflateIdleMonitors();142143return true;144}145146return false;147}148149}150151152