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

4.104.114.84.95
Last change on this file since ef70d9b was ef70d9b, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/02 at 18:20:59

2001-01-29 Joel Sherrill <joel@…>

  • Fixed bug where resetting a timer that was not at the head of one of the task timer chains resulted in the Timer Server task waking up too far in the future.
  • Added rtems_timer_get_information() directive to support testing.
  • sp31/init.c, sp31/system.h, sp31/task1.c: Modified to test for above condition.
  • Property mode set to 100644
File size: 7.5 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-2002.
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.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include "system.h"
22
23rtems_task Task_1(
24  rtems_task_argument argument
25)
26{
27  rtems_id                 tmid;
28  rtems_id                 tmid2;
29  rtems_time_of_day        time;
30  rtems_status_code        status;
31  rtems_timer_information  info;
32
33/* Get id */
34
35  puts( "TA1 - rtems_timer_ident - identing timer 1" );
36  status = rtems_timer_ident( Timer_name[ 1 ], &tmid );
37  directive_failed( status, "rtems_timer_ident" );
38  printf( "TA1 - timer 1 has id (0x%x)\n", tmid );
39
40  puts( "TA1 - rtems_timer_ident - identing timer 2" );
41  status = rtems_timer_ident( Timer_name[ 2 ], &tmid2 );
42  directive_failed( status, "rtems_timer_ident" );
43  printf( "TA1 - timer 2 has id (0x%x)\n", tmid2 );
44
45/* now check that rescheduling an active timer works OK. */
46  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 30 seconds" );
47  status = rtems_timer_server_fire_after(
48    tmid, 30 * TICKS_PER_SECOND, Delayed_resume, NULL );
49  directive_failed( status, "rtems_timer_server_fire_after" );
50
51  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
52  status = rtems_timer_server_fire_after(
53    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
54  directive_failed( status, "rtems_timer_server_fire_after" );
55
56  status = rtems_timer_get_information( tmid, &info );
57  printf( "Timer 1 scheduled for %d ticks since boot\n",
58    info.start_time + info.initial );
59  printf( "Timer Server scheduled for %d ticks since boot\n",
60    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
61
62  puts( "TA1 - rtems_task_wake_after - 1 second" );
63  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
64  directive_failed( status, "rtems_timer_wake_after" );
65
66  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
67  status = rtems_timer_server_fire_after(
68    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
69  directive_failed( status, "rtems_timer_server_fire_after" );
70
71  status = rtems_timer_get_information( tmid, &info );
72  directive_failed( status, "rtems_timer_get_information" );
73  printf( "Timer 1 scheduled for %d ticks since boot\n",
74    info.start_time + info.initial );
75  printf( "Timer Server scheduled for %d ticks since boot\n",
76    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
77  assert(  (info.start_time + info.initial) ==
78    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
79
80  puts( "TA1 - rtems_task_wake_after - 1 second" );
81  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
82  directive_failed( status, "rtems_timer_wake_after" );
83
84  puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
85  status = rtems_timer_server_fire_after(
86    tmid2, 60 * TICKS_PER_SECOND, Delayed_resume, NULL );
87  directive_failed( status, "rtems_timer_server_fire_after" );
88
89  status = rtems_timer_get_information( tmid, &info );
90  directive_failed( status, "rtems_timer_get_information" );
91  printf( "Timer 1 scheduled for %d ticks since boot\n",
92    info.start_time + info.initial );
93  printf( "Timer Server scheduled for %d ticks since boot\n",
94    _Timer_Server->Timer.initial + _Timer_Server->Timer.start_time );
95  assert(  (info.start_time + info.initial) ==
96    (_Timer_Server->Timer.initial + _Timer_Server->Timer.start_time) );
97
98  puts( "TA1 - rtems_timer_cancel - timer 1" );
99  status = rtems_timer_cancel( tmid );
100  directive_failed( status, "rtems_timer_cancel" );
101
102  puts( "TA1 - rtems_timer_cancel - timer 2" );
103  status = rtems_timer_cancel( tmid2 );
104  directive_failed( status, "rtems_timer_cancel" );
105
106/* after which is allowed to fire */
107
108  Print_time();
109
110  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
111  status = rtems_timer_server_fire_after(
112    tmid,
113    3 * TICKS_PER_SECOND,
114    Delayed_resume,
115    NULL
116  );
117  directive_failed( status, "rtems_timer_server_fire_after" );
118
119  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
120  status = rtems_task_suspend( RTEMS_SELF );
121  directive_failed( status, "rtems_task_suspend" );
122
123  Print_time();
124
125/* after which is reset and allowed to fire */
126
127  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
128  status = rtems_timer_server_fire_after(
129    tmid,
130    3 * TICKS_PER_SECOND,
131    Delayed_resume,
132    NULL
133  );
134  directive_failed( status, "rtems_timer_server_fire_after" );
135
136  puts( "TA1 - rtems_task_wake_after - 1 second" );
137  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
138  directive_failed( status, "rtems_task_wake_after" );
139
140  Print_time();
141
142  puts( "TA1 - rtems_timer_reset - timer 1" );
143  status = rtems_timer_reset( tmid );
144  directive_failed( status, "rtems_timer_reset" );
145
146  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
147  status = rtems_task_suspend( RTEMS_SELF );
148  directive_failed( status, "rtems_task_suspend" );
149
150  Print_time();
151
152  rtems_test_pause();
153
154  /*
155   *  Reset the time since we do not know how long the user waited
156   *  before pressing <cr> at the pause.  This insures that the
157   *  actual output matches the screen.
158   */
159
160  build_time( &time, 12, 31, 1988, 9, 0, 7, 0 );
161
162  status = rtems_clock_set( &time );
163  directive_failed( status, "rtems_clock_set" );
164
165/* after which is canceled */
166
167  puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
168  status = rtems_timer_server_fire_after(
169    tmid,
170    3 * TICKS_PER_SECOND,
171    Delayed_resume,
172    NULL
173  );
174  directive_failed( status, "rtems_timer_server_fire_after" );
175
176  puts( "TA1 - rtems_timer_cancel - timer 1" );
177  status = rtems_timer_cancel( tmid );
178  directive_failed( status, "rtems_timer_cancel" );
179
180/* when which is allowed to fire */
181
182  Print_time();
183
184  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
185  directive_failed( status, "rtems_clock_get" );
186
187  time.second += 3;
188
189  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
190  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
191  directive_failed( status, "rtems_timer_server_fire_when" );
192
193  puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
194  status = rtems_task_suspend( RTEMS_SELF );
195  directive_failed( status, "rtems_task_suspend" );
196
197  Print_time();
198
199/* when which is canceled */
200
201  status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time );
202  directive_failed( status, "rtems_clock_get" );
203
204  time.second += 3;
205
206  puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
207  status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
208  directive_failed( status, "rtems_timer_server_fire_when" );
209
210  puts( "TA1 - rtems_task_wake_after - 1 second" );
211  status = rtems_task_wake_after( 1 * TICKS_PER_SECOND );
212  directive_failed( status, "rtems_task_wake_after" );
213
214  Print_time();
215
216  puts( "TA1 - rtems_timer_cancel - timer 1" );
217  status = rtems_timer_cancel( tmid );
218  directive_failed( status, "rtems_timer_cancel" );
219
220/* delete */
221  puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" );
222  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
223  directive_failed( status, "rtems_task_wake_after" );
224
225  puts( "TA1 - timer_deleting - timer 1" );
226  status = rtems_timer_delete( tmid );
227  directive_failed( status, "rtems_timer_delete" );
228
229  puts( "*** END OF TEST 31 *** " );
230  exit( 0 );
231}
Note: See TracBrowser for help on using the repository browser.