source: rtems/testsuites/sptests/sp37/init.c @ b84f1fdc

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

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: 7.8 KB
Line 
1/*
2 *  Interrupt Disable/Enable Tests
3 *  Clock Tick from task level
4 *
5 *  COPYRIGHT (c) 1989-2009.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
16#define CONFIGURE_INIT
17#include "system.h"
18
19/* prototypes */
20void test_interrupt_inline(void);
21void check_isr_in_progress_inline(void);
22rtems_task blocked_task(rtems_task_argument argument);
23rtems_timer_service_routine test_unblock_task(
24  rtems_id  timer,
25  void     *arg
26);
27rtems_timer_service_routine test_unblock_task(
28  rtems_id  timer,
29  void     *arg
30);
31void check_isr_worked(
32  char *s,
33  int   result
34);
35rtems_timer_service_routine test_isr_in_progress(
36  rtems_id  timer,
37  void     *arg
38);
39
40/* test bodies */
41void test_interrupt_inline(void)
42{
43  rtems_interrupt_level level;
44  rtems_attribute level_attribute, level_attribute_macro;
45  bool                  in_isr;
46
47  puts( "interrupt is in progress (use body)" );
48  in_isr = rtems_interrupt_is_in_progress();
49  if ( in_isr ) {
50    puts( "interrupt reported to be is in progress (body)" );
51    rtems_test_exit( 0 );
52  }
53
54  puts( "interrupt disable (use inline)" );
55  rtems_interrupt_disable( level );
56
57  puts( "interrupt flash (use inline)" );
58  rtems_interrupt_flash( level );
59
60  puts( "interrupt enable (use inline)" );
61  rtems_interrupt_enable( level );
62 
63  puts( "interrupt level attribute (use inline)" );
64  level_attribute = rtems_interrupt_level_attribute( level );
65  level_attribute_macro = RTEMS_INTERRUPT_LEVEL(level);
66  if ( level_attribute_macro == level_attribute ) {
67    puts( "test case working.." );
68  }
69}
70
71volatile int isr_in_progress_body;
72volatile int isr_in_progress_inline;
73
74void check_isr_in_progress_inline(void)
75{
76  bool in_isr;
77
78  in_isr = rtems_interrupt_is_in_progress();
79  isr_in_progress_inline = ( in_isr ) ? 1 : 2;
80}
81
82#undef rtems_interrupt_disable
83#undef rtems_interrupt_enable
84#undef rtems_interrupt_flash
85#undef rtems_interrupt_is_in_progress
86
87rtems_timer_service_routine test_isr_in_progress(
88  rtems_id  timer,
89  void     *arg
90)
91{
92  bool in_isr;
93
94  check_isr_in_progress_inline();
95
96  in_isr = rtems_interrupt_is_in_progress();
97  isr_in_progress_body = ( in_isr ) ? 1 : 2;
98}
99
100void check_isr_worked(
101  char *s,
102  int   result
103)
104{
105  switch (result) {
106    case -1:
107      printf( "isr_in_progress(%s) timer did not fire\n", s );
108      break;
109    case 1:
110      printf( "isr_in_progress(%s) from ISR -- OK\n", s );
111      break;
112    case 2:
113      printf( "isr_in_progress(%s) from ISR -- returned bad value\n");
114      rtems_test_exit(0);
115      break;
116  }
117}
118
119volatile int blocked_task_status;
120rtems_id     blocked_task_id;
121
122rtems_task blocked_task(
123  rtems_task_argument argument
124)
125{
126  rtems_status_code     status;
127
128  puts( "Blocking task... suspending self" );
129  blocked_task_status = 1;
130  status = rtems_task_suspend( RTEMS_SELF );
131  directive_failed( status, "rtems_task_suspend" );
132
133  blocked_task_status = 3;
134  status = rtems_task_delete( RTEMS_SELF );
135  directive_failed( status, "rtems_task_delete" );
136}
137
138/*
139 *  Timer Service Routine
140 *
141 *  If we are in an ISR, then this is a normal clock tick.
142 *  If we are not, then it is the test case.
143 */
144rtems_timer_service_routine test_unblock_task(
145  rtems_id  timer,
146  void     *arg
147)
148{
149  bool              in_isr;
150  rtems_status_code status;
151
152  in_isr = rtems_interrupt_is_in_progress();
153  status = rtems_task_is_suspended( blocked_task_id );
154  if ( in_isr ) {
155    status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL );
156    directive_failed( status, "timer_fire_after failed" );
157    return;
158  }
159
160  if ( (status != RTEMS_ALREADY_SUSPENDED) ) {
161    status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL );
162    directive_failed( status, "timer_fire_after failed" );
163    return;
164  } 
165
166  blocked_task_status = 2;
167  _Thread_Disable_dispatch();
168  status = rtems_task_resume( blocked_task_id );
169  _Thread_Unnest_dispatch();
170  directive_failed( status, "rtems_task_resume" );
171}
172
173rtems_task Init(
174  rtems_task_argument argument
175)
176{
177  rtems_time_of_day     time;
178  rtems_status_code     status;
179  rtems_interrupt_level level;
180  rtems_attribute level_attribute,level_attribute_macro;
181  bool                  in_isr;
182  rtems_id              timer;
183  int                   i;
184
185  puts( "\n\n*** TEST 37 ***" );
186
187  build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
188  status = rtems_clock_set( &time );
189  directive_failed( status, "rtems_clock_set" );
190
191  /*
192   *  Timer used in multiple ways
193   */
194  status = rtems_timer_create( 1, &timer );
195  directive_failed( status, "rtems_timer_create" );
196
197  /*
198   *  Test clock tick from outside ISR
199   */
200  status = rtems_clock_tick();
201  directive_failed( status, "rtems_clock_tick" );
202  puts( "clock_tick from task level" );
203
204  /*
205   *  Now do a dispatch directly out of a clock tick that is
206   *  called from a task.  We need to create a task that will
207   *  block so we have one to unblock.  Then we schedule a TSR
208   *  to run in the clock tick but it has to be careful to
209   *  make sure it is not called from an ISR and that the
210   *  dispatching critical section is managed properly to
211   *  make the dispatch happen.
212   */
213
214  blocked_task_status = -1;
215
216  status = rtems_task_create(
217    rtems_build_name( 'T', 'A', '1', ' ' ),
218    1,
219    RTEMS_MINIMUM_STACK_SIZE,
220    RTEMS_DEFAULT_MODES,
221    RTEMS_DEFAULT_ATTRIBUTES,
222    &blocked_task_id
223  );
224  directive_failed( status, "rtems_task_create" );
225
226  status = rtems_task_start( blocked_task_id, blocked_task, 0 );
227  directive_failed( status, "rtems_task_start" );
228
229  status = rtems_task_wake_after( 10 );
230  directive_failed( status, "rtems_task_wake_after" );
231
232  status = rtems_timer_fire_after( timer, 1, test_unblock_task, NULL );
233  directive_failed( status, "timer_fire_after failed" );
234
235  /* we expect to be preempted from this call */
236  for ( i=0 ; i<100 && blocked_task_status != 3 ; i++ ) {
237    status = rtems_clock_tick();
238    directive_failed( status, "rtems_clock_tick" );
239  }
240  switch ( blocked_task_status ) {
241     case -1:
242       puts( "clock_tick with task preempt -- task blocked, timer did not fire" );
243       rtems_test_exit(0);
244       break;
245     case 1:
246       puts( "clock_tick with task preempt -- timer fired case 1" );
247       rtems_test_exit(0);
248       break;
249     case 2:
250       puts( "clock_tick with task preempt -- timer fired case 2" );
251       rtems_test_exit(0);
252       break;
253     case 3:
254       puts( "clock_tick from task level with preempt -- OK" );
255       break;
256  }
257
258  /*
259   *  Test interrupt inline versions
260   */
261  test_interrupt_inline();
262
263  /*
264   *  Test interrupt bodies
265   */
266  puts( "interrupt is in progress (use body)" );
267  in_isr = rtems_interrupt_is_in_progress();
268  if ( in_isr ) {
269    puts( "interrupt reported to be is in progress (body)" );
270    rtems_test_exit( 0 );
271  }
272
273  puts( "interrupt disable (use body)" );
274  level = rtems_interrupt_disable();
275
276  puts( "interrupt disable (use body)" );
277  level = rtems_interrupt_disable();
278
279  puts( "interrupt flash (use body)" );
280  rtems_interrupt_flash( level );
281
282  puts( "interrupt enable (use body)" );
283  rtems_interrupt_enable( level );
284 
285  puts( "interrupt level attribute (use body)" );
286  level_attribute = rtems_interrupt_level_attribute( level );
287  level_attribute_macro = RTEMS_INTERRUPT_LEVEL(level);
288  if ( level_attribute_macro == level_attribute ) {
289    puts("test seems to work");
290  }
291
292  /*
293   * Test ISR in progress from actual ISR
294   */
295  isr_in_progress_body   = -1;
296  isr_in_progress_inline = -1;
297
298  status = rtems_timer_fire_after( timer, 10, test_isr_in_progress, NULL );
299  directive_failed( status, "timer_fire_after failed" );
300
301  status = rtems_task_wake_after( 100 );
302  directive_failed( status, "wake_after failed" );
303 
304  check_isr_worked( "inline", isr_in_progress_body );
305
306  check_isr_worked( "body", isr_in_progress_body );
307
308
309  puts( "*** END OF TEST 37 ***" );
310  rtems_test_exit( 0 );
311}
Note: See TracBrowser for help on using the repository browser.