Changeset 24f6608 in rtems


Ignore:
Timestamp:
Nov 22, 1999, 4:05:09 PM (21 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
0ebf5694
Parents:
b41a0d1
Message:

+ Corrected error messages.
+ Added tests for sem_open, sem_close, and sem_unlink.
+ Yellow lined sem_open, sem_close, sem_unlink,

_POSIX_Semaphore_Delete, _POSIX_Semaphore_Name_to_id,
and _POSIX_Semaphore_Create_support. Except for MP, pshared
OBJECT_REMOTE, and out of memory paths.

Files:
2 edited

Legend:

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

    rb41a0d1 r24f6608  
    1717  sem_t           *n_sem1;
    1818  sem_t           *n_sem2;
    19   sem_t           testsem;
    2019  struct timespec waittime;
    2120  char            failure_msg[80];
     
    4847  puts( "Init: sem_getvalue - UNSUCCESSFUL ");
    4948  status = sem_getvalue(&sem2, &value);
    50   fatal_directive_status( status, -1, "sem_init error return status");
     49  fatal_directive_status( status, -1, "sem_getvalue error return status");
    5150  fatal_directive_status( errno, EINVAL, "sem_getvalue errno EINVAL");
    5251
     
    5756  puts( "Init: sem_destroy - UNSUCCESSFUL (EINVAL)" );
    5857  status = sem_destroy(&sem2);
    59   fatal_directive_status( status, -1, "sem_init error return status");
     58  fatal_directive_status( status, -1, "sem_destroy error return status");
    6059  fatal_directive_status( errno, EINVAL, "sem_destroy errno EINVAL");
    6160
     
    6665  puts( "Init: sem_wait - UNSUCCESSFUL (EINVAL)" );
    6766  status = sem_wait(&sem2);
    68   fatal_directive_status( status, -1, "sem_init error return status");
     67  fatal_directive_status( status, -1, "sem_wait error return status");
    6968  fatal_directive_status( errno, EINVAL, "sem_wait errno EINVAL");
    7069
     
    8382  puts( "Init: sem_trywait - UNSUCCESSFUL (EAGAIN)" );
    8483  status = sem_trywait(&sems[1]);
    85   fatal_directive_status( status, -1, "sem_init error return status");
     84  fatal_directive_status( status, -1, "sem_trywait error return status");
    8685  fatal_directive_status( errno, EAGAIN, "sem_trywait errno EAGAIN");
    8786
    8887  puts( "Init: sem_trywait - UNSUCCESSFUL (EINVAL)" );
    8988  status = sem_trywait(&sem2);
    90   fatal_directive_status( status, -1, "sem_init error return status");
     89  fatal_directive_status( status, -1, "sem_trywait error return status");
    9190  fatal_directive_status( errno, EINVAL, "sem_trywait errno EINVAL");
    9291
     
    9998  puts( "Init: sem_timedwait - UNSUCCESSFUL (ETIMEDOUT)" );
    10099  status = sem_timedwait(&sems[1], &waittime);
    101   fatal_directive_status( status, -1, "sem_init error return status");
    102   fatal_directive_status( errno, ETIMEDOUT, "sem_init errno ETIMEDOUT");
     100  fatal_directive_status( status, -1, "sem_timedwait error return status");
     101  fatal_directive_status( errno, ETIMEDOUT, "sem_timedwait errno ETIMEDOUT");
    103102
    104103  puts( "Init: sem_timedwait - UNSUCCESSFUL (EINVAL)" );
    105104  status = sem_timedwait(&sem2, &waittime);
    106   fatal_directive_status( status, -1, "sem_init error return status");
     105  fatal_directive_status( status, -1, "sem_timedwait error return status");
    107106  fatal_directive_status( errno, EINVAL, "sem_init errno EINVAL");
    108107
    109108  puts( "Init: sem_post - UNSUCCESSFUL (EINVAL)" );
    110109  status = sem_post(&sem2);
    111   fatal_directive_status( status, -1, "sem_init error return status");
     110  fatal_directive_status( status, -1, "sem_post error return status");
    112111  fatal_directive_status( errno, EINVAL, "sem_post errno EINVAL");
    113112
     
    126125
    127126  puts( "Init: sem_open - sem1 SUCCESSFUL" );
    128   n_sem1 = sem_open("sem1", O_CREAT, 00777, 1);
     127  n_sem1 = sem_open( "sem1", O_CREAT, 00777, 1 );
    129128  assert( n_sem1 != SEM_FAILED );
    130129
    131   puts( "Init: sem_open - UNSUCCESSFUL (EEXIST)" );
     130  puts( "Init: sem_open - Create an Existing sem (EEXIST)" );
    132131  n_sem2 = sem_open("sem1", O_CREAT | O_EXCL, 00777, 1);
    133132  fatal_directive_status(
    134133    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
    135   fatal_directive_status( errno, EEXIST,  "sem_open errno EEXIST");
     134  fatal_directive_status( errno, EEXIST,  "sem_open errno EEXIST");
     135
     136  puts( "Init: sem_open - Open new sem without create flag (ENOENT)" );
     137  n_sem2 = sem_open("sem3", O_EXCL, 00777, 1);
     138  fatal_directive_status(
     139    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
     140  fatal_directive_status( errno, ENOENT,  "sem_open errno EEXIST");
     141
     142  /*
     143   * XXX - Could not hit the following errors:
     144   *   E_POSIX_Semaphore_Create_support only fails if
     145   *     ENOSYS - When semaphore is shared between processes.
     146   *     ENOSPC - When out of memory.
     147   */
    136148
    137149  /*
     
    143155  fatal_directive_status( status, 0, "sem_wait opened semaphore");
    144156
    145 #if 0
     157  /*
     158   * Validate a second open returns the same semaphore.
     159   */
     160
     161  puts( "Init: sem_open - Open an existing sem ( same id )" );
     162  n_sem2 = sem_open("sem1", 0 );
     163  fatal_directive_status(
     164    (int) n_sem2, (int ) n_sem1, "sem_open error return status" );
     165 
     166  /*
     167   * Unlink the semaphore, then verify an open of the same name produces a
     168   * different semaphore.
     169   */
     170
    146171  puts( "Init: sem_unlink - sem1 SUCCESSFUL" );
    147172  status = sem_unlink( "sem1" );
     
    151176  n_sem2 = sem_open( "sem1", O_CREAT | O_EXCL, 00777, 1);
    152177  assert( n_sem2 != SEM_FAILED );
    153 #endif
     178  assert( n_sem2 != n_sem1 );
    154179
    155180  /*
     
    157182   */
    158183
    159   puts( "Init: sem_close - SUCCESSFUL" );
     184  puts( "Init: sem_close (1) - SUCCESSFUL" );
    160185  status = sem_close( n_sem1 );
    161186  fatal_directive_status( status, 0, "sem_close semaphore");
    162187
    163   /*
    164    * Notes: 
    165    *  Calls to sem_close when sem_link has not been previously called shall
    166    *  have no effect on the state of the semaphore.
    167    *
    168    *
    169  
     188
     189  /*
     190   * Validate it n_sem2 (the last open for sem1 name can be
     191   * correctly closed and unlinked.
     192   */
     193
     194  puts( "Init: sem_close (2) - SUCCESSFUL" );
     195  status = sem_close( n_sem2 );
     196  fatal_directive_status( status, 0, "sem_close semaphore");
     197
     198  puts( "Init: sem_unlink - sem1 (2) SUCCESSFUL" );
     199  status = sem_unlink( "sem1" );
     200  fatal_directive_status( status, 0, "sem_unlink locked semaphore");
     201
    170202  puts( "Init: sem_close - UNSUCCESSFUL (EINVAL)" );
    171203  status = sem_close(n_sem2);
    172   fatal_directive_status( status, -1, "sem_init error return status");
     204  fatal_directive_status( status, -1, "sem_close error return status");
    173205  fatal_directive_status( errno, EINVAL, "sem_close errno EINVAL");
    174206
    175   puts( "Init: sem_unlink - SUCCESSFUL" );
     207  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
    176208  status = sem_unlink("sem1");
    177   fatal_directive_status( status, 0, "sem_unlink semaphore");
     209  fatal_directive_status( status, -1, "sem_unlink error return status");
     210  fatal_directive_status( errno, ENOENT, "sem_close errno EINVAL");
     211
     212
     213  /*
     214   * Validate we can unlink (2)
     215   */
     216
     217  puts( "Init: sem_unlink (NULL) - EINVAL" );
     218  status = sem_unlink( NULL );
     219  fatal_directive_status( status, -1, "sem_unlink error return status");
     220  fatal_directive_status( errno, EINVAL, "sem_unlink errno value");
     221
     222  puts( "Init: sem_unlink (\"\") - EINVAL" );
     223  status = sem_unlink( "" );
     224  fatal_directive_status( status, -1, "sem_unlink error return status");
     225  fatal_directive_status( errno, EINVAL, "sem_unlink errno value");
     226
     227  /*
     228   * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
     229   *       sem_close and sem_unlink.
     230   */
    178231
    179232  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
    180233  status = sem_unlink("sem2");
    181   fatal_directive_status( status, -1, "sem_init error return status");
     234  fatal_directive_status( status, -1, "sem_unlink error return status");
    182235  fatal_directive_status( errno, ENOENT, "sem_unlink errno ENOENT");
    183236  assert( (status == -1) && (errno == ENOENT) );
    184   */
     237
    185238
    186239  /* Try adding in unlinking before closing... (can we still open?) */
     
    191244  return NULL; /* just so the compiler thinks we returned something */
    192245}
    193 
    194 
    195 
  • testsuites/psxtests/psxsem01/init.c

    rb41a0d1 r24f6608  
    1717  sem_t           *n_sem1;
    1818  sem_t           *n_sem2;
    19   sem_t           testsem;
    2019  struct timespec waittime;
    2120  char            failure_msg[80];
     
    4847  puts( "Init: sem_getvalue - UNSUCCESSFUL ");
    4948  status = sem_getvalue(&sem2, &value);
    50   fatal_directive_status( status, -1, "sem_init error return status");
     49  fatal_directive_status( status, -1, "sem_getvalue error return status");
    5150  fatal_directive_status( errno, EINVAL, "sem_getvalue errno EINVAL");
    5251
     
    5756  puts( "Init: sem_destroy - UNSUCCESSFUL (EINVAL)" );
    5857  status = sem_destroy(&sem2);
    59   fatal_directive_status( status, -1, "sem_init error return status");
     58  fatal_directive_status( status, -1, "sem_destroy error return status");
    6059  fatal_directive_status( errno, EINVAL, "sem_destroy errno EINVAL");
    6160
     
    6665  puts( "Init: sem_wait - UNSUCCESSFUL (EINVAL)" );
    6766  status = sem_wait(&sem2);
    68   fatal_directive_status( status, -1, "sem_init error return status");
     67  fatal_directive_status( status, -1, "sem_wait error return status");
    6968  fatal_directive_status( errno, EINVAL, "sem_wait errno EINVAL");
    7069
     
    8382  puts( "Init: sem_trywait - UNSUCCESSFUL (EAGAIN)" );
    8483  status = sem_trywait(&sems[1]);
    85   fatal_directive_status( status, -1, "sem_init error return status");
     84  fatal_directive_status( status, -1, "sem_trywait error return status");
    8685  fatal_directive_status( errno, EAGAIN, "sem_trywait errno EAGAIN");
    8786
    8887  puts( "Init: sem_trywait - UNSUCCESSFUL (EINVAL)" );
    8988  status = sem_trywait(&sem2);
    90   fatal_directive_status( status, -1, "sem_init error return status");
     89  fatal_directive_status( status, -1, "sem_trywait error return status");
    9190  fatal_directive_status( errno, EINVAL, "sem_trywait errno EINVAL");
    9291
     
    9998  puts( "Init: sem_timedwait - UNSUCCESSFUL (ETIMEDOUT)" );
    10099  status = sem_timedwait(&sems[1], &waittime);
    101   fatal_directive_status( status, -1, "sem_init error return status");
    102   fatal_directive_status( errno, ETIMEDOUT, "sem_init errno ETIMEDOUT");
     100  fatal_directive_status( status, -1, "sem_timedwait error return status");
     101  fatal_directive_status( errno, ETIMEDOUT, "sem_timedwait errno ETIMEDOUT");
    103102
    104103  puts( "Init: sem_timedwait - UNSUCCESSFUL (EINVAL)" );
    105104  status = sem_timedwait(&sem2, &waittime);
    106   fatal_directive_status( status, -1, "sem_init error return status");
     105  fatal_directive_status( status, -1, "sem_timedwait error return status");
    107106  fatal_directive_status( errno, EINVAL, "sem_init errno EINVAL");
    108107
    109108  puts( "Init: sem_post - UNSUCCESSFUL (EINVAL)" );
    110109  status = sem_post(&sem2);
    111   fatal_directive_status( status, -1, "sem_init error return status");
     110  fatal_directive_status( status, -1, "sem_post error return status");
    112111  fatal_directive_status( errno, EINVAL, "sem_post errno EINVAL");
    113112
     
    126125
    127126  puts( "Init: sem_open - sem1 SUCCESSFUL" );
    128   n_sem1 = sem_open("sem1", O_CREAT, 00777, 1);
     127  n_sem1 = sem_open( "sem1", O_CREAT, 00777, 1 );
    129128  assert( n_sem1 != SEM_FAILED );
    130129
    131   puts( "Init: sem_open - UNSUCCESSFUL (EEXIST)" );
     130  puts( "Init: sem_open - Create an Existing sem (EEXIST)" );
    132131  n_sem2 = sem_open("sem1", O_CREAT | O_EXCL, 00777, 1);
    133132  fatal_directive_status(
    134133    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
    135   fatal_directive_status( errno, EEXIST,  "sem_open errno EEXIST");
     134  fatal_directive_status( errno, EEXIST,  "sem_open errno EEXIST");
     135
     136  puts( "Init: sem_open - Open new sem without create flag (ENOENT)" );
     137  n_sem2 = sem_open("sem3", O_EXCL, 00777, 1);
     138  fatal_directive_status(
     139    (int) n_sem2, (int ) SEM_FAILED, "sem_open error return status" );
     140  fatal_directive_status( errno, ENOENT,  "sem_open errno EEXIST");
     141
     142  /*
     143   * XXX - Could not hit the following errors:
     144   *   E_POSIX_Semaphore_Create_support only fails if
     145   *     ENOSYS - When semaphore is shared between processes.
     146   *     ENOSPC - When out of memory.
     147   */
    136148
    137149  /*
     
    143155  fatal_directive_status( status, 0, "sem_wait opened semaphore");
    144156
    145 #if 0
     157  /*
     158   * Validate a second open returns the same semaphore.
     159   */
     160
     161  puts( "Init: sem_open - Open an existing sem ( same id )" );
     162  n_sem2 = sem_open("sem1", 0 );
     163  fatal_directive_status(
     164    (int) n_sem2, (int ) n_sem1, "sem_open error return status" );
     165 
     166  /*
     167   * Unlink the semaphore, then verify an open of the same name produces a
     168   * different semaphore.
     169   */
     170
    146171  puts( "Init: sem_unlink - sem1 SUCCESSFUL" );
    147172  status = sem_unlink( "sem1" );
     
    151176  n_sem2 = sem_open( "sem1", O_CREAT | O_EXCL, 00777, 1);
    152177  assert( n_sem2 != SEM_FAILED );
    153 #endif
     178  assert( n_sem2 != n_sem1 );
    154179
    155180  /*
     
    157182   */
    158183
    159   puts( "Init: sem_close - SUCCESSFUL" );
     184  puts( "Init: sem_close (1) - SUCCESSFUL" );
    160185  status = sem_close( n_sem1 );
    161186  fatal_directive_status( status, 0, "sem_close semaphore");
    162187
    163   /*
    164    * Notes: 
    165    *  Calls to sem_close when sem_link has not been previously called shall
    166    *  have no effect on the state of the semaphore.
    167    *
    168    *
    169  
     188
     189  /*
     190   * Validate it n_sem2 (the last open for sem1 name can be
     191   * correctly closed and unlinked.
     192   */
     193
     194  puts( "Init: sem_close (2) - SUCCESSFUL" );
     195  status = sem_close( n_sem2 );
     196  fatal_directive_status( status, 0, "sem_close semaphore");
     197
     198  puts( "Init: sem_unlink - sem1 (2) SUCCESSFUL" );
     199  status = sem_unlink( "sem1" );
     200  fatal_directive_status( status, 0, "sem_unlink locked semaphore");
     201
    170202  puts( "Init: sem_close - UNSUCCESSFUL (EINVAL)" );
    171203  status = sem_close(n_sem2);
    172   fatal_directive_status( status, -1, "sem_init error return status");
     204  fatal_directive_status( status, -1, "sem_close error return status");
    173205  fatal_directive_status( errno, EINVAL, "sem_close errno EINVAL");
    174206
    175   puts( "Init: sem_unlink - SUCCESSFUL" );
     207  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
    176208  status = sem_unlink("sem1");
    177   fatal_directive_status( status, 0, "sem_unlink semaphore");
     209  fatal_directive_status( status, -1, "sem_unlink error return status");
     210  fatal_directive_status( errno, ENOENT, "sem_close errno EINVAL");
     211
     212
     213  /*
     214   * Validate we can unlink (2)
     215   */
     216
     217  puts( "Init: sem_unlink (NULL) - EINVAL" );
     218  status = sem_unlink( NULL );
     219  fatal_directive_status( status, -1, "sem_unlink error return status");
     220  fatal_directive_status( errno, EINVAL, "sem_unlink errno value");
     221
     222  puts( "Init: sem_unlink (\"\") - EINVAL" );
     223  status = sem_unlink( "" );
     224  fatal_directive_status( status, -1, "sem_unlink error return status");
     225  fatal_directive_status( errno, EINVAL, "sem_unlink errno value");
     226
     227  /*
     228   * XXX - Cant' create location OBJECTS_ERROR or OBJECTS_REMOTE.
     229   *       sem_close and sem_unlink.
     230   */
    178231
    179232  puts( "Init: sem_unlink - UNSUCCESSFUL (ENOENT)" );
    180233  status = sem_unlink("sem2");
    181   fatal_directive_status( status, -1, "sem_init error return status");
     234  fatal_directive_status( status, -1, "sem_unlink error return status");
    182235  fatal_directive_status( errno, ENOENT, "sem_unlink errno ENOENT");
    183236  assert( (status == -1) && (errno == ENOENT) );
    184   */
     237
    185238
    186239  /* Try adding in unlinking before closing... (can we still open?) */
     
    191244  return NULL; /* just so the compiler thinks we returned something */
    192245}
    193 
    194 
    195 
Note: See TracChangeset for help on using the changeset viewer.