source: rtems/testsuites/psxtests/psxalarm01/init.c @ 39615f4

4.104.11
Last change on this file since 39615f4 was 39615f4, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 27, 2009 at 2:10:54 PM

Use PRIxpthread_t to print pthread_t's.

  • Property mode set to 100644
File size: 2.5 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#include <pmacros.h>
13
14#include <signal.h>
15#include <errno.h>
16
17volatile int Signal_occurred;
18volatile int Signal_count;
19void Signal_handler( int signo );
20void Signal_info_handler(
21  int        signo,
22  siginfo_t *info,
23  void      *context
24);
25
26void Signal_handler(
27  int signo
28)
29{
30  Signal_count++;
31  printf(
32    "Signal: %d caught by 0x%" PRIxpthread_t " (%d)\n",
33    signo,
34    pthread_self(),
35    Signal_count
36  );
37  Signal_occurred = 1;
38}
39
40void Signal_info_handler(
41  int        signo,
42  siginfo_t *info,
43  void      *context
44)
45{
46  Signal_count++;
47  printf(
48    "Signal_info: %d caught by 0x%" PRIxpthread_t " (%d) si_signo= %d si_code= %d value= %d\n",
49    signo,
50    pthread_self(),
51    Signal_count,
52    info->si_signo,
53    info->si_code,
54    info->si_value.sival_int
55  );
56  Signal_occurred = 1;
57}
58
59void *POSIX_Init(
60  void *argument
61)
62{
63  unsigned int      remaining;
64  int               sc;
65  struct sigaction  act;
66  sigset_t          mask;
67
68  puts( "\n\n*** POSIX ALARM TEST 01 ***" );
69
70  /* install a signal handler for SIGALRM and unblock it */
71
72  sc = sigemptyset( &act.sa_mask );
73  assert( !sc );
74
75  act.sa_handler = Signal_handler;
76  act.sa_flags   = 0;
77
78  sigaction( SIGALRM, &act, NULL );
79
80  sc = sigemptyset( &mask );
81  assert( !sc );
82
83  sc = sigaddset( &mask, SIGALRM );
84  assert( !sc );
85
86  puts( "Init: Unblock SIGALRM" );
87  sc = sigprocmask( SIG_UNBLOCK, &mask, NULL );
88  assert( !sc );
89
90  /* schedule the alarm */
91
92  puts( "Init: Firing alarm in 1 second" );
93  remaining = alarm( 1 );
94  printf( "Init: %d seconds left on previous alarm\n", sc );
95  assert( !sc );
96
97  puts( "Init: Wait for alarm" );
98  sleep( 2 );
99
100  puts( "Init: Cancel alarm" );
101  remaining = alarm( 0 );
102  printf( "Init: %d seconds left on previous alarm\n", remaining );
103  assert( remaining == 0 );
104
105  puts( "*** END OF POSIX ALARM TEST 01***" );
106  rtems_test_exit( 0 );
107
108  return NULL; /* just so the compiler thinks we returned something */
109}
110
111#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
112#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
113
114#define CONFIGURE_MAXIMUM_POSIX_THREADS        1
115
116#define CONFIGURE_POSIX_INIT_THREAD_TABLE
117#define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE \
118        (RTEMS_MINIMUM_STACK_SIZE * 4)
119
120#define CONFIGURE_INIT
121#include <rtems/confdefs.h>
122
Note: See TracBrowser for help on using the repository browser.