[K/N][Tests] Remove obsolete cppInterop tests

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-02-13 10:20:09 +01:00
committed by Space Team
parent b72effab98
commit 34af80943c
11 changed files with 0 additions and 571 deletions
@@ -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"
@@ -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 <class X> void fooTmplMember() const;
private:
CppTest* funPrivate() const;
static int s_funPrivate();
int iPriv;
};
int CppTest::counter;
CppTest retByValue(CppTest* s) {
return s ? *s : CppTest();
}
@@ -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>()
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>()
CppTest.__init__(x.ptr, 10, 3.8)
assertEquals(14, x.iPub)
}
}
@Test fun copyCtor(y: CppTest) {
val x = nativeHeap.alloc<CppTest>() {}
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<ns__NoName>()
var i = alloc<IntVar>()
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<CppTest>(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}}" )
}
*/
@@ -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 <typename T> class sk_sp {
public:
sk_sp(T* obj) : data(obj) {}
T* release() {
return data;
}
private:
T* data;
};
template <typename T> sk_sp<T> sk_ref_sp(T* obj) {
return sk_sp<T>(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<SkValue> foo(SkData *obj) {
SkValue* value = new SkValue();
value->setData(obj->data);
return sk_sp<SkValue>(value);
};
virtual SkData* bar(sk_sp<SkValue> obj) {
SkValue* value = obj.release();
SkData* data = new SkData();
data->setData(value->data);
return data;
};
virtual SkData* qux() {
return new SkData();
};
};
@@ -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")
}
@@ -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()
@@ -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 <typename T> class sk_sp {
public:
sk_sp(T* obj) : data(obj) {}
T* release() {
return data;
}
private:
T* data;
};
template <typename T> sk_sp<T> sk_ref_sp(T* obj) {
return sk_sp<T>(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;
};
};
@@ -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")
}
@@ -1,7 +0,0 @@
SkData()
SkData(19)
SkData(SkData*)
SkData(SkData*, SkData*)
SkData(200)
SkData(436)
true true true true true
@@ -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(); }
@@ -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<CppTest>(retByPtr(k).rawValue)
assertEquals(k, x.get())
}
@Test
fun test_retByPtrConst(k: Int) {
val x = interpretPointed<CppTest>(retByPtrConst(k).rawValue)
assertEquals(k, x.get())
}
@Test
fun test_retByRef(k: Int) {
val x = interpretPointed<CppTest>(retByRef(k).rawValue)
assertEquals(k, x.get())
}
@Test
fun test_retByRefConst(k: Int) {
val x = interpretPointed<CppTest>(retByRefConst(k).rawValue)
assertEquals(k, x.get())
}
/*
@Test
fun test_paramByValue(k: Int) {
val x = nativeHeap.alloc<CppTest>() {}
CppTest.__init__(x.ptr, k)
assertEquals(k, paramByValue(x.readValue()))
nativeHeap.free(x)
}
*/
@Test
fun test_paramByPtr(k: Int) {
val x = nativeHeap.alloc<CppTest>() {}
CppTest.__init__(x.ptr, k)
assertEquals(k, paramByPtr(x.ptr))
nativeHeap.free(x)
}
@Test
fun test_paramByPtrConst(k: Int) {
val x = nativeHeap.alloc<CppTest>() {}
CppTest.__init__(x.ptr, k)
assertEquals(k, paramByPtrConst(x.ptr))
nativeHeap.free(x)
}
@Test
fun test_paramByRef(k: Int) {
val x = nativeHeap.alloc<CppTest>() {}
CppTest.__init__(x.ptr, k)
assertEquals(k, paramByRef(x.ptr))
nativeHeap.free(x)
}
@Test
fun test_paramByRefConst(k: Int) {
val x = nativeHeap.alloc<CppTest>() {}
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())
}