[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
@@ -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)
}