OpenJDK / jdk / jdk12
changeset 50317:cf71bff5f533
8199371: [TESTBUG] Open source vm testbase JDWP tests
Reviewed-by: sspitsyn, mseledtsov
line wrap: on
line diff
--- a/test/hotspot/jtreg/ProblemList.txt Wed May 30 16:18:56 2018 -0700 +++ b/test/hotspot/jtreg/ProblemList.txt Wed May 30 20:54:45 2018 -0700 @@ -172,4 +172,6 @@ vmTestbase/heapdump/JMapHeapCore/TestDescription.java 8023376,8001227,8051445 generic-all vmTestbase/heapdump/JMapMetaspaceCore/TestDescription.java 8023376,8001227,8051445 generic-all +vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java 7199837 generic-all + #############################################################################
--- a/test/hotspot/jtreg/TEST.groups Wed May 30 16:18:56 2018 -0700 +++ b/test/hotspot/jtreg/TEST.groups Wed May 30 20:54:45 2018 -0700 @@ -1750,6 +1750,122 @@ vmTestbase/nsk/jvmti/unit/GetAllStackTraces/getallstktr001/TestDescription.java \ vmTestbase/nsk/jvmti/unit/GetConstantPool/getcpool001/TestDescription.java +# JDWP tests +vmTestbase_nsk_jdwp = \ + vmTestbase/nsk/jdwp + +vmTestbase_nsk_jdwp_quick = \ + vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java \ + vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java \ + vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/FIELD_ACCESS/fldaccess001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/FIELD_MODIFICATION/fldmodification001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/CLASS_UNLOAD/clsunload001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/METHOD_ENTRY/methentry001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/METHOD_EXIT/methexit001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep002/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep003/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/THREAD_DEATH/thrdeath001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/THREAD_START/thrstart001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/VM_START/vmstart001/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/Composite/composite001/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/Clear/clear001/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp001/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/Set/set001/TestDescription.java \ + vmTestbase/nsk/jdwp/EventRequest/Set/set002/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/LineTable/linetable001/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/VariableTable/vartable001/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/InvokeMethod/invokemeth001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/IsCollected/iscollected001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/MonitorInfo/monitorinfo001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/ReferenceType/referencetype001/TestDescription.java \ + vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/ClassLoader/classloader001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/ClassObject/classobj001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Fields/fields001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/GetValues/getvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Interfaces/interfaces001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Methods/methods001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Modifiers/modifiers001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/NestedTypes/nestedtypes001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Signature/signature001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/SourceFile/srcfile001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Status/status001/TestDescription.java \ + vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001/TestDescription.java \ + vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001/TestDescription.java \ + vmTestbase/nsk/jdwp/StringReference/Value/value001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadGroupReference/Parent/parent001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Name/name001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitors/ownmonitors001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Status/status001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/Suspend/suspend001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001/TestDescription.java \ + vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Capabilities/capabilities001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/IDSizes/idsizes001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Version/version001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/Version/version002/TestDescription.java \ + vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath002/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete002/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/SourceDebugExtension/srcdebugext001/TestDescription.java \ + vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001/TestDescription.java \ + vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001/TestDescription.java \ + vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/FieldsWithGeneric/fldwithgeneric001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/MethodsWithGeneric/methwithgeneric001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/SignatureWithGeneric/sigwithgeneric001/TestDescription.java \ + vmTestbase/nsk/jdwp/ReferenceType/Instances/instances001/instances001.java \ + vmTestbase/nsk/jdwp/ReferenceType/Instances/instances002/instances002.java \ + vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects001/referringObjects001.java \ + vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects002/referringObjects002.java \ + vmTestbase/nsk/jdwp/VirtualMachine/InstanceCounts/instanceCounts001/instanceCounts001.java \ + vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java \ + vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo001/ownedMonitorsStackDepthInfo001.java \ + vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo002/ownedMonitorsStackDepthInfo002.java + vmTestbase_nsk_stress = \ vmTestbase/nsk/stress
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.GetValues; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ArrayReference.GetValues. + * + * See getvalues001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class getvalues001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ArrayReference.GetValues"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "getvalues001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ArrayReference.GetValues"; + static final int JDWP_COMMAND_ID = JDWP.Command.ArrayReference.GetValues; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // name of the static field in the tested class with the tested object value + static final String ARRAY_FIELD_NAME = getvalues001a.ARRAY_FIELD_NAME; + static final int ARRAY_LENGTH = getvalues001a.ARRAY_LENGTH; + + // first index and number of array components to get + static final int ARRAY_FIRST_INDEX = 4; + static final int ARRAY_ITEMS_COUNT = 10; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new getvalues001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting ReferenceTypeID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debuggee for arrayID value from static field + log.display("Getting arrayID value from static field: " + + ARRAY_FIELD_NAME); + long arrayID = queryObjectID(classID, + ARRAY_FIELD_NAME, JDWP.Tag.ARRAY); + log.display(" got arrayID: " + arrayID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(arrayID); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + e.printStackTrace(out); + success = false; + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debuggee for objectID value of static class field. + */ + long queryObjectID(long classID, String fieldName, byte tag) { + // get fieledID for static field (declared in the class) + long fieldID = debugee.getClassFieldID(classID, fieldName, true); + // get value of the field + JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID); + + // check that value has THREAD tag + if (value.getTag() != tag) { + throw new Failure("Wrong objectID tag received from field \"" + fieldName + + "\": " + value.getTag() + " (expected: " + tag + ")"); + } + + // extract threadID from the value + long objectID = ((Long)value.getValue()).longValue(); + return objectID; + } + + /** + * Perform testing JDWP command for specified objectID. + */ + void testCommand(long arrayID) { + // create command packet + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + + // add out data to the command packet + log.display(" arrayID: " + arrayID); + command.addObjectID(arrayID); + log.display(" firstIndex: " + ARRAY_FIRST_INDEX); + command.addInt(ARRAY_FIRST_INDEX); + log.display(" length: " + ARRAY_ITEMS_COUNT); + command.addInt(ARRAY_ITEMS_COUNT); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract values tag + byte tag = (byte)0; + try { + tag = reply.getByte(); + log.display(" tag: " + tag); + + } catch (BoundException e) { + log.complain("Unable to extract values tag from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check if number of values are as expected + if (tag != JDWP.Tag.INT) { + log.complain("Unexpected values tag received:" + tag + + " (expected: " + JDWP.Tag.INT + ")"); + success = false; + } + + // extract number of values + int values = 0; + try { + values = reply.getInt(); + log.display(" values: " + values); + + } catch (BoundException e) { + log.complain("Unable to extract number of values from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check if number of values are as expected + if (values < 0) { + log.complain("Negative number of values received:" + values + + " (expected: " + ARRAY_ITEMS_COUNT + ")"); + success = false; + } else if (values != ARRAY_ITEMS_COUNT) { + log.complain("Unexpected number of values received:" + values + + " (expected: " + ARRAY_ITEMS_COUNT + ")"); + success = false; + } + + // extract and check each value + for (int i = 0; i < values; i++ ) { + int index = i + ARRAY_FIRST_INDEX; + log.display(" value #" + i + " (index: " + index + ")"); + + // extract value + JDWP.UntaggedValue value = null; + try { + value = reply.getUntaggedValue(JDWP.Tag.INT); + log.display(" untagged_value: " + value); + } catch (BoundException e) { + log.complain("Unable to extract " + i + " value from reply packet:\n\t" + + e.getMessage()); + success = false; + break; + } + + // check that extracted value is as expected + int intValue = ((Integer)value.getValue()).intValue(); + if (intValue != index * 10) { + log.complain("Unexpected value for " + index + " component received: " + + intValue + " (expected: " + (index * 10) + ")"); + success = false; + } + } + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + "0x" + reply.toHexString(reply.currentDataPosition(), 4)); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ArrayReference/GetValues/getvalues001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ArrayReference + * command: GetValues + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the returned values of requested array components are equal + * to the expected ones. Tested array contains primitive values. + * Test consists of two compoments: + * debugger: getvalues001 + * debuggee: getvalues001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization messages. + * Next, debugger obtains from debuggee classID for the tested class and + * arrayID as the value of the class static field. Checked array in + * debuggee is filled with the regular integer values. + * Then, debugger creates command packet for GetValues command with the + * found arrayID and start index and number of components as arguments, + * writes packet to the transport channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts values of the array components. Also test checks + * that extracted values are equal to the expected ones. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ArrayReference.GetValues.getvalues001 + * nsk.jdwp.ArrayReference.GetValues.getvalues001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ArrayReference.GetValues.getvalues001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.GetValues; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class getvalues001a { + + public static final String ARRAY_FIELD_NAME = "array"; + public static final int ARRAY_LENGTH = 16; + + public static void main(String args[]) { + getvalues001a _getvalues001a = new getvalues001a(); + System.exit(getvalues001.JCK_STATUS_BASE + _getvalues001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // meke communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating and fille tested array"); + TestedClass.setArrayValues(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + getvalues001.READY); + pipe.println(getvalues001.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + getvalues001.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(getvalues001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + getvalues001.QUIT + ")"); + log.display("Debugee FAILED"); + return getvalues001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return getvalues001.PASSED; + } + + // tested class with own static fields values + public static class TestedClass { + + // static field with tested array + public static int array[] = null; + + public static void setArrayValues() { + array = new int[ARRAY_LENGTH]; + for (int i = 0; i < ARRAY_LENGTH; i++) { + array[i] = i * 10; + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,527 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.GetValues; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ArrayReference.GetValues. + * + * See getvalues002.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class getvalues002 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ArrayReference.GetValues"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "getvalues002"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ArrayReference.GetValues"; + static final int JDWP_COMMAND_ID = JDWP.Command.ArrayReference.GetValues; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // name of the static field in the tested class with the tested object value + static final String ARRAY_FIELD_NAME = getvalues002a.ARRAY_FIELD_NAME; + static final int ARRAY_LENGTH = getvalues002a.ARRAY_LENGTH; + + // names of the statc fields with object values + static final int FIELDS_COUNT = getvalues002a.FIELDS_COUNT; + static final String FIELD_NAMES[] = { + "nullObject", + "baseObject", + "derivedObject", + "stringObject", + "primitiveArrayObject", + "objectArrayObject", + "threadObject", + "threadGroupObject", + "classObject", + "classLoaderObject", + }; + static final byte FIELD_TAGS[] = { + JDWP.Tag.OBJECT, // nullObject + JDWP.Tag.OBJECT, // baseobject + JDWP.Tag.OBJECT, // derivedObject + JDWP.Tag.STRING, // stringObject + JDWP.Tag.ARRAY, // primitiveArrayObject + JDWP.Tag.ARRAY, // objectArrayObject + JDWP.Tag.THREAD, // threadObject + JDWP.Tag.THREAD_GROUP, // threadGroupObject + JDWP.Tag.CLASS_OBJECT, // classObject + JDWP.Tag.CLASS_LOADER // classLoaderObject + }; + + // first index and number of array components to get + static final int ARRAY_FIRST_INDEX = getvalues002a.ARRAY_FIRST_INDEX; + static final int ARRAY_ITEMS_COUNT = FIELDS_COUNT; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new getvalues002().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting ReferenceTypeID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debugee for fieldIDs of the class static fields + log.display("Getting fieldIDs for static fields of the class"); + long fieldIDs[] = queryClassFieldIDs(classID); + log.display(" got fields: " + fieldIDs.length); + + // query debugee for object values of the fields + log.display("Getting objectID values of the static fields"); + long objectIDs[] = queryClassFieldValues(classID, fieldIDs); + log.display(" got objectIDs: " + objectIDs.length); + + // query debuggee for arrayID value from static field + log.display("Getting arrayID value from static field: " + + ARRAY_FIELD_NAME); + long arrayID = queryObjectID(classID, + ARRAY_FIELD_NAME, JDWP.Tag.ARRAY); + log.display(" got arrayID: " + arrayID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(arrayID, objectIDs); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + e.printStackTrace(out); + success = false; + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debugee for fieldID's of the class static fields. + */ + long[] queryClassFieldIDs(long classID) { + + long[] fieldIDs = new long[FIELDS_COUNT]; + for (int i = 0; i < FIELDS_COUNT; i++) { + fieldIDs[i] = 0; + } + + // compose ReferenceType.Fields command packet + CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.Fields); + command.addReferenceTypeID(classID); + command.setLength(); + + // send the command and receive reply + ReplyPacket reply = debugee.receiveReplyFor(command); + + // extract fieldIDs from the reply packet + try { + reply.resetPosition(); + + int declared = reply.getInt(); + + for (int i = 0; i < declared; i++ ) { + long fieldID = reply.getFieldID(); + String name = reply.getString(); + String signature = reply.getString(); + int modBits = reply.getInt(); + + for (int j = 0; j < FIELDS_COUNT; j++) { + if (FIELD_NAMES[j].equals(name)) { + fieldIDs[j] = fieldID; + } + } + } + + for (int i = 0; i < FIELDS_COUNT; i++) { + if (fieldIDs[i] == 0) { + log.complain("Not found fieldID for static field: " + FIELD_NAMES[i]); + throw new Failure("Error occured while getting static fieldIDs for classID: " + + classID); + } + } + + } catch (BoundException e) { + log.complain("Unable to parse reply packet for ReferenceType.Fields command:\n\t" + + e); + log.complain("Received reply packet:\n" + + reply); + throw new Failure("Error occured while getting static fieldIDs for classID: " + classID); + } + + return fieldIDs; + } + + /** + * Query debugee for objectID values of the class fields. + */ + long[] queryClassFieldValues(long classID, long fieldIDs[]) { + String error = "Error occured while getting object values for static fields of classID: " + + classID; + + // compose ReferenceType.Fields command packet + CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.GetValues); + command.addReferenceTypeID(classID); + command.addInt(FIELDS_COUNT); + for (int i = 0; i < FIELDS_COUNT; i++) { + command.addFieldID(fieldIDs[i]); + } + command.setLength(); + + // send the command and receive reply + ReplyPacket reply = debugee.receiveReplyFor(command); + + // extract values from the reply packet + try { + reply.resetPosition(); + + int valuesCount = reply.getInt(); + if (valuesCount != FIELDS_COUNT) { + log.complain("Unexpected number of values for static fields: " + valuesCount + + " (expected: " + FIELDS_COUNT + ")"); + throw new Failure(error); + } + + long objectIDs[] = new long[valuesCount]; + for (int i = 0; i < valuesCount; i++ ) { + JDWP.Value value = reply.getValue(); + byte tag = value.getTag(); + if (tag != FIELD_TAGS[i]) { + log.complain("Unexpected tag of oblectID value for static field " + + FIELD_NAMES[i] + ": " + tag + + " (expected: " + FIELD_TAGS[i] + ")"); + throw new Failure(error); + } + long objectID = ((Long)value.getValue()).longValue(); + objectIDs[i] = objectID; + } + return objectIDs; + } catch (BoundException e) { + log.complain("Unable to parse reply packet for ReferenceType.GetValues command:\n\t" + + e); + log.complain("Received reply packet:\n" + + reply); + throw new Failure("Error occured while getting static fields values for classID: " + classID); + } + } + + /** + * Query debuggee for objectID value of static class field. + */ + long queryObjectID(long classID, String fieldName, byte tag) { + // get fieledID for static field (declared in the class) + long fieldID = debugee.getClassFieldID(classID, fieldName, true); + // get value of the field + JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID); + + // check that value has THREAD tag + if (value.getTag() != tag) { + throw new Failure("Wrong objectID tag received from field \"" + fieldName + + "\": " + value.getTag() + " (expected: " + tag + ")"); + } + + // extract threadID from the value + long objectID = ((Long)value.getValue()).longValue(); + return objectID; + } + + /** + * Perform testing JDWP command for specified objectID. + */ + void testCommand(long arrayID, long objectIDs[]) { + // create command packet + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + + // add out data to the command packet + log.display(" arrayID: " + arrayID); + command.addObjectID(arrayID); + log.display(" firstIndex: " + ARRAY_FIRST_INDEX); + command.addInt(ARRAY_FIRST_INDEX); + log.display(" length: " + ARRAY_ITEMS_COUNT); + command.addInt(ARRAY_ITEMS_COUNT); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract values tag + byte tag = (byte)0; + try { + tag = reply.getByte(); + log.display(" tag: " + tag); + + } catch (BoundException e) { + log.complain("Unable to extract values tag from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check if number of values are as expected + if (tag != JDWP.Tag.OBJECT) { + log.complain("Unexpected values tag received:" + tag + + " (expected: " + JDWP.Tag.OBJECT + ")"); + success = false; + } + + // extract number of values + int values = 0; + try { + values = reply.getInt(); + log.display(" values: " + values); + + } catch (BoundException e) { + log.complain("Unable to extract number of values from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check if number of values are as expected + if (values < 0) { + log.complain("Negative number of values received:" + values + + " (expected: " + ARRAY_ITEMS_COUNT + ")"); + success = false; + } else if (values != ARRAY_ITEMS_COUNT) { + log.complain("Unexpected number of values received:" + values + + " (expected: " + ARRAY_ITEMS_COUNT + ")"); + success = false; + } + + // extract and check each value + for (int i = 0; i < values; i++ ) { + int index = i + ARRAY_FIRST_INDEX; + log.display(" value #" + i + " (index: " + index + ")"); + + // extract value + JDWP.Value value = null; + try { + value = reply.getValue(); + log.display(" value: " + value); + } catch (BoundException e) { + log.complain("Unable to extract " + i + " value from reply packet:\n\t" + + e.getMessage()); + success = false; + break; + } + + // check that value's tag is as expected + byte valueTag = value.getTag(); + if (valueTag != FIELD_TAGS[i]) { + log.complain("Unexpected value tag for " + index + " component (" + + FIELD_NAMES[i] + ") received: " + valueTag + + " (expected: " + FIELD_TAGS[i] + ")"); + success = false; + } + + // check that value's objectID is as expected + long objectID = ((Long)value.getValue()).longValue(); + if (objectID != objectIDs[i]) { + log.complain("Unexpected objectID for " + index + " component (" + + FIELD_NAMES[i] + ") received: " + objectID + + " (expected: " + objectIDs[i] + ")"); + success = false; + } + } + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + "0x" + reply.toHexString(reply.currentDataPosition(), 4)); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ArrayReference/GetValues/getvalues002. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ArrayReference + * command: GetValues + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the returned values of requested array components are equal + * to the expected ones. Tested array contains object values + * of several kinds (objects, strings, arrays, threads, etc.) + * Test consists of two compoments: + * debugger: getvalues002 + * debuggee: getvalues002a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization messages. + * Next, debugger obtains from debuggee classID for the tested class and + * arrayID as the value of the class static field. Also debugger obtains + * object values from static fileds. These values are the same as components + * of the tested array. + * Then, debugger creates command packet for GetValues command with the + * found arrayID and start index and number of components as arguments, + * writes packet to the transport channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts values of the array components. Also test checks + * that extracted object values are equal to the expected ones. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ArrayReference.GetValues.getvalues002 + * nsk.jdwp.ArrayReference.GetValues.getvalues002a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ArrayReference.GetValues.getvalues002 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.GetValues; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class getvalues002a { + + public static final String ARRAY_FIELD_NAME = "array"; + public static final int FIELDS_COUNT = 10; + public static final int ARRAY_FIRST_INDEX = 4; + public static final int ARRAY_LENGTH = ARRAY_FIRST_INDEX + FIELDS_COUNT + 5; + + public static void main(String args[]) { + getvalues002a _getvalues002a = new getvalues002a(); + System.exit(getvalues002.JCK_STATUS_BASE + _getvalues002a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // meke communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating and fille tested array"); + TestedClass.setArrayValues(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + getvalues002.READY); + pipe.println(getvalues002.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + getvalues002.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(getvalues002.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + getvalues002.QUIT + ")"); + log.display("Debugee FAILED"); + return getvalues002.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return getvalues002.PASSED; + } + + // tested class with own static fields values + public static class TestedClass { + + // static field with tested array + public static Object array[] = null; + + // static fields with object values + public static Object nullObject = null; + public static Object baseObject = new Object(); + public static TestedClass derivedObject = new TestedClass(); + public static String stringObject = new String("string"); + public static int[] primitiveArrayObject = new int[10]; + public static Object[] objectArrayObject = new Object[10]; + public static Thread threadObject = Thread.currentThread(); + public static ThreadGroup threadGroupObject = threadObject.getThreadGroup(); + public static Class classObject = derivedObject.getClass(); + public static ClassLoader classLoaderObject = classObject.getClassLoader(); + + public static void setArrayValues() { + array = new Object[ARRAY_LENGTH]; + for (int i = 0; i < ARRAY_LENGTH; i++) { + array[i] = null; + } + + int i = ARRAY_FIRST_INDEX; + array[i + 0] = nullObject; + array[i + 1] = baseObject; + array[i + 2] = derivedObject; + array[i + 3] = stringObject; + array[i + 4] = primitiveArrayObject; + array[i + 5] = objectArrayObject; + array[i + 6] = threadObject; + array[i + 7] = threadGroupObject; + array[i + 8] = classObject; + array[i + 9] = classLoaderObject; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.Length; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ArrayReference.Length. + * + * See length001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class length001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ArrayReference.Length"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "length001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ArrayReference.Length"; + static final int JDWP_COMMAND_ID = JDWP.Command.ArrayReference.Length; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // name of the static field in the tested class with the tested object value + static final String ARRAY_FIELD_NAME = length001a.ARRAY_FIELD_NAME; + static final int ARRAY_LENGTH = length001a.ARRAY_LENGTH; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new length001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting ReferenceTypeID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debuggee for arrayID value from static field + log.display("Getting arrayID value from static field: " + + ARRAY_FIELD_NAME); + long arrayID = queryObjectID(classID, + ARRAY_FIELD_NAME, JDWP.Tag.ARRAY); + log.display(" got arrayID: " + arrayID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(arrayID); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + e.printStackTrace(out); + success = false; + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debuggee for objectID value of static class field. + */ + long queryObjectID(long classID, String fieldName, byte tag) { + // get fieledID for static field (declared in the class) + long fieldID = debugee.getClassFieldID(classID, fieldName, true); + // get value of the field + JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID); + + // check that value has THREAD tag + if (value.getTag() != tag) { + throw new Failure("Wrong objectID tag received from field \"" + fieldName + + "\": " + value.getTag() + " (expected: " + tag + ")"); + } + + // extract threadID from the value + long objectID = ((Long)value.getValue()).longValue(); + return objectID; + } + + /** + * Perform testing JDWP command for specified arrayID. + */ + void testCommand(long arrayID) { + // create command packet + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + + // add out data to the command packet + log.display(" arrayID: " + arrayID); + command.addObjectID(arrayID); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract array length + int arrayLength = 0; + try { + arrayLength = reply.getInt(); + log.display(" arrayLength: " + arrayLength); + + } catch (BoundException e) { + log.complain("Unable to extract arrayLength from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check if arrayLength is as expected + if (arrayLength < 0) { + log.complain("Negative number of arrayLength received:" + arrayLength + + " (expected: " + ARRAY_LENGTH + ")"); + success = false; + } else if (arrayLength != ARRAY_LENGTH) { + log.complain("Unexpected number of values received:" + arrayLength + + " (expected: " + ARRAY_LENGTH + ")"); + success = false; + } + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + "0x" + reply.toHexString(reply.currentDataPosition(), 4)); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ArrayReference/Length/length001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ArrayReference + * command: Length + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the returned array length is equal to the expected one. + * Test consists of two compoments: + * debugger: length001 + * debuggee: length001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization messages. + * Next, debugger obtains from debuggee classID for the tested class and + * arrayID as the value of the class static field. Checked array in + * debuggee is filled with the regular integer values. + * Then, debugger creates command packet for Length command with the + * found arrayID and start index and number of components as arguments, + * writes packet to the transport channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts array length value. Also test checks that extracted array + * length is equal to the expected one. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ArrayReference.Length.length001 + * nsk.jdwp.ArrayReference.Length.length001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ArrayReference.Length.length001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.Length; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class length001a { + + public static final String ARRAY_FIELD_NAME = "array"; + public static final int ARRAY_LENGTH = 16; + + public static void main(String args[]) { + length001a _length001a = new length001a(); + System.exit(length001.JCK_STATUS_BASE + _length001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // meke communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating and fille tested array"); + TestedClass.setArrayValues(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + length001.READY); + pipe.println(length001.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + length001.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(length001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + length001.QUIT + ")"); + log.display("Debugee FAILED"); + return length001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return length001.PASSED; + } + + // tested class with own static fields values + public static class TestedClass { + + // static field with tested array + public static int array[] = null; + + public static void setArrayValues() { + array = new int[ARRAY_LENGTH]; + for (int i = 0; i < ARRAY_LENGTH; i++) { + array[i] = i * 10; + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.SetValues; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ArrayReference.SetValues. + * + * See setvalues001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class setvalues001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String RUN = "run"; + static final String DONE = "done"; + static final String ERROR = "error"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ArrayReference.SetValues"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "setvalues001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ArrayReference.SetValues"; + static final int JDWP_COMMAND_ID = JDWP.Command.ArrayReference.SetValues; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // name of the static field in the tested class with the tested object value + static final String ARRAY_FIELD_NAME = setvalues001a.ARRAY_FIELD_NAME; + + // length, first index and number of array components to get + static final int ARRAY_LENGTH = setvalues001a.ARRAY_LENGTH; + static final int ARRAY_FIRST_INDEX = setvalues001a.ARRAY_FIRST_INDEX; + static final int ARRAY_ITEMS_COUNT = setvalues001a.ARRAY_ITEMS_COUNT; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new setvalues001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting ReferenceTypeID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debuggee for arrayID value from static field + log.display("Getting arrayID value from static field: " + + ARRAY_FIELD_NAME); + long arrayID = queryObjectID(classID, + ARRAY_FIELD_NAME, JDWP.Tag.ARRAY); + log.display(" got arrayID: " + arrayID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(arrayID); + + // check confirmation from debuggee that values have been set correctly + log.display("\n>>> Checking that the values have been set correctly \n"); + checkValuesChanged(); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + e.printStackTrace(out); + success = false; + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debuggee for objectID value of static class field. + */ + long queryObjectID(long classID, String fieldName, byte tag) { + // get fieledID for static field (declared in the class) + long fieldID = debugee.getClassFieldID(classID, fieldName, true); + // get value of the field + JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID); + + // check that value has THREAD tag + if (value.getTag() != tag) { + throw new Failure("Wrong objectID tag received from field \"" + fieldName + + "\": " + value.getTag() + " (expected: " + tag + ")"); + } + + // extract threadID from the value + long objectID = ((Long)value.getValue()).longValue(); + return objectID; + } + + /** + * Perform testing JDWP command for specified objectID. + */ + void testCommand(long arrayID) { + // create command packet + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + + // add out data to the command packet + log.display(" arrayID: " + arrayID); + command.addObjectID(arrayID); + log.display(" firstIndex: " + ARRAY_FIRST_INDEX); + command.addInt(ARRAY_FIRST_INDEX); + log.display(" values: " + ARRAY_ITEMS_COUNT); + command.addInt(ARRAY_ITEMS_COUNT); + // add new int values for array components + for (int i = ARRAY_FIRST_INDEX; i < ARRAY_FIRST_INDEX + ARRAY_ITEMS_COUNT; i++) { + int intValue = i * 100 + 1; + JDWP.UntaggedValue value = new JDWP.UntaggedValue(new Integer(intValue)); + log.display(" untagged_value: " + value); + command.addUntaggedValue(value, JDWP.Tag.INT); + } + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // no reply data to extract + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + "0x" + reply.toHexString(reply.currentDataPosition(), 4)); + success = false; + } + } + + /** + * Check confirmation from debuggee that values are changed correctly. + */ + void checkValuesChanged() { + // send debugee signal RUN + log.display("Sending signal to debugee: " + RUN); + pipe.println(RUN); + + // wait for DONE signal from debugee + log.display("Waiting for signal from debugee: " + DONE); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + + // check received signal + if (signal == null) { + throw new TestBug("<null> signal received from debugee: " + signal + + " (expected: " + DONE + ")"); + } else if (signal.equals(DONE)) { + log.display("All array values have been correctly set into debuggee VM"); + } else if (signal.equals(ERROR)) { + log.complain("Not all array values have been correctly set into debuggee VM"); + success = false; + } else { + throw new TestBug("Unexpected signal received from debugee: " + signal + + " (expected: " + DONE + ")"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ArrayReference/SetValues/setvalues001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ArrayReference + * command: SetValues + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the new set values of array components are equal to the + * expected ones. + * Test consists of two compoments: + * debugger: setvalues001 + * debuggee: setvalues001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization messages. + * Next, debugger obtains from debuggee classID for the tested class and + * arrayID as the value of the class static field. Checked array in + * debuggee is filled with the initial integer values. + * Then, debugger creates command packet for SetValues command with the + * found arrayID, start index and number of components as arguments, + * and new integer values, writes packet to the transport channel + * and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and ensures there is no data in the packet. Also test send signal + * <RUN> to debuggee to check new array values. If new values are set + * correctly debuggee replies with signal DONE. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ArrayReference.SetValues.setvalues001 + * nsk.jdwp.ArrayReference.SetValues.setvalues001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ArrayReference.SetValues.setvalues001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayReference.SetValues; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class setvalues001a { + + // name of the static field with the tested array object + public static final String ARRAY_FIELD_NAME = "array"; + + // length, first index and number of array components to get + public static final int ARRAY_LENGTH = 16; + public static final int ARRAY_FIRST_INDEX = 4; + public static final int ARRAY_ITEMS_COUNT = 10; + + private static ArgumentHandler argumentHandler = null; + private static Log log = null; + + public static void main(String args[]) { + setvalues001a _setvalues001a = new setvalues001a(); + System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + argumentHandler = new ArgumentHandler(args); + log = new Log(out, argumentHandler); + + // meke communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating and initializing tested array"); + TestedClass.initArrayValues(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + setvalues001.READY); + pipe.println(setvalues001.READY); + + // wait for signal RUN from debugeer + log.display("Waiting for signal from debugger: " + setvalues001.RUN); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + // check received signal + if (signal == null || !signal.equals(setvalues001.RUN)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + setvalues001.RUN + ")"); + log.display("Debugee FAILED"); + return setvalues001.FAILED; + } + + // check assigned values + log.display("Checking new array values"); + if (TestedClass.checkArrayValues()) { + log.display("Sending signal to debugger: " + setvalues001.DONE); + pipe.println(setvalues001.DONE); + } else { + log.display("Sending signal to debugger: " + setvalues001.ERROR); + pipe.println(setvalues001.ERROR); + } + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + setvalues001.QUIT); + signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(setvalues001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + setvalues001.QUIT + ")"); + log.display("Debugee FAILED"); + return setvalues001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return setvalues001.PASSED; + } + + // tested class with own static fields values + public static class TestedClass { + + // static field with tested array + public static int array[] = null; + + public static void initArrayValues() { + array = new int[ARRAY_LENGTH]; + for (int i = 0; i < ARRAY_LENGTH; i++) { + array[i] = i * 10; + } + } + + public static boolean checkArrayValues() { + if (array == null) { + log.complain("Checked array == null after setting values: " + array); + return false; + } + + boolean success = true; + if (array.length != ARRAY_LENGTH) { + log.complain("Unexpected array length after setting values: " + + array.length + " (expected: " + ARRAY_LENGTH + ")"); + success = false; + } + + for (int i = 0; i < array.length; i++) { + int initial = i * 10; + int changed = i * 100 + 1; + if (i < ARRAY_FIRST_INDEX || i >= ARRAY_FIRST_INDEX + ARRAY_ITEMS_COUNT) { + log.display(" " + i + " (not changed): " + initial + " -> " + array[i]); + if (array[i] != initial) { + log.complain("Changed value of " + i + " component which is out of changed region: " + + array[i] + "(initial: " + initial + ")"); + success = false; + } + } else { + log.display(" " + i + " (changed): " + initial + " -> " + array[i]); + if (array[i] != changed) { + if (array[i] == initial) { + log.complain("Value of " + i + " component not changed: " + + array[i] + "(expected: " + changed + ")"); + success = false; + } else { + log.complain("Value of " + i + " component changed incorrectly: " + + array[i] + "(expected: " + changed + ")"); + success = false; + } + } + } + } + + return success; + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayType.NewInstance; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ArrayType.NewInstance. + * + * See newinstance001.README for description of test execution. + * + * This class represents debugger part of the test. + * Test is executed by invoking method runIt(). + * JDWP command is tested in the method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class newinstance001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ArrayType.NewInstance"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "newinstance001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ArrayType.NewInstance"; + static final int JDWP_COMMAND_ID = JDWP.Command.ArrayType.NewInstance; + + // tested array type signature constant + static final String TESTED_ARRAY_SIGNATURE = "[I"; + + // tested array type size constant + static final int TESTED_ARRAY_SIZE = 100; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new newinstance001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting arrayTypeID by signature:\n" + + " " + TESTED_ARRAY_SIGNATURE); + long typeID = debugee.getReferenceTypeID(TESTED_ARRAY_SIGNATURE); + log.display(" got TypeID: " + typeID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(typeID); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received from debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Perform testing JDWP command for specified TypeID. + */ + void testCommand(long typeID) { + // create command packet and fill requred out data + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + log.display(" arrayTypeID: " + typeID); + command.addReferenceTypeID(typeID); + log.display(" length: " + TESTED_ARRAY_SIZE); + command.addInt(TESTED_ARRAY_SIZE); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract and check number of nested classes + JDWP.Value newArray = null; + try { + newArray = reply.getValue(); + log.display(" newArray: " + newArray); + + byte tag = newArray.getTag(); + if (tag != JDWP.Tag.ARRAY) { + log.complain("Unexpected tag of new array value in the reply packet:" + + tag + " (expected: " + JDWP.Tag.ARRAY + ")"); + success = false; + } + + long objectID = 0; + try { + objectID = ((Long)newArray.getValue()).longValue(); + } catch (ClassCastException e) { + throw new TestBug("Caught ClassCastException vhile extracting objectID from tagged value: " + + newArray); + } + + if (objectID == 0) { + log.complain("Null objectID returned for new array value in the reply packet"); + success = false; + } + + } catch (BoundException e) { + log.complain("Unable to extract newArray value from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + reply.offsetString()); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ArrayType/NewInstance/newinstance001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ArrayType + * command: NewInstance + * Test checks that debugee accept the command packet and + * replies with correct reply packet. + * Test consists of two compoments: + * debugger: newinstance001 + * debuggee: newinstance001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization signals. + * Next, debugger obtains arrayTypeIDs for the tested class from debugee. + * Then, debugger creates command packet for ArrayType.NewInstance command + * with the found arrayTypeID as an argument, writes packet to the transport + * channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts tagged objectID value of the new created array. Also test + * checks that the tag of the extracted value is ARRAY_ID and objectID is + * not null. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ArrayType.NewInstance.newinstance001 + * nsk.jdwp.ArrayType.NewInstance.newinstance001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ArrayType.NewInstance.newinstance001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ArrayType.NewInstance; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +/** + * This class represents debuggee part in the test. + */ +public class newinstance001a { + + public static void main(String args[]) { + newinstance001a _newinstance001a = new newinstance001a(); + System.exit(newinstance001.JCK_STATUS_BASE + _newinstance001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // make communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested array type is loaded + log.display("Creating array of integer"); + int foo[] = new int[10]; + + // send debugger signal READY + log.display("Sending signal to debugger: " + newinstance001.READY); + pipe.println(newinstance001.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + newinstance001.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(newinstance001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + newinstance001.QUIT + ")"); + log.display("Debugee FAILED"); + return newinstance001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return newinstance001.PASSED; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassLoaderReference.VisibleClasses; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ClassLoaderReference.VisibleClasses. + * + * See visibclasses001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class visibclasses001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ClassLoaderReference.VisibleClasses"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "visibclasses001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ClassLoaderReference.VisibleClasses"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassLoaderReference.VisibleClasses; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new visibclasses001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for TypeID of tested class + log.display("Getting ReferenceTypeID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debugee for TypeIDs of classes been nested + log.display("Getting classLoaderID for tested classes"); + long classLoaderID = queryClassLoaderID(classID); + log.display(" got classLoaderID: " + classLoaderID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(classLoaderID, classID); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received from debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debugee for classLoaderID for specified classID. + */ + long queryClassLoaderID(long classID) { + CommandPacket command = + new CommandPacket(JDWP.Command.ReferenceType.ClassLoader); + command.addReferenceTypeID(classID); + ReplyPacket reply = debugee.receiveReplyFor(command); + + try { + reply.resetPosition(); + + long classLoaderID = reply.getObjectID(); + return classLoaderID; + } catch (BoundException e) { + throw new Failure("Unable to parse reply packet for ReferenceType.ClassLoader:\n\t" + + e); + } + } + + /** + * Perform testing JDWP command for specified classLoaderID. + */ + void testCommand(long classLoaderID, long expectedClassID) { + // create command packet and fill requred out data + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + log.display(" classLoaderID: " + classLoaderID); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + command.addObjectID(classLoaderID); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + return; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract and check number of nested classes + int classes = 0; + try { + classes = reply.getInt(); + log.display(" classes: " + classes); + + } catch (BoundException e) { + log.complain("Unable to extract number of nested classes from reply packet:\n\t" + + e.getMessage()); + success = false; + } + + if (classes < 0) { + log.complain("Negative number of classes in the reply packet:" + classes); + success = false; + } else if (classes == 0) { + log.complain("Zero number of classes in the reply packet:" + classes); + success = false; + } + + boolean found = false; + // extract and check TypeID for each received class + for (int i = 0; i < classes; i++ ) { + log.display(" class #" + i); + + // extract TypeTag byte + byte refTypeTag = (byte)0; + String refTypeTagName = null; + try { + refTypeTag = reply.getByte(); + String tag; + switch (refTypeTag) { + case JDWP.TypeTag.CLASS: + refTypeTagName = "CLASS"; + break; + case JDWP.TypeTag.INTERFACE: + refTypeTagName = "INTERFACE"; + break; + case JDWP.TypeTag.ARRAY: + refTypeTagName = "ARRAY"; + break; + default: + refTypeTagName = "UNKNOWN"; + break; + } + log.display(" refTypeTag: " + refTypeTag + "=" + refTypeTagName); + } catch (BoundException e) { + log.complain("Unable to extract refTypetag of " + i + + " class from reply packet:\n\t" + + e.getMessage()); + success = false; + break; + } + + // extract and check TypeID + long typeID = 0; + try { + typeID = reply.getReferenceTypeID(); + log.display(" typeID: " + typeID); + + } catch (BoundException e) { + log.complain("Unable to extract TypeID of " + i + + " nested class from reply packet:\n\t" + + e.getMessage()); + success = false; + break; + } + + if (typeID == expectedClassID) { + log.display("Found expected classID: " + expectedClassID); + found = true; + if (refTypeTag != JDWP.TypeTag.CLASS) { + log.complain("unexpected refTypeTag returned for checked class: " + + refTypeTag + "=" + refTypeTagName + + " (expected: " + JDWP.TypeTag.CLASS + "=CLASS)"); + success = false; + } + } + } + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + reply.offsetString()); + success = false; + } + + if (!found) { + log.complain("Expected classID not found in the list of visible classes: " + expectedClassID); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassLoaderReference + * command: VisibleClasses + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * list of classes returned for classObjectID contains at least + * one expected classID. + * Test consists of two compoments: + * debugger: visibclasses001 + * debuggee: visibclasses001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization signals. + * Next, debugger obtains classID for the tested class and its + * classLoaderID from debugee. + * Then, debugger creates command packet for VisibleClasses command + * with the found classObjectID as an argument, writes packet to the + * transport channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts list of typeIDs of the visible classes. Also test checks + * that this list includes expected classID of the original class. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001 + * nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassLoaderReference.VisibleClasses; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class visibclasses001a { + + public static void main(String args[]) { + visibclasses001a _visibclasses001a = new visibclasses001a(); + System.exit(visibclasses001.JCK_STATUS_BASE + _visibclasses001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // make communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating object of tested class"); + TestedClass foo = new TestedClass(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + visibclasses001.READY); + pipe.println(visibclasses001.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + visibclasses001.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(visibclasses001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + visibclasses001.QUIT + ")"); + log.display("Debugee FAILED"); + return visibclasses001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return visibclasses001.PASSED; + } + + // tested class with nested classes + public static class TestedClass { + int foo = 0; + public TestedClass() { + foo = 100; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassObjectReference.ReflectedType; + +import java.io.*; +import java.util.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +public class reflectype001 { + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + static final String PACKAGE_NAME = "nsk.jdwp.ClassObjectReference.ReflectedType"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "reflectype001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + static final String JDWP_COMMAND_NAME = "ClassObjectReference.ReflectedType"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassObjectReference.ReflectedType; + + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + public static int run(String argv[], PrintStream out) { + return new reflectype001().runIt(argv, out); + } + + public int runIt(String argv[], PrintStream out) { + + boolean success = true; + + try { + ArgumentHandler argumentHandler = new ArgumentHandler(argv); + Log log = new Log(out, argumentHandler); + + try { + + Binder binder = new Binder(argumentHandler, log); + log.display("Start debugee VM"); + Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + Transport transport = debugee.getTransport(); + IOPipe pipe = debugee.createIOPipe(); + + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + log.display("Resume debugee VM"); + debugee.resume(); + + log.display("Waiting for command: " + "ready"); + String cmd = pipe.readln(); + log.display("Received command: " + cmd); + + try { + + // get referenceTypeID for debugee class + + long originalTypeID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + + // get classObjectID for originalTypeID + + long classObjectID = 0; + { + log.display("Getting classObjectID for referenceTypeID: " + originalTypeID); + + CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.ClassObject); + command.addReferenceTypeID(originalTypeID); + + ReplyPacket reply = debugee.receiveReplyFor(command); + + classObjectID = reply.getObjectID(); + log.display("Found classObjectID: " + classObjectID); + + } + + // begin test of JDWP command + + log.display("Create command " + JDWP_COMMAND_NAME + + " with classObjectID: " + classObjectID); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + command.addObjectID(classObjectID); + command.setLength(); + + log.display("Sending command packet:\n" + command); + transport.write(command); + + log.display("Waiting for reply packet"); + ReplyPacket reply = new ReplyPacket(); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + + log.display("Parsing reply packet:"); + reply.resetPosition(); + + byte refTypeTag = reply.getByte(); + log.display(" refTypeTag: " + classObjectID); + + long typeID = reply.getReferenceTypeID(); + log.display(" typeID: " + typeID); + + if (refTypeTag != JDWP.TypeTag.CLASS) { + log.complain("No JDWP.TypeTag.CLASS tag returned for class object: " + refTypeTag); + success = false; + } + + if (typeID != originalTypeID) { + log.complain("Returned typeID does not equal to original referenceTypeID: " + originalTypeID); + success = false; + } + + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition()); + success = false; + } else { + log.display("Reply packet parsed successfully"); + } + + // end test of JDWP command + + } catch (Exception e) { + log.complain("Caught exception while testing JDWP command: " + e); + success = false; + } finally { + + log.display("Sending command: " + "quit"); + pipe.println("quit"); + + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + } catch (Exception e) { + log.complain("Caught unexpected exception while connecting to debugee: " + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + } catch (Exception e) { + out.println("Caught unexpected exception while starting the test: " + e); + e.printStackTrace(out); + out.println("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassObjectReference + * command: RefelectedType + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test check if + * received referenceTypeID for class object is equal to + * the original one. + * Test consists of two compoments: + * debugger: reflectype001 + * debuggee: reflectype001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with execution commands. + * Next, debugger obtains referenceTypeID for debuggee class and then + * classObjectID, which will be used to test JDWP command. + * Then, debugger creates command packet for RefelectedType command with the + * found classObjectID as an argument, writes packet to the transport + * channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts referenceTypeID. Debugger tests also that obtained + * referenceTypeID has the proper tag and is equal to the original one. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * COMMENTS + * Fixed misprint in package name according to test bug: + * 4782469 TEST_RFE: incorrect package name in some JPDA tests + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001 + * nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassObjectReference.ReflectedType; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class reflectype001a { + + public static void main(String args[]) { + reflectype001a _reflectype001a = new reflectype001a(); + System.exit(reflectype001.JCK_STATUS_BASE + _reflectype001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + log.display("Creating object of tested class"); + TestedClass foo = new TestedClass(); + log.display("Sending command: " + "ready"); + pipe.println("ready"); + log.display("Waiting for command: " + "quit"); + String command = pipe.readln(); + log.display("Received command: " + command); + log.display("Debugee PASSED"); + return reflectype001.PASSED; + } + + static public class TestedClass { + int foo = 0; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.InvokeMethod; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ClassType.InvokeMethod. + * + * See invokemeth001.README for description of test execution. + * + * This class represents debugger part of the test. + * Test is executed by invoking method runIt(). + * JDWP command is tested in the method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class invokemeth001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // package and classes names + static final String PACKAGE_NAME = "nsk.jdwp.ClassType.InvokeMethod"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "invokemeth001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command + static final String JDWP_COMMAND_NAME = "ClassType.InvokeMethod"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassType.InvokeMethod; + + // tested class name and signature + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedObjectClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // field and method names + static final String RESULT_FIELD_NAME = "result"; + static final String TESTED_METHOD_NAME = "testedMethod"; + static final String BREAKPOINT_METHOD_NAME = "run"; + static final int BREAKPOINT_LINE_NUMBER = invokemeth001a.BREAKPOINT_LINE_NUMBER; + + // data for invoked method + static final int ARGUMENTS_COUNT = 1; + static final int INITIAL_VALUE = invokemeth001a.INITIAL_VALUE; + static final int ARGUMENT_VALUE = invokemeth001a.FINAL_VALUE; + static final int RETURN_VALUE = INITIAL_VALUE; + static final int INVOKE_OPTIONS = 0; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + int waitTime = 0; // minutes + long timeout = 0; // milliseconds + boolean dead = false; + boolean success = true; + + // data obtained from debuggee + long classID = 0; + long threadID = 0; + long methodID = 0; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new invokemeth001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + waitTime = argumentHandler.getWaitTime(); // minutes + timeout = waitTime * 60 * 1000; // milliseconds + + // execute test and display results + try { + log.display("\n>>> Starting debugee \n"); + + // launch debuggee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee VM"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + log.display(" ... debuggee launched"); + + // set timeout for debuggee responces + log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)"); + transport.setReadTimeout(timeout); + log.display(" ... timeout set"); + + // wait for VM_INIT event + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + log.display(" ... VM_INIT event received"); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + log.display(" ... size of VM-dependent types adjusted"); + + // prepare debuggee for testing and obtain required data + log.display("\n>>> Getting prepared for testing \n"); + prepareForTest(); + + // test JDWP command + log.display("\n>> Testing JDWP command \n"); + testCommand(); + + // check command results + if (success) { + log.display("\n>>> Checking result of tested command \n"); + checkResult(); + } + + // finish debuggee + log.display("\n>> Finishing debuggee \n"); + + // resume debuggee after testing command + log.display("Resuming debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + + // wait for VM_DEATH event + log.display("Waiting for VM_DEATH event"); + debugee.waitForVMDeath(); + log.display(" ... VM_DEATH event received"); + dead = true; + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } finally { + log.display("\n>>> Finishing test \n"); + + // disconnect debugee and wait for its exit + if (debugee != null) { + quitDebugee(); + } + } + + // check result + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + out.println("TEST PASSED"); + return PASSED; + } + + /** + * Get debuggee prepared for testing and obtain required data. + */ + void prepareForTest() { + // wait for tested class loaded on debuggee startup and obtain its classID + log.display("Waiting for class loaded:\n\t" + TESTED_CLASS_NAME); + classID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL); + log.display(" ... class loaded with classID: " + classID); + log.display(""); + + // query debuggee for tested methodID + log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME); + methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true); + log.display(" ... got methodID: " + methodID); + log.display(""); + + // set breakpoint and wait for debugee reached it + log.display("Waiting for breakpoint reached at: " + + BREAKPOINT_METHOD_NAME + ":" + BREAKPOINT_LINE_NUMBER); + threadID = debugee.waitForBreakpointReached(classID, + BREAKPOINT_METHOD_NAME, + BREAKPOINT_LINE_NUMBER, + JDWP.SuspendPolicy.ALL); + log.display(" ... breakpoint reached with threadID: " + threadID); + log.display("Tested thread is suspended by breakpoint event"); + } + + /** + * Perform testing JDWP command. + */ + void testCommand() { + // create command packet and fill requred out data + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + log.display(" classID: " + classID); + command.addReferenceTypeID(classID); + log.display(" threadID: " + threadID); + command.addObjectID(threadID); + log.display(" methodID: " + methodID); + command.addMethodID(methodID); + log.display(" arguments: " + ARGUMENTS_COUNT); + command.addInt(ARGUMENTS_COUNT); + for (int i = 0; i < ARGUMENTS_COUNT; i++) { + JDWP.Value value = new JDWP.Value(JDWP.Tag.INT, new Integer(ARGUMENT_VALUE)); + log.display(" arg: " + value); + command.addValue(value); + } + log.display(" options: " + INVOKE_OPTIONS); + command.addInt(INVOKE_OPTIONS); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet for tested command:\n\t" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" ... packet header is correct"); + } catch (BoundException e) { + log.complain("Wrong header of reply packet for tested command:\n\t" + + e.getMessage()); + success = false; + return; + } + + // start parsing reply packet data + log.display("Parsing reply packet data:"); + reply.resetPosition(); + + // extract return value + JDWP.Value returnValue = null; + try { + returnValue = reply.getValue(); + log.display(" returnValue: " + returnValue); + } catch (BoundException e) { + log.complain("Unable to extract returnValues from reply packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // extract exception tag + JDWP.Value exception = null; + try { + exception = reply.getValue(); + log.display(" exception: " + exception); + } catch (BoundException e) { + log.complain("Unable to extract exception from reply packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... packed data parsed"); + + // check that return value is an integer + if (returnValue.getTag() != JDWP.Tag.INT) { + log.complain("Unexpected tag of returnValue returned: " + returnValue.getTag() + + " (expected: " + JDWP.Tag.INT + ")"); + success = false; + } + + // check that return value is as expected + int intValue = ((Integer)returnValue.getValue()).intValue(); + if (intValue != RETURN_VALUE) { + log.complain("Unexpected value of returnValue returned: " + intValue + + " (expected: " + RETURN_VALUE + ")"); + success = false; + } + + // check that exception value is an object + if (exception.getTag() != JDWP.Tag.OBJECT) { + log.complain("Unexpected tag of exception returned: " + exception.getTag() + + " (expected: " + JDWP.Tag.OBJECT + ")"); + success = false; + } + + // check that exception object is null + long exceptionID = ((Long)exception.getValue()).longValue(); + if (exceptionID != 0) { + log.complain("Non-null exception object returned: " + exceptionID + + " (expected: " + 0 + ")"); + success = false; + } + } + + /** + * Check result of the tested JDWP command. + */ + void checkResult() { + // query debuggee for result value from a static field + log.display("Getting result value from static field: " + RESULT_FIELD_NAME); + JDWP.Value value = debugee.getStaticFieldValue(classID, RESULT_FIELD_NAME, JDWP.Tag.INT); + int result = ((Integer)value.getValue()).intValue(); + log.display(" ... got result: " + result); + + // check if the result value is changed as expected + if (result != ARGUMENT_VALUE) { + log.complain("Method has not been really invoked: \n\t" + + "variable not changed by the method: " + result + + " (expected: " + ARGUMENT_VALUE + ")"); + success = false; + } else { + log.display("Method has been really invoked: \n\t" + + " variable changed by the method: " + result + + " (expected: " + ARGUMENT_VALUE + ")"); + } + } + + /** + * Disconnect debuggee and wait for it exited. + */ + void quitDebugee() { + if (debugee == null) + return; + + // disconnect debugee + if (!dead) { + try { + log.display("Disconnecting debuggee"); + debugee.dispose(); + log.display(" ... debuggee disconnected"); + } catch (Failure e) { + log.display("Failed to finally disconnect debuggee:\n\t" + + e.getMessage()); + } + } + + // wait for debugee exited + log.display("Waiting for debuggee exit"); + int code = debugee.waitFor(); + log.display(" ... debuggee exited with exit code: " + code); + + // analize debugee exit status code + if (code != JCK_STATUS_BASE + PASSED) { + log.complain("Debuggee FAILED with exit code: " + code); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassType/InvokeMethod/invokemeth001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassType + * command: InvokeMethod + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the tested static method is really invoked into debuggee. + * Test consists of two compoments: + * debugger: invokemeth001 + * debuggee: invokemeth001a + * First, debugger uses nsk.share.* support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Next, debugger waits for tested class loaded, requests methodID + * for tested method, sets breakpoint and wait for breakpoint reached. + * When breakpoint event received the tested thread into debuggee + * is suspended by this event. + * Then, debugger creates command packet for ClassType.InvokeMethod + * command with the found classID, methodID, threadID, and also adds + * one integer argument for the method invocation. Then debugger writes + * packet to the transport channel and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts method's result value and exception objectID. Test checks + * if result value is an expected integer and exception objectID is null. + * Also test gets value of static field, wich should be modified by + * the invoked method, to verify if this method was really invoked + * into debuggee. + * Finally, debugger disconnects debuggee, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassType.InvokeMethod.invokemeth001 + * nsk.jdwp.ClassType.InvokeMethod.invokemeth001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassType.InvokeMethod.invokemeth001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// THIS TEST IS LINE NUMBER SENSITIVE + +package nsk.jdwp.ClassType.InvokeMethod; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +/** + * This class represents debuggee part in the test. + */ +public class invokemeth001a { + + // name of the tested thread + public static final String THREAD_NAME = "testedThread"; + + // line nunber for breakpoint + public static final int BREAKPOINT_LINE_NUMBER = 86; + + // initial and final value of variable changed by the method invoked from debugger + public static final int INITIAL_VALUE = 10; + public static final int FINAL_VALUE = 1234; + + // scaffold objects + private static volatile ArgumentHandler argumentHandler = null; + private static volatile Log log = null; + + public static void main(String args[]) { + invokemeth001a _invokemeth001a = new invokemeth001a(); + System.exit(invokemeth001.JCK_STATUS_BASE + _invokemeth001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + argumentHandler = new ArgumentHandler(args); + log = new Log(out, argumentHandler); + + // create tested of tested class + log.display("Creating object of tested class"); + TestedObjectClass foo = new TestedObjectClass(); + log.display(" ... object created"); + + // run method with breakpoint + TestedObjectClass.run(); + + log.display("Debugee PASSED"); + return invokemeth001.PASSED; + } + + // tested object class + public static class TestedObjectClass { + // result of invoking tested mathod + public static volatile int result = INITIAL_VALUE; + + // suspend current thread on breakpoint + public static void run() { + log.display("Tested thread: started"); + + log.display("Breakpoint line reached"); + // next line is for breakpoint + int foo = 0; // BREAKPOINT_LINE_NUMBER + log.display("Breakpoint line passed"); + + log.display("Tested thread: finished"); + } + + // tested method for invocation from debugger + public static int testedMethod(int arg) { + log.display("Tested method invoked with argument:" + arg); + int old = result; + result = arg; + log.display("Tested method returned with result:" + old); + return old; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.NewInstance; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ClassType.NewInstance. + * + * See newinst001.README for description of test execution. + * + * This class represents debugger part of the test. + * Test is executed by invoking method runIt(). + * JDWP command is tested in the method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class newinst001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // package and classes names + static final String PACKAGE_NAME = "nsk.jdwp.ClassType.NewInstance"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "newinst001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command + static final String JDWP_COMMAND_NAME = "ClassType.NewInstance"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassType.NewInstance; + + // tested class name and signature + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedObjectClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // field and method names + static final String RESULT_FIELD_NAME = "result"; + static final String TESTED_CONSTRUCTOR_NAME = "<init>"; + static final String BREAKPOINT_METHOD_NAME = "run"; + static final int BREAKPOINT_LINE_NUMBER = newinst001a.BREAKPOINT_LINE_NUMBER; + + // data for invoked method + static final int ARGUMENTS_COUNT = 1; + static final int INITIAL_VALUE = newinst001a.INITIAL_VALUE; + static final int ARGUMENT_VALUE = newinst001a.FINAL_VALUE; + static final int RETURN_VALUE = INITIAL_VALUE; + static final int INVOKE_OPTIONS = 0; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + boolean dead = false; + + // data obtained from debuggee + long classID = 0; + long threadID = 0; + long methodID = 0; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main(String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new newinst001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Starting debugee \n"); + + // launch debuggee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee VM"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + log.display(" ... debuggee launched"); + + // set timeout for debuggee responces + int waitTime = argumentHandler.getWaitTime(); // minutes + long timeout = waitTime * 60 * 1000; // milliseconds + log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)"); + transport.setReadTimeout(timeout); + log.display(" ... timeout set"); + + // wait for VM_INIT event + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + log.display(" ... VM_INIT event received"); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + log.display(" ... size of VM-dependent types adjusted"); + + // run the test + runTest(); + + // wait for VM_DEATH event + log.display("Waiting for VM_DEATH event"); + debugee.waitForVMDeath(); + log.display(" ... VM_DEATH event received"); + dead = true; + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } finally { + log.display("\n>>> Finishing test \n"); + + // disconnect debugee and wait for its exit + if (debugee != null) { + quitDebugee(); + } + } + + // check result + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + out.println("TEST PASSED"); + return PASSED; + } + + /** + * Obtain required data and test JDWP command. + */ + void runTest() { + log.display("\n>>> Obtaining required data \n"); + + // wait for tested class loaded on debuggee startup and obtain its classID + log.display("Waiting for class loaded:\n\t" + TESTED_CLASS_NAME); + classID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL); + log.display(" ... got classID: " + classID); + log.display(""); + + // query debuggee for tested methodID + log.display("Getting tested methodID by constructor name: " + TESTED_CONSTRUCTOR_NAME); + methodID = debugee.getMethodID(classID, TESTED_CONSTRUCTOR_NAME, true); + log.display(" ... got methodID: " + methodID); + log.display(""); + + // set breakpoint and wait for debugee reached it + log.display("Waiting for breakpoint reached at: " + + BREAKPOINT_METHOD_NAME + ":" + BREAKPOINT_LINE_NUMBER); + threadID = debugee.waitForBreakpointReached(classID, + BREAKPOINT_METHOD_NAME, + BREAKPOINT_LINE_NUMBER, + JDWP.SuspendPolicy.EVENT_THREAD); + log.display(" ... breakpoint reached with threadID: " + threadID); + + // test JDWP command + log.display("\n>> Testing JDWP command \n"); + testCommand(); + + // check command results + if (success) { + log.display("\n>>> Checking command results \n"); + checkResult(); + } + + // resume debuggee after the command + log.display("Resuming debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + } + + /** + * Perform testing JDWP command. + */ + void testCommand() { + // create command packet and fill requred out data + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + log.display(" classID: " + classID); + command.addReferenceTypeID(classID); + log.display(" threadID: " + threadID); + command.addObjectID(threadID); + log.display(" methodID: " + methodID); + command.addMethodID(methodID); + log.display(" arguments: " + ARGUMENTS_COUNT); + command.addInt(ARGUMENTS_COUNT); + for (int i = 0; i < ARGUMENTS_COUNT; i++) { + JDWP.Value value = new JDWP.Value(JDWP.Tag.INT, new Integer(ARGUMENT_VALUE)); + log.display(" arg: " + value); + command.addValue(value); + } + log.display(" options: " + INVOKE_OPTIONS); + command.addInt(INVOKE_OPTIONS); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + return; + } + + // receive reply packet from debugee + ReplyPacket reply = new ReplyPacket(); + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet for tested command:\n\t" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" ... packet header is correct"); + } catch (BoundException e) { + log.complain("Wrong header of reply packet for tested command:\n\t" + + e.getMessage()); + success = false; + return; + } + + // start parsing reply packet data + log.display("Parsing reply packet data:"); + reply.resetPosition(); + + // extract return value + JDWP.Value newObject = null; + try { + newObject = reply.getValue(); + log.display(" newObject: " + newObject); + } catch (BoundException e) { + log.complain("Unable to extract returnValues from reply packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // extract exception tag + JDWP.Value exception = null; + try { + exception = reply.getValue(); + log.display(" exception: " + exception); + } catch (BoundException e) { + log.complain("Unable to extract exception from reply packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... packed data parsed"); + + // check that return value is an integer + if (newObject.getTag() != JDWP.Tag.OBJECT) { + log.complain("Unexpected tag of returnValue returned: " + newObject.getTag() + + " (expected: " + JDWP.Tag.OBJECT + ")"); + success = false; + } + + // check that return value is as expected + long newObjectID = ((Long)newObject.getValue()).longValue(); + if (newObjectID == 0) { + log.complain("Unexpected null objectID for newObject value returned: " + + newObjectID + " (expected: not " + 0 + ")"); + success = false; + } + + // check that exception value is an object + if (exception.getTag() != JDWP.Tag.OBJECT) { + log.complain("Unexpected tag of exception returned: " + exception.getTag() + + " (expected: " + JDWP.Tag.OBJECT + ")"); + success = false; + } + + // check that exception object is null + long exceptionID = ((Long)exception.getValue()).longValue(); + if (exceptionID != 0) { + log.complain("Not null objectID for exception value returned: " + exceptionID + + " (expected: " + 0 + ")"); + success = false; + } + } + + /** + * Check result of the tested JDWP command. + */ + void checkResult() { + // query debuggee for result value from a static field + log.display("Getting result value from static field: " + RESULT_FIELD_NAME); + int result = queryInt(classID, RESULT_FIELD_NAME, JDWP.Tag.INT); + log.display(" ... got result: " + result); + + // check if the result value is changed as expected + if (result != ARGUMENT_VALUE) { + log.complain("Method has not been really invoked: \n\t" + + "variable not changed by the method: " + result + + " (expected: " + ARGUMENT_VALUE + ")"); + success = false; + } else { + log.display("Method has been really invoked: \n\t" + + " variable changed by the method: " + result + + " (expected: " + ARGUMENT_VALUE + ")"); + } + } + + /** + * Query debuggee for value of static field of the class. + */ + JDWP.Value queryFieldValue(long classID, String fieldName, byte tag) { + // get fieledID for static field (declared in the class) + long fieldID = debugee.getClassFieldID(classID, fieldName, true); + // get value of the field + JDWP.Value value = debugee.getStaticFieldValue(classID, fieldID); + + // check that value has THREAD tag + if (value.getTag() != tag) { + log.complain("unexpedted value tag returned from debuggee: " + value.getTag() + + " (expected: " + tag + ")"); + throw new Failure("Error occured while getting value from static field: " + + fieldName); + } + + return value; + } + + /** + * Query debuggee for objectID value of static field of the class. + */ + long queryObjectID(long classID, String fieldName, byte tag) { + JDWP.Value value = queryFieldValue(classID, fieldName, tag); + long objectID = ((Long)value.getValue()).longValue(); + return objectID; + } + + /** + * Query debuggee for int value of static field of the class. + */ + int queryInt(long classID, String fieldName, byte tag) { + JDWP.Value value = queryFieldValue(classID, fieldName, tag); + int intValue = ((Integer)value.getValue()).intValue(); + return intValue; + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + if (debugee == null) + return; + + // disconnect debuggee if not dead + if (!dead) { + try { + log.display("Disconnecting debuggee"); + debugee.dispose(); + log.display(" ... debuggee disconnected"); + } catch (Failure e) { + log.display("Failed to finally dispose debuggee:\n\t" + e.getMessage()); + } + } + + // wait for debugee exits + log.display("Waiting for debuggee exits"); + int code = debugee.waitFor(); + log.display(" ... debuggee finished with exit code: " + code); + + // analize debuggee exit status code + if (code != JCK_STATUS_BASE + PASSED) { + log.complain("Debuggee FAILED with exit code: " + code); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassType/NewInstance/newinst001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassType + * command: NewInstance + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the tested constructor is really invoked into debuggee. + * Test consists of two compoments: + * debugger: newinst001 + * debuggee: newinst001a + * First, debugger uses nsk.share.* support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Next, debugger waits for tested class loaded, requests methodID + * for tested constructtor, sets breakpoint and wait for breakpoint reached. + * When breakpoint event is received the tested thread into debuggee + * is suspended by this event. + * Then, debugger creates command packet for classType.NewInstance + * command with the found classID, methodID, threadID, and also adds one + * integer argument for the constructor invocation. Then debugger writes + * packet to the transport channel and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts tegged objectID's of new created object and exception. + * Test checks if objectID is not null and exception objectID is null. + * Also test gets value of static field, wich should be modified by + * the invoked constructor, to verify if this constructor was really + * invoked into debuggee. + * Finally, debugger disconnects debuggee, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassType.NewInstance.newinst001 + * nsk.jdwp.ClassType.NewInstance.newinst001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassType.NewInstance.newinst001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// THIS TEST IS LINE NUMBER SENSITIVE + +package nsk.jdwp.ClassType.NewInstance; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +/** + * This class represents debuggee part in the test. + */ +public class newinst001a { + + // name of the tested thread + public static final String THREAD_NAME = "testedThread"; + + // line nunber for breakpoint + public static final int BREAKPOINT_LINE_NUMBER = 88; + + // initial and final value of variable changed by the method invoked from debugger + public static final int INITIAL_VALUE = 10; + public static final int FINAL_VALUE = 1234; + + // scaffold objects + private static volatile ArgumentHandler argumentHandler = null; + private static volatile Log log = null; + + public static void main(String args[]) { + newinst001a _newinst001a = new newinst001a(); + System.exit(newinst001.JCK_STATUS_BASE + _newinst001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + argumentHandler = new ArgumentHandler(args); + log = new Log(out, argumentHandler); + + // create tested of tested class + log.display("Accessing to tested class"); + TestedObjectClass.foo = 100; + log.display(" ... class loaded"); + + // invoke method with breakpoint + TestedObjectClass.run(); + + log.display("Debugee PASSED"); + return newinst001.PASSED; + } + + // tested object class + public static class TestedObjectClass { + public static int foo = 0; + + // result of invoking tested mathod + public static volatile int result = INITIAL_VALUE; + + // suspend current thread on on breakpoint + public static void run() { + log.display("Tested thread: started"); + + log.display("Breakpoint line reached"); + // next line is for breakpoint + int foo = 0; // BREAKPOINT_LINE_NUMBER + log.display("Breakpoint line passed"); + + log.display("Tested thread: finished"); + } + + // tested constructor for invokation from debugger + public TestedObjectClass(int arg) { + log.display("Tested constructor invoked with argument:" + arg); + if (arg != FINAL_VALUE) { + log.complain("Unexpected value of constructor argument: " + arg + + " (expected: " + FINAL_VALUE + ")"); + } + result = arg; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,426 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.SetValues; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ClassType.SetValues. + * + * See setvalues001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class setvalues001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String RUN = "run"; + static final String DONE = "done"; + static final String ERROR = "error"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ClassType.SetValues"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "setvalues001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ClassType.SetValues"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassType.SetValues; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // target values class name and signature constants + static final String TARGET_VALUES_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TargetValuesClass"; + static final String TARGET_VALUES_CLASS_SIGNATURE = "L" + TARGET_VALUES_CLASS_NAME.replace('.', '/') + ";"; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new setvalues001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for classID for the class with target values + log.display("Getting classID for class with target values by signature:\n" + + " " + TARGET_VALUES_CLASS_SIGNATURE); + long targetValuesClassID = + debugee.getReferenceTypeID(TARGET_VALUES_CLASS_SIGNATURE); + log.display(" got classID: " + targetValuesClassID); + + // query debugee for fieldIDs of the class static fields + log.display("Getting fieldIDs for static fields of the class"); + long targetValuesFieldIDs[] = queryClassFieldIDs(targetValuesClassID); + log.display(" got fields: " + targetValuesFieldIDs.length); + int count = targetValuesFieldIDs.length; + + // query debugee for values of the fields + log.display("Getting values of the static fields"); + JDWP.Value targetValues[] = + queryClassFieldValues(targetValuesClassID, targetValuesFieldIDs); + log.display(" got values: " + targetValues.length); + if (targetValues.length != count) { + throw new Failure("Unexpected number of static fields values received: " + + targetValues.length + "(expected: " + count + ")"); + } + + // query debugee for classID of the tested class + log.display("Getting tested classID by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long testedClassID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + testedClassID); + + // query debugee for fieldIDs of tested class static fields + log.display("Getting fieldIDs for static fields of the tested class"); + long testedFieldIDs[] = queryClassFieldIDs(testedClassID); + log.display(" got fields: " + testedFieldIDs.length); + if (testedFieldIDs.length != count) { + throw new Failure("Unexpected number of static fields of tested class received: " + + testedFieldIDs.length + "(expected: " + count + ")"); + } + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(testedClassID, testedFieldIDs, targetValues); + + // check confirmation from debuggee that values have been set properly + log.display("\n>>> Checking that the values have been set properly \n"); + checkValuesChanged(); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + e.printStackTrace(out); + success = false; + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Query debugee for fieldID's of the class static fields. + */ + long[] queryClassFieldIDs(long classID) { + // compose ReferenceType.Fields command packet + CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.Fields); + command.addReferenceTypeID(classID); + command.setLength(); + + // send the command and receive reply + ReplyPacket reply = debugee.receiveReplyFor(command); + + // extract fieldIDs from the reply packet + try { + reply.resetPosition(); + + int declared = reply.getInt(); + long[] fieldIDs = new long[declared]; + + for (int i = 0; i < declared; i++ ) { + long fieldID = reply.getFieldID(); + String name = reply.getString(); + String signature = reply.getString(); + int modBits = reply.getInt(); + + fieldIDs[i] = fieldID; + } + return fieldIDs; + } catch (BoundException e) { + log.complain("Unable to parse reply packet for ReferenceType.Fields command:\n\t" + + e); + log.complain("Received reply packet:\n" + + reply); + throw new Failure("Error occured while getting static fieldIDs for classID: " + classID); + } + } + + /** + * Query debugee for values of the class static fields. + */ + JDWP.Value[] queryClassFieldValues(long classID, long fieldIDs[]) { + // compose ReferenceType.Fields command packet + int count = fieldIDs.length; + CommandPacket command = new CommandPacket(JDWP.Command.ReferenceType.GetValues); + command.addReferenceTypeID(classID); + command.addInt(count); + for (int i = 0; i < count; i++) { + command.addFieldID(fieldIDs[i]); + } + command.setLength(); + + // send the command and receive reply + ReplyPacket reply = debugee.receiveReplyFor(command); + + // extract values from the reply packet + try { + reply.resetPosition(); + + int valuesCount = reply.getInt(); + JDWP.Value values[] = new JDWP.Value[valuesCount]; + for (int i = 0; i < valuesCount; i++ ) { + JDWP.Value value = reply.getValue(); + values[i] = value; + } + return values; + } catch (BoundException e) { + log.complain("Unable to parse reply packet for ReferenceType.GetValues command:\n\t" + + e); + log.complain("Received reply packet:\n" + + reply); + throw new Failure("Error occured while getting static fields values for classID: " + classID); + } + } + + /** + * Perform testing JDWP command for specified classID. + */ + void testCommand(long classID, long fieldIDs[], JDWP.Value values[]) { + int count = fieldIDs.length; + + // create command packet + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + + // add out data to the command packet + log.display(" classID: " + classID); + command.addReferenceTypeID(classID); + log.display(" values: " + count); + command.addInt(count); + for (int i = 0; i < count; i++) { + log.display(" field #" + i +":"); + log.display(" fieldID: " + fieldIDs[i]); + command.addFieldID(fieldIDs[i]); + + JDWP.Value value = values[i]; + JDWP.UntaggedValue untaggedValue = + new JDWP.UntaggedValue(value.getValue()); + log.display(" untagged_value: " + untaggedValue.getValue()); + command.addUntaggedValue(untaggedValue, value.getTag()); + } + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // no data to extract + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + + "0x" + reply.toHexString(reply.currentDataPosition(), 4)); + success = false; + } + } + + /** + * Check confiramtion from debuggee that values are changed. + */ + void checkValuesChanged() { + // send debugee signal RUN + log.display("Sending signal to debugee: " + RUN); + pipe.println(RUN); + + // wait for DONE signal from debugee + log.display("Waiting for signal from debugee: " + DONE); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + + // check received signal + if (signal == null) { + throw new TestBug("<null> signal received from debugee: " + signal + + " (expected: " + DONE + ")"); + } else if (signal.equals(DONE)) { + log.display("All static fields values have been correctly set into debuggee VM"); + } else if (signal.equals(ERROR)) { + log.complain("Not all static fields values have been correctly set into debuggee VM"); + success = false; + } else { + throw new TestBug("Unexpected signal received from debugee: " + signal + + " (expected: " + DONE + ")"); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassType/SetValues/setvalues001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassType + * command: SetValues + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test checks that + * the values are correctly set to debuggee class fields. + * Test consists of two compoments: + * debugger: setvalues001 + * debuggee: setvalues001a + * To set values to the static fields of the tested class + * and check that they are set correctly, test defines + * following classes into debuggee VM: + * OriginalValuesClass - with original values of static fields + * TargetValuesClass - with target values of static fields + * TestedClass - tested class with static fields to set values to + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization messages. + * Next, debugger obtains classIDs for the tested class and class with + * the target values from debugee, it obtains also fieldIDs for thess + * classese and target values of the fields. + * Then, debugger creates command packet for SetValues command with the + * found referenceTypeID and list of fieldIDs as arguments, writes packet + * to the transport channel, and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and and checks that there is no data in the reply packet. + * Then debugger sends signal RUN to debuggee to ask it to verify + * new fields values of tested class. Debuggee compares compares + * these values with original and terget values and sends ERROR signal + * to debugger if the values was not set correctly. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassType.SetValues.setvalues001 + * nsk.jdwp.ClassType.SetValues.setvalues001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassType.SetValues.setvalues001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,334 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.SetValues; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +/** + * This class represents debuggee part of the test. + */ +public class setvalues001a { + + static ArgumentHandler argumentHandler = null; + static Log log = null; + + public static void main(String args[]) { + setvalues001a _setvalues001a = new setvalues001a(); + System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + // make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + log = new Log(out, argumentHandler); + + // make communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating object of all required classes"); + OriginalValuesClass original = new OriginalValuesClass(); + TargetValuesClass target = new TargetValuesClass(); + TestedClass tested = new TestedClass(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + setvalues001.READY); + pipe.println(setvalues001.READY); + + // wait for signal RUN from debugeer + log.display("Waiting for signal from debugger: " + setvalues001.RUN); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + // check received signal + if (signal == null || !signal.equals(setvalues001.RUN)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + setvalues001.RUN + ")"); + log.display("Debugee FAILED"); + return setvalues001.FAILED; + } + + // check assigned values + if (checkValues()) { + log.display("Sending signal to debugger: " + setvalues001.DONE); + pipe.println(setvalues001.DONE); + } else { + log.display("Sending signal to debugger: " + setvalues001.ERROR); + pipe.println(setvalues001.ERROR); + } + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + setvalues001.QUIT); + signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + // check received signal + if (! signal.equals(setvalues001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + setvalues001.QUIT + ")"); + log.display("Debugee FAILED"); + return setvalues001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return setvalues001.PASSED; + } + + // check values of static fields for both classes + static boolean checkValues() { + int different = 0; + log.display("Checking that values have been set correctly:"); + + // check value of the field + if (TestedClass.booleanValue != TargetValuesClass.booleanValue) { + different++; + log.complain(" booleanValue = " + TestedClass.booleanValue + "\n" + + " setting: " + OriginalValuesClass.booleanValue + + " -> " + TargetValuesClass.booleanValue); + if (TestedClass.booleanValue == OriginalValuesClass.booleanValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" booleanValue: " + OriginalValuesClass.booleanValue + + " -> " + TargetValuesClass.booleanValue); + } + + // check value of the field + if (TestedClass.byteValue != TargetValuesClass.byteValue) { + different++; + log.complain(" byteValue = " + TestedClass.byteValue + "\n" + + " setting: " + OriginalValuesClass.byteValue + + " -> " + TargetValuesClass.byteValue); + if (TestedClass.byteValue == OriginalValuesClass.byteValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" byteValue: " + OriginalValuesClass.byteValue + + " -> " + TargetValuesClass.byteValue); + } + + // check value of the field + if (TestedClass.charValue != TargetValuesClass.charValue) { + different++; + log.complain(" charValue = " + TestedClass.charValue + "\n" + + " setting: " + OriginalValuesClass.charValue + + " -> " + TargetValuesClass.charValue); + if (TestedClass.charValue == OriginalValuesClass.charValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" charValue: " + OriginalValuesClass.charValue + + " -> " + TargetValuesClass.charValue); + } + + // check value of the field + if (TestedClass.intValue != TargetValuesClass.intValue) { + different++; + log.complain(" intValue = " + TestedClass.intValue + "\n" + + " setting: " + OriginalValuesClass.intValue + + " -> " + TargetValuesClass.intValue); + if (TestedClass.intValue == OriginalValuesClass.intValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" intValue: " + OriginalValuesClass.intValue + + " -> " + TargetValuesClass.intValue); + } + + // check value of the field + if (TestedClass.shortValue != TargetValuesClass.shortValue) { + different++; + log.complain(" shortValue = " + TestedClass.shortValue + "\n" + + " setting: " + OriginalValuesClass.shortValue + + " -> " + TargetValuesClass.shortValue); + if (TestedClass.shortValue == OriginalValuesClass.shortValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" shortValue: " + OriginalValuesClass.shortValue + + " -> " + TargetValuesClass.shortValue); + } + // check value of the field + if (TestedClass.longValue != TargetValuesClass.longValue) { + different++; + log.complain(" longValue = " + TestedClass.longValue + "\n" + + " setting: " + OriginalValuesClass.longValue + + " -> " + TargetValuesClass.longValue); + if (TestedClass.longValue == OriginalValuesClass.longValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" longValue: " + OriginalValuesClass.longValue + + " -> " + TargetValuesClass.longValue); + } + // check value of the field + if (TestedClass.floatValue != TargetValuesClass.floatValue) { + different++; + log.complain(" floatValue = " + TestedClass.floatValue + "\n" + + " setting: " + OriginalValuesClass.floatValue + + " -> " + TargetValuesClass.floatValue); + if (TestedClass.floatValue == OriginalValuesClass.floatValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" floatValue: " + OriginalValuesClass.floatValue + + " -> " + TargetValuesClass.floatValue); + } + // check value of the field + if (TestedClass.doubleValue != TargetValuesClass.doubleValue) { + different++; + log.complain(" doubleValue = " + TestedClass.doubleValue + "\n" + + " setting: " + OriginalValuesClass.doubleValue + + " -> " + TargetValuesClass.doubleValue); + if (TestedClass.doubleValue == OriginalValuesClass.doubleValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" doubleValue: " + OriginalValuesClass.doubleValue + + " -> " + TargetValuesClass.doubleValue); + } + + // check value of the field + if (TestedClass.stringValue != TargetValuesClass.stringValue) { + different++; + log.complain(" stringValue = " + TestedClass.stringValue + "\n" + + " setting: " + OriginalValuesClass.stringValue + + " -> " + TargetValuesClass.stringValue); + if (TestedClass.stringValue == OriginalValuesClass.stringValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" stringValue: " + OriginalValuesClass.stringValue + + " -> " + TargetValuesClass.stringValue); + } + + // check value of the field + if (TestedClass.objectValue != TargetValuesClass.objectValue) { + different++; + log.complain(" objectValue = " + TestedClass.objectValue + "\n" + + " setting: " + OriginalValuesClass.objectValue + + " -> " + TargetValuesClass.objectValue); + if (TestedClass.objectValue == OriginalValuesClass.objectValue) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" objectValue: " + OriginalValuesClass.objectValue + + " -> " + TargetValuesClass.objectValue); + } + +/* + // check value of the field + if (TestedClass.Value != TargetValuesClass.Value) { + different++; + log.complain(" Value = " + TestedClass.Value + "\n" + + " setting: " + OriginalValuesClass.Value + + " -> " + TargetValuesClass.Value); + if (TestedClass.Value == OriginalValuesClass.Value) { + log.complain(" not changed!"); + } else { + log.complain(" changed incorrectly!"); + } + } else { + log.display(" Value: " + OriginalValuesClass.Value + + " -> " + TargetValuesClass.Value); + } +*/ + + // check taht no any changed value differs from target + if (different > 0) { + log.complain("Values of " + different + " fields have not been set correctly"); + return false; + } + + log.display("Values of all fields have been set correctly"); + return true; + } + + // class with the original values of static fields + public static class OriginalValuesClass { + static final boolean booleanValue = true; + static final byte byteValue = (byte)0x01; + static final char charValue = 'Z'; + static final int intValue = 100; + static final short shortValue = (short)10; + static final long longValue = (long)1000000; + static final float floatValue = (float)3.14; + static final double doubleValue = (double)2.8e-12; + static final String stringValue = "text"; + static final Object objectValue = new OriginalValuesClass(); + } + + // class with the original values of static fields + public static class TargetValuesClass { + static final boolean booleanValue = false; + static final byte byteValue = (byte)0x0F; + static final char charValue = 'A'; + static final int intValue = 999; + static final short shortValue = (short)88; + static final long longValue = (long)11111111; + static final float floatValue = (float)7.19; + static final double doubleValue = (double)4.6e24; + static final String stringValue = "new text"; + static final Object objectValue = new TargetValuesClass(); + } + + // tested class with own static fields values + public static class TestedClass { + private static boolean booleanValue = OriginalValuesClass.booleanValue; + private static byte byteValue = OriginalValuesClass.byteValue; + protected static char charValue = OriginalValuesClass.charValue; + protected static int intValue = OriginalValuesClass.intValue; + public static short shortValue = OriginalValuesClass.shortValue; + public static long longValue = OriginalValuesClass.longValue; + static float floatValue = OriginalValuesClass.floatValue; + static double doubleValue = OriginalValuesClass.doubleValue; + static String stringValue = OriginalValuesClass.stringValue; + static Object objectValue = OriginalValuesClass.objectValue; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.Superclass; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP command: ClassType.Superclass. + * + * See superclass001.README for description of test execution. + * + * Test is executed by invoking method runIt(). + * JDWP command is tested in method testCommand(). + * + * @see #runIt() + * @see #testCommand() + */ +public class superclass001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // communication signals constants + static final String READY = "ready"; + static final String QUIT = "quit"; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.ClassType.Superclass"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "superclass001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP command constants + static final String JDWP_COMMAND_NAME = "ClassType.Superclass"; + static final int JDWP_COMMAND_ID = JDWP.Command.ClassType.Superclass; + + // tested class name and signature constants + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // tested superclass name and signature constants + static final String TESTED_SUPERCLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "Superclass"; + static final String TESTED_SUPERCLASS_SIGNATURE = "L" + TESTED_SUPERCLASS_NAME.replace('.', '/') + ";"; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + IOPipe pipe = null; + + // test passed or not + boolean success = true; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main (String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start JCK-compilant test. + */ + public static int run(String argv[], PrintStream out) { + return new superclass001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + + // execute test and display results + try { + log.display("\n>>> Preparing debugee for testing \n"); + + // launch debugee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + pipe = debugee.createIOPipe(); + + // make debuggee ready for testing + prepareDebugee(); + + // work with prepared debugee + try { + log.display("\n>>> Obtaining requred data from debugee \n"); + + // query debugee for classID of tested class + log.display("Getting classID of tested class by signature:\n" + + " " + TESTED_CLASS_SIGNATURE); + long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE); + log.display(" got classID: " + classID); + + // query debugee for classID of tested superclass + log.display("Getting classID of tested superclass by signature:\n" + + " " + TESTED_SUPERCLASS_SIGNATURE); + long superclassID = debugee.getReferenceTypeID(TESTED_SUPERCLASS_SIGNATURE); + log.display(" got classID: " + superclassID); + + // perform testing JDWP command + log.display("\n>>> Testing JDWP command \n"); + testCommand(classID, superclassID); + + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + } catch (Exception e) { + log.complain("Caught unexpected exception:\n" + e); + e.printStackTrace(out); + success = false; + } + + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Prepare debugee for testing and waiting for ready signal. + */ + void prepareDebugee() { + // wait for VM_INIT event from debugee + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + + // resume initially suspended debugee + log.display("Resuming debugee VM"); + debugee.resume(); + + // wait for READY signal from debugee + log.display("Waiting for signal from debugee: " + READY); + String signal = pipe.readln(); + log.display("Received signal from debugee: " + signal); + if (! signal.equals(READY)) { + throw new TestBug("Unexpected signal received form debugee: " + signal + + " (expected: " + READY + ")"); + } + } + + /** + * Sending debugee signal to quit and waiting for it exits. + */ + void quitDebugee() { + // send debugee signal to quit + log.display("Sending signal to debugee: " + QUIT); + pipe.println(QUIT); + + // wait for debugee exits + log.display("Waiting for debugee exits"); + int code = debugee.waitFor(); + + // analize debugee exit status code + if (code == JCK_STATUS_BASE + PASSED) { + log.display("Debugee PASSED with exit code: " + code); + } else { + log.complain("Debugee FAILED with exit code: " + code); + success = false; + } + } + + /** + * Perform testing JDWP command for specified classID's. + */ + void testCommand(long classID, long superclassID) { + // create command packet and fill requred out data + log.display("Create command packet:"); + log.display("Command: " + JDWP_COMMAND_NAME); + log.display(" ClassID: " + classID); + CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); + command.addReferenceTypeID(classID); + command.setLength(); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + } catch (IOException e) { + log.complain("Unable to send command packet:\n" + e); + success = false; + return; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display("Reply packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking reply packet header"); + reply.checkHeader(command.getPacketID()); + } catch (BoundException e) { + log.complain("Bad header of reply packet: " + e.getMessage()); + success = false; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract and check superclass ID + try { + long superclass = reply.getReferenceTypeID(); + log.display(" superclass: " + superclass); + + if (superclass != superclassID) { + log.complain("Unexpected classID for superclass in the reply packet:" + superclass + + " (expected: " + superclassID + ")"); + success = false; + } + } catch (BoundException e) { + log.complain("Unable to extract superclass ID from reply packet:\n" + e.getMessage()); + success = false; + } + + // check for extra data in reply packet + if (! reply.isParsed()) { + log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition()); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/ClassType/Superclass/superclass001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: ClassType + * command: Superclass + * Test checks that debugee accept the command packet and + * replies with correct reply packet. Also test check that the + * returned classID for a superclass is equal to the expected one. + * Test consists of two compoments: + * debugger: superclass001 + * debuggee: superclass001a + * First, debugger uses nsk.share support classes to launch debuggee + * and obtain Transport object, that represents JDWP transport channel. + * Also communication channel (IOPipe) is established between + * debugger and debuggee to exchange with synchronization signals. + * Next, debugger prepares for testing JDWP command and obtains + * classID's for the tested class and its superclass. + * Then, debugger creates command packet for Superclass command with the + * found classID as an argument, writes packet to the transport channel, + * and waits for a reply packet. + * When reply packet is received, debugger parses the packet structure + * and extracts classID of a superclass. Also test checks that extracted + * classID for a superclass is equal to the expected one. + * Finally, debugger sends debuggee signal to quit, waits for it exits + * and exits too with the proper exit code. + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.ClassType.Superclass.superclass001 + * nsk.jdwp.ClassType.Superclass.superclass001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.ClassType.Superclass.superclass001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.ClassType.Superclass; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +public class superclass001a { + + public static void main(String args[]) { + superclass001a _superclass001a = new superclass001a(); + System.exit(superclass001.JCK_STATUS_BASE + _superclass001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + ArgumentHandler argumentHandler = new ArgumentHandler(args); + Log log = new Log(out, argumentHandler); + + // meke communication pipe to debugger + log.display("Creating pipe"); + IOPipe pipe = argumentHandler.createDebugeeIOPipe(log); + + // ensure tested class loaded + log.display("Creating object of tested class"); + TestedClass foo = new TestedClass(); + + // send debugger signal READY + log.display("Sending signal to debugger: " + superclass001.READY); + pipe.println(superclass001.READY); + + // wait for signal QUIT from debugeer + log.display("Waiting for signal from debugger: " + superclass001.QUIT); + String signal = pipe.readln(); + log.display("Received signal from debugger: " + signal); + + // check received signal + if (! signal.equals(superclass001.QUIT)) { + log.complain("Unexpected communication signal from debugee: " + signal + + " (expected: " + superclass001.QUIT + ")"); + log.display("Debugee FAILED"); + return superclass001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return superclass001.PASSED; + } + + // indirect superclass for tested class + public static class IndirectSuperclass { + int foo = 0; + public IndirectSuperclass() { + foo = 100; + } + } + + // direct superclass for tested class + public static class Superclass extends IndirectSuperclass { + public Superclass() { + super(); + } + } + + // tested class + public static class TestedClass extends Superclass { + public TestedClass() { + super(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,653 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.Event.BREAKPOINT; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP event: BREAKPOINT. + * + * See breakpoint001.README for description of test execution. + * + * This class represents debugger part of the test. + * Test is executed by invoking method runIt(). + * JDWP event is tested in the method waitForTestedEvent(). + * + * @see #runIt() + * @see #waitForTestedEvent() + */ +public class breakpoint001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.Event.BREAKPOINT"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "breakpoint001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP event constants + static final byte TESTED_EVENT_KIND = JDWP.EventKind.BREAKPOINT; + static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL; + + // name and signature of the tested class + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + static final String TESTED_THREAD_NAME = "TestedThread"; + + // name of field and method of tested class + static final String THREAD_FIELD_NAME = "thread"; + static final String TESTED_METHOD_NAME = "run"; + static final int BREAKPOINT_LINE = breakpoint001a.BREAKPOINT_LINE; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + int waitTime = 0; // minutes + long timeout = 0; // milliseconds + boolean dead = false; + boolean success = true; + + // obtained data + long testedClassID = 0; + long testedThreadID = 0; + long testedMethodID = 0; + JDWP.Location testedLocation = null; + int eventRequestID = 0; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main(String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start test from JCK-compilant environment. + */ + public static int run(String argv[], PrintStream out) { + return new breakpoint001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + waitTime = argumentHandler.getWaitTime(); + timeout = waitTime * 60 * 1000; + + // execute test and display results + try { + log.display("\n>>> Starting debugee \n"); + + // launch debuggee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + log.display(" ... debugee launched"); + log.display(""); + + // set timeout for debuggee responces + log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)"); + transport.setReadTimeout(timeout); + log.display(" ... timeout set"); + + // wait for debuggee started + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + log.display(" ... VM_INIT event received"); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + log.display(" ... size of VM-dependent types adjusted"); + + // get debuggee prepared for testing + log.display("\n>>> Getting prepared for testing \n"); + prepareForTest(); + + // test JDWP event + log.display("\n>>> Testing JDWP event \n"); + + // request tested event + log.display("Making request for BREAKPOINT event at: " + + TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE); + requestTestedEvent(); + log.display(" ... got requestID: " + eventRequestID); + log.display(""); + + // resume debuggee + log.display("Resumindg debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + log.display(""); + + // wait for tested BREAKPOINT event + log.display("Waiting for BREAKPOINT event received"); + waitForTestedEvent(); + log.display(" ... event received"); + log.display(""); + + // check if event is for expected thread + if (success) { + log.display("Checking thread of BREAKPOINT event"); + checkThread(); + log.display(""); + } + + + // clear tested request for BREAKPOINT event + log.display("Clearing request for tested event"); + clearTestedRequest(); + log.display(" ... request removed"); + + // finish debuggee after testing + log.display("\n>>> Finishing debuggee \n"); + + // resume debuggee + log.display("Resuming debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + + // wait for debuggee exited + log.display("Waiting for VM_DEATH event"); + debugee.waitForVMDeath(); + dead = true; + log.display(" ... VM_DEATH event received"); + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + // check test results + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Get debuggee prepared for testing and obtain required data. + */ + void prepareForTest() { + // wait for tested class loaded + log.display("Waiting for tested class loaded"); + testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL); + log.display(" ... got classID: " + testedClassID); + log.display(""); + + // get methodID for tested method + log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME); + testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true); + log.display(" ... got methodID: " + testedMethodID); + + // get codeIndex for breakpoint line + log.display("Getting codeIndex for breakpoint line: " + BREAKPOINT_LINE); + long codeIndex = debugee.getCodeIndex(testedClassID, testedMethodID, BREAKPOINT_LINE); + log.display(" ... got index: " + codeIndex); + + // create location for breakpoint + log.display("Creating location for breakpoint request"); + testedLocation = new JDWP.Location(JDWP.TypeTag.CLASS, testedClassID, + testedMethodID, codeIndex); + log.display(" ... got location: " + testedLocation); + } + + /** + * Make request for tested BREAKPOINT event. + */ + void requestTestedEvent() { + Failure failure = new Failure("Error occured while makind request for tested event"); + + // create command packet and fill requred out data + log.display("Create command packet: " + "EventRequest.Set"); + CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Set); + log.display(" eventKind: " + TESTED_EVENT_KIND); + command.addByte(TESTED_EVENT_KIND); + log.display(" eventPolicy: " + TESTED_EVENT_SUSPEND_POLICY); + command.addByte(TESTED_EVENT_SUSPEND_POLICY); + log.display(" modifiers: " + 1); + command.addInt(1); + log.display(" modKind: " + JDWP.EventModifierKind.LOCATION_ONLY); + command.addByte(JDWP.EventModifierKind.LOCATION_ONLY); + log.display(" location: " + testedLocation); + command.addLocation(testedLocation); + command.setLength(); + log.display(" ... command packet composed"); + log.display(""); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + log.display(" ... command packet sent"); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + throw failure; + } + log.display(""); + + // receive reply packet from debugee + ReplyPacket reply = new ReplyPacket(); + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + throw failure; + } + log.display(""); + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" .. packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + throw failure; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract requestID + int requestID = 0; + try { + requestID = reply.getInt(); + log.display(" requestID: " + requestID); + } catch (BoundException e) { + log.complain("Unable to extract requestID from request reply packet:\n\t" + + e.getMessage()); + success = false; + throw failure; + } + + // check requestID + if (requestID == 0) { + log.complain("Unexpected null requestID returned: " + requestID); + success = false; + throw failure; + } + + eventRequestID = requestID; + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in request reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... reply packet parsed"); + } + + /** + * Clear request for tested BREAKPOINT event. + */ + void clearTestedRequest() { + Failure failure = new Failure("Error occured while clearing request for tested event"); + + // create command packet and fill requred out data + log.display("Create command packet: " + "EventRequest.Clear"); + CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Clear); + log.display(" event: " + TESTED_EVENT_KIND); + command.addByte(TESTED_EVENT_KIND); + log.display(" requestID: " + eventRequestID); + command.addInt(eventRequestID); + log.display(" ... command packet composed"); + log.display(""); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + log.display(" ... command packet sent"); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + throw failure; + } + log.display(""); + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + throw failure; + } + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" .. packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + throw failure; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + log.display(" no data"); + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in request reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... reply packet parsed"); + } + + /** + * Wait for tested BREAKPOINT event. + */ + void waitForTestedEvent() { + + EventPacket eventPacket = null; + + // receive reply packet from debugee + try { + log.display("Waiting for event packet"); + eventPacket = debugee.getEventPacket(timeout); + log.display(" ... event packet received:\n" + eventPacket); + } catch (IOException e) { + log.complain("Unable to read tested event packet:\n\t" + e); + success = false; + return; + } + log.display(""); + + // check reply packet header + try{ + log.display("Checking header of event packet"); + eventPacket.checkHeader(); + log.display(" ... packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // start parsing reply packet data + log.display("Parsing event packet:"); + eventPacket.resetPosition(); + + // get suspendPolicy value + byte suspendPolicy = 0; + try { + suspendPolicy = eventPacket.getByte(); + log.display(" suspendPolicy: " + suspendPolicy); + } catch (BoundException e) { + log.complain("Unable to get suspendPolicy value from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check suspendPolicy value + if (suspendPolicy != TESTED_EVENT_SUSPEND_POLICY) { + log.complain("Unexpected SuspendPolicy in tested event packet: " + + suspendPolicy + " (expected: " + TESTED_EVENT_SUSPEND_POLICY + ")"); + success = false; + } + + // get events count + int events = 0; + try { + events = eventPacket.getInt(); + log.display(" events: " + events); + } catch (BoundException e) { + log.complain("Unable to get events count from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check events count + if (events < 0) { + log.complain("Negative value of events number in tested event packet: " + + events + " (expected: " + 1 + ")"); + success = false; + } else if (events != 1) { + log.complain("Invalid number of events in tested event packet: " + + events + " (expected: " + 1 + ")"); + success = false; + } + + // extract each event + long eventThreadID = 0; + for (int i = 0; i < events; i++) { + log.display(" event #" + i + ":"); + + // get eventKind + byte eventKind = 0; + try { + eventKind = eventPacket.getByte(); + log.display(" eventKind: " + eventKind); + } catch (BoundException e) { + log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check eventKind + if (eventKind == JDWP.EventKind.VM_DEATH) { + log.complain("Unexpected VM_DEATH event received: " + + eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")"); + dead = true; + success = false; + return; + } else if (eventKind != JDWP.EventKind.BREAKPOINT) { + log.complain("Unexpected eventKind of event " + i + " in tested event packet: " + + eventKind + " (expected: " + JDWP.EventKind.BREAKPOINT + ")"); + success = false; + return; + } + + // get requestID + int requestID = 0; + try { + requestID = eventPacket.getInt(); + log.display(" requestID: " + requestID); + } catch (BoundException e) { + log.complain("Unable to get requestID of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check requestID + if (requestID != eventRequestID) { + log.complain("Unexpected requestID of event " + i + " in tested event packet: " + + requestID + " (expected: " + eventRequestID + ")"); + success = false; + } + + // get threadID + long threadID = 0; + try { + threadID = eventPacket.getObjectID(); + log.display(" threadID: " + threadID); + } catch (BoundException e) { + log.complain("Unable to get threadID of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // save threadID for further checking + testedThreadID = threadID; + + // get location + JDWP.Location location = null; + try { + location = eventPacket.getLocation(); + log.display(" location: " + location); + } catch (BoundException e) { + log.complain("Unable to get location of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check location + if (location.getTag() != testedLocation.getTag()) { + log.complain("Unexpected class tag of location of event " + i + + " in tested event packet: " + location.getTag() + + " (expected: " + testedLocation.getTag() + ")"); + success = false; + } + if (location.getClassID() != testedLocation.getClassID()) { + log.complain("Unexpected classID of location of event " + i + + " in tested event packet: " + location.getClassID() + + " (expected: " + testedLocation.getClassID() + ")"); + success = false; + } + if (location.getMethodID() != testedLocation.getMethodID()) { + log.complain("Unexpected methodID of location of event " + i + + " in tested event packet: " + location.getMethodID() + + " (expected: " + testedLocation.getMethodID() + ")"); + success = false; + } + if (location.getIndex() != testedLocation.getIndex()) { + log.complain("Unexpected codeIndex of location of event " + i + + " in tested event packet: " + location.getIndex() + + " (expected: " + testedLocation.getIndex() + ")"); + success = false; + } + } + + // check for extra data in event packet + if (!eventPacket.isParsed()) { + log.complain("Extra trailing bytes found in event packet at: " + + eventPacket.offsetString()); + success = false; + } + + log.display(" ... event packet parsed"); + } + + /** + * Check if threadID received by BREAKPOINT event is as expected one. + */ + void checkThread() { + // get thread value from static field of tested class + log.display("Getting thread value from static field: " + THREAD_FIELD_NAME); + JDWP.Value value = debugee.getStaticFieldValue(testedClassID, THREAD_FIELD_NAME, + JDWP.Tag.THREAD); + long threadID = ((Long)value.getValue()).longValue(); + log.display(" ... got threadID: " + testedThreadID); + + // check threadID + if (threadID != testedThreadID) { + log.complain("Unexpected threadID of BREAKPOINT event received: " + + testedThreadID + " (expected: " + threadID + ")"); + success = false; + } else { + log.display("Received threadID is as expected"); + } + } + + /** + * Disconnect debuggee and wait for it exited. + */ + void quitDebugee() { + if (debugee == null) + return; + + // disconnect debugee + if (!dead) { + try { + log.display("Disconnecting debuggee"); + debugee.dispose(); + log.display(" ... debuggee disconnected"); + } catch (Failure e) { + log.display("Failed to finally disconnect debuggee:\n\t" + + e.getMessage()); + } + } + + // wait for debugee exited + log.display("Waiting for debuggee exit"); + int code = debugee.waitFor(); + log.display(" ... debuggee exited with exit code: " + code); + + // analize debugee exit status code + if (code != JCK_STATUS_BASE + PASSED) { + log.complain("Debuggee FAILED with exit code: " + code); + success = false; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/* + * @test + * + * @summary converted from VM Testbase nsk/jdwp/Event/BREAKPOINT/breakpoint001. + * VM Testbase keywords: [quick, jpda, jdwp] + * VM Testbase readme: + * DESCRIPTION + * This test performs checking for + * command set: Event + * command: Composite + * command set: EventRequest + * command: Set, Clear + * event kind: BREAKPOINT + * Test checks that + * 1) debuggee successfully creates BREAKPOINT event request + * for particular location + * 2) expected BREAKPOINT event is received when the thread + * reaches breakpoint and has correct attributes + * 3) debuggee successfully removes event request + * Test consists of two compoments: + * debugger: breakpoint001 + * debuggee: breakpoint001a + * First, debugger uses nsk.share support classes to launch debuggee, + * and obtains Transport object, that represents JDWP transport channel. + * Next, debugger waits for tested class loaded and makes BREAKPOINT + * event request for location into method run() of the tested thread, + * When event is received debugger checks if the received event + * is for this location and has correct attributes. Then debugger + * removes event request. + * Finally, debugger disconnects debuggee, waits for it exited + * and exits too with proper exit code. + * COMMENTS + * Test was fixed due to test bug: + * 4797978 TEST_BUG: potential race condition in a number of JDWP tests + * + * @library /vmTestbase /test/hotspot/jtreg/vmTestbase + * /test/lib + * @run driver jdk.test.lib.FileInstaller . . + * @build nsk.jdwp.Event.BREAKPOINT.breakpoint001 + * nsk.jdwp.Event.BREAKPOINT.breakpoint001a + * @run main/othervm PropertyResolvingWrapper + * nsk.jdwp.Event.BREAKPOINT.breakpoint001 + * -arch=${os.family}-${os.simpleArch} + * -verbose + * -waittime=5 + * -debugee.vmkind=java + * -transport.address=dynamic + * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" + */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001a.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// THIS TEST IS LINE NUMBER SENSITIVE + +package nsk.jdwp.Event.BREAKPOINT; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +import java.io.*; + +/** + * This class represents debuggee part in the test. + */ +public class breakpoint001a { + + static final int BREAKPOINT_LINE = 91; + + static ArgumentHandler argumentHandler = null; + static Log log = null; + + public static void main(String args[]) { + breakpoint001a _breakpoint001a = new breakpoint001a(); + System.exit(breakpoint001.JCK_STATUS_BASE + _breakpoint001a.runIt(args, System.err)); + } + + public int runIt(String args[], PrintStream out) { + //make log for debugee messages + argumentHandler = new ArgumentHandler(args); + log = new Log(out, argumentHandler); + + // create tested thread + log.display("Creating tested thread"); + TestedClass.thread = new TestedClass(breakpoint001.TESTED_THREAD_NAME); + log.display(" ... thread created"); + + // start tested thread + log.display("Starting tested thread"); + TestedClass.thread.start(); + log.display(" ... thread started"); + + // wait for thread finished + try { + log.display("Waiting for tested thread finished"); + TestedClass.thread.join(); + log.display(" ... thread finished"); + } catch (InterruptedException e) { + log.complain("Interruption while waiting for tested thread finished"); + return breakpoint001.FAILED; + } + + // exit debugee + log.display("Debugee PASSED"); + return breakpoint001.PASSED; + } + + // tested class + public static class TestedClass extends Thread { + public static volatile TestedClass thread = null; + + public TestedClass(String name) { + super(name); + } + + public void run() { + log.display("Tested thread: started"); + log.display("Breakpoint line reached"); + // next line is for breakpoint + int foo = 0; // BREAKPOINT_LINE + log.display("Breakpoint line passed"); + log.display("Tested thread: finished"); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001.java Wed May 30 20:54:45 2018 -0700 @@ -0,0 +1,607 @@ +/* + * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package nsk.jdwp.Event.CLASS_PREPARE; + +import java.io.*; + +import nsk.share.*; +import nsk.share.jpda.*; +import nsk.share.jdwp.*; + +/** + * Test for JDWP event: CLASS_PREPARE. + * + * See clsprepare001.README for description of test execution. + * + * This class represents debugger part of the test. + * Test is executed by invoking method runIt(). + * JDWP event is tested in the method waitForTestedEvent(). + * + * @see #runIt() + * @see #waitForTestedEvent() + */ +public class clsprepare001 { + + // exit status constants + static final int JCK_STATUS_BASE = 95; + static final int PASSED = 0; + static final int FAILED = 2; + + // package and classes names constants + static final String PACKAGE_NAME = "nsk.jdwp.Event.CLASS_PREPARE"; + static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "clsprepare001"; + static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; + + // tested JDWP event constants + static final byte TESTED_EVENT_KIND = JDWP.EventKind.CLASS_PREPARE; + static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL; + + // name and signature of the tested class + static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass"; + static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; + + // usual scaffold objects + ArgumentHandler argumentHandler = null; + Log log = null; + Binder binder = null; + Debugee debugee = null; + Transport transport = null; + int waitTime = 0; // minutes + long timeout = 0; // milliseconds + boolean dead = false; + boolean success = true; + + // obtained data + int eventRequestID = 0; + + // ------------------------------------------------------------------- + + /** + * Start test from command line. + */ + public static void main(String argv[]) { + System.exit(run(argv,System.out) + JCK_STATUS_BASE); + } + + /** + * Start test from JCK-compilant environment. + */ + public static int run(String argv[], PrintStream out) { + return new clsprepare001().runIt(argv, out); + } + + // ------------------------------------------------------------------- + + /** + * Perform test execution. + */ + public int runIt(String argv[], PrintStream out) { + + // make log for debugger messages + argumentHandler = new ArgumentHandler(argv); + log = new Log(out, argumentHandler); + waitTime = argumentHandler.getWaitTime(); + timeout = waitTime * 60 * 1000; + + // execute test and display results + try { + log.display("\n>>> Starting debugee \n"); + + // launch debuggee + binder = new Binder(argumentHandler, log); + log.display("Launching debugee"); + debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); + transport = debugee.getTransport(); + log.display(" ... debugee launched"); + log.display(""); + + // set timeout for debuggee responces + log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)"); + transport.setReadTimeout(timeout); + log.display(" ... timeout set"); + + // wait for debuggee started + log.display("Waiting for VM_INIT event"); + debugee.waitForVMInit(); + log.display(" ... VM_INIT event received"); + + // query debugee for VM-dependent ID sizes + log.display("Querying for IDSizes"); + debugee.queryForIDSizes(); + log.display(" ... size of VM-dependent types adjusted"); + + // make request for CLASS_PREPARE event + log.display("\n>>> Making request for tested event \n"); + + log.display("Making request for CLASS_PREPARE event for class:\n\t" + + TESTED_CLASS_NAME); + requestTestedEvent(); + log.display(" ... got requestID: " + eventRequestID); + + // resume debuggee + log.display("Resumindg debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + + // wait for tested CLASS_PREPARE event + log.display("\n>>> Testing JDWP event \n"); + waitForTestedEvent(); + + // clear tested request for CLASS_PREPARE event + log.display("\n>>> Clearing request for tested event \n"); + clearTestedRequest(); + + // finish debuggee after testing + log.display("\n>>> Finishing debuggee \n"); + + // resume debuggee + log.display("Resuming debuggee"); + debugee.resume(); + log.display(" ... debuggee resumed"); + + // wait for debuggee exited + log.display("Waiting for VM_DEATH event"); + debugee.waitForVMDeath(); + dead = true; + log.display(" ... VM_DEATH event received"); + + } catch (Failure e) { + log.complain("TEST FAILED: " + e.getMessage()); + success = false; + } catch (Exception e) { + e.printStackTrace(out); + log.complain("Caught unexpected exception while running the test:\n\t" + e); + success = false; + } finally { + // quit debugee + log.display("\n>>> Finishing test \n"); + quitDebugee(); + } + + // check test results + if (!success) { + log.complain("TEST FAILED"); + return FAILED; + } + + out.println("TEST PASSED"); + return PASSED; + + } + + /** + * Make request for tested CLASS_PREPARE event. + */ + void requestTestedEvent() { + Failure failure = new Failure("Error occured while makind request for tested event"); + + // create command packet and fill requred out data + log.display("Create command packet: " + "EventRequest.Set"); + CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Set); + log.display(" eventKind: " + TESTED_EVENT_KIND); + command.addByte(TESTED_EVENT_KIND); + log.display(" eventPolicy: " + TESTED_EVENT_SUSPEND_POLICY); + command.addByte(TESTED_EVENT_SUSPEND_POLICY); + log.display(" modifiers: " + 1); + command.addInt(1); + log.display(" modKind: " + JDWP.EventModifierKind.CLASS_MATCH); + command.addByte(JDWP.EventModifierKind.CLASS_MATCH); + log.display(" classPattern: " + TESTED_CLASS_NAME); + command.addString(TESTED_CLASS_NAME); + command.setLength(); + log.display(" ... command packet composed"); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + log.display(" ... command packet sent"); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + throw failure; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + throw failure; + } + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" .. packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + throw failure; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + // extract requestID + int requestID = 0; + try { + requestID = reply.getInt(); + log.display(" requestID: " + requestID); + } catch (BoundException e) { + log.complain("Unable to extract requestID from request reply packet:\n\t" + + e.getMessage()); + success = false; + throw failure; + } + + // check requestID + if (requestID == 0) { + log.complain("Unexpected null requestID returned: " + requestID); + success = false; + throw failure; + } + + eventRequestID = requestID; + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in request reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... reply packet parsed"); + } + + /** + * Clear request for tested CLASS_PREPARE event. + */ + void clearTestedRequest() { + Failure failure = new Failure("Error occured while clearing request for tested event"); + + // create command packet and fill requred out data + log.display("Create command packet: " + "EventRequest.Clear"); + CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Clear); + log.display(" event: " + TESTED_EVENT_KIND); + command.addByte(TESTED_EVENT_KIND); + log.display(" requestID: " + eventRequestID); + command.addInt(eventRequestID); + log.display(" ... command packet composed"); + + // send command packet to debugee + try { + log.display("Sending command packet:\n" + command); + transport.write(command); + log.display(" ... command packet sent"); + } catch (IOException e) { + log.complain("Unable to send command packet:\n\t" + e); + success = false; + throw failure; + } + + ReplyPacket reply = new ReplyPacket(); + + // receive reply packet from debugee + try { + log.display("Waiting for reply packet"); + transport.read(reply); + log.display(" ... packet received:\n" + reply); + } catch (IOException e) { + log.complain("Unable to read reply packet:\n\t" + e); + success = false; + throw failure; + } + + // check reply packet header + try{ + log.display("Checking header of reply packet"); + reply.checkHeader(command.getPacketID()); + log.display(" .. packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of reply packet:\n\t" + e.getMessage()); + success = false; + throw failure; + } + + // start parsing reply packet data + log.display("Parsing reply packet:"); + reply.resetPosition(); + + log.display(" no data"); + + // check for extra data in reply packet + if (!reply.isParsed()) { + log.complain("Extra trailing bytes found in request reply packet at: " + + reply.offsetString()); + success = false; + } + + log.display(" ... reply packet parsed"); + } + + /** + * Wait for tested CLASS_PREPARE event. + */ + void waitForTestedEvent() { + + EventPacket eventPacket = null; + + // receive reply packet from debugee + try { + log.display("Waiting for event packet (for " + timeout + "ms timeout)"); + eventPacket = debugee.getEventPacket(timeout); + log.display(" ... event packet received:\n" + eventPacket); + } catch (IOException e) { + log.complain("Unable to read tested event packet:\n\t" + e); + success = false; + return; + } + + // check reply packet header + try{ + log.display("Checking header of event packet"); + eventPacket.checkHeader(); + log.display(" ... packet header is correct"); + } catch (BoundException e) { + log.complain("Bad header of tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // start parsing reply packet data + log.display("Parsing event packet:"); + eventPacket.resetPosition(); + + // get suspendPolicy value + byte suspendPolicy = 0; + try { + suspendPolicy = eventPacket.getByte(); + log.display(" suspendPolicy: " + suspendPolicy); + } catch (BoundException e) { + log.complain("Unable to get suspendPolicy value from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check suspendPolicy value + if (suspendPolicy != TESTED_EVENT_SUSPEND_POLICY) { + log.complain("Unexpected SuspendPolicy in tested event packet: " + + suspendPolicy + " (expected: " + TESTED_EVENT_SUSPEND_POLICY + ")"); + success = false; + } + + // get events count + int events = 0; + try { + events = eventPacket.getInt(); + log.display(" events: " + events); + } catch (BoundException e) { + log.complain("Unable to get events count from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check events count + if (events < 0) { + log.complain("Negative value of events number in tested event packet: " + + events + " (expected: " + 1 + ")"); + success = false; + } else if (events != 1) { + log.complain("Invalid number of events in tested event packet: " + + events + " (expected: " + 1 + ")"); + success = false; + } + + // extract each event + for (int i = 0; i < events; i++) { + log.display(" event #" + i + ":"); + + // get eventKind + byte eventKind = 0; + try { + eventKind = eventPacket.getByte(); + log.display(" eventKind: " + eventKind); + } catch (BoundException e) { + log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check eventKind + if (eventKind != JDWP.EventKind.CLASS_PREPARE) { + log.complain("Unexpected eventKind of event " + i + " in tested event packet: " + + eventKind + " (expected: " + JDWP.EventKind.CLASS_PREPARE + ")"); + success = false; + return; + } + + // get requestID + int requestID = 0; + try { + requestID = eventPacket.getInt(); + log.display(" requestID: " + requestID); + } catch (BoundException e) { + log.complain("Unable to get requestID of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check requestID + if (requestID != eventRequestID) { + log.complain("Unexpected requestID of event " + i + " in tested event packet: " + + requestID + " (expected: " + eventRequestID + ")"); + success = false; + } + + // get threadID + long threadID = 0; + try { + threadID = eventPacket.getObjectID(); + log.display(" threadID: " + threadID); + } catch (BoundException e) { + log.complain("Unable to get threadID of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check threadID + if (threadID == 0) { + log.complain("Unexpected null threadID of event " + i + " in tested event packet: " + + threadID); + success = false; + } + + // get refTypeTag + byte refTypeTag = 0; + try { + refTypeTag = eventPacket.getByte(); + log.display(" refTypeTag: " + refTypeTag); + } catch (BoundException e) { + log.complain("Unable to get refTypeTag of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check refTypeGag + if (refTypeTag != JDWP.TypeTag.CLASS) { + log.complain("Unexpected refTypeTag of event " + i + " in tested event packet: " + + refTypeTag + " (expected: " + JDWP.TypeTag.CLASS + ")"); + success = false; + } + + // get referenceTypeID + long referenceTypeID = 0; + try { + referenceTypeID = eventPacket.getReferenceTypeID(); + log.display(" referenceTypeID: " + referenceTypeID); + } catch (BoundException e) { + log.complain("Unable to get referenceTypeID of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check referenceTypeID + if (referenceTypeID == 0) { + log.complain("Unexpected null referenceTypeID of event " + i + " in tested event packet: " + + referenceTypeID); + success = false; + } + + // get signature + String signature = null; + try { + signature = eventPacket.getString(); + log.display(" signature: " + signature); + } catch (BoundException e) { + log.complain("Unable to get class signature of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check signature + if (!signature.equals(TESTED_CLASS_SIGNATURE)) { + log.complain("Unexpected class signature of event " + i + " in tested event packet: " + + signature + " (expected: " + TESTED_CLASS_SIGNATURE + ")"); + success = false; + } + + // get status + int status = 0; + try { + status = eventPacket.getInt(); + log.display(" status: " + status); + } catch (BoundException e) { + log.complain("Unable to get class status of event #" + i + " from tested event packet:\n\t" + + e.getMessage()); + success = false; + return; + } + + // check status + if ((status & JDWP.ClassStatus.ERROR) != 0) { + log.complain("Unexpected class status of event " + i + " in tested event packet: " + + status + " (expected: w/o bit " + JDWP.ClassStatus.ERROR + ")"); + success = false; + } + } + + // check for extra data in event packet + if (!eventPacket.isParsed()) { + log.complain("Extra trailing bytes found in event packet at: " + + eventPacket.offsetString()); + success = false; + } + + log.display(" ... event packet parsed"); + } + + /** + * Disconnect debuggee and wait for it exited. + */ + void quitDebugee() { + if (debugee == null) + return; + + // disconnect debugee + if (!dead) { + try { + log.display("Disconnecting debuggee"); + debugee.dispose(); + log.display(" ... debuggee disconnected"); + } catch (Failure e) { + log.display("Failed to finally disconnect debuggee:\n\t" + + e.getMessage()); + } + } + + // wait for debugee exited + log.display("Waiting for debuggee exit"); + int code = debugee.waitFor(); + log.display(" ... debuggee exited with exit code: " + code); + + // analize debugee exit s