From 55a78bf4997fe323748d2233be20871e9c7f4f44 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Sat, 6 Jan 2024 20:17:58 +0100 Subject: [PATCH] [K/N][Tests] Migrate testData of KT59030WorkaroundTest to new new test infra --- .../testData/CInterop/KT-59030/cvectors.def | 28 +++++++++++++++++++ .../testData/CInterop/KT-59030/vectors.kt | 28 +++++++++++++++++++ .../test/blackbox/KT59030WorkaroundTest.kt | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 native/native.tests/testData/CInterop/KT-59030/cvectors.def create mode 100644 native/native.tests/testData/CInterop/KT-59030/vectors.kt diff --git a/native/native.tests/testData/CInterop/KT-59030/cvectors.def b/native/native.tests/testData/CInterop/KT-59030/cvectors.def new file mode 100644 index 00000000000..233a35ea1d5 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-59030/cvectors.def @@ -0,0 +1,28 @@ +--- +typedef float __attribute__ ((__vector_size__ (16))) KVector4f; +typedef int __attribute__ ((__vector_size__ (16))) KVector4i32; + +struct Complex { + unsigned int ui; + KVector4f vec4f; + struct Complex* next; + int arr[2]; +}; + +struct Complex produceComplex() { + struct Complex complex = { + .ui = 128, + .vec4f = {1.0, 1.0, 1.0, 1.0}, + .next = 0, + .arr = {-51, -19} + }; + return complex; +}; + +static float sendV4F(KVector4f v) { + return v[0] + 2 * v[1] + 4 * v[2] + 8 * v[3]; +} + +static int sendV4I(KVector4i32 v) { + return v[0] + 2 * v[1] + 4 * v[2] + 8 * v[3]; +} diff --git a/native/native.tests/testData/CInterop/KT-59030/vectors.kt b/native/native.tests/testData/CInterop/KT-59030/vectors.kt new file mode 100644 index 00000000000..09ab8732cf5 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-59030/vectors.kt @@ -0,0 +1,28 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.experimental.ExperimentalNativeApi::class) + +import kotlinx.cinterop.* +import kotlinx.cinterop.vectorOf +import kotlin.native.* +import kotlin.test.* +import cvectors.* + +fun main() { + produceComplex().useContents { + assertEquals(vec4f, vectorOf(1.0f, 1.0f, 1.0f, 1.0f)) + vec4f = vectorOf(0.0f, 0.0f, 0.0f, 0.0f) + assertEquals(vec4f, vectorOf(0.0f, 0.0f, 0.0f, 0.0f)) + } + + // FIXME: KT-36285 + if (Platform.osFamily != OsFamily.LINUX || Platform.cpuArchitecture != CpuArchitecture.ARM32) { + assertEquals(49, sendV4I(vectorOf(1, 2, 3, 4))) + } + assertEquals(49, (sendV4F(vectorOf(1f, 2f, 3f, 4f)) + 0.00001).toInt()) + + memScoped { + val vector = alloc().also { + it.value = vectorOf(1, 2, 3, 4) + } + assertEquals(vector.value, vectorOf(1, 2, 3, 4)) + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KT59030WorkaroundTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KT59030WorkaroundTest.kt index d07e0cb1e03..4529d7c5916 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KT59030WorkaroundTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KT59030WorkaroundTest.kt @@ -91,7 +91,7 @@ class KT59030WorkaroundTest : AbstractNativeSimpleTest() { } companion object { - private const val TEST_DATA_DIR = "kotlin-native/backend.native/tests/interop/basics" + private const val TEST_DATA_DIR = "native/native.tests/testData/CInterop/KT-59030" const val DEF_FILE_PATH = "${TEST_DATA_DIR}/cvectors.def" const val MAIN_FILE_PATH = "${TEST_DATA_DIR}/vectors.kt"