source: rtems/testsuites/psxtests/psxmsgq01/init.c @ 99e7ab89

4.104.114.84.95
Last change on this file since 99e7ab89 was 99e7ab89, checked in by Jennifer Averett <Jennifer.Averett@…>, on 01/05/00 at 17:21:12

+ Added tests for open, close, unlink, and send.

  • Property mode set to 100644
File size: 12.6 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
38typedef enum {
39  DEFAULT_SIZE_TYPE,
40  TEST_SIZE_TYPE,
41  MAX_SIZE,
42  TYPES_OF_TEST_SIZES
43} TEST_MQ_SIZE_TYPES;
44
45
46/*
47 * Opens CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES then leaves size queues
48 * opened but closes the rest.
49 */
50
51void validate_mq_open_error_codes(
52  mqd_t   *mqs,      /* Must be large enough for Maximum to be opened. */
53  int      size
54)
55{
56  int             i;
57  mqd_t           n_mq2;
58  struct mq_attr  attr;
59  int             status;
60
61  assert( size < (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES-1) );
62
63  /*
64   * Validate mq_open errors that can occur when no queues are open.
65   *  EINVAL
66   *  ENOENT
67   *  EINTR
68   */
69
70  /*
71   * XXX EINVAL - inappropriate name was given for the message queue
72   */
73
74  attr.mq_maxmsg = -1;
75  puts( "mq_open - Create with maxmsg (-1) (EINVAL)" );
76  n_mq2 = mq_open("mq2", O_CREAT | O_RDONLY, 0x777, &attr);
77  fatal_directive_status(
78    (int) n_mq2, (int ) (-1), "mq_open error return status" );
79  fatal_directive_status( errno, EINVAL,  "mq_open errno EINVAL");
80
81  attr.mq_msgsize = -1;
82  puts( "mq_open - Create with msgsize (-1) (EINVAL)" );
83  n_mq2 = mq_open("mq2", O_CREAT | O_RDONLY, 0x777, &attr);
84  fatal_directive_status(
85    (int) n_mq2, (int ) (-1), "mq_open error return status" );
86  fatal_directive_status( errno, EINVAL,  "mq_open errno EINVAL");
87
88  puts( "mq_open - Open new mq without create flag (ENOENT)" );
89  n_mq2 = mq_open("mq3", O_EXCL | O_RDONLY, 0x777, NULL);
90  fatal_directive_status(
91    (int) n_mq2, (int ) (-1), "mq_open error return status" );
92  fatal_directive_status( errno, ENOENT,  "mq_open errno ENOENT");
93
94  /*
95   * XXX EINTR  - call was interrupted by a signal
96   */
97
98  /*
99   * XXX ENAMETOOLONG - Not checked in either sem_open or mq_open is
100   *                    this an error?
101   */
102
103  puts( "mq_open - Open with too long of a name (ENAMETOOLONG)" );
104  n_mq2 = mq_open( Get_Too_Long_Name(), O_CREAT | O_RDONLY, 0x777, NULL );
105  fatal_directive_status(
106    (int) n_mq2, (int ) (-1), "mq_open error return status" );
107  fatal_directive_status( errno, ENAMETOOLONG,  "mq_open errno ENAMETOOLONG");
108 
109  /*
110   * Open maximum number of message queues
111   */
112
113  puts( "mq_open - SUCCESSFUL" );
114  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) {
115    mqs[i] = mq_open( Get_Queue_Name(i), O_CREAT | O_RDWR, 0x777, NULL );
116    assert( mqs[i] != (-1) );
117    /*XXX - Isn't there a more general check */
118  }
119
120  /*
121   * Validate open errors that must occur after message queues are open.
122   *   EACCES
123   *   EEXIST
124   *   EMFILE
125   *   ENFILE
126   */
127
128  /*
129   * XXX EACCES - permission to create is denied.
130   */
131
132  /*
133   * XXX EACCES - queue exists permissions specified by o_flag are denied.
134  puts( "mq_open - open mq as write (EACCES)" );
135  n_mq2 = mq_open("mq1", O_CREAT | O_WRONLY, 0x777, NULL);
136  fatal_directive_status(
137    (int) n_mq2, (int ) (-1), "mq_open error return status" );
138  fatal_directive_status( errno, EACCES,  "mq_open errno EACCES");
139   */
140
141  puts( "mq_open - Create an Existing mq (EEXIST)" );
142  n_mq2 = mq_open("mq1", O_CREAT | O_EXCL | O_RDONLY, 0x777, NULL);
143  fatal_directive_status(
144    (int) n_mq2, (int ) (-1), "mq_open error return status" );
145  fatal_directive_status( errno, EEXIST,  "mq_open errno EEXIST");
146
147
148  /*
149   * XXX EMFILE  - Too many message queues open
150   */
151
152  puts( "mq_open - system is out of resources (ENFILE)" );
153  n_mq2 = mq_open( Get_Queue_Name(i), O_CREAT | O_RDONLY, 0x777, NULL );
154  fatal_directive_status(
155    (int) n_mq2, (int ) (-1), "mq_open error return status" );
156  fatal_directive_status( errno, ENFILE,  "mq_open errno ENFILE");
157
158  /*
159   * Unlink and Close .
160   */
161
162  puts( "mq_close and mq_unlink (mq3...mqn) - SUCCESSFUL" );
163  for (i = size; i < CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES; i++) {
164
165    status = mq_close( mqs[i] );
166    fatal_directive_status( status, 0, "mq_close message queue");
167
168    status = mq_unlink( Get_Queue_Name(i) );
169    fatal_directive_status( status, 0, "mq_unlink message queue");
170  }
171}
172
173void validate_mq_unlink_error_codes(
174  mqd_t   *mqs,     
175  int      size      /* Number still open in mqs */
176)
177{
178  int             status;
179
180  /*
181   * XXX - EACCES Permission Denied
182   */
183
184  /*
185   * XXX ENAMETOOLONG - Not checked in either sem_unlink or mq_unlink is
186   *                    this an error?
187   */
188
189  puts( "mq_unlink - mq_unlink with too long of a name (ENAMETOOLONG)" );
190  status = mq_unlink( Get_Too_Long_Name() );
191  fatal_directive_status( status, -1, "mq_unlink error return status");
192  fatal_directive_status( errno, ENAMETOOLONG, "mq_unlink errno ENAMETOOLONG");
193 
194  puts( "mq_unlink - UNSUCCESSFUL (ENOENT)" );
195  status = mq_unlink(Get_Queue_Name(size));
196  fatal_directive_status( status, -1, "mq_unlink error return status");
197  fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
198
199  /*
200   * XXX - These errors are not in the POSIX manual but may occur.
201   */
202
203  puts( "mq_unlink (NULL) - EINVAL" );
204  status = mq_unlink( NULL );
205  fatal_directive_status( status, -1, "mq_unlink error return status");
206  fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
207
208  puts( "mq_unlink (\"\") - EINVAL" );
209  status = mq_unlink( "" );
210  fatal_directive_status( status, -1, "mq_unlink error return status");
211  fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
212}
213
214void validate_mq_close_error_codes(
215  mqd_t   *mqs,     
216  int      size      /* Number still open in mqs */
217)
218{
219  int             status;
220
221  puts( "mq_close - UNSUCCESSFUL (EBADF)" );
222  status = mq_close(mqs[size]);
223  fatal_directive_status( status, -1, "mq_close error return status");
224  fatal_directive_status( errno, EBADF, "mq_close errno EBADF");
225}
226 
227/*
228 * Returns the number of messages queued after the test on the
229 * first queue.
230 */
231
232int validate_mq_send_error_codes(
233  mqd_t   *mqs,
234  int      size      /* Number still open in mqs */
235)
236{
237  int             status;
238  int             i;
239  mqd_t           n_mq1;
240  struct mq_attr  attr;
241
242  attr.mq_maxmsg  = 3;
243  attr.mq_msgsize = 8;
244
245  /*
246   * XXX - EBADF  Not a valid message descriptor.
247   *       Write to a invalid message descriptor
248   * XXX - Write to a read only queue
249   */
250
251  puts( "mq_send - Closed message queue (EBADF)" );
252  status = mq_send( mqs[size], "", 1, 0 );
253  fatal_directive_status( status, -1, "mq_send error return status");
254  fatal_directive_status( errno, EBADF, "mq_send errno EBADF");
255
256  puts( "mq_open - Open a read only queue" );
257  n_mq1 = mq_open("read_only", O_CREAT | O_RDONLY, 0x777, &attr);
258  assert( n_mq1 != (-1) );
259  /*XXX - Isn't there a more general check */
260
261  puts( "mq_send - Read only message queue (EBADF)" );
262  status = mq_send( n_mq1, "", 1, 0 );
263  fatal_directive_status( status, -1, "mq_send error return status");
264  fatal_directive_status( errno, EBADF, "mq_send errno EBADF");
265
266  status = mq_close( n_mq1 );
267  fatal_directive_status( status, 0, "mq_close message queue");
268
269  status = mq_unlink( "read_only" );
270  fatal_directive_status( status, 0, "mq_unlink message queue");
271
272  /*
273   * XXX - EINTR
274   *       Signal interrupted the call.
275
276  puts( "mq_send - UNSUCCESSFUL (EINTR)" );
277  status = mq_send( mqs, "", 0xffff, 0 );
278  fatal_directive_status( status, -1, "mq_send error return status");
279  fatal_directive_status( errno, E, "mq_send errno E");
280   */
281
282  /*
283   * XXX - EINVAL priority is out of range.
284   */
285
286  puts( "mq_send - Priority out of range (EINVAL)" );
287  status = mq_send( mqs[0], "", 1, MQ_PRIO_MAX + 1 );
288  fatal_directive_status( status, -1, "mq_send error return status");
289  fatal_directive_status( errno, EINVAL, "mq_send errno EINVAL");
290
291  /*
292   * XXX - EMSGSIZE - Message size larger than msg_len
293   */
294
295  puts( "mq_send - Message longer than msg_len (EMSGSIZE)" );
296  status = mq_send( mqs[0], "", 0xffff, 0 );
297  fatal_directive_status( status, -1, "mq_send error return status");
298  fatal_directive_status( errno, EMSGSIZE, "mq_send errno EMSGSIZE");
299
300  /*
301   * ENOSYS - send is supported should never happen.
302   */
303
304
305  /*
306   * XXX - EAGAIN
307   *       O_NONBLOCK and message queue is full.
308   *       This is validated in the read/write test.
309   */
310
311  i=0;
312  do {
313    status = mq_send( mqs[0], "", 1, 0 );
314    i++;
315  } while (status == 0);
316  fatal_directive_status( status, -1, "mq_send error return status");
317  fatal_directive_status( errno, EAGAIN, "mq_send errno EAGAIN");
318
319  return i-1;
320}
321
322void validate_mq_receive_error_codes(
323  mqd_t   *mqs,     
324  int      size      /* Number still open in mqs */
325)
326{
327  int             status;
328
329  /*
330   * EAGAIN -
331   */
332
333  /*
334   * EBADF -
335   */
336
337  /*
338   * EMSGSIZE -
339   */
340
341  /*
342   * EINTR -
343   */
344
345  /*
346   * EBADMSG - a data corruption problem.
347   *  XXX - Can not cause.
348   */
349
350  /*
351  puts( "mq_ - UNSUCCESSFUL ()" );
352  status = mq_(  );
353  fatal_directive_status( status, -1, "mq_ error return status");
354  fatal_directive_status( errno, E, "mq_c errno E");
355
356  */
357  /*
358   * ENOSYS -
359   */
360
361}
362
363void non_blocking_mq_read_write(
364  mqd_t   *mqs,     
365  int      size      /* Number still open in mqs */
366)
367{
368  /*
369  int         status;
370  char       *messages[] = {
371    "Msg 1",
372    "Test 2",
373    "12345678901234567890"
374  };
375
376  status = mq_send( mqs[0], messages[0], strlen( messages[0] ), 0 );
377  fatal_directive_status( status, 0, "mq_send error return status" );
378   
379  puts( "mq_send - UNSUCCESSFUL ()" );
380  do {
381    status = mq_send(  );
382  fatal_directive_status( status, -1, "mq_send error return status");
383  fatal_directive_status( errno, E, "mq_send errno E");
384  }
385  */
386}
387
388void *POSIX_Init(
389  void *argument
390)
391{
392  int             status;
393  mqd_t           mqs[CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES];
394  mqd_t           n_mq1;
395  mqd_t           n_mq2;
396  char           *messages[] = {
397    "Msg 1",
398    "Test 2",
399    "12345678901234567890"
400  };
401
402  puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" );
403
404  validate_mq_open_error_codes( mqs, 2 );
405  validate_mq_unlink_error_codes( mqs, 2 );
406  validate_mq_close_error_codes( mqs, 2 );
407
408  validate_mq_send_error_codes( mqs, 2 );
409  validate_mq_receive_error_codes( mqs, 2 );
410
411
412  /*
413   * Validate a second open returns the same message queue.
414   */
415
416  puts( "mq_open - Open an existing mq ( same id )" );
417  n_mq1 = mq_open("mq1", 0 );
418  fatal_directive_status(
419    (int) n_mq1, (int ) mqs[0], "mq_open error return status" );
420 
421  /*
422   * Unlink the message queue, then verify an open of the same name produces a
423   * different message queue.
424   */
425
426  puts( "mq_unlink - mq1 SUCCESSFUL" );
427  status = mq_unlink( "mq1" );
428  fatal_directive_status( status, 0, "mq_unlink locked message queue");
429
430  puts( "mq_open - Reopen mq1 SUCCESSFUL with a different id" );
431  n_mq2 = mq_open( "mq1", O_CREAT | O_EXCL, 00777, NULL);
432  assert( n_mq2 != (-1) );
433  assert( n_mq2 != n_mq1 );
434
435  /*
436   * Validate it "mq1" can be closed and unlinked.
437   */
438
439  puts( "mq_unlink - mq1 SUCCESSFUL" );
440  status = mq_unlink( "mq1" );
441  fatal_directive_status( status, 0, "mq_unlink locked message queue");
442
443  puts( "mq_close mq1 - SUCCESSFUL" );
444  status = mq_close( n_mq2 );
445  fatal_directive_status( status, 0, "mq_close message queue");
446  status = mq_close( n_mq1 );
447  fatal_directive_status( status, 0, "mq_close message queue");
448  status = mq_close( mqs[0] );
449  fatal_directive_status( status, 0, "mq_close message queue");
450
451  puts( "mq_unlink - UNSUCCESSFUL (ENOENT)" );
452  status = mq_unlink("mq1");
453  fatal_directive_status( status, -1, "mq_unlink error return status");
454  fatal_directive_status( errno, ENOENT, "mq_close errno EINVAL");
455
456  /*
457   * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
458   *       mq_close and mq_unlink.
459   * XXX - Don't think we need this save until yellow line tested.
460  puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
461  status = mq_unlink("mq3");
462  fatal_directive_status( status, -1, "mq_unlink error return status");
463  fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
464  assert( (status == -1) && (errno == ENOENT) );
465  */
466
467
468  /*
469   * Validate we can wait on a message queue opened with mq_open.
470   */
471#if (0) /* XXX FIX ME */
472  puts( "Init: mq_wait on mq1" );
473  status = mq_receive(n_mq1);
474  fatal_directive_status( status, 0, "mq_wait opened message queue");
475#endif
476
477
478  puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" );
479  exit( 0 );
480
481  return NULL; /* just so the compiler thinks we returned something */
482}
483
484
Note: See TracBrowser for help on using the repository browser.