• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.io.*
6 import kotlin.test.*
7 
8 /*
9  * This is intentionally put here instead of coreAgentTest to avoid accidental classpath replacing
10  * and ruining core agent test.
11  */
12 class PrecompiledDebugProbesTest {
13 
14     private val overwrite = java.lang.Boolean.getBoolean("overwrite.probes")
15 
16     @Test
testClassFileContentnull17     fun testClassFileContent() {
18         val clz = Class.forName("kotlin.coroutines.jvm.internal.DebugProbesKt")
19         val className: String = clz.getName()
20         val classFileResourcePath = className.replace(".", "/") + ".class"
21         val stream = clz.classLoader.getResourceAsStream(classFileResourcePath)!!
22         val array = stream.readBytes()
23         val binFile = clz.classLoader.getResourceAsStream("DebugProbesKt.bin")!!
24         val binContent = binFile.readBytes()
25         if (overwrite) {
26             val url = clz.classLoader.getResource("DebugProbesKt.bin")!!
27             val base = url.toExternalForm().toString().removePrefix("jar:file:").substringBefore("/build")
28             val probes = File(base, "jvm/resources/DebugProbesKt.bin")
29             FileOutputStream(probes).use { it.write(array) }
30             println("Content was successfully overwritten!")
31         } else {
32             assertTrue(
33                 array.contentEquals(binContent),
34                 "Compiled DebugProbesKt.class does not match the file shipped as a resource in kotlinx-coroutines-core. " +
35                         "Typically it happens because of the Kotlin version update (-> binary metadata). In that case, run the same test with -Poverwrite.probes=true and " +
36                         "ensure that classfile has major version equal to 50 (Java 6 compliance)")
37         }
38     }
39 }