forked from Imagelibrary/rtems
score: Add Atomic_Uint
This commit is contained in:
@@ -80,6 +80,7 @@ typedef struct {
|
||||
SMP_barrier_Control barrier;
|
||||
size_t worker_count;
|
||||
rtems_id stop_worker_timer_id;
|
||||
Atomic_Uint atomic_int_value;
|
||||
Atomic_Ulong atomic_value;
|
||||
unsigned long per_worker_value[CPU_COUNT];
|
||||
unsigned long normal_value;
|
||||
@@ -383,22 +384,29 @@ static void worker_task(size_t worker_index)
|
||||
|
||||
static void test_static_and_dynamic_initialization(void)
|
||||
{
|
||||
static Atomic_Uint static_uint =
|
||||
ATOMIC_INITIALIZER_UINT(0xc01dc0feU);
|
||||
static Atomic_Ulong static_ulong =
|
||||
ATOMIC_INITIALIZER_ULONG(0xdeadbeefUL);
|
||||
static Atomic_Pointer static_ptr =
|
||||
ATOMIC_INITIALIZER_PTR(&static_ptr);
|
||||
static Atomic_Flag static_flag = ATOMIC_INITIALIZER_FLAG;
|
||||
|
||||
Atomic_Uint stack_uint;
|
||||
Atomic_Ulong stack_ulong;
|
||||
Atomic_Pointer stack_ptr;
|
||||
Atomic_Flag stack_flag;
|
||||
|
||||
puts("=== static and dynamic initialization test case ===");
|
||||
|
||||
_Atomic_Init_uint(&stack_uint, 0xc01dc0feU);
|
||||
_Atomic_Init_ulong(&stack_ulong, 0xdeadbeefUL);
|
||||
_Atomic_Init_ptr(&stack_ptr, &static_ptr);
|
||||
_Atomic_Flag_clear(&stack_flag, ATOMIC_ORDER_RELAXED);
|
||||
|
||||
rtems_test_assert(
|
||||
memcmp(&stack_uint, &static_uint, sizeof(stack_uint)) == 0
|
||||
);
|
||||
rtems_test_assert(
|
||||
memcmp(&stack_ulong, &static_ulong, sizeof(stack_ulong)) == 0
|
||||
);
|
||||
@@ -409,6 +417,9 @@ static void test_static_and_dynamic_initialization(void)
|
||||
memcmp(&stack_flag, &static_flag, sizeof(stack_flag)) == 0
|
||||
);
|
||||
|
||||
rtems_test_assert(
|
||||
_Atomic_Load_uint(&stack_uint, ATOMIC_ORDER_RELAXED) == 0xc01dc0feU
|
||||
);
|
||||
rtems_test_assert(
|
||||
_Atomic_Load_ulong(&stack_ulong, ATOMIC_ORDER_RELAXED) == 0xdeadbeefUL
|
||||
);
|
||||
@@ -460,11 +471,18 @@ typedef void (*simple_test_body)(test_context *ctx);
|
||||
|
||||
static void test_simple_atomic_add_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple add test case ==\n");
|
||||
|
||||
_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);
|
||||
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);
|
||||
@@ -473,11 +491,18 @@ static void test_simple_atomic_add_body(test_context *ctx)
|
||||
|
||||
static void test_simple_atomic_sub_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple sub test case ==\n");
|
||||
|
||||
_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);
|
||||
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);
|
||||
@@ -486,11 +511,18 @@ static void test_simple_atomic_sub_body(test_context *ctx)
|
||||
|
||||
static void test_simple_atomic_or_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple or test case ==\n");
|
||||
|
||||
_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);
|
||||
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);
|
||||
@@ -499,11 +531,18 @@ static void test_simple_atomic_or_body(test_context *ctx)
|
||||
|
||||
static void test_simple_atomic_and_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple and test case ==\n");
|
||||
|
||||
_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);
|
||||
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);
|
||||
@@ -512,11 +551,18 @@ static void test_simple_atomic_and_body(test_context *ctx)
|
||||
|
||||
static void test_simple_atomic_exchange_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple exchange test case ==\n");
|
||||
|
||||
_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);
|
||||
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);
|
||||
@@ -525,11 +571,19 @@ static void test_simple_atomic_exchange_body(test_context *ctx)
|
||||
|
||||
static void test_simple_atomic_compare_exchange_body(test_context *ctx)
|
||||
{
|
||||
unsigned int ia = 8, ib = 4;
|
||||
unsigned int ic;
|
||||
unsigned long a = 2, b = 1;
|
||||
unsigned long c;
|
||||
|
||||
puts("=== atomic simple compare exchange test case ==\n");
|
||||
|
||||
_Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
|
||||
_Atomic_Compare_exchange_uint(&ctx->atomic_int_value, &ia, ib,
|
||||
ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
|
||||
ic = _Atomic_Load_uint(&ctx->atomic_int_value, ATOMIC_ORDER_RELAXED);
|
||||
rtems_test_assert(ic == ib);
|
||||
|
||||
_Atomic_Store_ulong(&ctx->atomic_value, a, ATOMIC_ORDER_RELAXED);
|
||||
_Atomic_Compare_exchange_ulong(&ctx->atomic_value, &a, b,
|
||||
ATOMIC_ORDER_RELAXED, ATOMIC_ORDER_RELAXED);
|
||||
|
||||
Reference in New Issue
Block a user