source: rtems/c/src/tests/psxtests/psx04/init.c @ 1094754f

4.104.114.84.95
Last change on this file since 1094754f was 1094754f, checked in by Joel Sherrill <joel.sherrill@…>, on 06/12/96 at 22:52:13

new files

  • Property mode set to 100644
File size: 3.0 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 4 ***" );
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 process */
67
68  Signal_count = 0;
69  Signal_occurred = 0;
70
71  printf( "Init: send SIGUSR1 to process\n" );
72  status = kill( getpid(), SIGUSR1 );
73  assert( !status );
74
75  Signal_occurred = 0;
76
77  /* now block the signal, send it, see if it is pending, and unblock it */
78
79  status = sigemptyset( &mask );
80  assert( !status );
81
82  status = sigaddset( &mask, SIGUSR1 );
83  assert( !status );
84
85  printf( "Init: Block SIGUSR1\n" );
86  status = sigprocmask( SIG_BLOCK, &mask, NULL );
87  assert( !status );
88
89  status = sigpending( &pending_set );
90  assert( !status );
91  printf( "Init: Signals pending 0x%08x\n", pending_set );
92 
93  printf( "Init: send SIGUSR1 to process\n" );
94  status = kill( getpid(), 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  puts( "*** END OF POSIX TEST 4 ***" );
106  exit( 0 );
107
108  /* create a thread */
109
110  status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
111  assert( !status );
112
113  /*
114   *  Loop for 5 seconds seeing how many signals we catch
115   */
116
117  tr.tv_sec = 5;
118  tr.tv_nsec = 0;
119 
120  do {
121    tv = tr;
122
123    Signal_occurred = 0;
124
125    status = nanosleep ( &tv, &tr );
126    assert( !status );
127
128    printf(
129      "Init: signal was %sprocessed with %d:%d time remaining\n",
130      (Signal_occurred) ? "" : "not ",
131      (int) tr.tv_sec,
132      (int) tr.tv_nsec
133   );
134
135  } while ( tr.tv_sec || tr.tv_nsec );
136
137  /* exit this thread */
138
139  puts( "*** END OF POSIX TEST 4 ***" );
140  exit( 0 );
141
142  return NULL; /* just so the compiler thinks we returned something */
143}
Note: See TracBrowser for help on using the repository browser.