source: rtems/testsuites/sptests/spintrcritical21/init.c @ af43554

5
Last change on this file since af43554 was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:11

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2011.
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.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#define CONFIGURE_INIT
17#include "system.h"
18
19#include <intrcritical.h>
20
21#include <rtems/score/threadimpl.h>
22#include <rtems/rtems/eventimpl.h>
23
24const char rtems_test_name[] = "SPINTRCRITICAL 21";
25
26/*
27 *  ERROR CHECKING NOTE:
28 *
29 *  We are either at dispatch disable level 1 or 2.  Either way, it is
30 *  safer not to check the dispatch level explicitly so we are using
31 *  fatal_directive_check_status_only() not directive_failed().
32 */
33
34static volatile bool case_hit;
35
36static rtems_id main_task;
37
38static Thread_Control *main_thread;
39
40static rtems_id other_task;
41
42static bool is_case_hit( void )
43{
44  return _Thread_Wait_flags_get( main_thread)
45    == ( THREAD_WAIT_CLASS_EVENT | THREAD_WAIT_STATE_INTEND_TO_BLOCK );
46}
47
48static rtems_timer_service_routine test_event_from_isr(
49  rtems_id  timer,
50  void     *arg
51)
52{
53  rtems_status_code     status;
54
55  if ( is_case_hit() ) {
56    /*
57     *  This event send hits the critical section but sends to
58     *  another task so doesn't impact this critical section.
59     */
60    status = rtems_event_send( other_task, 0x02 );
61    fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
62
63    /*
64     *  This event send hits the main task but doesn't satisfy
65     *  it's blocking condition so it will still block
66     */
67    status = rtems_event_send( main_task, 0x02 );
68    fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
69
70    case_hit = true;
71  }
72  status = rtems_event_send( main_task, 0x01 );
73  fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
74}
75
76static bool test_body_event_from_isr( void *arg )
77{
78  rtems_status_code status;
79  rtems_event_set   out;
80
81  (void) arg;
82
83  status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
84  rtems_test_assert( status == RTEMS_SUCCESSFUL );
85
86  return case_hit;
87}
88
89static rtems_timer_service_routine test_event_with_timeout_from_isr(
90  rtems_id  timer,
91  void     *arg
92)
93{
94  rtems_status_code     status;
95
96  if ( is_case_hit() ) {
97    /*
98     *  We want to catch the task while it is blocking.  Otherwise
99     *  just send and make it happy.
100     */
101    case_hit = true;
102  }
103  status = rtems_event_send( main_task, 0x01 );
104  fatal_directive_check_status_only( status, RTEMS_SUCCESSFUL, "event send" );
105}
106
107static bool test_body_event_with_timeout_from_isr( void *arg )
108{
109  rtems_status_code status;
110  rtems_event_set   out;
111
112  (void) arg;
113
114  status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
115  rtems_test_assert( status == RTEMS_SUCCESSFUL || status == RTEMS_TIMEOUT );
116
117  return case_hit;
118}
119
120rtems_task Init(
121  rtems_task_argument argument
122)
123{
124  rtems_status_code     status;
125
126  TEST_BEGIN();
127
128  main_task = rtems_task_self();
129  main_thread = _Thread_Get_executing();
130
131  status = rtems_task_create(
132    0xa5a5a5a5,
133    1,
134    RTEMS_MINIMUM_STACK_SIZE,
135    RTEMS_DEFAULT_MODES,
136    RTEMS_DEFAULT_ATTRIBUTES,
137    &other_task
138  );
139  directive_failed( status, "rtems_task_create" );
140
141  /*
142   * Test Event send successful from ISR -- receive is forever
143   */
144
145  case_hit = false;
146  interrupt_critical_section_test(
147    test_body_event_from_isr,
148    NULL,
149    test_event_from_isr
150  );
151
152  printf(
153    "Event sent from ISR hitting synchronization point has %soccurred\n",
154    case_hit ? "" : "NOT "
155  );
156
157  rtems_test_assert( case_hit );
158
159  /*
160   * Test Event send successful from ISR -- receive has timeout
161   */
162
163  case_hit = false;
164  interrupt_critical_section_test(
165    test_body_event_with_timeout_from_isr,
166    NULL,
167    test_event_with_timeout_from_isr
168  );
169
170  printf(
171    "Event sent from ISR (with timeout) hitting synchronization "
172      "point has %soccurred\n",
173    case_hit ? "" : "NOT "
174  );
175
176  rtems_test_assert( case_hit );
177
178  TEST_END();
179  rtems_test_exit( 0 );
180}
Note: See TracBrowser for help on using the repository browser.