diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 6a580e829b1..a1eaed78061 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1018,22 +1018,6 @@ createInterop("leakMemoryWithRunningThread") { it.extraOpts "-Xcompile-source", "$projectDir/interop/leakMemoryWithRunningThread/leakMemory.cpp" } -createInterop("cppClass") { - it.defFile 'interop/cpp/cppClass.def' -} - -createInterop("cppTypes") { - it.defFile 'interop/cpp/types.def' -} - -createInterop("cppSkia") { - it.defFile 'interop/cpp/skia.def' -} - -createInterop("cppSkiaSignature") { - it.defFile 'interop/cpp/skiaSignature.def' -} - createInterop("workerSignals") { it.defFile "interop/workerSignals/workerSignals.def" it.headers "$projectDir/interop/workerSignals/workerSignals.h" @@ -1221,34 +1205,6 @@ interopTest("interop_leakMemoryWithRunningThreadChecked") { outputChecker = { s -> s.contains("Cannot run checkers when there are 1 alive runtimes at the shutdown") } } -interopTest("interop_cppClass") { - disabled = PlatformInfo.isAppleTarget(project) // KT-58422 - source = "interop/cpp/cppClass.kt" - interop = 'cppClass' -} - -interopTest("interop_cppTypes") { - disabled = PlatformInfo.isAppleTarget(project) // KT-58422 - source = "interop/cpp/types.kt" - interop = 'cppTypes' -} - -interopTest("interop_cppSkia") { - disabled = true // KT-58422 - source = "interop/cpp/skia.kt" - interop = 'cppSkia' - useGoldenData = true - UtilsKt.dependsOnPlatformLibs(it) -} - -interopTest("interop_cppSkiaSignature") { - disabled = PlatformInfo.isAppleTarget(project) // KT-58422 - source = "interop/cpp/skiaSignature.kt" - interop = "cppSkiaSignature" - useGoldenData = true - UtilsKt.dependsOnPlatformLibs(it) -} - interopTest("interop_workerSignals") { disabled = project.testTarget == 'mingw_x64' // cross-thread signalling does not work on Windows source = "interop/workerSignals/workerSignals.kt" diff --git a/kotlin-native/backend.native/tests/interop/cpp/cppClass.def b/kotlin-native/backend.native/tests/interop/cpp/cppClass.def deleted file mode 100644 index 5238de60c35..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/cppClass.def +++ /dev/null @@ -1,42 +0,0 @@ -language = C++ -compilerOpts = -std=c++14 -plugin = org.jetbrains.kotlin.native.interop.skia - ---- -class CppTest { -public: - CppTest() { ++counter; } - - CppTest(const CppTest&) = default; - - explicit CppTest(int i, double j = 3.14) : iPub(i + int(j + 0.5)) {} - - ~CppTest() { --counter; } - - int iPub = 42; - - virtual int foo() { return iPub; } - - static int counter; - static int s_fun() { return counter; } - - class Nested { - public: - int nestedFoo() { return -2; } - } nested; - -// not supported yet - operator CppTest::Nested() const; - template void fooTmplMember() const; - -private: - CppTest* funPrivate() const; - static int s_funPrivate(); - int iPriv; -}; - -int CppTest::counter; - -CppTest retByValue(CppTest* s) { - return s ? *s : CppTest(); -} diff --git a/kotlin-native/backend.native/tests/interop/cpp/cppClass.kt b/kotlin-native/backend.native/tests/interop/cpp/cppClass.kt deleted file mode 100644 index f5ae5bf6245..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/cppClass.kt +++ /dev/null @@ -1,137 +0,0 @@ -@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) - -import kotlinx.cinterop.* -import kotlin.test.* - -import cppClass.* - -class FeatureTest { - - @Test fun ctorDefault() { - memScoped { - val x = alloc() - CppTest.__init__(x.ptr) - assertEquals(42, x.iPub) - assertEquals(42, x.foo()) - // dtor is not called, leak is intentional for the purpose of UT - } - } - - @Test fun ctorWithParam() { - memScoped { - val x = alloc() - CppTest.__init__(x.ptr, 10, 3.8) - assertEquals(14, x.iPub) - } - } - - @Test fun copyCtor(y: CppTest) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, y.ptr) - - assertEquals(y.iPub, x.iPub) - nativeHeap.free(x) - } -/* - @Test fun reinitWithCtorAndDtor(y: CppTest) { - val count = CppTest.getCount() - val x = nativeHeap.alloc< CppTest>() {} - CppTest.__init__(x.ptr, y.ptr) - assertEquals( CppTest.getCount(), count + 1) - assertEquals(y.iPub, x.iPub) - - CppTest.__destroy__(x.ptr) - y.iPub = -11 - assertEquals(y.iPub, -11) - CppTest.__init__(x.ptr, y.ptr) - assertEquals(x.iPub, -11) - - CppTest.__destroy__(x.ptr) - assertEquals( CppTest.getCount(), count) - - nativeHeap.free(x) - } - - @Test fun publicField(x : CppTest) { - x.iPub = 21 - assertEquals(22, x.foo(x.ptr)) - } - - @Test fun lvRefParameter() { - memScoped { - val x = alloc() - var i = alloc() - i.value = 758 - assertEquals(x.noNameMember(i.ptr), 759) - assertEquals(i.value, 759) - } - - } - - @Test fun staticField() { - val save = CppTest.getCount() - assertEquals( CppTest.getCount(), CppTest.counter) - - CppTest.counter = 654 - assertEquals( CppTest.getCount(), 654) - assertEquals( CppTest.getCount(), CppTest.counter) - - CppTest.counter = save - assertEquals( CppTest.getCount(), save) - } -*/ -} - -fun main() { - - val testRun = FeatureTest() - testRun.ctorDefault() - testRun.ctorWithParam() - - // By value for C++ requires further design of stubs mechanism. - // So not supported for now. - //val a0 = retByValue(null) - //println("a0.useContents {iPub} = ${a0.useContents {iPub}}" ) - //println("a0.useContents { foo() } = ${a0.useContents { foo() }}" ) - -// retByValue(null)!!.getValue().foo() -// val a1 = interpretPointed(retByValue(null).rawValue) -// println(a1.foo()) -/* - val a1 = interpretPointed< CppTest>(ns__create().rawValue) - testRun.publicField(a1) - - testRun.staticField() - - testRun.lvRefParameter() - - a1.iPub = 112 - testRun.copyCtor(a1) - testRun.reinitWithCtorAndDtor(a1) - */ -} -/* -fun testStatic() { - println(" CppTest.s_fun() returns ${ CppTest.s_fun()}") - println(" CppTest.s_fun() returns ${ CppTest.s_fun()}") - println(" CppTest.s_fun() returns ${ CppTest.s_fun()}") -} - -fun testCtor() { - println("testCtor") - val cxx = nativeHeap.alloc< CppTest>() { - memcpy(ptr, ns__create(), typeOf< CppTest>().size.convert()) // use placement new here - } - cxx.foo(null) - nativeHeap.free(cxx) -} - -fun test2() { - println("test2") - val x = ns__bar(null) -// val theS = interpretPointed< CppTest>(ns__bar(null).rawValue) -// theS.foo(null) - - println("x.useContents {iPub} = ${x.useContents {iPub}}" ) -} -*/ diff --git a/kotlin-native/backend.native/tests/interop/cpp/skia.def b/kotlin-native/backend.native/tests/interop/cpp/skia.def deleted file mode 100644 index 9fb5e5f77fd..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skia.def +++ /dev/null @@ -1,87 +0,0 @@ -language = C++ -compilerOpts = -std=c++17 -plugin = org.jetbrains.kotlin.native.interop.skia -package = org.jetbrains.skiko.skia.native -headers = stdio.h - ---- -// TODO: this one checks the syntactic aspect for now. -// To be updated for proper c++ destructor and -// kotlin garbage collection interaction. - - -template class sk_sp { -public: - sk_sp(T* obj) : data(obj) {} - T* release() { - return data; - } -private: - T* data; -}; - -template sk_sp sk_ref_sp(T* obj) { - return sk_sp(obj); -} - -class SkValue { - public: - SkValue() { - printf("SkValue()\n"); - }; - - void unref() { - printf("unref\n"); - }; - - int data; - void setData(int val) { - data = val; - }; -}; - -class SkData { - public: - SkData() { - printf("SkData()\n"); - }; - - ~SkData() { - printf("~SkData()\n"); - }; - - int data; - - void setData(int val) { - data = val; - }; -}; - -class SkFoo { -public: - SkFoo() { - printf("SkFoo()\n"); - }; - - ~SkFoo() { - printf("~SkFoo()\n"); - }; - - virtual sk_sp foo(SkData *obj) { - SkValue* value = new SkValue(); - value->setData(obj->data); - return sk_sp(value); - }; - - virtual SkData* bar(sk_sp obj) { - SkValue* value = obj.release(); - SkData* data = new SkData(); - data->setData(value->data); - return data; - }; - - virtual SkData* qux() { - return new SkData(); - }; -}; - diff --git a/kotlin-native/backend.native/tests/interop/cpp/skia.kt b/kotlin-native/backend.native/tests/interop/cpp/skia.kt deleted file mode 100644 index 6eaae5734a4..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skia.kt +++ /dev/null @@ -1,33 +0,0 @@ -@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -@file:Suppress("OPT_IN_USAGE_ERROR") - -import kotlinx.cinterop.* -import kotlin.test.* -import kotlin.native.internal.* - -import org.jetbrains.skiko.skia.native.* -import platform.posix.printf - -fun main() { - - // TODO: the test used to work with forceCheckedShutdown, - // but it is broken now. Revisit after it is fixed. - // kotlin.native.runtime.Debugging.forceCheckedShutdown = true - Platform.isCleanersLeakCheckerActive = true - - val f = Foo() - - val a = Data() - a.setData(17) - val b = f.qux()!! - b.setData(19) - - val v = f.foo(a) - val c = f.bar(v)!! - - // Use printf instead of println to avoid messages - // appearing out of order with the native code. - // The native code uses printf. - printf("MANAGED: f: ${f.managed}, a: ${a.managed}, b: ${b.managed}, v: ${v.managed}, c: ${c.managed}\n") - printf("DATA: ${a.cpp.data} ${b.cpp.data} ${v.cpp.data} ${c.cpp.data}\n") -} diff --git a/kotlin-native/backend.native/tests/interop/cpp/skia.out b/kotlin-native/backend.native/tests/interop/cpp/skia.out deleted file mode 100644 index f374642cd70..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skia.out +++ /dev/null @@ -1,10 +0,0 @@ -SkFoo() -SkData() -SkData() -SkValue() -SkData() -MANAGED: f: true, a: true, b: false, v: true, c: false -DATA: 17 19 17 17 -unref -~SkData() -~SkFoo() diff --git a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.def b/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.def deleted file mode 100644 index 935f3cb482d..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.def +++ /dev/null @@ -1,61 +0,0 @@ -language = C++ -compilerOpts = -std=c++17 -plugin = org.jetbrains.kotlin.native.interop.skia -package = org.jetbrains.skiko.skia.native -headers = stdio.h - ---- -// TODO: this one checks the syntactic aspect for now. -// To be updated for proper c++ destructor and -// kotlin garbage collection interaction. - - -template class sk_sp { -public: - sk_sp(T* obj) : data(obj) {} - T* release() { - return data; - } -private: - T* data; -}; - -template sk_sp sk_ref_sp(T* obj) { - return sk_sp(obj); -} - -class SkData { - public: - SkData() { - printf("SkData()\n"); - }; - - SkData(int val) { - printf("SkData(%d)\n", val); - data = val + 100; - }; - - SkData(SkData* obj) { - printf("SkData(SkData*)\n"); - data = obj->data + 200; - }; - - SkData(SkData* obj, SkData* obj2) { - printf("SkData(SkData*, SkData*)\n"); - data = obj->data + obj2->data + 300; - }; - - SkData* foo(SkData* obj, SkData* obj2) { - return new SkData(obj->data + obj2->data + data); - }; - - int data; - - void setData(int val) { - data = val; - }; - - int checkData(int val) { - return val == data; - }; -}; diff --git a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.kt b/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.kt deleted file mode 100644 index 611f37d5f33..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.kt +++ /dev/null @@ -1,29 +0,0 @@ -@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) -@file:Suppress("OPT_IN_USAGE_ERROR") - -import kotlinx.cinterop.* -import kotlin.test.* -import kotlin.native.internal.* - -import org.jetbrains.skiko.skia.native.* -import platform.posix.printf - -fun main() { - val a = Data() - a.setData(17) - val b = Data(19) - val c = Data(a) - val d = Data(a, b) - val e = Data(200).foo(a, b)!! - - val a1 = a.checkData(17) != 0 - val b1 = b.checkData(119) != 0 - val c1 = c.checkData(217) != 0 - val d1 = d.checkData(436) != 0 - val e1 = e.checkData(536) != 0 - - // Use printf instead of println to avoid messages - // appearing out of order with the native code. - // The native code uses printf. - printf("$a1 $b1 $c1 $d1 $e1\n") -} diff --git a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.out b/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.out deleted file mode 100644 index cd28fca7396..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/skiaSignature.out +++ /dev/null @@ -1,7 +0,0 @@ -SkData() -SkData(19) -SkData(SkData*) -SkData(SkData*, SkData*) -SkData(200) -SkData(436) -true true true true true diff --git a/kotlin-native/backend.native/tests/interop/cpp/types.def b/kotlin-native/backend.native/tests/interop/cpp/types.def deleted file mode 100644 index f702069d305..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/types.def +++ /dev/null @@ -1,25 +0,0 @@ -language = C++ -compilerOpts = -std=c++14 -plugin = org.jetbrains.kotlin.native.interop.skia -package = cpptypes - ---- - -class CppTest { -public: - explicit CppTest(int m) : n(m) {} - int n = 11; - virtual int get() const { return n; } - virtual void set(int m) { n = m; } -}; - -CppTest retByValue(int k) { return CppTest(k); } -CppTest* retByPtr(int k) { return new CppTest(k); } // Leak is intentional -CppTest const* retByPtrConst(int k) { return new CppTest(k); } // Leak is intentional -CppTest& retByRef(int k) { return * new CppTest(k); } // Leak is intentional -CppTest const& retByRefConst(int k) { return * new CppTest(k); } // Leak is intentional -int paramByValue(CppTest x) { return x.get(); } -int paramByPtr(CppTest* x) { return x? x->get() : 0; } -int paramByPtrConst(CppTest const* x) { return x? x->get() : 0; } -int paramByRef(CppTest& x) { return x.get(); } -int paramByRefConst(CppTest const& x) { return x.get(); } diff --git a/kotlin-native/backend.native/tests/interop/cpp/types.kt b/kotlin-native/backend.native/tests/interop/cpp/types.kt deleted file mode 100644 index 15580e24292..00000000000 --- a/kotlin-native/backend.native/tests/interop/cpp/types.kt +++ /dev/null @@ -1,96 +0,0 @@ -@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) - -import kotlinx.cinterop.* -import kotlin.test.* -import kotlin.random.* - -import cpptypes.* -/* -@Test -fun test_retByValue(k: Int) { - memScoped { - val x: CppTest = retByValue(k).getPointer(memScope).pointed - assertEquals(k, x.get()) - } -} -*/ - -@Test -fun test_retByPtr(k: Int) { - val x = interpretPointed(retByPtr(k).rawValue) - assertEquals(k, x.get()) -} - -@Test -fun test_retByPtrConst(k: Int) { - val x = interpretPointed(retByPtrConst(k).rawValue) - assertEquals(k, x.get()) -} - -@Test -fun test_retByRef(k: Int) { - val x = interpretPointed(retByRef(k).rawValue) - assertEquals(k, x.get()) -} - -@Test -fun test_retByRefConst(k: Int) { - val x = interpretPointed(retByRefConst(k).rawValue) - assertEquals(k, x.get()) -} -/* -@Test -fun test_paramByValue(k: Int) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, k) - assertEquals(k, paramByValue(x.readValue())) - nativeHeap.free(x) -} -*/ -@Test -fun test_paramByPtr(k: Int) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, k) - assertEquals(k, paramByPtr(x.ptr)) - nativeHeap.free(x) -} - -@Test -fun test_paramByPtrConst(k: Int) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, k) - assertEquals(k, paramByPtrConst(x.ptr)) - nativeHeap.free(x) -} - -@Test -fun test_paramByRef(k: Int) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, k) - assertEquals(k, paramByRef(x.ptr)) - nativeHeap.free(x) -} - -@Test -fun test_paramByRefConst(k: Int) { - val x = nativeHeap.alloc() {} - CppTest.__init__(x.ptr, k) - assertEquals(k, paramByRefConst(x.ptr)) - nativeHeap.free(x) -} - -fun main() { - val seed = Random.nextInt() - val r = Random(seed) - - //test_retByValue(r.nextInt()) - test_retByPtr(r.nextInt()) - test_retByPtrConst(r.nextInt()) - test_retByRef(r.nextInt()) - test_retByRefConst(r.nextInt()) - //test_paramByValue(r.nextInt()) - test_paramByPtr(r.nextInt()) - test_paramByPtrConst(r.nextInt()) - test_paramByRef(r.nextInt()) - test_paramByRefConst(r.nextInt()) -}