diff options
Diffstat (limited to 'testsuites/sptests/spatomic01/init.c')
-rw-r--r-- | testsuites/sptests/spatomic01/init.c | 155 |
1 files changed, 110 insertions, 45 deletions
diff --git a/testsuites/sptests/spatomic01/init.c b/testsuites/sptests/spatomic01/init.c index b90ffd05f5..b5fa6c4a7a 100644 --- a/testsuites/sptests/spatomic01/init.c +++ b/testsuites/sptests/spatomic01/init.c @@ -27,8 +27,9 @@ const char rtems_test_name[] = "SPATOMIC 1"; typedef struct { - Atomic_Uint atomic_int_value; - Atomic_Ulong atomic_value; + Atomic_Uint uint_atomic; + Atomic_Uintptr uintptr_atomic; + Atomic_Ulong ulong_atomic; } test_context; static test_context test_instance; @@ -43,19 +44,20 @@ static void test_static_and_dynamic_initialization(void) static Atomic_Uint static_uint = ATOMIC_INITIALIZER_UINT(UINT_CONSTANT); static Atomic_Ulong static_ulong = ATOMIC_INITIALIZER_ULONG(0xdeadbeefUL); - static Atomic_Pointer static_ptr = ATOMIC_INITIALIZER_PTR(&static_ptr); + static Atomic_Uintptr static_uintptr = + ATOMIC_INITIALIZER_UINTPTR((uintptr_t) &static_uintptr); static Atomic_Flag static_flag = ATOMIC_INITIALIZER_FLAG; Atomic_Uint stack_uint; Atomic_Ulong stack_ulong; - Atomic_Pointer stack_ptr; + Atomic_Uintptr stack_uintptr; Atomic_Flag stack_flag; puts("=== static and dynamic initialization test case ==="); _Atomic_Init_uint(&stack_uint, UINT_CONSTANT); _Atomic_Init_ulong(&stack_ulong, 0xdeadbeefUL); - _Atomic_Init_ptr(&stack_ptr, &static_ptr); + _Atomic_Init_uintptr(&stack_uintptr, (uintptr_t) &static_uintptr); _Atomic_Flag_clear(&stack_flag, ATOMIC_ORDER_RELAXED); rtems_test_assert( @@ -65,7 +67,7 @@ static void test_static_and_dynamic_initialization(void) memcmp(&stack_ulong, &static_ulong, sizeof(stack_ulong)) == 0 ); rtems_test_assert( - memcmp(&stack_ptr, &static_ptr, sizeof(stack_ptr)) == 0 + memcmp(&stack_uintptr, &static_uintptr, sizeof(stack_uintptr)) == 0 ); rtems_test_assert( memcmp(&stack_flag, &static_flag, sizeof(stack_flag)) == 0 @@ -78,7 +80,8 @@ static void test_static_and_dynamic_initialization(void) _Atomic_Load_ulong(&stack_ulong, ATOMIC_ORDER_RELAXED) == 0xdeadbeefUL ); rtems_test_assert( - _Atomic_Load_ptr(&stack_ptr, ATOMIC_ORDER_RELAXED) == &static_ptr + _Atomic_Load_uintptr(&stack_uintptr, ATOMIC_ORDER_RELAXED) + == (uintptr_t) &static_uintptr ); rtems_test_assert( !_Atomic_Flag_test_and_set(&stack_flag, ATOMIC_ORDER_RELAXED) @@ -91,19 +94,26 @@ static void test_simple_atomic_add_body(test_context *ctx) { unsigned int ia = 8, ib = 4; unsigned int ic; + uintptr_t pa = 42, pb = 24; + uintptr_t pc; unsigned long a = 2, b = 1; unsigned long c; puts("=== atomic simple add test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_add_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED); - ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_add_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED); + ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(ic == (ia + ib)); - _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_add_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED); - c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_add_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED); + pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == (pa + pb)); + + _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_add_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED); + c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(c == (a + b)); } @@ -111,19 +121,26 @@ static void test_simple_atomic_sub_body(test_context *ctx) { unsigned int ia = 8, ib = 4; unsigned int ic; + uintptr_t pa = 42, pb = 24; + uintptr_t pc; unsigned long a = 2, b = 1; unsigned long c; puts("=== atomic simple sub test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_sub_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED); - ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_sub_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED); + ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(ic == (ia - ib)); - _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_sub_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED); - c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_sub_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED); + pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == (pa - pb)); + + _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_sub_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED); + c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(c == (a - b)); } @@ -131,19 +148,26 @@ static void test_simple_atomic_or_body(test_context *ctx) { unsigned int ia = 8, ib = 4; unsigned int ic; + uintptr_t pa = 42, pb = 24; + uintptr_t pc; unsigned long a = 2, b = 1; unsigned long c; puts("=== atomic simple or test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_or_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED); - ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_or_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED); + ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(ic == (ia | ib)); - _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_or_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED); - c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_or_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED); + pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == (pa | pb)); + + _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_or_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED); + c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(c == (a | b)); } @@ -151,19 +175,26 @@ static void test_simple_atomic_and_body(test_context *ctx) { unsigned int ia = 8, ib = 4; unsigned int ic; + uintptr_t pa = 42, pb = 24; + uintptr_t pc; unsigned long a = 2, b = 1; unsigned long c; puts("=== atomic simple and test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_and_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED); - ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_and_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED); + ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(ic == (ia & ib)); - _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED); - _Atomic_Fetch_and_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED); - c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_and_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED); + pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == (pa & pb)); + + _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED); + _Atomic_Fetch_and_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED); + c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(c == (a & b)); } @@ -171,19 +202,29 @@ static void test_simple_atomic_exchange_body(test_context *ctx) { unsigned int ia = 8, ib = 4; unsigned int ic; + uintptr_t pa = 42, pb = 24; + uintptr_t pc; unsigned long a = 2, b = 1; unsigned long c; puts("=== atomic simple exchange test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED); - _Atomic_Exchange_uint(&ctx->atomic_int_value, ib, ATOMIC_ORDER_RELAXED); - ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, ia, ATOMIC_ORDER_RELAXED); + ic = _Atomic_Exchange_uint(&ctx->uint_atomic, ib, ATOMIC_ORDER_RELAXED); + rtems_test_assert(ic == ia); + ic = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(ic == ib); - _Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED); - _Atomic_Exchange_ulong(&ctx->atomic_value, b, ATOMIC_ORDER_RELAXED); - c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, pa, ATOMIC_ORDER_RELAXED); + pc = _Atomic_Exchange_uintptr(&ctx->uintptr_atomic, pb, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == pa); + pc = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(pc == pb); + + _Atomic_Store_ulong(&ctx->ulong_atomic, a, ATOMIC_ORDER_RELAXED); + c = _Atomic_Exchange_ulong(&ctx->ulong_atomic, b, ATOMIC_ORDER_RELAXED); + rtems_test_assert(c == a); + c = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(c == b); } @@ -191,16 +232,18 @@ static void test_simple_atomic_compare_exchange_body(test_context *ctx) { unsigned int ei; unsigned int vi; + uintptr_t ep; + uintptr_t vp; unsigned long el; unsigned long vl; bool success; puts("=== atomic simple compare exchange test case ==="); - _Atomic_Store_uint(&ctx->atomic_int_value, 1, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uint(&ctx->uint_atomic, 1, ATOMIC_ORDER_RELAXED); ei = 2; success = _Atomic_Compare_exchange_uint( - &ctx->atomic_int_value, + &ctx->uint_atomic, &ei, 3, ATOMIC_ORDER_RELAXED, @@ -209,20 +252,42 @@ static void test_simple_atomic_compare_exchange_body(test_context *ctx) rtems_test_assert(!success); rtems_test_assert(ei == 1); success = _Atomic_Compare_exchange_uint( - &ctx->atomic_int_value, + &ctx->uint_atomic, &ei, 3, ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED ); rtems_test_assert(success); - vi = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED); + vi = _Atomic_Load_uint(&ctx->uint_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(vi == 3); - _Atomic_Store_ulong(&ctx->atomic_value, 10, ATOMIC_ORDER_RELAXED); + _Atomic_Store_uintptr(&ctx->uintptr_atomic, 111, ATOMIC_ORDER_RELAXED); + ep = 211; + success = _Atomic_Compare_exchange_uintptr( + &ctx->uintptr_atomic, + &ep, + 311, + ATOMIC_ORDER_RELAXED, + ATOMIC_ORDER_RELAXED + ); + rtems_test_assert(!success); + rtems_test_assert(ep == 111); + success = _Atomic_Compare_exchange_uintptr( + &ctx->uintptr_atomic, + &ep, + 311, + ATOMIC_ORDER_RELAXED, + ATOMIC_ORDER_RELAXED + ); + rtems_test_assert(success); + vp = _Atomic_Load_uintptr(&ctx->uintptr_atomic, ATOMIC_ORDER_RELAXED); + rtems_test_assert(vp == 311); + + _Atomic_Store_ulong(&ctx->ulong_atomic, 10, ATOMIC_ORDER_RELAXED); el = 11; success = _Atomic_Compare_exchange_ulong( - &ctx->atomic_value, + &ctx->ulong_atomic, &el, 12, ATOMIC_ORDER_RELAXED, @@ -231,14 +296,14 @@ static void test_simple_atomic_compare_exchange_body(test_context *ctx) rtems_test_assert(!success); rtems_test_assert(el == 10); success = _Atomic_Compare_exchange_ulong( - &ctx->atomic_value, + &ctx->ulong_atomic, &el, 12, ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED ); rtems_test_assert(success); - vl = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED); + vl = _Atomic_Load_ulong(&ctx->ulong_atomic, ATOMIC_ORDER_RELAXED); rtems_test_assert(vl == 12); } |