source: rtems/testsuites/psxtests/psxmsgq04/init.c @ 236839e2

4.104.115
Last change on this file since 236839e2 was 236839e2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/09 at 16:33:36

2009-08-05 Joel Sherrill <joel.sherrill@…>

  • psxmsgq04/init.c, psxmsgq04/psxmsgq04.doc, psxmsgq04/psxmsgq04.scn: Update to handle ENFILE case now that POSIX message queues and message queue file descriptors are configured separately and this error is possible.
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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#include <pmacros.h>
13#include <unistd.h>
14#include <errno.h>
15#include <tmacros.h>
16
17#include <fcntl.h>           /* For O_* constants */
18#include <sys/stat.h>        /* For mode constants */
19#include <mqueue.h>
20
21#include "test_support.h"
22
23void *POSIX_Init(
24  void *argument
25)
26{
27  struct mq_attr          attr;
28  mqd_t                   Queue, second_Queue;
29  int                     sc;
30  Heap_Information_block  info;
31  bool                    sb;
32
33  puts( "\n\n*** POSIX MESSAGE QUEUE TEST 4 ***" );
34
35  attr.mq_maxmsg = 1;
36  attr.mq_msgsize = sizeof(int);
37
38  puts( "Init - Open message queue instance 1" );
39  Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr );
40  if ( Queue == (-1) )
41    perror( "mq_open failed" );
42  assert( Queue != (-1) );
43
44  puts( "Init - Open message queue instance 2 - FAIL - ENFILE " );
45  second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr );
46  if ( second_Queue != (-1) )
47    puts( "mq_open did not failed" );
48  assert( second_Queue == (-1) );
49  assert( errno == ENFILE );
50
51  puts( "Init - Unlink message queue instance 1" );
52  sc = mq_unlink( "Queue" );
53  if ( sc != 0 )
54    perror( "mq_unlink failed" );
55  assert( sc == 0 );
56
57  puts( "Init - Close message queue instance 1" );
58  sc = mq_close( Queue );
59  if ( sc != 0 )
60    perror( "mq_close failed" );
61  assert( sc == 0 );
62
63  puts( "Init - Memory allocation error test" );
64
65  sb = rtems_workspace_get_information( &info );
66
67  attr.mq_msgsize = info.Free.largest;
68
69  while ( attr.mq_msgsize > 0 ) {
70    second_Queue = mq_open("second_queue",O_CREAT | O_RDWR, 0x777, &attr );
71    if ( second_Queue!=(-1) )
72      break;
73    attr.mq_msgsize -= 48;
74  }
75
76  if ( second_Queue == (-1) ) {
77    perror( "mq_open failed" );
78    assert( second_Queue != (-1) );
79  }
80
81  puts( "Init - Message Queue created" );
82  puts( "Init - Unlink message queue" );
83    sc = mq_unlink( "second_queue" );
84    if ( sc != 0 )
85      perror( "mq_unlink failed" );
86    assert( sc==0 );
87
88  puts( "Init - Close message queue" );
89    sc = mq_close( second_Queue );
90    if ( sc !=0 )
91      perror( "mq_close failed" );
92    assert( sc == 0 );
93  puts( "*** END OF POSIX MESSAGE QUEUE TEST 4 ***" );
94  rtems_test_exit( 0 );
95
96  return NULL; /* just so the compiler thinks we returned something */
97}
98
99/* configuration information */
100
101#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
102#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
103
104#define CONFIGURE_POSIX_INIT_THREAD_TABLE
105
106#define CONFIGURE_MAXIMUM_POSIX_THREADS                        1
107#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES                 1
108#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_FILE_DESCRIPTORS 2
109
110#define CONFIGURE_POSIX_INIT_THREAD_TABLE
111
112#define CONFIGURE_INIT
113#include <rtems/confdefs.h>
114/* end of include file */
Note: See TracBrowser for help on using the repository browser.