source: rtems/testsuites/psxtests/psx02/init.c @ d802489

4.104.114.84.95
Last change on this file since d802489 was d802489, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:53:21

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/pmacros.h, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx11/init.c, psx12/init.c, psx13/Makefile.am, psx13/main.c, psx13/test.c, psxcancel/init.c, psxchroot01/Makefile.am, psxchroot01/main.c, psxchroot01/test.c, psxfile01/Makefile.am, psxfile01/main.c, psxfile01/test.c, psxfile01/test_cat.c, psxfile01/test_extend.c, psxfile01/test_write.c, psxmount/Makefile.am, psxmount/main.c, psxmount/test.c, psxmsgq01/init.c, psxreaddir/Makefile.am, psxreaddir/main.c, psxreaddir/test.c, psxsem01/init.c, psxstat/Makefile.am, psxstat/main.c, psxstat/test.c, psxtime/main.c, psxtime/test.c, psxtimer/psxtimer.c: Modified.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
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;
18
19void Signal_handler(
20  int signo
21)
22{
23  Signal_count++;
24  printf(
25    "Signal: %d caught by 0x%x (%d)\n",
26    signo,
27    pthread_self(),
28    Signal_count
29  );
30  Signal_occurred = 1;
31}
32
33void *POSIX_Init(
34  void *argument
35)
36{
37  int               status;
38  struct timespec   tv;
39  struct timespec   tr;
40  struct sigaction  act;
41  sigset_t          mask;
42  sigset_t          pending_set;
43
44  puts( "\n\n*** POSIX TEST 2 ***" );
45
46  /* set the time of day, and print our buffer in multiple ways */
47
48  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
49
50  /* get id of this thread */
51
52  Init_id = pthread_self();
53  printf( "Init's ID is 0x%08x\n", Init_id );
54
55  /* install a signal handler */
56
57  status = sigemptyset( &act.sa_mask );
58  assert( !status );
59
60  act.sa_handler = Signal_handler;
61  act.sa_flags   = 0;
62 
63  sigaction( SIGUSR1, &act, NULL );
64
65  /* simple signal to self */
66
67  Signal_count = 0;
68  Signal_occurred = 0;
69
70  status = pthread_kill( Init_id, SIGUSR1 );
71  assert( !status );
72
73  Signal_occurred = 0;
74
75  /* now block the signal, send it, see if it is pending, and unblock it */
76
77  status = sigemptyset( &mask );
78  assert( !status );
79
80  status = sigaddset( &mask, SIGUSR1 );
81  assert( !status );
82
83  printf( "Init: Block SIGUSR1\n" );
84  status = sigprocmask( SIG_BLOCK, &mask, NULL );
85  assert( !status );
86
87  status = sigpending( &pending_set );
88  assert( !status );
89  printf( "Init: Signals pending 0x%08x\n", pending_set );
90 
91 
92  printf( "Init: send SIGUSR1 to self\n" );
93  status = pthread_kill( Init_id, SIGUSR1 );
94  assert( !status );
95
96  status = sigpending( &pending_set );
97  assert( !status );
98  printf( "Init: Signals pending 0x%08x\n", pending_set );
99 
100  printf( "Init: Unblock SIGUSR1\n" );
101  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
102  assert( !status );
103
104  /* create a thread */
105
106  status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
107  assert( !status );
108
109  /*
110   *  Loop for 5 seconds seeing how many signals we catch
111   */
112
113  tr.tv_sec = 5;
114  tr.tv_nsec = 0;
115 
116  do {
117    tv = tr;
118
119    Signal_occurred = 0;
120
121    status = nanosleep ( &tv, &tr );
122 
123    if ( status == -1 ) {
124      assert( errno == EINTR );
125      assert( tr.tv_nsec || tr.tv_sec );
126    } else if ( !status ) {
127      assert( !tr.tv_nsec && !tr.tv_sec );
128    }
129     
130    printf(
131      "Init: signal was %sprocessed with %d:%d time remaining\n",
132      (Signal_occurred) ? "" : "not ",
133      (int) tr.tv_sec,
134      (int) tr.tv_nsec
135   );
136
137  } while ( tr.tv_sec || tr.tv_nsec );
138
139  /* exit this thread */
140
141  puts( "*** END OF POSIX TEST 2 ***" );
142  rtems_test_exit( 0 );
143
144  return NULL; /* just so the compiler thinks we returned something */
145}
Note: See TracBrowser for help on using the repository browser.