JDI-based tests run, many fail
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Test" type="JUnit" factoryName="JUnit">
|
||||
<configuration default="false" name="Reflection Test" type="JUnit" factoryName="JUnit">
|
||||
<module name="eval4j" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" value="" />
|
||||
@@ -1,16 +1,31 @@
|
||||
<root>
|
||||
<item name='com.sun.jdi.Bootstrap com.sun.jdi.VirtualMachineManager virtualMachineManager()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.ClassObjectReference com.sun.jdi.ReferenceType reflectedType()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.Location com.sun.jdi.Method method()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.ReferenceType com.sun.jdi.ClassObjectReference classObject()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.ReferenceType java.util.List<com.sun.jdi.Location> allLineLocations()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.ReferenceType java.util.List<com.sun.jdi.Method> methodsByName(java.lang.String, java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.StackFrame com.sun.jdi.Location location()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.StackFrame java.util.List<com.sun.jdi.LocalVariable> visibleVariables()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.StackFrame java.util.List<com.sun.jdi.Value> getArgumentValues()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.Type java.lang.String signature()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
@@ -20,7 +35,22 @@
|
||||
<item name='com.sun.jdi.Value com.sun.jdi.Type type()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachine com.sun.jdi.event.EventQueue eventQueue()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachine com.sun.jdi.request.EventRequestManager eventRequestManager()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachine java.util.List<com.sun.jdi.ReferenceType> allClasses()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachine java.util.List<com.sun.jdi.ReferenceType> classesByName(java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachineManager java.util.List<com.sun.jdi.connect.AttachingConnector> attachingConnectors()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.VirtualMachineManager java.util.List<com.sun.jdi.connect.LaunchingConnector> launchingConnectors()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,5 @@
|
||||
<root>
|
||||
<item name='com.sun.jdi.connect.Connector java.util.Map<java.lang.String,com.sun.jdi.connect.Connector.Argument> defaultArguments()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,8 @@
|
||||
<root>
|
||||
<item name='com.sun.jdi.event.EventQueue com.sun.jdi.event.EventSet remove()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.event.LocatableEvent com.sun.jdi.ThreadReference thread()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,8 @@
|
||||
<root>
|
||||
<item name='com.sun.jdi.request.EventRequestManager com.sun.jdi.request.BreakpointRequest createBreakpointRequest(com.sun.jdi.Location)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.sun.jdi.request.EventRequestManager com.sun.jdi.request.ClassPrepareRequest createClassPrepareRequest()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,8 @@
|
||||
<root>
|
||||
<item name='java.lang.Process java.io.InputStream getErrorStream()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='java.lang.Process java.io.InputStream getInputStream()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.jetbrains.eval4j.jdi.test;
|
||||
|
||||
public class Debugee {
|
||||
public static void main(String[] args) {
|
||||
// BREAKPOINT
|
||||
Runtime.getRuntime();
|
||||
System.out.println("hi");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.jetbrains.eval4j.jdi.test
|
||||
|
||||
import com.sun.jdi
|
||||
import junit.framework.TestSuite
|
||||
import org.jetbrains.eval4j.test.buildTestSuite
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.eval4j.interpreterLoop
|
||||
import org.junit.Assert.*
|
||||
import org.jetbrains.eval4j.jdi.makeInitialFrame
|
||||
import org.jetbrains.eval4j.jdi.JDIEval
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import org.jetbrains.eval4j.ExceptionThrown
|
||||
import org.jetbrains.eval4j.jdi.asJdiValue
|
||||
import org.jetbrains.eval4j.MethodDescription
|
||||
|
||||
val DEBUGEE_CLASS = javaClass<Debugee>()
|
||||
|
||||
fun suite(): TestSuite {
|
||||
val connectors = jdi.Bootstrap.virtualMachineManager().launchingConnectors()
|
||||
val connector = connectors[0]
|
||||
println("Using connector $connector")
|
||||
|
||||
val connectorArgs = connector.defaultArguments()
|
||||
|
||||
val debugeeName = DEBUGEE_CLASS.getName()
|
||||
println("Debugee name: $debugeeName")
|
||||
connectorArgs["main"]!!.setValue(debugeeName)
|
||||
connectorArgs["options"]!!.setValue("-classpath out/production/eval4j:out/test/eval4j")
|
||||
val vm = connector.launch(connectorArgs)!!
|
||||
|
||||
val req = vm.eventRequestManager().createClassPrepareRequest()
|
||||
req.addClassFilter("*.Debugee")
|
||||
req.enable()
|
||||
|
||||
val latch = CountDownLatch(1)
|
||||
var classLoader : jdi.ClassLoaderReference? = null
|
||||
var thread : jdi.ThreadReference? = null
|
||||
|
||||
Thread {
|
||||
val eventQueue = vm.eventQueue()
|
||||
@mainLoop while (true) {
|
||||
val eventSet = eventQueue.remove()
|
||||
for (event in eventSet.eventIterator()) {
|
||||
when (event) {
|
||||
is jdi.event.ClassPrepareEvent -> {
|
||||
val _class = event.referenceType()!!
|
||||
if (_class.name() == debugeeName) {
|
||||
for (l in _class.allLineLocations()) {
|
||||
if (l.method().name() == "main") {
|
||||
classLoader = l.method().declaringType().classLoader()
|
||||
val breakpointRequest = vm.eventRequestManager().createBreakpointRequest(l)
|
||||
breakpointRequest.enable()
|
||||
println("Breakpoint: $breakpointRequest")
|
||||
vm.resume()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is jdi.event.BreakpointEvent -> {
|
||||
println("Suspended at: " + event.location())
|
||||
|
||||
thread = event.thread()
|
||||
latch.countDown()
|
||||
|
||||
break @mainLoop
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
|
||||
vm.resume()
|
||||
|
||||
latch.await()
|
||||
|
||||
var remainingTests = AtomicInteger(0)
|
||||
|
||||
val suite = buildTestSuite {
|
||||
methodNode, ownerClass, expected ->
|
||||
remainingTests.incrementAndGet()
|
||||
object : TestCase("test" + methodNode.name.capitalize()) {
|
||||
|
||||
override fun runTest() {
|
||||
val eval = JDIEval(
|
||||
vm, classLoader!!, thread!!
|
||||
)
|
||||
val value = interpreterLoop(
|
||||
methodNode,
|
||||
makeInitialFrame(methodNode, listOf()),
|
||||
eval
|
||||
)
|
||||
|
||||
if (remainingTests.decrementAndGet() == 0) vm.resume()
|
||||
|
||||
if (value is ExceptionThrown) {
|
||||
val str = eval.invokeMethod(
|
||||
value.exception,
|
||||
MethodDescription(
|
||||
"java/lang/Object",
|
||||
"toString",
|
||||
"()Ljava/lang/String;",
|
||||
false
|
||||
),
|
||||
listOf())
|
||||
System.err.println("Exception: $str")
|
||||
}
|
||||
|
||||
assertEquals(expected, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return suite
|
||||
}
|
||||
Reference in New Issue
Block a user