Skip to content

Commit 8d8745c

Browse files
committed
Introduce mechanism to produce a DebugProbesKt.bin and verify them against golden value
1 parent fada750 commit 8d8745c

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

DebugProbesKt.class

1.69 KB
Binary file not shown.

integration-testing/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ sourceSets {
3333
}
3434
}
3535

36+
compileDebugAgentTestKotlin {
37+
kotlinOptions {
38+
freeCompilerArgs += ["-Xallow-kotlin-package"]
39+
}
40+
}
41+
3642
task npmTest(type: Test) {
3743
def sourceSet = sourceSets.npmTest
3844
environment "projectRoot", project.rootDir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
5+
package kotlin.coroutines.jvm.internal
6+
7+
import kotlinx.coroutines.debug.internal.*
8+
import kotlin.coroutines.*
9+
10+
internal fun <T> probeCoroutineCreated(completion: Continuation<T>): Continuation<T> = DebugProbesImpl.probeCoroutineCreated(completion)
11+
12+
internal fun probeCoroutineResumed(frame: Continuation<*>) = DebugProbesImpl.probeCoroutineResumed(frame)
13+
14+
internal fun probeCoroutineSuspended(frame: Continuation<*>) = DebugProbesImpl.probeCoroutineSuspended(frame)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
import org.junit.Test
5+
import kotlin.test.*
6+
7+
/*
8+
* This is intentionally put here instead of coreAgentTest to avoid accidental classpath replacing
9+
* and ruining core agent test.
10+
*/
11+
class PrecompiledDebugProbesTest {
12+
13+
@Test
14+
fun testClassFileContent() {
15+
val clz = Class.forName("kotlin.coroutines.jvm.internal.DebugProbesKt")
16+
val className: String = clz.getName()
17+
val classFileResourcePath = className.replace(".", "/") + ".class"
18+
val stream = clz.classLoader.getResourceAsStream(classFileResourcePath)!!
19+
val array = stream.readBytes()
20+
val binFile = clz.classLoader.getResourceAsStream("DebugProbesKt.bin")!!
21+
val binContent = binFile.readBytes()
22+
assertTrue(array.contentEquals(binContent))
23+
}
24+
25+
private fun diffpos(a: ByteArray, b: ByteArray, typeLenght: Int): Int {
26+
if (a.size == b.size) {
27+
for (i in a.indices) {
28+
if (a[i] != b[i]) {
29+
println(i)
30+
}
31+
}
32+
}
33+
return -1
34+
}
35+
}
Binary file not shown.

kotlinx-coroutines-core/jvm/src/debug/AgentPremain.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ internal object AgentPremain {
4141
* DebugProbesKt.bin contains `kotlin.coroutines.jvm.internal.DebugProbesKt` class
4242
* with method bodies that delegate all calls directly to their counterparts in
4343
* kotlinx.coroutines.debug.DebugProbesImpl. This is done to avoid classfile patching
44-
* on the fly (-> get rid of ASM dependency)
44+
* on the fly (-> get rid of ASM dependency).
45+
* You can verify its content either by using javap on it or looking at out integration test module.
4546
*/
4647
return loader.getResourceAsStream("DebugProbesKt.bin").readBytes()
4748
}

0 commit comments

Comments
 (0)