From c06875b8e98f701584b74be80b766c275e760a6e Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Mon, 15 Nov 2021 11:58:21 +0300 Subject: [PATCH] [K/N] Added test for exceptions behaviour in case of dynamic libs (KT-47828) --- kotlin-native/backend.native/tests/build.gradle | 9 +++++++++ .../tests/interop/exceptions/exceptionHook.cpp | 11 +++++++++++ .../tests/interop/exceptions/exceptionHook.kt | 11 +++++++++++ 3 files changed, 31 insertions(+) create mode 100644 kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp create mode 100644 kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index a52158569a9..61963e3df31 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5152,6 +5152,15 @@ dynamicTest("interop_exceptions_throwThroughBridge") { interop = "exceptions_throwThroughBridge" } +dynamicTest("interop_kotlin_exception_hook") { + disabled = (project.testTarget == 'wasm32') // Uses exceptions + dynamic is unsupported for wasm. + source = "interop/exceptions/exceptionHook.kt" + cSource = "$projectDir/interop/exceptions/exceptionHook.cpp" + clangTool = "clang++" + expectedExitStatusChecker = { it != 0 } + outputChecker = { s -> s.contains("OK. Kotlin unhandled exception hook") } +} + interopTest("interop_exceptions_cCallback") { disabled = (project.testTarget == 'wasm32') // Uses exceptions source = "interop/exceptions/cCallback.kt" diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp new file mode 100644 index 00000000000..6b1ad80cabb --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp @@ -0,0 +1,11 @@ +#include "testlib_api.h" + +#include + +int main(int argc, char** argv) { + try { + testlib_symbols()->kotlin.root.setHookAndThrow(); + } catch (...) { + printf("FAIL. Native catch.\n"); + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt new file mode 100644 index 00000000000..94adb7f23a9 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt @@ -0,0 +1,11 @@ +import kotlin.native.concurrent.freeze + +// KT-47828 +fun setHookAndThrow() { + val hook = { _: Throwable -> + println("OK. Kotlin unhandled exception hook") + } + hook.freeze() + setUnhandledExceptionHook(hook) + throw Exception("Error") +} \ No newline at end of file