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-2008. |
---|
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.com/license/LICENSE. |
---|
21 | * |
---|
22 | * $Id$ |
---|
23 | */ |
---|
24 | |
---|
25 | #define CONFIGURE_INIT |
---|
26 | #include "system.h" |
---|
27 | #include "tmacros.h" |
---|
28 | #include <signal.h> /* signal facilities */ |
---|
29 | #include <unistd.h> /* sleep facilities */ |
---|
30 | #include <time.h> /* time facilities */ |
---|
31 | #include <stdio.h> /* console facilities */ |
---|
32 | |
---|
33 | void *POSIX_Init ( |
---|
34 | void *argument |
---|
35 | ) |
---|
36 | |
---|
37 | { |
---|
38 | struct timespec now; |
---|
39 | struct sigevent event; |
---|
40 | int status; |
---|
41 | timer_t timer; |
---|
42 | timer_t timer1; |
---|
43 | struct itimerspec itimer; |
---|
44 | |
---|
45 | /* |
---|
46 | * If these are not filled in correctly, we don't pass its error checking. |
---|
47 | */ |
---|
48 | event.sigev_notify = SIGEV_SIGNAL; |
---|
49 | event.sigev_signo = SIGUSR1; |
---|
50 | |
---|
51 | puts( "\n\n*** POSIX Timers Test 02 ***" ); |
---|
52 | |
---|
53 | puts( "timer_create - bad clock id - EINVAL" ); |
---|
54 | status = timer_create( -1, &event, &timer ); |
---|
55 | fatal_posix_service_status_errno( status, EINVAL, "bad clock id" ); |
---|
56 | |
---|
57 | puts( "timer_create - bad timer id pointer - EINVAL" ); |
---|
58 | status = timer_create( CLOCK_REALTIME, &event, NULL ); |
---|
59 | fatal_posix_service_status_errno( status, EINVAL, "bad timer id" ); |
---|
60 | |
---|
61 | puts( "timer_create - OK" ); |
---|
62 | status = timer_create( CLOCK_REALTIME, NULL, &timer ); |
---|
63 | posix_service_failed( status, "timer_create OK" ); |
---|
64 | |
---|
65 | puts( "timer_create - too many - EAGAIN" ); |
---|
66 | status = timer_create( CLOCK_REALTIME, NULL, &timer1 ); |
---|
67 | fatal_posix_service_status_errno( status, EAGAIN, "too many" ); |
---|
68 | |
---|
69 | puts( "timer_delete - bad id - EINVAL" ); |
---|
70 | status = timer_delete( timer1 + 1 ); |
---|
71 | fatal_posix_service_status_errno( status, EINVAL, "bad id" ); |
---|
72 | |
---|
73 | puts( "timer_getoverrun - bad id - EINVAL" ); |
---|
74 | status = timer_getoverrun( timer1 + 1 ); |
---|
75 | fatal_posix_service_status_errno( status, EINVAL, "bad id" ); |
---|
76 | |
---|
77 | puts( "timer_gettime - bad itimer - EINVAL" ); |
---|
78 | status = timer_gettime( timer1, NULL ); |
---|
79 | fatal_posix_service_status_errno( status, EINVAL, "bad id" ); |
---|
80 | |
---|
81 | puts( "timer_gettime - bad id - EINVAL" ); |
---|
82 | status = timer_gettime( timer1 + 1, &itimer ); |
---|
83 | fatal_posix_service_status_errno( status, EINVAL, "bad id" ); |
---|
84 | |
---|
85 | puts( "timer_settime - bad itimer pointer - EINVAL" ); |
---|
86 | status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL ); |
---|
87 | fatal_posix_service_status_errno( status, EINVAL, "bad itimer pointer" ); |
---|
88 | |
---|
89 | itimer.it_value.tv_nsec = 2000000000; |
---|
90 | puts( "timer_settime - bad itimer value - too many nanosecond - EINVAL" ); |
---|
91 | status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL ); |
---|
92 | fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #1" ); |
---|
93 | |
---|
94 | itimer.it_value.tv_nsec = -1; |
---|
95 | puts( "timer_settime - bad itimer value - negative nanosecond - EINVAL" ); |
---|
96 | status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL ); |
---|
97 | fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #2" ); |
---|
98 | |
---|
99 | clock_gettime( CLOCK_REALTIME, &now ); |
---|
100 | itimer.it_value = now; |
---|
101 | itimer.it_value.tv_sec = itimer.it_value.tv_sec - 1; |
---|
102 | puts( "timer_settime - bad itimer value - previous time - EINVAL" ); |
---|
103 | status = timer_settime( timer, TIMER_ABSTIME, &itimer, NULL ); |
---|
104 | fatal_posix_service_status_errno( status, EINVAL, "bad itimer value #3" ); |
---|
105 | |
---|
106 | itimer.it_value.tv_nsec = 0; |
---|
107 | puts( "timer_settime - bad clock value - EINVAL" ); |
---|
108 | status = timer_settime( timer, 0x80, &itimer, NULL ); |
---|
109 | fatal_posix_service_status_errno( status, EINVAL, "bad clock value" ); |
---|
110 | |
---|
111 | puts( "timer_delete - OK" ); |
---|
112 | status = timer_delete( timer ); |
---|
113 | posix_service_failed( status, "timer_delete OK" ); |
---|
114 | |
---|
115 | puts( "timer_delete - bad id - EINVAL" ); |
---|
116 | status = timer_delete( timer ); |
---|
117 | fatal_posix_service_status_errno( status, EINVAL, "bad id" ); |
---|
118 | |
---|
119 | puts( "*** END OF POSIX Timers Test 02 ***" ); |
---|
120 | rtems_test_exit (0); |
---|
121 | } |
---|