Migrate CodegenJdkCommonTestSuite.kt to gradle

This commit is contained in:
Mikhael Bogdanov
2017-09-27 09:46:39 +02:00
parent 4a0ad54829
commit e7e28419e4
3 changed files with 73 additions and 81 deletions
+41 -3
View File
@@ -85,8 +85,12 @@ evaluationDependsOn(":compiler:tests-common-jvm6")
fun Project.codegenTest(taskName: String, jdk: String, body: Test.() -> Unit): Test = projectTest(taskName) {
dependsOn(*testDistProjects.map { "$it:dist" }.toTypedArray())
workingDir = rootDir
environment("TEST_SERVER_CLASSES_DIRS", project(":compiler:tests-common-jvm6").the<JavaPluginConvention>().sourceSets.getByName("main").output.classesDirs.asPath)
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CodegenJdkCommonTestSuite*")
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxCodegenTestGenerated*")
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxInlineCodegenTestGenerated*")
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CompileKotlinAgainstInlineKotlinTestGenerated*")
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CompileKotlinAgainstKotlinTestGenerated*")
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxAgainstJavaCodegenTestGenerated*")
if (jdk == "JDK_9") {
jvmArgs = listOf("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED")
@@ -105,9 +109,43 @@ fun Project.codegenTest(taskName: String, jdk: String, body: Test.() -> Unit): T
}
codegenTest("codegen-target6-jvm6-test", "JDK_18") {
dependsOn(":compiler:tests-common-jvm6:build")
//TODO make port flexible
val port = "5100"
var jdkProcess: Process? = null
doFirst {
logger.info("Configuring JDK 6 server...")
val jdkPath = project.property("JDK_16") ?: error("JDK_16 is not optional to run this test")
val executable = "$jdkPath/bin/java"
val main = "org.jetbrains.kotlin.test.clientserver.TestProcessServer"
val classpath = getSourceSetsFrom(":compiler:tests-common-jvm6")["main"].output.asPath + ":" +
getSourceSetsFrom(":kotlin-stdlib")["main"].output.asPath + ":" +
getSourceSetsFrom(":kotlin-stdlib")["builtins"].output.asPath + ":" +
getSourceSetsFrom(":kotlin-test:kotlin-test-jvm")["main"].output.asPath
logger.debug("Server classpath: $classpath")
val builder = ProcessBuilder(executable, "-cp", classpath, main, port)
builder.directory(rootDir)
builder.inheritIO()
builder.redirectErrorStream(true)
logger.info("Starting JDK 6 server $executable")
jdkProcess = builder.start()
}
systemProperty("kotlin.test.default.jvm.target", "1.6")
systemProperty("kotlin.test.java.compilation.target", "1.6")
systemProperty("kotlin.test.box.in.separate.process.port", "5100")
systemProperty("kotlin.test.box.in.separate.process.port", port)
doLast {
logger.info("Stopping JDK 6 server...")
jdkProcess?.destroy()
}
}
codegenTest("codegen-target6-jvm9-test", "JDK_9") {
@@ -25,6 +25,8 @@ 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
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> {
try {
@@ -47,7 +49,19 @@ fun getBoxMethodOrNull(aClass: Class<*>): Method? {
//Use only JDK 1.6 compatible api
object TestProcessServer {
val executor = Executors.newFixedThreadPool(1)!!
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
@JvmStatic
fun main(args: Array<String>) {
@@ -55,17 +69,34 @@ object TestProcessServer {
println("Starting server on port $portNumber...")
val serverSocket = ServerSocket(portNumber)
sheduleShutdownProcess()
try {
while (true) {
lastTime = System.currentTimeMillis()
isProcessingTask = false
val clientSocket = serverSocket.accept()
isProcessingTask = true
println("Socket established...")
executor.execute(ServerTest(clientSocket))
}
}
finally {
handler.cancel(false)
scheduler.shutdown()
serverSocket.close()
println("Server stopped!")
}
}
private fun sheduleShutdownProcess() {
handler = scheduler.scheduleAtFixedRate({
if (!isProcessingTask && (System.currentTimeMillis() - lastTime) >= 60 * 1000 /*60 sec*/) {
println("Stopping server...")
serverSocket.close()
}
}, 60, 60, TimeUnit.SECONDS)
}
}
private class ServerTest(val clientSocket: Socket) : Runnable {
@@ -1,77 +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.codegen
import org.jetbrains.kotlin.test.clientserver.TestProcessServer
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.junit.AfterClass
import org.junit.Assert.assertNotNull
import org.junit.BeforeClass
import org.junit.runner.RunWith
import org.junit.runners.Suite
import java.io.File
/**
* This suite is used to run java codegen tests under jdk 1.6, 1.8 and 9
* with different default targets - 1.6, 1.8, 1.9.
*/
@RunWith(Suite::class)
@Suite.SuiteClasses(
BlackBoxCodegenTestGenerated::class,
BlackBoxInlineCodegenTestGenerated::class,
CompileKotlinAgainstInlineKotlinTestGenerated::class,
CompileKotlinAgainstKotlinTestGenerated::class,
BlackBoxAgainstJavaCodegenTestGenerated::class
)
object CodegenJdkCommonTestSuite {
private var jdkProcess: Process? = null
@BeforeClass
@JvmStatic
fun setUp() {
val boxInSeparateProcessPort = System.getProperty(CodegenTestCase.RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT)
if (boxInSeparateProcessPort != null) {
val classpath = (System.getenv("TEST_SERVER_CLASSES_DIRS") ?: "out/test/tests-common") +
File.pathSeparatorChar +
ForTestCompileRuntime.runtimeJarForTests() +
File.pathSeparatorChar +
ForTestCompileRuntime.kotlinTestJarForTests()
val jdk16 = System.getenv("JDK_16")
assertNotNull(jdk16, "Please specify JDK_16 system property to run codegen test in separate process")
val builder = ProcessBuilder(
jdk16 + "/bin/java", "-cp", classpath,
TestProcessServer::class.java.name, boxInSeparateProcessPort
)
println("Starting separate process to run test: " + builder.command().joinToString())
builder.inheritIO()
builder.redirectErrorStream(true)
jdkProcess = builder.start()
}
}
@AfterClass
@JvmStatic
fun tearDown() {
if (jdkProcess != null) {
println("Stop separate test process")
jdkProcess!!.destroy()
}
}
}