diff --git a/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.c b/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.c new file mode 100644 index 00000000000..86ba864c550 --- /dev/null +++ b/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.c @@ -0,0 +1,59 @@ +#include +#undef NDEBUG // Make sure that asserts are enabled. +#include +#include + +#define DECLARE_ADDER(T) \ + T add_##T(T a, T b) + +DECLARE_ADDER(int8_t); +DECLARE_ADDER(int16_t); +DECLARE_ADDER(int32_t); +DECLARE_ADDER(int64_t); + +DECLARE_ADDER(uint8_t); +DECLARE_ADDER(uint16_t); +DECLARE_ADDER(uint32_t); +DECLARE_ADDER(uint64_t); + +DECLARE_ADDER(float); +DECLARE_ADDER(double); + +float float_nan(); +double double_nan(); + +_Bool logical_or(_Bool a, _Bool b); + +int main() { + assert(add_int8_t(1, 1) == 2); + assert(add_int16_t(1, 1) == 2); + assert(add_int32_t(1, 1) == 2); + assert(add_int32_t(1, 1) == 2); + + assert(add_uint8_t(1, 1) == 2); + assert(add_uint16_t(1, 1) == 2); + assert(add_uint32_t(1, 1) == 2); + assert(add_uint32_t(1, 1) == 2); + + assert(add_int8_t(INT8_MAX, 1) == INT8_MIN); + assert(add_int16_t(INT16_MAX, 1) == INT16_MIN); + assert(add_int32_t(INT32_MAX, 1) == INT32_MIN); + assert(add_int64_t(INT64_MAX, 1) == INT64_MIN); + + assert(add_uint8_t(UINT8_MAX, 1) == 0); + assert(add_uint16_t(UINT16_MAX, 1) == 0); + assert(add_uint32_t(UINT32_MAX, 1) == 0); + assert(add_uint64_t(UINT64_MAX, 1) == 0); + + assert(logical_or(1, 1) == 1); + assert(logical_or(0, 1) == 1); + + assert(add_float(3.0, -3.0) == 0.0); + assert(add_double(3.0, -3.0) == 0.0); + + assert(add_float(3.0, -3.0) == 0.0); + assert(add_double(3.0, -3.0) == 0.0); + + assert(isnan(float_nan())); + assert(isnan(double_nan())); +} \ No newline at end of file diff --git a/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.kt b/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.kt new file mode 100644 index 00000000000..152fb1009bb --- /dev/null +++ b/native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/main.kt @@ -0,0 +1,42 @@ +package org.lab.mat + +import kotlin.native.internal.ExportedBridge + +@ExportedBridge("add_int8_t") +fun add(a: Byte, b: Byte): Int = a + b + +@ExportedBridge("add_int16_t") +fun add(a: Short, b: Short): Int = a + b + +@ExportedBridge("add_int32_t") +fun add(a: Int, b: Int): Int = a + b + +@ExportedBridge("add_int64_t") +fun add(a: Long, b: Long): Long = a + b + +@ExportedBridge("add_uint8_t") +fun add(a: UByte, b: UByte): UInt = a + b + +@ExportedBridge("add_uint16_t") +fun add(a: UShort, b: UShort): UInt = a + b + +@ExportedBridge("add_uint32_t") +fun add(a: UInt, b: UInt): UInt = a + b + +@ExportedBridge("add_uint64_t") +fun add(a: ULong, b: ULong): ULong = a + b + +@ExportedBridge("add_float") +fun add(a: Float, b: Float): Float = a + b + +@ExportedBridge("add_double") +fun add(a: Double, b: Double): Double = a + b + +@ExportedBridge("logical_or") +fun or(a: Boolean, b: Boolean): Boolean = a || b + +@ExportedBridge("float_nan") +fun floatNaN(): Float = Float.NaN + +@ExportedBridge("double_nan") +fun doubleNaN(): Double = Double.NaN \ No newline at end of file diff --git a/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.c b/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.c new file mode 100644 index 00000000000..0e50eaf8be3 --- /dev/null +++ b/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.c @@ -0,0 +1,9 @@ +#include + +int32_t my_function(int32_t); + +int main() { + if (my_function(5) != 5) { + return -1; + } +} \ No newline at end of file diff --git a/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.kt b/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.kt new file mode 100644 index 00000000000..e07a9d90c83 --- /dev/null +++ b/native/native.tests/testData/CExport/InterfaceNone/smoke0/main.kt @@ -0,0 +1,4 @@ +import kotlin.native.internal.ExportedBridge + +@ExportedBridge("my_function") +fun myFunction(value: Int): Int = value \ No newline at end of file diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceNoneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceNoneTestGenerated.java new file mode 100644 index 00000000000..36eb1edccde --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceNoneTestGenerated.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2024 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty; +import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport/InterfaceNone") +@TestDataPath("$PROJECT_ROOT") +@EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "DYNAMIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "NONE") +public class CExportDynamicInterfaceNoneTestGenerated extends AbstractNativeCExportTest { + @Test + public void testAllFilesPresentInInterfaceNone() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceNone"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("primitiveTypes") + public void testPrimitiveTypes() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceV1TestGenerated.java similarity index 90% rename from native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicTestGenerated.java rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceV1TestGenerated.java index 41c3ec08aa6..0248d05c7ae 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportDynamicInterfaceV1TestGenerated.java @@ -21,7 +21,8 @@ import java.util.regex.Pattern; @TestMetadata("native/native.tests/testData/CExport/InterfaceV1") @TestDataPath("$PROJECT_ROOT") @EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "DYNAMIC") -public class CExportDynamicTestGenerated extends AbstractNativeCExportTest { +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "V1") +public class CExportDynamicInterfaceV1TestGenerated extends AbstractNativeCExportTest { @Test public void testAllFilesPresentInInterfaceV1() { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceV1"), Pattern.compile("^([^_](.+))$"), null, false); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceNoneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceNoneTestGenerated.java new file mode 100644 index 00000000000..550668959a4 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceNoneTestGenerated.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2024 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty; +import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport/InterfaceNone") +@TestDataPath("$PROJECT_ROOT") +@EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "STATIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "NONE") +public class CExportStaticInterfaceNoneTestGenerated extends AbstractNativeCExportTest { + @Test + public void testAllFilesPresentInInterfaceNone() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceNone"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("primitiveTypes") + public void testPrimitiveTypes() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceV1TestGenerated.java similarity index 90% rename from native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticTestGenerated.java rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceV1TestGenerated.java index 702acccee99..b19604c5453 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportStaticInterfaceV1TestGenerated.java @@ -21,7 +21,8 @@ import java.util.regex.Pattern; @TestMetadata("native/native.tests/testData/CExport/InterfaceV1") @TestDataPath("$PROJECT_ROOT") @EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "STATIC") -public class CExportStaticTestGenerated extends AbstractNativeCExportTest { +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "V1") +public class CExportStaticInterfaceV1TestGenerated extends AbstractNativeCExportTest { @Test public void testAllFilesPresentInInterfaceV1() { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceV1"), Pattern.compile("^([^_](.+))$"), null, false); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceNoneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceNoneTestGenerated.java new file mode 100644 index 00000000000..bc6aa3a1e46 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceNoneTestGenerated.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2024 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty; +import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport/InterfaceNone") +@TestDataPath("$PROJECT_ROOT") +@EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "DYNAMIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "NONE") +@Tag("frontend-fir") +@FirPipeline() +public class FirCExportDynamicInterfaceNoneTestGenerated extends AbstractNativeCExportTest { + @Test + public void testAllFilesPresentInInterfaceNone() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceNone"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("primitiveTypes") + public void testPrimitiveTypes() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceV1TestGenerated.java similarity index 90% rename from native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicTestGenerated.java rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceV1TestGenerated.java index 943205c11e5..a0a06e681ce 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportDynamicInterfaceV1TestGenerated.java @@ -23,9 +23,10 @@ import java.util.regex.Pattern; @TestMetadata("native/native.tests/testData/CExport/InterfaceV1") @TestDataPath("$PROJECT_ROOT") @EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "DYNAMIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "V1") @Tag("frontend-fir") @FirPipeline() -public class FirCExportDynamicTestGenerated extends AbstractNativeCExportTest { +public class FirCExportDynamicInterfaceV1TestGenerated extends AbstractNativeCExportTest { @Test public void testAllFilesPresentInInterfaceV1() { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceV1"), Pattern.compile("^([^_](.+))$"), null, false); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceNoneTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceNoneTestGenerated.java new file mode 100644 index 00000000000..8936963dc50 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceNoneTestGenerated.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2024 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. + */ + +package org.jetbrains.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty; +import org.jetbrains.kotlin.konan.test.blackbox.support.ClassLevelProperty; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport/InterfaceNone") +@TestDataPath("$PROJECT_ROOT") +@EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "STATIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "NONE") +@Tag("frontend-fir") +@FirPipeline() +public class FirCExportStaticInterfaceNoneTestGenerated extends AbstractNativeCExportTest { + @Test + public void testAllFilesPresentInInterfaceNone() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceNone"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("primitiveTypes") + public void testPrimitiveTypes() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/primitiveTypes/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/InterfaceNone/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceV1TestGenerated.java similarity index 90% rename from native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticTestGenerated.java rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceV1TestGenerated.java index aaafea014b9..e272294b506 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportStaticInterfaceV1TestGenerated.java @@ -23,9 +23,10 @@ import java.util.regex.Pattern; @TestMetadata("native/native.tests/testData/CExport/InterfaceV1") @TestDataPath("$PROJECT_ROOT") @EnforcedProperty(property = ClassLevelProperty.BINARY_LIBRARY_KIND, propertyValue = "STATIC") +@EnforcedProperty(property = ClassLevelProperty.C_INTERFACE_MODE, propertyValue = "V1") @Tag("frontend-fir") @FirPipeline() -public class FirCExportStaticTestGenerated extends AbstractNativeCExportTest { +public class FirCExportStaticInterfaceV1TestGenerated extends AbstractNativeCExportTest { @Test public void testAllFilesPresentInInterfaceV1() { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport/InterfaceV1"), Pattern.compile("^([^_](.+))$"), null, false); diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt index 0439282a158..b11e37476f3 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt @@ -469,18 +469,25 @@ fun main() { ) // C Export testGroup("native/native.tests/tests-gen", "native/native.tests/testData") { + val cinterfaceModes = mapOf( + "InterfaceV1" to cinterfaceMode("V1"), + "InterfaceNone" to cinterfaceMode("NONE") + ) binaryLibraryKinds.forEach { binaryKind -> frontendFlags.forEach { frontend -> - val frontendKey = if (frontend.key == "Classic") "" else frontend.key - val suiteTestClassName = "${frontendKey}CExport${binaryKind.key}TestGenerated" - testClass( - suiteTestClassName, - annotations = listOf( - binaryKind.value, - *frontend.value - ) - ) { - model("CExport/InterfaceV1", pattern = "^([^_](.+))$", recursive = false) + cinterfaceModes.forEach { cinterfaceMode -> + val frontendKey = if (frontend.key == "Classic") "" else frontend.key + val suiteTestClassName = "${frontendKey}CExport${binaryKind.key}${cinterfaceMode.key}TestGenerated" + testClass( + suiteTestClassName, + annotations = listOf( + binaryKind.value, + cinterfaceMode.value, + *frontend.value + ) + ) { + model("CExport/${cinterfaceMode.key}", pattern = "^([^_](.+))$", recursive = false) + } } } } @@ -566,3 +573,8 @@ private fun binaryLibraryKind(kind: String = "DYNAMIC") = annotation( "property" to ClassLevelProperty.BINARY_LIBRARY_KIND, "propertyValue" to kind ) +private fun cinterfaceMode(mode: String = "V1") = annotation( + EnforcedProperty::class.java, + "property" to ClassLevelProperty.C_INTERFACE_MODE, + "propertyValue" to mode +) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt index 42b439d04fc..63effe9df44 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt @@ -122,7 +122,10 @@ abstract class AbstractNativeCExportTest() : AbstractNativeSimpleTest() { id = TestCaseId.Named(moduleName), kind = TestKind.STANDALONE_NO_TR, modules = setOf(module), - freeCompilerArgs = TestCompilerArgs(listOf()), + freeCompilerArgs = TestCompilerArgs(listOf( + "-opt-in", "kotlin.experimental.ExperimentalNativeApi", + "-opt-in", "kotlinx.cinterop.ExperimentalForeignApi", + )), nominalPackageName = PackageName(moduleName), checks = TestRunChecks( executionTimeoutCheck = TestRunCheck.ExecutionTimeout.ShouldNotExceed(testRunSettings.get().executionTimeout), diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt index 10d61915aff..52ea87f7161 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/ConfigurationProperties.kt @@ -73,6 +73,7 @@ internal enum class ClassLevelProperty(val shortName: String) { PIPELINE_TYPE("pipelineType"), SHARED_TEST_EXECUTION("sharedTestExecution"), BINARY_LIBRARY_KIND("binaryLibraryKind"), + C_INTERFACE_MODE("cInterfaceMode"), ; internal val propertyName = fullPropertyName(shortName) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt index 5068127a9ee..7f9aafcc934 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/NativeTestSupport.kt @@ -210,6 +210,7 @@ internal object NativeTestSupport { output += computeUsedPartialLinkageConfig(enclosingTestClass) output += computeCompilerOutputInterceptor(enforcedProperties) output += computeBinaryLibraryKind(enforcedProperties) + output += computeCInterfaceMode(enforcedProperties) return nativeTargets } @@ -508,6 +509,10 @@ internal object NativeTestSupport { private fun computeBinaryLibraryKind(enforcedProperties: EnforcedProperties): BinaryLibraryKind = ClassLevelProperty.BINARY_LIBRARY_KIND.readValue(enforcedProperties, BinaryLibraryKind.values(), BinaryLibraryKind.STATIC) + + private fun computeCInterfaceMode(enforcedProperties: EnforcedProperties): CInterfaceMode = + ClassLevelProperty.C_INTERFACE_MODE.readValue(enforcedProperties, CInterfaceMode.values(), CInterfaceMode.NONE) + /*************** Test class settings (simplified) ***************/ private fun ExtensionContext.getOrCreateSimpleTestClassSettings(): SimpleTestClassSettings = diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt index 4fcc642f2b1..77013be5499 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt @@ -351,6 +351,7 @@ internal class BinaryLibraryCompilation( dependencies = CategorizedDependencies(dependencies), expectedArtifact = expectedArtifact ) { + private val cinterfaceMode = settings.get().compilerFlag override val binaryOptions get() = BinaryOptions.RuntimeAssertionsMode.defaultForTesting(optimizationMode, freeCompilerArgs.assertionsMode) override fun applySpecificArgs(argsBuilder: ArgsBuilder) = with(argsBuilder) { @@ -360,7 +361,8 @@ internal class BinaryLibraryCompilation( } add( "-produce", libraryKind, - "-output", expectedArtifact.libraryFile.absolutePath + "-output", expectedArtifact.libraryFile.absolutePath, + cinterfaceMode ) super.applySpecificArgs(argsBuilder) } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt index 78b3a55584d..2a3820b79f3 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/settings/TestProcessSettings.kt @@ -299,3 +299,8 @@ internal enum class CompilerOutputInterceptor { internal enum class BinaryLibraryKind { STATIC, DYNAMIC } + +internal enum class CInterfaceMode(val compilerFlag: String) { + V1("-Xbinary=cInterfaceMode=v1"), + NONE("-Xbinary=cInterfaceMode=none") +}