1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include "test_support.h" |
---|
16 | #include <rtems/gxx_wrappers.h> |
---|
17 | |
---|
18 | /* forward declarations to avoid warnings */ |
---|
19 | rtems_task Init(rtems_task_argument argument); |
---|
20 | void test_recursive_mutex(void); |
---|
21 | void test_mutex(void); |
---|
22 | void once_function(void); |
---|
23 | void test_once(void); |
---|
24 | void key_dtor(void *ptr); |
---|
25 | void test_key(void); |
---|
26 | |
---|
27 | void test_recursive_mutex(void) |
---|
28 | { |
---|
29 | int sc; |
---|
30 | __gthread_mutex_t mutex; |
---|
31 | |
---|
32 | mutex = 0; |
---|
33 | puts( "rtems_gxx_recursive_mutex_init() - OK" ); |
---|
34 | rtems_gxx_recursive_mutex_init(&mutex); |
---|
35 | rtems_test_assert( mutex != 0 ); |
---|
36 | |
---|
37 | puts( "rtems_gxx_recursive_mutex_trylock() - OK" ); |
---|
38 | sc = rtems_gxx_recursive_mutex_trylock(&mutex); |
---|
39 | rtems_test_assert( sc == 0 ); |
---|
40 | |
---|
41 | puts( "rtems_gxx_recursive_mutex_trylock() - Nest" ); |
---|
42 | sc = rtems_gxx_recursive_mutex_trylock(&mutex); |
---|
43 | rtems_test_assert( sc == 0 ); |
---|
44 | |
---|
45 | puts( "rtems_gxx_recursive_mutex_unlock() - Unnest" ); |
---|
46 | sc = rtems_gxx_recursive_mutex_unlock(&mutex); |
---|
47 | rtems_test_assert( sc == 0 ); |
---|
48 | |
---|
49 | puts( "rtems_gxx_recursive_mutex_unlock() - OK" ); |
---|
50 | sc = rtems_gxx_recursive_mutex_unlock(&mutex); |
---|
51 | rtems_test_assert( sc == 0 ); |
---|
52 | |
---|
53 | puts( "rtems_gxx_recursive_mutex_lock() - OK" ); |
---|
54 | sc = rtems_gxx_recursive_mutex_lock(&mutex); |
---|
55 | rtems_test_assert( sc == 0 ); |
---|
56 | |
---|
57 | puts( "rtems_gxx_recursive_mutex_unlock() - OK" ); |
---|
58 | sc = rtems_gxx_recursive_mutex_unlock(&mutex); |
---|
59 | rtems_test_assert( sc == 0 ); |
---|
60 | |
---|
61 | puts( "rtems_gxx_mutex_destroy(mutex) - OK" ); |
---|
62 | sc = rtems_gxx_mutex_destroy(&mutex); |
---|
63 | rtems_test_assert( sc == 0 ); |
---|
64 | |
---|
65 | puts( "rtems_gxx_mutex_destroy(mutex) - NOT OK" ); |
---|
66 | sc = rtems_gxx_mutex_destroy(&mutex); |
---|
67 | rtems_test_assert( sc == -1 ); |
---|
68 | } |
---|
69 | |
---|
70 | void test_mutex(void) |
---|
71 | { |
---|
72 | int sc; |
---|
73 | __gthread_mutex_t mutex; |
---|
74 | |
---|
75 | mutex = 0; |
---|
76 | puts( "rtems_gxx_mutex_init() - OK" ); |
---|
77 | rtems_gxx_mutex_init(&mutex); |
---|
78 | rtems_test_assert( mutex != 0 ); |
---|
79 | |
---|
80 | puts( "rtems_gxx_mutex_trylock() - OK" ); |
---|
81 | sc = rtems_gxx_mutex_trylock(&mutex); |
---|
82 | rtems_test_assert( sc == 0 ); |
---|
83 | |
---|
84 | puts( "rtems_gxx_mutex_unlock() - OK" ); |
---|
85 | sc = rtems_gxx_mutex_unlock(&mutex); |
---|
86 | rtems_test_assert( sc == 0 ); |
---|
87 | |
---|
88 | puts( "rtems_gxx_mutex_lock() - OK" ); |
---|
89 | sc = rtems_gxx_mutex_lock(&mutex); |
---|
90 | rtems_test_assert( sc == 0 ); |
---|
91 | |
---|
92 | puts( "rtems_gxx_mutex_unlock() - OK" ); |
---|
93 | sc = rtems_gxx_mutex_unlock(&mutex); |
---|
94 | rtems_test_assert( sc == 0 ); |
---|
95 | } |
---|
96 | |
---|
97 | void once_function(void) |
---|
98 | { |
---|
99 | puts( "Running once method" ); |
---|
100 | } |
---|
101 | |
---|
102 | void test_once(void) |
---|
103 | { |
---|
104 | __gthread_once_t once; |
---|
105 | int sc; |
---|
106 | |
---|
107 | once = 0; |
---|
108 | |
---|
109 | puts( "Call once method the first time" ); |
---|
110 | sc = rtems_gxx_once(&once, once_function); |
---|
111 | rtems_test_assert( sc == 0 ); |
---|
112 | |
---|
113 | puts( "Call once method the second time" ); |
---|
114 | sc = rtems_gxx_once(&once, once_function); |
---|
115 | rtems_test_assert( sc == 0 ); |
---|
116 | } |
---|
117 | |
---|
118 | volatile bool key_dtor_ran; |
---|
119 | void *key_for_testing; |
---|
120 | |
---|
121 | void key_dtor(void *ptr) |
---|
122 | { |
---|
123 | key_dtor_ran = true; |
---|
124 | } |
---|
125 | |
---|
126 | void test_key(void) |
---|
127 | { |
---|
128 | int sc; |
---|
129 | __gthread_key_t key; |
---|
130 | void *p; |
---|
131 | |
---|
132 | puts( "rtems_gxx_key_create(&key, NULL) - OK" ); |
---|
133 | sc = rtems_gxx_key_create(&key, NULL); |
---|
134 | rtems_test_assert( sc == 0 ); |
---|
135 | |
---|
136 | puts( "rtems_gxx_key_delete(key) - OK" ); |
---|
137 | sc = rtems_gxx_key_delete(key); |
---|
138 | rtems_test_assert( sc == 0 ); |
---|
139 | |
---|
140 | puts( "rtems_gxx_key_create(&key, key_dtor) - OK" ); |
---|
141 | sc = rtems_gxx_key_create(&key, key_dtor); |
---|
142 | rtems_test_assert( sc == 0 ); |
---|
143 | |
---|
144 | puts( "rtems_gxx_setspecific() - OK" ); |
---|
145 | sc = rtems_gxx_setspecific(key, (void *)0x1234); |
---|
146 | rtems_test_assert( sc == 0 ); |
---|
147 | |
---|
148 | puts( "rtems_gxx_getspecific(key) already existing - OK" ); |
---|
149 | p = rtems_gxx_getspecific(key); |
---|
150 | rtems_test_assert( p == (void *)0x1234 ); |
---|
151 | |
---|
152 | puts( "rtems_gxx_key_delete(key) - OK" ); |
---|
153 | sc = rtems_gxx_key_delete(key); |
---|
154 | rtems_test_assert( sc == 0 ); |
---|
155 | rtems_test_assert( key_dtor_ran == true ); |
---|
156 | |
---|
157 | puts( "rtems_gxx_getspecific(key_for_testing) non-existent - OK" ); |
---|
158 | p = rtems_gxx_getspecific((__gthread_key_t) &key_for_testing); |
---|
159 | rtems_test_assert( p == NULL ); |
---|
160 | rtems_test_assert( key_for_testing == NULL ); |
---|
161 | |
---|
162 | key_for_testing = malloc(4); |
---|
163 | rtems_test_assert( key_for_testing != NULL ); |
---|
164 | |
---|
165 | puts( "rtems_gxx_key_delete(key_for_testing) - OK" ); |
---|
166 | sc = rtems_gxx_key_delete((__gthread_key_t) &key_for_testing); |
---|
167 | rtems_test_assert( sc == 0 ); |
---|
168 | rtems_test_assert( key_for_testing == NULL ); |
---|
169 | |
---|
170 | |
---|
171 | key = (void *)0x1234; |
---|
172 | puts( "rtems_gxx_key_dtor(&key) - OK" ); |
---|
173 | sc = rtems_gxx_key_dtor((__gthread_key_t) &key, key_dtor); |
---|
174 | rtems_test_assert( sc == 0 ); |
---|
175 | rtems_test_assert( key == NULL ); |
---|
176 | } |
---|
177 | |
---|
178 | rtems_task Init( |
---|
179 | rtems_task_argument argument |
---|
180 | ) |
---|
181 | { |
---|
182 | puts( "\n\n*** TEST GXX 01 ***" ); |
---|
183 | |
---|
184 | test_mutex(); |
---|
185 | puts( "" ); |
---|
186 | |
---|
187 | test_recursive_mutex(); |
---|
188 | puts( "" ); |
---|
189 | |
---|
190 | test_once(); |
---|
191 | puts( "" ); |
---|
192 | |
---|
193 | test_key(); |
---|
194 | puts( "" ); |
---|
195 | |
---|
196 | puts( "*** END OF TEST GXX 01 ***" ); |
---|
197 | |
---|
198 | rtems_test_exit( 0 ); |
---|
199 | } |
---|
200 | |
---|
201 | /* configuration information */ |
---|
202 | |
---|
203 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
204 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
205 | |
---|
206 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
207 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
208 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
209 | |
---|
210 | #define CONFIGURE_INIT |
---|
211 | |
---|
212 | #include <rtems/confdefs.h> |
---|
213 | /* end of file */ |
---|