[K/N][tests] Migrate various runtime/ tests ^KT-61259
This commit is contained in:
committed by
Space Team
parent
7ad4e58a7a
commit
d88092aa94
+20
@@ -0,0 +1,20 @@
|
||||
// OUTPUT_DATA_FILE: cleaner_in_main_with_checker.out
|
||||
// DISABLE_NATIVE: gcType=NOOP
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.native.ref.Cleaner
|
||||
import kotlin.native.ref.createCleaner
|
||||
import kotlin.native.Platform
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// This cleaner will run, because with the checker active this cleaner
|
||||
// will get collected, block scheduled and executed before cleaners are disabled.
|
||||
createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
42
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// OUTPUT_DATA_FILE: cleaner_in_main_without_checker.out
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.native.ref.createCleaner
|
||||
import kotlin.native.Platform
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = false
|
||||
// This cleaner will not run, because with the checker inactive this cleaner
|
||||
// will not get collected before cleaners are disabled.
|
||||
createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// DISABLE_NATIVE: gcType=NOOP
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Cleaner (0x)?[0-9a-fA-F]+ was disposed during program exit.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.ref.Cleaner
|
||||
import kotlin.native.ref.createCleaner
|
||||
import kotlin.native.Platform
|
||||
|
||||
@ThreadLocal
|
||||
var tlsCleaner: Cleaner? = null
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// This cleaner won't be run
|
||||
tlsCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.ref.Cleaner
|
||||
import kotlin.native.ref.createCleaner
|
||||
import kotlin.native.Platform
|
||||
|
||||
@ThreadLocal
|
||||
var tlsCleaner: Cleaner? = null
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = false
|
||||
// This cleaner won't be run
|
||||
tlsCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// DISABLE_NATIVE: gcType=NOOP
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Cleaner (0x)?[0-9a-fA-F]+ was disposed during program exit.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.ref.Cleaner
|
||||
import kotlin.native.ref.createCleaner
|
||||
import kotlin.native.Platform
|
||||
|
||||
// This cleaner won't be run, because it's deinitialized with globals after
|
||||
// cleaners are disabled.
|
||||
val globalCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// Make sure cleaner is initialized.
|
||||
assertNotNull(globalCleaner)
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// OUTPUT_DATA_FILE: cleaner_leak_without_checker.out
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.ref.Cleaner
|
||||
import kotlin.native.ref.createCleaner
|
||||
|
||||
// This cleaner won't be run, because it's deinitialized with globals after
|
||||
// cleaners are disabled.
|
||||
val globalCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Make sure cleaner is initialized.
|
||||
assertNotNull(globalCleaner)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, ExperimentalForeignApi::class)
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
StableRef.create(Any())
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// KIND: REGULAR
|
||||
// FREE_COMPILER_ARGS: -opt-in=kotlin.experimental.ExperimentalNativeApi,kotlinx.cinterop.ExperimentalForeignApi
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@BeforeTest
|
||||
fun enableMemoryChecker() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
StableRef.create(Any())
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, ObsoleteWorkersApi::class, ExperimentalForeignApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.Platform
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
val worker = Worker.start()
|
||||
// Make sure worker is initialized.
|
||||
worker.execute(TransferMode.SAFE, {}, {}).result;
|
||||
StableRef.create(Any())
|
||||
worker.requestTermination().result
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Unfinished workers detected, 1 workers leaked!.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, ExperimentalForeignApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.Platform
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
val worker = Worker.start()
|
||||
// Make sure worker is initialized.
|
||||
worker.execute(TransferMode.SAFE, {}, {}).result;
|
||||
StableRef.create(Any())
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, ObsoleteWorkersApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@ThreadLocal
|
||||
var x = Any()
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
val worker = Worker.start()
|
||||
|
||||
worker.execute(TransferMode.SAFE, {}) {
|
||||
println(x) // Make sure x is initialized
|
||||
}.result
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
val x = initRuntimeIfNeeded()
|
||||
|
||||
fun main() {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// FREE_COMPILER_ARGS: -Xruntime-logs=gc=info,mm=warning,tls=error,logging=debug
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_ONLY_DIST
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_EVERYWHERE
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
|
||||
// OUTPUT_REGEX: \[INFO\]\[logging\].*Logging enabled for: logging = DEBUG, gc = INFO, mm = WARNING, tls = ERROR.*\[INFO\]\[gc\].*
|
||||
fun main() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// FREE_COMPILER_ARGS: -Xruntime-logs=logging=info,logging=debug,logging=error
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_ONLY_DIST
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_EVERYWHERE
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
|
||||
// OUTPUT_REGEX: ^$
|
||||
fun main() {}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// OUTPUT_REGEX: ^$
|
||||
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
// Ensure that termination of current worker on main thread doesn't lead to problems.
|
||||
fun main() {
|
||||
val worker = Worker.current
|
||||
val future = worker.requestTermination(false)
|
||||
worker.processQueue()
|
||||
assertEquals(future.state, FutureState.COMPUTED)
|
||||
future.consume {}
|
||||
// After termination request this worker is no longer addressable.
|
||||
assertFailsWith<IllegalStateException> { worker.executeAfter(0, {
|
||||
println("BUG!")
|
||||
})}
|
||||
}
|
||||
native/native.tests/testData/standalone/termination/unhandledExceptionInCurrentWorkerExecuteAfter.kt
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: .*an error.*
|
||||
// OUTPUT_REGEX: (?!.*Will not happen.*).*
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
Worker.current.executeAfter(0L, {
|
||||
throw Error("an error")
|
||||
})
|
||||
Worker.current.processQueue()
|
||||
println("Will not happen")
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// KIND: REGULAR
|
||||
// OUTPUT_REGEX: hook called\R
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
@Test
|
||||
fun testExecuteAfterStartQuiet() {
|
||||
setUnhandledExceptionHook {
|
||||
println("hook called")
|
||||
}
|
||||
Worker.current.executeAfter(0L, {
|
||||
throw Error("an error")
|
||||
})
|
||||
Worker.current.processQueue()
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// KIND: REGULAR
|
||||
// OUTPUT_REGEX: .*an error.*
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@Test
|
||||
fun testExecuteStart() {
|
||||
val worker = Worker.start()
|
||||
val future = worker.execute(TransferMode.SAFE, {}) {
|
||||
throw Error("an error")
|
||||
}
|
||||
assertFailsWith<Throwable> {
|
||||
future.result
|
||||
}
|
||||
worker.requestTermination().result
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: .*an error.*
|
||||
// OUTPUT_REGEX: (?!.*Will not happen.*).*
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
val worker = Worker.start()
|
||||
worker.executeAfter(0L, {
|
||||
throw Error("an error")
|
||||
})
|
||||
worker.requestTermination().result
|
||||
println("Will not happen")
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// KIND: REGULAR
|
||||
// OUTPUT_REGEX: (?!.*an error.*)
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@Test
|
||||
fun testExecuteAfterStartQuiet() {
|
||||
val worker = Worker.start(errorReporting = false)
|
||||
worker.executeAfter(0L, {
|
||||
throw Error("an error")
|
||||
})
|
||||
worker.requestTermination().result
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// KIND: REGULAR
|
||||
// OUTPUT_REGEX: hook called\R
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
@Test
|
||||
fun testExecuteAfterStartQuiet() {
|
||||
setUnhandledExceptionHook {
|
||||
println("hook called")
|
||||
}
|
||||
val worker = Worker.start()
|
||||
worker.executeAfter(0L, {
|
||||
throw Error("an error")
|
||||
})
|
||||
worker.requestTermination().result
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// KIND: REGULAR
|
||||
// OUTPUT_REGEX: (?!.*an error.*)
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@Test
|
||||
fun testExecuteStartQuiet() {
|
||||
val worker = Worker.start(errorReporting = false)
|
||||
val future = worker.execute(TransferMode.SAFE, {}) {
|
||||
throw Error("an error")
|
||||
}
|
||||
assertFailsWith<Throwable> {
|
||||
future.result
|
||||
}
|
||||
worker.requestTermination().result
|
||||
}
|
||||
Reference in New Issue
Block a user