From bd688b3ef76abbe3c73bedde08f7c630a95c91a3 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Fri, 19 Jan 2024 13:07:57 +0100 Subject: [PATCH] [K/N][Tests] Migrate tests kt49034*.kt ^KT-61259 --- .../box/cinterop/objc/kt49034_objcclass.kt | 37 ++++++++++++ .../box/cinterop/objc/kt49034_struct.kt | 58 +++++++++++++++++++ .../backend.native/tests/build.gradle | 32 ---------- .../objc/kt49034/objcclass/kt49034.def | 1 - .../interop/objc/kt49034/objcclass/kt49034.h | 2 - .../interop/objc/kt49034/objcclass/main.kt | 13 ----- .../tests/interop/objc/kt49034/struct/main.kt | 16 ----- .../FirNativeCodegenBoxTestGenerated.java | 12 ++++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 12 ++++ .../NativeCodegenBoxTestGenerated.java | 12 ++++ .../NativeCodegenBoxTestNoPLGenerated.java | 12 ++++ .../support/group/ExtTestCaseGroupProvider.kt | 4 ++ 12 files changed, 147 insertions(+), 64 deletions(-) create mode 100644 compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt create mode 100644 compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt delete mode 100644 kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt diff --git a/compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt b/compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt new file mode 100644 index 00000000000..6ea06acad3e --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt @@ -0,0 +1,37 @@ +/* + * 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. + */ +// TARGET_BACKEND: NATIVE +// `import objcnames` somehow works only with NATIVE_STANDALONE test directive +// NATIVE_STANDALONE +// The test checks no collision between kt49034.__darwin_fp_control and platform.posix.__darwin_fp_control +// The test makes sense only on Apple x64 targets, where `class __darwin_fp_control` present in posix platform lib +// DISABLE_NATIVE: isAppleTarget=false +// DISABLE_NATIVE: targetArchitecture=ARM64 + +// MODULE: cinterop +// FILE: kt49034.def +headers = kt49034.h +language = Objective-C + +// FILE: kt49034.h +@class __darwin_fp_control; +void foo(__darwin_fp_control*); + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import objcnames.classes.__darwin_fp_control + +open class C + +class D : C<__darwin_fp_control>() + +fun box(): String { + println(D()) + return "OK" +} + +// FILE: checkPlatformDarwinFPControl.kt +import platform.posix.__darwin_fp_control diff --git a/compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt b/compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt new file mode 100644 index 00000000000..05fe200dca9 --- /dev/null +++ b/compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt @@ -0,0 +1,58 @@ +/* + * 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. + */ +// TARGET_BACKEND: NATIVE +// The test depends on collision between kt49034.JSContext and platform.JavaScriptCore.JSContext +// DISABLE_NATIVE: isAppleTarget=false +// There is no JavaScriptCore on watchOS. +// DISABLE_NATIVE: targetFamily=WATCHOS + +// MODULE: cinterop +// FILE: kt49034.def +headers = kt49034.h + +// FILE: kt49034.h +#ifdef __cplusplus +extern "C" { +#endif + +struct JSContext; + +struct JSContext* bar(); + +#ifdef __cplusplus +} +#endif + +// FILE: impl.c +#include "kt49034.h" + +struct JSContext { + int field; +}; + +struct JSContext global = { 15 }; + +extern "C" struct JSContext* bar() { + return &global; +} + +// MODULE: main(cinterop) +// FILE: main.kt +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) +import kt49034.bar +import cnames.structs.JSContext +import kotlinx.cinterop.CPointer + +fun baz(s: CPointer) { + println(s) +} + +fun box(): String { + baz(bar()!!) + return "OK" +} + +// FILE: checkPlatformJavaScriptCore.kt +import platform.JavaScriptCore.JSContext diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 402d1b305f0..1c83a98f0ec 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1170,20 +1170,6 @@ if (PlatformInfo.isAppleTarget(project)) { it.headers "$projectDir/interop/objc/kt55938/objclib.h" } - createInterop("kt49034_struct") { - it.defFile 'interop/objc/kt49034/struct/kt49034.def' - it.headers "$projectDir/interop/objc/kt49034/struct/kt49034.h" - it.extraOpts "-Xcompile-source", "$projectDir/interop/objc/kt49034/struct/impl.c" - } - - createInterop("kt49034_objcclass") { - it.defFile 'interop/objc/kt49034/objcclass/kt49034.def' - it.headers "$projectDir/interop/objc/kt49034/objcclass/kt49034.h" - } - createInterop("kt49034_objcprotocol") { - it.defFile 'interop/objc/kt49034/objcprotocol/kt49034.def' - it.headers "$projectDir/interop/objc/kt49034/objcprotocol/kt49034.h" - } createInterop("objc_include_categories") { it.defFile 'interop/objc/include_categories/objc_include_categories.def' it.headers "$projectDir/interop/objc/include_categories/objc_include_categories.h" @@ -1471,24 +1457,6 @@ if (PlatformInfo.isAppleTarget(project)) { } } - // KT-49034 tests don't need whole compilation pipeline (only frontend) or platform libraries. Consider simplifying them when porting - // to the new test infra. - interopTest("interop_kt49034_struct") { - interop = 'kt49034_struct' - source = 'interop/objc/kt49034/struct/main.kt' - - // The test depends on collision between kt49034.JSContext and platform.JavaScriptCore.JSContext - UtilsKt.dependsOnPlatformLibs(it) - } - - interopTest("interop_kt49034_objcclass") { - interop = 'kt49034_objcclass' - source = 'interop/objc/kt49034/objcclass/main.kt' - - // The test depends on collision between kt49034.__darwin_fp_control and platform.darwin.__darwin_fp_control - UtilsKt.dependsOnPlatformLibs(it) - } - standaloneTest("interop_objc_kt61441") { source = "interop/objc/kt61441.kt" UtilsKt.dependsOnPlatformLibs(it) diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def deleted file mode 100644 index bc752fc0d3e..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def +++ /dev/null @@ -1 +0,0 @@ -language = Objective-C \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h deleted file mode 100644 index 93cd37fdd2c..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h +++ /dev/null @@ -1,2 +0,0 @@ -@class __darwin_fp_control; -void foo(__darwin_fp_control*); diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt deleted file mode 100644 index 1030f72a0f5..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 objcnames.classes.__darwin_fp_control - -open class C - -class D : C<__darwin_fp_control>() - -fun main() { - println(D()) -} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt deleted file mode 100644 index 2b19035c252..00000000000 --- a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 kt49034.bar -import cnames.structs.JSContext -import kotlinx.cinterop.CPointer - -fun baz(s: CPointer) { - println(s) -} - -fun main() { - baz(bar()!!) -} \ No newline at end of file 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 8fda9fe7e8d..97d231c6e97 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 @@ -5092,6 +5092,18 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); } + @Test + @TestMetadata("kt49034_objcclass.kt") + public void testKt49034_objcclass() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt"); + } + + @Test + @TestMetadata("kt49034_struct.kt") + public void testKt49034_struct() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() 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 8c50fc97df6..75cf300acd9 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 @@ -5208,6 +5208,18 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); } + @Test + @TestMetadata("kt49034_objcclass.kt") + public void testKt49034_objcclass() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt"); + } + + @Test + @TestMetadata("kt49034_struct.kt") + public void testKt49034_struct() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { 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 a614c198f0f..30a7487aa01 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 @@ -4976,6 +4976,18 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); } + @Test + @TestMetadata("kt49034_objcclass.kt") + public void testKt49034_objcclass() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt"); + } + + @Test + @TestMetadata("kt49034_struct.kt") + public void testKt49034_struct() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() 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 c4fb61c1226..a5a7c985ada 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 @@ -5093,6 +5093,18 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/cinterop/objc/kt48816_lazy_ir_enable.kt"); } + @Test + @TestMetadata("kt49034_objcclass.kt") + public void testKt49034_objcclass() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_objcclass.kt"); + } + + @Test + @TestMetadata("kt49034_struct.kt") + public void testKt49034_struct() throws Exception { + runTest("compiler/testData/codegen/box/cinterop/objc/kt49034_struct.kt"); + } + @Test @TestMetadata("kt53151.kt") public void testKt53151() throws Exception { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt index 99de5b01b95..689234d2c77 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/group/ExtTestCaseGroupProvider.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.konan.target.Architecture import org.jetbrains.kotlin.konan.target.Family import org.jetbrains.kotlin.konan.test.blackbox.support.* import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase.WithTestRunnerExtras @@ -933,12 +934,14 @@ private fun Settings.isIgnoredWithIGNORE_BACKEND(directives: Directives): Boolea } private val TARGET_FAMILY = "targetFamily" +private val TARGET_ARCHITECTURE = "targetArchitecture" private val IS_APPLE_TARGET = "isAppleTarget" private val CACHE_MODE_NAMES = CacheMode.Alias.entries.map { it.name } private val TEST_MODE_NAMES = TestMode.entries.map { it.name } private val OPTIMIZATION_MODE_NAMES = OptimizationMode.entries.map { it.name } private val GC_TYPE_NAMES = GCType.entries.map { it.name } private val FAMILY_NAMES = Family.entries.map { it.name } +private val ARCHITECTURE_NAMES = Architecture.entries.map { it.name } private val BOOLEAN_NAMES = listOf(true.toString(), false.toString()) private fun Settings.isDisabledNative(directives: Directives) = @@ -965,6 +968,7 @@ private fun Settings.evaluate(directiveValues: List): Boolean { ClassLevelProperty.TEST_TARGET.shortName -> get().testTarget.name to null ClassLevelProperty.GC_TYPE.shortName -> get().name to GC_TYPE_NAMES TARGET_FAMILY -> get().testTarget.family.name to FAMILY_NAMES + TARGET_ARCHITECTURE -> get().testTarget.architecture.name to ARCHITECTURE_NAMES IS_APPLE_TARGET -> get().testTarget.family.isAppleFamily.toString() to BOOLEAN_NAMES else -> throw AssertionError("ClassLevelProperty name: $propName is not yet supported in IGNORE_NATIVE* test directives.") }