From 7b73595acaa6714a1349c4f0604d0a0b52617de6 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 6 Feb 2020 16:57:11 +0700 Subject: [PATCH] [Interop][Test] Extend bitfields test with signed enum --- backend.native/tests/interop/basics/bf.kt | 32 +++++++++++-------- .../tests/interop/basics/bitfields.def | 6 ++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/backend.native/tests/interop/basics/bf.kt b/backend.native/tests/interop/basics/bf.kt index a91bca7dccc..d8c7091f553 100644 --- a/backend.native/tests/interop/basics/bf.kt +++ b/backend.native/tests/interop/basics/bf.kt @@ -11,7 +11,7 @@ fun assertEquals(value1: Any?, value2: Any?) { throw AssertionError("Expected $value1, got $value2") } -fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long) { +fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) { assertEquals(x1, s.x1) assertEquals(x1, getX1(s.ptr)) @@ -29,18 +29,23 @@ fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long) { assertEquals(x6, s.x6) assertEquals(x6, getX6(s.ptr)) + + assertEquals(x7, s.x7) + assertEquals(x7, getX7(s.ptr)) } -fun assign(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long) { +fun assign(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) { s.x1 = x1 s.x2 = x2 s.x3 = x3 s.x4 = x4 s.x5 = x5 s.x6 = x6 + s.x7 = x7 } -fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long) { +fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) { + s.x7 = x7 s.x6 = x6 s.x5 = x5 s.x4 = x4 @@ -49,20 +54,20 @@ fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Lo s.x1 = x1 } -fun test(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long) { - assign(s, x1, x2, x3, x4, x5, x6) - check(s, x1, x2, x3, x4, x5, x6) +fun test(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) { + assign(s, x1, x2, x3, x4, x5, x6, x7) + check(s, x1, x2, x3, x4, x5, x6, x7) - assignReversed(s, x1, x2, x3, x4, x5, x6) - check(s, x1, x2, x3, x4, x5, x6) + assignReversed(s, x1, x2, x3, x4, x5, x6, x7) + check(s, x1, x2, x3, x4, x5, x6, x7) // Also check with some insignificant bits modified: - assign(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE) - check(s, x1, x2, x3, x4, x5, x6) + assign(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7) + check(s, x1, x2, x3, x4, x5, x6, x7) - assignReversed(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE) - check(s, x1, x2, x3, x4, x5, x6) + assignReversed(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7) + check(s, x1, x2, x3, x4, x5, x6, x7) } fun main(args: Array) { @@ -74,6 +79,7 @@ fun main(args: Array) { for (x4 in uintArrayOf(0u, 6u, 15u)) for (x5 in intArrayOf(-16, -2, -1, 0, 5, 15)) for (x6 in longArrayOf(Long.MIN_VALUE/2, -1L shl 36, -325L, 0, 1L shl 48, Long.MAX_VALUE/2)) - test(s, x1, x2, x3.toUShort(), x4, x5, x6) + for (x7 in E.values()) + test(s, x1, x2, x3.toUShort(), x4, x5, x6, x7) } } diff --git a/backend.native/tests/interop/basics/bitfields.def b/backend.native/tests/interop/basics/bitfields.def index 11bf1ca4b5c..4fcf1c734cb 100644 --- a/backend.native/tests/interop/basics/bitfields.def +++ b/backend.native/tests/interop/basics/bitfields.def @@ -3,6 +3,10 @@ enum B2 { ZERO, ONE, TWO, THREE }; +enum E : short { + A, B +}; + struct __attribute__((packed)) S { long long x1 : 1; enum B2 x2 : 2; @@ -10,6 +14,7 @@ struct __attribute__((packed)) S { unsigned int x4 : 4; int x5 : 5; long long x6 : 63; + enum E x7: 2; }; static long long getX1(struct S* s) { return s->x1; } @@ -18,3 +23,4 @@ static unsigned short getX3(struct S* s) { return s->x3; } static unsigned int getX4(struct S* s) { return s->x4; } static int getX5(struct S* s) { return s->x5; } static long long getX6(struct S* s) { return s->x6; } +static enum E getX7(struct S* s) { return s->x7; }