source: rtems/testsuites/psxtests/psx02/init.c @ 698c2e50

4.115
Last change on this file since 698c2e50 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

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