1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2008. |
---|
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 | #define CONFIGURE_INIT |
---|
13 | #include "system.h" |
---|
14 | #include <sched.h> |
---|
15 | #include <fcntl.h> |
---|
16 | #include <time.h> |
---|
17 | #include <tmacros.h> |
---|
18 | #include <signal.h> /* signal facilities */ |
---|
19 | |
---|
20 | typedef struct { |
---|
21 | char msg[ 50 ]; |
---|
22 | int size; |
---|
23 | unsigned int priority; |
---|
24 | }Test_Message_t; |
---|
25 | Test_Message_t Predefined_Msgs[MAXMSG+1]; |
---|
26 | Test_Message_t Predefined_Msgs[MAXMSG+1] = { |
---|
27 | { "12345678", 9, MQ_PRIO_MAX-1 }, /* Max Length Message med */ |
---|
28 | { "", 1, 1 }, /* NULL Message low */ |
---|
29 | { "Last", 5, MQ_PRIO_MAX }, /* Queue Full Message hi */ |
---|
30 | { "No Message", 0, MQ_PRIO_MAX-1 }, /* 0 length Message med */ |
---|
31 | { "1", 2, 0 }, /* Cause Overflow Behavior */ |
---|
32 | }; |
---|
33 | int Priority_Order[MAXMSG+1] = { 2, 0, 3, 1, MAXMSG }; |
---|
34 | |
---|
35 | |
---|
36 | typedef struct { |
---|
37 | mqd_t mq; |
---|
38 | Test_Queue_Types index; |
---|
39 | char *name; |
---|
40 | int oflag; |
---|
41 | int maxmsg; |
---|
42 | int msgsize; |
---|
43 | int count; |
---|
44 | } Test_queue_type; |
---|
45 | |
---|
46 | Test_queue_type Test_q[ NUMBER_OF_TEST_QUEUES + 1 ] = |
---|
47 | { |
---|
48 | { 0, 0, "Qread", ( O_CREAT | O_RDONLY | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 }, |
---|
49 | { 0, 1, "Qwrite", ( O_CREAT | O_WRONLY | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 }, |
---|
50 | { 0, 2, "Qnoblock", ( O_CREAT | O_RDWR | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 }, |
---|
51 | { 0, 3, "Qblock", ( O_CREAT | O_RDWR ) , MAXMSG, MSGSIZE, 0 }, |
---|
52 | { 0, 4, "Qdefault", ( O_CREAT | O_RDWR ) , 10, 16, 0 }, |
---|
53 | { 0, 5, "mq6", ( O_CREAT | O_WRONLY | O_NONBLOCK ), MAXMSG, MSGSIZE, 0 }, |
---|
54 | { 0, 6, "Qblock", ( O_RDWR ) , MAXMSG, MSGSIZE, 0 }, |
---|
55 | }; |
---|
56 | |
---|
57 | #define RW_NAME Test_q[ RW_QUEUE ].name |
---|
58 | #define DEFAULT_NAME Test_q[ DEFAULT_RW ].name |
---|
59 | #define RD_NAME Test_q[ RD_QUEUE ].name |
---|
60 | #define WR_NAME Test_q[ WR_QUEUE ].name |
---|
61 | #define BLOCKING_NAME Test_q[ BLOCKING ].name |
---|
62 | #define CLOSED_NAME Test_q[ CLOSED ].name |
---|
63 | |
---|
64 | #define RW_ATTR Test_q[ RW_QUEUE ].oflag |
---|
65 | #define DEFAULT_ATTR Test_q[ DEFAULT_RW ].oflag |
---|
66 | #define RD_ATTR Test_q[ RD_QUEUE ].oflag |
---|
67 | #define WR_ATTR Test_q[ WR_QUEUE ].oflag |
---|
68 | #define BLOCK_ATTR Test_q[ BLOCKING ].oflag |
---|
69 | #define CLOSED_ATTR Test_q[ CLOSED ].oflag |
---|
70 | |
---|
71 | /* |
---|
72 | * Outputs a header at each test section. |
---|
73 | */ |
---|
74 | void Start_Test( |
---|
75 | char *description |
---|
76 | ) |
---|
77 | { |
---|
78 | printf( "_______________%s\n", description ); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void Validate_attributes( |
---|
83 | mqd_t mq, |
---|
84 | int oflag, |
---|
85 | int msg_count |
---|
86 | ) |
---|
87 | { |
---|
88 | int status; |
---|
89 | struct mq_attr attr; |
---|
90 | |
---|
91 | status = mq_getattr( mq, &attr ); |
---|
92 | fatal_posix_service_status( status, 0, "mq_getattr valid return status"); |
---|
93 | |
---|
94 | if ( mq != Test_q[ DEFAULT_RW ].mq ){ |
---|
95 | fatal_int_service_status((int)attr.mq_maxmsg, MAXMSG, "maxmsg attribute" ); |
---|
96 | fatal_int_service_status((int)attr.mq_msgsize,MSGSIZE,"msgsize attribute"); |
---|
97 | } |
---|
98 | |
---|
99 | fatal_int_service_status((int)attr.mq_curmsgs, msg_count, "count attribute" ); |
---|
100 | fatal_int_service_status((int)attr.mq_flags, oflag, "flag attribute" ); |
---|
101 | } |
---|
102 | |
---|
103 | char Queue_Name[PATH_MAX + 2]; |
---|
104 | #define Get_Queue_Name( i ) Test_q[i].name |
---|
105 | |
---|
106 | char *Build_Queue_Name( int i ) { |
---|
107 | sprintf(Queue_Name,"mq%d", i+1 ); |
---|
108 | return Queue_Name; |
---|
109 | } |
---|
110 | |
---|
111 | char *Get_Too_Long_Name() |
---|
112 | { |
---|
113 | int i; |
---|
114 | |
---|
115 | for ( i=0; i< PATH_MAX+1; i++ ) |
---|
116 | Queue_Name[i] = 'N'; |
---|
117 | Queue_Name[i] = '\0'; |
---|
118 | return Queue_Name; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | void open_test_queues() |
---|
123 | { |
---|
124 | struct mq_attr attr; |
---|
125 | int status; |
---|
126 | Test_queue_type *tq; |
---|
127 | int que; |
---|
128 | |
---|
129 | attr.mq_maxmsg = MAXMSG; |
---|
130 | attr.mq_msgsize = MSGSIZE; |
---|
131 | |
---|
132 | puts( "Init: Open Test Queues" ); |
---|
133 | |
---|
134 | for( que = 0; que < NUMBER_OF_TEST_QUEUES+1; que++ ) { |
---|
135 | |
---|
136 | tq = &Test_q[ que ]; |
---|
137 | if ( que == DEFAULT_RW) |
---|
138 | Test_q[que].mq = mq_open( tq->name, tq->oflag, 0x777, NULL ); |
---|
139 | else |
---|
140 | Test_q[que].mq = mq_open( tq->name, tq->oflag, 0x777, &attr ); |
---|
141 | |
---|
142 | assert( Test_q[que].mq != (-1) ); |
---|
143 | } |
---|
144 | |
---|
145 | status = mq_close( Test_q[NUMBER_OF_TEST_QUEUES].mq ); |
---|
146 | fatal_posix_service_status( status, 0, "mq_close duplicate message queue"); |
---|
147 | status = mq_close( Test_q[CLOSED].mq ); |
---|
148 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
149 | status = mq_unlink( CLOSED_NAME ); |
---|
150 | fatal_posix_service_status( status, 0, "mq_unlink message queue"); |
---|
151 | } |
---|
152 | |
---|
153 | /* |
---|
154 | * Opens CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES then leaves size queues |
---|
155 | * opened but closes the rest. |
---|
156 | */ |
---|
157 | |
---|
158 | void validate_mq_open_error_codes() |
---|
159 | { |
---|
160 | int i; |
---|
161 | mqd_t n_mq2; |
---|
162 | struct mq_attr attr; |
---|
163 | int status; |
---|
164 | mqd_t open_mq[CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES + 1]; |
---|
165 | |
---|
166 | attr.mq_maxmsg = MAXMSG; |
---|
167 | attr.mq_msgsize = MSGSIZE; |
---|
168 | |
---|
169 | Start_Test( "mq_open errors" ); |
---|
170 | |
---|
171 | /* |
---|
172 | * XXX EINVAL - inappropriate name was given for the message queue |
---|
173 | */ |
---|
174 | |
---|
175 | /* |
---|
176 | * EINVAL - Create with negative maxmsg. |
---|
177 | */ |
---|
178 | |
---|
179 | attr.mq_maxmsg = -1; |
---|
180 | puts( "Init: mq_open - Create with maxmsg (-1) (EINVAL)" ); |
---|
181 | n_mq2 = mq_open( "mq2", O_CREAT | O_RDONLY, 0x777, &attr); |
---|
182 | fatal_posix_service_status( |
---|
183 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
184 | fatal_posix_service_status( errno, EINVAL, "mq_open errno EINVAL"); |
---|
185 | attr.mq_maxmsg = MAXMSG; |
---|
186 | |
---|
187 | /* |
---|
188 | * EINVAL - Create withnegative msgsize. |
---|
189 | */ |
---|
190 | |
---|
191 | attr.mq_msgsize = -1; |
---|
192 | puts( "Init: mq_open - Create with msgsize (-1) (EINVAL)" ); |
---|
193 | n_mq2 = mq_open( "mq2", O_CREAT | O_RDONLY, 0x777, &attr); |
---|
194 | fatal_posix_service_status( |
---|
195 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
196 | fatal_posix_service_status( errno, EINVAL, "mq_open errno EINVAL"); |
---|
197 | attr.mq_msgsize = MSGSIZE; |
---|
198 | |
---|
199 | /* |
---|
200 | * ENOENT - Open a non-created file. |
---|
201 | */ |
---|
202 | |
---|
203 | puts( "Init: mq_open - Open new mq without create flag (ENOENT)" ); |
---|
204 | n_mq2 = mq_open( "mq3", O_EXCL | O_RDONLY, 0x777, NULL); |
---|
205 | fatal_posix_service_status( |
---|
206 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
207 | fatal_posix_service_status( errno, ENOENT, "mq_open errno ENOENT"); |
---|
208 | |
---|
209 | /* |
---|
210 | * XXX EINTR - call was interrupted by a signal |
---|
211 | */ |
---|
212 | |
---|
213 | /* |
---|
214 | * ENAMETOOLONG - Give a name greater than PATH_MAX. |
---|
215 | */ |
---|
216 | |
---|
217 | puts( "Init: mq_open - Open with too long of a name (ENAMETOOLONG)" ); |
---|
218 | n_mq2 = mq_open( Get_Too_Long_Name(), O_CREAT | O_RDONLY, 0x777, NULL ); |
---|
219 | fatal_posix_service_status( |
---|
220 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
221 | fatal_posix_service_status( errno, ENAMETOOLONG, "mq_open errno ENAMETOOLONG"); |
---|
222 | |
---|
223 | /* |
---|
224 | * XXX - ENAMETOOLONG - Give a name greater than NAME_MAX |
---|
225 | * Per implementation not possible. |
---|
226 | */ |
---|
227 | |
---|
228 | /* |
---|
229 | * EEXIST - Create an existing queue. |
---|
230 | */ |
---|
231 | |
---|
232 | puts( "Init: mq_open - Create an Existing mq (EEXIST)" ); |
---|
233 | open_mq[0] = mq_open( |
---|
234 | Build_Queue_Name(0), O_CREAT | O_RDWR | O_NONBLOCK, 0x777, NULL ); |
---|
235 | assert( open_mq[0] != (-1) ); |
---|
236 | |
---|
237 | n_mq2 = mq_open( |
---|
238 | Build_Queue_Name(0), O_CREAT | O_EXCL | O_RDONLY, 0x777, NULL); |
---|
239 | fatal_posix_service_status( |
---|
240 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
241 | fatal_posix_service_status( errno, EEXIST, "mq_open errno EEXIST"); |
---|
242 | |
---|
243 | status = mq_unlink( Build_Queue_Name(0) ); |
---|
244 | fatal_posix_service_status( status, 0, "mq_unlink message queue"); |
---|
245 | |
---|
246 | status = mq_close( open_mq[0]); |
---|
247 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
248 | |
---|
249 | /* |
---|
250 | * Open maximum number of message queues |
---|
251 | */ |
---|
252 | |
---|
253 | puts( "Init: mq_open - SUCCESSFUL" ); |
---|
254 | for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) { |
---|
255 | open_mq[i] = mq_open( |
---|
256 | Build_Queue_Name(i), O_CREAT | O_RDWR | O_NONBLOCK, 0x777, NULL ); |
---|
257 | assert( open_mq[i] != (-1) ); |
---|
258 | assert( open_mq[i] ); |
---|
259 | /*XXX - Isn't there a more general check */ |
---|
260 | /* JRS printf( "mq_open 0x%x %s\n", open_mq[i], Build_Queue_Name(i) ); */ |
---|
261 | } |
---|
262 | |
---|
263 | /* |
---|
264 | * XXX EACCES - permission to create is denied. |
---|
265 | */ |
---|
266 | |
---|
267 | /* |
---|
268 | * XXX EACCES - queue exists permissions specified by o_flag are denied. |
---|
269 | */ |
---|
270 | |
---|
271 | /* |
---|
272 | * XXX EMFILE - Too many message queues in use by the process |
---|
273 | */ |
---|
274 | |
---|
275 | /* |
---|
276 | * ENFILE - Too many message queues open in the system |
---|
277 | */ |
---|
278 | |
---|
279 | puts( "Init: mq_open - system is out of resources (ENFILE)" ); |
---|
280 | n_mq2 = mq_open( Build_Queue_Name(i), O_CREAT | O_RDONLY, 0x777, NULL ); |
---|
281 | fatal_posix_service_status( |
---|
282 | (int) n_mq2, (int ) (-1), "mq_open error return status" ); |
---|
283 | fatal_posix_service_status( errno, ENFILE, "mq_open errno ENFILE"); |
---|
284 | |
---|
285 | /* |
---|
286 | * Unlink and Close all queues. |
---|
287 | */ |
---|
288 | |
---|
289 | puts( "Init: mq_close and mq_unlink (mq3...mqn) - SUCCESSFUL" ); |
---|
290 | for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) { |
---|
291 | |
---|
292 | status = mq_close( open_mq[i]); |
---|
293 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
294 | |
---|
295 | status = mq_unlink( Build_Queue_Name(i) ); |
---|
296 | if ( status == -1 ) |
---|
297 | perror( "mq_unlink" ); |
---|
298 | fatal_posix_service_status( status, 0, "mq_unlink message queue"); |
---|
299 | /* JRS printf( "mq_close/mq_unlink 0x%x %s\n", open_mq[i], Build_Queue_Name(i) ); */ |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | void validate_mq_unlink_error_codes() |
---|
304 | { |
---|
305 | int status; |
---|
306 | |
---|
307 | Start_Test( "mq_unlink errors" ); |
---|
308 | |
---|
309 | /* |
---|
310 | * XXX - EACCES Permission Denied |
---|
311 | */ |
---|
312 | |
---|
313 | /* |
---|
314 | * ENAMETOOLONG - Give a name greater than PATH_MAX. |
---|
315 | */ |
---|
316 | |
---|
317 | puts( "Init: mq_unlink - mq_unlink with too long of a name (ENAMETOOLONG)" ); |
---|
318 | status = mq_unlink( Get_Too_Long_Name() ); |
---|
319 | fatal_posix_service_status( status, -1, "mq_unlink error return status"); |
---|
320 | fatal_posix_service_status( errno, ENAMETOOLONG, "mq_unlink errno ENAMETOOLONG"); |
---|
321 | |
---|
322 | /* |
---|
323 | * XXX - ENAMETOOLONG - Give a name greater than NAME_MAX |
---|
324 | * Per implementation not possible. |
---|
325 | */ |
---|
326 | |
---|
327 | /* |
---|
328 | * ENOENT - Unlink an unopened queue |
---|
329 | */ |
---|
330 | |
---|
331 | puts( "Init: mq_unlink - A Queue not opened (ENOENT)" ); |
---|
332 | status = mq_unlink( CLOSED_NAME ); |
---|
333 | fatal_posix_service_status( status, -1, "mq_unlink error return status"); |
---|
334 | fatal_posix_service_status( errno, ENOENT, "mq_unlink errno ENOENT"); |
---|
335 | |
---|
336 | /* |
---|
337 | * XXX - The following were not listed in the POSIX document as |
---|
338 | * possible errors. Under other commands the EINVAL is |
---|
339 | * given for these conditions. |
---|
340 | */ |
---|
341 | |
---|
342 | /* |
---|
343 | * EINVAL - Unlink a queue with no name |
---|
344 | */ |
---|
345 | |
---|
346 | puts( "Init: mq_unlink (NULL) - EINVAL" ); |
---|
347 | status = mq_unlink( NULL ); |
---|
348 | fatal_posix_service_status( status, -1, "mq_unlink error return status"); |
---|
349 | fatal_posix_service_status( errno, EINVAL, "mq_unlink errno value"); |
---|
350 | |
---|
351 | /* |
---|
352 | * EINVAL - Unlink a queue with a null name |
---|
353 | */ |
---|
354 | |
---|
355 | puts( "Init: mq_unlink (\"\") - EINVAL" ); |
---|
356 | status = mq_unlink( "" ); |
---|
357 | fatal_posix_service_status( status, -1, "mq_unlink error return status"); |
---|
358 | fatal_posix_service_status( errno, EINVAL, "mq_unlink errno value"); |
---|
359 | } |
---|
360 | |
---|
361 | void validate_mq_close_error_codes() |
---|
362 | { |
---|
363 | int status; |
---|
364 | |
---|
365 | Start_Test( "mq_close errors" ); |
---|
366 | |
---|
367 | /* |
---|
368 | * EBADF - Close a queue that is not open. |
---|
369 | */ |
---|
370 | |
---|
371 | puts( "Init: mq_close - unopened queue (EBADF)" ); |
---|
372 | status = mq_close( Test_q[CLOSED].mq ); |
---|
373 | fatal_posix_service_status( status, -1, "mq_close error return status"); |
---|
374 | fatal_posix_service_status( errno, EBADF, "mq_close errno EBADF"); |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | void validate_mq_getattr_error_codes() |
---|
379 | { |
---|
380 | struct mq_attr attr; |
---|
381 | int status; |
---|
382 | |
---|
383 | Start_Test( "mq_getattr errors" ); |
---|
384 | |
---|
385 | /* |
---|
386 | * EBADF - Get the attributes from a closed queue. |
---|
387 | */ |
---|
388 | |
---|
389 | puts( "Init: mq_getattr - unopened queue (EBADF)" ); |
---|
390 | status = mq_getattr( Test_q[CLOSED].mq, &attr ); |
---|
391 | fatal_posix_service_status( status, -1, "mq_close error return status"); |
---|
392 | fatal_posix_service_status( errno, EBADF, "mq_close errno EBADF"); |
---|
393 | |
---|
394 | /* |
---|
395 | * XXX - The following are not listed in the POSIX manual but |
---|
396 | * may occur. |
---|
397 | */ |
---|
398 | |
---|
399 | /* |
---|
400 | * EINVAL - NULL attributes |
---|
401 | */ |
---|
402 | |
---|
403 | puts( "Init: mq_getattr - NULL attributes (EINVAL)" ); |
---|
404 | status = mq_getattr( Test_q[RW_QUEUE].mq, NULL ); |
---|
405 | fatal_posix_service_status( status, -1, "mq_close error return status"); |
---|
406 | fatal_posix_service_status( errno, EINVAL, "mq_close errno EINVAL"); |
---|
407 | |
---|
408 | } |
---|
409 | |
---|
410 | |
---|
411 | void Send_msg_to_que( |
---|
412 | int que, |
---|
413 | int msg |
---|
414 | ) |
---|
415 | { |
---|
416 | Test_Message_t *ptr = &Predefined_Msgs[msg]; |
---|
417 | int status; |
---|
418 | |
---|
419 | status = mq_send( Test_q[que].mq, ptr->msg, ptr->size , ptr->priority ); |
---|
420 | fatal_posix_service_status( status, 0, "mq_send valid return status"); |
---|
421 | Test_q[que].count++; |
---|
422 | } |
---|
423 | |
---|
424 | void Show_send_msg_to_que( |
---|
425 | char *task_name, |
---|
426 | int que, |
---|
427 | int msg |
---|
428 | ) |
---|
429 | { |
---|
430 | Test_Message_t *ptr = &Predefined_Msgs[msg]; |
---|
431 | printf( "%s mq_send - to %s msg: %s priority %d\n", |
---|
432 | task_name, Test_q[que].name, ptr->msg, ptr->priority); |
---|
433 | Send_msg_to_que( que, msg ); |
---|
434 | } |
---|
435 | |
---|
436 | void verify_queues_full( |
---|
437 | char *task_name |
---|
438 | ) |
---|
439 | { |
---|
440 | int que; |
---|
441 | |
---|
442 | /* |
---|
443 | * Validate that the queues are full. |
---|
444 | */ |
---|
445 | |
---|
446 | printf( "%s Verify Queues are full\n", task_name ); |
---|
447 | for( que = RW_QUEUE; que < CLOSED; que++ ) |
---|
448 | Validate_attributes( Test_q[que].mq, Test_q[que].oflag, Test_q[que].count ); |
---|
449 | |
---|
450 | } |
---|
451 | void verify_queues_empty( |
---|
452 | char *task_name |
---|
453 | ) |
---|
454 | { |
---|
455 | int que; |
---|
456 | |
---|
457 | printf( "%s Verify Queues are empty\n", task_name ); |
---|
458 | for( que = RW_QUEUE; que < CLOSED; que++ ) |
---|
459 | Validate_attributes( Test_q[que].mq, Test_q[que].oflag, 0 ); |
---|
460 | } |
---|
461 | |
---|
462 | int fill_message_queues( |
---|
463 | char *task_name |
---|
464 | ) |
---|
465 | { |
---|
466 | int msg; |
---|
467 | int que; |
---|
468 | |
---|
469 | |
---|
470 | verify_queues_empty( task_name ); |
---|
471 | |
---|
472 | /* |
---|
473 | * Fill Queue with predefined messages. |
---|
474 | */ |
---|
475 | |
---|
476 | printf( "%s Fill Queues with messages\n", task_name ); |
---|
477 | for(msg=0; msg<MAXMSG; msg++){ |
---|
478 | for( que = RW_QUEUE; que < CLOSED; que++ ) { |
---|
479 | Send_msg_to_que( que, msg ); |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | verify_queues_full( "Init:" ); |
---|
484 | return msg; |
---|
485 | } |
---|
486 | |
---|
487 | |
---|
488 | void Read_msg_from_que( |
---|
489 | int que, |
---|
490 | int msg |
---|
491 | ) |
---|
492 | { |
---|
493 | unsigned int priority; |
---|
494 | Test_Message_t *ptr; |
---|
495 | int status; |
---|
496 | char message[100]; |
---|
497 | char err_msg[100]; |
---|
498 | |
---|
499 | ptr = &Predefined_Msgs[msg]; |
---|
500 | status = mq_receive(Test_q[ que ].mq, message, 100, &priority ); |
---|
501 | Test_q[que].count--; |
---|
502 | |
---|
503 | sprintf( err_msg, "%s msg %s size failure", Test_q[ que ].name, ptr->msg ); |
---|
504 | fatal_int_service_status( status, ptr->size, err_msg ); |
---|
505 | |
---|
506 | assert( !strcmp( message, ptr->msg ) ); |
---|
507 | strcpy( message, "No Message" ); |
---|
508 | |
---|
509 | sprintf( err_msg,"%s msg %s size failure", Test_q[ que ].name, ptr->msg ); |
---|
510 | fatal_int_service_status(priority, ptr->priority, err_msg ); |
---|
511 | } |
---|
512 | |
---|
513 | int empty_message_queues( |
---|
514 | char *task_name |
---|
515 | ) |
---|
516 | { |
---|
517 | int que; |
---|
518 | int i; |
---|
519 | |
---|
520 | printf( "%s Empty all Queues\n", task_name ); |
---|
521 | for( que = RW_QUEUE; que < CLOSED; que++ ) { |
---|
522 | for(i=0; Test_q[que].count != 0; i++ ) |
---|
523 | Read_msg_from_que( que, Priority_Order[i] ); |
---|
524 | |
---|
525 | Validate_attributes( Test_q[ que].mq, Test_q[ que ].oflag, 0 ); |
---|
526 | } |
---|
527 | return 0; |
---|
528 | } |
---|
529 | |
---|
530 | /* |
---|
531 | * Returns the number of messages queued after the test on the |
---|
532 | * first queue. |
---|
533 | */ |
---|
534 | |
---|
535 | int validate_mq_send_error_codes( ) |
---|
536 | { |
---|
537 | int status; |
---|
538 | int i; |
---|
539 | char *str; |
---|
540 | |
---|
541 | Start_Test( "mq_send errors" ); |
---|
542 | |
---|
543 | /* |
---|
544 | * EBADF - Write to a closed queue. |
---|
545 | */ |
---|
546 | |
---|
547 | puts( "Init: mq_send - Closed message queue (EBADF)" ); |
---|
548 | status = mq_send( Test_q[CLOSED].mq, "", 1, 0 ); |
---|
549 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
550 | fatal_posix_service_status( errno, EBADF, "mq_send errno EBADF"); |
---|
551 | |
---|
552 | /* |
---|
553 | * EBADF - Write to a read only queue. |
---|
554 | */ |
---|
555 | |
---|
556 | puts( "Init: mq_send - Read only message queue (EBADF)" ); |
---|
557 | status = mq_send( Test_q[ RD_QUEUE ].mq, "", 1, 0 ); |
---|
558 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
559 | fatal_posix_service_status( errno, EBADF, "mq_send errno EBADF"); |
---|
560 | |
---|
561 | /* |
---|
562 | * XXX - EINTR Signal interrupted the call. |
---|
563 | * |
---|
564 | puts( "Init: mq_send - UNSUCCESSFUL (EINTR)" ); |
---|
565 | status = mq_send( Test_q, "", 0xffff, 0 ); |
---|
566 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
567 | fatal_posix_service_status( errno, E, "mq_send errno E"); |
---|
568 | */ |
---|
569 | |
---|
570 | /* |
---|
571 | * EINVAL priority is out of range. |
---|
572 | */ |
---|
573 | |
---|
574 | puts( "Init: mq_send - Priority out of range (EINVAL)" ); |
---|
575 | status = mq_send( Test_q[ RW_QUEUE ].mq, "", 1, MQ_PRIO_MAX + 1 ); |
---|
576 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
577 | fatal_posix_service_status( errno, EINVAL, "mq_send errno EINVAL"); |
---|
578 | |
---|
579 | /* |
---|
580 | * EMSGSIZE - Message size larger than msg_len |
---|
581 | * Validates that msgsize is stored correctly. |
---|
582 | */ |
---|
583 | |
---|
584 | puts( "Init: mq_send - Message longer than msg_len (EMSGSIZE)" ); |
---|
585 | status = mq_send( Test_q[ RW_QUEUE ].mq, "", MSGSIZE+1, 0 ); |
---|
586 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
587 | fatal_posix_service_status( errno, EMSGSIZE, "mq_send errno EMSGSIZE"); |
---|
588 | |
---|
589 | i = fill_message_queues( "Init:" ); |
---|
590 | |
---|
591 | /* |
---|
592 | * ENOSYS - send not supported |
---|
593 | puts( "Init: mq_send - Blocking Queue overflow (ENOSYS)" ); |
---|
594 | status = mq_send( n_mq1, Predefined_Msgs[i], 0, 0 ); |
---|
595 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
596 | fatal_posix_service_status( errno, EBADF, "mq_send errno EBADF"); |
---|
597 | |
---|
598 | status = mq_close( n_mq1 ); |
---|
599 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
600 | |
---|
601 | status = mq_unlink( "read_only" ); |
---|
602 | fatal_posix_service_status( status, 0, "mq_unlink message queue"); |
---|
603 | */ |
---|
604 | |
---|
605 | /* |
---|
606 | * EAGAIN - O_NONBLOCK and message queue is full. |
---|
607 | */ |
---|
608 | |
---|
609 | puts( "Init: mq_send - on a FULL non-blocking queue with (EAGAIN)" ); |
---|
610 | str = Predefined_Msgs[i].msg; |
---|
611 | status = mq_send(Test_q[RW_QUEUE].mq, str, 0, 0 ); |
---|
612 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
613 | fatal_posix_service_status( errno, EAGAIN, "mq_send errno EAGAIN"); |
---|
614 | |
---|
615 | return i-1; |
---|
616 | } |
---|
617 | |
---|
618 | void validate_mq_receive_error_codes( ) |
---|
619 | { |
---|
620 | int status; |
---|
621 | char message[100]; |
---|
622 | unsigned int priority; |
---|
623 | |
---|
624 | Start_Test( "mq_receive errors" ); |
---|
625 | |
---|
626 | /* |
---|
627 | * EBADF - Not A Valid Message Queue |
---|
628 | */ |
---|
629 | |
---|
630 | puts( "Init: mq_receive - Unopened message queue (EBADF)" ); |
---|
631 | status = mq_receive( Test_q[CLOSED].mq, message, 100, &priority ); |
---|
632 | fatal_posix_service_status( status, -1, "mq_ error return status"); |
---|
633 | fatal_posix_service_status( errno, EBADF, "mq_receive errno EBADF"); |
---|
634 | |
---|
635 | /* |
---|
636 | * EBADF - Queue not opened to read |
---|
637 | */ |
---|
638 | |
---|
639 | puts( "Init: mq_receive - Write only queue (EBADF)" ); |
---|
640 | status = mq_receive( Test_q[WR_QUEUE].mq, message, 100, &priority ); |
---|
641 | fatal_posix_service_status( status, -1, "mq_ error return status"); |
---|
642 | fatal_posix_service_status( errno, EBADF, "mq_receive errno EBADF"); |
---|
643 | |
---|
644 | /* |
---|
645 | * EMSGSIZE - Size is less than the message size attribute |
---|
646 | */ |
---|
647 | |
---|
648 | puts( "Init: mq_receive - Size is less than the message (EMSGSIZE)" ); |
---|
649 | status = mq_receive( |
---|
650 | Test_q[RW_QUEUE].mq, message, Predefined_Msgs[0].size-1, &priority ); |
---|
651 | fatal_posix_service_status( status, -1, "mq_ error return status"); |
---|
652 | fatal_posix_service_status( errno, EMSGSIZE, "mq_receive errno EMSGSIZE"); |
---|
653 | |
---|
654 | |
---|
655 | /* |
---|
656 | * EAGAIN - O_NONBLOCK and Queue is empty |
---|
657 | */ |
---|
658 | verify_queues_full( "Init:" ); |
---|
659 | empty_message_queues( "Init:" ); |
---|
660 | |
---|
661 | puts( "Init: mq_receive - Queue is empty (EAGAIN)" ); |
---|
662 | status = mq_receive( Test_q[RW_QUEUE].mq, message, 100, &priority ); |
---|
663 | fatal_posix_service_status( status, -1, "mq_ error return status"); |
---|
664 | fatal_posix_service_status( errno, EAGAIN, "mq_receive errno EAGAIN"); |
---|
665 | |
---|
666 | /* |
---|
667 | * XXX - EINTR - Interrupted by a signal |
---|
668 | */ |
---|
669 | |
---|
670 | /* |
---|
671 | * XXX - EBADMSG - a data corruption problem. |
---|
672 | */ |
---|
673 | |
---|
674 | /* |
---|
675 | * XXX - ENOSYS - mq_receive not supported |
---|
676 | */ |
---|
677 | } |
---|
678 | |
---|
679 | void verify_open_functionality() |
---|
680 | { |
---|
681 | #if 0 |
---|
682 | mqd_t n_mq; |
---|
683 | #endif |
---|
684 | |
---|
685 | Start_Test( "mq_open functionality" ); |
---|
686 | |
---|
687 | /* |
---|
688 | * Validate a second open returns the same message queue. |
---|
689 | */ |
---|
690 | |
---|
691 | #if 0 |
---|
692 | puts( "Init: mq_open - Open an existing mq ( same id )" ); |
---|
693 | n_mq = mq_open( RD_NAME, 0 ); |
---|
694 | fatal_posix_service_status( |
---|
695 | (int) n_mq, (int ) Test_q[RD_QUEUE].mq, "mq_open error return status" ); |
---|
696 | #endif |
---|
697 | } |
---|
698 | |
---|
699 | void verify_unlink_functionality() |
---|
700 | { |
---|
701 | mqd_t n_mq; |
---|
702 | int status; |
---|
703 | |
---|
704 | Start_Test( "mq_unlink functionality" ); |
---|
705 | |
---|
706 | /* |
---|
707 | * Unlink the message queue, then verify an open of the same name produces a |
---|
708 | * different message queue. |
---|
709 | */ |
---|
710 | |
---|
711 | puts( "Init: Unlink and Open without closing SUCCESSFUL" ); |
---|
712 | status = mq_unlink( DEFAULT_NAME ); |
---|
713 | fatal_posix_service_status( status, 0, "mq_unlink locked message queue"); |
---|
714 | |
---|
715 | n_mq = mq_open( DEFAULT_NAME, DEFAULT_ATTR, 0x777, NULL ); |
---|
716 | assert( n_mq != (-1) ); |
---|
717 | assert( n_mq != Test_q[ DEFAULT_RW ].mq ); |
---|
718 | |
---|
719 | |
---|
720 | status = mq_unlink( DEFAULT_NAME ); |
---|
721 | fatal_posix_service_status( status, 0, "mq_unlink locked message queue"); |
---|
722 | status = mq_close( Test_q[ DEFAULT_RW ].mq ); |
---|
723 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
724 | |
---|
725 | Test_q[ DEFAULT_RW ].mq = n_mq; |
---|
726 | } |
---|
727 | |
---|
728 | void verify_close_functionality() |
---|
729 | { |
---|
730 | int i; |
---|
731 | int status; |
---|
732 | Start_Test( "Unlink and Close All Files" ); |
---|
733 | for (i=0; i<DEFAULT_RW; i++) { |
---|
734 | |
---|
735 | status = mq_unlink( Get_Queue_Name(i) ); |
---|
736 | fatal_posix_service_status( status, 0, "mq_unlink message queue"); |
---|
737 | |
---|
738 | status = mq_close( Test_q[i].mq ); |
---|
739 | fatal_posix_service_status( status, 0, "mq_close message queue"); |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | |
---|
744 | void verify_timed_send_queue( |
---|
745 | int que, |
---|
746 | int is_blocking |
---|
747 | ) |
---|
748 | { |
---|
749 | struct timespec timeout; |
---|
750 | struct timeval tv1, tv2, tv3; |
---|
751 | struct timezone tz1, tz2; |
---|
752 | int len; |
---|
753 | int status; |
---|
754 | char *msg; |
---|
755 | |
---|
756 | timeout.tv_sec = 1; |
---|
757 | timeout.tv_nsec = 0; |
---|
758 | |
---|
759 | printf( "Init: mq_timedsend - on queue %s ", Test_q[que].name); |
---|
760 | len = Predefined_Msgs[MAXMSG].size; |
---|
761 | msg = Predefined_Msgs[MAXMSG].msg; |
---|
762 | gettimeofday( &tv1, &tz1 ); |
---|
763 | status = mq_timedsend( Test_q[que].mq, msg, len , 0, &timeout ); |
---|
764 | gettimeofday( &tv2, &tz2 ); |
---|
765 | tv3.tv_sec = tv2.tv_sec - tv1.tv_sec; |
---|
766 | tv3.tv_usec = tv2.tv_usec - tv1.tv_usec; |
---|
767 | |
---|
768 | if ( is_blocking ) { /* Don't verify the non-blocking queue */ |
---|
769 | fatal_int_service_status( status, -1, "mq_timedsend status"); |
---|
770 | fatal_posix_service_status( errno, ETIMEDOUT, "errno ETIMEDOUT"); |
---|
771 | } |
---|
772 | |
---|
773 | printf("Init: %ld sec %ld us\n", (long)tv3.tv_sec, (long)tv3.tv_usec ); |
---|
774 | |
---|
775 | if ( is_blocking ) /* non-blocking queue */ |
---|
776 | assert( tv3.tv_sec == 1 ); |
---|
777 | else |
---|
778 | assert( tv3.tv_sec == 0 ); |
---|
779 | |
---|
780 | if ( que == DEFAULT_RW ) |
---|
781 | Test_q[que].count++; |
---|
782 | } |
---|
783 | |
---|
784 | void verify_timed_send() |
---|
785 | { |
---|
786 | int que; |
---|
787 | |
---|
788 | Start_Test( "mq_timedsend" ); |
---|
789 | |
---|
790 | for( que = RW_QUEUE; que < CLOSED; que++ ) { |
---|
791 | if ( que == BLOCKING ) |
---|
792 | verify_timed_send_queue( que, 1 ); |
---|
793 | else |
---|
794 | verify_timed_send_queue( que, 0 ); |
---|
795 | } |
---|
796 | } |
---|
797 | |
---|
798 | void verify_timed_receive_queue( |
---|
799 | char *task_name, |
---|
800 | int que, |
---|
801 | int is_blocking |
---|
802 | ) |
---|
803 | { |
---|
804 | char message[ 100 ]; |
---|
805 | unsigned int priority; |
---|
806 | struct timespec tm; |
---|
807 | struct timeval tv1, tv2, tv3; |
---|
808 | struct timezone tz1, tz2; |
---|
809 | int status; |
---|
810 | |
---|
811 | tm.tv_sec = 1; |
---|
812 | tm.tv_nsec = 0; |
---|
813 | |
---|
814 | printf( "Init: %s mq_timedreceive - on queue %s ", task_name, Test_q[que].name); |
---|
815 | |
---|
816 | gettimeofday( &tv1, &tz1 ); |
---|
817 | status = mq_timedreceive( Test_q[ que ].mq, message, 100, &priority, &tm ); |
---|
818 | gettimeofday( &tv2, &tz2 ); |
---|
819 | tv3.tv_sec = tv2.tv_sec - tv1.tv_sec; |
---|
820 | tv3.tv_usec = tv2.tv_usec - tv1.tv_usec; |
---|
821 | |
---|
822 | fatal_int_service_status( status, -1, "mq_timedreceive status"); |
---|
823 | if ( is_blocking ) |
---|
824 | fatal_posix_service_status( errno, ETIMEDOUT, "errno ETIMEDOUT"); |
---|
825 | printf( "Init: %ld sec %ld us\n", (long)tv3.tv_sec, (long)tv3.tv_usec ); |
---|
826 | |
---|
827 | if ( is_blocking ) |
---|
828 | assert( tv3.tv_sec == 1 ); |
---|
829 | else |
---|
830 | assert( tv3.tv_sec == 0 ); |
---|
831 | } |
---|
832 | |
---|
833 | |
---|
834 | |
---|
835 | void verify_timed_receive() |
---|
836 | { |
---|
837 | int que; |
---|
838 | |
---|
839 | Start_Test( "mq_timedreceive" ); |
---|
840 | |
---|
841 | for( que = RW_QUEUE; que < CLOSED; que++ ) { |
---|
842 | if (( que == BLOCKING ) || ( que == DEFAULT_RW )) |
---|
843 | verify_timed_receive_queue( "Init:", que, 1 ); |
---|
844 | else |
---|
845 | verify_timed_receive_queue( "Init:", que, 0 ); |
---|
846 | } |
---|
847 | } |
---|
848 | |
---|
849 | #if (0) |
---|
850 | void verify_set_attr() |
---|
851 | { |
---|
852 | struct mq_attr save_attr[ NUMBER_OF_TEST_QUEUES ]; |
---|
853 | struct mq_attr attr; |
---|
854 | int i; |
---|
855 | int status; |
---|
856 | |
---|
857 | attr.mq_maxmsg = 0; |
---|
858 | attr.mq_msgsize = 0; |
---|
859 | |
---|
860 | Start_Test( "mq_setattr" ); |
---|
861 | |
---|
862 | puts( "Init: set_attr all queues to blocking" ); |
---|
863 | for(i=0; i<CLOSED; i++) { |
---|
864 | attr.mq_flags = Test_q[i].oflag & (~O_NONBLOCK ); |
---|
865 | status = mq_setattr( Test_q[i].mq, &attr, &save_attr[i] ); |
---|
866 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
867 | |
---|
868 | Validate_attributes( Test_q[i].mq, attr.mq_flags, 0 ); |
---|
869 | } |
---|
870 | |
---|
871 | for( i = RW_QUEUE; i < CLOSED; i++ ) { |
---|
872 | verify_timed_receive_queue( "Init:", i, 1 ); |
---|
873 | } |
---|
874 | |
---|
875 | for(i=0; i<CLOSED; i++) { |
---|
876 | attr.mq_flags = Test_q[i].oflag & (~O_NONBLOCK ); |
---|
877 | status = mq_setattr( Test_q[i].mq, &save_attr[i], NULL ); |
---|
878 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
879 | |
---|
880 | Validate_attributes( Test_q[i].mq, Test_q[i].oflag, 0 ); |
---|
881 | } |
---|
882 | } |
---|
883 | #endif |
---|
884 | |
---|
885 | void wait_for_signal( |
---|
886 | sigset_t *waitset, |
---|
887 | int sec, |
---|
888 | int expect_signal |
---|
889 | ) |
---|
890 | { |
---|
891 | siginfo_t siginfo; |
---|
892 | int status; |
---|
893 | struct timespec timeout; |
---|
894 | int signo; |
---|
895 | |
---|
896 | siginfo.si_code = -1; |
---|
897 | siginfo.si_signo = -1; |
---|
898 | siginfo.si_value.sival_int = -1; |
---|
899 | |
---|
900 | timeout.tv_sec = sec; |
---|
901 | timeout.tv_nsec = 0; |
---|
902 | |
---|
903 | status = sigemptyset( waitset ); |
---|
904 | assert( !status ); |
---|
905 | |
---|
906 | status = sigaddset( waitset, SIGUSR1 ); |
---|
907 | assert( !status ); |
---|
908 | |
---|
909 | printf( "waiting on any signal for %d seconds.\n", sec ); |
---|
910 | signo = sigtimedwait( waitset, &siginfo, &timeout ); |
---|
911 | if (expect_signal) { |
---|
912 | fatal_int_service_status( signo, SIGUSR1, "got SISUSR1" ); |
---|
913 | } else { |
---|
914 | fatal_int_service_status( signo, -1, "error return status"); |
---|
915 | fatal_posix_service_status( errno, EAGAIN, "errno EAGAIN"); |
---|
916 | } |
---|
917 | } |
---|
918 | |
---|
919 | void verify_notify() |
---|
920 | { |
---|
921 | struct sigevent event; |
---|
922 | int status; |
---|
923 | timer_t timer_id; |
---|
924 | sigset_t set; |
---|
925 | |
---|
926 | Start_Test( "mq_notify" ); |
---|
927 | |
---|
928 | /* timer create */ |
---|
929 | event.sigev_notify = SIGEV_SIGNAL; |
---|
930 | event.sigev_signo = SIGUSR1; |
---|
931 | if (timer_create (CLOCK_REALTIME, &event, &timer_id) == -1) |
---|
932 | fatal_posix_service_status( errno, 0, "errno ETIMEDOUT"); |
---|
933 | |
---|
934 | /* block the timer signal */ |
---|
935 | sigemptyset( &set ); |
---|
936 | sigaddset( &set, SIGUSR1 ); |
---|
937 | pthread_sigmask( SIG_BLOCK, &set, NULL ); |
---|
938 | |
---|
939 | /* |
---|
940 | * EBADF - Not A Valid Message Queue |
---|
941 | */ |
---|
942 | |
---|
943 | puts( "Init: mq_notify - Unopened message queue (EBADF)" ); |
---|
944 | status = mq_notify( Test_q[CLOSED].mq, NULL ); |
---|
945 | fatal_posix_service_status( status, -1, "mq_ error return status"); |
---|
946 | fatal_posix_service_status( errno, EBADF, "mq_receive errno EBADF"); |
---|
947 | |
---|
948 | /* |
---|
949 | * Create ... |
---|
950 | */ |
---|
951 | |
---|
952 | /* |
---|
953 | * XXX setup notification |
---|
954 | */ |
---|
955 | printf( "_____mq_notify - notify when %s gets a message\n",RW_NAME); |
---|
956 | status = mq_notify( Test_q[RW_QUEUE].mq, &event ); |
---|
957 | fatal_posix_service_status( status, 0, "mq_notify valid status"); |
---|
958 | wait_for_signal( &set, 3, 0 ); |
---|
959 | |
---|
960 | /* |
---|
961 | * Send and verify signal occurs and registration is removed. |
---|
962 | */ |
---|
963 | |
---|
964 | puts( "Init: Verify Signal when send" ); |
---|
965 | Show_send_msg_to_que( "Init:", RW_QUEUE, 0 ); |
---|
966 | wait_for_signal( &set, 3, 1 ); |
---|
967 | Read_msg_from_que( RW_QUEUE, 0 ); |
---|
968 | |
---|
969 | puts( "Init: Verify No Signal when send" ); |
---|
970 | Show_send_msg_to_que( "Init:", RW_QUEUE, 0 ); |
---|
971 | wait_for_signal( &set, 3, 0 ); |
---|
972 | Read_msg_from_que( RW_QUEUE, 0 ); |
---|
973 | |
---|
974 | |
---|
975 | /* |
---|
976 | * EBUSY - Already Registered |
---|
977 | */ |
---|
978 | |
---|
979 | printf( "____mq_notify - notify when %s gets a message\n",RD_NAME); |
---|
980 | status = mq_notify( Test_q[RW_QUEUE].mq, &event ); |
---|
981 | fatal_posix_service_status( status, 0, "mq_notify valid status"); |
---|
982 | wait_for_signal( &set, 3, 0 ); |
---|
983 | |
---|
984 | puts( "Init: mq_notify - (EBUSY)" ); |
---|
985 | status = mq_notify( Test_q[RW_QUEUE].mq, &event ); |
---|
986 | fatal_posix_service_status( status, -1, "mq_notify error return status"); |
---|
987 | fatal_posix_service_status( errno, EBUSY, "mq_notify errno EBUSY"); |
---|
988 | |
---|
989 | /* |
---|
990 | * Verify NULL removes registration. |
---|
991 | */ |
---|
992 | |
---|
993 | puts( "Init: mq_notify - Remove notification with null" ); |
---|
994 | status = mq_notify( Test_q[RW_QUEUE].mq, NULL ); |
---|
995 | fatal_posix_service_status( status, 0, "mq_notify valid status"); |
---|
996 | |
---|
997 | puts( "Init: Verify No Signal when send" ); |
---|
998 | Show_send_msg_to_que( "Init:", RW_QUEUE, 0 ); |
---|
999 | wait_for_signal( &set, 3, 0 ); |
---|
1000 | Read_msg_from_que( RW_QUEUE, 0 ); |
---|
1001 | |
---|
1002 | } |
---|
1003 | |
---|
1004 | void verify_with_threads() |
---|
1005 | { |
---|
1006 | int status; |
---|
1007 | pthread_t id; |
---|
1008 | Test_Message_t *ptr; |
---|
1009 | #if 0 |
---|
1010 | unsigned int priority; |
---|
1011 | char message[100]; |
---|
1012 | #endif |
---|
1013 | |
---|
1014 | |
---|
1015 | #if 0 |
---|
1016 | /* |
---|
1017 | * Create a task then block until the task sends the message. |
---|
1018 | * Task tests set attributes so one queue will have a thread |
---|
1019 | * blocked while attributes are changed. |
---|
1020 | */ |
---|
1021 | |
---|
1022 | Start_Test( "multi-thread Task 4 Receive Test" ); |
---|
1023 | status = pthread_create( &id, NULL, Task_4, NULL ); |
---|
1024 | assert( !status ); |
---|
1025 | puts( "Init: mq_receive - Empty queue changes to non-blocking (EAGAIN)" ); |
---|
1026 | status = mq_receive( Test_q[BLOCKING].mq, message, 100, &priority ); |
---|
1027 | fatal_int_service_status( status, -1, "mq_receive error return status"); |
---|
1028 | fatal_posix_service_status( errno, EAGAIN, "mq_receive errno EAGAIN"); |
---|
1029 | print_current_time( "Init: ", "" ); |
---|
1030 | #endif |
---|
1031 | /* |
---|
1032 | * Create a task then block until the task sends the message. |
---|
1033 | * Task tests set attributes so one queue will have a thread |
---|
1034 | * blocked while attributes are changed. |
---|
1035 | */ |
---|
1036 | |
---|
1037 | Start_Test( "multi-thread Task 1 Test" ); |
---|
1038 | status = pthread_create( &id, NULL, Task_1, NULL ); |
---|
1039 | assert( !status ); |
---|
1040 | Read_msg_from_que( BLOCKING, 0 ); /* Block until init writes */ |
---|
1041 | print_current_time( "Init: ", "" ); |
---|
1042 | |
---|
1043 | #if 0 |
---|
1044 | /* |
---|
1045 | * Fill the queue then create a task then block until the task receives a message. |
---|
1046 | * Task tests set attributes so one queue will have a thread |
---|
1047 | * blocked while attributes are changed. |
---|
1048 | */ |
---|
1049 | |
---|
1050 | Start_Test( "multi-thread Task 4 Send Test" ); |
---|
1051 | fill_message_queues( "Init:" ); |
---|
1052 | status = pthread_create( &id, NULL, Task_4, NULL ); |
---|
1053 | assert( !status ); |
---|
1054 | puts( "Init: mq_send - Full queue changes to non-blocking (EAGAIN)" ); |
---|
1055 | status = mq_send(Test_q[BLOCKING].mq, message, 0, 0 ); |
---|
1056 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
1057 | fatal_posix_service_status( errno, EAGAIN, "mq_send errno EAGAIN"); |
---|
1058 | verify_queues_full( "Init:" ); |
---|
1059 | empty_message_queues( "Init:" ); |
---|
1060 | #endif |
---|
1061 | /* |
---|
1062 | * Create a task then block until the task reads a message. |
---|
1063 | */ |
---|
1064 | |
---|
1065 | Start_Test( "multi-thread Task 2 Test" ); |
---|
1066 | fill_message_queues( "Init:" ); |
---|
1067 | status = pthread_create( &id, NULL, Task_2, NULL ); |
---|
1068 | assert( !status ); |
---|
1069 | Show_send_msg_to_que( "Init:", BLOCKING, Priority_Order[0] ); |
---|
1070 | print_current_time( "Init: ", "" ); |
---|
1071 | verify_queues_full( "Init:" ); |
---|
1072 | empty_message_queues( "Init:" ); |
---|
1073 | |
---|
1074 | /* |
---|
1075 | * Create a task then block until it deletes and closes all queues. |
---|
1076 | * EBADF - Queue unlinked and closed while blocked |
---|
1077 | */ |
---|
1078 | |
---|
1079 | Start_Test( "multi-thread Task 3 Test" ); |
---|
1080 | fill_message_queues( "Init:" ); |
---|
1081 | status = pthread_create( &id, NULL, Task_3, NULL ); |
---|
1082 | assert( !status ); |
---|
1083 | puts( "Init: mq_send - Block while thread deletes queue (EBADF)" ); |
---|
1084 | ptr = &Predefined_Msgs[0]; |
---|
1085 | status = mq_send( Test_q[BLOCKING].mq, ptr->msg, ptr->size , ptr->priority ); |
---|
1086 | fatal_posix_service_status( status, -1, "mq_send error return status"); |
---|
1087 | fatal_posix_service_status( errno, EBADF, "mq_send errno EBADF"); |
---|
1088 | |
---|
1089 | } |
---|
1090 | |
---|
1091 | void validate_mq_setattr() |
---|
1092 | { |
---|
1093 | struct mq_attr attr; |
---|
1094 | struct mq_attr save_attr[ NUMBER_OF_TEST_QUEUES ]; |
---|
1095 | int status; |
---|
1096 | int i; |
---|
1097 | |
---|
1098 | /* |
---|
1099 | * EBADF - Get the attributes from a closed queue. |
---|
1100 | */ |
---|
1101 | |
---|
1102 | puts( "Task1:mq_setattr - unopened queue (EBADF)" ); |
---|
1103 | status = mq_setattr( Test_q[CLOSED].mq, &attr, NULL ); |
---|
1104 | fatal_posix_service_status( status, -1, "mq_setattr error return status"); |
---|
1105 | fatal_posix_service_status( errno, EBADF, "mq_setattr errno EBADF"); |
---|
1106 | |
---|
1107 | /* |
---|
1108 | * XXX - The following are not listed in the POSIX manual but |
---|
1109 | * may occur. |
---|
1110 | */ |
---|
1111 | |
---|
1112 | /* |
---|
1113 | * EINVAL - NULL attributes |
---|
1114 | */ |
---|
1115 | |
---|
1116 | puts( "Task1:mq_setattr - NULL attributes (EINVAL)" ); |
---|
1117 | status = mq_setattr( Test_q[RW_QUEUE].mq, NULL, NULL ); |
---|
1118 | fatal_posix_service_status( status, -1, "mq_setattr error return status"); |
---|
1119 | fatal_posix_service_status( errno, EINVAL, "mq_setattr errno EINVAL"); |
---|
1120 | |
---|
1121 | /* |
---|
1122 | * Verify change queues to blocking, by verifying all queues block |
---|
1123 | * for a timed receive. |
---|
1124 | */ |
---|
1125 | |
---|
1126 | puts( "Init: set_attr all queues to blocking" ); |
---|
1127 | for(i=0; i<CLOSED; i++) { |
---|
1128 | attr.mq_flags = Test_q[i].oflag & (~O_NONBLOCK ); |
---|
1129 | status = mq_setattr( Test_q[i].mq, &attr, &save_attr[i] ); |
---|
1130 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
1131 | Validate_attributes( Test_q[i].mq, attr.mq_flags, 0 ); |
---|
1132 | } |
---|
1133 | for( i = RW_QUEUE; i < CLOSED; i++ ) { |
---|
1134 | verify_timed_receive_queue( "Init:", i, 1 ); |
---|
1135 | } |
---|
1136 | |
---|
1137 | /* |
---|
1138 | * Restore restore all queues to their old attribute. |
---|
1139 | */ |
---|
1140 | |
---|
1141 | for(i=0; i<CLOSED; i++) { |
---|
1142 | status = mq_setattr( Test_q[i].mq, &save_attr[i], NULL ); |
---|
1143 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
1144 | Validate_attributes( Test_q[i].mq, Test_q[i].oflag, 0 ); |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | void *POSIX_Init( |
---|
1149 | void *argument |
---|
1150 | ) |
---|
1151 | { |
---|
1152 | puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" ); |
---|
1153 | |
---|
1154 | validate_mq_open_error_codes( ); |
---|
1155 | open_test_queues(); |
---|
1156 | validate_mq_unlink_error_codes(); |
---|
1157 | validate_mq_close_error_codes(); |
---|
1158 | verify_unlink_functionality(); |
---|
1159 | validate_mq_setattr( ); |
---|
1160 | validate_mq_send_error_codes(); |
---|
1161 | validate_mq_getattr_error_codes(); |
---|
1162 | verify_timed_send(); |
---|
1163 | validate_mq_receive_error_codes(); |
---|
1164 | verify_timed_receive(); |
---|
1165 | verify_open_functionality(); |
---|
1166 | verify_notify(); |
---|
1167 | verify_with_threads(); |
---|
1168 | |
---|
1169 | puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" ); |
---|
1170 | rtems_test_exit( 0 ); |
---|
1171 | |
---|
1172 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1173 | } |
---|
1174 | |
---|
1175 | |
---|
1176 | void *Task_1 ( |
---|
1177 | void *argument |
---|
1178 | ) |
---|
1179 | { |
---|
1180 | /* Block Waiting for a message */ |
---|
1181 | |
---|
1182 | print_current_time( "Task_1: ", "" ); |
---|
1183 | |
---|
1184 | Show_send_msg_to_que( "Task_1:", BLOCKING, 0 ); |
---|
1185 | |
---|
1186 | puts( "Task_1: pthread_exit" ); |
---|
1187 | pthread_exit( NULL ); |
---|
1188 | |
---|
1189 | /* switch to Init */ |
---|
1190 | |
---|
1191 | assert( 0 ); |
---|
1192 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1193 | } |
---|
1194 | |
---|
1195 | void *Task_2( |
---|
1196 | void *argument |
---|
1197 | ) |
---|
1198 | { |
---|
1199 | print_current_time( "Task_2: ", "" ); |
---|
1200 | |
---|
1201 | |
---|
1202 | /* Block waiting to send a message */ |
---|
1203 | |
---|
1204 | verify_queues_full( "Task_2:" ); |
---|
1205 | Read_msg_from_que( BLOCKING, Priority_Order[0] ); /* Cause context switch */ |
---|
1206 | |
---|
1207 | puts( "Task_2: pthread_exit" ); |
---|
1208 | pthread_exit( NULL ); |
---|
1209 | |
---|
1210 | /* switch to Init */ |
---|
1211 | |
---|
1212 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1213 | } |
---|
1214 | |
---|
1215 | void *Task_3 ( |
---|
1216 | void *argument |
---|
1217 | ) |
---|
1218 | { |
---|
1219 | |
---|
1220 | print_current_time( "Task_3: ", "" ); |
---|
1221 | |
---|
1222 | /* |
---|
1223 | * close and unlink all queues. |
---|
1224 | */ |
---|
1225 | |
---|
1226 | verify_close_functionality( "Task_3: " ); |
---|
1227 | puts( "Task_3: pthread_exit" ); |
---|
1228 | pthread_exit( NULL ); |
---|
1229 | |
---|
1230 | /* switch to Init */ |
---|
1231 | |
---|
1232 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1233 | |
---|
1234 | } |
---|
1235 | |
---|
1236 | void *Task_4 ( |
---|
1237 | void *argument |
---|
1238 | ) |
---|
1239 | { |
---|
1240 | struct mq_attr attr; |
---|
1241 | int status; |
---|
1242 | int count; |
---|
1243 | |
---|
1244 | print_current_time( "Task_4: ", "" ); |
---|
1245 | |
---|
1246 | /* |
---|
1247 | * Set the count to the number of messages in the queue. |
---|
1248 | */ |
---|
1249 | |
---|
1250 | status = mq_getattr( Test_q[BLOCKING].mq, &attr ); |
---|
1251 | fatal_posix_service_status( status, 0, "mq_getattr valid return status"); |
---|
1252 | count = attr.mq_curmsgs; |
---|
1253 | |
---|
1254 | puts("Task_4: Set queue to non-blocking"); |
---|
1255 | attr.mq_flags = Test_q[BLOCKING].oflag | O_NONBLOCK; |
---|
1256 | status = mq_setattr( Test_q[BLOCKING].mq, &attr, NULL ); |
---|
1257 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
1258 | Validate_attributes( Test_q[BLOCKING].mq, attr.mq_flags, count ); |
---|
1259 | |
---|
1260 | puts("Task_4: Return queue to blocking"); |
---|
1261 | attr.mq_flags = Test_q[BLOCKING].oflag; |
---|
1262 | status = mq_setattr( Test_q[BLOCKING].mq, &attr, NULL ); |
---|
1263 | fatal_int_service_status( status, 0, "mq_setattr valid return status"); |
---|
1264 | Validate_attributes( Test_q[BLOCKING].mq, attr.mq_flags, count ); |
---|
1265 | |
---|
1266 | puts( "Task_4: pthread_exit" ); |
---|
1267 | pthread_exit( NULL ); |
---|
1268 | |
---|
1269 | /* switch to Init */ |
---|
1270 | |
---|
1271 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1272 | |
---|
1273 | } |
---|
1274 | |
---|
1275 | void *Task_5 ( |
---|
1276 | void *argument |
---|
1277 | ) |
---|
1278 | { |
---|
1279 | |
---|
1280 | print_current_time( "Task_5: ", "" ); |
---|
1281 | |
---|
1282 | puts( "Task_5: pthread_exit" ); |
---|
1283 | pthread_exit( NULL ); |
---|
1284 | |
---|
1285 | /* switch to Init */ |
---|
1286 | |
---|
1287 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1288 | |
---|
1289 | } |
---|
1290 | |
---|
1291 | void *Task_ ( |
---|
1292 | void *argument |
---|
1293 | ) |
---|
1294 | { |
---|
1295 | |
---|
1296 | print_current_time( "Task_: ", "" ); |
---|
1297 | |
---|
1298 | puts( "Task_: pthread_exit" ); |
---|
1299 | pthread_exit( NULL ); |
---|
1300 | |
---|
1301 | /* switch to Init */ |
---|
1302 | |
---|
1303 | return NULL; /* just so the compiler thinks we returned something */ |
---|
1304 | |
---|
1305 | } |
---|