source: rtems/testsuites/sptests/sp37/init.c @ 6bc19a1

4.104.114.95
Last change on this file since 6bc19a1 was 6bc19a1, checked in by Joel Sherrill <joel.sherrill@…>, on 12/14/07 at 17:44:15

2007-12-14 Joel Sherrill <joel.sherrill@…>

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