Index: testsuites/smptests/smpatomic01/init.c
===================================================================
--- testsuites/smptests/smpatomic01/init.c	(revision 4e3d9a4d6c76fba8e31138d503f736405dafc213)
+++ testsuites/smptests/smpatomic01/init.c	(revision 7f577d3a56a63a76fe79bcb54c130c35159faf66)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2013-2015 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
@@ -20,6 +20,6 @@
 
 #include <rtems/score/atomic.h>
-#include <rtems/score/smpbarrier.h>
 #include <rtems.h>
+#include <rtems/test.h>
 #include <limits.h>
 #include <string.h>
@@ -36,8 +36,5 @@
 
 typedef struct {
-  Atomic_Ulong stop;
-  SMP_barrier_Control barrier;
-  size_t worker_count;
-  rtems_id stop_worker_timer_id;
+  rtems_test_parallel_context base;
   Atomic_Uint atomic_int_value;
   Atomic_Ulong atomic_value;
@@ -47,29 +44,15 @@
   unsigned long second_value;
   Atomic_Flag global_flag;
-} test_context;
-
-typedef struct {
-  void (*init)(test_context *ctx);
-  void (*body)(test_context *ctx, size_t worker_index);
-  void (*fini)(test_context *ctx);
-} test_case;
-
-static test_context test_instance = {
-  .stop = ATOMIC_INITIALIZER_ULONG(0),
-  .barrier = SMP_BARRIER_CONTROL_INITIALIZER
-};
-
-static bool stop(test_context *ctx)
-{
-  return _Atomic_Load_ulong(&ctx->stop, ATOMIC_ORDER_RELAXED) != 0;
-}
-
-static bool is_master_worker(size_t worker_index)
-{
-  return worker_index == 0;
+} smpatomic01_context;
+
+static smpatomic01_context test_instance;
+
+static rtems_interval test_duration(void)
+{
+  return rtems_clock_get_ticks_per_second();
 }
 
 static void test_fini(
-  test_context *ctx,
+  smpatomic01_context *ctx,
   const char *test,
   bool atomic
@@ -82,5 +65,9 @@
   printf("=== atomic %s test case ===\n", test);
 
-  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
+  for (
+    worker_index = 0;
+    worker_index < ctx->base.worker_count;
+    ++worker_index
+  ) {
     unsigned long worker_value = ctx->per_worker_value[worker_index];
 
@@ -109,14 +96,27 @@
 }
 
-static void test_atomic_add_init(test_context *ctx)
-{
+
+static rtems_interval test_atomic_add_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   _Atomic_Init_ulong(&ctx->atomic_value, 0);
-}
-
-static void test_atomic_add_body(test_context *ctx, size_t worker_index)
-{
+
+  return test_duration();
+}
+
+static void test_atomic_add_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
   unsigned long counter = 0;
 
-  while (!stop(ctx)) {
+  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     ++counter;
     _Atomic_Fetch_add_ulong(&ctx->atomic_value, 1, ATOMIC_ORDER_RELAXED);
@@ -126,20 +126,34 @@
 }
 
-static void test_atomic_add_fini(test_context *ctx)
-{
+static void test_atomic_add_fini(rtems_test_parallel_context *base, void *arg)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   test_fini(ctx, "add", true);
 }
 
-static void test_atomic_flag_init(test_context *ctx)
-{
+static rtems_interval test_atomic_flag_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   _Atomic_Flag_clear(&ctx->global_flag, ATOMIC_ORDER_RELEASE);
   ctx->normal_value = 0;
-}
-
-static void test_atomic_flag_body(test_context *ctx, size_t worker_index)
-{
+
+  return test_duration();
+}
+
+static void test_atomic_flag_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
   unsigned long counter = 0;
 
-  while (!stop(ctx)) {
+  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     while (_Atomic_Flag_test_and_set(&ctx->global_flag, ATOMIC_ORDER_ACQUIRE)) {
       /* Wait */
@@ -155,19 +169,33 @@
 }
 
-static void test_atomic_flag_fini(test_context *ctx)
-{
+static void test_atomic_flag_fini(rtems_test_parallel_context *base, void *arg)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   test_fini(ctx, "flag", false);
 }
 
-static void test_atomic_sub_init(test_context *ctx)
-{
+static rtems_interval test_atomic_sub_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   _Atomic_Init_ulong(&ctx->atomic_value, 0);
-}
-
-static void test_atomic_sub_body(test_context *ctx, size_t worker_index)
-{
+
+  return test_duration();
+}
+
+static void test_atomic_sub_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
   unsigned long counter = 0;
 
-  while (!stop(ctx)) {
+  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     --counter;
     _Atomic_Fetch_sub_ulong(&ctx->atomic_value, 1, ATOMIC_ORDER_RELAXED);
@@ -177,20 +205,34 @@
 }
 
-static void test_atomic_sub_fini(test_context *ctx)
-{
+static void test_atomic_sub_fini(rtems_test_parallel_context *base, void *arg)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   test_fini(ctx, "sub", true);
 }
 
-static void test_atomic_compare_exchange_init(test_context *ctx)
-{
+static rtems_interval test_atomic_compare_exchange_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   _Atomic_Init_ulong(&ctx->atomic_value, 0);
   ctx->normal_value = 0;
-}
-
-static void test_atomic_compare_exchange_body(test_context *ctx, size_t worker_index)
-{
+
+  return test_duration();
+}
+
+static void test_atomic_compare_exchange_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
   unsigned long counter = 0;
 
-  while (!stop(ctx)) {
+  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     bool success;
 
@@ -216,20 +258,37 @@
 }
 
-static void test_atomic_compare_exchange_fini(test_context *ctx)
-{
+static void test_atomic_compare_exchange_fini(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   test_fini(ctx, "compare exchange", false);
 }
 
-static void test_atomic_or_and_init(test_context *ctx)
-{
+static rtems_interval test_atomic_or_and_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   _Atomic_Init_ulong(&ctx->atomic_value, 0);
-}
-
-static void test_atomic_or_and_body(test_context *ctx, size_t worker_index)
-{
+
+  return test_duration();
+}
+
+static void test_atomic_or_and_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
   unsigned long the_bit = 1UL << worker_index;
   unsigned long current_bit = 0;
 
-  while (!stop(ctx)) {
+  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     unsigned long previous;
 
@@ -256,22 +315,40 @@
 }
 
-static void test_atomic_or_and_fini(test_context *ctx)
-{
+static void test_atomic_or_and_fini(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   test_fini(ctx, "or/and", true);
 }
 
-static void test_atomic_fence_init(test_context *ctx)
-{
+static rtems_interval test_atomic_fence_init(
+  rtems_test_parallel_context *base,
+  void *arg
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   ctx->normal_value = 0;
   ctx->second_value = 0;
   _Atomic_Fence(ATOMIC_ORDER_RELEASE);
-}
-
-static void test_atomic_fence_body(test_context *ctx, size_t worker_index)
-{
-  if (is_master_worker(worker_index)) {
+
+  return test_duration();
+}
+
+static void test_atomic_fence_body(
+  rtems_test_parallel_context *base,
+  void *arg,
+  size_t worker_index
+)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
+  if (rtems_test_parallel_is_master_worker(worker_index)) {
     unsigned long counter = 0;
 
-    while (!stop(ctx)) {
+    while (!rtems_test_parallel_stop_job(&ctx->base)) {
       ++counter;
       ctx->normal_value = counter;
@@ -280,5 +357,5 @@
     }
   } else {
-    while (!stop(ctx)) {
+    while (!rtems_test_parallel_stop_job(&ctx->base)) {
       unsigned long n;
       unsigned long s;
@@ -293,6 +370,8 @@
 }
 
-static void test_atomic_fence_fini(test_context *ctx)
-{
+static void test_atomic_fence_fini(rtems_test_parallel_context *base, void *arg)
+{
+  smpatomic01_context *ctx = (smpatomic01_context *) base;
+
   printf(
     "=== atomic fence test case ===\n"
@@ -303,5 +382,5 @@
 }
 
-static const test_case test_cases[] = {
+static const rtems_test_parallel_job test_jobs[] = {
   {
     test_atomic_add_init,
@@ -331,102 +410,16 @@
 };
 
-#define TEST_COUNT RTEMS_ARRAY_SIZE(test_cases)
-
-static void stop_worker_timer(rtems_id timer_id, void *arg)
-{
-  test_context *ctx = arg;
-
-  _Atomic_Store_ulong(&ctx->stop, 1, ATOMIC_ORDER_RELAXED);
-}
-
-static void start_worker_stop_timer(test_context *ctx)
-{
-  rtems_status_code sc;
-
-  _Atomic_Store_ulong(&ctx->stop, 0, ATOMIC_ORDER_RELEASE);
-
-  sc = rtems_timer_fire_after(
-    ctx->stop_worker_timer_id,
-    rtems_clock_get_ticks_per_second(),
-    stop_worker_timer,
-    ctx
+static void Init(rtems_task_argument arg)
+{
+  smpatomic01_context *ctx = &test_instance;
+
+  TEST_BEGIN();
+
+  rtems_test_parallel(
+    &ctx->base,
+    WORKER_PRIORITY,
+    &test_jobs[0],
+    RTEMS_ARRAY_SIZE(test_jobs)
   );
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-}
-
-static void run_tests(test_context *ctx, size_t worker_index)
-{
-  SMP_barrier_State bs = SMP_BARRIER_STATE_INITIALIZER;
-  size_t test;
-
-  for (test = 0; test < TEST_COUNT; ++test) {
-    const test_case *tc = &test_cases[test];
-
-    if (is_master_worker(worker_index)) {
-      start_worker_stop_timer(ctx);
-      (*tc->init)(ctx);
-    }
-
-    _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count);
-
-    (*tc->body)(ctx, worker_index);
-
-    _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count);
-
-    if (is_master_worker(worker_index)) {
-      (*tc->fini)(ctx);
-    }
-  }
-}
-
-static void worker_task(size_t worker_index)
-{
-  test_context *ctx = &test_instance;
-
-  run_tests(ctx, worker_index);
-
-  (void) rtems_task_suspend(RTEMS_SELF);
-  rtems_test_assert(0);
-}
-
-static void test(void)
-{
-  test_context *ctx = &test_instance;
-  rtems_status_code sc;
-  size_t worker_index;
-
-  ctx->worker_count = rtems_get_processor_count();
-
-  sc = rtems_timer_create(
-    rtems_build_name('S', 'T', 'O', 'P'),
-    &ctx->stop_worker_timer_id
-  );
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
-  for (worker_index = 1; worker_index < ctx->worker_count; ++worker_index) {
-    rtems_id worker_id;
-
-    sc = rtems_task_create(
-      rtems_build_name('W', 'O', 'R', 'K'),
-      WORKER_PRIORITY,
-      RTEMS_MINIMUM_STACK_SIZE,
-      RTEMS_DEFAULT_MODES,
-      RTEMS_DEFAULT_ATTRIBUTES,
-      &worker_id
-    );
-    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
-    sc = rtems_task_start(worker_id, worker_task, worker_index);
-    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-  }
-
-  run_tests(ctx, 0);
-}
-
-static void Init(rtems_task_argument arg)
-{
-  TEST_BEGIN();
-
-  test();
 
   TEST_END();
