[K/N][Tests] Migrate test direct.kt

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-01-18 21:57:55 +01:00
parent e59a80bd69
commit 4aa8774c6e
12 changed files with 172 additions and 154 deletions
+148
View File
@@ -0,0 +1,148 @@
// TARGET_BACKEND: NATIVE
// DISABLE_NATIVE: isAppleTarget=false
// FILECHECK_STAGE: CStubs
// LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion
// MODULE: cinterop
// FILE: direct.def
language = Objective-C
headers = direct.h
headerFilter = direct.h
// FILE: direct.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
__attribute__((objc_runtime_name("CC")))
__attribute__((swift_name("CC")))
@interface CallingConventions : NSObject
+ (uint64_t)regular:(uint64_t)arg;
- (uint64_t)regular:(uint64_t)arg;
+ (uint64_t)direct:(uint64_t)arg __attribute__((objc_direct));
- (uint64_t)direct:(uint64_t)arg __attribute__((objc_direct));
@end
@interface CallingConventions(Ext)
+ (uint64_t)regularExt:(uint64_t)arg;
- (uint64_t)regularExt:(uint64_t)arg;
+ (uint64_t)directExt:(uint64_t)arg __attribute__((objc_direct));
- (uint64_t)directExt:(uint64_t)arg __attribute__((objc_direct));
@end
__attribute__((objc_runtime_name("CCH")))
__attribute__((swift_name("CCH")))
@interface CallingConventionsHeir : CallingConventions
@end
NS_ASSUME_NONNULL_END
// FILE: direct.m
#import "direct.h"
#define TEST_METHOD_IMPL(NAME) (uint64_t)NAME:(uint64_t)arg { return arg; }
@implementation CallingConventions : NSObject
+ TEST_METHOD_IMPL(regular);
- TEST_METHOD_IMPL(regular);
+ TEST_METHOD_IMPL(direct);
- TEST_METHOD_IMPL(direct);
@end
@implementation CallingConventions(Ext)
+ TEST_METHOD_IMPL(regularExt);
- TEST_METHOD_IMPL(regularExt);
+ TEST_METHOD_IMPL(directExt);
- TEST_METHOD_IMPL(directExt);
@end
@implementation CallingConventionsHeir
@end
// MODULE: main(cinterop)
// FILE: main.kt
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
import kotlin.native.Retain
import direct.*
import kotlinx.cinterop.*
import kotlin.test.*
class CallingConventionsNativeHeir() : CallingConventions() {
// nothing
}
typealias CC = CallingConventions
typealias CCH = CallingConventionsHeir
typealias CCN = CallingConventionsNativeHeir
// KT-54610
fun box(): String {
autoreleasepool {
val cc = CC()
val cch = CCH()
val ccn = CCN()
assertEquals(42UL, CC.regular(42))
assertEquals(42UL, cc.regular(42))
assertEquals(42UL, CC.regularExt(42))
assertEquals(42UL, cc.regularExt(42))
assertEquals(42UL, CCH.regular(42))
assertEquals(42UL, cch.regular(42))
assertEquals(42UL, CCH.regularExt(42))
assertEquals(42UL, cch.regularExt(42))
assertEquals(42UL, ccn.regular(42UL))
assertEquals(42UL, ccn.regularExt(42UL))
assertEquals(42UL, CC.direct(42))
assertEquals(42UL, cc.direct(42))
assertEquals(42UL, CC.directExt(42))
assertEquals(42UL, cc.directExt(42))
assertEquals(42UL, CCH.direct(42))
assertEquals(42UL, cch .direct(42))
assertEquals(42UL, CCH.directExt(42))
assertEquals(42UL, cch .directExt(42))
assertEquals(42UL, ccn .direct(42UL))
assertEquals(42UL, ccn .directExt(42UL))
}
// FileCheck part
callDirect()
callRegular()
return "OK"
}
@Retain
//CHECK-LABEL: define i64 @"kfun:#callDirect(){}kotlin.ULong"()
fun callDirect(): ULong {
val cc = CallingConventions()
//CHECK: invoke i64 @_{{[a-zA-Z0-9]+}}_knbridge{{[0-9]+}}(i8* %{{[0-9]+}}, i64 42)
return cc.direct(42uL)
}
@Retain
//CHECK-LABEL: define i64 @"kfun:#callRegular(){}kotlin.ULong"()
fun callRegular(): ULong {
val cc = CallingConventions()
//CHECK: invoke i64 @_{{[a-zA-Z0-9]+}}_knbridge{{[0-9]+}}(i8* %{{[0-9]+}}, i8* %{{[0-9]+}}, i64 42)
return cc.regular(42uL)
}
@@ -2,7 +2,6 @@
// DISABLE_NATIVE: isAppleTarget=false
// FREE_CINTEROP_ARGS: -compiler-option -fmodule-map-file=$generatedSourcesDir/cinterop/module_library.modulemap
// FREE_CINTEROP_ARGS: -compiler-option -I$generatedSourcesDir/cinterop
// MODULE: cinterop
// FILE: module_library.def
language = Objective-C
@@ -1137,13 +1137,6 @@ if (PlatformInfo.isAppleTarget(project)) {
it.headers "$projectDir/interop/objc/msg_send/messaging.h"
}
createInterop("objcDirect") {
it.defFile 'interop/objc/direct/direct.def'
it.headers "$projectDir/interop/objc/direct/direct.h"
it.extraOpts "-Xcompile-source", "$projectDir/interop/objc/direct/direct.m", "-Xsource-compiler-option", "-DNS_FORMAT_ARGUMENT(A)="
it.compilerOpts '-DNS_FORMAT_ARGUMENT(A)='
}
createInterop("foreignException") {
it.defFile 'interop/objc/foreignException/objc_wrap.def'
it.headers "$projectDir/interop/objc/foreignException/objc_wrap.h"
@@ -1539,11 +1532,6 @@ if (PlatformInfo.isAppleTarget(project)) {
}
}
interopTest("interop_objc_direct") {
source = "interop/objc/direct/main.kt"
interop = "objcDirect"
}
interopTest("interop_objc_foreignException") {
source = "interop/objc/foreignException/objc_wrap.kt"
interop = 'foreignException'
@@ -2643,14 +2631,6 @@ fileCheckTest("filecheck_signext_zeroext_objc_export") {
enabled = target.family.appleFamily
}
fileCheckTest("filecheck_objc_direct") {
enabled = enabled && cacheTesting == null
annotatedSource = project.file('filecheck/objc_direct.kt')
interop = "objcDirect"
enabled = target.family.appleFamily
}
dependencies {
nopPluginApi kotlinCompilerModule
nopPluginApi project(":native:kotlin-native-utils")
@@ -1,26 +0,0 @@
/*
* 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.
*/
import direct.*
import kotlinx.cinterop.*
//CHECK-LABEL: kfun:#callDirect(){}kotlin.ULong
fun callDirect(): ULong {
val cc = CallingConventions()
//CHECK: invoke i64 @_{{[a-zA-Z0-9]+}}_knbridge{{[0-9]+}}(i8* %{{[0-9]+}}, i64 42)
return cc.direct(42uL)
}
//CHECK-LABEL: kfun:#callRegular(){}kotlin.ULong
fun callRegular(): ULong {
val cc = CallingConventions()
//CHECK: invoke i64 @_{{[a-zA-Z0-9]+}}_knbridge{{[0-9]+}}(i8* %{{[0-9]+}}, i8* %{{[0-9]+}}, i64 42)
return cc.regular(42uL)
}
fun main() {
callDirect()
callRegular()
}
@@ -1,2 +0,0 @@
language = Objective-C
headerFilter = **/direct.h
@@ -1,32 +0,0 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
__attribute__((objc_runtime_name("CC")))
__attribute__((swift_name("CC")))
@interface CallingConventions : NSObject
+ (uint64_t)regular:(uint64_t)arg;
- (uint64_t)regular:(uint64_t)arg;
+ (uint64_t)direct:(uint64_t)arg __attribute__((objc_direct));
- (uint64_t)direct:(uint64_t)arg __attribute__((objc_direct));
@end
@interface CallingConventions(Ext)
+ (uint64_t)regularExt:(uint64_t)arg;
- (uint64_t)regularExt:(uint64_t)arg;
+ (uint64_t)directExt:(uint64_t)arg __attribute__((objc_direct));
- (uint64_t)directExt:(uint64_t)arg __attribute__((objc_direct));
@end
__attribute__((objc_runtime_name("CCH")))
__attribute__((swift_name("CCH")))
@interface CallingConventionsHeir : CallingConventions
@end
NS_ASSUME_NONNULL_END
@@ -1,27 +0,0 @@
#import "direct.h"
#define TEST_METHOD_IMPL(NAME) (uint64_t)NAME:(uint64_t)arg { return arg; }
@implementation CallingConventions : NSObject
+ TEST_METHOD_IMPL(regular);
- TEST_METHOD_IMPL(regular);
+ TEST_METHOD_IMPL(direct);
- TEST_METHOD_IMPL(direct);
@end
@implementation CallingConventions(Ext)
+ TEST_METHOD_IMPL(regularExt);
- TEST_METHOD_IMPL(regularExt);
+ TEST_METHOD_IMPL(directExt);
- TEST_METHOD_IMPL(directExt);
@end
@implementation CallingConventionsHeir
@end
@@ -1,46 +0,0 @@
import direct.*
import kotlinx.cinterop.*
import kotlin.test.*
class CallingConventionsNativeHeir() : CallingConventions() {
// nothing
}
typealias CC = CallingConventions
typealias CCH = CallingConventionsHeir
typealias CCN = CallingConventionsNativeHeir
// KT-54610
fun main(args: Array<String>) {
autoreleasepool {
val cc = CC()
val cch = CCH()
val ccn = CCN()
assertEquals(42UL, CC.regular(42))
assertEquals(42UL, cc.regular(42))
assertEquals(42UL, CC.regularExt(42))
assertEquals(42UL, cc.regularExt(42))
assertEquals(42UL, CCH.regular(42))
assertEquals(42UL, cch.regular(42))
assertEquals(42UL, CCH.regularExt(42))
assertEquals(42UL, cch.regularExt(42))
assertEquals(42UL, ccn.regular(42UL))
assertEquals(42UL, ccn.regularExt(42UL))
assertEquals(42UL, CC.direct(42))
assertEquals(42UL, cc.direct(42))
assertEquals(42UL, CC.directExt(42))
assertEquals(42UL, cc.directExt(42))
assertEquals(42UL, CCH.direct(42))
assertEquals(42UL, cch .direct(42))
assertEquals(42UL, CCH.directExt(42))
assertEquals(42UL, cch .directExt(42))
assertEquals(42UL, ccn .direct(42UL))
assertEquals(42UL, ccn .directExt(42UL))
}
}
@@ -5068,6 +5068,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/objc"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("direct.kt")
public void testDirect() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("illegal_sharing_with_weak.kt")
public void testIllegal_sharing_with_weak() throws Exception {
@@ -5184,6 +5184,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/objc"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("direct.kt")
public void testDirect() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("illegal_sharing_with_weak.kt")
public void testIllegal_sharing_with_weak() throws Exception {
@@ -4952,6 +4952,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/objc"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("direct.kt")
public void testDirect() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("illegal_sharing_with_weak.kt")
public void testIllegal_sharing_with_weak() throws Exception {
@@ -5069,6 +5069,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/cinterop/objc"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("direct.kt")
public void testDirect() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/objc/direct.kt");
}
@Test
@TestMetadata("illegal_sharing_with_weak.kt")
public void testIllegal_sharing_with_weak() throws Exception {