source: rtems/testsuites/psxtests/psx04/init.c @ e4cc4176

4.104.114.84.95
Last change on this file since e4cc4176 was e4cc4176, checked in by Mark Johannes <Mark.Johannes@…>, on 08/23/96 at 15:58:24

Changed all EFAULTS to EINVALs

  • Property mode set to 100644
File size: 14.2 KB
RevLine 
[1094754f]1/*
2 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
3 *  On-Line Applications Research Corporation (OAR).
4 *  All rights assigned to U.S. Government, 1994.
5 *
6 *  This material may be reproduced by or for the U.S. Government pursuant
7 *  to the copyright license under the clause at DFARS 252.227-7013.  This
8 *  notice must appear in all copies of this file and its derivatives.
9 *
10 *  $Id$
11 */
12
13#define CONFIGURE_INIT
14#include "system.h"
15#include <signal.h>
[7fb19bb]16#include <errno.h>
[1094754f]17
18volatile int Signal_occurred;
19volatile int Signal_count;
20
21void Signal_handler(
22  int signo
23)
24{
25  Signal_count++;
26  printf(
27    "Signal: %d caught by 0x%x (%d)\n",
28    signo,
29    pthread_self(),
30    Signal_count
31  );
32  Signal_occurred = 1;
33}
34
[481d8f8]35void Signal_info_handler(
36  int        signo,
37  siginfo_t *info,
38  void      *context
39)
40{
41  Signal_count++;
42  printf(
43    "Signal_info: %d caught by 0x%x (%d) si_signo= %d si_code= %d value= %d\n",
44    signo,
45    pthread_self(),
46    Signal_count,
47    info->si_signo,
48    info->si_code,
49    info->si_value.sival_int
50  );
51  Signal_occurred = 1;
52}
53
[1094754f]54void *POSIX_Init(
55  void *argument
56)
57{
58  int               status;
59  struct sigaction  act;
60  sigset_t          mask;
61  sigset_t          pending_set;
[481d8f8]62  sigset_t          oset;
[7fb19bb]63  struct timespec   timeout;
64  siginfo_t         info;
[1094754f]65
66  puts( "\n\n*** POSIX TEST 4 ***" );
67
68  /* set the time of day, and print our buffer in multiple ways */
69
70  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
71
72  /* get id of this thread */
73
74  Init_id = pthread_self();
75  printf( "Init's ID is 0x%08x\n", Init_id );
76
[481d8f8]77/* install a signal handler for SIGUSR1 */
[1094754f]78
79  status = sigemptyset( &act.sa_mask );
80  assert( !status );
[481d8f8]81  printf( "Init: sigemptyset -  set= 0x%08x\n", act.sa_mask );
82
83  /* test sigfillset following the above sigemptyset */
84
85  status = sigfillset( &act.sa_mask );
86  assert( !status );
87  printf( "Init: sigfillset -  set= 0x%08x\n", act.sa_mask );
88
89  /* test sigdelset */
90
91  status = sigdelset( &act.sa_mask, SIGUSR1 );
92  assert( !status );
93  printf( "Init: sigdelset - delete SIGUSR1 set= 0x%08x\n", act.sa_mask );
94
95  /* test sigismember - FALSE */
96
97  status = sigismember( &act.sa_mask, SIGUSR1 );
98  assert( !status );
99  puts( "Init: sigismember - FALSE since SIGUSR1 is not a member" );
100
101  /* test sigismember - TRUE */
102
103  status = sigismember( &act.sa_mask, SIGUSR2 );
104  assert( status );
105  puts( "Init: sigismember - TRUE since SIGUSR2 is a member" );
106
107  /* return the set to empty */
[1094754f]108
109  act.sa_handler = Signal_handler;
110  act.sa_flags   = 0;
111 
112  sigaction( SIGUSR1, &act, NULL );
113
114  /* simple signal to process */
115
116  Signal_count = 0;
117  Signal_occurred = 0;
118
[7fb19bb]119  puts( "Init: send SIGUSR1 to process" );
[1094754f]120  status = kill( getpid(), SIGUSR1 );
121  assert( !status );
122
[481d8f8]123/* end of install a signal handler for SIGUSR1 */
124
125  Signal_occurred = 0;
126
127  /* now block the signal, send it, see if it is pending, and unblock it */
128
129  empty_line();
130
131  status = sigemptyset( &mask );
132  assert( !status );
133
134  status = sigaddset( &mask, SIGUSR1 );
135  assert( !status );
136
[7fb19bb]137  puts( "Init: Block SIGUSR1" );
[481d8f8]138  act.sa_handler = Signal_handler;
139  act.sa_flags   = 0;
140 
141  sigaction( SIGUSR1, &act, NULL );
142
143  /* simple signal to process */
144
145  Signal_count = 0;
146  Signal_occurred = 0;
147
[7fb19bb]148  puts( "Init: send SIGUSR1 to process" );
[481d8f8]149  status = kill( getpid(), SIGUSR1 );
150  assert( !status );
151
[1094754f]152  Signal_occurred = 0;
153
154  /* now block the signal, send it, see if it is pending, and unblock it */
155
[ce0f7d95]156  empty_line();
157
[1094754f]158  status = sigemptyset( &mask );
159  assert( !status );
160
161  status = sigaddset( &mask, SIGUSR1 );
162  assert( !status );
163
[7fb19bb]164  puts( "Init: Block SIGUSR1" );
[1094754f]165  status = sigprocmask( SIG_BLOCK, &mask, NULL );
166  assert( !status );
167
168  status = sigpending( &pending_set );
169  assert( !status );
170  printf( "Init: Signals pending 0x%08x\n", pending_set );
171 
[7fb19bb]172  puts( "Init: send SIGUSR1 to process" );
[1094754f]173  status = kill( getpid(), SIGUSR1 );
174  assert( !status );
175
176  status = sigpending( &pending_set );
177  assert( !status );
178  printf( "Init: Signals pending 0x%08x\n", pending_set );
179 
[7fb19bb]180  puts( "Init: Unblock SIGUSR1" );
[1094754f]181  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
182  assert( !status );
183
[ce0f7d95]184  /* now let another task get interrupted by a signal */
[1094754f]185
[ce0f7d95]186  empty_line();
[1094754f]187
[7fb19bb]188  puts( "Init: create a thread interested in SIGUSR1" );
[481d8f8]189  status = pthread_create( &Task1_id, NULL, Task_1, NULL );
[1094754f]190  assert( !status );
191
[7fb19bb]192  puts( "Init: Block SIGUSR1" );
[ce0f7d95]193  status = sigprocmask( SIG_BLOCK, &mask, NULL );
194  assert( !status );
195 
196  status = sigpending( &pending_set );
197  assert( !status );
198  printf( "Init: Signals pending 0x%08x\n", pending_set );
[1094754f]199
[7fb19bb]200  puts( "Init: sleep so the other task can block" );
[ce0f7d95]201  status = sleep( 1 );
202  assert( !status );
203
204     /* switch to task 1 */
205
[7fb19bb]206  puts( "Init: send SIGUSR1 to process" );
[ce0f7d95]207  status = kill( getpid(), SIGUSR1 );
208  assert( !status );
[1094754f]209 
[ce0f7d95]210  status = sigpending( &pending_set );
211  assert( !status );
212  printf( "Init: Signals pending 0x%08x\n", pending_set );
213
[7fb19bb]214  puts( "Init: sleep so the other task can catch signal" );
[ce0f7d95]215  status = sleep( 1 );
216  assert( !status );
[1094754f]217
[ce0f7d95]218     /* switch to task 1 */
[1094754f]219
[ce0f7d95]220  /* test alarm */
221
222  empty_line();
223
224  /* install a signal handler for SIGALRM and unblock it */
225 
226  status = sigemptyset( &act.sa_mask );
227  assert( !status );
228 
229  act.sa_handler = Signal_handler;
230  act.sa_flags   = 0;
231 
232  sigaction( SIGALRM, &act, NULL );
233 
234  status = sigemptyset( &mask );
235  assert( !status );
236 
237  status = sigaddset( &mask, SIGALRM );
238  assert( !status );
239 
[7fb19bb]240  puts( "Init: Unblock SIGALRM" );
[ce0f7d95]241  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
242  assert( !status );
243
244  /* schedule the alarm */
245 
[7fb19bb]246  puts( "Init: Firing alarm in 5 seconds" );
[ce0f7d95]247  status = alarm( 5 );
248  printf( "Init: %d seconds left on previous alarm\n", status );
249  assert( !status );
[1094754f]250
[7fb19bb]251  puts( "Init: Firing alarm in 2 seconds" );
[ce0f7d95]252  status = alarm( 2 );
253  printf( "Init: %d seconds left on previous alarm\n", status );
254  assert( status );
[1094754f]255
[7fb19bb]256  puts( "Init: Wait 4 seconds for alarm" );
[ce0f7d95]257  status = sleep( 4 );
258  printf( "Init: %d seconds left in sleep\n", status );
259  assert( status );
[1094754f]260
[481d8f8]261  /* test SIG_SETMASK case and returning oset of pthread_sigmask */
262
263  empty_line();
264
265  status = sigemptyset( &mask );
266  assert( !status );
267 
268  status = sigaddset( &mask, SIGUSR1 );
269  assert( !status );
270
271  status = sigaddset( &mask, SIGUSR2 );
272  assert( !status );
273
[7fb19bb]274  puts( "Init: Block SIGUSR1 and SIGUSR2 only" );
[481d8f8]275  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
276  printf( "Init: Previous blocked set was 0x%08x\n", oset );
277  assert( !status );
278
279  /* test inquiry about current blocked set with pthread_sigmask */
280 
[7fb19bb]281  status = pthread_sigmask( 0, NULL, &oset );
[481d8f8]282  printf( "Init: Current blocked set is 0x%08x\n", oset );
283  assert( !status );
284
285  /* return blocked mask to no signals blocked */
286
287  status = sigemptyset( &mask );
288  assert( !status );
289 
[7fb19bb]290  puts( "Init: Unblock all signals" );
[481d8f8]291  status = pthread_sigmask( SIG_SETMASK, &mask, &oset );
292  printf( "Init: Previous blocked set was 0x%08x\n", oset );
293  assert( !status );
294
295  /* test sigsuspend */
296
297  empty_line();
298
[7fb19bb]299  puts( "Init: create a thread to send Init SIGUSR1" );
[481d8f8]300  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
301  assert( !status );
302
303  status = sigemptyset( &mask );
304  assert( !status );
305 
[7fb19bb]306  puts( "Init: sigsuspend for any signal" );
[481d8f8]307  status = sigsuspend( &mask );
308  assert( status );
309  printf( "Init: awakended from sigsuspend status=%08d \n", status );
310
311  /* test a SIGINFO case, these are signals sent to a process only */
312
313  empty_line();
314
[7fb19bb]315  puts( "Init: create a thread to sent Process SIGUSR1 with SA_SIGINFO" );
[481d8f8]316  status = pthread_create( &Task3_id, NULL, Task_3, NULL );
317  assert( !status );
318
319  /* set action on SIGUSR1 to an info case */
320  act.sa_handler   = Signal_handler;
321  act.sa_flags     = SA_SIGINFO;
322  act.sa_sigaction = Signal_info_handler;
323 
324  sigaction( SIGUSR1, &act, NULL );
325
[7fb19bb]326  puts( "Init: sleep so the Task_3 can sigqueue SIGUSR1" );
[481d8f8]327  status = sleep( 1 );
328  assert( !status );
329
330     /* switch to task 1 */
331
332  puts( "Init: sigqueue occurred" );
333
334  /* Send SIGUSR1, Task_3 has issued a sigwaitinfo */
335
336  status = sigemptyset( &mask );
337  assert( !status );
338
339  status = sigaddset( &mask, SIGUSR1 );
340  assert( !status );
341
[7fb19bb]342  puts( "Init: Block SIGUSR1" );
[481d8f8]343  status = sigprocmask( SIG_BLOCK, &mask, NULL );
344  assert( !status );
345
[7fb19bb]346  puts( "Init: send SIGUSR1 to process" );
[481d8f8]347  status = kill( getpid(), SIGUSR1 );
348  assert( !status );
349
[7fb19bb]350  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
[481d8f8]351  status = sleep( 1 );
352  assert( !status );
353
354  /* Send SIGUSR1, Task_3 has issued a sigwait */
355 
356  status = sigemptyset( &mask );
357  assert( !status );
358 
359  status = sigaddset( &mask, SIGUSR1 );
360  assert( !status );
361 
[7fb19bb]362  puts( "Init: Block SIGUSR1" );
[481d8f8]363  status = sigprocmask( SIG_BLOCK, &mask, NULL );
364  assert( !status );
365 
[7fb19bb]366  puts( "Init: send SIGUSR1 to process" );
[481d8f8]367  status = kill( getpid(), SIGUSR1 );
368  assert( !status );
369 
[7fb19bb]370  puts( "Init: sleep so the Task_3 can receive SIGUSR1" );
[481d8f8]371  status = sleep( 1 );
372  assert( !status );
373
374  /* Send SIGUSR1, Task_3 has issued a sigwaitinfo */
375 
376  status = sigemptyset( &mask );
377  assert( !status );
378 
379  status = sigaddset( &mask, SIGUSR2 );
380  assert( !status );
381 
[7fb19bb]382  puts( "Init: Block SIGUSR2" );
[481d8f8]383  status = sigprocmask( SIG_BLOCK, &mask, NULL );
384  assert( !status );
385 
[7fb19bb]386  puts( "Init: send SIGUSR2 to process" );
[481d8f8]387  status = kill( getpid(), SIGUSR2 );
388  assert( !status );
389 
[7fb19bb]390  puts( "Init: sleep so the Task_3 can receive SIGUSR2" );
[481d8f8]391  status = sleep( 1 );
392  assert( !status );
393
394  /* Suspend for signal that has already be sent */
395
[7fb19bb]396  puts( "Init: sigsuspend for any signal" );
[481d8f8]397  status = sigsuspend( &mask );
398  assert( status );
399  printf( "Init: awakended from sigsuspend status=%d \n", status );
400
[7fb19bb]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 );
[e4cc4176]408  assert( errno == EINVAL );
409  puts( "Init: sigemptyset - EINVAL (set invalid)" );
[7fb19bb]410
411  status = sigfillset( NULL );
412  if ( status != -1 )
413    printf( "status = %d\n", status );
[e4cc4176]414  assert( errno == EINVAL );
415  puts( "Init: sigfillset - EINVAL (set invalid)" );
[7fb19bb]416
417  status = sigaddset( NULL, SIGUSR1 );
418  if ( status != -1 )
419    printf( "status = %d\n", status );
[e4cc4176]420  assert( errno == EINVAL );
421  puts( "Init: sigaddset - EINVAL (set invalid)" );
[7fb19bb]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 );
[e4cc4176]436  assert( errno == EINVAL );
437  puts( "Init: sigdelset - EINVAL (set invalid)" );
[7fb19bb]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 );
[e4cc4176]452  assert( errno == EINVAL );
453  puts( "Init: sigismember - EINVAL (set invalid)" );
[7fb19bb]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 );
[e4cc4176]484  assert( errno == EINVAL );
485  puts( "Init: pthread_sigmask - EINVAL (set and oset invalid)" );
[7fb19bb]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 );
[e4cc4176]496  assert( errno == EINVAL );
497  puts( "Init: sigpending - EINVAL (set invalid)" );
[7fb19bb]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
[e4cc4176]552  status = kill( getpid(), 999 );
553  if ( status != -1 )
554    printf( "status = %d\n", status );
555  assert( errno == EINVAL );
556  puts( "Init: kill - EINVAL (sig invalid)" );
557
[1094754f]558  /* exit this thread */
559
560  puts( "*** END OF POSIX TEST 4 ***" );
561  exit( 0 );
562
563  return NULL; /* just so the compiler thinks we returned something */
564}
Note: See TracBrowser for help on using the repository browser.