1 | /* Init |
---|
2 | * |
---|
3 | * This routine is the XXX. |
---|
4 | * |
---|
5 | * Input parameters: |
---|
6 | * argument - task argument |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 2008. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifdef HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #define TEST_INIT |
---|
23 | |
---|
24 | #define CONFIGURE_INIT |
---|
25 | #include "system.h" |
---|
26 | |
---|
27 | #include <rtems/score/watchdogimpl.h> |
---|
28 | |
---|
29 | const char rtems_test_name[] = "SPWATCHDOG"; |
---|
30 | |
---|
31 | typedef struct { |
---|
32 | Watchdog_Control Base; |
---|
33 | int counter; |
---|
34 | } test_watchdog; |
---|
35 | |
---|
36 | static void test_watchdog_routine( Watchdog_Control *base ) |
---|
37 | { |
---|
38 | test_watchdog *watchdog = (test_watchdog *) base; |
---|
39 | |
---|
40 | ++watchdog->counter; |
---|
41 | } |
---|
42 | |
---|
43 | static void test_watchdog_static_init( void ) |
---|
44 | { |
---|
45 | static Watchdog_Control a = WATCHDOG_INITIALIZER( |
---|
46 | test_watchdog_routine |
---|
47 | ); |
---|
48 | Watchdog_Control b; |
---|
49 | |
---|
50 | memset( &b, 0, sizeof( b ) ); |
---|
51 | _Watchdog_Preinitialize( &b, _Per_CPU_Get_by_index( 0 ) ); |
---|
52 | _Watchdog_Initialize( |
---|
53 | &b, |
---|
54 | test_watchdog_routine |
---|
55 | ); |
---|
56 | |
---|
57 | rtems_test_assert( memcmp( &a, &b, sizeof( a ) ) == 0 ); |
---|
58 | } |
---|
59 | |
---|
60 | static void test_watchdog_config( void ) |
---|
61 | { |
---|
62 | rtems_test_assert( _Watchdog_Nanoseconds_per_tick == 10000000 ); |
---|
63 | rtems_test_assert( _Watchdog_Ticks_per_second == 100 ); |
---|
64 | rtems_test_assert( _Watchdog_Monotonic_max_seconds == 184467440737095516 ); |
---|
65 | rtems_test_assert( rtems_clock_get_ticks_per_second() == 100 ); |
---|
66 | #undef rtems_clock_get_ticks_per_second |
---|
67 | rtems_test_assert( rtems_clock_get_ticks_per_second() == 100 ); |
---|
68 | } |
---|
69 | |
---|
70 | static bool test_watchdog_is_inactive( test_watchdog *watchdog ) |
---|
71 | { |
---|
72 | return _Watchdog_Get_state( &watchdog->Base ) == WATCHDOG_INACTIVE; |
---|
73 | } |
---|
74 | |
---|
75 | static void test_watchdog_init( test_watchdog *watchdog, int counter ) |
---|
76 | { |
---|
77 | _Watchdog_Preinitialize( &watchdog->Base, _Per_CPU_Get_snapshot() ); |
---|
78 | _Watchdog_Initialize( &watchdog->Base, test_watchdog_routine ); |
---|
79 | rtems_test_assert( test_watchdog_is_inactive( watchdog ) ) ; |
---|
80 | watchdog->counter = counter; |
---|
81 | } |
---|
82 | |
---|
83 | static uint64_t test_watchdog_tick( Watchdog_Header *header, uint64_t now ) |
---|
84 | { |
---|
85 | ISR_LOCK_DEFINE( , lock, "Test" ) |
---|
86 | ISR_lock_Context lock_context; |
---|
87 | |
---|
88 | _ISR_lock_ISR_disable_and_acquire( &lock, &lock_context ); |
---|
89 | ++now; |
---|
90 | _Watchdog_Tickle( header, now, &lock, &lock_context ); |
---|
91 | _ISR_lock_Destroy( &lock ); |
---|
92 | |
---|
93 | return now; |
---|
94 | } |
---|
95 | |
---|
96 | static void test_watchdog_operations( void ) |
---|
97 | { |
---|
98 | Watchdog_Header header; |
---|
99 | uint64_t now; |
---|
100 | test_watchdog a; |
---|
101 | test_watchdog b; |
---|
102 | test_watchdog c; |
---|
103 | |
---|
104 | _Watchdog_Header_initialize( &header ); |
---|
105 | rtems_test_assert( _RBTree_Is_empty( &header.Watchdogs ) ); |
---|
106 | rtems_test_assert( header.first == NULL ); |
---|
107 | |
---|
108 | test_watchdog_init( &a, 10 ); |
---|
109 | test_watchdog_init( &b, 20 ); |
---|
110 | test_watchdog_init( &c, 30 ); |
---|
111 | |
---|
112 | now = 0; |
---|
113 | now = test_watchdog_tick( &header, now ); |
---|
114 | |
---|
115 | _Watchdog_Insert( &header, &a.Base, now + 1 ); |
---|
116 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
117 | rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; |
---|
118 | rtems_test_assert( a.Base.expire == 2 ); |
---|
119 | rtems_test_assert( a.counter == 10 ); |
---|
120 | |
---|
121 | _Watchdog_Remove( &header, &a.Base ); |
---|
122 | rtems_test_assert( header.first == NULL ); |
---|
123 | rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; |
---|
124 | rtems_test_assert( a.Base.expire == 2 ); |
---|
125 | rtems_test_assert( a.counter == 10 ); |
---|
126 | |
---|
127 | _Watchdog_Remove( &header, &a.Base ); |
---|
128 | rtems_test_assert( header.first == NULL ); |
---|
129 | rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; |
---|
130 | rtems_test_assert( a.Base.expire == 2 ); |
---|
131 | rtems_test_assert( a.counter == 10 ); |
---|
132 | |
---|
133 | _Watchdog_Insert( &header, &a.Base, now + 1 ); |
---|
134 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
135 | rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; |
---|
136 | rtems_test_assert( a.Base.expire == 2 ); |
---|
137 | rtems_test_assert( a.counter == 10 ); |
---|
138 | |
---|
139 | _Watchdog_Insert( &header, &b.Base, now + 1 ); |
---|
140 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
141 | rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; |
---|
142 | rtems_test_assert( b.Base.expire == 2 ); |
---|
143 | rtems_test_assert( b.counter == 20 ); |
---|
144 | |
---|
145 | _Watchdog_Insert( &header, &c.Base, now + 2 ); |
---|
146 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
147 | rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; |
---|
148 | rtems_test_assert( c.Base.expire == 3 ); |
---|
149 | rtems_test_assert( c.counter == 30 ); |
---|
150 | |
---|
151 | _Watchdog_Remove( &header, &a.Base ); |
---|
152 | rtems_test_assert( header.first == &b.Base.Node.RBTree ); |
---|
153 | rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; |
---|
154 | rtems_test_assert( a.Base.expire == 2 ); |
---|
155 | rtems_test_assert( a.counter == 10 ); |
---|
156 | |
---|
157 | _Watchdog_Remove( &header, &b.Base ); |
---|
158 | rtems_test_assert( header.first == &c.Base.Node.RBTree ); |
---|
159 | rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; |
---|
160 | rtems_test_assert( b.Base.expire == 2 ); |
---|
161 | rtems_test_assert( b.counter == 20 ); |
---|
162 | |
---|
163 | _Watchdog_Remove( &header, &c.Base ); |
---|
164 | rtems_test_assert( header.first == NULL ); |
---|
165 | rtems_test_assert( test_watchdog_is_inactive( &c ) ) ; |
---|
166 | rtems_test_assert( c.Base.expire == 3 ); |
---|
167 | rtems_test_assert( c.counter == 30 ); |
---|
168 | |
---|
169 | _Watchdog_Insert( &header, &a.Base, now + 2 ); |
---|
170 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
171 | rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; |
---|
172 | rtems_test_assert( a.Base.expire == 3 ); |
---|
173 | rtems_test_assert( a.counter == 10 ); |
---|
174 | |
---|
175 | _Watchdog_Insert( &header, &b.Base, now + 2 ); |
---|
176 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
177 | rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; |
---|
178 | rtems_test_assert( b.Base.expire == 3 ); |
---|
179 | rtems_test_assert( b.counter == 20 ); |
---|
180 | |
---|
181 | _Watchdog_Insert( &header, &c.Base, now + 3 ); |
---|
182 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
183 | rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; |
---|
184 | rtems_test_assert( c.Base.expire == 4 ); |
---|
185 | rtems_test_assert( c.counter == 30 ); |
---|
186 | |
---|
187 | now = test_watchdog_tick( &header, now ); |
---|
188 | rtems_test_assert( !_RBTree_Is_empty( &header.Watchdogs ) ); |
---|
189 | rtems_test_assert( header.first == &a.Base.Node.RBTree ); |
---|
190 | rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; |
---|
191 | rtems_test_assert( a.Base.expire == 3 ); |
---|
192 | rtems_test_assert( a.counter == 10 ); |
---|
193 | rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; |
---|
194 | rtems_test_assert( b.Base.expire == 3 ); |
---|
195 | rtems_test_assert( b.counter == 20 ); |
---|
196 | rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; |
---|
197 | rtems_test_assert( c.Base.expire == 4 ); |
---|
198 | rtems_test_assert( c.counter == 30 ); |
---|
199 | |
---|
200 | now = test_watchdog_tick( &header, now ); |
---|
201 | rtems_test_assert( !_RBTree_Is_empty( &header.Watchdogs ) ); |
---|
202 | rtems_test_assert( header.first == &c.Base.Node.RBTree ); |
---|
203 | rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; |
---|
204 | rtems_test_assert( a.Base.expire == 3 ); |
---|
205 | rtems_test_assert( a.counter == 11 ); |
---|
206 | rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; |
---|
207 | rtems_test_assert( b.Base.expire == 3 ); |
---|
208 | rtems_test_assert( b.counter == 21 ); |
---|
209 | rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; |
---|
210 | rtems_test_assert( c.Base.expire == 4 ); |
---|
211 | rtems_test_assert( c.counter == 30 ); |
---|
212 | |
---|
213 | now = test_watchdog_tick( &header, now ); |
---|
214 | rtems_test_assert( _RBTree_Is_empty( &header.Watchdogs ) ); |
---|
215 | rtems_test_assert( header.first == NULL ); |
---|
216 | rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; |
---|
217 | rtems_test_assert( a.Base.expire == 3 ); |
---|
218 | rtems_test_assert( a.counter == 11 ); |
---|
219 | rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; |
---|
220 | rtems_test_assert( b.Base.expire == 3 ); |
---|
221 | rtems_test_assert( b.counter == 21 ); |
---|
222 | rtems_test_assert( test_watchdog_is_inactive( &c ) ) ; |
---|
223 | rtems_test_assert( c.Base.expire == 4 ); |
---|
224 | rtems_test_assert( c.counter == 31 ); |
---|
225 | |
---|
226 | _Watchdog_Header_destroy( &header ); |
---|
227 | } |
---|
228 | |
---|
229 | rtems_task Init( |
---|
230 | rtems_task_argument argument |
---|
231 | ) |
---|
232 | { |
---|
233 | rtems_time_of_day time; |
---|
234 | rtems_status_code status; |
---|
235 | |
---|
236 | TEST_BEGIN(); |
---|
237 | |
---|
238 | test_watchdog_operations(); |
---|
239 | test_watchdog_static_init(); |
---|
240 | test_watchdog_config(); |
---|
241 | |
---|
242 | build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); |
---|
243 | |
---|
244 | status = rtems_clock_set( &time ); |
---|
245 | directive_failed( status, "rtems_clock_set" ); |
---|
246 | |
---|
247 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); |
---|
248 | Timer_name[ 1 ] = rtems_build_name( 'T', 'M', '1', ' ' ); |
---|
249 | |
---|
250 | status = rtems_task_create( |
---|
251 | Task_name[ 1 ], |
---|
252 | 1, |
---|
253 | RTEMS_MINIMUM_STACK_SIZE * 2, |
---|
254 | RTEMS_DEFAULT_MODES, |
---|
255 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
256 | &Task_id[ 1 ] |
---|
257 | ); |
---|
258 | directive_failed( status, "rtems_task_create of TA1" ); |
---|
259 | |
---|
260 | status = rtems_task_start( Task_id[ 1 ], Task_1, 0 ); |
---|
261 | directive_failed( status, "rtems_task_start of TA1" ); |
---|
262 | |
---|
263 | puts( "INIT - rtems_timer_create - creating timer 1" ); |
---|
264 | status = rtems_timer_create( Timer_name[ 1 ], &Timer_id[ 1 ] ); |
---|
265 | directive_failed( status, "rtems_timer_create" ); |
---|
266 | |
---|
267 | printf( "INIT - timer 1 has id (0x%" PRIxrtems_id ")\n", Timer_id[ 1 ] ); |
---|
268 | |
---|
269 | status = rtems_task_delete( RTEMS_SELF ); |
---|
270 | directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); |
---|
271 | |
---|
272 | |
---|
273 | rtems_test_exit( 0 ); |
---|
274 | } |
---|