Skip to content

Commit 5e58d89

Browse files
committed
Native: Improve KT-57335 test reliability via stack shifting
1 parent 4f676f4 commit 5e58d89

File tree

1 file changed

+18
-12
lines changed
  • native/native.tests/testData/codegen/vector

1 file changed

+18
-12
lines changed

native/native.tests/testData/codegen/vector/kt57335.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// WITH_PLATFORM_LIBS
33
// FREE_COMPILER_ARGS: -opt-in=kotlin.ExperimentalStdlibApi,kotlinx.cinterop.ExperimentalForeignApi
44

5-
// FILE: lib.kt
65
import kotlinx.cinterop.*
6+
import kotlin.test.*
77

88
value class Vector3(val data: Vector128) {
99
constructor(x: Float, y: Float, z: Float) : this(vectorOf(x, y, z, 0f))
@@ -28,22 +28,28 @@ value class Vector4(val data: Vector128) {
2828
override fun toString(): String = "Vector4(${x}, ${y}, ${z}, ${w})"
2929
}
3030

31-
// FILE: main.kt
32-
import kotlinx.cinterop.*
33-
34-
@OptIn(ExperimentalForeignApi::class)
35-
fun box(): String {
31+
fun performTest(): String {
3632
val v3 = Vector3(1f, 2f, 3f) + Vector3(10f, 20f, 30f)
3733
val v4 = Vector4(1f, 2f, 3f, 4f) + Vector4(10f, 20f, 30f, 40f)
34+
3835
val sumVecV3 = v3.toString()
3936
val sumVecV4 = v4.toString()
4037

41-
if (sumVecV3 != "Vector3(11.0, 22.0, 33.0)") {
42-
return "FAIL: sumVecV3 is ${sumVecV3}"
43-
}
44-
if (sumVecV4 != "Vector4(11.0, 22.0, 33.0, 44.0)") {
45-
return "FAIL: sumVecV4 is ${sumVecV4}"
46-
}
38+
if (sumVecV3 != "Vector3(11.0, 22.0, 33.0)") return "FAIL: sumVecV3 is ${sumVecV3}"
39+
if (sumVecV4 != "Vector4(11.0, 22.0, 33.0, 44.0)") return "FAIL: sumVecV4 is ${sumVecV4}"
4740

41+
return "OK"
42+
}
43+
44+
fun confuseStackAndRun(depth: Int): String {
45+
if (depth == 0) return performTest()
46+
return confuseStackAndRun(depth - 1)
47+
}
48+
49+
fun box(): String {
50+
for (i in 0..10) {
51+
val result = confuseStackAndRun(i)
52+
if (result != "OK") return result
53+
}
4854
return "OK"
4955
}

0 commit comments

Comments
 (0)