source: rtems/testsuites/sptests/sp31/task1.c @ d5ae827

4.104.115
Last change on this file since d5ae827 was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on 05/10/09 at 14:39:46

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 8.9 KB
Line 
1/*  Task_1
2 *
3 *  This routine serves as a test task.  It verifies the basic task
4 *  switching capabilities of the executive.
5 *
6 *  Input parameters:
7 *    argument - task argument
8 *
9 *  Output parameters:  NONE
10 *
11 *  COPYRIGHT (c) 1989-2009.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include "system.h"
22
23rtems_timer_service_routine Should_not_fire_TSR(
24  rtems_id  ignored_id,
25  void     *ignored_address
26);
27
28volatile int TSR_fired;
29
30rtems_timer_service_routine Should_not_fire_TSR(
31  rtems_id  ignored_id,
32  void     *ignored_address
33)
34{
35  TSR_fired = 1;
36}
37
38rtems_task Task_1(
39  rtems_task_argument argument
40)
41{
42  rtems_id                 tmid;
43  rtems_id                 tmid2;
44  rtems_time_of_day        time;
45  rtems_status_code        status;
46  rtems_timer_information  info;
47
48/* Get id */
49
50  puts( "TA1 - rtems_timer_ident - identing timer 1" );
51  status = rtems_timer_ident( Timer_name[ 1 ], &tmid );
52  directive_failed( status, "rtems_timer_ident" );
53  printf( "TA1 - timer 1 has id (0x%x)\n", tmid );
54
55  puts( "TA1 - rtems_timer_ident - identing timer 2" );
56  status = rtems_timer_ident( Timer_name[ 2 ], &tmid2 );
57  directive_failed( status, "rtems_timer_ident" );
58  printf( "TA1 - timer 2 has id (0x%x)\n", tmid2 );
59
60/* make sure insertion does not unintentionally fire a timer per PR147 */
61
62  TSR_fired = 0;
63
64  puts( "TA1 - rtems_timer_server_fire_after - 1 second" );
65  status = rtems_timer_server_fire_after(
66    tmid, TICKS_PER_SECOND, Should_not_fire_TSR, NULL );
67  directive_failed( status, "rtems_timer_server_fire_after" );
68
69  puts( "TA1 - rtems_task_wake_after - 1/2 second" );
70  status = rtems_task_wake_after( TICKS_PER_SECOND / 2 );
71  directive_failed( status, "rtems_timer_server_fire_after" );
72
73  directive_failed( status, "rtems_timer_server_fire_after" );
74  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1/2 second" );
75  status = rtems_timer_server_fire_after(
76    tmid2, TICKS_PER_SECOND / 2, Should_not_fire_TSR, NULL );
77  directive_failed( status, "rtems_timer_server_fire_after" );
78
79  if ( TSR_fired ) {
80    puts( "TA1 - TSR fired and should not have!" );
81    rtems_test_exit(1);
82  }
83
84  puts( "TA1 - rtems_timer_cancel - timer 1" );
85  status = rtems_timer_cancel( tmid );
86  directive_failed( status, "rtems_timer_cancel" );
87
88  puts( "TA1 - rtems_timer_cancel - timer 2" );
89  status = rtems_timer_cancel( tmid2 );
90  directive_failed( status, "rtems_timer_cancel" );
91
92
93/* now check that rescheduling an active timer works OK. */
94  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 30 seconds" );
95  status = rtems_timer_server_fire_after(
96    tmid, 30 * TICKS_PER_SECOND, Delayed_resume, NULL );
97  directive_failed( status, "rtems_timer_server_fire_after" );
98
99  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
100  status = rtems_timer_server_fire_after(
101    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
102  directive_failed( status, "rtems_timer_server_fire_after" );
103
104  status = rtems_timer_get_information( tmid, &info );
105  printf( "Timer 1 scheduled for %d ticks since boot\n",
106    info.start_time + info.initial );
107  printf( "Timer Server scheduled for %d ticks since boot\n",
108    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
109
110  puts( "TA1 - rtems_task_wake_after - 1 second" );
111  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
112  directive_failed( status, "rtems_timer_wake_after" );
113
114  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
115  status = rtems_timer_server_fire_after(
116    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
117  directive_failed( status, "rtems_timer_server_fire_after" );
118
119  status = rtems_timer_get_information( tmid, &info );
120  directive_failed( status, "rtems_timer_get_information" );
121  printf( "Timer 1 scheduled for %d ticks since boot\n",
122    info.start_time + info.initial );
123  printf( "Timer Server scheduled for %d ticks since boot\n",
124    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
125  assert(  (info.start_time + info.initial) ==
126    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
127
128  puts( "TA1 - rtems_task_wake_after - 1 second" );
129  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
130  directive_failed( status, "rtems_timer_wake_after" );
131
132  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
133  status = rtems_timer_server_fire_after(
134    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
135  directive_failed( status, "rtems_timer_server_fire_after" );
136
137  status = rtems_timer_get_information( tmid, &info );
138  directive_failed( status, "rtems_timer_get_information" );
139  printf( "Timer 1 scheduled for %d ticks since boot\n",
140    info.start_time + info.initial );
141  printf( "Timer Server scheduled for %d ticks since boot\n",
142    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
143  assert(  (info.start_time + info.initial) ==
144    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
145
146  puts( "TA1 - rtems_timer_cancel - timer 1" );
147  status = rtems_timer_cancel( tmid );
148  directive_failed( status, "rtems_timer_cancel" );
149
150  puts( "TA1 - rtems_timer_cancel - timer 2" );
151  status = rtems_timer_cancel( tmid2 );
152  directive_failed( status, "rtems_timer_cancel" );
153
154/* after which is allowed to fire */
155
156  Print_time();
157
158  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
159  status = rtems_timer_server_fire_after(
160    tmid,
161    3 * TICKS_PER_SECOND,
162    Delayed_resume,
163    NULL
164  );
165  directive_failed( status, "rtems_timer_server_fire_after" );
166
167  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
168  status = rtems_task_suspend( RTEMS_SELF );
169  directive_failed( status, "rtems_task_suspend" );
170
171  Print_time();
172
173/* after which is reset and allowed to fire */
174
175  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
176  status = rtems_timer_server_fire_after(
177    tmid,
178    3 * TICKS_PER_SECOND,
179    Delayed_resume,
180    NULL
181  );
182  directive_failed( status, "rtems_timer_server_fire_after" );
183
184  puts( "TA1 - rtems_task_wake_after - 1 second" );
185  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
186  directive_failed( status, "rtems_task_wake_after" );
187
188  Print_time();
189
190  puts( "TA1 - rtems_timer_reset - timer 1" );
191  status = rtems_timer_reset( tmid );
192  directive_failed( status, "rtems_timer_reset" );
193
194  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
195  status = rtems_task_suspend( RTEMS_SELF );
196  directive_failed( status, "rtems_task_suspend" );
197
198  Print_time();
199
200  rtems_test_pause();
201
202  /*
203   *  Reset the time since we do not know how long the user waited
204   *  before pressing <cr> at the pause.  This insures that the
205   *  actual output matches the screen.
206   */
207
208  build_time( &time, 12, 31, 1988, 9, 0, 7, 0 );
209
210  status = rtems_clock_set( &time );
211  directive_failed( status, "rtems_clock_set" );
212
213/* after which is canceled */
214
215  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
216  status = rtems_timer_server_fire_after(
217    tmid,
218    3 * TICKS_PER_SECOND,
219    Delayed_resume,
220    NULL
221  );
222  directive_failed( status, "rtems_timer_server_fire_after" );
223
224  puts( "TA1 - rtems_timer_cancel - timer 1" );
225  status = rtems_timer_cancel( tmid );
226  directive_failed( status, "rtems_timer_cancel" );
227
228/* when which is allowed to fire */
229
230  Print_time();
231
232  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
233  directive_failed( status, "rtems_clock_get" );
234
235  time.second += 3;
236
237  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
238  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
239  directive_failed( status, "rtems_timer_server_fire_when" );
240
241  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
242  status = rtems_task_suspend( RTEMS_SELF );
243  directive_failed( status, "rtems_task_suspend" );
244
245  Print_time();
246
247/* when which is canceled */
248
249  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
250  directive_failed( status, "rtems_clock_get" );
251
252  time.second += 3;
253
254  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
255  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
256  directive_failed( status, "rtems_timer_server_fire_when" );
257
258  puts( "TA1 - rtems_task_wake_after - 1 second" );
259  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
260  directive_failed( status, "rtems_task_wake_after" );
261
262  Print_time();
263
264  puts( "TA1 - rtems_timer_cancel - timer 1" );
265  status = rtems_timer_cancel( tmid );
266  directive_failed( status, "rtems_timer_cancel" );
267
268/* delete */
269  puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" );
270  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
271  directive_failed( status, "rtems_task_wake_after" );
272
273  puts( "TA1 - timer_deleting - timer 1" );
274  status = rtems_timer_delete( tmid );
275  directive_failed( status, "rtems_timer_delete" );
276
277  puts( "*** END OF TEST 31 *** " );
278  rtems_test_exit( 0 );
279}
Note: See TracBrowser for help on using the repository browser.