Remove hack with targets. Add target for most recent jdk

This commit is contained in:
Mikhael Bogdanov
2019-05-15 11:59:29 +02:00
parent a53fa0dfbf
commit 812b766894
4 changed files with 40 additions and 32 deletions
@@ -31,12 +31,7 @@ enum class JvmTarget(override val description: String) : TargetPlatformVersion {
val bytecodeVersion: Int by lazy { val bytecodeVersion: Int by lazy {
when (this) { when (this) {
JVM_1_6 -> Opcodes.V1_6 JVM_1_6 -> Opcodes.V1_6
JVM_1_8 -> JVM_1_8 -> Opcodes.V1_8
when {
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.10")) -> Opcodes.V9 + 1
java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.1.9")) -> Opcodes.V9
else -> Opcodes.V1_8
}
JVM_9 -> Opcodes.V9 JVM_9 -> Opcodes.V9
JVM_10 -> Opcodes.V9 + 1 JVM_10 -> Opcodes.V9 + 1
JVM_11 -> Opcodes.V9 + 2 JVM_11 -> Opcodes.V9 + 2
@@ -623,12 +623,22 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
} }
private static void setCustomDefaultJvmTarget(CompilerConfiguration configuration) { protected void setCustomDefaultJvmTarget(CompilerConfiguration configuration) {
JvmTarget target = configuration.get(JVMConfigurationKeys.JVM_TARGET); if (DEFAULT_JVM_TARGET != null) {
if (target == null && DEFAULT_JVM_TARGET != null) { JvmTarget customDefaultTarget = JvmTarget.fromString(DEFAULT_JVM_TARGET);
JvmTarget value = JvmTarget.fromString(DEFAULT_JVM_TARGET); assert customDefaultTarget != null : "Can't construct JvmTarget for " + DEFAULT_JVM_TARGET;
assert value != null : "Can't construct JvmTarget for " + DEFAULT_JVM_TARGET; JvmTarget originalTarget = configuration.get(JVMConfigurationKeys.JVM_TARGET);
configuration.put(JVMConfigurationKeys.JVM_TARGET, value); if (originalTarget == null || customDefaultTarget.getBytecodeVersion() > originalTarget.getBytecodeVersion()) {
// It's not safe to substitute target in general
// cause it can affect generated bytecode and original behaviour should be tested somehow.
// Original behaviour testing is perfomed by
//
// codegenTest(target = 6, jvm = "Last", jdk = mostRecentJdk)
// codegenTest(target = 8, jvm = "Last", jdk = mostRecentJdk)
//
// in compiler/tests-different-jdk/build.gradle.kts
configuration.put(JVMConfigurationKeys.JVM_TARGET, customDefaultTarget);
}
} }
} }
+20 -20
View File
@@ -32,18 +32,20 @@ fun Project.codegenTest(
fun Project.codegenTest( fun Project.codegenTest(
target: Int, jvm: String, jdk: String, target: Int, jvm: String, jdk: String,
targetInTestClass: String = "$target",
body: Test.() -> Unit body: Test.() -> Unit
): Test = projectTest("codegenTarget${target}Jvm${jvm}Test") { ): Test = projectTest("codegenTarget${targetInTestClass}Jvm${jvm}Test") {
dependsOn(":dist") dependsOn(":dist")
workingDir = rootDir workingDir = rootDir
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.jdk.JvmTarget${target}OnJvm${jvm}") filter.includeTestsMatching("org.jetbrains.kotlin.codegen.jdk.JvmTarget${targetInTestClass}OnJvm${jvm}")
systemProperty("kotlin.test.default.jvm.target", "${if (target <= 8) "1." else ""}$target")
body() body()
doFirst { doFirst {
val jdkPath = project.findProperty(jdk) ?: error("$jdk is not optional to run this test") val jdkPath = project.findProperty(jdk) ?: error("$jdk is not optional to run this test")
executable = "$jdkPath/bin/java" executable = "$jdkPath/bin/java"
println("Running test with $executable") println("Running tests with $target target and $executable")
} }
group = "verification" group = "verification"
} }
@@ -59,31 +61,29 @@ codegenTest(target = 6, jvm = 6, jdk = "JDK_18") {
systemProperty("kotlin.test.box.in.separate.process.server.classpath", testJvm6ServerRuntime.asPath) systemProperty("kotlin.test.box.in.separate.process.server.classpath", testJvm6ServerRuntime.asPath)
} }
codegenTest(target = 6, jvm = 9) { codegenTest(target = 6, jvm = 9) {}
systemProperty("kotlin.test.default.jvm.target", "1.6")
}
codegenTest(target = 8, jvm = 8) { codegenTest(target = 8, jvm = 8) {}
systemProperty("kotlin.test.default.jvm.target", "1.8")
}
codegenTest(target = 8, jvm = 9) { codegenTest(target = 8, jvm = 9) {}
systemProperty("kotlin.test.default.jvm.target", "1.8")
}
codegenTest(target = 9, jvm = 9) { codegenTest(target = 9, jvm = 9) {}
systemProperty("kotlin.test.default.jvm.target", "1.8")
systemProperty("kotlin.test.substitute.bytecode.1.8.to.1.9", "true")
}
codegenTest(target = 6, jvm = "Last", jdk = JdkMajorVersion.values().last().name) { val mostRecentJdk = JdkMajorVersion.values().last().name
systemProperty("kotlin.test.default.jvm.target", "1.6")
codegenTest(target = 6, jvm = "Last", jdk = mostRecentJdk) {
jvmArgs!!.add( "-XX:-FailOverToOldVerifier") jvmArgs!!.add( "-XX:-FailOverToOldVerifier")
} }
codegenTest(target = 8, jvm = "Last", jdk = JdkMajorVersion.values().last().name) { codegenTest(target = 8, jvm = "Last", jdk = mostRecentJdk) {
systemProperty("kotlin.test.default.jvm.target", "1.8")
jvmArgs!!.add( "-XX:-FailOverToOldVerifier") jvmArgs!!.add( "-XX:-FailOverToOldVerifier")
} }
codegenTest(
mostRecentJdk.substringAfter('_').toInt(),
targetInTestClass = "Last",
jvm = "Last",
jdk = mostRecentJdk
) {}
testsJar() testsJar()
@@ -94,3 +94,6 @@ class JvmTarget6OnJvmLast : CustomJvmTargetOnJvmBaseTest()
@RunWith(SuiteRunnerForCustomJdk::class) @RunWith(SuiteRunnerForCustomJdk::class)
class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest() class JvmTarget8OnJvmLast : CustomJvmTargetOnJvmBaseTest()
@RunWith(SuiteRunnerForCustomJdk::class)
class JvmTargetLastOnJvmLast : CustomJvmTargetOnJvmBaseTest()