[WIP] Add Compiler Smoke Tests for (suspend) main methods

This commit ports the (parameterless) main integration tests in
`CompilerSmokeTest` to the IR backend. It also includes a simple
suspend main test.

The advanced ones (like `helloAppSuspendParameterlessMain`) are
currently blocked by pending changes to capturing suspend lambdas,
which are underway.
This commit is contained in:
Kristoffer Andersen
2019-11-20 15:49:50 +01:00
committed by Ilmir Usmanov
parent 55aafb3430
commit 5b62c9e54d
29 changed files with 251 additions and 1 deletions
@@ -33,7 +33,6 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin {
object STATIC_INLINE_CLASS_REPLACEMENT : IrDeclarationOriginImpl("STATIC_INLINE_CLASS_REPLACEMENT")
object GENERATED_ASSERTION_ENABLED_FIELD : IrDeclarationOriginImpl("GENERATED_ASSERTION_ENABLED_FIELD", isSynthetic = true)
object GENERATED_EXTENDED_MAIN : IrDeclarationOriginImpl("GENERATED_EXTENDED_MAIN", isSynthetic = true)
object SUSPEND_FUNCTION_VIEW : IrDeclarationOriginImpl("SUSPEND_FUNCTION_VIEW")
object SUSPEND_IMPL_STATIC_FUNCTION : IrDeclarationOriginImpl("SUSPEND_IMPL_STATIC_FUNCTION", isSynthetic = true)
object INTERFACE_COMPANION_PRIVATE_INSTANCE : IrDeclarationOriginImpl("INTERFACE_COMPANION_PRIVATE_INSTANCE", isSynthetic = true)
object POLYMORPHIC_SIGNATURE_INSTANTIATION : IrDeclarationOriginImpl("POLYMORPHIC_SIGNATURE_INSTANTIATION", isSynthetic = true)
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,6 @@
package Hello
fun main(args: kotlin.Array<kotlin.String>) {
args.size
System.out.println("Hello from fully qualified main!")
}
@@ -0,0 +1,4 @@
OUT:
Hello from fully qualified main!
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,5 @@
package Hello
fun main() {
System.out.println("Hello!")
}
@@ -0,0 +1,4 @@
OUT:
Hello!
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,10 @@
package Hello
fun main(args: Array<String>) {
args.size
System.out.println("Hello!")
}
fun main() {
System.out.println("Fail")
}
@@ -0,0 +1,4 @@
OUT:
Hello!
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,5 @@
package Hello
fun main() {
System.out.println("Hello!")
}
@@ -0,0 +1,4 @@
OUT:
Hello!
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,35 @@
package Hello
import kotlin.concurrent.thread
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
@kotlin.jvm.Volatile
private var result = ""
@kotlin.jvm.Volatile
private var callback: Function0<Unit>? = null
suspend fun appendAndSuspend(s: String) {
result += s
suspendCoroutine<Unit> { continuation ->
callback = {
continuation.resume(Unit)
}
}
}
suspend fun main(args: Array<String>) {
thread(isDaemon = true) {
while (true) {
val c = callback
c?.invoke()
Thread.sleep(500)
}
}
appendAndSuspend(args[0])
appendAndSuspend(args[1])
println(result)
callback = null
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,37 @@
@file:JvmMultifileClass
@file:JvmName("Foo")
package Hello
import kotlin.concurrent.thread
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
@kotlin.jvm.Volatile
private var result = ""
@kotlin.jvm.Volatile
private var callback: Function0<Unit>? = null
suspend fun appendAndSuspend(s: String) {
result += s
suspendCoroutine<Unit> { continuation ->
callback = {
continuation.resume(Unit)
}
}
}
suspend fun main(args: Array<String>) {
thread(isDaemon = true) {
while (true) {
val c = callback
c?.invoke()
Thread.sleep(500)
}
}
appendAndSuspend(args[0])
appendAndSuspend(args[1])
println(result)
callback = null
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,36 @@
package Hello
import kotlin.concurrent.thread
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
import kotlin.reflect.jvm.javaMethod
@kotlin.jvm.Volatile
private var result = ""
@kotlin.jvm.Volatile
private var callback: Function0<Unit>? = null
suspend fun appendAndSuspend(s: String) {
result += s
suspendCoroutine<Unit> { continuation ->
callback = {
continuation.resume(Unit)
}
}
}
suspend fun main() {
thread(isDaemon = true) {
while (true) {
val c = callback
c?.invoke()
Thread.sleep(500)
}
}
appendAndSuspend("O")
appendAndSuspend("K")
println(result)
callback = null
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,6 @@
package Hello
fun main(vararg args: kotlin.String) {
args.size
System.out.println("Hello from vararg main!")
}
@@ -0,0 +1,4 @@
OUT:
Hello from vararg main!
Return code: 0
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,10 @@
package Hello
suspend fun f(o: String, k: String): String {
return o + k
}
suspend fun main(args: Array<String>) {
val result = f(args[0], args[1])
println(result)
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0
@@ -29,6 +29,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppFQMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -36,6 +43,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppFQMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppVarargMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -43,6 +57,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppVarargMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppSuspendMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -57,6 +78,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.Foo", "O", "K");
}
public void testHelloAppSuspendMainInMultifileIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.Foo", "O", "K");
}
public void testHelloAppParameterlessMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -64,6 +92,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppParameterlessMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppOldAndParameterlessMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -71,6 +106,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppOldAndParameterlessMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppSuspendParameterlessMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
@@ -78,6 +120,20 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase {
run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K");
}
public void testHelloAppSuspendParameterlessMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K");
}
public void testSimplestSuspendMainIR() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K");
}
public void testCompilationFailed() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "smoke.jar";