Remove :compiler:tests-common-jvm6 project and JvmTarget6OnBaseJvm tests

This commit is contained in:
Abduqodiri Qurbonzoda
2022-07-12 11:49:28 +03:00
parent de775ad728
commit cf44753aed
17 changed files with 61 additions and 432 deletions
@@ -14,7 +14,7 @@ import kotlin.contracts.contract
*/ */
object KtAssert { object KtAssert {
@JvmStatic @JvmStatic
fun fail(message: String) { fun fail(message: String): Nothing {
throw AssertionError(message) throw AssertionError(message)
} }
@@ -1,18 +0,0 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
project.updateJvmTarget("1.6") // Should this project be removed altogether ?
dependencies {
api(kotlinStdlib())
testApi(project(":kotlin-test:kotlin-test-jvm"))
}
sourceSets {
"main" { }
"test" { projectDefault() }
}
testsJar {}
@@ -1,24 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.test.clientserver
enum class MessageHeader {
NEW_TEST,
CLASS_PATH,
RESULT,
ERROR
}
@@ -1,182 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.test.clientserver
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.lang.reflect.Method
import java.net.ServerSocket
import java.net.Socket
import java.net.URL
import java.net.URLClassLoader
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
private fun ClassLoader.loadClassOrNull(name: String): Class<*>? =
try {
loadClass(name)
} catch (e: ClassNotFoundException) {
null
}
private fun Class<*>.getMethodOrNull(name: String, vararg parameterTypes: Class<*>): Method? =
try {
getMethod(name, *parameterTypes)
} catch (e: NoSuchMethodException) {
null
}
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> =
classLoader.loadClassOrNull(className) ?: error("No class file was generated for: $className")
fun getBoxMethodOrNull(aClass: Class<*>): Method? =
aClass.getMethodOrNull("box")
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.Continuation")?.let { aClass.getMethodOrNull("box", it) }
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.experimental.Continuation")?.let { aClass.getMethodOrNull("box", it) }
fun runBoxMethod(method: Method): String? {
if (method.parameterTypes.isEmpty()) {
return method.invoke(null) as? String
}
val emptyContinuationClass = method.declaringClass.classLoader.loadClass("helpers.ResultContinuation")
val emptyContinuation = emptyContinuationClass.declaredConstructors.single().newInstance()
val result = method.invoke(null, emptyContinuation)
val resultAfterSuspend = emptyContinuationClass.getField("result").get(emptyContinuation)
return (resultAfterSuspend ?: result) as? String
}
//Use only JDK 1.6 compatible api
object TestProcessServer {
const val DEBUG_TEST = "--debugTest"
private val executor = Executors.newFixedThreadPool(1)!!
@Volatile
private var isProcessingTask = true
@Volatile
private var lastTime = System.currentTimeMillis()
private val scheduler = Executors.newScheduledThreadPool(1)
private lateinit var handler: ScheduledFuture<*>
private lateinit var serverSocket: ServerSocket
private var suppressOutput = false
private var allocatePort = false
@JvmStatic
fun main(args: Array<String>) {
if (args[0] == DEBUG_TEST) {
suppressOutput = true
allocatePort = true
}
val portNumber = if (allocatePort) 0 else args[0].toInt()
println("Starting server on port $portNumber...")
val serverSocket = ServerSocket(portNumber)
println("...server started on port ${serverSocket.localPort}")
scheduleShutdownProcess()
try {
while (true) {
lastTime = System.currentTimeMillis()
isProcessingTask = false
val clientSocket = serverSocket.accept()
isProcessingTask = true
println("Socket established...")
executor.execute(ServerTest(clientSocket, suppressOutput))
}
}
finally {
handler.cancel(false)
scheduler.shutdown()
serverSocket.close()
println("Server stopped!")
}
}
private fun scheduleShutdownProcess() {
handler = scheduler.scheduleAtFixedRate({
if (!isProcessingTask && (System.currentTimeMillis() - lastTime) >= 60 * 1000 /*60 sec*/) {
println("Stopping server...")
serverSocket.close()
}
}, 60, 60, TimeUnit.SECONDS)
}
private fun printlnTest(text: String) {
if (!suppressOutput) {
println(text)
}
}
}
private class ServerTest(val clientSocket: Socket, val suppressOutput: Boolean) : Runnable {
private lateinit var className: String
private lateinit var testMethod: String
override fun run() {
val input = ObjectInputStream(clientSocket.getInputStream())
val output = if (suppressOutput) null else ObjectOutputStream(clientSocket.getOutputStream())
try {
var message = input.readObject() as MessageHeader
assert(message == MessageHeader.NEW_TEST, { "New test marker missed, but $message received" })
className = input.readObject() as String
testMethod = input.readObject() as String
println("Preparing to execute test $className")
message = input.readObject() as MessageHeader
assert(message == MessageHeader.CLASS_PATH, { "Class path marker missed, but $message received" })
@Suppress("UNCHECKED_CAST")
val classPath = input.readObject() as Array<URL>
val result = executeTest(URLClassLoader(classPath, JDK_EXT_JARS_CLASS_LOADER))
output?.writeObject(MessageHeader.RESULT)
output?.writeObject(result)
} catch (e: Throwable) {
output?.writeObject(MessageHeader.ERROR)
output?.writeObject(e)
} finally {
output?.close()
input.close()
clientSocket.close()
}
}
fun executeTest(classLoader: ClassLoader): String {
val clazz = getGeneratedClass(classLoader, className)
return runBoxMethod(getBoxMethodOrNull(clazz)!!) as String
}
companion object {
//Required for org.jetbrains.kotlin.codegen.BlackBoxCodegenTestGenerated.FullJdk#testClasspath
val JDK_EXT_JARS_CLASS_LOADER: ClassLoader
init {
val javaHome = System.getProperty("java.home")
val extFolder = File(javaHome + "/lib/ext/")
println(extFolder.canonicalPath)
val listFiles = extFolder.listFiles()
val additionalJars = listFiles?.filter { it.name.endsWith(".jar") }?.map { it.toURI().toURL() } ?: emptyList()
JDK_EXT_JARS_CLASS_LOADER = URLClassLoader(additionalJars.toTypedArray(), null)
}
}
}
@@ -23,7 +23,6 @@ dependencies {
testApi(projectTests(":compiler:test-infrastructure")) testApi(projectTests(":compiler:test-infrastructure"))
testApi(projectTests(":compiler:test-infrastructure-utils")) testApi(projectTests(":compiler:test-infrastructure-utils"))
testApi(projectTests(":compiler:tests-compiler-utils")) testApi(projectTests(":compiler:tests-compiler-utils"))
testApi(projectTests(":compiler:tests-common-jvm6"))
/* /*
* Actually those dependencies are needed only at runtime, but they * Actually those dependencies are needed only at runtime, but they
-1
View File
@@ -52,7 +52,6 @@ dependencies {
testApi(projectTests(":generators:test-generator")) testApi(projectTests(":generators:test-generator"))
testApi(projectTests(":compiler:tests-compiler-utils")) testApi(projectTests(":compiler:tests-compiler-utils"))
testApi(project(":kotlin-test:kotlin-test-jvm")) testApi(project(":kotlin-test:kotlin-test-jvm"))
testApi(projectTests(":compiler:tests-common-jvm6"))
testApi(project(":kotlin-scripting-compiler-impl")) testApi(project(":kotlin-scripting-compiler-impl"))
testApi(projectTests(":compiler:test-infrastructure-utils")) testApi(projectTests(":compiler:test-infrastructure-utils"))
testApi(commonDependency("junit:junit")) testApi(commonDependency("junit:junit"))
@@ -22,8 +22,8 @@ import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import static org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile; import static org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull; import static org.jetbrains.kotlin.codegen.CodegenTestUtilsKt.getBoxMethodOrNull;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass; import static org.jetbrains.kotlin.codegen.CodegenTestUtilsKt.getGeneratedClass;
@ObsoleteTestInfrastructure(replacer = "org.jetbrains.kotlin.test.runners.codegen.AbstractBlackBoxCodegenTest") @ObsoleteTestInfrastructure(replacer = "org.jetbrains.kotlin.test.runners.codegen.AbstractBlackBoxCodegenTest")
public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase { public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
@@ -19,12 +19,10 @@ import org.jetbrains.kotlin.TestsCompilerError;
import org.jetbrains.kotlin.TestsCompiletimeError; import org.jetbrains.kotlin.TestsCompiletimeError;
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection; import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection;
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil; import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil;
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
import org.jetbrains.kotlin.cli.common.output.OutputUtilsKt; import org.jetbrains.kotlin.cli.common.output.OutputUtilsKt;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace; import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace;
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.config.CompilerConfiguration;
@@ -54,7 +52,7 @@ import java.util.stream.Collectors;
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo; import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*; import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls; import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.*; import static org.jetbrains.kotlin.codegen.CodegenTestUtilsKt.*;
import static org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar; import static org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar;
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> { public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen
import java.lang.reflect.Method
private fun ClassLoader.loadClassOrNull(name: String): Class<*>? =
try {
loadClass(name)
} catch (e: ClassNotFoundException) {
null
}
private fun Class<*>.getMethodOrNull(name: String, vararg parameterTypes: Class<*>): Method? =
try {
getMethod(name, *parameterTypes)
} catch (e: NoSuchMethodException) {
null
}
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> =
classLoader.loadClassOrNull(className) ?: error("No class file was generated for: $className")
fun getBoxMethodOrNull(aClass: Class<*>): Method? =
aClass.getMethodOrNull("box")
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.Continuation")?.let { aClass.getMethodOrNull("box", it) }
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.experimental.Continuation")?.let { aClass.getMethodOrNull("box", it) }
fun runBoxMethod(method: Method): String? {
if (method.parameterTypes.isEmpty()) {
return method.invoke(null) as? String
}
val emptyContinuationClass = method.declaringClass.classLoader.loadClass("helpers.ResultContinuation")
val emptyContinuation = emptyContinuationClass.declaredConstructors.single().newInstance()
val result = method.invoke(null, emptyContinuation)
val resultAfterSuspend = emptyContinuationClass.getField("result").get(emptyContinuation)
return (resultAfterSuspend ?: result) as? String
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.test.clientserver
enum class MessageHeader {
NEW_TEST,
CLASS_PATH,
RESULT,
ERROR
}
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.test.clientserver package org.jetbrains.kotlin.test.clientserver
@@ -21,7 +10,7 @@ import java.io.ObjectInputStream
import java.io.ObjectOutputStream import java.io.ObjectOutputStream
import java.net.Socket import java.net.Socket
import java.net.URL import java.net.URL
import kotlin.test.fail import org.jetbrains.kotlin.test.KtAssert.fail
class TestProxy(val serverPort: Int, val testClass: String, val classPath: List<URL>) { class TestProxy(val serverPort: Int, val testClass: String, val classPath: List<URL>) {
@@ -3,8 +3,6 @@ plugins {
id("jps-compatible") id("jps-compatible")
} }
val testJvm6ServerRuntime by configurations.creating
dependencies { dependencies {
testApi(projectTests(":compiler")) testApi(projectTests(":compiler"))
testApi(projectTests(":compiler:test-infrastructure")) testApi(projectTests(":compiler:test-infrastructure"))
@@ -16,7 +14,6 @@ dependencies {
testImplementation(intellijCore()) testImplementation(intellijCore())
testRuntimeOnly(project(":kotlin-reflect")) testRuntimeOnly(project(":kotlin-reflect"))
testJvm6ServerRuntime(projectTests(":compiler:tests-common-jvm6"))
} }
sourceSets { sourceSets {
@@ -50,44 +47,16 @@ fun Project.codegenTest(
group = "verification" group = "verification"
} }
// Should the tests with target = 6 be removed ?
codegenTest(
target = 6,
jdk = JdkMajorVersion.JDK_1_8,
jvm = JdkMajorVersion.JDK_1_6.majorVersion.toString()
) {
dependsOn(testJvm6ServerRuntime)
doFirst {
systemProperty("kotlin.test.default.jvm.target", "1.6")
systemProperty("kotlin.test.java.compilation.target", "1.6")
systemProperty(
"JDK_16",
project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_6).get().metadata.installationPath.asFile.absolutePath
)
val port = project.findProperty("kotlin.compiler.codegen.tests.port") ?: "5100"
systemProperty("kotlin.test.box.in.separate.process.port", port)
systemProperty("kotlin.test.box.in.separate.process.server.classpath", testJvm6ServerRuntime.asPath)
}
}
//JDK 8 //JDK 8
codegenTest(target = 6, jdk = JdkMajorVersion.JDK_1_8)
// This is default one and is executed in default build configuration // This is default one and is executed in default build configuration
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_1_8) codegenTest(target = 8, jdk = JdkMajorVersion.JDK_1_8)
//JDK 11 //JDK 11
codegenTest(target = 6, jdk = JdkMajorVersion.JDK_11)
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_11) codegenTest(target = 8, jdk = JdkMajorVersion.JDK_11)
codegenTest(target = 11, jdk = JdkMajorVersion.JDK_11) codegenTest(target = 11, jdk = JdkMajorVersion.JDK_11)
//JDK 17 //JDK 17
codegenTest(target = 6, jdk = JdkMajorVersion.JDK_17)
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_17) codegenTest(target = 8, jdk = JdkMajorVersion.JDK_17)
codegenTest(target = 17, jdk = JdkMajorVersion.JDK_17) { codegenTest(target = 17, jdk = JdkMajorVersion.JDK_17) {
@@ -98,7 +67,6 @@ codegenTest(target = 17, jdk = JdkMajorVersion.JDK_17) {
val mostRecentJdk = JdkMajorVersion.values().last() val mostRecentJdk = JdkMajorVersion.values().last()
//LAST JDK from JdkMajorVersion available on machine //LAST JDK from JdkMajorVersion available on machine
codegenTest(target = 6, jvm = "Last", jdk = mostRecentJdk)
codegenTest(target = 8, jvm = "Last", jdk = mostRecentJdk) codegenTest(target = 8, jvm = "Last", jdk = mostRecentJdk)
codegenTest( codegenTest(
@@ -8,8 +8,6 @@
package org.jetbrains.kotlin.codegen.jdk package org.jetbrains.kotlin.codegen.jdk
import org.jetbrains.kotlin.test.runners.codegen.* import org.jetbrains.kotlin.test.runners.codegen.*
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode
import org.junit.platform.runner.JUnitPlatform import org.junit.platform.runner.JUnitPlatform
import org.junit.platform.suite.api.ExcludeTags import org.junit.platform.suite.api.ExcludeTags
import org.junit.platform.suite.api.IncludeClassNamePatterns import org.junit.platform.suite.api.IncludeClassNamePatterns
@@ -35,23 +33,11 @@ import org.junit.runner.RunWith
@UseTechnicalNames @UseTechnicalNames
abstract class CustomJvmTargetOnJvmBaseTest abstract class CustomJvmTargetOnJvmBaseTest
// JDK 6
@RunOnlyJdk6Test
@Execution(ExecutionMode.SAME_THREAD)
@RunWith(JUnitPlatformRunnerForJdk6::class)
class JvmTarget6OnJvm6 : CustomJvmTargetOnJvmBaseTest()
// JDK 8 // JDK 8
@RunWith(JUnitPlatform::class)
class JvmTarget6OnJvm8 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget8OnJvm8 : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvm8 : CustomJvmTargetOnJvmBaseTest()
// JDK 11 // JDK 11
@RunWith(JUnitPlatform::class)
class JvmTarget6OnJvm11 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget8OnJvm11 : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvm11 : CustomJvmTargetOnJvmBaseTest()
@@ -59,18 +45,12 @@ class JvmTarget8OnJvm11 : CustomJvmTargetOnJvmBaseTest()
class JvmTarget11OnJvm11 : CustomJvmTargetOnJvmBaseTest() class JvmTarget11OnJvm11 : CustomJvmTargetOnJvmBaseTest()
// JDK 15 // JDK 15
@RunWith(JUnitPlatform::class)
class JvmTarget6OnJvm15 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget8OnJvm15 : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvm15 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget15OnJvm15 : CustomJvmTargetOnJvmBaseTest() class JvmTarget15OnJvm15 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class)
class JvmTarget6OnJvm17 : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget8OnJvm17 : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvm17 : CustomJvmTargetOnJvmBaseTest()
@@ -79,9 +59,6 @@ class JvmTarget17OnJvm17 : CustomJvmTargetOnJvmBaseTest()
// LAST JDK from JdkMajorVersion available on machine // LAST JDK from JdkMajorVersion available on machine
@RunWith(JUnitPlatform::class)
class JvmTarget6OnJvmLast : CustomJvmTargetOnJvmBaseTest()
@RunWith(JUnitPlatform::class) @RunWith(JUnitPlatform::class)
class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest()
@@ -1,56 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION")
package org.jetbrains.kotlin.codegen.jdk
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.TestMetadata
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.Description
import org.junit.runner.manipulation.Filter
import org.junit.runner.notification.RunNotifier
import java.io.File
annotation class RunOnlyJdk6Test
class JUnitPlatformRunnerForJdk6(testClass: Class<*>) : JUnitPlatform(testClass) {
init {
if (testClass.getAnnotation(RunOnlyJdk6Test::class.java) != null) {
this.filter(object : Filter() {
override fun shouldRun(description: Description): Boolean {
if (description.isTest) {
@Suppress("NAME_SHADOWING")
val testClass = description.testClass ?: return true
val methodName = description.methodName ?: return true
val testClassAnnotation = testClass.getAnnotation(TestMetadata::class.java) ?: return true
val method = testClass.getMethod(methodName)
val methodAnnotation = method.getAnnotation(TestMetadata::class.java) ?: return true
val path = "${testClassAnnotation.value}/${methodAnnotation.value}"
val fileText = File(path).readText()
return !InTextDirectivesUtils.isDirectiveDefined(fileText, "// JVM_TARGET:") &&
!InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_JDK6")
}
return true
}
override fun describe(): String {
return "skipped on JDK 6"
}
})
}
}
override fun run(notifier: RunNotifier?) {
SeparateJavaProcessHelper.setUp()
try {
super.run(notifier)
} finally {
SeparateJavaProcessHelper.tearDown()
}
}
}
@@ -1,73 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen.jdk
import org.jetbrains.kotlin.codegen.CodegenTestCase
import java.io.File
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
import kotlin.test.assertTrue
object SeparateJavaProcessHelper {
private lateinit var jdkProcess: Process
private val lock = ReentrantLock()
private var counter = 0
fun setUp() {
lock.withLock {
if (counter == 0) {
initJdkProcess()
}
counter += 1
}
}
fun tearDown() {
lock.withLock {
counter -= 1
if (counter == 0) {
destroyJdkProcess()
}
}
}
private fun initJdkProcess() {
println("Configuring JDK6 Test server...")
val jdkPath = System.getProperty("JDK_16") ?: error("JDK_16 is not optional to run this test")
val executable = File(jdkPath, "bin/java").canonicalPath
assert(File(executable).exists()) { "Not a JDK path: $jdkPath"}
val main = "org.jetbrains.kotlin.test.clientserver.TestProcessServer"
val classpath =
System.getProperty("kotlin.test.box.in.separate.process.server.classpath") ?: System.getProperty("java.class.path")
println("Server classpath: $classpath")
val port = CodegenTestCase.BOX_IN_SEPARATE_PROCESS_PORT ?: error("kotlin.test.box.in.separate.process.port is not specified")
val builder = ProcessBuilder(executable, "-cp", classpath, main, port)
builder.inheritIO()
println("Starting JDK 6 server $executable...")
jdkProcess = builder.start()
Thread.sleep(2000)
assertTrue(jdkProcess.isAlive, "Test server process hasn't started")
println("Test server started!")
Runtime.getRuntime().addShutdownHook(object : Thread() {
override fun run() {
destroyJdkProcess()
}
})
}
private fun destroyJdkProcess() {
println("Stopping JDK 6 server...")
if (::jdkProcess.isInitialized) {
jdkProcess.destroy()
}
}
}
@@ -3,7 +3,6 @@ plugins {
} }
val testModules = listOf( val testModules = listOf(
":compiler:tests-common-jvm6",
":compiler:test-infrastructure", ":compiler:test-infrastructure",
":compiler:test-infrastructure-utils", ":compiler:test-infrastructure-utils",
":compiler:tests-compiler-utils", ":compiler:tests-compiler-utils",
-1
View File
@@ -153,7 +153,6 @@ include ":benchmarks",
":compiler:tests-common", ":compiler:tests-common",
":compiler:tests-mutes", ":compiler:tests-mutes",
":compiler:tests-mutes:tc-integration", ":compiler:tests-mutes:tc-integration",
":compiler:tests-common-jvm6",
":compiler:tests-against-klib", ":compiler:tests-against-klib",
":compiler:tests-for-compiler-generator", ":compiler:tests-for-compiler-generator",
":js:js.ast", ":js:js.ast",