[K/N][Tests] Move funptr.kt to standalone tests due to OUTPUT_DATA_FILE directive

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-19 20:59:40 +01:00
committed by Space Team
parent c286b0efd7
commit 2f3705f0eb
9 changed files with 20 additions and 28 deletions
+150
View File
@@ -0,0 +1,150 @@
/*
* 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.
*/
// TARGET_BACKEND: NATIVE
// OUTPUT_DATA_FILE: funptr.out
// MODULE: cinterop
// FILE: cfunptr.def
headerFilter = NOTHING
---
#include <stdio.h>
#include <stdlib.h>
typedef int (*atoiPtrType)(const char*);
static atoiPtrType getAtoiPtr() {
return &atoi;
}
static void __printInt(int x) {
printf("%d\n", x);
}
static void* __getPrintIntPtr() {
return &__printInt;
}
typedef void* (*getPrintIntPtrPtrType)(void);
static getPrintIntPtrPtrType getGetPrintIntPtrPtr() {
return &__getPrintIntPtr;
}
static double __add(double x, double y) {
return x + y;
}
typedef double (*addPtrType)(double, double);
static addPtrType getAddPtr() {
return &__add;
}
static int __doubleToInt(double x) {
return (int) x;
}
typedef int (*doubleToIntPtrType)(double);
static doubleToIntPtrType getDoubleToIntPtr() {
return &__doubleToInt;
}
static _Bool __isIntPositive(int x) {
return x > 0;
}
typedef _Bool (*isIntPositivePtrType)(int);
static isIntPositivePtrType getIsIntPositivePtr() {
return &__isIntPositive;
}
static unsigned int getMaxUInt(void) {
return 0xffffffff;
}
static typeof(&getMaxUInt) getMaxUIntGetter() {
return &getMaxUInt;
}
typedef int (*longSignatureFunctionPtrType)(
int, int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int
);
typedef int (*notSoLongSignatureFunctionPtrType)(
int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int
);
static int longSignatureFunction(
int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10, int p11, int p12,
int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p20, int p21, int p22, int p23
) {
return 42;
}
static int notSoLongSignatureFunction(
int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10, int p11, int p12,
int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p20, int p21, int p22
) {
return 42;
}
static longSignatureFunctionPtrType getLongSignatureFunctionPtr() {
return &longSignatureFunction;
}
static notSoLongSignatureFunctionPtrType getNotSoLongSignatureFunctionPtr() {
return &notSoLongSignatureFunction;
}
// MODULE: main(cinterop)
// FILE: main.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
import kotlinx.cinterop.*
import cfunptr.*
import kotlin.test.*
typealias NotSoLongSignatureFunction = (
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int
) -> Int
fun main() {
val atoiPtr = getAtoiPtr()!!
val getPrintIntPtrPtr = getGetPrintIntPtrPtr()!!
val printIntPtr = getPrintIntPtrPtr()!!.reinterpret<CFunction<(Int) -> Unit>>()
val fortyTwo = memScoped {
atoiPtr("42".cstr.getPointer(memScope))
}
printIntPtr(fortyTwo)
printIntPtr(
getDoubleToIntPtr()!!(
getAddPtr()!!(5.1, 12.2)
)
)
val isIntPositivePtr = getIsIntPositivePtr()!!
printIntPtr(isIntPositivePtr(42).ifThenOneElseZero())
printIntPtr(isIntPositivePtr(-42).ifThenOneElseZero())
assertEquals(getMaxUIntGetter()!!(), UInt.MAX_VALUE)
val longSignaturePtr: COpaquePointer? = getLongSignatureFunctionPtr()
val notSoLongSignaturePtr: CPointer<CFunction<NotSoLongSignatureFunction>>? = getNotSoLongSignatureFunctionPtr()
printIntPtr(notSoLongSignaturePtr!!.invoke(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
printIntPtr(notSoLongSignatureFunction(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
fun Boolean.ifThenOneElseZero() = if (this) 1 else 0
+6
View File
@@ -0,0 +1,6 @@
42
17
1
0
42
42
@@ -4808,12 +4808,6 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/cinterop/forwardDeclarationsTwoLibs.kt");
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/funptr.kt");
}
@Test
@TestMetadata("globals.kt")
public void testGlobals() throws Exception {
@@ -4918,12 +4918,6 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/cinterop/forwardDeclarationsTwoLibs.kt");
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/funptr.kt");
}
@Test
@TestMetadata("globals.kt")
public void testGlobals() throws Exception {
@@ -34,6 +34,12 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("native/native.tests/testData/standalone/funptr.kt");
}
@Test
@TestMetadata("kt56048.kt")
public void testKt56048() throws Exception {
@@ -4698,12 +4698,6 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/cinterop/forwardDeclarationsTwoLibs.kt");
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/funptr.kt");
}
@Test
@TestMetadata("globals.kt")
public void testGlobals() throws Exception {
@@ -4809,12 +4809,6 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/cinterop/forwardDeclarationsTwoLibs.kt");
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/funptr.kt");
}
@Test
@TestMetadata("globals.kt")
public void testGlobals() throws Exception {
@@ -31,6 +31,12 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("funptr.kt")
public void testFunptr() throws Exception {
runTest("native/native.tests/testData/standalone/funptr.kt");
}
@Test
@TestMetadata("kt56048.kt")
public void testKt56048() throws Exception {
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.FREE_COMP
import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE
import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE_K1
import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.IGNORE_NATIVE_K2
import org.jetbrains.kotlin.konan.test.blackbox.support.TestDirectives.OUTPUT_DATA_FILE
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunChecks
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.*
@@ -52,6 +53,7 @@ import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_K2
import org.jetbrains.kotlin.test.directives.model.StringDirective
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertFalse
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File
@@ -126,7 +128,11 @@ private class ExtTestDataFile(
else
MANDATORY_SOURCE_TRANSFORMERS + customSourceTransformers
structureFactory.ExtTestDataFileStructure(testDataFile, allSourceTransformers)
structureFactory.ExtTestDataFileStructure(testDataFile, allSourceTransformers).also {
assertFalse(it.directives.contains(OUTPUT_DATA_FILE.name)) {
"${testDataFile.absolutePath}: directive ${OUTPUT_DATA_FILE.name} is not supported by ExtTestDataFile"
}
}
}
private val isExpectedFailure: Boolean = settings.isIgnoredTarget(structure.directives)