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

4.104.115
Last change on this file since c8633f1 was c8633f1, checked in by Joel Sherrill <joel.sherrill@…>, on 04/20/09 at 15:47:32

2009-04-20 Santosh G Vattam <vattam.santosh@…>

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