source: rtems/testsuites/sptests/spintrcritical22/init.c @ 73f2ddb

5
Last change on this file since 73f2ddb was 73f2ddb, checked in by Sebastian Huber <sebastian.huber@…>, on 05/30/16 at 08:43:31

rtems: Fix semaphore field name

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <tmacros.h>
20#include <intrcritical.h>
21#include <rtems/rtems/semimpl.h>
22
23const char rtems_test_name[] = "SPINTRCRITICAL 22";
24
25typedef struct {
26  rtems_id semaphore_id;
27  Semaphore_Control *semaphore_control;
28  Thread_Control *main_task_control;
29  volatile bool done;
30} test_context;
31
32static test_context ctx_instance;
33
34static Semaphore_Control *get_semaphore_control(rtems_id id)
35{
36  Thread_queue_Context queue_context;
37  Semaphore_Control *sem;
38
39  sem = _Semaphore_Get(id, &queue_context);
40  rtems_test_assert(sem != NULL);
41  _ISR_lock_ISR_enable(&queue_context.Lock_context);
42
43  return sem;
44}
45
46static void release_semaphore(rtems_id timer, void *arg)
47{
48  /* The arg is NULL */
49  test_context *ctx = &ctx_instance;
50  rtems_status_code sc;
51
52  if (
53    _Thread_Wait_flags_get(ctx->main_task_control)
54      == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK)
55  ) {
56    CORE_semaphore_Control *sem;
57
58    ctx->done = true;
59
60    sc = rtems_semaphore_release(ctx->semaphore_id);
61    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
62
63    rtems_test_assert(
64      _Thread_Wait_flags_get(ctx->main_task_control)
65        == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN)
66    );
67    sem = &ctx->semaphore_control->Core_control.Semaphore;
68    rtems_test_assert(sem->count == 0);
69  } else {
70    sc = rtems_semaphore_release(ctx->semaphore_id);
71    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
72  }
73}
74
75static bool test_body(void *arg)
76{
77  test_context *ctx = arg;
78  rtems_status_code sc;
79
80  sc = rtems_semaphore_obtain(
81    ctx->semaphore_id,
82    RTEMS_NO_WAIT,
83    0
84  );
85  rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_UNSATISFIED);
86
87  sc = rtems_semaphore_obtain(
88    ctx->semaphore_id,
89    RTEMS_WAIT,
90    2
91  );
92  rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT);
93
94  return ctx->done;
95}
96
97static void Init(rtems_task_argument ignored)
98{
99  test_context *ctx = &ctx_instance;
100  rtems_status_code sc;
101
102  TEST_BEGIN();
103
104  ctx->main_task_control = _Thread_Get_executing();
105
106  sc = rtems_semaphore_create(
107    rtems_build_name('S', 'E', 'M', 'A'),
108    1,
109    RTEMS_SIMPLE_BINARY_SEMAPHORE,
110    0,
111    &ctx->semaphore_id
112  );
113  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
114
115  ctx->semaphore_control = get_semaphore_control(ctx->semaphore_id);
116
117  interrupt_critical_section_test(test_body, ctx, release_semaphore);
118  rtems_test_assert(ctx->done);
119
120  TEST_END();
121
122  rtems_test_exit(0);
123}
124
125#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
126#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
127
128#define CONFIGURE_MICROSECONDS_PER_TICK 1000
129
130#define CONFIGURE_MAXIMUM_SEMAPHORES 1
131#define CONFIGURE_MAXIMUM_TASKS 1
132#define CONFIGURE_MAXIMUM_TIMERS 1
133#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
134
135#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
136
137#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
138
139#define CONFIGURE_INIT
140
141#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.