source: rtems/testsuites/psxtests/psxtimer02/psxtimer.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 *
3 *  This is a simple real-time applications which contains 3 periodic tasks.
4 *
5 *  Task A is an independent task.
6 *
7 *  Task B and C share a data.
8 *
9 *  Tasks are implemented as POSIX threads.
10 *
11 *  The share data is protected with a POSIX mutex.
12 *
13 *  Other POSIX facilities such as timers, condition, .. is also used
14 *
15 *  COPYRIGHT (c) 1989-2009.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#define CONFIGURE_INIT
28#include "system.h"
29#include "tmacros.h"
30#include <signal.h>   /* signal facilities */
31#include <unistd.h>   /* sleep facilities */
32#include <time.h>     /* time facilities */
33#include <stdio.h>    /* console facilities */
34
35const char rtems_test_name[] = "PSXTIMER 2";
36
37void *POSIX_Init (
38  void *argument
39)
40
41{
42  struct timespec   now;
43  struct sigevent   event;
44  int               status;
45  timer_t           timer;
46  timer_t           timer1;
47  struct itimerspec itimer;
48
49  /*
50   *  If these are not filled in correctly, we don't pass its error checking.
51   */
52  event.sigev_notify = SIGEV_SIGNAL;
53  event.sigev_signo = SIGUSR1;
54
55  TEST_BEGIN();
56
57  puts( "timer_create - bad clock id - EINVAL" );
58  status = timer_create( (timer_t) -1, &event, &timer );
59  fatal_posix_service_status_errno( status, EINVAL, "bad clock id" );
60
61  puts( "timer_create - bad timer id pointer - EINVAL" );
62  status = timer_create( CLOCK_REALTIME, &event, NULL );
63  fatal_posix_service_status_errno( status, EINVAL, "bad timer id" );
64
65  puts( "timer_create - OK" );
66  status = timer_create( CLOCK_REALTIME, NULL, &timer );
67  posix_service_failed( status, "timer_create OK" );
68
69  puts( "timer_create - too many - EAGAIN" );
70  status = timer_create( CLOCK_REALTIME, NULL, &timer1 );
71  fatal_posix_service_status_errno( status, EAGAIN, "too many" );
72
73  puts( "timer_delete - bad id - EINVAL" );
74  status = timer_delete( timer1 + 1 );
75  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
76
77  puts( "timer_getoverrun - bad id - EINVAL" );
78  status = timer_getoverrun( timer1 + 1 );
79  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
80
81  puts( "timer_gettime - bad itimer - EINVAL" );
82  status = timer_gettime( timer1, NULL );
83  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
84
85  puts( "timer_gettime - bad id - EINVAL" );
86  status = timer_gettime( timer1 + 1, &itimer );
87  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
88
89  puts( "timer_settime - bad itimer pointer - EINVAL" );
90  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );
91  fatal_posix_service_status_errno( status, EINVAL, "bad itimer pointer" );
92
93  itimer.it_value.tv_nsec = 2000000000;
94  puts( "timer_settime - bad itimer value - too many nanosecond - EINVAL" );
95  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );
96  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #1" );
97
98  itimer.it_value.tv_nsec = -1;
99  puts( "timer_settime - bad itimer value - negative nanosecond - EINVAL" );
100  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );
101  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #2" );
102
103  clock_gettime( CLOCK_REALTIME, &now );
104  itimer.it_value = now;
105  itimer.it_value.tv_sec = itimer.it_value.tv_sec - 1;
106  puts( "timer_settime - bad itimer value - previous time - EINVAL" );
107  status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL );
108  fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #3" );
109
110  clock_gettime( CLOCK_REALTIME, &now );
111  itimer.it_value = now;
112  itimer.it_value.tv_sec = itimer.it_value.tv_sec + 1;
113  puts( "timer_settime - bad id - EINVAL" );
114  status = timer_settime( timer1, TIMER_ABSTIME, &itimer, NULL );
115  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
116
117  itimer.it_value.tv_nsec = 0;
118  puts( "timer_settime - bad clock value - EINVAL" );
119  status = timer_settime( timer, 0x80, &itimer, NULL );
120  fatal_posix_service_status_errno( status, EINVAL, "bad clock value" );
121
122  puts( "timer_delete - OK" );
123  status = timer_delete( timer );
124  posix_service_failed( status, "timer_delete OK" );
125
126  puts( "timer_delete - bad id - EINVAL" );
127  status = timer_delete( timer );
128  fatal_posix_service_status_errno( status, EINVAL, "bad id" );
129
130  TEST_END();
131  rtems_test_exit (0);
132}
Note: See TracBrowser for help on using the repository browser.