diff options
author | WeiY <wei.a.yang@gmail.com> | 2013-01-26 00:01:17 +0800 |
---|---|---|
committer | Gedare Bloom <gedare@rtems.org> | 2013-02-07 17:02:12 -0500 |
commit | 7e02305018cc7dff2a9039c2bd9b35badd0c79f9 (patch) | |
tree | a2b0673e785967722bf5558f098b56bf56adb332 /testsuites/smptests/smpatomic06/tasks.c | |
parent | tests: atomic support for RTEMS. Uniprocessor tests for atomic ops. (diff) | |
download | rtems-7e02305018cc7dff2a9039c2bd9b35badd0c79f9.tar.bz2 |
tests: atomic support for RTEMS. SMP tests for atomic operations.
Diffstat (limited to 'testsuites/smptests/smpatomic06/tasks.c')
-rw-r--r-- | testsuites/smptests/smpatomic06/tasks.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/testsuites/smptests/smpatomic06/tasks.c b/testsuites/smptests/smpatomic06/tasks.c new file mode 100644 index 0000000000..ec29b28ac2 --- /dev/null +++ b/testsuites/smptests/smpatomic06/tasks.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012 Deng Hengyi. + * + * This test case is to test atomic or operation. + * + * 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. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "system.h" + +#include <stdlib.h> +#include <rtems/rtems/atomic.h> + +#define TEST_REPEAT 200000 + +#define ATOMIC_FETCH_OR_NO_BARRIER(NAME, TYPE, cpuid, mem_bar) \ +{ \ + Atomic_##TYPE t = 0, a = 0, b = 0; \ + 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; \ + _Atomic_Fetch_or_##NAME(&t, b, mem_bar); \ + rtems_test_assert(t == (Atomic_##TYPE)(a | b)); \ + } \ + locked_printf("\nCPU%d _Atomic_Fetch_or_" #NAME ": SUCCESS\n", cpuid); \ +} + +rtems_task Test_task( + rtems_task_argument argument + ) +{ + int cpu_num; + char name[5]; + char *p; + + /* Get the task name */ + p = rtems_object_get_name( RTEMS_SELF, 5, name ); + rtems_test_assert( p != NULL ); + + /* Get the CPU Number */ + cpu_num = bsp_smp_processor_id(); + + /* Print that the task is up and running. */ + /* test relaxed barrier */ + ATOMIC_FETCH_OR_NO_BARRIER(int, Int, cpu_num, ATOMIC_RELAXED_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(long, Long, cpu_num, ATOMIC_RELAXED_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, cpu_num, ATOMIC_RELAXED_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, cpu_num, ATOMIC_RELAXED_BARRIER); + + /* test acquire barrier */ + ATOMIC_FETCH_OR_NO_BARRIER(int, Int, cpu_num, ATOMIC_ACQUIRE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(long, Long, cpu_num, ATOMIC_ACQUIRE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, cpu_num, ATOMIC_ACQUIRE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, cpu_num, ATOMIC_ACQUIRE_BARRIER); + + /* test release barrier */ + ATOMIC_FETCH_OR_NO_BARRIER(int, Int, cpu_num, ATOMIC_RELEASE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(long, Long, cpu_num, ATOMIC_RELEASE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(ptr, Pointer, cpu_num, ATOMIC_RELEASE_BARRIER); + + ATOMIC_FETCH_OR_NO_BARRIER(32, Int32, cpu_num, ATOMIC_RELEASE_BARRIER); + +// ATOMIC_FETCH_OR_NO_BARRIER(64, cpu_num); + + /* Set the flag that the task is up and running */ + TaskRan[cpu_num] = true; + + /* Drop into a loop which will keep this task on + * running on the cpu. + */ + while(1); +} |