Changeset 520949bf in rtems


Ignore:
Timestamp:
08/14/96 17:16:14 (26 years ago)
Author:
Mark Johannes <Mark.Johannes@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
b0c483ed
Parents:
645fc954
Message:

init: added error case for wait timedwait, and wait support

Files:
2 edited

Legend:

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

    r645fc954 r520949bf  
    2121{
    2222  int                 status;
    23   pthread_t           thread_id;
    2423  pthread_condattr_t  attr;
     24  pthread_condattr_t  attr_error;
    2525  int                 pshared;
    2626  pthread_cond_t      cond;
     
    3333  assert( !status );
    3434
    35   puts( "Init: pthread_condattr_init - EINVAL" );
     35  puts( "Init: pthread_condattr_init - EINVAL (attribute invalid)" );
    3636  status = pthread_condattr_init( NULL );
    3737  if ( status != EINVAL )
     
    4343  assert( !status );
    4444
    45   puts( "Init: pthread_condattr_destroy - EINVAL" );
     45  puts( "Init: pthread_condattr_destroy - EINVAL (attribute invalid)" );
    4646  status = pthread_condattr_destroy( NULL );
    4747  if ( status != EINVAL )
     
    6565    printf( "status = %d\n", status );
    6666  assert( status == EINVAL );
    67   puts( "Init: pthread_condattr_setpshared - EINVAL - attr" );
     67  puts( "Init: pthread_condattr_setpshared - EINVAL (attribute invalid)" );
    6868
    6969  status = pthread_condattr_setpshared( &attr, 0xFFFFFF );
     
    7171    printf( "status = %d\n", status );
    7272  assert( status == EINVAL );
    73   puts( "Init: pthread_condattr_setpshared - EINVAL - pshared" );
     73  puts( "Init: pthread_condattr_setpshared - EINVAL (pshared invalid)" );
    7474
    7575  status = pthread_condattr_getpshared( &attr, &pshared );
     
    8181    printf( "status = %d\n", status );
    8282  assert( status == EINVAL );
    83   puts( "Init: pthread_condattr_getpshared - EINVAL" );
     83  puts( "Init: pthread_condattr_getpshared - EINVAL (attribute invalid)" );
    8484
    8585  puts( "Init: pthread_cond_init - NULL attr" );
     
    8787  assert( !status );
    8888
     89/* error for attribute not initialized */
     90
     91  status = pthread_cond_init( &cond, &attr_error );
     92  if ( status != EINVAL )
     93    printf( "status = %d\n", status );
     94  assert( status == EINVAL );
     95  puts( "Init: pthread_cond_init - EINVAL (attr not initialized)" );
     96
     97  status = pthread_cond_init( &cond, NULL );
     98  if ( status != ENOMEM )
     99    printf( "status = %d\n", status );
     100  assert( status == ENOMEM );
     101  puts( "Init: pthread_cond_init - ENOMEM (too many conds)" );
     102
    89103  puts( "Init: pthread_cond_destroy" );
    90104  status = pthread_cond_destroy( &cond );
    91105  assert( !status );
    92106
     107/* error for bad condition variable passed */
     108
     109  status = pthread_cond_destroy( NULL );
     110  if ( status != EINVAL )
     111    printf( "status = %d\n", status );
     112  assert( status == EINVAL );
     113  puts( "Init: pthread_cond_destroy - EINVAL (cond invalid)" );
     114
    93115/* initiailize the attribute for the rest of the test */
    94116
     
    109131  sleep( 1 );
    110132
     133  status = pthread_cond_destroy( &Cond1_id );
     134  if ( status != EBUSY )
     135    printf( "status = %d\n", status );
     136  assert( status == EBUSY );
     137  puts( "Init: pthread_cond_destroy - EBUSY (task1 waiting)" );
     138
    111139  puts( "Init: pthread_cond_signal" );
    112140  status = pthread_cond_signal( &Cond1_id );
     
    146174    printf( "status = %d\n", status );
    147175  assert( status == ETIMEDOUT );
    148 
    149   puts( "Init: timedout on pthread_cond_timedwait release mutex" );
    150   /* exit this thread */
     176  puts( "Init: pthread_cond_timedwait - ETIMEDOUT - (mutex not acquired)" );
     177
     178/* remaining error messages */
     179
     180  empty_line();
     181
     182/* errors for bad variable passed */
     183
     184  status = pthread_cond_signal( NULL );
     185  if ( status != EINVAL )
     186    printf( "status = %d\n", status );
     187  assert( status == EINVAL );
     188  puts( "Init: pthread_cond_signal - EINVAL (cond invalid)" );
     189
     190  status = pthread_cond_broadcast( NULL );
     191  if ( status != EINVAL )
     192    printf( "status = %d\n", status );
     193  assert( status == EINVAL );
     194  puts( "Init: pthread_cond_broadcast - EINVAL (cond invalid)" );
     195
     196/* acquire mutex so errors will occur */
     197
     198  status = pthread_mutex_lock( &Mutex_id );
     199  assert( !status );
     200
     201  status = pthread_cond_wait( NULL, &Mutex_id );
     202  if ( status != EINVAL )
     203    printf( "status = %d\n", status );
     204  assert( status == EINVAL );
     205  puts( "Init: pthread_cond_wait - EINVAL (cond invalid)" );
     206
     207  status = pthread_cond_timedwait( NULL, &Mutex_id, &timeout );
     208  if ( status != EINVAL )
     209    printf( "status = %d\n", status );
     210  assert( status == EINVAL );
     211  puts( "Init: pthread_cond_timedwait - EINVAL (cond invalid)" );
     212
     213  status = pthread_cond_wait( &Cond1_id, NULL );
     214  if ( status != EINVAL )
     215    printf( "status = %d\n", status );
     216  assert( status == EINVAL );
     217  puts( "Init: pthread_cond_wait - EINVAL (mutex invalid)" );
     218 
     219  status = pthread_cond_timedwait( &Cond1_id, NULL, &timeout );
     220  if ( status != EINVAL )
     221    printf( "status = %d\n", status );
     222  assert( status == EINVAL );
     223  puts( "Init: pthread_cond_timedwait - EINVAL (mutex invalid)" );
     224
     225  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, NULL );
     226  if ( status != EINVAL )
     227    printf( "status = %d\n", status );
     228  assert( status == EINVAL );
     229  puts( "Init: pthread_cond_timedwait - EINVAL (abstime NULL)" );
     230
     231  timeout.tv_sec = -1;
     232  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     233  if ( status != EINVAL )
     234    printf( "status = %d\n", status );
     235  assert( status == EINVAL );
     236  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_sec invalid)" );
     237
     238  timeout.tv_sec = 2;
     239  timeout.tv_nsec = -1;
     240  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     241  if ( status != EINVAL )
     242    printf( "status = %d\n", status );
     243  assert( status == EINVAL );
     244  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec invalid)" );
     245
     246  timeout.tv_sec = 2;
     247  timeout.tv_nsec = 2;
     248  timeout.tv_nsec = 0x7FFFFFFF;
     249  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     250  if ( status != EINVAL )
     251    printf( "status = %d\n", status );
     252  assert( status == EINVAL );
     253  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec to large)" );
     254
     255/* unlock mutex for rest of test */
     256
     257  status = pthread_mutex_unlock( &Mutex_id );
     258  assert( !status );
     259
     260/* wait and timedwait without mutex */
     261
     262  status = pthread_cond_wait( &Cond1_id, &Mutex_id );
     263  if ( status != EINVAL )
     264    printf( "status = %d\n", status );
     265  assert( status == EINVAL );
     266  puts( "Init: pthread_cond_wait - EINVAL (mutex not locked before call)" );
     267
     268  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     269  if ( status != EINVAL )
     270    printf( "status = %d\n", status );
     271  assert( status == EINVAL );
     272  puts( "Init: pthread_cond_timedwait - EINVAL (mutex not locked before call)");
     273
     274  empty_line();
     275
     276  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
     277  assert( !status );
     278
     279/* switch to task3 to allow it to wait for broadcast signal */
     280
     281  puts( "Init: sleep - switch to Task_3" );
     282  sleep( 1 );
     283
     284/* destroy the mutex so Task3 can not acguire at the end of Wait_support */
     285
     286  status = pthread_mutex_destroy( &Mutex_id );
     287  assert( !status );
     288
     289/* signal a condition variable to task3 */
     290
     291  puts( "Init: pthread_cond_signal" );
     292  status = pthread_cond_signal( &Cond1_id );
     293
     294  puts( "Init: sleep - switch to Task_3" );
     295  sleep( 1 );
    151296
    152297  puts( "*** END OF POSIX TEST 5 ***" );
  • testsuites/psxtests/psx10/init.c

    r645fc954 r520949bf  
    2121{
    2222  int                 status;
    23   pthread_t           thread_id;
    2423  pthread_condattr_t  attr;
     24  pthread_condattr_t  attr_error;
    2525  int                 pshared;
    2626  pthread_cond_t      cond;
     
    3333  assert( !status );
    3434
    35   puts( "Init: pthread_condattr_init - EINVAL" );
     35  puts( "Init: pthread_condattr_init - EINVAL (attribute invalid)" );
    3636  status = pthread_condattr_init( NULL );
    3737  if ( status != EINVAL )
     
    4343  assert( !status );
    4444
    45   puts( "Init: pthread_condattr_destroy - EINVAL" );
     45  puts( "Init: pthread_condattr_destroy - EINVAL (attribute invalid)" );
    4646  status = pthread_condattr_destroy( NULL );
    4747  if ( status != EINVAL )
     
    6565    printf( "status = %d\n", status );
    6666  assert( status == EINVAL );
    67   puts( "Init: pthread_condattr_setpshared - EINVAL - attr" );
     67  puts( "Init: pthread_condattr_setpshared - EINVAL (attribute invalid)" );
    6868
    6969  status = pthread_condattr_setpshared( &attr, 0xFFFFFF );
     
    7171    printf( "status = %d\n", status );
    7272  assert( status == EINVAL );
    73   puts( "Init: pthread_condattr_setpshared - EINVAL - pshared" );
     73  puts( "Init: pthread_condattr_setpshared - EINVAL (pshared invalid)" );
    7474
    7575  status = pthread_condattr_getpshared( &attr, &pshared );
     
    8181    printf( "status = %d\n", status );
    8282  assert( status == EINVAL );
    83   puts( "Init: pthread_condattr_getpshared - EINVAL" );
     83  puts( "Init: pthread_condattr_getpshared - EINVAL (attribute invalid)" );
    8484
    8585  puts( "Init: pthread_cond_init - NULL attr" );
     
    8787  assert( !status );
    8888
     89/* error for attribute not initialized */
     90
     91  status = pthread_cond_init( &cond, &attr_error );
     92  if ( status != EINVAL )
     93    printf( "status = %d\n", status );
     94  assert( status == EINVAL );
     95  puts( "Init: pthread_cond_init - EINVAL (attr not initialized)" );
     96
     97  status = pthread_cond_init( &cond, NULL );
     98  if ( status != ENOMEM )
     99    printf( "status = %d\n", status );
     100  assert( status == ENOMEM );
     101  puts( "Init: pthread_cond_init - ENOMEM (too many conds)" );
     102
    89103  puts( "Init: pthread_cond_destroy" );
    90104  status = pthread_cond_destroy( &cond );
    91105  assert( !status );
    92106
     107/* error for bad condition variable passed */
     108
     109  status = pthread_cond_destroy( NULL );
     110  if ( status != EINVAL )
     111    printf( "status = %d\n", status );
     112  assert( status == EINVAL );
     113  puts( "Init: pthread_cond_destroy - EINVAL (cond invalid)" );
     114
    93115/* initiailize the attribute for the rest of the test */
    94116
     
    109131  sleep( 1 );
    110132
     133  status = pthread_cond_destroy( &Cond1_id );
     134  if ( status != EBUSY )
     135    printf( "status = %d\n", status );
     136  assert( status == EBUSY );
     137  puts( "Init: pthread_cond_destroy - EBUSY (task1 waiting)" );
     138
    111139  puts( "Init: pthread_cond_signal" );
    112140  status = pthread_cond_signal( &Cond1_id );
     
    146174    printf( "status = %d\n", status );
    147175  assert( status == ETIMEDOUT );
    148 
    149   puts( "Init: timedout on pthread_cond_timedwait release mutex" );
    150   /* exit this thread */
     176  puts( "Init: pthread_cond_timedwait - ETIMEDOUT - (mutex not acquired)" );
     177
     178/* remaining error messages */
     179
     180  empty_line();
     181
     182/* errors for bad variable passed */
     183
     184  status = pthread_cond_signal( NULL );
     185  if ( status != EINVAL )
     186    printf( "status = %d\n", status );
     187  assert( status == EINVAL );
     188  puts( "Init: pthread_cond_signal - EINVAL (cond invalid)" );
     189
     190  status = pthread_cond_broadcast( NULL );
     191  if ( status != EINVAL )
     192    printf( "status = %d\n", status );
     193  assert( status == EINVAL );
     194  puts( "Init: pthread_cond_broadcast - EINVAL (cond invalid)" );
     195
     196/* acquire mutex so errors will occur */
     197
     198  status = pthread_mutex_lock( &Mutex_id );
     199  assert( !status );
     200
     201  status = pthread_cond_wait( NULL, &Mutex_id );
     202  if ( status != EINVAL )
     203    printf( "status = %d\n", status );
     204  assert( status == EINVAL );
     205  puts( "Init: pthread_cond_wait - EINVAL (cond invalid)" );
     206
     207  status = pthread_cond_timedwait( NULL, &Mutex_id, &timeout );
     208  if ( status != EINVAL )
     209    printf( "status = %d\n", status );
     210  assert( status == EINVAL );
     211  puts( "Init: pthread_cond_timedwait - EINVAL (cond invalid)" );
     212
     213  status = pthread_cond_wait( &Cond1_id, NULL );
     214  if ( status != EINVAL )
     215    printf( "status = %d\n", status );
     216  assert( status == EINVAL );
     217  puts( "Init: pthread_cond_wait - EINVAL (mutex invalid)" );
     218 
     219  status = pthread_cond_timedwait( &Cond1_id, NULL, &timeout );
     220  if ( status != EINVAL )
     221    printf( "status = %d\n", status );
     222  assert( status == EINVAL );
     223  puts( "Init: pthread_cond_timedwait - EINVAL (mutex invalid)" );
     224
     225  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, NULL );
     226  if ( status != EINVAL )
     227    printf( "status = %d\n", status );
     228  assert( status == EINVAL );
     229  puts( "Init: pthread_cond_timedwait - EINVAL (abstime NULL)" );
     230
     231  timeout.tv_sec = -1;
     232  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     233  if ( status != EINVAL )
     234    printf( "status = %d\n", status );
     235  assert( status == EINVAL );
     236  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_sec invalid)" );
     237
     238  timeout.tv_sec = 2;
     239  timeout.tv_nsec = -1;
     240  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     241  if ( status != EINVAL )
     242    printf( "status = %d\n", status );
     243  assert( status == EINVAL );
     244  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec invalid)" );
     245
     246  timeout.tv_sec = 2;
     247  timeout.tv_nsec = 2;
     248  timeout.tv_nsec = 0x7FFFFFFF;
     249  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     250  if ( status != EINVAL )
     251    printf( "status = %d\n", status );
     252  assert( status == EINVAL );
     253  puts( "Init: pthread_cond_timedwait - EINVAL (abstime->tv_nsec to large)" );
     254
     255/* unlock mutex for rest of test */
     256
     257  status = pthread_mutex_unlock( &Mutex_id );
     258  assert( !status );
     259
     260/* wait and timedwait without mutex */
     261
     262  status = pthread_cond_wait( &Cond1_id, &Mutex_id );
     263  if ( status != EINVAL )
     264    printf( "status = %d\n", status );
     265  assert( status == EINVAL );
     266  puts( "Init: pthread_cond_wait - EINVAL (mutex not locked before call)" );
     267
     268  status = pthread_cond_timedwait( &Cond1_id, &Mutex_id, &timeout );
     269  if ( status != EINVAL )
     270    printf( "status = %d\n", status );
     271  assert( status == EINVAL );
     272  puts( "Init: pthread_cond_timedwait - EINVAL (mutex not locked before call)");
     273
     274  empty_line();
     275
     276  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
     277  assert( !status );
     278
     279/* switch to task3 to allow it to wait for broadcast signal */
     280
     281  puts( "Init: sleep - switch to Task_3" );
     282  sleep( 1 );
     283
     284/* destroy the mutex so Task3 can not acguire at the end of Wait_support */
     285
     286  status = pthread_mutex_destroy( &Mutex_id );
     287  assert( !status );
     288
     289/* signal a condition variable to task3 */
     290
     291  puts( "Init: pthread_cond_signal" );
     292  status = pthread_cond_signal( &Cond1_id );
     293
     294  puts( "Init: sleep - switch to Task_3" );
     295  sleep( 1 );
    151296
    152297  puts( "*** END OF POSIX TEST 5 ***" );
Note: See TracChangeset for help on using the changeset viewer.