1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
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 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | #include <fcntl.h> |
---|
16 | #include <timesys.h> |
---|
17 | #include <errno.h> |
---|
18 | #include <rtems/timerdrv.h> |
---|
19 | #include "test_support.h" |
---|
20 | #include <tmacros.h> |
---|
21 | #include <mqueue.h> |
---|
22 | #include <signal.h> /* signal facilities */ |
---|
23 | |
---|
24 | #define MQ_MAXMSG 1 |
---|
25 | #define MQ_MSGSIZE sizeof(int) |
---|
26 | |
---|
27 | mqd_t queue; |
---|
28 | mqd_t queue2; |
---|
29 | const char *q_name; |
---|
30 | |
---|
31 | void benchmark_mq_open(int printable) |
---|
32 | { |
---|
33 | benchmark_timer_t end_time; |
---|
34 | struct mq_attr attr; |
---|
35 | |
---|
36 | attr.mq_maxmsg = MQ_MAXMSG; |
---|
37 | attr.mq_msgsize = MQ_MSGSIZE; |
---|
38 | q_name= "queue"; |
---|
39 | |
---|
40 | benchmark_timer_initialize(); |
---|
41 | queue = mq_open( q_name, O_CREAT | O_RDWR , 0x777, &attr ); |
---|
42 | end_time = benchmark_timer_read(); |
---|
43 | rtems_test_assert( queue != (-1) ); |
---|
44 | |
---|
45 | if (printable == 1) |
---|
46 | put_time( |
---|
47 | "mq_open (first open)", |
---|
48 | end_time, |
---|
49 | 1, /* Only executed once */ |
---|
50 | 0, |
---|
51 | 0 |
---|
52 | ); |
---|
53 | } |
---|
54 | |
---|
55 | void benchmark_mq_open_second(int printable) |
---|
56 | { |
---|
57 | benchmark_timer_t end_time; |
---|
58 | struct mq_attr attr; |
---|
59 | |
---|
60 | attr.mq_maxmsg = MQ_MAXMSG; |
---|
61 | attr.mq_msgsize = MQ_MSGSIZE; |
---|
62 | |
---|
63 | benchmark_timer_initialize(); |
---|
64 | queue2 =mq_open( q_name, O_RDONLY | O_CREAT , 0x777, &attr); |
---|
65 | end_time = benchmark_timer_read(); |
---|
66 | rtems_test_assert( queue2 != (-1) ); |
---|
67 | |
---|
68 | if (printable == 1) |
---|
69 | put_time( |
---|
70 | "mq_open (second open)", |
---|
71 | end_time, |
---|
72 | 1, /* Only executed once */ |
---|
73 | 0, |
---|
74 | 0 |
---|
75 | ); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | void benchmark_mq_close(int printable) |
---|
80 | { |
---|
81 | benchmark_timer_t end_time; |
---|
82 | int status; |
---|
83 | |
---|
84 | benchmark_timer_initialize(); |
---|
85 | status = mq_close(queue); |
---|
86 | end_time = benchmark_timer_read(); |
---|
87 | rtems_test_assert( status == 0 ); |
---|
88 | |
---|
89 | if (printable == 1) |
---|
90 | put_time( |
---|
91 | "mq_close (close of first)", |
---|
92 | end_time, |
---|
93 | 1, /* Only executed once */ |
---|
94 | 0, |
---|
95 | 0 |
---|
96 | ); |
---|
97 | } |
---|
98 | |
---|
99 | void benchmark_mq_close_second(int printable) |
---|
100 | { |
---|
101 | benchmark_timer_t end_time; |
---|
102 | int status; |
---|
103 | |
---|
104 | benchmark_timer_initialize(); |
---|
105 | status = mq_close(queue2); |
---|
106 | end_time = benchmark_timer_read(); |
---|
107 | rtems_test_assert( status == 0 ); |
---|
108 | |
---|
109 | if (printable == 1) |
---|
110 | put_time( |
---|
111 | "mq_close (close of second)", |
---|
112 | end_time, |
---|
113 | 1, /* Only executed once */ |
---|
114 | 0, |
---|
115 | 0 |
---|
116 | ); |
---|
117 | } |
---|
118 | |
---|
119 | void benchmark_mq_unlink(void) |
---|
120 | { |
---|
121 | benchmark_timer_t end_time; |
---|
122 | int status; |
---|
123 | |
---|
124 | benchmark_timer_initialize(); |
---|
125 | status = mq_unlink(q_name); |
---|
126 | end_time = benchmark_timer_read(); |
---|
127 | rtems_test_assert( status == 0 ); |
---|
128 | |
---|
129 | put_time( |
---|
130 | "mq_unlink", |
---|
131 | end_time, |
---|
132 | 1, /* Only executed once */ |
---|
133 | 0, |
---|
134 | 0 |
---|
135 | ); |
---|
136 | } |
---|
137 | |
---|
138 | void benchmark_mq_notify(void) |
---|
139 | { |
---|
140 | benchmark_timer_t end_time; |
---|
141 | int status; |
---|
142 | struct sigevent event; |
---|
143 | |
---|
144 | event.sigev_notify = SIGEV_SIGNAL; |
---|
145 | event.sigev_signo = SIGUSR1; |
---|
146 | |
---|
147 | benchmark_timer_initialize(); |
---|
148 | status = mq_notify( queue2, &event ); |
---|
149 | end_time = benchmark_timer_read(); |
---|
150 | rtems_test_assert( status == 0 ); |
---|
151 | |
---|
152 | put_time( |
---|
153 | "mq_notify", |
---|
154 | end_time, |
---|
155 | 1, /* Only executed once */ |
---|
156 | 0, |
---|
157 | 0 |
---|
158 | ); |
---|
159 | } |
---|
160 | |
---|
161 | void benchmark_mq_send(void) |
---|
162 | { |
---|
163 | benchmark_timer_t end_time; |
---|
164 | int status; |
---|
165 | |
---|
166 | status = 9; |
---|
167 | benchmark_timer_initialize(); |
---|
168 | status = mq_send( queue, (const char *)&status, MQ_MSGSIZE, 1 ); |
---|
169 | end_time = benchmark_timer_read(); |
---|
170 | rtems_test_assert( status != (-1) ); |
---|
171 | |
---|
172 | put_time( |
---|
173 | "mq_send - no threads waiting", |
---|
174 | end_time, |
---|
175 | 1, /* Only executed once */ |
---|
176 | 0, |
---|
177 | 0 |
---|
178 | ); |
---|
179 | } |
---|
180 | |
---|
181 | void benchmark_mq_receive(void) |
---|
182 | { |
---|
183 | benchmark_timer_t end_time; |
---|
184 | int status; |
---|
185 | unsigned int priority; |
---|
186 | int message[MQ_MAXMSG]; |
---|
187 | priority = 1; /*priority low*/ |
---|
188 | |
---|
189 | benchmark_timer_initialize(); |
---|
190 | status = mq_receive( queue2, ( char *)message, MQ_MSGSIZE, &priority ); |
---|
191 | end_time = benchmark_timer_read(); |
---|
192 | rtems_test_assert( status != (-1) ); |
---|
193 | |
---|
194 | put_time( |
---|
195 | "mq_receive - available", |
---|
196 | end_time, |
---|
197 | 1, /* Only executed once */ |
---|
198 | 0, |
---|
199 | 0 |
---|
200 | ); |
---|
201 | } |
---|
202 | |
---|
203 | void benchmark_mq_timedsend(void) |
---|
204 | { |
---|
205 | benchmark_timer_t end_time; |
---|
206 | int status; |
---|
207 | struct timespec timeout; |
---|
208 | |
---|
209 | status = 5; |
---|
210 | timeout.tv_sec = 0; |
---|
211 | timeout.tv_nsec = 1; |
---|
212 | benchmark_timer_initialize(); |
---|
213 | status = mq_timedsend( |
---|
214 | queue, (const char *)&status, MQ_MSGSIZE, 1, &timeout); |
---|
215 | end_time = benchmark_timer_read(); |
---|
216 | rtems_test_assert( status != (-1) ); |
---|
217 | |
---|
218 | put_time( |
---|
219 | "mq_timedsend - no threads waiting", |
---|
220 | end_time, |
---|
221 | 1, /* Only executed once */ |
---|
222 | 0, |
---|
223 | 0 |
---|
224 | ); |
---|
225 | } |
---|
226 | |
---|
227 | void benchmark_mq_timedreceive(void) |
---|
228 | { |
---|
229 | benchmark_timer_t end_time; |
---|
230 | int status; |
---|
231 | unsigned int priority; |
---|
232 | struct timespec timeout; |
---|
233 | int message[MQ_MAXMSG]; |
---|
234 | |
---|
235 | priority = 1; /*priority low*/ |
---|
236 | timeout.tv_sec = 0; |
---|
237 | timeout.tv_nsec = 0; |
---|
238 | benchmark_timer_initialize(); |
---|
239 | status = mq_timedreceive( |
---|
240 | queue2, ( char *)message, MQ_MSGSIZE, &priority, &timeout); |
---|
241 | end_time = benchmark_timer_read(); |
---|
242 | rtems_test_assert( status != (-1) ); |
---|
243 | |
---|
244 | put_time( |
---|
245 | "mq_timedreceive - available", |
---|
246 | end_time, |
---|
247 | 1, /* Only executed once */ |
---|
248 | 0, |
---|
249 | 0 |
---|
250 | ); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | void *POSIX_Init( |
---|
255 | void *argument |
---|
256 | ) |
---|
257 | { |
---|
258 | puts( "\n\n*** POSIX TIME TEST PSXTMMQ01 ***" ); |
---|
259 | /* create the first message queue READWRITE */ |
---|
260 | benchmark_mq_open(1); |
---|
261 | /* send message using first queue */ |
---|
262 | benchmark_mq_send(); |
---|
263 | /* open a second message queue READ ONLY */ |
---|
264 | benchmark_mq_open_second(1); |
---|
265 | /* receiving message using the seconde queue */ |
---|
266 | benchmark_mq_receive(); |
---|
267 | /* closing the second message queue */ |
---|
268 | benchmark_mq_close_second(0); |
---|
269 | /* unlinking the first queue */ |
---|
270 | benchmark_mq_unlink(); |
---|
271 | /* closing the first queue */ |
---|
272 | benchmark_mq_close(0); |
---|
273 | /* now repeat basically the same, but for the timed-send/recive */ |
---|
274 | /* open the first queue */ |
---|
275 | benchmark_mq_open(0); |
---|
276 | /* send message using the first queue */ |
---|
277 | benchmark_mq_timedsend(); |
---|
278 | /* open a second message queue READ ONLY */ |
---|
279 | benchmark_mq_open_second(0); |
---|
280 | /* receiving message using the seconde queue */ |
---|
281 | benchmark_mq_timedreceive(); |
---|
282 | /* calling notify */ |
---|
283 | benchmark_mq_notify(); |
---|
284 | /* closing the second message queue */ |
---|
285 | benchmark_mq_close_second(1); |
---|
286 | /* closing the first queue */ |
---|
287 | benchmark_mq_close(1); |
---|
288 | |
---|
289 | puts( "*** END OF POSIX TIME TEST PSXTMMQ01 ***" ); |
---|
290 | rtems_test_exit(0); |
---|
291 | } |
---|
292 | |
---|
293 | /* configuration information */ |
---|
294 | |
---|
295 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
296 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
297 | |
---|
298 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
299 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
300 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 2 |
---|
301 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS 2 |
---|
302 | |
---|
303 | #define CONFIGURE_INIT |
---|
304 | |
---|
305 | #include <rtems/confdefs.h> |
---|
306 | /* end of file */ |
---|