source: rtems/testsuites/sptests/spintrcritical22/init.c @ e266d13

5
Last change on this file since e266d13 was e266d13, checked in by Sebastian Huber <sebastian.huber@…>, on 05/20/16 at 13:10:27

Replace *_Get_interrupt_disable() with *_Get()

Uniformly use *_Get() to get an object by identifier with a lock
context.

  • 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  ISR_lock_Context lock_context;
37  Semaphore_Control *sem;
38
39  sem = _Semaphore_Get(id, &lock_context);
40  rtems_test_assert(sem != NULL);
41  _ISR_lock_ISR_enable(&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  CORE_mutex_Control *mtx = &ctx->semaphore_control->Core_control.mutex;
52
53  if (
54    _Thread_Wait_flags_get(ctx->main_task_control)
55      == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK)
56  ) {
57    ctx->done = true;
58
59    sc = rtems_semaphore_release(ctx->semaphore_id);
60    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
61
62    rtems_test_assert(
63      _Thread_Wait_flags_get(ctx->main_task_control)
64        == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN)
65    );
66    rtems_test_assert(mtx->nest_count == 1);
67    rtems_test_assert(mtx->holder == ctx->main_task_control);
68  } else {
69    sc = rtems_semaphore_release(ctx->semaphore_id);
70    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
71  }
72}
73
74static bool test_body(void *arg)
75{
76  test_context *ctx = arg;
77  rtems_status_code sc;
78
79  sc = rtems_semaphore_obtain(
80    ctx->semaphore_id,
81    RTEMS_NO_WAIT,
82    0
83  );
84  rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_UNSATISFIED);
85
86  sc = rtems_semaphore_obtain(
87    ctx->semaphore_id,
88    RTEMS_WAIT,
89    2
90  );
91  rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT);
92
93  return ctx->done;
94}
95
96static void Init(rtems_task_argument ignored)
97{
98  test_context *ctx = &ctx_instance;
99  rtems_status_code sc;
100
101  TEST_BEGIN();
102
103  ctx->main_task_control = _Thread_Get_executing();
104
105  sc = rtems_semaphore_create(
106    rtems_build_name('S', 'E', 'M', 'A'),
107    1,
108    RTEMS_SIMPLE_BINARY_SEMAPHORE,
109    0,
110    &ctx->semaphore_id
111  );
112  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
113
114  ctx->semaphore_control = get_semaphore_control(ctx->semaphore_id);
115
116  interrupt_critical_section_test(test_body, ctx, release_semaphore);
117  rtems_test_assert(ctx->done);
118
119  TEST_END();
120
121  rtems_test_exit(0);
122}
123
124#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
125#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
126
127#define CONFIGURE_MICROSECONDS_PER_TICK 1000
128
129#define CONFIGURE_MAXIMUM_SEMAPHORES 1
130#define CONFIGURE_MAXIMUM_TASKS 1
131#define CONFIGURE_MAXIMUM_TIMERS 1
132#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
133
134#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
135
136#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
137
138#define CONFIGURE_INIT
139
140#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.