[c3a8293] | 1 | /* |
---|
[2317457] | 2 | * COPYRIGHT (c) 1989-2009. |
---|
[c3a8293] | 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 | |
---|
[cafefbf] | 12 | #ifdef HAVE_CONFIG_H |
---|
| 13 | #include "config.h" |
---|
| 14 | #endif |
---|
| 15 | |
---|
[c3a8293] | 16 | #define CONFIGURE_INIT |
---|
| 17 | #include "system.h" |
---|
| 18 | #include <signal.h> |
---|
| 19 | #include <unistd.h> |
---|
| 20 | #include <errno.h> |
---|
| 21 | typedef void (*sighandler_t)(int); |
---|
| 22 | sighandler_t signal(int signum, sighandler_t handler); |
---|
| 23 | extern void _POSIX_signals_Abnormal_termination_handler( int signo ); |
---|
| 24 | |
---|
| 25 | volatile int Signal_occurred; |
---|
| 26 | volatile int Signal_count; |
---|
| 27 | |
---|
| 28 | void Signal_handler( |
---|
| 29 | int signo |
---|
| 30 | ) |
---|
| 31 | { |
---|
| 32 | Signal_count++; |
---|
| 33 | printf( |
---|
[39615f4] | 34 | "Signal: %d caught by 0x%" PRIxpthread_t " (%d)\n", |
---|
[c3a8293] | 35 | signo, |
---|
| 36 | pthread_self(), |
---|
| 37 | Signal_count |
---|
| 38 | ); |
---|
| 39 | Signal_occurred = 1; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | rtems_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 | |
---|
| 52 | void *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(); |
---|
[39615f4] | 70 | printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); |
---|
[c3a8293] | 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 ); |
---|
[33c46f1] | 86 | rtems_test_assert( !status ); |
---|
[c3a8293] | 87 | status = sigaddset( &mask, SIGALRM ); |
---|
[33c46f1] | 88 | rtems_test_assert( !status ); |
---|
[c3a8293] | 89 | puts( "Init: Unblock SIGALRM" ); |
---|
| 90 | status = sigprocmask( SIG_UNBLOCK, &mask, NULL ); |
---|
[33c46f1] | 91 | rtems_test_assert( !status ); |
---|
[c3a8293] | 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 | } |
---|