source: rtems/testsuites/sptests/sp41/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: 4.9 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define CONFIGURE_INIT
15#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
16#include "system.h"
17
18volatile bool case_hit;
19
20rtems_id main_task;
21rtems_id Semaphore;
22
23/* prototypes */
24Thread_blocking_operation_States getState(void);
25rtems_timer_service_routine test_release_from_isr(
26  rtems_id  timer,
27  void     *arg
28);
29rtems_timer_service_routine test_release_with_timeout_from_isr(
30  rtems_id  timer,
31  void     *arg
32);
33
34Thread_blocking_operation_States getState(void)
35{
36  Objects_Locations  location;
37  Semaphore_Control *sem;
38
39  sem = (Semaphore_Control *)_Objects_Get(
40    &_Semaphore_Information, Semaphore, &location ); 
41  if ( location != OBJECTS_LOCAL ) {
42    puts( "Bad object lookup" );
43    rtems_test_exit(0);
44  }
45  _Thread_Unnest_dispatch();
46
47  return sem->Core_control.semaphore.Wait_queue.sync_state;
48}
49
50rtems_timer_service_routine test_release_from_isr(
51  rtems_id  timer,
52  void     *arg
53)
54{
55  rtems_status_code     status;
56
57  if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
58    case_hit = TRUE;
59  }
60  status = rtems_semaphore_release( Semaphore );
61}
62
63rtems_timer_service_routine test_release_with_timeout_from_isr(
64  rtems_id  timer,
65  void     *arg
66)
67{
68  rtems_status_code     status;
69
70  if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
71    /*
72     *  We want to catch the task while it is blocking.  Otherwise
73     *  just send and make it happy.
74     */
75    case_hit = TRUE;
76  }
77  status = rtems_semaphore_release( Semaphore );
78}
79
80rtems_task Init(
81  rtems_task_argument argument
82)
83{
84  rtems_status_code     status;
85  rtems_id              timer;
86  int                   i;
87  int                   max;
88  uint32_t              iterations = 0;
89
90  puts( "\n\n*** TEST 41 ***" );
91
92  main_task = rtems_task_self();
93
94  /*
95   *  Timer used in multiple ways
96   */
97  status = rtems_timer_create( 1, &timer );
98  directive_failed( status, "rtems_timer_create" );
99
100  status = rtems_semaphore_create(
101    rtems_build_name( 'S', 'M', '1', ' ' ),
102    1,
103    RTEMS_DEFAULT_ATTRIBUTES,
104    RTEMS_NO_PRIORITY,
105    &Semaphore
106  );
107  directive_failed( status, "rtems_semaphore_create of SM1" );
108
109  /*
110   * Test semaphore release successful from ISR -- obtain is forever
111   */
112  case_hit = FALSE;
113  iterations = 0;
114  max = 1;
115
116  while (1) {
117    if ( case_hit )
118      break;
119    status = rtems_timer_fire_after( timer, 1, test_release_from_isr, NULL );
120    directive_failed( status, "timer_fire_after failed" );
121
122    for (i=0 ; i<max ; i++ )
123      if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED )
124        break;
125
126    status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 );
127    directive_failed( status, "rtems_semaphore_obtain" );
128    if ( case_hit == TRUE )
129      break;
130    max += 2;
131
132    /* with our clock tick, this is about 30 seconds */
133    if ( ++iterations >= 4L * 1000L * 30L)
134      break;
135  }
136
137  status = rtems_semaphore_release( Semaphore );
138  directive_failed( status, "rtems_semaphore_release" );
139  printf(
140    "Release from ISR hitting synchronization point has %soccurred\n",
141    (( case_hit == TRUE ) ? "" : "NOT ")
142  ); 
143
144  /*
145   * Test semaphore release successful from ISR -- obtain has timeout
146   */
147  case_hit = FALSE;
148  iterations = 0;
149  max = 1;
150
151  while (1) {
152    if ( case_hit )
153      break;
154    status = rtems_timer_fire_after(
155      timer, 1, test_release_with_timeout_from_isr, NULL );
156    directive_failed( status, "timer_fire_after failed" );
157
158    for (i=0 ; i<max ; i++ )
159      if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED )
160        break;
161
162    status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 10 );
163    directive_failed( status, "rtems_semaphore_obtain" );
164    if ( case_hit == TRUE )
165      break;
166    max += 2;
167
168    /* with our clock tick, this is about 30 seconds */
169    if ( ++iterations >= 4L * 1000L * 30L)
170      break;
171  }
172
173  printf(
174    "Release from ISR (with timeout) hitting synchronization "
175      "point has %soccurred\n",
176    (( case_hit == TRUE ) ? "" : "NOT ")
177  ); 
178
179  /*
180   *  Now try for a timeout case -- semaphore must not be available
181   */
182  iterations = 0;
183  case_hit = FALSE;
184  max = 1;
185
186  puts(
187    "Run multiple times in attempt to hit threadq timeout synchronization point"
188  ); 
189  while (1) {
190
191    for (i=0 ; i<max ; i++ )
192      if ( getState() == THREAD_BLOCKING_OPERATION_SATISFIED )
193        break;
194
195    status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 1 );
196    fatal_directive_status( status, RTEMS_TIMEOUT, "rtems_semaphore_obtain" );
197
198    if ( ++max > 10240 )
199      max = 0;
200
201    /* with our clock tick, this is about 30 seconds */
202    if ( ++iterations >= 4L * 1000L * 30L)
203      break;
204  }
205
206  puts( "*** END OF TEST 41 ***" );
207  rtems_test_exit( 0 );
208}
Note: See TracBrowser for help on using the repository browser.