source: rtems/testsuites/psxtests/psxualarm/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was ae0f048, checked in by Sebastian Huber <sebastian.huber@…>, on 05/18/16 at 09:09:10

psxtests/psxualarm: Avoid output in signal handler

Avoid output in signal handler to not disturb the timings which are
checked in this test. Use asserts to ensure proper signal handler
invocations.

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