From 126d1caba1c8dfca2f4a17af62c2fb928d2750aa Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Wed, 17 Jun 2020 17:25:44 +0300 Subject: [PATCH] Calculate expected value according to the platform endianness: layout of bytes is different for Big Endian mips32. --- backend.native/tests/interop/basics/union.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend.native/tests/interop/basics/union.kt b/backend.native/tests/interop/basics/union.kt index 43f958bd9f4..9eb21d51921 100644 --- a/backend.native/tests/interop/basics/union.kt +++ b/backend.native/tests/interop/basics/union.kt @@ -1,5 +1,6 @@ import cunion.* import kotlinx.cinterop.* +import kotlin.native.* import kotlin.test.* fun main() { @@ -7,7 +8,12 @@ fun main() { val basicUnion = alloc() for (value in Short.MIN_VALUE..Short.MAX_VALUE) { basicUnion.ll = value.toLong() - assertEquals(value.toShort(), basicUnion.s) + val expected = if (Platform.isLittleEndian) { + value + } else { + value.toLong() ushr (Long.SIZE_BITS - Short.SIZE_BITS) + } + assertEquals(expected.toShort(), basicUnion.s) } } memScoped { @@ -18,7 +24,12 @@ fun main() { memScoped { val union = alloc() union.b = 1u - assertEquals(1u, union.i) + var expected = if (Platform.isLittleEndian) { + 1u + } else { + 1u shl (Int.SIZE_BITS - Byte.SIZE_BITS) + } + assertEquals(expected, union.i) union.i = 0u assertEquals(0u, union.b) }