From 5f51f5e1fcdce9d86f5f9264e09918412fd703d9 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Sat, 13 Jan 2024 12:23:35 +0100 Subject: [PATCH] [K/N] Migrate more cinterop tests ^KT-61259 --- .../codegen/box/cinterop/basics/statbuf.kt | 25 ++ .../backend.native/tests/build.gradle | 72 ----- .../backend.native/tests/interop/basics/0.kt | 15 - .../backend.native/tests/interop/basics/0.out | 2 - .../tests/interop/basics/cstdio.def | 8 - .../tests/interop/basics/pinning.kt | 248 ----------------- .../threadStates/callbacksWithExceptions.kt | 97 ------- .../interop/threadStates/threadStates.cpp | 33 --- .../interop/threadStates/threadStates.def | 21 -- .../interop/threadStates/threadStates.kt | 59 ---- .../threadStates/unhandledException.kt | 23 -- .../unhandledExceptionInForeignThread.kt | 23 -- .../test/kotlinx.cinterop/PinningTest.kt | 263 ++++++++++++++++++ .../testData/standalone/console/fprintf.kt | 13 + .../testData/standalone/console/fprintf.out | 0 .../testData/standalone/console/printf.kt | 1 + .../testData/standalone/console/printf.out | 0 .../testData/standalone/console/puts.kt | 8 + .../testData/standalone/console/puts.out | 0 .../termination/unhandledException.kt | 90 ++++++ .../unhandledExceptionInForeignThread.kt | 89 ++++++ .../standalone/threadStates/callback.kt | 51 ++++ .../threadStates/callbackOnSeparateThread.kt | 40 +++ .../threadStates/callbackWithException.kt | 64 +++++ .../threadStates/callbackWithFinally.kt | 63 +++++ .../callbackWithFinallyNoCatch.kt | 62 +++++ .../threadStates/directStaticCFunctionCall.kt | 24 ++ .../standalone/threadStates/nativeCall.kt | 50 ++++ .../nestedCallbackWithException.kt | 67 +++++ .../threadStates/nestedCallbackWithFinally.kt | 66 +++++ .../standalone/threadStates/nestedCalls.kt | 60 ++++ .../FirNativeCodegenBoxTestGenerated.java | 6 + .../FirNativeCodegenBoxTestNoPLGenerated.java | 6 + .../FirNativeStandaloneTestGenerated.java | 105 +++++++ .../NativeCodegenBoxTestGenerated.java | 6 + .../NativeCodegenBoxTestNoPLGenerated.java | 6 + .../NativeStandaloneTestGenerated.java | 103 +++++++ 37 files changed, 1268 insertions(+), 601 deletions(-) create mode 100644 compiler/testData/codegen/box/cinterop/basics/statbuf.kt delete mode 100644 kotlin-native/backend.native/tests/interop/basics/0.kt delete mode 100644 kotlin-native/backend.native/tests/interop/basics/0.out delete mode 100644 kotlin-native/backend.native/tests/interop/basics/cstdio.def delete mode 100644 kotlin-native/backend.native/tests/interop/basics/pinning.kt delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/callbacksWithExceptions.kt delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/threadStates.cpp delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/threadStates.def delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/threadStates.kt delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/unhandledException.kt delete mode 100644 kotlin-native/backend.native/tests/interop/threadStates/unhandledExceptionInForeignThread.kt create mode 100644 kotlin-native/runtime/test/kotlinx.cinterop/PinningTest.kt rename kotlin-native/backend.native/tests/interop/basics/4.kt => native/native.tests/testData/standalone/console/fprintf.kt (73%) rename kotlin-native/backend.native/tests/interop/basics/4.out => native/native.tests/testData/standalone/console/fprintf.out (100%) rename kotlin-native/backend.native/tests/interop/basics/5.kt => native/native.tests/testData/standalone/console/printf.kt (92%) rename kotlin-native/backend.native/tests/interop/basics/5.out => native/native.tests/testData/standalone/console/printf.out (100%) rename kotlin-native/backend.native/tests/interop/basics/2.kt => native/native.tests/testData/standalone/console/puts.kt (50%) rename kotlin-native/backend.native/tests/interop/basics/2.out => native/native.tests/testData/standalone/console/puts.out (100%) create mode 100644 native/native.tests/testData/standalone/termination/unhandledException.kt create mode 100644 native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt create mode 100644 native/native.tests/testData/standalone/threadStates/callback.kt create mode 100644 native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt create mode 100644 native/native.tests/testData/standalone/threadStates/callbackWithException.kt create mode 100644 native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt create mode 100644 native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt create mode 100644 native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt create mode 100644 native/native.tests/testData/standalone/threadStates/nativeCall.kt create mode 100644 native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt create mode 100644 native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt create mode 100644 native/native.tests/testData/standalone/threadStates/nestedCalls.kt diff --git a/compiler/testData/codegen/box/cinterop/basics/statbuf.kt b/compiler/testData/codegen/box/cinterop/basics/statbuf.kt new file mode 100644 index 00000000000..02d4ed836cc --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/basics/statbuf.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2023 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. + */ +// TARGET_BACKEND: NATIVE +// IGNORE_NATIVE: target=linux_arm64 +// MODULE: cinterop +// FILE: sysstat.def +headers = sys/stat.h + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +import sysstat.* +import kotlin.test.* +import kotlinx.cinterop.* + +fun box(): String { + val statBuf = nativeHeap.alloc() + assertEquals(0, stat("/", statBuf.ptr)) + assertEquals("0", statBuf.st_uid.toString()) + + return "OK" +} diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 11ac32f322c..bd1be2c0842 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1019,20 +1019,6 @@ void createInterop(String name, Closure conf) { } } -createInterop("sysstat") { - // FIXME: creates empty file to workaround konan gradle plugin issue (should be able to have no def file) - def f = File.createTempFile("sysstat.empty", ".def") - it.packageName 'sysstat' - // FIXME: this option doesn't work due to an issue in plugin: it tries to resolve header in project dir. - //it.headers 'sys/stat.h' - f.write("headers = sys/stat.h") - it.defFile f -} - -createInterop("cstdio") { - it.defFile 'interop/basics/cstdio.def' -} - createInterop("sockets") { it.defFile 'interop/basics/sockets.def' } @@ -1342,31 +1328,6 @@ standaloneTest("interop_objc_allocException") { UtilsKt.dependsOnPlatformLibs(it) } -interopTest("interop0") { - disabled = (project.testTarget == 'linux_arm64') - useGoldenData = true - source = "interop/basics/0.kt" - interop = 'sysstat' -} - -interopTest("interop2") { - useGoldenData = true - source = "interop/basics/2.kt" - interop = 'cstdio' -} - -interopTest("interop4") { - useGoldenData = true - source = "interop/basics/4.kt" - interop = 'cstdio' -} - -standaloneTest("interop5") { - useGoldenData = true - source = "interop/basics/5.kt" - UtilsKt.dependsOnPlatformLibs(it) -} - interopTest("interop_concurrentTerminate") { source = "interop/concurrentTerminate/main.kt" interop = 'concurrentTerminate' @@ -1379,34 +1340,6 @@ interopTest("interop_embedStaticLibraries") { interop = 'embedStaticLibraries' } -interopTest("interop_threadStates") { - source = "interop/threadStates/threadStates.kt" - flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative'] - interop = "threadStates" -} - -interopTest("interop_threadStates_callbacksWithExceptions") { - source = "interop/threadStates/callbacksWithExceptions.kt" - interop = "threadStates" - flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative'] -} - -interopTest("interop_threadStates_unhandledException") { - source = "interop/threadStates/unhandledException.kt" - interop = "threadStates" - outputChecker = { it.contains("Error. Runnable state: true") } - expectedExitStatusChecker = { it != 0 } - flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative'] -} - -interopTest("interop_threadStates_unhandledExceptionInForeignThread") { - source = "interop/threadStates/unhandledExceptionInForeignThread.kt" - interop = "threadStates" - outputChecker = { it.contains("Error. Runnable state: true") } - expectedExitStatusChecker = { it != 0 } - flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative'] -} - interopTest("interop_withSpaces") { interop ='withSpaces' source = "interop/basics/withSpaces.kt" @@ -1446,11 +1379,6 @@ interopTest("interop_leakMemoryWithRunningThreadChecked") { outputChecker = { s -> s.contains("Cannot run checkers when there are 1 alive runtimes at the shutdown") } } -standaloneTest("interop_pinning") { - source = "interop/basics/pinning.kt" - flags = [ "-tr" ] -} - interopTest("interop_cppClass") { disabled = PlatformInfo.isAppleTarget(project) // KT-58422 source = "interop/cpp/cppClass.kt" diff --git a/kotlin-native/backend.native/tests/interop/basics/0.kt b/kotlin-native/backend.native/tests/interop/basics/0.kt deleted file mode 100644 index 2b6f4397d55..00000000000 --- a/kotlin-native/backend.native/tests/interop/basics/0.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class) - -import sysstat.* -import kotlinx.cinterop.* - -fun main(args: Array) { - val statBuf = nativeHeap.alloc() - val res = stat("/", statBuf.ptr) - println(res) - println(statBuf.st_uid) -} diff --git a/kotlin-native/backend.native/tests/interop/basics/0.out b/kotlin-native/backend.native/tests/interop/basics/0.out deleted file mode 100644 index aa47d0d46d4..00000000000 --- a/kotlin-native/backend.native/tests/interop/basics/0.out +++ /dev/null @@ -1,2 +0,0 @@ -0 -0 diff --git a/kotlin-native/backend.native/tests/interop/basics/cstdio.def b/kotlin-native/backend.native/tests/interop/basics/cstdio.def deleted file mode 100644 index 13dc2a82526..00000000000 --- a/kotlin-native/backend.native/tests/interop/basics/cstdio.def +++ /dev/null @@ -1,8 +0,0 @@ -headers = stdio.h -compilerOpts.osx = -D_ANSI_SOURCE - ---- - -static inline FILE* getStdout() { - return stdout; -} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/basics/pinning.kt b/kotlin-native/backend.native/tests/interop/basics/pinning.kt deleted file mode 100644 index 07842ee9cab..00000000000 --- a/kotlin-native/backend.native/tests/interop/basics/pinning.kt +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright 2010-2023 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(kotlinx.cinterop.ExperimentalForeignApi::class) - -import kotlin.test.* -import kotlinx.cinterop.* - -@Test fun pinnedByteArrayAddressOf() { - val arr = ByteArray(10) { 0 } - arr.usePinned { - assertEquals(0, it.addressOf(0).pointed.value) - assertEquals(0, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedStringAddressOf() { - val str = "0000000000" - str.usePinned { - it.addressOf(0) - it.addressOf(9) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedCharArrayAddressOf() { - val arr = CharArray(10) { '0' } - arr.usePinned { - it.addressOf(0) - it.addressOf(9) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedShortArrayAddressOf() { - val arr = ShortArray(10) { 0 } - arr.usePinned { - assertEquals(0, it.addressOf(0).pointed.value) - assertEquals(0, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedIntArrayAddressOf() { - val arr = IntArray(10) { 0 } - arr.usePinned { - assertEquals(0, it.addressOf(0).pointed.value) - assertEquals(0, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedLongArrayAddressOf() { - val arr = LongArray(10) { 0 } - arr.usePinned { - assertEquals(0, it.addressOf(0).pointed.value) - assertEquals(0, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedUByteArrayAddressOf() { - val arr = UByteArray(10) { 0U } - arr.usePinned { - assertEquals(0U, it.addressOf(0).pointed.value) - assertEquals(0U, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedUShortArrayAddressOf() { - val arr = UShortArray(10) { 0U } - arr.usePinned { - assertEquals(0U, it.addressOf(0).pointed.value) - assertEquals(0U, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedUIntArrayAddressOf() { - val arr = UIntArray(10) { 0U } - arr.usePinned { - assertEquals(0U, it.addressOf(0).pointed.value) - assertEquals(0U, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedULongArrayAddressOf() { - val arr = ULongArray(10) { 0U } - arr.usePinned { - assertEquals(0U, it.addressOf(0).pointed.value) - assertEquals(0U, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedFloatArrayAddressOf() { - val arr = FloatArray(10) { 0.0f } - arr.usePinned { - assertEquals(0.0f, it.addressOf(0).pointed.value) - assertEquals(0.0f, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} - -@Test fun pinnedDoubleArrayAddressOf() { - val arr = DoubleArray(10) { 0.0 } - arr.usePinned { - assertEquals(0.0, it.addressOf(0).pointed.value) - assertEquals(0.0, it.addressOf(9).pointed.value) - assertFailsWith { - it.addressOf(10) - } - assertFailsWith { - it.addressOf(-1) - } - assertFailsWith { - it.addressOf(Int.MAX_VALUE) - } - assertFailsWith { - it.addressOf(Int.MIN_VALUE) - } - } -} diff --git a/kotlin-native/backend.native/tests/interop/threadStates/callbacksWithExceptions.kt b/kotlin-native/backend.native/tests/interop/threadStates/callbacksWithExceptions.kt deleted file mode 100644 index 9c64d72707a..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/callbacksWithExceptions.kt +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class) - -import kotlin.native.runtime.Debugging -import kotlin.test.* -import kotlinx.cinterop.staticCFunction -import threadStates.* - -fun main() { - callbackWithException() - callbackWithFinally() - callbackWithFinallyNoCatch() - nestedCallbackWithException() - nestedCallbackWithFinally() -} - -fun assertRunnableThreadState() { - assertTrue(Debugging.isThreadStateRunnable) -} - -class CustomException() : Exception() - -fun throwException() { - assertRunnableThreadState() - throw CustomException() -} - -fun callbackWithException() { - try { - runCallback(staticCFunction(::throwException)) - } catch (e: CustomException) { - assertRunnableThreadState() - return - } catch (e: Throwable) { - assertRunnableThreadState() - fail("Wrong exception type: ${e.message}") - } - fail("No exception thrown") -} - -fun callbackWithFinally() { - try { - runCallback(staticCFunction(::throwException)) - } catch (e: CustomException) { - assertRunnableThreadState() - return - } finally { - assertRunnableThreadState() - } - fail("No exception thrown") -} - -fun callbackWithFinallyNoCatch() { - try { - try { - runCallback(staticCFunction(::throwException)) - } finally { - assertRunnableThreadState() - } - assertRunnableThreadState() - } catch (_: CustomException) {} -} - -fun nestedCallbackWithException() { - try { - runCallback(staticCFunction { -> - assertRunnableThreadState() - runCallback(staticCFunction(::throwException)) - }) - } catch (e: CustomException) { - assertRunnableThreadState() - return - } catch (e: Throwable) { - assertRunnableThreadState() - fail("Wrong exception type: ${e.message}") - } - fail("No exception thrown") -} - -fun nestedCallbackWithFinally() { - try { - runCallback(staticCFunction { -> - assertRunnableThreadState() - runCallback(staticCFunction(::throwException)) - }) - } catch (e: CustomException) { - assertRunnableThreadState() - return - } finally { - assertRunnableThreadState() - } - fail("No exception thrown") -} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.cpp b/kotlin-native/backend.native/tests/interop/threadStates/threadStates.cpp deleted file mode 100644 index 28cb0d6b7a1..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include - -// Implemented in the runtime for test purposes. -extern "C" bool Kotlin_Debugging_isThreadStateNative(); - -extern "C" void assertNativeThreadState() { - if (!Kotlin_Debugging_isThreadStateNative()) { - printf("Incorrect thread state. Expected native thread state."); - abort(); - } -} - -extern "C" void runInNewThread(void(*callback)(void)) { - std::thread t([callback]() { - callback(); - }); - t.join(); -} - -extern "C" void runInForeignThread(void(*callback)(void)) { - std::thread t([callback]() { - // This thread is not attached to the Kotlin runtime. - auto future = std::async(std::launch::async, callback); - - // The machinery of the direct interop doesn't filter out a Kotlin exception thrown by the callback. - // The get() call will re-throw this exception. - future.get(); - }); - t.join(); -} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.def b/kotlin-native/backend.native/tests/interop/threadStates/threadStates.def deleted file mode 100644 index b98c6fded2f..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.def +++ /dev/null @@ -1,21 +0,0 @@ -language = C - ---- - -#include - -void assertNativeThreadState(); - -void runCallback(void(*callback)(void)) { - assertNativeThreadState(); - callback(); - assertNativeThreadState(); -} - -int32_t answer() { - assertNativeThreadState(); - return 42; -} - -void runInNewThread(void(*callback)(void)); -void runInForeignThread(void(*callback)(void)); \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.kt b/kotlin-native/backend.native/tests/interop/threadStates/threadStates.kt deleted file mode 100644 index 4f29284c09f..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/threadStates.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class) - -import kotlin.native.runtime.Debugging -import kotlin.test.* -import kotlinx.cinterop.* -import threadStates.* - -fun main() { - nativeCall() - callback() - nestedCalls() - directStaticCFunctionCall() - callbackOnSeparateThread() -} - -fun assertRunnableThreadState() { - assertTrue(Debugging.isThreadStateRunnable) -} - -fun nativeCall() { - answer() - assertRunnableThreadState() -} - -fun callback() { - runCallback(staticCFunction { -> - assertRunnableThreadState() - }) - assertRunnableThreadState() -} - -fun nestedCalls() { - runCallback(staticCFunction { -> - assertRunnableThreadState() - answer() - Unit - }) - assertRunnableThreadState() -} - -fun directStaticCFunctionCall() { - val funPtr = staticCFunction { -> - assertRunnableThreadState() - } - assertRunnableThreadState() - funPtr() - assertRunnableThreadState() -} - -fun callbackOnSeparateThread() { - runInNewThread(staticCFunction { -> - assertRunnableThreadState() - }) -} diff --git a/kotlin-native/backend.native/tests/interop/threadStates/unhandledException.kt b/kotlin-native/backend.native/tests/interop/threadStates/unhandledException.kt deleted file mode 100644 index e894033a809..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/unhandledException.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ -@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class) - -import kotlin.native.concurrent.* -import kotlin.native.runtime.Debugging -import kotlinx.cinterop.staticCFunction -import threadStates.* - -fun main() { - val hook = { throwable: Throwable -> - print("${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}") - } - if (Platform.memoryModel != MemoryModel.EXPERIMENTAL) { - hook.freeze() - } - - setUnhandledExceptionHook(hook) - - runInNewThread(staticCFunction { throw Error("Error") }) -} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/threadStates/unhandledExceptionInForeignThread.kt b/kotlin-native/backend.native/tests/interop/threadStates/unhandledExceptionInForeignThread.kt deleted file mode 100644 index 471652f51be..00000000000 --- a/kotlin-native/backend.native/tests/interop/threadStates/unhandledExceptionInForeignThread.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ -@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class) - -import kotlin.native.concurrent.* -import kotlin.native.runtime.Debugging -import kotlinx.cinterop.staticCFunction -import threadStates.* - -fun main() { - val hook = { throwable: Throwable -> - print("${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}") - } - if (Platform.memoryModel != MemoryModel.EXPERIMENTAL) { - hook.freeze() - } - - setUnhandledExceptionHook(hook) - - runInForeignThread(staticCFunction { throw Error("Error") }) -} \ No newline at end of file diff --git a/kotlin-native/runtime/test/kotlinx.cinterop/PinningTest.kt b/kotlin-native/runtime/test/kotlinx.cinterop/PinningTest.kt new file mode 100644 index 00000000000..ae50c111283 --- /dev/null +++ b/kotlin-native/runtime/test/kotlinx.cinterop/PinningTest.kt @@ -0,0 +1,263 @@ +/* + * Copyright 2010-2023 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(ExperimentalForeignApi::class) +package test.kotlinx.cinterop + +import kotlin.test.* +import kotlinx.cinterop.* + +class PinnedTest { + @Test + fun pinnedByteArrayAddressOf() { + val arr = ByteArray(10) { 0 } + arr.usePinned { + assertEquals(0, it.addressOf(0).pointed.value) + assertEquals(0, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedStringAddressOf() { + val str = "0000000000" + str.usePinned { + it.addressOf(0) + it.addressOf(9) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedCharArrayAddressOf() { + val arr = CharArray(10) { '0' } + arr.usePinned { + it.addressOf(0) + it.addressOf(9) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedShortArrayAddressOf() { + val arr = ShortArray(10) { 0 } + arr.usePinned { + assertEquals(0, it.addressOf(0).pointed.value) + assertEquals(0, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedIntArrayAddressOf() { + val arr = IntArray(10) { 0 } + arr.usePinned { + assertEquals(0, it.addressOf(0).pointed.value) + assertEquals(0, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedLongArrayAddressOf() { + val arr = LongArray(10) { 0 } + arr.usePinned { + assertEquals(0, it.addressOf(0).pointed.value) + assertEquals(0, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedUByteArrayAddressOf() { + val arr = UByteArray(10) { 0U } + arr.usePinned { + assertEquals(0U, it.addressOf(0).pointed.value) + assertEquals(0U, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedUShortArrayAddressOf() { + val arr = UShortArray(10) { 0U } + arr.usePinned { + assertEquals(0U, it.addressOf(0).pointed.value) + assertEquals(0U, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedUIntArrayAddressOf() { + val arr = UIntArray(10) { 0U } + arr.usePinned { + assertEquals(0U, it.addressOf(0).pointed.value) + assertEquals(0U, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedULongArrayAddressOf() { + val arr = ULongArray(10) { 0U } + arr.usePinned { + assertEquals(0U, it.addressOf(0).pointed.value) + assertEquals(0U, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedFloatArrayAddressOf() { + val arr = FloatArray(10) { 0.0f } + arr.usePinned { + assertEquals(0.0f, it.addressOf(0).pointed.value) + assertEquals(0.0f, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } + + @Test + fun pinnedDoubleArrayAddressOf() { + val arr = DoubleArray(10) { 0.0 } + arr.usePinned { + assertEquals(0.0, it.addressOf(0).pointed.value) + assertEquals(0.0, it.addressOf(9).pointed.value) + assertFailsWith { + it.addressOf(10) + } + assertFailsWith { + it.addressOf(-1) + } + assertFailsWith { + it.addressOf(Int.MAX_VALUE) + } + assertFailsWith { + it.addressOf(Int.MIN_VALUE) + } + } + } +} diff --git a/kotlin-native/backend.native/tests/interop/basics/4.kt b/native/native.tests/testData/standalone/console/fprintf.kt similarity index 73% rename from kotlin-native/backend.native/tests/interop/basics/4.kt rename to native/native.tests/testData/standalone/console/fprintf.kt index 135465f7199..04ab4ad1f9a 100644 --- a/kotlin-native/backend.native/tests/interop/basics/4.kt +++ b/native/native.tests/testData/standalone/console/fprintf.kt @@ -2,6 +2,19 @@ * Copyright 2010-2023 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. */ +// OUTPUT_DATA_FILE: fprintf.out +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: cstdio.def +headers = stdio.h +compilerOpts.osx = -D_ANSI_SOURCE +--- +static inline FILE* getStdout() { + return stdout; +} + +// MODULE: main(cinterop) +// FILE: main.kt @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import cstdio.* diff --git a/kotlin-native/backend.native/tests/interop/basics/4.out b/native/native.tests/testData/standalone/console/fprintf.out similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/4.out rename to native/native.tests/testData/standalone/console/fprintf.out diff --git a/kotlin-native/backend.native/tests/interop/basics/5.kt b/native/native.tests/testData/standalone/console/printf.kt similarity index 92% rename from kotlin-native/backend.native/tests/interop/basics/5.kt rename to native/native.tests/testData/standalone/console/printf.kt index 193dbbb6913..90373aaf730 100644 --- a/kotlin-native/backend.native/tests/interop/basics/5.kt +++ b/native/native.tests/testData/standalone/console/printf.kt @@ -2,6 +2,7 @@ * Copyright 2010-2023 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. */ +// OUTPUT_DATA_FILE: printf.out @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import platform.posix.printf diff --git a/kotlin-native/backend.native/tests/interop/basics/5.out b/native/native.tests/testData/standalone/console/printf.out similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/5.out rename to native/native.tests/testData/standalone/console/printf.out diff --git a/kotlin-native/backend.native/tests/interop/basics/2.kt b/native/native.tests/testData/standalone/console/puts.kt similarity index 50% rename from kotlin-native/backend.native/tests/interop/basics/2.kt rename to native/native.tests/testData/standalone/console/puts.kt index da76c28a84b..51cbe5b5691 100644 --- a/kotlin-native/backend.native/tests/interop/basics/2.kt +++ b/native/native.tests/testData/standalone/console/puts.kt @@ -2,7 +2,15 @@ * 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. */ +// OUTPUT_DATA_FILE: puts.out +// TARGET_BACKEND: NATIVE +// MODULE: cinterop +// FILE: cstdio.def +headers = stdio.h +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import cstdio.* fun main(args: Array) { diff --git a/kotlin-native/backend.native/tests/interop/basics/2.out b/native/native.tests/testData/standalone/console/puts.out similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/2.out rename to native/native.tests/testData/standalone/console/puts.out diff --git a/native/native.tests/testData/standalone/termination/unhandledException.kt b/native/native.tests/testData/standalone/termination/unhandledException.kt new file mode 100644 index 00000000000..f70f5355f8e --- /dev/null +++ b/native/native.tests/testData/standalone/termination/unhandledException.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// OUTPUT_REGEX: Error. Runnable state:.* +// EXIT_CODE: !0 +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +#include + +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +int32_t answer() { + assertNativeThreadState(); + return 42; +} + +void runInNewThread(void(*callback)(void)); +void runInForeignThread(void(*callback)(void)); + +// FILE: threadStates.cpp +#include +#include +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +extern "C" void runInNewThread(void(*callback)(void)) { + std::thread t([callback]() { + callback(); + }); + t.join(); +} + +extern "C" void runInForeignThread(void(*callback)(void)) { + std::thread t([callback]() { + // This thread is not attached to the Kotlin runtime. + auto future = std::async(std::launch::async, callback); + + // The machinery of the direct interop doesn't filter out a Kotlin exception thrown by the callback. + // The get() call will re-throw this exception. + future.get(); + }); + t.join(); +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(FreezingIsDeprecated::class, + kotlin.experimental.ExperimentalNativeApi::class, + kotlin.native.runtime.NativeRuntimeApi::class, + kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.concurrent.* +import kotlin.test.* +import kotlin.native.runtime.Debugging +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + val hook = { throwable: Throwable -> + print("${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}") + } + if (Platform.memoryModel != MemoryModel.EXPERIMENTAL) { + hook.freeze() + } + + setUnhandledExceptionHook(hook) + + runInNewThread(staticCFunction { throw Error("Error") }) +} \ No newline at end of file diff --git a/native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt b/native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt new file mode 100644 index 00000000000..6b211639eb8 --- /dev/null +++ b/native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// OUTPUT_REGEX: Error. Runnable state:.* +// EXIT_CODE: !0 +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +#include + +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +int32_t answer() { + assertNativeThreadState(); + return 42; +} + +void runInNewThread(void(*callback)(void)); +void runInForeignThread(void(*callback)(void)); + +// FILE: threadStates.cpp +#include +#include +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +extern "C" void runInNewThread(void(*callback)(void)) { + std::thread t([callback]() { + callback(); + }); + t.join(); +} + +extern "C" void runInForeignThread(void(*callback)(void)) { + std::thread t([callback]() { + // This thread is not attached to the Kotlin runtime. + auto future = std::async(std::launch::async, callback); + + // The machinery of the direct interop doesn't filter out a Kotlin exception thrown by the callback. + // The get() call will re-throw this exception. + future.get(); + }); + t.join(); +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(FreezingIsDeprecated::class, + kotlin.experimental.ExperimentalNativeApi::class, + kotlin.native.runtime.NativeRuntimeApi::class, + kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.concurrent.* +import kotlin.native.runtime.Debugging +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + val hook = { throwable: Throwable -> + print("${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}") + } + if (Platform.memoryModel != MemoryModel.EXPERIMENTAL) { + hook.freeze() + } + + setUnhandledExceptionHook(hook) + + runInForeignThread(staticCFunction { throw Error("Error") }) +} \ No newline at end of file diff --git a/native/native.tests/testData/standalone/threadStates/callback.kt b/native/native.tests/testData/standalone/threadStates/callback.kt new file mode 100644 index 00000000000..264853c6489 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/callback.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.* +import threadStates.* + +fun main() { + runCallback(staticCFunction { -> + assertRunnableThreadState() + }) + assertRunnableThreadState() +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} diff --git a/native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt b/native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt new file mode 100644 index 00000000000..d5e2bb40134 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void runInNewThread(void(*callback)(void)); + +// FILE: threadStates.cpp +#include + +extern "C" void runInNewThread(void(*callback)(void)) { + std::thread t([callback]() { + callback(); + }); + t.join(); +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.* +import threadStates.* + +fun main() { + runInNewThread(staticCFunction { -> + assertRunnableThreadState() + }) +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} diff --git a/native/native.tests/testData/standalone/threadStates/callbackWithException.kt b/native/native.tests/testData/standalone/threadStates/callbackWithException.kt new file mode 100644 index 00000000000..b3a456b057e --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/callbackWithException.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + try { + runCallback(staticCFunction(::throwException)) + } catch (e: CustomException) { + assertRunnableThreadState() + return + } catch (e: Throwable) { + assertRunnableThreadState() + fail("Wrong exception type: ${e.message}") + } + fail("No exception thrown") +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} + +class CustomException() : Exception() + +fun throwException() { + assertRunnableThreadState() + throw CustomException() +} diff --git a/native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt b/native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt new file mode 100644 index 00000000000..773c519ca1f --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + try { + runCallback(staticCFunction(::throwException)) + } catch (e: CustomException) { + assertRunnableThreadState() + return + } finally { + assertRunnableThreadState() + } + fail("No exception thrown") +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} + +class CustomException() : Exception() + +fun throwException() { + assertRunnableThreadState() + throw CustomException() +} diff --git a/native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt b/native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt new file mode 100644 index 00000000000..34f376ef7e6 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + try { + try { + runCallback(staticCFunction(::throwException)) + } finally { + assertRunnableThreadState() + } + assertRunnableThreadState() + } catch (_: CustomException) {} +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} + +class CustomException() : Exception() + +fun throwException() { + assertRunnableThreadState() + throw CustomException() +} diff --git a/native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt b/native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt new file mode 100644 index 00000000000..0759cc946b2 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.* + +fun main() { + val funPtr = staticCFunction { -> + assertRunnableThreadState() + } + assertRunnableThreadState() + funPtr() + assertRunnableThreadState() +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} diff --git a/native/native.tests/testData/standalone/threadStates/nativeCall.kt b/native/native.tests/testData/standalone/threadStates/nativeCall.kt new file mode 100644 index 00000000000..efa9b874276 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/nativeCall.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +#include + +void assertNativeThreadState(); + +int32_t answer() { + assertNativeThreadState(); + return 42; +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.* +import threadStates.* + +fun main() { + answer() + assertRunnableThreadState() +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} diff --git a/native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt b/native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt new file mode 100644 index 00000000000..2251efeb201 --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + try { + runCallback(staticCFunction { -> + assertRunnableThreadState() + runCallback(staticCFunction(::throwException)) + }) + } catch (e: CustomException) { + assertRunnableThreadState() + return + } catch (e: Throwable) { + assertRunnableThreadState() + fail("Wrong exception type: ${e.message}") + } + fail("No exception thrown") +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} + +class CustomException() : Exception() + +fun throwException() { + assertRunnableThreadState() + throw CustomException() +} diff --git a/native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt b/native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt new file mode 100644 index 00000000000..8375857bcee --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.staticCFunction +import threadStates.* + +fun main() { + try { + runCallback(staticCFunction { -> + assertRunnableThreadState() + runCallback(staticCFunction(::throwException)) + }) + } catch (e: CustomException) { + assertRunnableThreadState() + return + } finally { + assertRunnableThreadState() + } + fail("No exception thrown") +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} + +class CustomException() : Exception() + +fun throwException() { + assertRunnableThreadState() + throw CustomException() +} diff --git a/native/native.tests/testData/standalone/threadStates/nestedCalls.kt b/native/native.tests/testData/standalone/threadStates/nestedCalls.kt new file mode 100644 index 00000000000..d8bc9c8ba7b --- /dev/null +++ b/native/native.tests/testData/standalone/threadStates/nestedCalls.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +// TARGET_BACKEND: NATIVE +// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative +// MODULE: cinterop +// FILE: threadStates.def +language = C +--- +#include + +void assertNativeThreadState(); + +void runCallback(void(*callback)(void)) { + assertNativeThreadState(); + callback(); + assertNativeThreadState(); +} + +int32_t answer() { + assertNativeThreadState(); + return 42; +} + +// FILE: threadStates.cpp +#include +#include + +// Implemented in the runtime for test purposes. +extern "C" bool Kotlin_Debugging_isThreadStateNative(); + +extern "C" void assertNativeThreadState() { + if (!Kotlin_Debugging_isThreadStateNative()) { + printf("Incorrect thread state. Expected native thread state."); + abort(); + } +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlinx.cinterop.ExperimentalForeignApi::class) + +import kotlin.native.runtime.Debugging +import kotlin.test.* +import kotlinx.cinterop.* +import threadStates.* + +fun main() { + runCallback(staticCFunction { -> + assertRunnableThreadState() + answer() + Unit + }) + assertRunnableThreadState() +} + +fun assertRunnableThreadState() { + assertTrue(Debugging.isThreadStateRunnable) +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index 3395ec753a7..26683b6f71f 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -4928,6 +4928,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/cinterop/basics/mangling_keywords2.kt"); } + @Test + @TestMetadata("statbuf.kt") + public void testStatbuf() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/basics/statbuf.kt"); + } + @Test @TestMetadata("structAnonRecordMember_ExplicitAlignment.kt") public void testStructAnonRecordMember_ExplicitAlignment() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index 3d8fafa9be9..2b1594cbdda 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -5040,6 +5040,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/cinterop/basics/mangling_keywords2.kt"); } + @Test + @TestMetadata("statbuf.kt") + public void testStatbuf() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/basics/statbuf.kt"); + } + @Test @TestMetadata("structAnonRecordMember_ExplicitAlignment.kt") public void testStructAnonRecordMember_ExplicitAlignment() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java index 9cdc683db95..f71a073484c 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeStandaloneTestGenerated.java @@ -48,12 +48,30 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/console"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test + @TestMetadata("fprintf.kt") + public void testFprintf() throws Exception { + runTest("native/native.tests/testData/standalone/console/fprintf.kt"); + } + + @Test + @TestMetadata("printf.kt") + public void testPrintf() throws Exception { + runTest("native/native.tests/testData/standalone/console/printf.kt"); + } + @Test @TestMetadata("println.kt") public void testPrintln() throws Exception { runTest("native/native.tests/testData/standalone/console/println.kt"); } + @Test + @TestMetadata("puts.kt") + public void testPuts() throws Exception { + runTest("native/native.tests/testData/standalone/console/puts.kt"); + } + @Test @TestMetadata("readLine.kt") public void testReadLine() throws Exception { @@ -186,6 +204,12 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest runTest("native/native.tests/testData/standalone/termination/terminateWithUnhandledException.kt"); } + @Test + @TestMetadata("unhandledException.kt") + public void testUnhandledException() throws Exception { + runTest("native/native.tests/testData/standalone/termination/unhandledException.kt"); + } + @Test @TestMetadata("unhandledExceptionHookClosure.kt") public void testUnhandledExceptionHookClosure() throws Exception { @@ -227,5 +251,86 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest public void testUnhandledExceptionHookWithProcess() throws Exception { runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookWithProcess.kt"); } + + @Test + @TestMetadata("unhandledExceptionInForeignThread.kt") + public void testUnhandledExceptionInForeignThread() throws Exception { + runTest("native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/standalone/threadStates") + @TestDataPath("$PROJECT_ROOT") + @Tag("standalone") + @EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR") + @UseStandardTestCaseGroupProvider() + @Tag("frontend-fir") + @FirPipeline() + public class ThreadStates { + @Test + public void testAllFilesPresentInThreadStates() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/threadStates"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("callback.kt") + public void testCallback() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callback.kt"); + } + + @Test + @TestMetadata("callbackOnSeparateThread.kt") + public void testCallbackOnSeparateThread() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt"); + } + + @Test + @TestMetadata("callbackWithException.kt") + public void testCallbackWithException() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithException.kt"); + } + + @Test + @TestMetadata("callbackWithFinally.kt") + public void testCallbackWithFinally() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt"); + } + + @Test + @TestMetadata("callbackWithFinallyNoCatch.kt") + public void testCallbackWithFinallyNoCatch() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt"); + } + + @Test + @TestMetadata("directStaticCFunctionCall.kt") + public void testDirectStaticCFunctionCall() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt"); + } + + @Test + @TestMetadata("nativeCall.kt") + public void testNativeCall() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nativeCall.kt"); + } + + @Test + @TestMetadata("nestedCallbackWithException.kt") + public void testNestedCallbackWithException() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt"); + } + + @Test + @TestMetadata("nestedCallbackWithFinally.kt") + public void testNestedCallbackWithFinally() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt"); + } + + @Test + @TestMetadata("nestedCalls.kt") + public void testNestedCalls() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCalls.kt"); + } } } diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index ef246ec52af..2d42c5b979a 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -4816,6 +4816,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/cinterop/basics/mangling_keywords2.kt"); } + @Test + @TestMetadata("statbuf.kt") + public void testStatbuf() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/basics/statbuf.kt"); + } + @Test @TestMetadata("structAnonRecordMember_ExplicitAlignment.kt") public void testStructAnonRecordMember_ExplicitAlignment() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index a0446d621e9..da7fc54dbb8 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -4929,6 +4929,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/cinterop/basics/mangling_keywords2.kt"); } + @Test + @TestMetadata("statbuf.kt") + public void testStatbuf() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/basics/statbuf.kt"); + } + @Test @TestMetadata("structAnonRecordMember_ExplicitAlignment.kt") public void testStructAnonRecordMember_ExplicitAlignment() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java index 93f75833544..feaba454c1c 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeStandaloneTestGenerated.java @@ -43,12 +43,30 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/console"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test + @TestMetadata("fprintf.kt") + public void testFprintf() throws Exception { + runTest("native/native.tests/testData/standalone/console/fprintf.kt"); + } + + @Test + @TestMetadata("printf.kt") + public void testPrintf() throws Exception { + runTest("native/native.tests/testData/standalone/console/printf.kt"); + } + @Test @TestMetadata("println.kt") public void testPrintln() throws Exception { runTest("native/native.tests/testData/standalone/console/println.kt"); } + @Test + @TestMetadata("puts.kt") + public void testPuts() throws Exception { + runTest("native/native.tests/testData/standalone/console/puts.kt"); + } + @Test @TestMetadata("readLine.kt") public void testReadLine() throws Exception { @@ -177,6 +195,12 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest { runTest("native/native.tests/testData/standalone/termination/terminateWithUnhandledException.kt"); } + @Test + @TestMetadata("unhandledException.kt") + public void testUnhandledException() throws Exception { + runTest("native/native.tests/testData/standalone/termination/unhandledException.kt"); + } + @Test @TestMetadata("unhandledExceptionHookClosure.kt") public void testUnhandledExceptionHookClosure() throws Exception { @@ -218,5 +242,84 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest { public void testUnhandledExceptionHookWithProcess() throws Exception { runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookWithProcess.kt"); } + + @Test + @TestMetadata("unhandledExceptionInForeignThread.kt") + public void testUnhandledExceptionInForeignThread() throws Exception { + runTest("native/native.tests/testData/standalone/termination/unhandledExceptionInForeignThread.kt"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/standalone/threadStates") + @TestDataPath("$PROJECT_ROOT") + @Tag("standalone") + @EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR") + @UseStandardTestCaseGroupProvider() + public class ThreadStates { + @Test + public void testAllFilesPresentInThreadStates() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/threadStates"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("callback.kt") + public void testCallback() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callback.kt"); + } + + @Test + @TestMetadata("callbackOnSeparateThread.kt") + public void testCallbackOnSeparateThread() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackOnSeparateThread.kt"); + } + + @Test + @TestMetadata("callbackWithException.kt") + public void testCallbackWithException() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithException.kt"); + } + + @Test + @TestMetadata("callbackWithFinally.kt") + public void testCallbackWithFinally() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithFinally.kt"); + } + + @Test + @TestMetadata("callbackWithFinallyNoCatch.kt") + public void testCallbackWithFinallyNoCatch() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/callbackWithFinallyNoCatch.kt"); + } + + @Test + @TestMetadata("directStaticCFunctionCall.kt") + public void testDirectStaticCFunctionCall() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/directStaticCFunctionCall.kt"); + } + + @Test + @TestMetadata("nativeCall.kt") + public void testNativeCall() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nativeCall.kt"); + } + + @Test + @TestMetadata("nestedCallbackWithException.kt") + public void testNestedCallbackWithException() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCallbackWithException.kt"); + } + + @Test + @TestMetadata("nestedCallbackWithFinally.kt") + public void testNestedCallbackWithFinally() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCallbackWithFinally.kt"); + } + + @Test + @TestMetadata("nestedCalls.kt") + public void testNestedCalls() throws Exception { + runTest("native/native.tests/testData/standalone/threadStates/nestedCalls.kt"); + } } }