source: rtems/testsuites/psxtests/psxualarm/init.c @ 20b423c6

4.115
Last change on this file since 20b423c6 was 20b423c6, checked in by Sebastian Huber <sebastian.huber@…>, on 05/11/15 at 13:02:51

psxualarm: Avoid endless signal handling

Increase the ualarm timer interval to avoid endless signal handling.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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#include <unistd.h>
18#include <errno.h>
19
20const char rtems_test_name[] = "PSXUALARM";
21
22/* forward declarations to avoid warnings */
23void Signal_handler(int signo);
24rtems_timer_service_routine Signal_duringISR_TSR(
25  rtems_id  ignored_id,
26  void     *ignored_address
27);
28
29typedef void (*sighandler_t)(int);
30sighandler_t signal(int signum, sighandler_t handler);
31extern void _POSIX_signals_Abnormal_termination_handler( int signo );
32
33volatile int Signal_occurred;
34volatile int Signal_count;
35
36void Signal_handler(
37  int signo
38)
39{
40  Signal_count++;
41  printf(
42    "Signal: %d caught by 0x%" PRIxpthread_t " (%d)\n",
43    signo,
44    pthread_self(),
45    Signal_count
46  );
47  Signal_occurred = 1;
48}
49
50rtems_timer_service_routine Signal_duringISR_TSR(
51  rtems_id  ignored_id,
52  void     *ignored_address
53)
54{
55  int               status;
56
57  status = kill( getpid(), SIGUSR1 );
58  rtems_test_assert( status == 0 );
59}
60
61
62void *POSIX_Init(
63  void *argument
64)
65{
66  int               status;
67  useconds_t        result;
68  struct sigaction  act;
69  sigset_t          mask;
70
71  TEST_BEGIN();
72
73  /* set the time of day, and print our buffer in multiple ways */
74
75  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
76
77  /* get id of this thread */
78
79  Init_id = pthread_self();
80  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
81
82  Signal_occurred = 0;
83  Signal_count = 0;
84
85  /* Validate ualarm is ignored if signal not caught */
86  act.sa_handler = Signal_handler;
87  act.sa_flags   = 0;
88  sigaction( SIGALRM, &act, NULL );
89  puts( "Init: ualarm in 100000 us" );
90  sleep(3);
91  result = ualarm(100000,0);
92  rtems_test_assert( result == 0 );
93 
94  status = sleep(10);
95  rtems_test_assert( status == 0 );
96
97  /* unblock Signal and see if it happened */
98  status = sigemptyset( &mask );
99  rtems_test_assert( !status );
100  status = sigaddset( &mask, SIGALRM );
101  rtems_test_assert( !status );
102  puts( "Init: Unblock SIGALRM" );
103  status = sigprocmask( SIG_UNBLOCK, &mask, NULL );
104  rtems_test_assert( !status );
105  status = sleep(10);
106
107  /* stop ularm */
108  puts( "Init: clear ualarm with 0,0" );
109  result = ualarm(0,0);
110  status = sleep(10);
111
112  TEST_END();
113  rtems_test_exit(0);
114
115  return NULL; /* just so the compiler thinks we returned something */
116}
Note: See TracBrowser for help on using the repository browser.