[PATCH 4/7] spatomic test case update
WeiY
wei.a.yang at gmail.com
Mon Jul 15 15:31:11 UTC 2013
---
testsuites/sptests/spatomic01/tasks.c | 33 ++++++--------
testsuites/sptests/spatomic02/tasks.c | 35 ++++++---------
testsuites/sptests/spatomic03/tasks.c | 44 ++++++++-----------
testsuites/sptests/spatomic04/tasks.c | 46 ++++++++------------
testsuites/sptests/spatomic05/tasks.c | 44 ++++++++-----------
testsuites/sptests/spatomic06/tasks.c | 44 ++++++++-----------
testsuites/sptests/spatomic07/tasks.c | 77 +++++++++++++++------------------
7 files changed, 135 insertions(+), 188 deletions(-)
diff --git a/testsuites/sptests/spatomic01/tasks.c b/testsuites/sptests/spatomic01/tasks.c
index c75a94d..9392a5b 100644
--- a/testsuites/sptests/spatomic01/tasks.c
+++ b/testsuites/sptests/spatomic01/tasks.c
@@ -18,20 +18,21 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_LOAD_NO_BARRIER(NAME, TYPE, task_id, mem_bar) \
+#define ATOMIC_LOAD_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar) \
{ \
- Atomic_##TYPE t = (Atomic_##TYPE)-1, a = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
unsigned int i; \
- a = _Atomic_Load_##NAME(&t, mem_bar); \
- rtems_test_assert(a == t); \
for (i = 0; i < TEST_REPEAT; i++){ \
- t = (Atomic_##TYPE)rand(); \
+ b = (R_TYPE)rand(); \
+ atomic_init(&t, b); \
a = _Atomic_Load_##NAME(&t, mem_bar); \
- rtems_test_assert(a == t); \
+ rtems_test_assert(a == b); \
} \
- printf("\ntask%d: _Atomic_Load_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ printf("\ntask%d: Atomic_Load_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,22 +49,14 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_LOAD_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_LOAD_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_LOAD_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_LOAD_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_LOAD_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_LOAD_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_LOAD_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_LOAD_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic02/tasks.c b/testsuites/sptests/spatomic02/tasks.c
index 67c2460..558b718 100644
--- a/testsuites/sptests/spatomic02/tasks.c
+++ b/testsuites/sptests/spatomic02/tasks.c
@@ -18,20 +18,21 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_STORE_NO_BARRIER(NAME, TYPE, task_id, mem_bar) \
+#define ATOMIC_STORE_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar) \
{ \
- Atomic_##TYPE t = (Atomic_##TYPE)-1, a = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
unsigned int i; \
- _Atomic_Store_##NAME(&a, t, mem_bar); \
- rtems_test_assert(a == t); \
for (i = 0; i < TEST_REPEAT; i++){ \
- t = (Atomic_##TYPE)rand(); \
- _Atomic_Store_##NAME(&a, t, mem_bar); \
- rtems_test_assert(a == t); \
+ b = (R_TYPE)rand(); \
+ _Atomic_Store_##NAME(&t, b, mem_bar); \
+ a = _Atomic_Load_##NAME(&t, memory_order_relaxed); \
+ rtems_test_assert(a == b); \
} \
- printf("\ntask%d: _Atomic_Store_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ printf("\ntask%d: Atomic_Store_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,22 +49,14 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_STORE_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_STORE_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_STORE_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_STORE_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_STORE_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_STORE_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test release barrier */
- ATOMIC_STORE_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_STORE_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_STORE_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_STORE_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_STORE_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_STORE_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic03/tasks.c b/testsuites/sptests/spatomic03/tasks.c
index 2218b1b..d03cf54 100644
--- a/testsuites/sptests/spatomic03/tasks.c
+++ b/testsuites/sptests/spatomic03/tasks.c
@@ -18,20 +18,24 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_FETCH_ADD_NO_BARRIER(NAME, TYPE, task_id, mem_bar)\
+#define ATOMIC_FETCH_ADD_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar)\
{ \
- Atomic_##TYPE t = 0, a = 0, b = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
+ R_TYPE c; \
unsigned int i; \
for (i = 0; i < TEST_REPEAT; i++){ \
- a = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- b = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- t = a; \
+ a = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ b = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
_Atomic_Fetch_add_##NAME(&t, b, mem_bar); \
- rtems_test_assert(t == (Atomic_##TYPE)(a + b)); \
+ c = _Atomic_Load_##NAME(&t, ATOMIC_ORDER_RELAXED); \
+ rtems_test_assert(c == (R_TYPE)(a + b)); \
} \
- printf("\ntask%d: _Atomic_Fetch_add_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ printf("\ntask%d: Atomic_Fetch_add_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,31 +52,19 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_FETCH_ADD_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_FETCH_ADD_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_FETCH_ADD_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* test release barrier */
- ATOMIC_FETCH_ADD_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_FETCH_ADD_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_ADD_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic04/tasks.c b/testsuites/sptests/spatomic04/tasks.c
index 4600f39..9f587be 100644
--- a/testsuites/sptests/spatomic04/tasks.c
+++ b/testsuites/sptests/spatomic04/tasks.c
@@ -18,20 +18,24 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_FETCH_SUB_NO_BARRIER(NAME, TYPE, task_id, mem_bar)\
+#define ATOMIC_FETCH_SUB_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar)\
{ \
- Atomic_##TYPE t = 0, a = 0, b = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
+ R_TYPE c; \
unsigned int i; \
for (i = 0; i < TEST_REPEAT; i++){ \
- a = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- b = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- t = a; \
+ a = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ b = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
_Atomic_Fetch_sub_##NAME(&t, b, mem_bar); \
- rtems_test_assert(t == (Atomic_##TYPE)(a - b)); \
- } \
- printf("\ntask%d: _Atomic_Fetch_sub_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ c = _Atomic_Load_##NAME(&t, ATOMIC_ORDER_RELAXED); \
+ rtems_test_assert(c == (R_TYPE)(a - b)); \
+ } \
+ printf("\ntask%d: Atomic_Fetch_sub_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,31 +52,19 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_FETCH_SUB_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_FETCH_SUB_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_FETCH_SUB_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* test release barrier */
- ATOMIC_FETCH_SUB_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_FETCH_SUB_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_SUB_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic05/tasks.c b/testsuites/sptests/spatomic05/tasks.c
index d0df98a..5f93dae 100644
--- a/testsuites/sptests/spatomic05/tasks.c
+++ b/testsuites/sptests/spatomic05/tasks.c
@@ -18,20 +18,24 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_FETCH_AND_NO_BARRIER(NAME, TYPE, task_id, mem_bar)\
+#define ATOMIC_FETCH_AND_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar)\
{ \
- Atomic_##TYPE t = 0, a = 0, b = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
+ R_TYPE c; \
unsigned int i; \
for (i = 0; i < TEST_REPEAT; i++){ \
- a = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- b = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- t = a; \
+ a = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ b = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
_Atomic_Fetch_and_##NAME(&t, b, mem_bar); \
- rtems_test_assert(t == (Atomic_##TYPE)(a & b)); \
+ c = _Atomic_Load_##NAME(&t, ATOMIC_ORDER_RELAXED); \
+ rtems_test_assert(c == (R_TYPE)(a & b)); \
} \
- printf("\ntask%d: _Atomic_Fetch_and_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ printf("\ntask%d: Atomic_Fetch_and_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,31 +52,19 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_FETCH_AND_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_FETCH_AND_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_FETCH_AND_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* test release barrier */
- ATOMIC_FETCH_AND_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_FETCH_AND_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_AND_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic06/tasks.c b/testsuites/sptests/spatomic06/tasks.c
index 753b91a..b03d3f0 100644
--- a/testsuites/sptests/spatomic06/tasks.c
+++ b/testsuites/sptests/spatomic06/tasks.c
@@ -18,20 +18,24 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_FETCH_OR_NO_BARRIER(NAME, TYPE, task_id, mem_bar) \
+#define ATOMIC_FETCH_OR_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar) \
{ \
- Atomic_##TYPE t = 0, a = 0, b = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
+ R_TYPE c; \
unsigned int i; \
for (i = 0; i < TEST_REPEAT; i++){ \
- a = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- b = (Atomic_##TYPE)(rand() % ((Atomic_##TYPE)-1 / 2)); \
- t = a; \
+ a = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ b = (R_TYPE)(rand() % ((R_TYPE)-1 / 2)); \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
_Atomic_Fetch_or_##NAME(&t, b, mem_bar); \
- rtems_test_assert(t == (Atomic_##TYPE)(a | b)); \
+ c = _Atomic_Load_##NAME(&t, ATOMIC_ORDER_RELAXED); \
+ rtems_test_assert(c == (R_TYPE)(a | b)); \
} \
- printf("\ntask%d: _Atomic_Fetch_or_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ printf("\ntask%d: Atomic_Fetch_or_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -48,31 +52,19 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_FETCH_OR_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_FETCH_OR_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_FETCH_OR_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* test release barrier */
- ATOMIC_FETCH_OR_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
diff --git a/testsuites/sptests/spatomic07/tasks.c b/testsuites/sptests/spatomic07/tasks.c
index ff925d0..286a994 100644
--- a/testsuites/sptests/spatomic07/tasks.c
+++ b/testsuites/sptests/spatomic07/tasks.c
@@ -18,35 +18,40 @@
#include <stdlib.h>
#include <rtems/rtems/atomic.h>
-#define TEST_REPEAT 200000
+#define TEST_REPEAT 1000
-#define ATOMIC_CAS_NO_BARRIER(NAME, TYPE, task_id, mem_bar) \
+#define ATOMIC_CAS_NO_BARRIER(NAME, TYPE, R_TYPE, task_id, mem_bar) \
{ \
- Atomic_##TYPE a = 0, b = 0; \
+ Atomic_##TYPE t; \
+ R_TYPE a; \
+ R_TYPE b; \
unsigned int i; \
int r; \
for (i = 0; i < TEST_REPEAT; i++){ \
- a = rand() % (Atomic_##TYPE)-1; \
- b = a; \
- r = _Atomic_Compare_exchange_##NAME(&b, a + 1, a - 1, mem_bar); \
- if(r != 0){ \
- printf("\ntask%d: _Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
- rtems_test_exit( 0 ); \
- } \
- b = a; \
- r = _Atomic_Compare_exchange_##NAME(&b, a, a - 1, mem_bar); \
- if((r == 0) ||((r != 0) && ((a - 1) != b))){ \
- printf("\ntask%d: _Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
- rtems_test_exit( 0 ); \
- } \
- b = a; \
- r = _Atomic_Compare_exchange_##NAME(&b, a + 1, a, mem_bar); \
- if(r != 0){ \
- printf("\ntask%d: _Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
- rtems_test_exit( 0 ); \
- } \
- } \
- printf("\ntask%d: _Atomic_Compare_exchange_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
+ a = rand() % (R_TYPE)-1; \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
+ b = a + 1; \
+ r = _Atomic_Compare_exchange_##NAME(&t, &b, a - 1, mem_bar, memory_order_relaxed); \
+ if(r != 0){ \
+ printf("\ntask%d: Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
+ rtems_test_exit( 0 ); \
+ } \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
+ r = _Atomic_Compare_exchange_##NAME(&t, &a, a - 1, mem_bar, memory_order_relaxed); \
+ b = _Atomic_Load_##NAME(&t, ATOMIC_ORDER_RELAXED); \
+ if((r == 0) ||((r != 0) && ((a - 1) != b))){ \
+ printf("\ntask%d: Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
+ rtems_test_exit( 0 ); \
+ } \
+ _Atomic_Store_##NAME(&t, a, ATOMIC_ORDER_RELAXED); \
+ b = a + 1; \
+ r = _Atomic_Compare_exchange_##NAME(&t, &b, a, mem_bar, memory_order_relaxed); \
+ if(r != 0){ \
+ printf("\ntask%d: Atomic_Compare_exchange_" #NAME ": FAILED\n", (unsigned int)task_id); \
+ rtems_test_exit( 0 ); \
+ } \
+ } \
+ printf("\ntask%d: Atomic_Compare_exchange_" #NAME ": SUCCESS\n", (unsigned int)task_id); \
}
rtems_task Test_task(
@@ -63,31 +68,19 @@ rtems_task Test_task(
/* Print that the task is up and running. */
/* test relaxed barrier */
- ATOMIC_CAS_NO_BARRIER(int, Int, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELAXED);
- ATOMIC_CAS_NO_BARRIER(long, Long, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELAXED_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(32, Int32, argument, ATOMIC_RELAXED_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELAXED);
/* test acquire barrier */
- ATOMIC_CAS_NO_BARRIER(int, Int, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(long, Long, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_ACQUIRE);
- ATOMIC_CAS_NO_BARRIER(ptr, Pointer, argument, ATOMIC_ACQUIRE_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(32, Int32, argument, ATOMIC_ACQUIRE_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_ACQUIRE);
/* test release barrier */
- ATOMIC_CAS_NO_BARRIER(int, Int, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(long, Long, argument, ATOMIC_RELEASE_BARRIER);
-
- ATOMIC_CAS_NO_BARRIER(ptr, Pointer, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(uint, Uint, uint_fast32_t, argument, ATOMIC_ORDER_RELEASE);
- ATOMIC_CAS_NO_BARRIER(32, Int32, argument, ATOMIC_RELEASE_BARRIER);
+ ATOMIC_CAS_NO_BARRIER(ptr, Pointer, uintptr_t, argument, ATOMIC_ORDER_RELEASE);
/* Set the flag that the task is up and running */
TaskRan[argument] = true;
--
1.7.9.5
More information about the devel
mailing list