source: rtems/testsuites/sptests/spintrcritical10/init.c @ ae75429

4.115
Last change on this file since ae75429 was ae75429, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 6, 2013 at 2:10:26 PM

PR766: Delete RTEMS_VIOLATE_KERNEL_VISIBILITY

  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  Copyright (c) 2013 embedded brains GmbH.
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
12#ifdef HAVE_CONFIG_H
13  #include "config.h"
14#endif
15
16#include <tmacros.h>
17#include <intrcritical.h>
18
19#include <rtems/rtems/eventimpl.h>
20
21#define GREEN RTEMS_EVENT_0
22
23#define RED RTEMS_EVENT_1
24
25#define EVENTS (GREEN | RED)
26
27#define DEADBEEF 0xdeadbeef
28
29typedef struct {
30  rtems_id timer;
31  Thread_Control *thread;
32  bool hit;
33} test_context;
34
35static void any_satisfy_before_timeout(rtems_id timer, void *arg)
36{
37  rtems_status_code sc;
38  test_context *ctx = arg;
39  const Thread_Control *thread = ctx->thread;
40
41  if (thread->Wait.count != 0) {
42    ctx->hit = _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
43
44    rtems_test_assert(thread->Wait.count == EVENTS);
45    rtems_test_assert(
46      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
47    );
48    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
49
50    sc = rtems_event_send(thread->Object.id, GREEN);
51    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
52
53    rtems_test_assert(thread->Wait.count == 0);
54    rtems_test_assert(
55      *(rtems_event_set *) thread->Wait.return_argument == GREEN
56    );
57    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
58
59    sc = rtems_event_send(thread->Object.id, RED);
60    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
61
62    rtems_test_assert(thread->Wait.count == 0);
63    rtems_test_assert(
64      *(rtems_event_set *) thread->Wait.return_argument == GREEN
65    );
66    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
67
68    _Event_Timeout(thread->Object.id, &_Event_Sync_state);
69
70    rtems_test_assert(thread->Wait.count == 0);
71    rtems_test_assert(
72      *(rtems_event_set *) thread->Wait.return_argument == GREEN
73    );
74    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
75
76    if (ctx->hit) {
77      rtems_test_assert(
78        _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED
79      );
80    }
81  }
82
83  sc = rtems_timer_reset(timer);
84  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
85}
86
87static void test_any_satisfy_before_timeout(test_context *ctx)
88{
89  rtems_status_code sc;
90  int resets = 0;
91
92  puts(
93    "Init - Trying to generate any satisfied before timeout "
94    "while blocking on event"
95  );
96
97  ctx->hit = false;
98
99  interrupt_critical_section_test_support_initialize(NULL);
100
101  sc = rtems_timer_fire_after(ctx->timer, 1, any_satisfy_before_timeout, ctx);
102  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
103
104  while (!ctx->hit && resets < 2) {
105    rtems_event_set out;
106
107    if (interrupt_critical_section_test_support_delay())
108      resets++;
109
110    out = DEADBEEF;
111    sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ANY | RTEMS_WAIT, 1, &out);
112    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
113    rtems_test_assert(out == GREEN);
114
115    out = DEADBEEF;
116    sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, 0, &out);
117    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
118    rtems_test_assert(out == RED);
119  }
120
121  sc = rtems_timer_cancel(ctx->timer);
122  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
123
124  rtems_test_assert(ctx->hit);
125}
126
127static void all_satisfy_before_timeout(rtems_id timer, void *arg)
128{
129  rtems_status_code sc;
130  test_context *ctx = arg;
131  const Thread_Control *thread = ctx->thread;
132
133  if (thread->Wait.count != 0) {
134    ctx->hit = _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
135
136    rtems_test_assert(thread->Wait.count == EVENTS);
137    rtems_test_assert(
138      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
139    );
140    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
141
142    sc = rtems_event_send(thread->Object.id, GREEN);
143    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
144
145    rtems_test_assert(thread->Wait.count == EVENTS);
146    rtems_test_assert(
147      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
148    );
149    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
150
151    sc = rtems_event_send(thread->Object.id, RED);
152    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
153
154    rtems_test_assert(thread->Wait.count == 0);
155    rtems_test_assert(
156      *(rtems_event_set *) thread->Wait.return_argument == EVENTS
157    );
158    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
159
160    _Event_Timeout(thread->Object.id, &_Event_Sync_state);
161
162    rtems_test_assert(thread->Wait.count == 0);
163    rtems_test_assert(
164      *(rtems_event_set *) thread->Wait.return_argument == EVENTS
165    );
166    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
167
168    if (ctx->hit) {
169      rtems_test_assert(
170        _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED
171      );
172    }
173  }
174
175  sc = rtems_timer_reset(timer);
176  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
177}
178
179static void test_all_satisfy_before_timeout(test_context *ctx)
180{
181  rtems_status_code sc;
182  int resets = 0;
183
184  puts(
185    "Init - Trying to generate all satisfied before timeout "
186    "while blocking on event"
187  );
188
189  ctx->hit = false;
190
191  interrupt_critical_section_test_support_initialize(NULL);
192
193  sc = rtems_timer_fire_after(ctx->timer, 1, all_satisfy_before_timeout, ctx);
194  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
195
196  while (!ctx->hit && resets < 2) {
197    rtems_event_set out;
198
199    if (interrupt_critical_section_test_support_delay())
200      resets++;
201
202    out = DEADBEEF;
203    sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_WAIT, 1, &out);
204    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
205    rtems_test_assert(out == EVENTS);
206  }
207
208  sc = rtems_timer_cancel(ctx->timer);
209  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
210
211  rtems_test_assert(ctx->hit);
212}
213
214static void timeout_before_satisfied(rtems_id timer, void *arg)
215{
216  rtems_status_code sc;
217  test_context *ctx = arg;
218  const Thread_Control *thread = ctx->thread;
219
220  if (thread->Wait.count != 0) {
221    ctx->hit =
222      _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
223
224    rtems_test_assert(thread->Wait.count == EVENTS);
225    rtems_test_assert(
226      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
227    );
228    rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
229
230    _Event_Timeout(thread->Object.id, &_Event_Sync_state);
231
232    rtems_test_assert(thread->Wait.count == 0);
233    rtems_test_assert(
234      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
235    );
236    rtems_test_assert(thread->Wait.return_code == RTEMS_TIMEOUT);
237
238    sc = rtems_event_send(thread->Object.id, EVENTS);
239    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
240
241    rtems_test_assert(thread->Wait.count == 0);
242    rtems_test_assert(
243      *(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
244    );
245    rtems_test_assert(thread->Wait.return_code == RTEMS_TIMEOUT);
246
247    if (ctx->hit) {
248      rtems_test_assert(
249        _Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT
250      );
251    }
252  }
253
254  sc = rtems_timer_reset(timer);
255  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
256}
257
258static void test_timeout_before_all_satisfy(test_context *ctx)
259{
260  rtems_status_code sc;
261  int resets = 0;
262
263  puts(
264    "Init - Trying to generate timeout before all satisfied "
265    "while blocking on event"
266  );
267
268  ctx->hit = false;
269
270  interrupt_critical_section_test_support_initialize(NULL);
271
272  sc = rtems_timer_fire_after(ctx->timer, 1, timeout_before_satisfied, ctx);
273  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
274
275  while (!ctx->hit && resets < 2) {
276    rtems_event_set out;
277
278    if (interrupt_critical_section_test_support_delay())
279      resets++;
280
281    out = DEADBEEF;
282    sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_WAIT, 1, &out);
283    rtems_test_assert(sc == RTEMS_TIMEOUT);
284    rtems_test_assert(out == DEADBEEF);
285
286    out = DEADBEEF;
287    sc = rtems_event_receive(EVENTS, RTEMS_EVENT_ALL | RTEMS_NO_WAIT, 0, &out);
288    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
289    rtems_test_assert(out == EVENTS);
290  }
291
292  sc = rtems_timer_cancel(ctx->timer);
293  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
294
295  rtems_test_assert(ctx->hit);
296}
297
298static rtems_task Init(
299  rtems_task_argument ignored
300)
301{
302  rtems_status_code sc;
303  test_context ctx = {
304    .thread = _Thread_Get_executing()
305  };
306
307  puts( "\n\n*** TEST INTERRUPT CRITICAL SECTION 10 ***" );
308
309  sc = rtems_timer_create(rtems_build_name('T', 'I', 'M', 'R'), &ctx.timer);
310  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
311
312  test_any_satisfy_before_timeout(&ctx);
313  test_all_satisfy_before_timeout(&ctx);
314  test_timeout_before_all_satisfy(&ctx);
315
316  puts( "*** END OF TEST INTERRUPT CRITICAL SECTION 10 ***" );
317  rtems_test_exit(0);
318}
319
320/* configuration information */
321
322#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
323#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
324
325#define CONFIGURE_MAXIMUM_TASKS       1
326#define CONFIGURE_MAXIMUM_TIMERS      1
327#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
328#define CONFIGURE_MICROSECONDS_PER_TICK  1000
329
330#define CONFIGURE_INIT
331#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.