[K/N][Tests] Migrate test illegal_sharing_with_weak.kt
^KT-61259
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
// DISABLE_NATIVE: isAppleTarget=false
|
||||
|
||||
// MODULE: cinterop
|
||||
// FILE: objclib.def
|
||||
language = Objective-C
|
||||
headers = objclib.h
|
||||
headerFilter = objclib.h
|
||||
|
||||
// FILE: objclib.h
|
||||
#import <objc/NSObject.h>
|
||||
|
||||
static NSObject* __weak globalObject = nil;
|
||||
|
||||
void setObject(NSObject* obj) {
|
||||
globalObject = obj;
|
||||
}
|
||||
|
||||
// Make sure this function persists, because the test expects to find this function in the stack trace.
|
||||
__attribute__((noinline))
|
||||
bool isObjectAliveShouldCrash() {
|
||||
return globalObject != nil;
|
||||
}
|
||||
|
||||
// MODULE: main(cinterop)
|
||||
// FILE: main.kt
|
||||
@file:OptIn(ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.autoreleasepool
|
||||
import objclib.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
autoreleasepool {
|
||||
run()
|
||||
}
|
||||
// Experimental MM supports arbitrary object sharing.
|
||||
assertEquals("Before\nAfter true\n", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
private class NSObjectImpl : NSObject() {
|
||||
var x = 111
|
||||
}
|
||||
|
||||
fun run() = withWorker {
|
||||
val obj = NSObjectImpl()
|
||||
setObject(obj)
|
||||
|
||||
sb.appendLine("Before")
|
||||
val isAlive = try {
|
||||
execute(TransferMode.SAFE, {}) {
|
||||
isObjectAliveShouldCrash()
|
||||
}.result
|
||||
} catch (e: Throwable) {
|
||||
false
|
||||
}
|
||||
sb.appendLine("After $isAlive")
|
||||
}
|
||||
@@ -1165,10 +1165,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
it.headers "$projectDir/framework/gh3343/objclib.h"
|
||||
it.linkerOpts "-lobjcgh3343"
|
||||
}
|
||||
createInterop("objc_illegal_sharing_with_weak") {
|
||||
it.defFile 'interop/objc/illegal_sharing_with_weak/objclib.def'
|
||||
it.headers "$projectDir/interop/objc/illegal_sharing_with_weak/objclib.h"
|
||||
}
|
||||
createInterop("objcKt43517") {
|
||||
it.defFile 'framework/kt43517/kt43517.def'
|
||||
}
|
||||
@@ -1618,13 +1614,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
}
|
||||
}
|
||||
|
||||
interopTest("interop_objc_illegal_sharing_with_weak") {
|
||||
source = "interop/objc/illegal_sharing_with_weak/main.kt"
|
||||
interop = 'objc_illegal_sharing_with_weak'
|
||||
// Experimental MM supports arbitrary object sharing.
|
||||
outputChecker = { it == "Before\nAfter true\n" }
|
||||
}
|
||||
|
||||
interopTest("interop_objc_kt42172") {
|
||||
enabled = !isNoopGC
|
||||
source = "interop/objc/kt42172/main.kt"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
@file:OptIn(ObsoleteWorkersApi::class)
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlinx.cinterop.autoreleasepool
|
||||
import objclib.*
|
||||
|
||||
fun main() {
|
||||
autoreleasepool {
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
||||
private class NSObjectImpl : NSObject() {
|
||||
var x = 111
|
||||
}
|
||||
|
||||
fun run() = withWorker {
|
||||
val obj = NSObjectImpl()
|
||||
setObject(obj)
|
||||
|
||||
println("Before")
|
||||
val isAlive = try {
|
||||
execute(TransferMode.SAFE, {}) {
|
||||
isObjectAliveShouldCrash()
|
||||
}.result
|
||||
} catch (e: Throwable) {
|
||||
false
|
||||
}
|
||||
println("After $isAlive")
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/objclib.h
|
||||
@@ -1,13 +0,0 @@
|
||||
#import <objc/NSObject.h>
|
||||
|
||||
static NSObject* __weak globalObject = nil;
|
||||
|
||||
void setObject(NSObject* obj) {
|
||||
globalObject = obj;
|
||||
}
|
||||
|
||||
// Make sure this function persists, because the test expects to find this function in the stack trace.
|
||||
__attribute__((noinline))
|
||||
bool isObjectAliveShouldCrash() {
|
||||
return globalObject != nil;
|
||||
}
|
||||
+6
@@ -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("illegal_sharing_with_weak.kt")
|
||||
public void testIllegal_sharing_with_weak() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/cinterop/objc/illegal_sharing_with_weak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt34467.kt")
|
||||
public void testKt34467() throws Exception {
|
||||
|
||||
+6
@@ -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("illegal_sharing_with_weak.kt")
|
||||
public void testIllegal_sharing_with_weak() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/cinterop/objc/illegal_sharing_with_weak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt34467.kt")
|
||||
public void testKt34467() throws Exception {
|
||||
|
||||
+6
@@ -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("illegal_sharing_with_weak.kt")
|
||||
public void testIllegal_sharing_with_weak() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/cinterop/objc/illegal_sharing_with_weak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt34467.kt")
|
||||
public void testKt34467() throws Exception {
|
||||
|
||||
+6
@@ -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("illegal_sharing_with_weak.kt")
|
||||
public void testIllegal_sharing_with_weak() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/cinterop/objc/illegal_sharing_with_weak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt34467.kt")
|
||||
public void testKt34467() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user