Changeset 7fb19bb in rtems for testsuites/psxtests/psx04


Ignore:
Timestamp:
Aug 15, 1996, 7:27:08 PM (24 years ago)
Author:
Mark Johannes <Mark.Johannes@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
9ac3e76
Parents:
851b18d
Message:

init: added tests for pthread_kill and kill errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psx04/init.c

    r851b18d r7fb19bb  
    1414#include "system.h"
    1515#include <signal.h>
     16#include <errno.h>
    1617
    1718volatile int Signal_occurred;
     
    6061  sigset_t          pending_set;
    6162  sigset_t          oset;
     63  struct timespec   timeout;
     64  siginfo_t         info;
    6265
    6366  puts( "\n\n*** POSIX TEST 4 ***" );
     
    114117  Signal_occurred = 0;
    115118
    116   printf( "Init: send SIGUSR1 to process\n" );
     119  puts( "Init: send SIGUSR1 to process" );
    117120  status = kill( getpid(), SIGUSR1 );
    118121  assert( !status );
     
    132135  assert( !status );
    133136
    134   printf( "Init: Block SIGUSR1\n" );
     137  puts( "Init: Block SIGUSR1" );
    135138  act.sa_handler = Signal_handler;
    136139  act.sa_flags   = 0;
     
    143146  Signal_occurred = 0;
    144147
    145   printf( "Init: send SIGUSR1 to process\n" );
     148  puts( "Init: send SIGUSR1 to process" );
    146149  status = kill( getpid(), SIGUSR1 );
    147150  assert( !status );
     
    159162  assert( !status );
    160163
    161   printf( "Init: Block SIGUSR1\n" );
     164  puts( "Init: Block SIGUSR1" );
    162165  status = sigprocmask( SIG_BLOCK, &mask, NULL );
    163166  assert( !status );
     
    167170  printf( "Init: Signals pending 0x%08x\n", pending_set );
    168171 
    169   printf( "Init: send SIGUSR1 to process\n" );
     172  puts( "Init: send SIGUSR1 to process" );
    170173  status = kill( getpid(), SIGUSR1 );
    171174  assert( !status );
     
    175178  printf( "Init: Signals pending 0x%08x\n", pending_set );
    176179 
    177   printf( "Init: Unblock SIGUSR1\n" );
     180  puts( "Init: Unblock SIGUSR1" );
    178181  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
    179182  assert( !status );
     
    183186  empty_line();
    184187
    185   printf( "Init: create a thread interested in SIGUSR1\n" );
     188  puts( "Init: create a thread interested in SIGUSR1" );
    186189  status = pthread_create( &Task1_id, NULL, Task_1, NULL );
    187190  assert( !status );
    188191
    189   printf( "Init: Block SIGUSR1\n" );
     192  puts( "Init: Block SIGUSR1" );
    190193  status = sigprocmask( SIG_BLOCK, &mask, NULL );
    191194  assert( !status );
     
    195198  printf( "Init: Signals pending 0x%08x\n", pending_set );
    196199
    197   printf( "Init: sleep so the other task can block\n" );
     200  puts( "Init: sleep so the other task can block" );
    198201  status = sleep( 1 );
    199202  assert( !status );
     
    201204     /* switch to task 1 */
    202205
    203   printf( "Init: send SIGUSR1 to process\n" );
     206  puts( "Init: send SIGUSR1 to process" );
    204207  status = kill( getpid(), SIGUSR1 );
    205208  assert( !status );
     
    209212  printf( "Init: Signals pending 0x%08x\n", pending_set );
    210213
    211   printf( "Init: sleep so the other task can catch signal\n" );
     214  puts( "Init: sleep so the other task can catch signal" );
    212215  status = sleep( 1 );
    213216  assert( !status );
     
    235238  assert( !status );
    236239 
    237   printf( "Init: Unblock SIGALRM\n" );
     240  puts( "Init: Unblock SIGALRM" );
    238241  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
    239242  assert( !status );
     
    241244  /* schedule the alarm */
    242245 
    243   printf( "Init: Firing alarm in 5 seconds\n" );
     246  puts( "Init: Firing alarm in 5 seconds" );
    244247  status = alarm( 5 );
    245248  printf( "Init: %d seconds left on previous alarm\n", status );
    246249  assert( !status );
    247250
    248   printf( "Init: Firing alarm in 2 seconds\n" );
     251  puts( "Init: Firing alarm in 2 seconds" );
    249252  status = alarm( 2 );
    250253  printf( "Init: %d seconds left on previous alarm\n", status );
    251254  assert( status );
    252255
    253   printf( "Init: Wait 4 seconds for alarm\n" );
     256  puts( "Init: Wait 4 seconds for alarm" );
    254257  status = sleep( 4 );
    255258  printf( "Init: %d seconds left in sleep\n", status );
     
    269272  assert( !status );
    270273
    271   printf( "Init: Block SIGUSR1 and SIGUSR2 only\n" );
     274  puts( "Init: Block SIGUSR1 and SIGUSR2 only" );
    272275  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
    273276  printf( "Init: Previous blocked set was 0x%08x\n", oset );
     
    276279  /* test inquiry about current blocked set with pthread_sigmask */
    277280 
    278   status = pthread_sigmask( NULL, NULL, &oset );
     281  status = pthread_sigmask( 0, NULL, &oset );
    279282  printf( "Init: Current blocked set is 0x%08x\n", oset );
    280283  assert( !status );
     
    285288  assert( !status );
    286289 
    287   printf( "Init: Unblock all signals\n" );
     290  puts( "Init: Unblock all signals" );
    288291  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
    289292  printf( "Init: Previous blocked set was 0x%08x\n", oset );
     
    294297  empty_line();
    295298
    296   printf( "Init: create a thread to send Init SIGUSR1\n" );
     299  puts( "Init: create a thread to send Init SIGUSR1" );
    297300  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
    298301  assert( !status );
     
    301304  assert( !status );
    302305 
    303   printf( "Init: sigsuspend for any signal\n" );
     306  puts( "Init: sigsuspend for any signal" );
    304307  status = sigsuspend( &mask );
    305308  assert( status );
     
    310313  empty_line();
    311314
    312   printf( "Init: create a thread to sent Process SIGUSR1 with SA_SIGINFO\n" );
     315  puts( "Init: create a thread to sent Process SIGUSR1 with SA_SIGINFO" );
    313316  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
    314317  assert( !status );
     
    321324  sigaction( SIGUSR1, &act, NULL );
    322325
    323   printf( "Init: sleep so the Task_3 can sigqueue SIGUSR1\n" );
     326  puts( "Init: sleep so the Task_3 can sigqueue SIGUSR1" );
    324327  status = sleep( 1 );
    325328  assert( !status );
     
    337340  assert( !status );
    338341
    339   printf( "Init: Block SIGUSR1\n" );
     342  puts( "Init: Block SIGUSR1" );
    340343  status = sigprocmask( SIG_BLOCK, &mask, NULL );
    341344  assert( !status );
    342345
    343   printf( "Init: send SIGUSR1 to process\n" );
     346  puts( "Init: send SIGUSR1 to process" );
    344347  status = kill( getpid(), SIGUSR1 );
    345348  assert( !status );
    346349
    347   printf( "Init: sleep so the Task_3 can receive SIGUSR1\n" );
     350  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
    348351  status = sleep( 1 );
    349352  assert( !status );
     
    357360  assert( !status );
    358361 
    359   printf( "Init: Block SIGUSR1\n" );
     362  puts( "Init: Block SIGUSR1" );
    360363  status = sigprocmask( SIG_BLOCK, &mask, NULL );
    361364  assert( !status );
    362365 
    363   printf( "Init: send SIGUSR1 to process\n" );
     366  puts( "Init: send SIGUSR1 to process" );
    364367  status = kill( getpid(), SIGUSR1 );
    365368  assert( !status );
    366369 
    367   printf( "Init: sleep so the Task_3 can receive SIGUSR1\n" );
     370  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
    368371  status = sleep( 1 );
    369372  assert( !status );
     
    377380  assert( !status );
    378381 
    379   printf( "Init: Block SIGUSR2\n" );
     382  puts( "Init: Block SIGUSR2" );
    380383  status = sigprocmask( SIG_BLOCK, &mask, NULL );
    381384  assert( !status );
    382385 
    383   printf( "Init: send SIGUSR2 to process\n" );
     386  puts( "Init: send SIGUSR2 to process" );
    384387  status = kill( getpid(), SIGUSR2 );
    385388  assert( !status );
    386389 
    387   printf( "Init: sleep so the Task_3 can receive SIGUSR2\n" );
     390  puts( "Init: sleep so the Task_3 can receive SIGUSR2" );
    388391  status = sleep( 1 );
    389392  assert( !status );
     
    391394  /* Suspend for signal that has already be sent */
    392395
    393   printf( "Init: sigsuspend for any signal\n" );
     396  puts( "Init: sigsuspend for any signal" );
    394397  status = sigsuspend( &mask );
    395398  assert( status );
    396399  printf( "Init: awakended from sigsuspend status=%d \n", status );
    397400
     401  /* generate error cases for psignal */
     402
     403  empty_line();
     404
     405  status = sigemptyset( NULL );
     406  if ( status != -1 )
     407    printf( "status = %d\n", status );
     408  assert( errno == EFAULT );
     409  puts( "Init: sigemptyset - EFAULT (set invalid)" );
     410
     411  status = sigfillset( NULL );
     412  if ( status != -1 )
     413    printf( "status = %d\n", status );
     414  assert( errno == EFAULT );
     415  puts( "Init: sigfillset - EFAULT (set invalid)" );
     416
     417  status = sigaddset( NULL, SIGUSR1 );
     418  if ( status != -1 )
     419    printf( "status = %d\n", status );
     420  assert( errno == EFAULT );
     421  puts( "Init: sigaddset - EFAULT (set invalid)" );
     422
     423  status = sigaddset( &mask, 0 );
     424  assert( !status );
     425  puts( "Init: sigaddset - SUCCESSFUL (signal = 0)" );
     426
     427  status = sigaddset( &mask, 999 );
     428  if ( status != -1 )
     429    printf( "status = %d\n", status );
     430  assert( errno == EINVAL );
     431  puts( "Init: sigaddset - EINVAL (set invalid)" );
     432
     433  status = sigdelset( NULL, SIGUSR1 );
     434  if ( status != -1 )
     435    printf( "status = %d\n", status );
     436  assert( errno == EFAULT );
     437  puts( "Init: sigdelset - EFAULT (set invalid)" );
     438 
     439  status = sigdelset( &mask, 0 );
     440  assert( !status );
     441  puts( "Init: sigdelset - SUCCESSFUL (signal = 0)" );
     442 
     443  status = sigdelset( &mask, 999 );
     444  if ( status != -1 )
     445    printf( "status = %d\n", status );
     446  assert( errno == EINVAL );
     447  puts( "Init: sigdelset - EINVAL (set invalid)" );
     448
     449  status = sigismember( NULL, SIGUSR1 );
     450  if ( status != -1 )
     451    printf( "status = %d\n", status );
     452  assert( errno == EFAULT );
     453  puts( "Init: sigismember - EFAULT (set invalid)" );
     454 
     455  status = sigismember( &mask, 0 );
     456  assert( !status );
     457  puts( "Init: sigismember - SUCCESSFUL (signal = 0)" );
     458 
     459  status = sigismember( &mask, 999 );
     460  if ( status != -1 )
     461    printf( "status = %d\n", status );
     462  assert( errno == EINVAL );
     463  puts( "Init: sigismember - EINVAL (signal invalid)" );
     464
     465  status = sigaction( 0, &act, 0 );
     466  assert( !status );
     467  puts( "Init: sigaction - SUCCESSFUL (signal = 0)" );
     468 
     469  status = sigaction( 999, &act, NULL );
     470  if ( status != -1 )
     471    printf( "status = %d\n", status );
     472  assert( errno == EINVAL );
     473  puts( "Init: sigaction - EINVAL (signal invalid)" );
     474
     475  status = sigaction( SIGKILL, &act, NULL );
     476  if ( status != -1 )
     477    printf( "status = %d\n", status );
     478  assert( errno == EINVAL );
     479  puts( "Init: sigaction - EINVAL (SIGKILL)" );
     480
     481  status = pthread_sigmask( SIG_BLOCK, NULL, NULL );
     482  if ( status != -1 )
     483    printf( "status = %d\n", status );
     484  assert( errno == EFAULT );
     485  puts( "Init: pthread_sigmask - EFAULT (set and oset invalid)" );
     486
     487  status = pthread_sigmask( 999, &pending_set, NULL );
     488  if ( status != -1 )
     489    printf( "status = %d\n", status );
     490  assert( errno == EINVAL );
     491  puts( "Init: pthread_sigmask - EINVAL (how invalid)" );
     492
     493  status = sigpending( NULL );
     494  if ( status != -1 )
     495    printf( "status = %d\n", status );
     496  assert( errno == EFAULT );
     497  puts( "Init: sigpending - EFAULT (set invalid)" );
     498
     499  timeout.tv_nsec = -1;
     500  status = sigtimedwait( &mask, &info, &timeout );
     501  if ( status != -1 )
     502    printf( "status = %d\n", status );
     503  assert( errno == EINVAL );
     504  puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid < 0)" );
     505
     506  timeout.tv_nsec = 0x7fffffff;
     507  status = sigtimedwait( &mask, &info, &timeout );
     508  if ( status != -1 )
     509    printf( "status = %d\n", status );
     510  assert( errno == EINVAL );
     511  puts( "Init: pthread_sigmask - EINVAL (timout->nsec invalid to large)" );
     512
     513  status = pthread_kill( Init_id, 999 );
     514  if ( status != -1 )
     515    printf( "status = %d\n", status );
     516  assert( errno == EINVAL );
     517  puts( "Init: pthread_kill - EINVAL (sig invalid)" );
     518
     519  status = pthread_kill( 0, SIGUSR1 );
     520  if ( status != -1 )
     521    printf( "status = %d\n", status );
     522  assert( errno == ENOSYS );
     523  puts( "Init: pthread_kill - ENOSYS (signal SA_SIGINFO)" );
     524
     525  status = pthread_kill( 0, SIGUSR2 );
     526  if ( status != -1 )
     527    printf( "status = %d\n", status );
     528  assert( errno == ESRCH );
     529  puts( "Init: pthread_kill - ESRCH (signal SA_SIGINFO)" );
     530
     531  status = pthread_kill( Init_id, 0 );
     532  assert( !status );
     533  puts( "Init: pthread_kill - SUCCESSFUL (signal = 0)" );
     534
     535  act.sa_handler = SIG_IGN;
     536  act.sa_flags = 0;
     537  sigaction( SIGUSR2, &act, NULL );
     538  status = pthread_kill( Init_id, SIGUSR2 );
     539  assert( !status );
     540  puts( "Init: pthread_kill - SUCCESSFUL (signal = SIG_IGN)" );
     541
     542  status = kill( 0x7fffffff, SIGUSR1 );
     543  if ( status != -1 )
     544    printf( "status = %d\n", status );
     545  assert( errno == ESRCH );
     546  puts( "Init: kill - ESRCH (pid invalid)" );
     547
     548  status = kill( getpid(), 0 );
     549  assert( !status );
     550  puts( "Init: kill - SUCCESSFUL (signal = 0)" );
     551
    398552  /* exit this thread */
    399553
Note: See TracChangeset for help on using the changeset viewer.