source: rtems/testsuites/sptests/sp37/init.c @ 9e15e9b

4.115
Last change on this file since 9e15e9b was 9e15e9b, checked in by Joel Sherrill <joel.sherrill@…>, on 07/24/11 at 22:10:20

2011-07-24 Joel Sherrill <joel.sherrill@…>

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