[JVM+IR] Unify new debugger tests expectations

This commit unifies the expectation format between the stepping and
LVT tests in the new debugging test harness.

Furthermore, it introduces a compression of runs of locations without
linenumbers. These default to showing as bytecode offsets from
previous line number, which overspecifies the tests: the bytecodes
chosen should not be constrained by a debugging step test.
This commit is contained in:
Kristoffer Andersen
2020-10-19 15:34:16 +02:00
committed by max-kammerer
parent e19ecdfb3d
commit 27fb46712a
16 changed files with 184 additions and 99 deletions
+7 -7
View File
@@ -10,10 +10,10 @@ fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:3: // test.kt:3 box:
// TestKt:4: // test.kt:4 box:
// TestKt:5: a:int=1:int // test.kt:5 box: a:int=1:int
// TestKt:6: a:int=0:int // test.kt:6 box: a:int=0:int
// TestKt:7: // test.kt:7 box:
// TestKt:8: e:java.lang.Throwable=java.lang.ArithmeticException // test.kt:8 box: e:java.lang.Throwable=java.lang.ArithmeticException
// TestKt:10: // test.kt:10 box:
+8 -9
View File
@@ -8,12 +8,11 @@ fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:6: // test.kt:6 box:
// someClass:3: a:double=1.0:double, b:double=2.0:double // test.kt:3 <init>: a:double=1.0:double, b:double=2.0:double
// TestKt:6: // test.kt:6 box:
// TestKt:7: a:someClass=someClass // test.kt:7 box: a:someClass=someClass
// someClass:3: a:double=1.0:double, b:double=3.0:double // test.kt:3 <init>: a:double=1.0:double, b:double=3.0:double
// someClass.copy(double, double)+9: a:double=1.0:double, b:double=3.0:double // test.kt:-1 copy: a:double=1.0:double, b:double=3.0:double
// someClass.copy$default(someClass, double, double, int, java.lang.Object)+30: // test.kt:7 box: a:someClass=someClass
// TestKt:7: a:someClass=someClass // test.kt:8 box: a:someClass=someClass, b:someClass=someClass
// TestKt:8: a:someClass=someClass, b:someClass=someClass
@@ -11,9 +11,9 @@ fun box() {
} }
// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: JVM_IR
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:6: // test.kt:6 box:
// TestKt:8: map:java.util.Map=java.util.Collections$SingletonMap // test.kt:8 box: map:java.util.Map=java.util.Collections$SingletonMap
// TestKt:7: map:java.util.Map=java.util.Collections$SingletonMap // test.kt:7 box: map:java.util.Map=java.util.Collections$SingletonMap
// TestKt:9: map:java.util.Map=java.util.Collections$SingletonMap, a:java.lang.String="1":java.lang.String, b:java.lang.String="23":java.lang.String // test.kt:9 box: map:java.util.Map=java.util.Collections$SingletonMap, a:java.lang.String="1":java.lang.String, b:java.lang.String="23":java.lang.String
// TestKt:7: map:java.util.Map=java.util.Collections$SingletonMap // test.kt:7 box: map:java.util.Map=java.util.Collections$SingletonMap
// TestKt:11: map:java.util.Map=java.util.Collections$SingletonMap // test.kt:11 box: map:java.util.Map=java.util.Collections$SingletonMap
@@ -7,14 +7,13 @@ fun foo(a: A, block: (A) -> String): String = block(a)
fun box() { fun box() {
foo(A("O", 123)) { (x, y) -> x + y } foo(A("O", 123)) { (x, y) -> x + y }
} }
// IGNORE_BACKEND: JVM_IR
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:8: // test.kt:8 box:
// A:3: x:java.lang.String="O":java.lang.String, y:int=123:int // test.kt:3 <init>: x:java.lang.String="O":java.lang.String, y:int=123:int
// TestKt:8: // test.kt:8 box:
// TestKt:5: a:A=A, block:kotlin.jvm.functions.Function1=TestKt$box$1 // test.kt:5 foo: a:A=A, block:kotlin.jvm.functions.Function1=TestKt$box$1
// TestKt$box$1:8: $dstr$x$y:A=A // test.kt:8 invoke: $dstr$x$y:A=A
// TestKt$box$1.invoke(java.lang.Object)+8: // test.kt:5 foo: a:A=A, block:kotlin.jvm.functions.Function1=TestKt$box$1
// TestKt:5: a:A=A, block:kotlin.jvm.functions.Function1=TestKt$box$1 // test.kt:8 box:
// TestKt:8: // test.kt:9 box:
// TestKt:9:
+8 -8
View File
@@ -11,11 +11,11 @@ fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:8: // test.kt:8 box:
// A:2: // test.kt:2 <init>:
// TestKt:8: // test.kt:8 box:
// TestKt:9: a:A=A // test.kt:9 box: a:A=A
// TestKt:4: a:A=A, this_$iv:A=A, $i$f$getS:int=0:int // test.kt:4 box: a:A=A, this_$iv:A=A, $i$f$getS:int=0:int
// TestKt:9: a:A=A // test.kt:9 box: a:A=A
// TestKt:10: a:A=A, y:int=1:int // test.kt:10 box: a:A=A, y:int=1:int
// TestKt:11: a:A=A, y:int=2:int // test.kt:11 box: a:A=A, y:int=2:int
+5 -7
View File
@@ -10,10 +10,8 @@ fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:9: // test.kt:9 box:
// C:3: // test.kt:3 <init>:
// TestKt:9: // test.kt:9 box:
// C:4: // test.kt:5 foo: firstParam:int=4:int, secondParam:java.lang.String="":java.lang.String
// C:5: firstParam:int=4:int, secondParam:java.lang.String="":java.lang.String // test.kt:10 box:
// C:4:
// TestKt:10:
+4 -4
View File
@@ -10,7 +10,7 @@ fun box() {
} }
// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: JVM_IR
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:9: // test.kt:9 box:
// TestKt:4: // test.kt:4 foo:
// TestKt:6: $fun$bar$1:TestKt$foo$1=TestKt$foo$1 // test.kt:6 foo: $fun$bar$1:TestKt$foo$1=TestKt$foo$1
// TestKt:10: // test.kt:10 box:
@@ -8,6 +8,6 @@ fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:7: // test.kt:7 box:
// TestKt:4: $this$test:java.lang.String="OK":java.lang.String // test.kt:4 test: $this$test:java.lang.String="OK":java.lang.String
// TestKt:8: // test.kt:8 box:
+2 -2
View File
@@ -6,5 +6,5 @@ suspend fun box() {
} }
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:5: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation // test.kt:5 box: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// TestKt:6: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation, x:int=1:int // test.kt:6 box: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation, x:int=1:int
@@ -0,0 +1,52 @@
// WITH_RUNTIME
// WITH_COROUTINES
// FILE: test.kt
class A {
operator fun component1() = "O"
operator fun component2(): String = throw RuntimeException("fail 0")
operator fun component3() = "K"
}
suspend fun foo(a: A, block: suspend (A) -> String): String = block(a)
suspend fun box() = foo(A()) { (x_param, _, y_param) ->
x_param + y_param
}
// Parameters (including anonymous destructuring parameters) are moved to fields in the Continuation class for the suspend lambda class.
// However, in non-IR, the fields are first stored in local variables, and they are not read directly (even for destructuring components).
// In IR, the fields are directly read from.
// METHOD : UnderscoreNamesKt$test$2.invokeSuspend(Ljava/lang/Object;)Ljava/lang/Object;
// JVM_TEMPLATES
// VARIABLE : NAME=x_param TYPE=Ljava/lang/String; INDEX=3
// VARIABLE : NAME=y_param TYPE=Ljava/lang/String; INDEX=4
// VARIABLE : NAME=this TYPE=LUnderscoreNamesKt$test$2; INDEX=0
// VARIABLE : NAME=$result TYPE=Ljava/lang/Object; INDEX=1
// JVM_IR_TEMPLATES
// VARIABLE : NAME=x_param TYPE=Ljava/lang/String; INDEX=2
// VARIABLE : NAME=y_param TYPE=Ljava/lang/String; INDEX=3
// VARIABLE : NAME=this TYPE=LUnderscoreNamesKt$test$2; INDEX=0
// VARIABLE : NAME=$result TYPE=Ljava/lang/Object; INDEX=1
// IGNORE_BACKEND: JVM_IR
// LOCAL VARIABLES
// test.kt:12 box: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// test.kt:4 <init>:
// test.kt:12 box: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// test.kt:10 foo: a:A=A, block:kotlin.jvm.functions.Function2=TestKt$box$2, $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// CoroutineUtil.kt:28 getContext:
// test.kt:-1 <init>:
// test.kt:-1 create: value:java.lang.Object=A, completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// test.kt:-1 invoke:
// test.kt:12 invokeSuspend:
// test.kt:5 component1:
// test.kt:12 invokeSuspend: $result:java.lang.Object=kotlin.Unit, $dstr$x_param$_u24__u24$y_param:A=A
// test.kt:7 component3:
// test.kt:12 invokeSuspend: $result:java.lang.Object=kotlin.Unit, $dstr$x_param$_u24__u24$y_param:A=A
// test.kt:13 invokeSuspend: $result:java.lang.Object=kotlin.Unit, x_param:java.lang.String="O":java.lang.String, y_param:java.lang.String="K":java.lang.String
// test.kt:-1 invoke:
// test.kt:10 foo: a:A=A, block:kotlin.jvm.functions.Function2=TestKt$box$2, $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
// test.kt:14 box: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
+17 -24
View File
@@ -23,27 +23,20 @@ fun box() {
} }
// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: JVM_IR
// LOCAL VARIABLES // LOCAL VARIABLES
// TestKt:11: // test.kt:11 box:
// A:3: // test.kt:3 <init>: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char
// A:3: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char // test.kt:11 box:
// A:3: // test.kt:5 foo: a:A=A, block:kotlin.jvm.functions.Function3=TestKt$box$1
// TestKt:11: // test.kt:14 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int
// TestKt:5: a:A=A, block:kotlin.jvm.functions.Function3=TestKt$box$1 // test.kt:3 <init>: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char
// TestKt$box$1:14: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int // test.kt:14 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char
// A:3: // test.kt:15 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char
// A:3: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char // test.kt:3 <init>: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char
// A:3: // test.kt:15 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char
// TestKt$box$1:14: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char // test.kt:17 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char
// TestKt$box$1:15: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char // test.kt:7 getArrayOfA:
// A:3: // test.kt:17 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char
// A:3: x:double=1.0:double, y:java.lang.String="":java.lang.String, z:char=0:char // test.kt:21 invoke: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char
// A:3: // test.kt:5 foo: a:A=A, block:kotlin.jvm.functions.Function3=TestKt$box$1
// TestKt$box$1:15: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char // test.kt:11 box:
// TestKt$box$1:17: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char // test.kt:23 box:
// TestKt:7:
// TestKt$box$1:17: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char
// TestKt$box$1:21: $dstr$x$_u24__u24$y:A=A, $noName_1:java.lang.String="":java.lang.String, w:int=1:int, x:double=1.0:double, y:char=0:char, a:double=1.0:double, c:char=0:char, _:java.lang.String="":java.lang.String, d:char=0:char
// TestKt$box$1.invoke(java.lang.Object, java.lang.Object, java.lang.Object)+19:
// TestKt:5: a:A=A, block:kotlin.jvm.functions.Function3=TestKt$box$1
// TestKt:11:
// TestKt:23:
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.SystemInfo
import com.intellij.util.PathUtil import com.intellij.util.PathUtil
import com.intellij.util.SystemProperties import com.intellij.util.SystemProperties
import com.sun.jdi.AbsentInformationException import com.sun.jdi.AbsentInformationException
import com.sun.jdi.Location
import com.sun.jdi.VirtualMachine import com.sun.jdi.VirtualMachine
import com.sun.jdi.event.* import com.sun.jdi.event.*
import com.sun.jdi.request.EventRequest import com.sun.jdi.request.EventRequest
@@ -266,6 +267,34 @@ abstract class AbstractDebugTest : CodegenTestCase() {
checkResult(wholeFile, loggedItems) checkResult(wholeFile, loggedItems)
} }
fun Location.formatAsExpectation(): String {
val synthetic = if (method().isSynthetic) " (synthetic)" else ""
return "${sourceName()}:${lineNumber()} ${method().name()}$synthetic"
}
/*
Compresses runs of the same, linenumber-less location in the log:
specifically removes locations without linenumber, that would otherwise
print as byte offsets. This avoids overspecifying code generation
strategy in debug tests.
*/
fun <T> compressRunsWithoutLinenumber(loggedItems: List<T>, getLocation: (T) -> Location): List<T> {
if (loggedItems.isEmpty()) return listOf()
val logIterator = loggedItems.iterator()
var currentItem = logIterator.next()
val result = mutableListOf(currentItem)
for (logItem in logIterator) {
if (getLocation(currentItem).lineNumber() != -1 || getLocation(currentItem).formatAsExpectation() != getLocation(logItem).formatAsExpectation()) {
result.add(logItem)
currentItem = logItem
}
}
return result
}
abstract fun storeStep(loggedItems: ArrayList<Any>, event: Event) abstract fun storeStep(loggedItems: ArrayList<Any>, event: Event)
abstract fun checkResult(wholeFile: File, loggedItems: List<Any>) abstract fun checkResult(wholeFile: File, loggedItems: List<Any>)
@@ -72,19 +72,24 @@ abstract class AbstractLocalVariableTest : AbstractDebugTest() {
} }
} }
data class LVTStep(
val location : Location,
val visibleVars: Collection<LocalVariableRecord>
)
override fun storeStep(loggedItems: ArrayList<Any>, event: Event) { override fun storeStep(loggedItems: ArrayList<Any>, event: Event) {
waitUntil { (event as LocatableEvent).thread().isSuspended } val locatableEvent = event as LocatableEvent
val frame = (event as LocatableEvent).thread().frame(0) waitUntil { locatableEvent.thread().isSuspended }
try { val location = locatableEvent.location()
val visibleVars = frame if (location.method().isSynthetic) return
.visibleVariables() val frame = locatableEvent.thread().frame(0)
.map { variable -> toRecord(frame, variable) } val visibleVars = try {
.joinToString(", ") frame.visibleVariables().map { variable -> toRecord(frame, variable) }
loggedItems.add("${event.location()}: $visibleVars".trim())
} catch (e: AbsentInformationException) { } catch (e: AbsentInformationException) {
// LVT Completely absent - not distinguished from an empty table // LVT Completely absent - not distinguished from an empty table
loggedItems.add("${event.location()}:".trim()) listOf()
} }
loggedItems.add(LVTStep(location, visibleVars))
} }
override fun checkResult(wholeFile: File, loggedItems: List<Any>) { override fun checkResult(wholeFile: File, loggedItems: List<Any>) {
@@ -109,11 +114,14 @@ abstract class AbstractLocalVariableTest : AbstractDebugTest() {
continue continue
} }
if (currentBackend == TargetBackend.ANY || currentBackend == backend) { if (currentBackend == TargetBackend.ANY || currentBackend == backend) {
expectedLocalVariables.add(line.drop(3)) expectedLocalVariables.add(line)
} }
} }
val actualLocalVariables = loggedItems.joinToString("\n") val compressedLog = compressRunsWithoutLinenumber(loggedItems as List<LVTStep>, LVTStep::location)
val actualLocalVariables = compressedLog.joinToString("\n") {
"// ${it.location.formatAsExpectation()}: ${it.visibleVars.joinToString(", ")}".trim()
}
TestCase.assertEquals(expectedLocalVariables.joinToString("\n"), actualLocalVariables) TestCase.assertEquals(expectedLocalVariables.joinToString("\n"), actualLocalVariables)
} }
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.codegen.debugInformation
import com.sun.jdi.VirtualMachine import com.sun.jdi.VirtualMachine
import com.sun.jdi.event.Event import com.sun.jdi.event.Event
import com.sun.jdi.event.LocatableEvent import com.sun.jdi.event.LocatableEvent
import junit.framework.TestCase
import org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile import org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
import org.junit.AfterClass import org.junit.AfterClass
@@ -57,18 +56,14 @@ abstract class AbstractSteppingTest : AbstractDebugTest() {
val lines = wholeFile.readLines() val lines = wholeFile.readLines()
val forceStepInto = lines.any { it.startsWith(FORCE_STEP_INTO_MARKER) } val forceStepInto = lines.any { it.startsWith(FORCE_STEP_INTO_MARKER) }
val actualLineNumbers = loggedItems val actualLineNumbers = compressRunsWithoutLinenumber(loggedItems as List<LocatableEvent>, LocatableEvent::location)
.filter { .filter {
val location = (it as LocatableEvent).location() val location = it.location()
// Ignore synthetic code with no line number information // Ignore synthetic code with no line number information
// unless force step into behavior is requested. // unless force step into behavior is requested.
forceStepInto || !location.method().isSynthetic forceStepInto || !location.method().isSynthetic
} }
.map { event -> .map { "// ${it.location().formatAsExpectation()}" }
val location = (event as LocatableEvent).location()
val synthetic = if (location.method().isSynthetic) " (synthetic)" else ""
"// ${location.sourceName()}:${location.lineNumber()} ${location.method().name()}$synthetic"
}
val actualLineNumbersIterator = actualLineNumbers.iterator() val actualLineNumbersIterator = actualLineNumbers.iterator()
val lineIterator = lines.iterator() val lineIterator = lines.iterator()
@@ -103,5 +103,11 @@ public class IrLocalVariableTestGenerated extends AbstractIrLocalVariableTest {
public void testSimple() throws Exception { public void testSimple() throws Exception {
runTest("compiler/testData/debug/localVariables/suspend/simple.kt"); runTest("compiler/testData/debug/localVariables/suspend/simple.kt");
} }
@Test
@TestMetadata("underscoreNames.kt")
public void testUnderscoreNames() throws Exception {
runTest("compiler/testData/debug/localVariables/suspend/underscoreNames.kt");
}
} }
} }
@@ -103,5 +103,11 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest {
public void testSimple() throws Exception { public void testSimple() throws Exception {
runTest("compiler/testData/debug/localVariables/suspend/simple.kt"); runTest("compiler/testData/debug/localVariables/suspend/simple.kt");
} }
@Test
@TestMetadata("underscoreNames.kt")
public void testUnderscoreNames() throws Exception {
runTest("compiler/testData/debug/localVariables/suspend/underscoreNames.kt");
}
} }
} }