Changeset 6eb3e68 in rtems


Ignore:
Timestamp:
Dec 23, 1999, 10:12:15 PM (20 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
20385957
Parents:
2e97c01
Message:

+ Tests added for mq_open, mq_close, and mq_unlink

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/tests/psxtests/psxmsgq01/init.c

    r2e97c01 r6eb3e68  
    1313#include "system.h"
    1414#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}
    15208
    16209void *POSIX_Init(
     
    23216  mqd_t           mqs[CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES];
    24217  mqd_t           mq2;
    25   mqd_t           *n_mq1;
    26   mqd_t           *n_mq2;
     218  mqd_t           n_mq1;
     219  mqd_t           n_mq2;
    27220  struct timespec waittime;
    28221  char            failure_msg[80];
    29 
     222  struct mq_attr  attr;
    30223
    31224  puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" );
    32225
    33 #if 0
    34   /* Modes are currently unsupported */
    35 
    36   /*
    37    * Validate all mq_open return paths.
    38    */
    39 
    40   puts( "Init: mq_open - mq1 SUCCESSFUL" );
    41   n_mq1 = mq_open( "mq1", O_CREAT, 00777, 1 );
    42   assert( n_mq1 != SEM_FAILED );
    43 
    44   puts( "Init: mq_open - Create an Existing mq (EEXIST)" );
    45   n_mq2 = mq_open("mq1", O_CREAT | O_EXCL, 00777, 1);
    46   fatal_directive_status(
    47     (int) n_mq2, (int ) SEM_FAILED, "mq_open error return status" );
    48   fatal_directive_status( errno, EEXIST,  "mq_open errno EEXIST");
    49 
    50   puts( "Init: mq_open - Open new mq without create flag (ENOENT)" );
    51   n_mq2 = mq_open("mq3", O_EXCL, 00777, 1);
    52   fatal_directive_status(
    53     (int) n_mq2, (int ) SEM_FAILED, "mq_open error return status" );
    54   fatal_directive_status( errno, ENOENT,  "mq_open errno EEXIST");
    55 
    56   /*
    57    * XXX - Could not hit the following errors:
    58    *   E_POSIX_Semaphore_Create_support only fails if
    59    *     ENOSYS - When semaphore is shared between processes.
    60    *     ENOSPC - When out of memory.
    61    */
     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
    62299
    63300  /*
    64301   * Validate we can wait on a message queue opened with mq_open.
    65302   */
    66 
     303#if (0) /* XXX FIX ME */
    67304  puts( "Init: mq_wait on mq1" );
    68305  status = mq_receive(n_mq1);
    69306  fatal_directive_status( status, 0, "mq_wait opened message queue");
    70 
    71   /*
    72    * Validate a second open returns the same message queue.
    73    */
    74 
    75   puts( "Init: mq_open - Open an existing mq ( same id )" );
    76   n_mq2 = mq_open("mq1", 0 );
    77   fatal_directive_status(
    78     (int) n_mq2, (int ) n_mq1, "mq_open error return status" );
    79  
    80   /*
    81    * Unlink the message queue, then verify an open of the same name produces a
    82    * different message queue.
    83    */
    84 
    85   puts( "Init: mq_unlink - mq1 SUCCESSFUL" );
    86   status = mq_unlink( "mq1" );
    87   fatal_directive_status( status, 0, "mq_unlink locked message queue");
    88 
    89   puts( "Init: mq_open - Reopen mq1 SUCCESSFUL with a different id" );
    90   n_mq2 = mq_open( "mq1", O_CREAT | O_EXCL, 00777, 1);
    91   assert( n_mq2 != SEM_FAILED );
    92   assert( n_mq2 != n_mq1 );
    93 
    94   /*
    95    * Validate we can call close on a message queue opened with mq_open.
    96    */
    97 
    98   puts( "Init: mq_close (1) - SUCCESSFUL" );
    99   status = mq_close( n_mq1 );
    100   fatal_directive_status( status, 0, "mq_close message queue");
    101 
    102 
    103   /*
    104    * Validate it n_mq2 (the last open for mq1 name can be
    105    * correctly closed and unlinked.
    106    */
    107 
    108   puts( "Init: mq_close (2) - SUCCESSFUL" );
    109   status = mq_close( n_mq2 );
    110   fatal_directive_status( status, 0, "mq_close message queue");
    111 
    112   puts( "Init: mq_unlink - mq1 (2) SUCCESSFUL" );
    113   status = mq_unlink( "mq1" );
    114   fatal_directive_status( status, 0, "mq_unlink locked message queue");
    115 
    116   puts( "Init: mq_close - UNSUCCESSFUL (EINVAL)" );
    117   status = mq_close(n_mq2);
    118   fatal_directive_status( status, -1, "mq_close error return status");
    119   fatal_directive_status( errno, EINVAL, "mq_close errno EINVAL");
    120 
    121   puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
    122   status = mq_unlink("mq1");
    123   fatal_directive_status( status, -1, "mq_unlink error return status");
    124   fatal_directive_status( errno, ENOENT, "mq_close errno EINVAL");
    125 
    126 
    127   /*
    128    * Validate we can unlink (2)
    129    */
    130 
    131   puts( "Init: mq_unlink (NULL) - EINVAL" );
    132   status = mq_unlink( NULL );
    133   fatal_directive_status( status, -1, "mq_unlink error return status");
    134   fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
    135 
    136   puts( "Init: mq_unlink (\"\") - EINVAL" );
    137   status = mq_unlink( "" );
    138   fatal_directive_status( status, -1, "mq_unlink error return status");
    139   fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
    140 
    141   /*
    142    * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
    143    *       mq_close and mq_unlink.
    144    */
    145 
    146   puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
    147   status = mq_unlink("mq2");
    148   fatal_directive_status( status, -1, "mq_unlink error return status");
    149   fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
    150   assert( (status == -1) && (errno == ENOENT) );
    151 
    152307#endif
     308
     309
    153310  puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" );
    154311  exit( 0 );
  • c/src/tests/psxtests/psxmsgq01/system.h

    r2e97c01 r6eb3e68  
    3939#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    4040
    41 #define CONFIGURE_MAXIMUM_POSIX_THREADS     2
     41#define CONFIGURE_MAXIMUM_POSIX_THREADS          2
     42#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES   10
     43
     44#define CONFIGURE_POSIX_INIT_THREAD_TABLE
     45#define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
     46        (RTEMS_MINIMUM_STACK_SIZE * 4)
    4247
    4348#include <confdefs.h>
    4449
    4550/* global variables */
    46 
    47 #ifdef CONFIGURE_INIT
    48 #define TEST_EXTERN
    49 #else
    50 #define TEST_EXTERN extern
    51 #endif
    5251
    5352TEST_EXTERN pthread_t        Init_id;
  • testsuites/psxtests/psxmsgq01/init.c

    r2e97c01 r6eb3e68  
    1313#include "system.h"
    1414#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}
    15208
    16209void *POSIX_Init(
     
    23216  mqd_t           mqs[CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES];
    24217  mqd_t           mq2;
    25   mqd_t           *n_mq1;
    26   mqd_t           *n_mq2;
     218  mqd_t           n_mq1;
     219  mqd_t           n_mq2;
    27220  struct timespec waittime;
    28221  char            failure_msg[80];
    29 
     222  struct mq_attr  attr;
    30223
    31224  puts( "\n\n*** POSIX MESSAGE QUEUE TEST ***" );
    32225
    33 #if 0
    34   /* Modes are currently unsupported */
    35 
    36   /*
    37    * Validate all mq_open return paths.
    38    */
    39 
    40   puts( "Init: mq_open - mq1 SUCCESSFUL" );
    41   n_mq1 = mq_open( "mq1", O_CREAT, 00777, 1 );
    42   assert( n_mq1 != SEM_FAILED );
    43 
    44   puts( "Init: mq_open - Create an Existing mq (EEXIST)" );
    45   n_mq2 = mq_open("mq1", O_CREAT | O_EXCL, 00777, 1);
    46   fatal_directive_status(
    47     (int) n_mq2, (int ) SEM_FAILED, "mq_open error return status" );
    48   fatal_directive_status( errno, EEXIST,  "mq_open errno EEXIST");
    49 
    50   puts( "Init: mq_open - Open new mq without create flag (ENOENT)" );
    51   n_mq2 = mq_open("mq3", O_EXCL, 00777, 1);
    52   fatal_directive_status(
    53     (int) n_mq2, (int ) SEM_FAILED, "mq_open error return status" );
    54   fatal_directive_status( errno, ENOENT,  "mq_open errno EEXIST");
    55 
    56   /*
    57    * XXX - Could not hit the following errors:
    58    *   E_POSIX_Semaphore_Create_support only fails if
    59    *     ENOSYS - When semaphore is shared between processes.
    60    *     ENOSPC - When out of memory.
    61    */
     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
    62299
    63300  /*
    64301   * Validate we can wait on a message queue opened with mq_open.
    65302   */
    66 
     303#if (0) /* XXX FIX ME */
    67304  puts( "Init: mq_wait on mq1" );
    68305  status = mq_receive(n_mq1);
    69306  fatal_directive_status( status, 0, "mq_wait opened message queue");
    70 
    71   /*
    72    * Validate a second open returns the same message queue.
    73    */
    74 
    75   puts( "Init: mq_open - Open an existing mq ( same id )" );
    76   n_mq2 = mq_open("mq1", 0 );
    77   fatal_directive_status(
    78     (int) n_mq2, (int ) n_mq1, "mq_open error return status" );
    79  
    80   /*
    81    * Unlink the message queue, then verify an open of the same name produces a
    82    * different message queue.
    83    */
    84 
    85   puts( "Init: mq_unlink - mq1 SUCCESSFUL" );
    86   status = mq_unlink( "mq1" );
    87   fatal_directive_status( status, 0, "mq_unlink locked message queue");
    88 
    89   puts( "Init: mq_open - Reopen mq1 SUCCESSFUL with a different id" );
    90   n_mq2 = mq_open( "mq1", O_CREAT | O_EXCL, 00777, 1);
    91   assert( n_mq2 != SEM_FAILED );
    92   assert( n_mq2 != n_mq1 );
    93 
    94   /*
    95    * Validate we can call close on a message queue opened with mq_open.
    96    */
    97 
    98   puts( "Init: mq_close (1) - SUCCESSFUL" );
    99   status = mq_close( n_mq1 );
    100   fatal_directive_status( status, 0, "mq_close message queue");
    101 
    102 
    103   /*
    104    * Validate it n_mq2 (the last open for mq1 name can be
    105    * correctly closed and unlinked.
    106    */
    107 
    108   puts( "Init: mq_close (2) - SUCCESSFUL" );
    109   status = mq_close( n_mq2 );
    110   fatal_directive_status( status, 0, "mq_close message queue");
    111 
    112   puts( "Init: mq_unlink - mq1 (2) SUCCESSFUL" );
    113   status = mq_unlink( "mq1" );
    114   fatal_directive_status( status, 0, "mq_unlink locked message queue");
    115 
    116   puts( "Init: mq_close - UNSUCCESSFUL (EINVAL)" );
    117   status = mq_close(n_mq2);
    118   fatal_directive_status( status, -1, "mq_close error return status");
    119   fatal_directive_status( errno, EINVAL, "mq_close errno EINVAL");
    120 
    121   puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
    122   status = mq_unlink("mq1");
    123   fatal_directive_status( status, -1, "mq_unlink error return status");
    124   fatal_directive_status( errno, ENOENT, "mq_close errno EINVAL");
    125 
    126 
    127   /*
    128    * Validate we can unlink (2)
    129    */
    130 
    131   puts( "Init: mq_unlink (NULL) - EINVAL" );
    132   status = mq_unlink( NULL );
    133   fatal_directive_status( status, -1, "mq_unlink error return status");
    134   fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
    135 
    136   puts( "Init: mq_unlink (\"\") - EINVAL" );
    137   status = mq_unlink( "" );
    138   fatal_directive_status( status, -1, "mq_unlink error return status");
    139   fatal_directive_status( errno, EINVAL, "mq_unlink errno value");
    140 
    141   /*
    142    * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
    143    *       mq_close and mq_unlink.
    144    */
    145 
    146   puts( "Init: mq_unlink - UNSUCCESSFUL (ENOENT)" );
    147   status = mq_unlink("mq2");
    148   fatal_directive_status( status, -1, "mq_unlink error return status");
    149   fatal_directive_status( errno, ENOENT, "mq_unlink errno ENOENT");
    150   assert( (status == -1) && (errno == ENOENT) );
    151 
    152307#endif
     308
     309
    153310  puts( "*** END OF POSIX MESSAGE QUEUE TEST ***" );
    154311  exit( 0 );
  • testsuites/psxtests/psxmsgq01/system.h

    r2e97c01 r6eb3e68  
    3939#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    4040
    41 #define CONFIGURE_MAXIMUM_POSIX_THREADS     2
     41#define CONFIGURE_MAXIMUM_POSIX_THREADS          2
     42#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES   10
     43
     44#define CONFIGURE_POSIX_INIT_THREAD_TABLE
     45#define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
     46        (RTEMS_MINIMUM_STACK_SIZE * 4)
    4247
    4348#include <confdefs.h>
    4449
    4550/* global variables */
    46 
    47 #ifdef CONFIGURE_INIT
    48 #define TEST_EXTERN
    49 #else
    50 #define TEST_EXTERN extern
    51 #endif
    5251
    5352TEST_EXTERN pthread_t        Init_id;
Note: See TracChangeset for help on using the changeset viewer.