1 | /* |
---|
2 | * Copyright (c) 2012 Deng Hengyi. |
---|
3 | * |
---|
4 | * This test case is to test atomic load operation. |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | * |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include "system.h" |
---|
17 | |
---|
18 | #include <stdlib.h> |
---|
19 | #include <rtems/rtems/atomic.h> |
---|
20 | |
---|
21 | #define TEST_REPEAT 1000 |
---|
22 | |
---|
23 | #define ATOMIC_LOAD_NO_BARRIER(NAME, TYPE, R_TYPE, cpuid, mem_bar) \ |
---|
24 | { \ |
---|
25 | Atomic_##TYPE t; \ |
---|
26 | R_TYPE a; \ |
---|
27 | R_TYPE b; \ |
---|
28 | unsigned int i; \ |
---|
29 | for (i = 0; i < TEST_REPEAT; i++){ \ |
---|
30 | b = (R_TYPE)rand(); \ |
---|
31 | atomic_init(&t, b); \ |
---|
32 | a = _Atomic_Load_##NAME(&t, mem_bar); \ |
---|
33 | rtems_test_assert(a == b); \ |
---|
34 | } \ |
---|
35 | locked_printf("\nCPU%d Atomic_Load_" #NAME ": SUCCESS\n", cpuid); \ |
---|
36 | } |
---|
37 | |
---|
38 | rtems_task Test_task( |
---|
39 | rtems_task_argument argument |
---|
40 | ) |
---|
41 | { |
---|
42 | uint32_t cpu_num; |
---|
43 | char name[5]; |
---|
44 | char *p; |
---|
45 | |
---|
46 | /* Get the task name */ |
---|
47 | p = rtems_object_get_name( RTEMS_SELF, 5, name ); |
---|
48 | rtems_test_assert( p != NULL ); |
---|
49 | |
---|
50 | /* Get the CPU Number */ |
---|
51 | cpu_num = rtems_smp_get_current_processor(); |
---|
52 | |
---|
53 | /* Print that the task is up and running. */ |
---|
54 | /* test relaxed barrier */ |
---|
55 | ATOMIC_LOAD_NO_BARRIER(ulong, Ulong, unsigned long, cpu_num, ATOMIC_ORDER_RELAXED); |
---|
56 | |
---|
57 | ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, uintptr_t, cpu_num, ATOMIC_ORDER_RELAXED); |
---|
58 | |
---|
59 | /* test acquire barrier */ |
---|
60 | ATOMIC_LOAD_NO_BARRIER(ulong, Ulong, unsigned long, cpu_num, ATOMIC_ORDER_ACQUIRE); |
---|
61 | |
---|
62 | ATOMIC_LOAD_NO_BARRIER(ptr, Pointer, unsigned long, cpu_num, ATOMIC_ORDER_ACQUIRE); |
---|
63 | |
---|
64 | // ATOMIC_LOAD_NO_BARRIER(64, cpu_num); |
---|
65 | |
---|
66 | /* Set the flag that the task is up and running */ |
---|
67 | TaskRan[cpu_num] = true; |
---|
68 | |
---|
69 | /* Drop into a loop which will keep this task on |
---|
70 | * running on the cpu. |
---|
71 | */ |
---|
72 | while(1); |
---|
73 | } |
---|