diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 5489b73497f..8e56e7fbb94 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -3372,18 +3372,6 @@ createInterop("sockets") { it.defFile 'interop/basics/sockets.def' } -createInterop("bitfields") { - it.defFile 'interop/basics/bitfields.def' -} - -createInterop("cglobals") { - it.defFile 'interop/basics/cglobals.def' -} - -createInterop("cfunptr") { - it.defFile 'interop/basics/cfunptr.def' -} - createInterop("cmacros") { it.defFile 'interop/basics/cmacros.def' } @@ -3392,10 +3380,6 @@ createInterop("cunsupported") { it.defFile 'interop/basics/cunsupported.def' } -createInterop("ctoKString") { - it.defFile 'interop/basics/ctoKString.def' -} - createInterop("ctypes") { it.defFile 'interop/basics/ctypes.def' } @@ -3416,10 +3400,6 @@ createInterop("cstructs") { it.defFile 'interop/basics/cstructs.def' } -createInterop("ccallbacksAndVarargs") { - it.defFile 'interop/basics/ccallbacksAndVarargs.def' -} - createInterop("cmangling") { it.defFile 'interop/basics/mangling.def' } @@ -3440,22 +3420,6 @@ createInterop("cunion") { it.defFile 'interop/basics/cunion.def' } -createInterop("cenums") { - it.defFile 'interop/basics/cenums.def' -} - -createInterop("carrayPointers") { - it.defFile 'interop/basics/carrayPointers.def' -} - -createInterop("auxiliaryCppSources") { - // We need to provide empty def file to create correct `KonanInteropTask`. - it.defFile 'interop/auxiliary_sources/auxiliaryCppSources.def' - it.headers "$projectDir/interop/auxiliary_sources/name.h" - it.extraOpts "-Xcompile-source", "$projectDir/interop/auxiliary_sources/name.cpp" - it.extraOpts "-Xsource-compiler-option", "-std=c++17" -} - createInterop("concurrentTerminate") { it.defFile 'interop/concurrentTerminate/concurrentTerminate.def' it.headers "$projectDir/interop/concurrentTerminate/async.h" @@ -3464,12 +3428,6 @@ createInterop("concurrentTerminate") { it.extraOpts "-Xsource-compiler-option", "-std=c++17" } -createInterop("incomplete_types") { - it.defFile 'interop/incomplete_types/library.def' - it.headers "$projectDir/interop/incomplete_types/library.h" - it.extraOpts "-Xcompile-source", "$projectDir/interop/incomplete_types/library.cpp" -} - createInterop("embedStaticLibraries") { it.defFile 'interop/embedStaticLibraries/embedStaticLibraries.def' it.headers "$projectDir/interop/embedStaticLibraries/embedStaticLibraries.h" @@ -3494,27 +3452,10 @@ createInterop("embedStaticLibraries") { it.extraOpts '-staticLibrary', "2.a" } -createInterop("kt43265") { - it.defFile 'interop/kt43265/kt43265.def' -} - -createInterop("kt44283") { - it.defFile 'interop/kt44283/kt44283.def' -} - createInterop("kt51925") { it.defFile 'interop/kt51925/kt51925.def' } -createInterop("kt54284") { - it.defFile 'interop/kt54284/kt54284.def' -} - -createInterop("kt54284_fmodules") { - it.defFile 'interop/kt54284/kt54284.def' - it.extraOpts '-compiler-option', '-fmodules' -} - createInterop("kt43502") { it.defFile 'interop/kt43502/kt43502.def' it.headers "$projectDir/interop/kt43502/kt43502.h" @@ -3566,10 +3507,6 @@ createInterop("workerSignals") { it.extraOpts "-Xcompile-source", "$projectDir/interop/workerSignals/workerSignals.cpp" } -createInterop("cForwardDeclarations") { - it.defFile "interop/forwardDeclarations/cForwardDeclarations.def" -} - createInterop("cForwardDeclarationsTwoLibs1") { it.defFile "interop/forwardDeclarationsTwoLibs/cForwardDeclarationsTwoLibs1.def" } @@ -3836,23 +3773,6 @@ standaloneTest("interop5") { UtilsKt.dependsOnPlatformLibs(it) } -interopTest("interop_bitfields") { - disabled = isAggressiveGC // TODO: Investigate why too slow - source = "interop/basics/bf.kt" - interop = 'bitfields' -} - -interopTest("interop_funptr") { - useGoldenData = true - source = "interop/basics/funptr.kt" - interop = 'cfunptr' -} - -interopTest("interop_globals") { - source = "interop/basics/globals.kt" - interop = 'cglobals' -} - interopTest("interop_macros") { source = "interop/basics/macros.kt" interop = 'cmacros' @@ -3863,11 +3783,6 @@ interopTest("interop_unsupported") { interop = 'cunsupported' } -interopTest("interop_toKString") { - source = "interop/basics/toKString.kt" - interop = 'ctoKString' -} - interopTest("interop_types") { source = "interop/basics/types.kt" interop = 'ctypes' @@ -3903,11 +3818,6 @@ interopTest("interop_mangling_keywords2") { interop = 'cmangling_keywords2' } -interopTest("interop_auxiliarySources") { - source = "interop/auxiliary_sources/main.kt" - interop = 'auxiliaryCppSources' -} - interopTest("interop_concurrentTerminate") { source = "interop/concurrentTerminate/main.kt" interop = 'concurrentTerminate' @@ -3915,11 +3825,6 @@ interopTest("interop_concurrentTerminate") { expectedExitStatus = 99 } -interopTest("interop_incompleteTypes") { - source = "interop/incomplete_types/main.kt" - interop = 'incomplete_types' -} - interopTest("interop_embedStaticLibraries") { source = "interop/embedStaticLibraries/main.kt" interop = 'embedStaticLibraries' @@ -3935,11 +3840,6 @@ interopTest("interop_structs") { interop = 'cstructs' } -interopTest("interop_callbacksAndVarargs") { - source = "interop/basics/callbacksAndVarargs.kt" - interop = 'ccallbacksAndVarargs' -} - interopTest("interop_threadStates") { source = "interop/threadStates/threadStates.kt" flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative'] @@ -3982,39 +3882,6 @@ interopTest("interop_union") { source = "interop/basics/union.kt" } -interopTest("interop_enums") { - interop = 'cenums' - flags = ['-XXLanguage:+EnumEntries'] - source = "interop/basics/enums.kt" -} - -interopTest("interop_array_pointers") { - interop = 'carrayPointers' - source = "interop/basics/arrayPointers.kt" -} - -interopTest("interop_kt43265") { - interop = 'kt43265' - source = "interop/kt43265/usage.kt" -} - -interopTest("interop_kt44283") { - disabled = project.globalTestArgs.contains('-opt') // Incompatible with -g. - flags = ['-g'] - interop = 'kt44283' - source = "interop/kt44283/main.kt" -} - -interopTest("interop_kt54284") { - interop = 'kt54284' - source = "interop/kt54284/main.kt" -} - -interopTest("interop_kt54284_fmodules") { - interop = 'kt54284_fmodules' - source = "interop/kt54284/main.kt" -} - // TODO: This test should be run with caches on. interopTest("interop_kt51925") { interop = 'kt51925' @@ -4038,11 +3905,6 @@ dynamicTest("interop_kt43502") { useGoldenData = true } -interopTest("interop_leakMemoryWithRunningThreadUnchecked") { - interop = 'leakMemoryWithRunningThread' - source = "interop/leakMemoryWithRunningThread/unchecked.kt" -} - interopTest("interop_leakMemoryWithRunningThreadChecked") { interop = 'leakMemoryWithRunningThread' source = "interop/leakMemoryWithRunningThread/checked.kt" @@ -4102,11 +3964,6 @@ interopTest("interop_workerSignals") { interop = "workerSignals" } -interopTest("interop_forwardDeclarations") { - source = "interop/forwardDeclarations/forwardDeclarations.kt" - interop = "cForwardDeclarations" -} - interopTest("interop_forwardDeclarationsTwoLibs") { source = "interop/forwardDeclarationsTwoLibs/forwardDeclarationsTwoLibs.kt" interop = "cForwardDeclarationsTwoLibs1" diff --git a/kotlin-native/backend.native/tests/interop/auxiliary_sources/auxiliaryCppSources.def b/kotlin-native/backend.native/tests/interop/auxiliary_sources/auxiliaryCppSources.def deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/library.def b/kotlin-native/backend.native/tests/interop/incomplete_types/library.def deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/kotlin-native/backend.native/tests/interop/basics/carrayPointers.def b/native/native.tests/testData/CInterop/executable/arrayPointers/arrayPointers.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/carrayPointers.def rename to native/native.tests/testData/CInterop/executable/arrayPointers/arrayPointers.def diff --git a/kotlin-native/backend.native/tests/interop/basics/arrayPointers.kt b/native/native.tests/testData/CInterop/executable/arrayPointers/arrayPointers.kt similarity index 94% rename from kotlin-native/backend.native/tests/interop/basics/arrayPointers.kt rename to native/native.tests/testData/CInterop/executable/arrayPointers/arrayPointers.kt index f33cdb3613d..61c019babc3 100644 --- a/kotlin-native/backend.native/tests/interop/basics/arrayPointers.kt +++ b/native/native.tests/testData/CInterop/executable/arrayPointers/arrayPointers.kt @@ -1,6 +1,6 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import carrayPointers.* +import arrayPointers.* import kotlin.test.* import kotlinx.cinterop.* diff --git a/kotlin-native/backend.native/tests/interop/auxiliary_sources/name.h b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.aux.h similarity index 100% rename from kotlin-native/backend.native/tests/interop/auxiliary_sources/name.h rename to native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.aux.h diff --git a/kotlin-native/backend.native/tests/interop/auxiliary_sources/name.cpp b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.cpp similarity index 76% rename from kotlin-native/backend.native/tests/interop/auxiliary_sources/name.cpp rename to native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.cpp index 14f6b211d85..3f321734742 100644 --- a/kotlin-native/backend.native/tests/interop/auxiliary_sources/name.cpp +++ b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.cpp @@ -1,5 +1,5 @@ #include -#include "name.h" +#include "auxiliarySources.aux.h" static std::string _name = "Hello from C++"; diff --git a/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.def b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.def new file mode 100644 index 00000000000..4389c1838fa --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.def @@ -0,0 +1,2 @@ +# The def file is empty intentianally +# `auxiliarySources.aux.h` is meant to be included via `-header` option of cinterop tool diff --git a/kotlin-native/backend.native/tests/interop/auxiliary_sources/main.kt b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.kt similarity index 86% rename from kotlin-native/backend.native/tests/interop/auxiliary_sources/main.kt rename to native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.kt index 2bba4e61263..3812cfb5b30 100644 --- a/kotlin-native/backend.native/tests/interop/auxiliary_sources/main.kt +++ b/native/native.tests/testData/CInterop/executable/auxiliarySources/auxiliarySources.kt @@ -1,6 +1,6 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import auxiliaryCppSources.* +import auxiliarySources.* import kotlin.test.* import kotlinx.cinterop.* diff --git a/kotlin-native/backend.native/tests/interop/basics/bitfields.def b/native/native.tests/testData/CInterop/executable/bitfields/bitfields.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/bitfields.def rename to native/native.tests/testData/CInterop/executable/bitfields/bitfields.def diff --git a/kotlin-native/backend.native/tests/interop/basics/bf.kt b/native/native.tests/testData/CInterop/executable/bitfields/bitfields.kt similarity index 97% rename from kotlin-native/backend.native/tests/interop/basics/bf.kt rename to native/native.tests/testData/CInterop/executable/bitfields/bitfields.kt index ef6739c61e3..e2aa9432dbb 100644 --- a/kotlin-native/backend.native/tests/interop/basics/bf.kt +++ b/native/native.tests/testData/CInterop/executable/bitfields/bitfields.kt @@ -2,6 +2,8 @@ * 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. */ +// May need disabling when gcSchedulerType=aggressive . since it may be too slow + @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import bitfields.* diff --git a/kotlin-native/backend.native/tests/interop/basics/ccallbacksAndVarargs.def b/native/native.tests/testData/CInterop/executable/callbacksAndVarargs/callbacksAndVarargs.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/ccallbacksAndVarargs.def rename to native/native.tests/testData/CInterop/executable/callbacksAndVarargs/callbacksAndVarargs.def diff --git a/kotlin-native/backend.native/tests/interop/basics/callbacksAndVarargs.kt b/native/native.tests/testData/CInterop/executable/callbacksAndVarargs/callbacksAndVarargs.kt similarity index 98% rename from kotlin-native/backend.native/tests/interop/basics/callbacksAndVarargs.kt rename to native/native.tests/testData/CInterop/executable/callbacksAndVarargs/callbacksAndVarargs.kt index 30276377e53..514b2927aa2 100644 --- a/kotlin-native/backend.native/tests/interop/basics/callbacksAndVarargs.kt +++ b/native/native.tests/testData/CInterop/executable/callbacksAndVarargs/callbacksAndVarargs.kt @@ -6,7 +6,7 @@ import kotlin.test.* import kotlinx.cinterop.* -import ccallbacksAndVarargs.* +import callbacksAndVarargs.* fun main() { testStructCallbacks() diff --git a/kotlin-native/backend.native/tests/interop/basics/cenums.def b/native/native.tests/testData/CInterop/executable/enums/enums.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/cenums.def rename to native/native.tests/testData/CInterop/executable/enums/enums.def diff --git a/kotlin-native/backend.native/tests/interop/basics/enums.kt b/native/native.tests/testData/CInterop/executable/enums/enums.kt similarity index 95% rename from kotlin-native/backend.native/tests/interop/basics/enums.kt rename to native/native.tests/testData/CInterop/executable/enums/enums.kt index b147bdab53e..f568038f2da 100644 --- a/kotlin-native/backend.native/tests/interop/basics/enums.kt +++ b/native/native.tests/testData/CInterop/executable/enums/enums.kt @@ -2,9 +2,10 @@ * Copyright 2010-2023 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. */ +// !LANGUAGE: +EnumEntries @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import cenums.* +import enums.* import kotlinx.cinterop.* import kotlin.test.* diff --git a/kotlin-native/backend.native/tests/interop/forwardDeclarations/cForwardDeclarations.def b/native/native.tests/testData/CInterop/executable/forwardDeclarations/forwardDeclarations.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/forwardDeclarations/cForwardDeclarations.def rename to native/native.tests/testData/CInterop/executable/forwardDeclarations/forwardDeclarations.def diff --git a/kotlin-native/backend.native/tests/interop/forwardDeclarations/forwardDeclarations.kt b/native/native.tests/testData/CInterop/executable/forwardDeclarations/forwardDeclarations.kt similarity index 97% rename from kotlin-native/backend.native/tests/interop/forwardDeclarations/forwardDeclarations.kt rename to native/native.tests/testData/CInterop/executable/forwardDeclarations/forwardDeclarations.kt index e38cde37f27..282d68cef3b 100644 --- a/kotlin-native/backend.native/tests/interop/forwardDeclarations/forwardDeclarations.kt +++ b/native/native.tests/testData/CInterop/executable/forwardDeclarations/forwardDeclarations.kt @@ -1,7 +1,7 @@ // This test mostly checks frontend behaviour. @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import cForwardDeclarations.* +import forwardDeclarations.* import cnames.structs.StructDeclared import kotlin.test.assertEquals diff --git a/kotlin-native/backend.native/tests/interop/basics/cfunptr.def b/native/native.tests/testData/CInterop/executable/funptr/funptr.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/cfunptr.def rename to native/native.tests/testData/CInterop/executable/funptr/funptr.def diff --git a/kotlin-native/backend.native/tests/interop/basics/funptr.kt b/native/native.tests/testData/CInterop/executable/funptr/funptr.kt similarity index 97% rename from kotlin-native/backend.native/tests/interop/basics/funptr.kt rename to native/native.tests/testData/CInterop/executable/funptr/funptr.kt index b5e81736818..686a9adcee3 100644 --- a/kotlin-native/backend.native/tests/interop/basics/funptr.kt +++ b/native/native.tests/testData/CInterop/executable/funptr/funptr.kt @@ -1,3 +1,4 @@ +// OUT_DATA_FILE: funptr.out /* * 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. @@ -5,7 +6,7 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) import kotlinx.cinterop.* -import cfunptr.* +import funptr.* import kotlin.test.* typealias NotSoLongSignatureFunction = ( diff --git a/kotlin-native/backend.native/tests/interop/basics/funptr.out b/native/native.tests/testData/CInterop/executable/funptr/funptr.out similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/funptr.out rename to native/native.tests/testData/CInterop/executable/funptr/funptr.out diff --git a/kotlin-native/backend.native/tests/interop/basics/cglobals.def b/native/native.tests/testData/CInterop/executable/globals/globals.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/cglobals.def rename to native/native.tests/testData/CInterop/executable/globals/globals.def diff --git a/kotlin-native/backend.native/tests/interop/basics/globals.kt b/native/native.tests/testData/CInterop/executable/globals/globals.kt similarity index 97% rename from kotlin-native/backend.native/tests/interop/basics/globals.kt rename to native/native.tests/testData/CInterop/executable/globals/globals.kt index df57370636a..b790bdcda30 100644 --- a/kotlin-native/backend.native/tests/interop/basics/globals.kt +++ b/native/native.tests/testData/CInterop/executable/globals/globals.kt @@ -5,7 +5,7 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.experimental.ExperimentalNativeApi::class) import kotlinx.cinterop.* -import cglobals.* +import globals.* fun main(args: Array) { assert(g1__ == 42) diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/library.h b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.aux.h similarity index 100% rename from kotlin-native/backend.native/tests/interop/incomplete_types/library.h rename to native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.aux.h diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.cpp similarity index 95% rename from kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp rename to native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.cpp index 32ff138ba85..441e9b08833 100644 --- a/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp +++ b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.cpp @@ -1,5 +1,5 @@ #include -#include "library.h" +#include "incompleteTypes.aux.h" extern "C" { diff --git a/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.def b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.def new file mode 100644 index 00000000000..a20fcb74b4d --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.def @@ -0,0 +1,2 @@ +# The def file is empty intentianally +# `incompleteTypes.aux.h` is meant to be included via `-header` option of cinterop tool diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.kt similarity index 96% rename from kotlin-native/backend.native/tests/interop/incomplete_types/main.kt rename to native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.kt index 80d53c32a02..880183f47d6 100644 --- a/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt +++ b/native/native.tests/testData/CInterop/executable/incompleteTypes/incompleteTypes.kt @@ -1,6 +1,6 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import library.* +import incompleteTypes.* import kotlinx.cinterop.* import kotlin.test.* diff --git a/kotlin-native/backend.native/tests/interop/kt43265/kt43265.def b/native/native.tests/testData/CInterop/executable/kt43265/kt43265.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/kt43265/kt43265.def rename to native/native.tests/testData/CInterop/executable/kt43265/kt43265.def diff --git a/kotlin-native/backend.native/tests/interop/kt43265/usage.kt b/native/native.tests/testData/CInterop/executable/kt43265/kt43265.kt similarity index 79% rename from kotlin-native/backend.native/tests/interop/kt43265/usage.kt rename to native/native.tests/testData/CInterop/executable/kt43265/kt43265.kt index 7ccdca15207..8e3c5d62c66 100644 --- a/kotlin-native/backend.native/tests/interop/kt43265/usage.kt +++ b/native/native.tests/testData/CInterop/executable/kt43265/kt43265.kt @@ -1,6 +1,7 @@ import kt43265.* import kotlin.test.* +@kotlinx.cinterop.ExperimentalForeignApi fun main() { assertEquals(bcm2835FunctionSelect.BCM2835_GPIO_FSEL_ALT3, bcm2835FunctionSelect.BCM2835_GPIO_FSEL_MASK) } \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/kt44283/kt44283.def b/native/native.tests/testData/CInterop/executable/kt44283/kt44283.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/kt44283/kt44283.def rename to native/native.tests/testData/CInterop/executable/kt44283/kt44283.def diff --git a/kotlin-native/backend.native/tests/interop/kt44283/main.kt b/native/native.tests/testData/CInterop/executable/kt44283/kt44283.kt similarity index 96% rename from kotlin-native/backend.native/tests/interop/kt44283/main.kt rename to native/native.tests/testData/CInterop/executable/kt44283/kt44283.kt index a4458552783..194b91bb919 100644 --- a/kotlin-native/backend.native/tests/interop/kt44283/main.kt +++ b/native/native.tests/testData/CInterop/executable/kt44283/kt44283.kt @@ -7,6 +7,7 @@ import kotlin.test.* val callbackCounter = AtomicInt(0) +@ExperimentalForeignApi fun main() { val func = staticCFunction, Unit> { kotlin.native.runtime.GC.collect() // Helps to ensure that "runtime" is already initialized. diff --git a/kotlin-native/backend.native/tests/interop/kt54284/kt54284.def b/native/native.tests/testData/CInterop/executable/kt54284/kt54284.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/kt54284/kt54284.def rename to native/native.tests/testData/CInterop/executable/kt54284/kt54284.def diff --git a/kotlin-native/backend.native/tests/interop/kt54284/main.kt b/native/native.tests/testData/CInterop/executable/kt54284/kt54284.kt similarity index 93% rename from kotlin-native/backend.native/tests/interop/kt54284/main.kt rename to native/native.tests/testData/CInterop/executable/kt54284/kt54284.kt index 9fca500b2af..726a2277a55 100644 --- a/kotlin-native/backend.native/tests/interop/kt54284/main.kt +++ b/native/native.tests/testData/CInterop/executable/kt54284/kt54284.kt @@ -2,6 +2,7 @@ import kotlinx.cinterop.* import kt54284.* import kotlin.test.* +@ExperimentalForeignApi fun main() { assertEquals("FILE:__FILE__", KFILE) assertEquals("LINE:__LINE__", KLINE) diff --git a/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.def b/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.def new file mode 100644 index 00000000000..226b6dedb1c --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.def @@ -0,0 +1,8 @@ +compilerOpts = -fmodules +--- +#define KFILE "FILE:" __FILE__ +#define KLINE "LINE:" __LINE__ +#define KTIME "TIME:" __TIME__ +#define KDATE "DATE:" __DATE__ +#define KFILENAME "NAME:" __FILE_NAME__ +#define KBASEFILE "BASE:" __BASE_FILE__ diff --git a/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.kt b/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.kt new file mode 100644 index 00000000000..321f5e9bc9c --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/kt54284_fmodules/kt54284_fmodules.kt @@ -0,0 +1,13 @@ +import kotlinx.cinterop.* +import kt54284_fmodules.* +import kotlin.test.* + +@ExperimentalForeignApi +fun main() { + assertEquals("FILE:__FILE__", KFILE) + assertEquals("LINE:__LINE__", KLINE) + assertEquals("TIME:__TIME__", KTIME) + assertEquals("DATE:__DATE__", KDATE) + assertEquals("NAME:__FILE_NAME__", KFILENAME) + assertEquals("BASE:__BASE_FILE__", KBASEFILE) +} diff --git a/native/native.tests/testData/CInterop/executable/KT-63048/library.def b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.def similarity index 53% rename from native/native.tests/testData/CInterop/executable/KT-63048/library.def rename to native/native.tests/testData/CInterop/executable/kt63048/kt63048.def index 7935e0cbdcc..7bc757c1528 100644 --- a/native/native.tests/testData/CInterop/executable/KT-63048/library.def +++ b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.def @@ -1,2 +1,2 @@ language = Objective-C -headers = library.h +headers = kt63048.h diff --git a/native/native.tests/testData/CInterop/executable/KT-63048/library.h b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.h similarity index 100% rename from native/native.tests/testData/CInterop/executable/KT-63048/library.h rename to native/native.tests/testData/CInterop/executable/kt63048/kt63048.h diff --git a/native/native.tests/testData/CInterop/executable/KT-63048/usage.kt b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.kt similarity index 97% rename from native/native.tests/testData/CInterop/executable/KT-63048/usage.kt rename to native/native.tests/testData/CInterop/executable/kt63048/kt63048.kt index 59593aba963..83822b1672b 100644 --- a/native/native.tests/testData/CInterop/executable/KT-63048/usage.kt +++ b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.kt @@ -1,6 +1,6 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.experimental.ExperimentalObjCName::class) -import library.* +import kt63048.* import kotlin.test.assertEquals @ObjCName("KotlinImplWithCompanionPropertyOverride") diff --git a/native/native.tests/testData/CInterop/executable/KT-63048/library.m b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.m similarity index 86% rename from native/native.tests/testData/CInterop/executable/KT-63048/library.m rename to native/native.tests/testData/CInterop/executable/kt63048/kt63048.m index 1a7a6a46cf5..e29178a6202 100644 --- a/native/native.tests/testData/CInterop/executable/KT-63048/library.m +++ b/native/native.tests/testData/CInterop/executable/kt63048/kt63048.m @@ -1,4 +1,4 @@ -#import "library.h" +#import "kt63048.h" @implementation WithClassProperty : NSObject -(instancetype) init {} diff --git a/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.cpp b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.cpp new file mode 100644 index 00000000000..f02e787ae99 --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.cpp @@ -0,0 +1,15 @@ +#include "leakMemoryWithRunningThreadUnchecked.h" + +#include +#include + +extern "C" void test_RunInNewThread(void (*f)()) { + std::atomic haveRun(false); + std::thread t([f, &haveRun]() { + f(); + haveRun = true; + while (true) {} + }); + t.detach(); + while (!haveRun) {} +} diff --git a/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.def b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.def new file mode 100644 index 00000000000..e5b0d0a250c --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.def @@ -0,0 +1,5 @@ +package leakMemoryWithRunningThreadUnchecked + +--- + +void test_RunInNewThread(void (*)()); diff --git a/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.h b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.h new file mode 100644 index 00000000000..2342ed9c920 --- /dev/null +++ b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +void test_RunInNewThread(void (*)()); + +#ifdef __cplusplus +} +#endif diff --git a/kotlin-native/backend.native/tests/interop/leakMemoryWithRunningThread/unchecked.kt b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.kt similarity index 79% rename from kotlin-native/backend.native/tests/interop/leakMemoryWithRunningThread/unchecked.kt rename to native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.kt index 480e1b94fb6..0b841788892 100644 --- a/kotlin-native/backend.native/tests/interop/leakMemoryWithRunningThread/unchecked.kt +++ b/native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/leakMemoryWithRunningThreadUnchecked.kt @@ -1,6 +1,10 @@ -@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class) +@file:OptIn( + kotlin.experimental.ExperimentalNativeApi::class, + kotlin.native.runtime.NativeRuntimeApi::class, + kotlinx.cinterop.ExperimentalForeignApi::class +) -import leakMemory.* +import leakMemoryWithRunningThreadUnchecked.* import kotlin.concurrent.AtomicInt import kotlin.native.concurrent.* import kotlin.native.Platform diff --git a/kotlin-native/backend.native/tests/interop/basics/ctoKString.def b/native/native.tests/testData/CInterop/executable/toKString/toKString.def similarity index 100% rename from kotlin-native/backend.native/tests/interop/basics/ctoKString.def rename to native/native.tests/testData/CInterop/executable/toKString/toKString.def diff --git a/kotlin-native/backend.native/tests/interop/basics/toKString.kt b/native/native.tests/testData/CInterop/executable/toKString/toKString.kt similarity index 95% rename from kotlin-native/backend.native/tests/interop/basics/toKString.kt rename to native/native.tests/testData/CInterop/executable/toKString/toKString.kt index c085b7d2d4b..083fbdc046f 100644 --- a/kotlin-native/backend.native/tests/interop/basics/toKString.kt +++ b/native/native.tests/testData/CInterop/executable/toKString/toKString.kt @@ -1,6 +1,6 @@ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -import ctoKString.* +import toKString.* import kotlinx.cinterop.* import kotlin.native.* import kotlin.test.* diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/ClassicNativeCInteropExecutableTest.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/ClassicNativeCInteropExecutableTest.java index c691cdc3acd..ee742fa1e54 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/ClassicNativeCInteropExecutableTest.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/ClassicNativeCInteropExecutableTest.java @@ -25,8 +25,98 @@ public class ClassicNativeCInteropExecutableTest extends AbstractNativeCInteropE } @Test - @TestMetadata("KT-63048") - public void testKT_63048() throws Exception { - runTest("native/native.tests/testData/CInterop/executable/KT-63048/"); + @TestMetadata("arrayPointers") + public void testArrayPointers() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/arrayPointers/"); + } + + @Test + @TestMetadata("auxiliarySources") + public void testAuxiliarySources() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/auxiliarySources/"); + } + + @Test + @TestMetadata("bitfields") + public void testBitfields() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/bitfields/"); + } + + @Test + @TestMetadata("callbacksAndVarargs") + public void testCallbacksAndVarargs() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/callbacksAndVarargs/"); + } + + @Test + @TestMetadata("enums") + public void testEnums() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/enums/"); + } + + @Test + @TestMetadata("forwardDeclarations") + public void testForwardDeclarations() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/forwardDeclarations/"); + } + + @Test + @TestMetadata("funptr") + public void testFunptr() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/funptr/"); + } + + @Test + @TestMetadata("globals") + public void testGlobals() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/globals/"); + } + + @Test + @TestMetadata("incompleteTypes") + public void testIncompleteTypes() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/incompleteTypes/"); + } + + @Test + @TestMetadata("kt43265") + public void testKt43265() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt43265/"); + } + + @Test + @TestMetadata("kt44283") + public void testKt44283() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt44283/"); + } + + @Test + @TestMetadata("kt54284") + public void testKt54284() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt54284/"); + } + + @Test + @TestMetadata("kt54284_fmodules") + public void testKt54284_fmodules() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt54284_fmodules/"); + } + + @Test + @TestMetadata("kt63048") + public void testKt63048() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt63048/"); + } + + @Test + @TestMetadata("leakMemoryWithRunningThreadUnchecked") + public void testLeakMemoryWithRunningThreadUnchecked() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/"); + } + + @Test + @TestMetadata("toKString") + public void testToKString() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/toKString/"); } } diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCInteropExecutableTest.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCInteropExecutableTest.java index 159d446577c..46c5eed6a0f 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCInteropExecutableTest.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCInteropExecutableTest.java @@ -29,8 +29,98 @@ public class FirNativeCInteropExecutableTest extends AbstractNativeCInteropExecu } @Test - @TestMetadata("KT-63048") - public void testKT_63048() throws Exception { - runTest("native/native.tests/testData/CInterop/executable/KT-63048/"); + @TestMetadata("arrayPointers") + public void testArrayPointers() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/arrayPointers/"); + } + + @Test + @TestMetadata("auxiliarySources") + public void testAuxiliarySources() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/auxiliarySources/"); + } + + @Test + @TestMetadata("bitfields") + public void testBitfields() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/bitfields/"); + } + + @Test + @TestMetadata("callbacksAndVarargs") + public void testCallbacksAndVarargs() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/callbacksAndVarargs/"); + } + + @Test + @TestMetadata("enums") + public void testEnums() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/enums/"); + } + + @Test + @TestMetadata("forwardDeclarations") + public void testForwardDeclarations() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/forwardDeclarations/"); + } + + @Test + @TestMetadata("funptr") + public void testFunptr() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/funptr/"); + } + + @Test + @TestMetadata("globals") + public void testGlobals() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/globals/"); + } + + @Test + @TestMetadata("incompleteTypes") + public void testIncompleteTypes() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/incompleteTypes/"); + } + + @Test + @TestMetadata("kt43265") + public void testKt43265() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt43265/"); + } + + @Test + @TestMetadata("kt44283") + public void testKt44283() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt44283/"); + } + + @Test + @TestMetadata("kt54284") + public void testKt54284() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt54284/"); + } + + @Test + @TestMetadata("kt54284_fmodules") + public void testKt54284_fmodules() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt54284_fmodules/"); + } + + @Test + @TestMetadata("kt63048") + public void testKt63048() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/kt63048/"); + } + + @Test + @TestMetadata("leakMemoryWithRunningThreadUnchecked") + public void testLeakMemoryWithRunningThreadUnchecked() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/leakMemoryWithRunningThreadUnchecked/"); + } + + @Test + @TestMetadata("toKString") + public void testToKString() throws Exception { + runTest("native/native.tests/testData/CInterop/executable/toKString/"); } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCInteropExecutableTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCInteropExecutableTest.kt index 231959e54a4..20e1855c6f3 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCInteropExecutableTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCInteropExecutableTest.kt @@ -20,24 +20,41 @@ import java.io.File abstract class AbstractNativeCInteropExecutableTest : AbstractNativeSimpleTest() { protected fun runTest(@TestDataFile testDataDir: String) { - val defFile = File(testDataDir, "library.def") + val testName = File(testDataDir).name + val defFile = File(testDataDir, "$testName.def") muteCInteropTestIfNecessary(defFile, targets.testTarget) - val mFile = File(testDataDir, "library.m") - val ktFile = File(testDataDir, "usage.kt") + val interopSourceFileM = File(testDataDir, "$testName.m") + val interopSourceFileCPP = File(testDataDir, "$testName.cpp") + val interopSourceFile = when { + interopSourceFileM.exists() -> interopSourceFileM + interopSourceFileCPP.exists() -> interopSourceFileCPP + else -> null + } + val ktFile = File(testDataDir, "$testName.kt") + val compilerArgs = buildList { + add("-compiler-option") + add("-I$testDataDir") + val auxHeader = File(testDataDir, "$testName.aux.h") + if (auxHeader.exists()) { + add("-header") + add(auxHeader.absolutePath) + } + interopSourceFile?.let { + add("-Xcompile-source") + add(it.absolutePath) + add("-Xsource-compiler-option") + add("-fobjc-arc") + add("-Xsource-compiler-option") + add("-DNS_FORMAT_ARGUMENT(A)=") + } + } val library = cinteropToLibrary( targets = targets, defFile = defFile, outputDir = buildDir, - freeCompilerArgs = TestCompilerArgs( - listOf( - "-compiler-option", "-I$testDataDir", - "-Xcompile-source", mFile.absolutePath, - "-Xsource-compiler-option", "-fobjc-arc", - "-Xsource-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=", - ) - ) + freeCompilerArgs = TestCompilerArgs(compilerArgs) ).assertSuccess().resultingArtifact val testCase = generateTestCaseWithSingleFile(