source: rtems/c/src/tests/psxtests/psx02/init.c @ 699fe08a

4.104.114.84.95
Last change on this file since 699fe08a was 699fe08a, checked in by Joel Sherrill <joel.sherrill@…>, on 06/11/96 at 20:46:13

Added test case which blocks a signal, sees what signals are pending, sends
that same signal to the executing thread, sees what is pending, then unblocks
that signal so the handler can execute.

  • Property mode set to 100644
File size: 2.9 KB
Line 
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>
16
17volatile int Signal_occurred;
18volatile int Signal_count;
19
20void Signal_handler(
21  int signo
22)
23{
24  Signal_count++;
25  printf(
26    "Signal: %d caught by 0x%x (%d)\n",
27    signo,
28    pthread_self(),
29    Signal_count
30  );
31  Signal_occurred = 1;
32}
33
34void *POSIX_Init(
35  void *argument
36)
37{
38  int               status;
39  struct timespec   tv;
40  struct timespec   tr;
41  struct sigaction  act;
42  sigset_t          mask;
43  sigset_t          pending_set;
44
45  puts( "\n\n*** POSIX TEST 2 ***" );
46
47  /* set the time of day, and print our buffer in multiple ways */
48
49  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
50
51  /* get id of this thread */
52
53  Init_id = pthread_self();
54  printf( "Init's ID is 0x%08x\n", Init_id );
55
56  /* install a signal handler */
57
58  status = sigemptyset( &act.sa_mask );
59  assert( !status );
60
61  act.sa_handler = Signal_handler;
62  act.sa_flags   = 0;
63 
64  sigaction( SIGUSR1, &act, NULL );
65
66  /* simple signal to self */
67
68  Signal_count = 0;
69  Signal_occurred = 0;
70
71  status = pthread_kill( Init_id, SIGUSR1 );
72  assert( !status );
73
74  Signal_occurred = 0;
75
76  /* now block the signal, send it, see if it is pending, and unblock it */
77
78  status = sigemptyset( &mask );
79  assert( !status );
80
81  status = sigaddset( &mask, SIGUSR1 );
82  assert( !status );
83
84  printf( "Init: Block SIGUSR1\n" );
85  status = sigprocmask( SIG_BLOCK, &mask, NULL );
86  assert( !status );
87
88  status = sigpending( &pending_set );
89  assert( !status );
90  printf( "Init: Signals pending 0x%08x\n", pending_set );
91 
92 
93  printf( "Init: send SIGUSR1 to self\n" );
94  status = pthread_kill( Init_id, SIGUSR1 );
95  assert( !status );
96
97  status = sigpending( &pending_set );
98  assert( !status );
99  printf( "Init: Signals pending 0x%08x\n", pending_set );
100 
101  printf( "Init: Unblock SIGUSR1\n" );
102  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
103  assert( !status );
104
105  /* create a thread */
106
107  status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
108  assert( !status );
109
110  /*
111   *  Loop for 5 seconds seeing how many signals we catch
112   */
113
114  tr.tv_sec = 5;
115  tr.tv_nsec = 0;
116 
117  do {
118    tv = tr;
119
120    Signal_occurred = 0;
121
122    status = nanosleep ( &tv, &tr );
123    assert( !status );
124
125    printf(
126      "Init: signal was %sprocessed with %d:%d time remaining\n",
127      (Signal_occurred) ? "" : "not ",
128      (int) tr.tv_sec,
129      (int) tr.tv_nsec
130   );
131
132  } while ( tr.tv_sec || tr.tv_nsec );
133
134  /* exit this thread */
135
136  puts( "*** END OF POSIX TEST 2 ***" );
137  exit( 0 );
138
139  return NULL; /* just so the compiler thinks we returned something */
140}
Note: See TracBrowser for help on using the repository browser.