[rtems commit] add simple atomic test cases into smpatomic08

Sebastian Huber sebh at rtems.org
Tue Oct 8 14:01:27 UTC 2013


Module:    rtems
Branch:    master
Commit:    fee154be37c3b1ccaeb57d05929290542366db6f
Changeset: http://git.rtems.org/rtems/commit/?id=fee154be37c3b1ccaeb57d05929290542366db6f

Author:    WeiY <wei.a.yang at gmail.com>
Date:      Sat Sep 28 14:54:36 2013 +0800

add simple atomic test cases into smpatomic08

---

 testsuites/smptests/smpatomic08/init.c |  108 ++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/testsuites/smptests/smpatomic08/init.c b/testsuites/smptests/smpatomic08/init.c
index c047ff0..1120b2b 100644
--- a/testsuites/smptests/smpatomic08/init.c
+++ b/testsuites/smptests/smpatomic08/init.c
@@ -7,6 +7,8 @@
  *  Germany
  *  <rtems at embedded-brains.de>
  *
+ * Copyright (c) 2013 Deng Hengyi.
+ *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
  * http://www.rtems.com/license/LICENSE.
@@ -454,10 +456,116 @@ static void test(void)
   run_tests(ctx, 0);
 }
 
+typedef void (*simple_test_body)(test_context *ctx);
+
+static void test_simple_atomic_add_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple add test case ==\n");
+
+  _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);
+  rtems_test_assert(c == (a + b));
+}
+
+static void test_simple_atomic_sub_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple sub test case ==\n");
+
+  _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);
+  rtems_test_assert(c == (a - b));
+}
+
+static void test_simple_atomic_or_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple or test case ==\n");
+
+  _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);
+  rtems_test_assert(c == (a | b));
+}
+
+static void test_simple_atomic_and_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple and test case ==\n");
+
+  _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);
+  rtems_test_assert(c == (a & b));
+}
+
+static void test_simple_atomic_exchange_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple exchange test case ==\n");
+
+  _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);
+  rtems_test_assert(c == b);
+}
+
+static void test_simple_atomic_compare_exchange_body(test_context *ctx)
+{
+  unsigned long a = 2, b = 1;
+  unsigned long c;
+
+  puts("=== atomic simple compare exchange test case ==\n");
+
+  _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);
+  c = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
+  rtems_test_assert(c == b);
+}
+
+static const simple_test_body simple_test_bodies[] = {
+  test_simple_atomic_add_body,
+  test_simple_atomic_sub_body,
+  test_simple_atomic_or_body,
+  test_simple_atomic_and_body,
+  test_simple_atomic_exchange_body,
+  test_simple_atomic_compare_exchange_body,
+};
+
+#define SIMPLE_TEST_COUNT RTEMS_ARRAY_SIZE(simple_test_bodies)
+
+static void simple_tests(void)
+{
+  test_context *ctx = &test_instance;
+  size_t test;
+
+  for (test = 0; test < SIMPLE_TEST_COUNT; ++test) {
+    const simple_test_body *test_body = &simple_test_bodies[test];
+
+    (*test_body)(ctx);
+  }
+}
+
 static void Init(rtems_task_argument arg)
 {
   puts("\n\n*** TEST SMPATOMIC 8 ***");
 
+  simple_tests();
+
   test();
 
   puts("*** END OF TEST SMPATOMIC 8 ***");




More information about the vc mailing list