source: rtems/testsuites/psxtests/psx02/init.c @ 56864ffc

4.104.115
Last change on this file since 56864ffc was 2e7e636f, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/09 at 01:41:16

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • psx01/init.c, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task3.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/init.c, psx09/init.c, psx11/task.c, psx12/init.c, psx13/main.c, psx13/test.c, psxbarrier01/test.c, psxcancel/init.c, psxcleanup/psxcleanup.c, psxenosys/init.c, psxmsgq02/init.c, psxtime/main.c, psxtime/test.c, psxtimer01/psxtimer.c, psxtimer02/psxtimer.c: Fix warnings.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#define CONFIGURE_INIT
13#include "system.h"
14#include <signal.h>
15
16volatile int Signal_occurred;
17volatile int Signal_count;
18void Signal_handler( int signo );
19
20void Signal_handler(
21  int signo
22)
23{
24  Signal_count++;
25  printf(
26    "Signal: %d caught by 0x%x (%d)\n",
27    (int) signo,
28    (unsigned int) 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", (unsigned int) 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", (unsigned int) 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
124    if ( status == -1 ) {
125      assert( errno == EINTR );
126      assert( tr.tv_nsec || tr.tv_sec );
127    } else if ( !status ) {
128      assert( !tr.tv_nsec && !tr.tv_sec );
129    }
130
131    printf(
132      "Init: signal was %sprocessed with %d:%d time remaining\n",
133      (Signal_occurred) ? "" : "not ",
134      (int) tr.tv_sec,
135      (int) tr.tv_nsec
136   );
137
138  } while ( tr.tv_sec || tr.tv_nsec );
139
140  /* exit this thread */
141
142  puts( "*** END OF POSIX TEST 2 ***" );
143  rtems_test_exit( 0 );
144
145  return NULL; /* just so the compiler thinks we returned something */
146}
Note: See TracBrowser for help on using the repository browser.