[K/N][tests] Migrate termination runtime tests to new testing infra ^KT-61259

This commit is contained in:
Alexander Shabalin
2023-11-08 11:47:43 +01:00
committed by Space Team
parent 226ee3c367
commit 04a2a2d90d
33 changed files with 347 additions and 363 deletions
@@ -314,11 +314,6 @@ standaloneTest("runtime_basic_init") {
expectedExitStatus = 0
}
standaloneTest("runtime_basic_exit") {
source = "runtime/basic/exit.kt"
expectedExitStatus = 42
}
standaloneTest('enumEquals') {
useGoldenData = true
source = "runtime/basic/enum_equals.kt"
@@ -833,70 +828,6 @@ standaloneTest("throw_from_except_constr") {
source = "runtime/exceptions/throw_from_except_constr.kt"
}
standaloneTest("custom_hook") {
outputChecker = {
it.contains("value 42: Error. Runnable state: true") && it.contains("Uncaught Kotlin exception: kotlin.Error: an error")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook.kt"
flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative']
}
standaloneTest("custom_hook_memory_leak") {
outputChecker = {
it.contains("Hook 42") && it.contains("Uncaught Kotlin exception: kotlin.Error: an error")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook_memory_leak.kt"
}
standaloneTest("custom_hook_get") {
source = "runtime/exceptions/custom_hook_get.kt"
}
standaloneTest("custom_hook_no_reset") {
outputChecker = {
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: some error")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook_no_reset.kt"
}
standaloneTest("custom_hook_throws") {
outputChecker = {
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: another error") && !it.contains("some error")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook_throws.kt"
}
standaloneTest("custom_hook_unhandled_exception") {
useGoldenData = true
source = "runtime/exceptions/custom_hook_unhandled_exception.kt"
}
standaloneTest("custom_hook_terminate") {
outputChecker = {
it.contains("Hook called")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook_terminate.kt"
}
standaloneTest("custom_hook_terminate_unhandled_exception") {
outputChecker = {
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: some error") && !it.contains("Not going to happen")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/custom_hook_terminate_unhandled_exception.kt"
}
standaloneTest("exception_in_global_init") {
source = "runtime/exceptions/exception_in_global_init.kt"
expectedExitStatusChecker = { it != 0 }
outputChecker = { s -> s.contains("Uncaught Kotlin exception:") && s.contains("FAIL") && !s.contains("in kotlin main") }
}
tasks.register("rethrow_exception", KonanLocalTest) {
source = "runtime/exceptions/rethrow.kt"
}
@@ -905,42 +836,6 @@ tasks.register("throw_from_catch", KonanLocalTest) {
source = "runtime/exceptions/throw_from_catch.kt"
}
standaloneTest("terminate") {
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/terminate.kt"
}
standaloneTest("unhandled_exception") {
outputChecker = {
it.contains("Uncaught Kotlin exception: kotlin.Error: some error")
}
expectedExitStatusChecker = { it != 0 }
source = "runtime/exceptions/unhandled_exception.kt"
}
tasks.register("main_exception", KonanLocalTest) {
outputChecker = { s -> s.contains("kotlin.Error: Hello!") }
expectedExitStatus = 1
source = "runtime/basic/main_exception.kt"
}
standaloneTest("runtime_basic_assert_failed") {
expectedExitStatusChecker = { it != 0 }
source = "runtime/basic/assert_failed.kt"
}
standaloneTest("runtime_basic_assert_passed") {
expectedExitStatus = 0
source = "runtime/basic/assert_passed.kt"
}
standaloneTest("runtime_basic_assert_disabled") {
expectedExitStatus = 0
enableKonanAssertions = false
source = "runtime/basic/assert_failed.kt"
}
tasks.register("initializers0", KonanLocalTest) {
useGoldenData = true
source = "runtime/basic/initializers0.kt"
@@ -1,9 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun main(args: Array<String>) {
assert(false)
}
@@ -1,9 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun main(args: Array<String>) {
assert(true)
}
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.system.*
fun main(args: Array<String>) {
exitProcess(42)
@Suppress("UNREACHABLE_CODE")
throw RuntimeException("Exit function call returned normally")
}
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package runtime.basic.main_exception
import kotlin.test.*
@Test fun runTest() {
throw Error("Hello!")
}
@@ -1,49 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
import kotlin.native.internal.*
import kotlin.native.runtime.Debugging
fun mainLegacyMM() {
val wrong = "wrong"
assertFailsWith<InvalidMutabilityException> {
setUnhandledExceptionHook { _ -> println(wrong) }
}
val x = 42
val old = setUnhandledExceptionHook({ throwable: Throwable ->
println("value $x: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
}.freeze())
assertNull(old)
throw Error("an error")
}
fun mainExperimentalMM() {
val unset = setUnhandledExceptionHook { _ -> println("ok") }
assertNull(unset)
val x = 42
val old = setUnhandledExceptionHook { throwable: Throwable ->
println("value $x: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
}
assertNotNull(old)
throw Error("an error")
}
fun main() {
if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) {
mainExperimentalMM()
} else {
mainLegacyMM()
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.native.concurrent.*
fun main() {
val exceptionHook = { _: Throwable ->
println("Hook")
}.freeze()
val oldHook = setUnhandledExceptionHook(exceptionHook)
assertNull(oldHook)
val hook1 = getUnhandledExceptionHook()
assertEquals(exceptionHook, hook1)
val hook2 = getUnhandledExceptionHook()
assertEquals(exceptionHook, hook2)
val hook3 = setUnhandledExceptionHook(null)
assertEquals(exceptionHook, hook3)
val hook4 = getUnhandledExceptionHook()
assertNull(hook4)
}
@@ -1,22 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
data class C(val x: Int)
fun main() {
Platform.isMemoryLeakCheckerActive = true
val c = C(42)
setUnhandledExceptionHook({ _: Throwable ->
println("Hook ${c.x}")
}.freeze())
throw Error("an error")
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.native.concurrent.*
fun customExceptionHook(throwable: Throwable) {
println("Hook called")
assertEquals(::customExceptionHook, getUnhandledExceptionHook())
}
fun main() {
setUnhandledExceptionHook((::customExceptionHook).freeze())
throw Error("some error")
}
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.native.concurrent.*
fun main() {
setUnhandledExceptionHook({ t: Throwable ->
println("Hook called")
terminateWithUnhandledException(t)
}.freeze())
throw Error("some error")
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.native.concurrent.*
fun main() {
setUnhandledExceptionHook({ t: Throwable ->
println("Hook called")
terminateWithUnhandledException(t)
}.freeze())
val exception = Error("some error")
processUnhandledException(exception)
println("Not going to happen")
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
fun customExceptionHook(throwable: Throwable) {
println("Hook called")
throw Error("another error")
}
fun main() {
setUnhandledExceptionHook((::customExceptionHook).freeze())
throw Error("some error")
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
import kotlin.test.*
import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
fun main() {
val called = AtomicInt(0)
setUnhandledExceptionHook({ _: Throwable ->
called.value = 1
}.freeze())
val exception = Error("some error")
processUnhandledException(exception)
assertEquals(1, called.value)
}
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
val p: Nothing = error("FAIL")
fun main() {
println("in kotlin main")
}
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
import kotlin.test.*
fun main() {
val exception = Error("some error")
terminateWithUnhandledException(exception)
}
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
import kotlin.test.*
fun main() {
val exception = Error("some error")
processUnhandledException(exception)
}