source: rtems/testsuites/psxtests/psxmsgq01/init.c @ b302d527

4.104.114.84.95
Last change on this file since b302d527 was 6eb3e68, checked in by Jennifer Averett <Jennifer.Averett@…>, on 12/23/99 at 22:12:15

+ Tests added for mq_open, mq_close, and mq_unlink

  • Property mode set to 100644
File size: 8.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
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
19char Queue_Name[PATH_MAX + 2];
20char *Get_Queue_Name(
21  int i
22)
23{
24  sprintf(Queue_Name,"mq%d",i+1);
25  return Queue_Name;
26}
27
28char *Get_Too_Long_Name()
29{
30  int i;
31
32  for ( i=0; i< PATH_MAX+1; i++ )
33    Queue_Name[i] = 'N';
34  Queue_Name[i] = '\0';
35  return Queue_Name;
36}
37
38/*
39 * Opens CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES then leaves size queues
40 * opened but closes the rest.
41 */
42
43void validate_mq_open_error_codes(
44  mqd_t   *mqs,      /* Must be large enough for Maximum to be opened. */
45  int      size
46)
47{
48  int             i;
49  mqd_t           n_mq2;
50  struct mq_attr  attr;
51  int             status;
52
53  assert( size < (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES-1) );
54
55  /*
56   * Validate mq_open errors that can occur when no queues are open.
57   *  EINVAL
58   *  ENOENT
59   *  EINTR
60   */
61
62  /*
63   * XXX EINVAL - inappropriate name was given for the message queue
64   */
65
66  attr.mq_maxmsg = -1;
67  puts( "mq_open - Create with maxmsg (-1) (EINVAL)" );
68  n_mq2 = mq_open("mq2", O_CREAT, O_RDONLY, &attr);
69  fatal_directive_status(
70    (int) n_mq2, (int ) (-1), "mq_open error return status" );
71  fatal_directive_status( errno, EINVAL,  "mq_open errno EINVAL");
72
73  attr.mq_msgsize = -1;
74  puts( "mq_open - Create with msgsize (-1) (EINVAL)" );
75  n_mq2 = mq_open("mq2", O_CREAT, O_RDONLY, &attr);
76  fatal_directive_status(
77    (int) n_mq2, (int ) (-1), "mq_open error return status" );
78  fatal_directive_status( errno, EINVAL,  "mq_open errno EINVAL");
79
80
81  puts( "mq_open - Open new mq without create flag (ENOENT)" );
82  n_mq2 = mq_open("mq3", O_EXCL, O_RDONLY, NULL);
83  fatal_directive_status(
84    (int) n_mq2, (int ) (-1), "mq_open error return status" );
85  fatal_directive_status( errno, ENOENT,  "mq_open errno ENOENT");
86
87  /*
88   * XXX EINTR  - call was interrupted by a signal
89   */
90
91  /*
92   * XXX ENAMETOOLONG - Not checked in either sem_open or mq_open is
93   *                    this an error?
94   */
95
96  puts( "mq_open - Open with too long of a name (ENAMETOOLONG)" );
97  n_mq2 = mq_open( Get_Too_Long_Name(), O_CREAT, O_RDONLY, NULL );
98  fatal_directive_status(
99    (int) n_mq2, (int ) (-1), "mq_open error return status" );
100  fatal_directive_status( errno, ENAMETOOLONG,  "mq_open errno ENAMETOOLONG");
101 
102  /*
103   * Open maximum number of message queues
104   */
105
106  puts( "mq_open - SUCCESSFUL" );
107  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) {
108    mqs[i] = mq_open( Get_Queue_Name(i), O_CREAT, O_RDONLY, NULL );
109    assert( mqs[i] != (-1) );
110    /*XXX - Isn't there a more general check */
111  }
112
113  /*
114   * Validate open errors that must occur after message queues are open.
115   *   EACCES
116   *   EEXIST
117   *   EMFILE
118   *   ENFILE
119   */
120
121  /*
122   * XXX EACCES - permission to create is denied.
123   */
124
125  /*
126   * XXX EACCES - queue exists permissions specified by o_flag are denied.
127  puts( "mq_open - open mq as write (EACCES)" );
128  n_mq2 = mq_open("mq1", O_CREAT, O_WRONLY, NULL);
129  fatal_directive_status(
130    (int) n_mq2, (int ) (-1), "mq_open error return status" );
131  fatal_directive_status( errno, EACCES,  "mq_open errno EACCES");
132   */
133
134  puts( "mq_open - Create an Existing mq (EEXIST)" );
135  n_mq2 = mq_open("mq1", O_CREAT | O_EXCL, O_RDONLY, NULL);
136  fatal_directive_status(
137    (int) n_mq2, (int ) (-1), "mq_open error return status" );
138  fatal_directive_status( errno, EEXIST,  "mq_open errno EEXIST");
139
140
141  /*
142   * XXX EMFILE  - Too many message queues open
143   */
144
145  puts( "mq_open - system is out of resources (ENFILE)" );
146  n_mq2 = mq_open( Get_Queue_Name(i), O_CREAT, O_RDONLY, NULL );
147  fatal_directive_status(
148    (int) n_mq2, (int ) (-1), "mq_open error return status" );
149  fatal_directive_status( errno, ENFILE,  "mq_open errno ENFILE");
150
151  /*
152   * Unlink and Close .
153   */
154
155  puts( "mq_close and mq_unlink (mq3...mqn) - SUCCESSFUL" );
156  for (i = size; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) {
157
158    status = mq_close( mqs[i] );
159    fatal_directive_status( status, 0, "mq_close message queue");
160
161    status = mq_unlink( Get_Queue_Name(i) );
162    fatal_directive_status( status, 0, "mq_unlink message queue");
163  }
164}
165
166void validate_mq_unlink_error_codes(
167  mqd_t   *mqs,      /* Must be large enough for Maximum to be opened. */
168  int      size      /* Number still open */
169)
170{
171  int             status;
172
173  /*
174   * XXX - EACCES Permission Denied
175   */
176
177  /*
178   * XXX ENAMETOOLONG - Not checked in either sem_unlink or mq_unlink is
179   *                    this an error?
180  for ( i=0; i< PATH_MAX+1; i++ )
181    name[i] = 'N';
182  puts( "mq_open - Open with too long of a name (ENAMETOOLONG)" );
183  n_mq2 = mq_open( Get_Too_Long_Name(), O_CREAT, O_RDONLY, NULL );
184  fatal_directive_status(
185    (int) n_mq2, (int ) (-1), "mq_open error return status" );
186  fatal_directive_status( errno, ENAMETOOLONG,  "mq_open errno ENAMETOOLONG");
187  */
188 
189  puts( "mq_unlink - UNSUCCESSFUL (ENOENT)" );
190  status = mq_unlink(Get_Queue_Name(size));
191  fatal_directive_status( status, -1, "mq_unlink error return status");
192  fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
193}
194
195void validate_mq_close_error_codes(
196  mqd_t   *mqs,      /* Must be large enough for Maximum to be opened. */
197  int      size      /* Number still open */
198)
199{
200  int             status;
201
202  puts( "mq_close - UNSUCCESSFUL (EBADF)" );
203  status = mq_close(mqs[size]);
204  fatal_directive_status( status, -1, "mq_close error return status");
205  fatal_directive_status( errno, EBADF, "mq_close errno EBADF");
206
207}
208
209void *POSIX_Init(
210  void *argument
211)
212{
213  int             status;
214  int             value;
215  int             i;
216  mqd_t           mqs[CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES];
217  mqd_t           mq2;
218  mqd_t           n_mq1;
219  mqd_t           n_mq2;
220  struct timespec waittime;
221  char            failure_msg[80];
222  struct mq_attr  attr;
223
224  puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" );
225
226  validate_mq_open_error_codes( mqs, 2 );
227  validate_mq_unlink_error_codes( mqs, 2 );
228  validate_mq_close_error_codes( mqs, 2 );
229
230  /*
231   * Validate a second open returns the same message queue.
232   */
233
234  puts( "mq_open - Open an existing mq ( same id )" );
235  n_mq2 = mq_open("mq1", 0 );
236  fatal_directive_status(
237    (int) n_mq2, (int ) mqs[0], "mq_open error return status" );
238 
239  /*
240   * Unlink the message queue, then verify an open of the same name produces a
241   * different message queue.
242   */
243
244  puts( "mq_unlink - mq1 SUCCESSFUL" );
245  status = mq_unlink( "mq1" );
246  fatal_directive_status( status, 0, "mq_unlink locked message queue");
247
248  puts( "mq_open - Reopen mq1 SUCCESSFUL with a different id" );
249  n_mq2 = mq_open( "mq1", O_CREAT | O_EXCL, 00777, NULL);
250  assert( n_mq2 != (-1) );
251  assert( n_mq2 != n_mq1 );
252
253  /*
254   * Validate it n_mq2 (the last open for mq1 name can be
255   * correctly closed and unlinked.
256   */
257
258  puts( "Init: mq_unlink - mq1 (2) SUCCESSFUL" );
259  status = mq_unlink( "mq1" );
260  fatal_directive_status( status, 0, "mq_unlink locked message queue");
261
262  puts( "Init: mq_close (2) - SUCCESSFUL" );
263  status = mq_close( n_mq2 );
264  fatal_directive_status( status, 0, "mq_close message queue");
265
266
267  puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
268  status = mq_unlink("mq1");
269  fatal_directive_status( status, -1, "mq_unlink error return status");
270  fatal_directive_status( errno, ENOENT, "mq_close errno EINVAL");
271
272
273  /*
274   * Validate we can unlink (2)
275   */
276
277  puts( "Init: mq_unlink (NULL) - EINVAL" );
278  status = mq_unlink( NULL );
279  fatal_directive_status( status, -1, "mq_unlink error return status");
280  fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
281
282  puts( "Init: mq_unlink (\"\") - EINVAL" );
283  status = mq_unlink( "" );
284  fatal_directive_status( status, -1, "mq_unlink error return status");
285  fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
286
287  /*
288   * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
289   *       mq_close and mq_unlink.
290   */
291
292  puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
293  status = mq_unlink("mq3");
294  fatal_directive_status( status, -1, "mq_unlink error return status");
295  fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
296  assert( (status == -1) && (errno == ENOENT) );
297
298
299
300  /*
301   * Validate we can wait on a message queue opened with mq_open.
302   */
303#if (0) /* XXX FIX ME */
304  puts( "Init: mq_wait on mq1" );
305  status = mq_receive(n_mq1);
306  fatal_directive_status( status, 0, "mq_wait opened message queue");
307#endif
308
309
310  puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" );
311  exit( 0 );
312
313  return NULL; /* just so the compiler thinks we returned something */
314}
Note: See TracBrowser for help on using the repository browser.