source: rtems/testsuites/sptests/sp39/init.c @ 3168deaa

4.104.114.95
Last change on this file since 3168deaa was 265d9b64, checked in by Joel Sherrill <joel.sherrill@…>, on 01/22/08 at 14:46:13

2008-01-22 Joel Sherrill <joel.sherrill@…>

  • sp39/init.c: Modify to improve coverage.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2007.
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 TEST_INIT
15#include "system.h"
16
17volatile boolean case_hit;
18
19rtems_id main_task;
20rtems_id other_task;
21
22rtems_timer_service_routine test_event_from_isr(
23  rtems_id  timer,
24  void     *arg
25)
26{
27  rtems_status_code     status;
28
29  if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
30    /*
31     *  This event send hits the critical section but sends to
32     *  another task so doesn't impact this critical section.
33     */
34    rtems_event_send( other_task, 0x02 );
35
36    /*
37     *  This event send hits the main task but doesn't satisfy
38     *  it's blocking condition so it will still block
39     */
40    rtems_event_send( main_task, 0x02 );
41
42    case_hit = TRUE;
43  }
44  status = rtems_event_send( main_task, 0x01 );
45}
46
47rtems_task Init(
48  rtems_task_argument argument
49)
50{
51  rtems_status_code     status;
52  rtems_id              timer;
53  rtems_event_set       out;
54  int                   i;
55  int                   max;
56  int                   iterations = 0;
57
58  puts( "\n\n*** TEST 39 ***" );
59
60  main_task = rtems_task_self();
61
62  /*
63   *  Timer used in multiple ways
64   */
65  status = rtems_timer_create( 1, &timer );
66  directive_failed( status, "rtems_timer_create" );
67
68  status = rtems_task_create(
69     0xa5a5a5a5,
70     1,
71     RTEMS_MINIMUM_STACK_SIZE,
72     RTEMS_DEFAULT_MODES,
73     RTEMS_DEFAULT_ATTRIBUTES,
74     &other_task
75  );
76  directive_failed( status, "rtems_task_create" );
77
78  /*
79   * Test Event send successful from ISR
80   */
81  case_hit = FALSE;
82  max = 1;
83
84  while (1) {
85    if ( case_hit )
86      break;
87    status = rtems_timer_fire_after( timer, 1, test_event_from_isr, NULL );
88    directive_failed( status, "timer_fire_after failed" );
89
90    for (i=0 ; i<max ; i++ )
91      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
92        break;
93
94    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
95    directive_failed( status, "rtems_event_receive" );
96    if ( case_hit == TRUE )
97      break;
98    max += 2;
99  }
100
101   printf(
102     "Event sent from ISR hitting synchronization point has %soccurred\n",
103     (( case_hit == TRUE ) ? "" : "NOT ")
104  );
105
106  /*
107   *  Now try for a timeout case
108   */
109  iterations = 0;
110  case_hit = FALSE;
111  max = 1;
112
113  puts(
114    "Run multiple times in attempt to hit event timeout synchronization point"
115  );
116  while (1) {
117
118    for (i=0 ; i<max ; i++ )
119      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
120        break;
121
122    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
123    fatal_directive_status( status, RTEMS_TIMEOUT, "event_receive timeout" );
124    if ( case_hit )
125      break;
126
127    if ( ++max > 1024 )
128      max = 0;
129
130    if ( ++iterations >= 0x1000 )
131      break;
132  }
133
134  puts( "*** END OF TEST 39 ***" );
135  rtems_test_exit( 0 );
136}
Note: See TracBrowser for help on using the repository browser.