[K/N] Migrate misc runtime/ tests to new testing infra ^KT-61259
This commit is contained in:
committed by
Space Team
parent
364dcd30c8
commit
fd1579186f
@@ -2880,10 +2880,6 @@ standaloneTest("memory_only_gc") {
|
||||
source = "runtime/memory/only_gc.kt"
|
||||
}
|
||||
|
||||
tasks.register("memory_stable_ref_cross_thread_check", KonanLocalTest) {
|
||||
source = "runtime/memory/stable_ref_cross_thread_check.kt"
|
||||
}
|
||||
|
||||
standaloneTest("leakMemory") {
|
||||
source = "runtime/memory/leak_memory.kt"
|
||||
}
|
||||
@@ -4277,10 +4273,6 @@ tasks.register("interop_sourceCodeStruct", KonanLocalTest) {
|
||||
source = "codegen/intrinsics/interop_sourceCodeStruct.kt"
|
||||
}
|
||||
|
||||
tasks.register("interop_alloc_value", KonanLocalTest) {
|
||||
source = "runtime/interop/interop_alloc_value.kt"
|
||||
}
|
||||
|
||||
standaloneTest("isExperimentalMM") {
|
||||
source = "codegen/intrinsics/isExperimentalMM.kt"
|
||||
flags = [ "-tr" ]
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
|
||||
package runtime.interop.interop_alloc_value
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun testBoolean() = memScoped {
|
||||
assertEquals(true, alloc(true).value)
|
||||
assertEquals(false, alloc(false).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testByte() = memScoped<Unit> {
|
||||
assertEquals(Byte.MIN_VALUE, alloc(Byte.MIN_VALUE).value)
|
||||
assertEquals(Byte.MAX_VALUE, alloc(Byte.MAX_VALUE).value)
|
||||
assertEquals(0.toByte(), alloc(0.toByte()).value)
|
||||
assertEquals(1.toByte(), alloc(1.toByte()).value)
|
||||
assertEquals(1, alloc<Byte>(1).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShort() = memScoped<Unit> {
|
||||
assertEquals(Short.MIN_VALUE, alloc(Short.MIN_VALUE).value)
|
||||
assertEquals(Short.MAX_VALUE, alloc(Short.MAX_VALUE).value)
|
||||
assertEquals(0.toShort(), alloc(0.toShort()).value)
|
||||
assertEquals(2.toShort(), alloc(2.toShort()).value)
|
||||
assertEquals(2, alloc<Short>(2).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInt() = memScoped<Unit> {
|
||||
assertEquals(Int.MIN_VALUE, alloc(Int.MIN_VALUE).value)
|
||||
assertEquals(Int.MAX_VALUE, alloc(Int.MAX_VALUE).value)
|
||||
assertEquals(0.toInt(), alloc(0.toInt()).value)
|
||||
assertEquals(3.toInt(), alloc(3.toInt()).value)
|
||||
assertEquals(3, alloc<Int>(3).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLong() = memScoped<Unit> {
|
||||
assertEquals(Long.MIN_VALUE, alloc(Long.MIN_VALUE).value)
|
||||
assertEquals(Long.MAX_VALUE, alloc(Long.MAX_VALUE).value)
|
||||
assertEquals(0L, alloc(0L).value)
|
||||
assertEquals(4L, alloc(4L).value)
|
||||
assertEquals(4, alloc<Long>(4).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUByte() = memScoped<Unit> {
|
||||
assertEquals(UByte.MIN_VALUE, alloc(UByte.MIN_VALUE).value)
|
||||
assertEquals(UByte.MAX_VALUE, alloc(UByte.MAX_VALUE).value)
|
||||
assertEquals(5.toUByte(), alloc(5.toUByte()).value)
|
||||
assertEquals(5u, alloc<UByte>(5u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUShort() = memScoped<Unit> {
|
||||
assertEquals(UShort.MIN_VALUE, alloc(UShort.MIN_VALUE).value)
|
||||
assertEquals(UShort.MAX_VALUE, alloc(UShort.MAX_VALUE).value)
|
||||
assertEquals(6.toUShort(), alloc(6.toUShort()).value)
|
||||
assertEquals(6u, alloc<UShort>(6u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUInt() = memScoped<Unit> {
|
||||
assertEquals(UInt.MIN_VALUE, alloc(UInt.MIN_VALUE).value)
|
||||
assertEquals(UInt.MAX_VALUE, alloc(UInt.MAX_VALUE).value)
|
||||
assertEquals(7.toUInt(), alloc(7.toUInt()).value)
|
||||
assertEquals(7u, alloc<UInt>(7u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testULong() = memScoped<Unit> {
|
||||
assertEquals(ULong.MIN_VALUE, alloc(ULong.MIN_VALUE).value)
|
||||
assertEquals(ULong.MAX_VALUE, alloc(ULong.MAX_VALUE).value)
|
||||
assertEquals(8uL, alloc(8uL).value)
|
||||
assertEquals(8u, alloc<ULong>(8u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFloat() = memScoped<Unit> {
|
||||
assertEquals(Float.MIN_VALUE, alloc(Float.MIN_VALUE).value)
|
||||
assertEquals(Float.MAX_VALUE, alloc(Float.MAX_VALUE).value)
|
||||
assertEquals(0.0f, alloc(0.0f).value)
|
||||
assertEquals(9.0f, alloc(9.0f).value)
|
||||
assertEquals(9.0f, alloc<Float>(9.0f).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDouble() = memScoped<Unit> {
|
||||
assertEquals(Double.MIN_VALUE, alloc(Double.MIN_VALUE).value)
|
||||
assertEquals(Double.MAX_VALUE, alloc(Double.MAX_VALUE).value)
|
||||
assertEquals(0.0, alloc(0.0).value)
|
||||
assertEquals(10.0, alloc(10.0).value)
|
||||
assertEquals(10.0, alloc<Double>(10.0).value)
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.
|
||||
*/
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
|
||||
package runtime.memory.stable_ref_cross_thread_check
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
class Holder(val value: Int)
|
||||
|
||||
@Test
|
||||
fun runTest1() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val future = worker.execute(TransferMode.SAFE, { }) {
|
||||
StableRef.create(Holder(42))
|
||||
}
|
||||
val ref = future.result
|
||||
if (kotlin.native.Platform.memoryModel == kotlin.native.MemoryModel.EXPERIMENTAL) {
|
||||
val value = ref.get()
|
||||
assertEquals(value.value, 42)
|
||||
} else {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
val value = ref.get()
|
||||
println(value.value)
|
||||
}
|
||||
}
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest2() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val mainThreadRef = StableRef.create(Holder(42))
|
||||
// Simulate this going through interop as raw C pointer.
|
||||
val pointerValue: Long = mainThreadRef.asCPointer().toLong()
|
||||
val future = worker.execute(TransferMode.SAFE, { pointerValue }) {
|
||||
val pointer: COpaquePointer = it.toCPointer()!!
|
||||
if (kotlin.native.Platform.memoryModel == kotlin.native.MemoryModel.EXPERIMENTAL) {
|
||||
val otherThreadRef: StableRef<Holder> = pointer.asStableRef()
|
||||
assertEquals(otherThreadRef.get().value, 42)
|
||||
} else {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
// Even attempting to convert a pointer to StableRef should fail.
|
||||
val otherThreadRef: StableRef<Holder> = pointer.asStableRef()
|
||||
println(otherThreadRef.get().value)
|
||||
}
|
||||
}
|
||||
Unit
|
||||
}
|
||||
future.result
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
@@ -20,15 +20,3 @@ class Node(var next: Node?)
|
||||
kotlin.native.ref.WeakReference(node1)
|
||||
println("OK")
|
||||
}
|
||||
|
||||
@Test fun runTest2() {
|
||||
val string = "Hello"
|
||||
val refString = WeakReference(string)
|
||||
assertEquals(string, refString.value)
|
||||
val zero = 0
|
||||
val refZero = WeakReference(zero)
|
||||
assertEquals(0, refZero.value)
|
||||
val long = Long.MAX_VALUE
|
||||
val refLong = WeakReference(long)
|
||||
assertEquals(Long.MAX_VALUE, refLong.value)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package test.kotlinx.cinterop
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
class AllocTest {
|
||||
@Test
|
||||
fun boolean() = memScoped {
|
||||
assertEquals(true, alloc(true).value)
|
||||
assertEquals(false, alloc(false).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun byte() = memScoped<Unit> {
|
||||
assertEquals(Byte.MIN_VALUE, alloc(Byte.MIN_VALUE).value)
|
||||
assertEquals(Byte.MAX_VALUE, alloc(Byte.MAX_VALUE).value)
|
||||
assertEquals(0.toByte(), alloc(0.toByte()).value)
|
||||
assertEquals(1.toByte(), alloc(1.toByte()).value)
|
||||
assertEquals(1, alloc<Byte>(1).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun short() = memScoped<Unit> {
|
||||
assertEquals(Short.MIN_VALUE, alloc(Short.MIN_VALUE).value)
|
||||
assertEquals(Short.MAX_VALUE, alloc(Short.MAX_VALUE).value)
|
||||
assertEquals(0.toShort(), alloc(0.toShort()).value)
|
||||
assertEquals(2.toShort(), alloc(2.toShort()).value)
|
||||
assertEquals(2, alloc<Short>(2).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun int() = memScoped<Unit> {
|
||||
assertEquals(Int.MIN_VALUE, alloc(Int.MIN_VALUE).value)
|
||||
assertEquals(Int.MAX_VALUE, alloc(Int.MAX_VALUE).value)
|
||||
assertEquals(0.toInt(), alloc(0.toInt()).value)
|
||||
assertEquals(3.toInt(), alloc(3.toInt()).value)
|
||||
assertEquals(3, alloc<Int>(3).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun long() = memScoped<Unit> {
|
||||
assertEquals(Long.MIN_VALUE, alloc(Long.MIN_VALUE).value)
|
||||
assertEquals(Long.MAX_VALUE, alloc(Long.MAX_VALUE).value)
|
||||
assertEquals(0L, alloc(0L).value)
|
||||
assertEquals(4L, alloc(4L).value)
|
||||
assertEquals(4, alloc<Long>(4).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uByte() = memScoped<Unit> {
|
||||
assertEquals(UByte.MIN_VALUE, alloc(UByte.MIN_VALUE).value)
|
||||
assertEquals(UByte.MAX_VALUE, alloc(UByte.MAX_VALUE).value)
|
||||
assertEquals(5.toUByte(), alloc(5.toUByte()).value)
|
||||
assertEquals(5u, alloc<UByte>(5u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uShort() = memScoped<Unit> {
|
||||
assertEquals(UShort.MIN_VALUE, alloc(UShort.MIN_VALUE).value)
|
||||
assertEquals(UShort.MAX_VALUE, alloc(UShort.MAX_VALUE).value)
|
||||
assertEquals(6.toUShort(), alloc(6.toUShort()).value)
|
||||
assertEquals(6u, alloc<UShort>(6u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uInt() = memScoped<Unit> {
|
||||
assertEquals(UInt.MIN_VALUE, alloc(UInt.MIN_VALUE).value)
|
||||
assertEquals(UInt.MAX_VALUE, alloc(UInt.MAX_VALUE).value)
|
||||
assertEquals(7.toUInt(), alloc(7.toUInt()).value)
|
||||
assertEquals(7u, alloc<UInt>(7u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uLong() = memScoped<Unit> {
|
||||
assertEquals(ULong.MIN_VALUE, alloc(ULong.MIN_VALUE).value)
|
||||
assertEquals(ULong.MAX_VALUE, alloc(ULong.MAX_VALUE).value)
|
||||
assertEquals(8uL, alloc(8uL).value)
|
||||
assertEquals(8u, alloc<ULong>(8u).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun float() = memScoped<Unit> {
|
||||
assertEquals(Float.MIN_VALUE, alloc(Float.MIN_VALUE).value)
|
||||
assertEquals(Float.MAX_VALUE, alloc(Float.MAX_VALUE).value)
|
||||
assertEquals(0.0f, alloc(0.0f).value)
|
||||
assertEquals(9.0f, alloc(9.0f).value)
|
||||
assertEquals(9.0f, alloc<Float>(9.0f).value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun double() = memScoped<Unit> {
|
||||
assertEquals(Double.MIN_VALUE, alloc(Double.MIN_VALUE).value)
|
||||
assertEquals(Double.MAX_VALUE, alloc(Double.MAX_VALUE).value)
|
||||
assertEquals(0.0, alloc(0.0).value)
|
||||
assertEquals(10.0, alloc(10.0).value)
|
||||
assertEquals(10.0, alloc<Double>(10.0).value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package test.kotlinx.cinterop
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.test.*
|
||||
|
||||
private class Box(val value: Int)
|
||||
|
||||
class StableRefTest {
|
||||
@Test
|
||||
fun crossThreadPassing() = withWorker {
|
||||
val future = execute(TransferMode.SAFE, {}) {
|
||||
StableRef.create(Box(42))
|
||||
}
|
||||
assertEquals(42, future.result.get().value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun crossThreadPassingAsPointer() = withWorker {
|
||||
val mainThreadRef = StableRef.create(Box(42))
|
||||
// Simulate this going through interop as raw C pointer.
|
||||
val pointerValue: Long = mainThreadRef.asCPointer().toLong()
|
||||
val future = execute(TransferMode.SAFE, { pointerValue }) {
|
||||
val pointer: COpaquePointer = it.toCPointer()!!
|
||||
val otherThreadRef: StableRef<Box> = pointer.asStableRef()
|
||||
otherThreadRef.get().value
|
||||
}
|
||||
assertEquals(42, future.result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package test.native.ref
|
||||
|
||||
import kotlin.native.ref.WeakReference
|
||||
import kotlin.test.*
|
||||
|
||||
class WeakReferenceTest {
|
||||
@Test
|
||||
fun string() {
|
||||
val v = "Hello"
|
||||
val weak = WeakReference(v)
|
||||
assertEquals(v, weak.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun int() {
|
||||
val v = 0
|
||||
val weak = WeakReference(v)
|
||||
assertEquals(0, weak.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun long() {
|
||||
val v = Long.MAX_VALUE
|
||||
val weak = WeakReference(v)
|
||||
assertEquals(Long.MAX_VALUE, weak.value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user