[K/N] Move special backend checks test sources to diagnostic tests folder

^KT-61564
This commit is contained in:
Vladimir Sukharev
2023-11-22 19:56:02 +01:00
committed by Space Team
parent 3d0a91bf3c
commit 8f12bf6cc8
67 changed files with 82 additions and 157 deletions
@@ -0,0 +1,60 @@
This testsuit fir specialBackendChecks on Mac hosts relies on platform libs are installed.
To run testsuit locally, make sure the above is executed first:
- `./gradlew :kotlin-native:platformLibs:macos_arm64Install` or
- `./gradlew :kotlin-native:platformLibs:macos_x64Install`
This testsuit is run differently for K1 and K2 frontends:
- K1/N manual: run `compiler/testData/diagnostics/nativeTests/specialBackendChecks/runtests.sh -language-version 1.9`,
- K2/N manual: run `compiler/testData/diagnostics/nativeTests/specialBackendChecks/runtests.sh`,
- K2/N tests are also run in scope of `FirLightTreeOldFrontendNativeDiagnosticsTestGenerated` and `FirPsiOldFrontendNativeDiagnosticsTestGenerated`.
Reference output for K1/N manual run is provided below.
Reference output for K2/N manual run is slightly different for newly-migrated Fir checks: source lines are displayed.
For not yet migrated checks, the output must be the same as below.
```text
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t1.kt
/tmp/t1.kt:12:5: error: variadic function pointers are not supported
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t10.kt
/tmp/t10.kt:8:5: error: type kotlin.Function1<*, kotlin.Int> of callback parameter 1 is not supported here: * as 1 parameter type
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t11.kt
/tmp/t11.kt:8:5: error: type kotlin.Function1<in kotlin.Int, kotlin.Int> of callback parameter 1 is not supported here: in-variance of 1 parameter type
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t12.kt
/tmp/t12.kt:8:5: error: type kotlinx.cinterop.CValue<*>? of callback parameter 1 is not supported here: must not be nullable
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t13.kt
/tmp/t13.kt:9:5: error: type kotlinx.cinterop.CValue<T of <root>.bar> of callback parameter 1 is not supported here: must be parameterized with concrete class
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t14.kt
/tmp/t14.kt:10:5: error: type kotlinx.cinterop.CValue<<root>.Z> of callback parameter 1 is not supported here: not a structure or too complex
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t37.kt
/tmp/t37.kt:8:5: error: subclasses of kotlinx.cinterop.NativePointed cannot have properties with backing fields
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t38.kt
/tmp/t38.kt:8:5: error: subclasses of kotlinx.cinterop.NativePointed cannot have properties with backing fields
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t40.kt
/tmp/t40.kt:10:5: error: kotlinx.cinterop.staticCFunction must take an unbound, non-capturing function or lambda, but captures at:
/tmp/t40.kt:10:21
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t41.kt
/tmp/t41.kt:9:5: error: kotlinx.cinterop.staticCFunction must take an unbound, non-capturing function or lambda, but captures at:
/tmp/t41.kt:7:17: x
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t42.kt
/tmp/t42.kt:8:5: error: c function signature element mismatch: expected 'kotlin.Any', got 'kotlin.String'
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t43.kt
/tmp/t43.kt:5:21: error: receiver's type kotlin.Float is not an integer type
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t44.kt
/tmp/t44.kt:5:21: error: type argument kotlin.Float is not an integer type
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t45.kt
/tmp/t45.kt:5:21: error: unable to sign extend kotlin.Int to kotlin.Short
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t46.kt
/tmp/t46.kt:5:21: error: unable to narrow kotlin.Int to kotlin.Long
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t47.kt
/tmp/t47.kt:5:21: error: unable to convert kotlin.Int to kotlin.String
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t60.kt
/tmp/t60.kt:6:5: error: subclasses of kotlinx.cinterop.NativePointed cannot have properties with backing fields
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t63.kt
/tmp/t63.kt:26:17: error: calling suspend functions from `autoreleasepool {}` is prohibited, see https://youtrack.jetbrains.com/issue/KT-50786
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t64.kt
/tmp/t64.kt:29:17: error: calling suspend functions from `autoreleasepool {}` is prohibited, see https://youtrack.jetbrains.com/issue/KT-50786
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t8.kt
/tmp/t8.kt:8:5: error: type kotlin.Function0<*> of callback parameter 1 is not supported here: * as return type
compiler/testData/diagnostics/nativeTests/specialBackendChecks/cInterop/t9.kt
```
@@ -0,0 +1,11 @@
import kotlinx.cinterop.*
fun foo(x: Int, vararg s: String): Int {
var sum = x
s.forEach { sum += it.length }
return sum
}
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function1<*, Int>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function1<in Int, Int>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(x: CValue<*>?) = x
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
fun <T: CVariable> bar() {
fun foo(x: CValue<T>) = x
staticCFunction(::foo)
}
@@ -0,0 +1,9 @@
import kotlinx.cinterop.*
class Z(rawPtr: NativePtr): CStructVar(rawPtr)
fun foo(x: CValue<Z>) = x
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,11 @@
import kotlinx.cinterop.*
import kotlinx.cinterop.internal.*
@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
val x: Pair<Int, Int>? = null
@CStruct.MemberAt(offset = 0L) get
}
fun foo(z: Z) = z.x
fun main() { }
@@ -0,0 +1,14 @@
import kotlinx.cinterop.*
import kotlinx.cinterop.internal.*
@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
var x: Pair<Int, Int>? = null
@CStruct.MemberAt(offset = 0L) get
@CStruct.MemberAt(offset = 0L) set
}
fun foo(z: Z) {
z.x = 42 to 117
}
fun main() { }
@@ -0,0 +1,9 @@
import kotlinx.cinterop.*
class Z {
fun foo(x: Int) = x
}
fun bar() {
staticCFunction(Z()::foo)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
fun bar(x: Int) {
fun foo() = x
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(x: Any) = x
fun bar() {
staticCFunction<String, Any>(::foo)
}
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Float) = x.signExtend<Int>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.signExtend<Float>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.signExtend<Short>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.narrow<Long>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.convert<String>()
@@ -0,0 +1,10 @@
import kotlinx.cinterop.*
class Vertex constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
var x: Float = 0f
var y: Float = 0f
var r: Float = 0f
var g: Float = 0f
var b: Float = 0f
companion object : CStructVar.Type(40, 8)
}
@@ -0,0 +1,30 @@
import kotlinx.cinterop.*
import kotlin.coroutines.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
lateinit var continuation: Continuation<Unit>
suspend fun suspendHere(): Unit = suspendCoroutine { cont ->
continuation = cont
}
fun startCoroutine(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
fun main() {
autoreleasepool {
startCoroutine {
autoreleasepool {
suspendHere()
}
}
}
continuation.resume(Unit)
}
@@ -0,0 +1,32 @@
import kotlinx.cinterop.*
import kotlin.coroutines.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
lateinit var continuation: Continuation<Unit>
suspend fun suspendHere(): Unit = suspendCoroutine { cont ->
continuation = cont
}
fun startCoroutine(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
inline fun <T> myAutoreleasepool(block: () -> T) = autoreleasepool(block)
fun main() {
autoreleasepool {
startCoroutine {
myAutoreleasepool {
suspendHere()
}
}
}
continuation.resume(Unit)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function0<*>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function0<out Int>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,10 @@
import kotlin.native.concurrent.*
class Z(val x: Int) {
fun bar(s: String) = s + x.toString()
}
fun foo(x: Int) {
val worker = Worker.start()
worker.execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar)
}
@@ -0,0 +1,6 @@
import kotlin.native.concurrent.*
fun foo(x: Int) {
val worker = Worker.start()
worker.execute(TransferMode.SAFE, { "zzz" }) { s -> s + x.toString() }
}
@@ -0,0 +1,14 @@
@file:OptIn(ObsoleteWorkersApi::class)
import kotlin.native.concurrent.*
class Z(val x: Int) {
fun bar(s: String) = s + x.toString()
}
class Q(x: Int) {
init {
val worker = Worker.start()
worker.execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar)
}
}
@@ -0,0 +1,11 @@
@file:OptIn(ObsoleteWorkersApi::class)
import kotlin.native.concurrent.*
class Z(val x: Int) {
fun bar(s: String) = s + x.toString()
}
class Q(x: Int) {
val z = Worker.start().execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar)
}
@@ -0,0 +1 @@
fun foo(arr: ShortArray) = immutableBlobOf(*arr)
@@ -0,0 +1 @@
fun foo(x: Short) = immutableBlobOf(x)
@@ -0,0 +1 @@
fun foo() = immutableBlobOf(1000)
@@ -0,0 +1 @@
fun foo() = immutableBlobOf()
@@ -0,0 +1,6 @@
import kotlin.native.ref.*
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun foo(x: Int) {
createCleaner(42) { println(x) }
}
@@ -0,0 +1,10 @@
import kotlin.native.ref.*
class C(val x: Int) {
fun bar(y: Int) = println(x + y)
}
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun foo(x: Int) {
createCleaner(42, C(x)::bar)
}
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = NSLog("zzz", {})
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
class Z
fun foo() = NSLog("zzz", Z())
@@ -0,0 +1,8 @@
import platform.darwin.*
import platform.Foundation.*
class Foo : NSObject(), NSPortDelegateProtocol {
fun foo() {
super.handlePortMessage(TODO())
}
}
@@ -0,0 +1,9 @@
import platform.darwin.*
class Foo : NSObject() {
companion object : NSObjectMeta() {
fun bar() {
super.hash()
}
}
}
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
override fun handleFailureInFunction(functionName: String, file: String, lineNumber: NSInteger /* = Long */, description: String?, vararg args: Any?) { }
}
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
interface Zzz : NSCopyingProtocolMeta
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
open class Zzz : NSAssertionHandler()
@@ -0,0 +1,8 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
companion object {
val Z = 42
}
}
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
interface I
class Zzz : NSAssertionHandler(), I
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSCopyingProtocolMeta
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
override fun toString() = "zzz"
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun String.foo() = println(this)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun foo(x: String) = println(x)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun foo() = 42
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCOutlet
val x: NSObject get() = this
}
@@ -0,0 +1,10 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCOutlet
var NSObject.x: NSObject
get() = this
set(value: NSObject) { }
}
@@ -0,0 +1,10 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCOutlet
var x: String
get() = "zzz"
set(value: String) { }
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler {
@OverrideInit
constructor(x: Int) { }
}
@@ -0,0 +1,10 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSString {
@OverrideInit
constructor(coder: NSCoder) { }
override fun initWithCoder(coder: NSCoder): String? = "zzz"
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun foo(x: NSObject, y: NSObject, z: NSObject) { }
}
@@ -0,0 +1,5 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSValue()
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = println(NSAssertionHandler()::handleFailureInFunction)
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, "qzz")
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo(s: Array<Any?>) = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, *s)
@@ -0,0 +1,9 @@
/*
* Copyright 2010-2022 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.
*/
// KT-50109
class Foo {
companion object : platform.darwin.NSObjectMeta()
}
@@ -0,0 +1,7 @@
/*
* Copyright 2010-2022 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.
*/
// KT-50109
class Foo : platform.darwin.NSObjectMeta()
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo(s: Array<Any?>) = NSLog("zzz", *s)
@@ -0,0 +1,5 @@
import platform.posix.*
fun main() {
println(::printf)
}
@@ -0,0 +1,4 @@
import kotlinx.cinterop.*
import platform.posix.*
fun foo() = stat(malloc(42u)!!.rawValue)
@@ -0,0 +1,7 @@
import kotlin.reflect.*
@OptIn(kotlin.ExperimentalStdlibApi::class)
fun <T : Comparable<T>> foo() {
typeOf<List<T>>()
}
@@ -0,0 +1,7 @@
import kotlin.reflect.*
@OptIn(kotlin.ExperimentalStdlibApi::class)
inline fun <T : Comparable<T>> foo() {
typeOf<List<T>>()
}
@@ -0,0 +1,12 @@
#
# 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.
#
# Usage: compiler/testData/diagnostics/nativeTests/specialBackendChecks/runtest.sh <t??.kt> <-language-version 1.9>
FILTERED_FILE=/tmp/$(basename $1)
# Remove diagnostic directives from test source
cat $1 | sed -e 's/<![a-zA-Z_!]*!>//g' | sed -e 's/<!>//g' > $FILTERED_FILE
shift
konanc -opt-in=kotlin.native.internal.InternalForKotlinNative "$FILTERED_FILE" "$@"
@@ -0,0 +1,10 @@
#
# 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.
#
SOURCE=${BASH_SOURCE[0]}
SCRIPT_DIR=$(dirname $SOURCE)
for TEST in $SCRIPT_DIR/**/*.kt; do
echo "$TEST"
compiler/testData/diagnostics/nativeTests/specialBackendChecks/runtest.sh $TEST "$@"
done