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

4.11
Last change on this file since cafefbf was cafefbf, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 22, 2011 at 9:47:36 AM

Add HAVE_CONFIG_H.

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