source: rtems/testsuites/psxtests/psxualarm/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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