From af566dd454ee2baadf49269ea200f1a52280afe1 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 27 Apr 2022 10:55:57 +0500 Subject: [PATCH] [K/N][tests] Added test for KT-51925 --- .../backend.native/tests/build.gradle | 13 +++++++++++ .../tests/interop/kt51925/kt51925.def | 9 ++++++++ .../tests/interop/kt51925/kt51925_lib.kt | 23 +++++++++++++++++++ .../tests/interop/kt51925/kt51925_main.kt | 9 ++++++++ .../tests/interop/kt51925/kt51925_main.out | 2 ++ 5 files changed, 56 insertions(+) create mode 100644 kotlin-native/backend.native/tests/interop/kt51925/kt51925.def create mode 100644 kotlin-native/backend.native/tests/interop/kt51925/kt51925_lib.kt create mode 100644 kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.kt create mode 100644 kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.out diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 861ca1489fd..3f01b4d647c 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4230,6 +4230,10 @@ createInterop("kt44283") { it.defFile 'interop/kt44283/kt44283.def' } +createInterop("kt51925") { + it.defFile 'interop/kt51925/kt51925.def' +} + createInterop("kt43502") { it.defFile 'interop/kt43502/kt43502.def' it.headers "$projectDir/interop/kt43502/kt43502.h" @@ -4685,6 +4689,15 @@ interopTest("interop_kt44283") { source = "interop/kt44283/main.kt" } +// TODO: This test should be run with caches on. +interopTest("interop_kt51925") { + disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + interop = 'kt51925' + lib = 'interop/kt51925/kt51925_lib.kt' + source = 'interop/kt51925/kt51925_main.kt' + useGoldenData = true +} + dynamicTest("interop_kt43502") { disabled = (project.testTarget == 'wasm32') // wasm doesn't support -produce dynamic interop = "kt43502" diff --git a/kotlin-native/backend.native/tests/interop/kt51925/kt51925.def b/kotlin-native/backend.native/tests/interop/kt51925/kt51925.def new file mode 100644 index 00000000000..b46afe2b15b --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/kt51925/kt51925.def @@ -0,0 +1,9 @@ +strictEnums = E +--- +enum E { + X = 1, Y = 2, Z = 42 +}; + +typedef struct { + int d; +} Struct; \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/kt51925/kt51925_lib.kt b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_lib.kt new file mode 100644 index 00000000000..5113481f17b --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_lib.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2022 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. + */ + +import kt51925.* +import kotlinx.cinterop.* + +fun bar1(e: E) = e.value + +inline fun foo1() = bar1(E.Z) + +fun bar2(s: Struct): Int { + return s.d +} + +inline fun foo2(): Int { + memScoped { + val s = alloc() + s.d = 42 + return bar2(s) + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.kt b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.kt new file mode 100644 index 00000000000..52540d8c2f5 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2010-2022 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. + */ + +fun main() { + println(foo1()) + println(foo2()) +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.out b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.out new file mode 100644 index 00000000000..daaac9e3030 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/kt51925/kt51925_main.out @@ -0,0 +1,2 @@ +42 +42