source: rtems/testsuites/psxtests/psxmsgq01/init.c @ 698c2e50

4.115
Last change on this file since 698c2e50 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

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