source: rtems/testsuites/sptests/spsem03/init.c @ 79cf35d

4.10
Last change on this file since 79cf35d was 79cf35d, checked in by Gedare Bloom <gedare@…>, on 12/19/17 at 18:18:45

sptests: back-port spsem01, spsem02, and spsem03 from 4.11

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2014, 2016 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
21const char rtems_test_name[] = "SPSEM 3";
22
23typedef struct {
24  rtems_id low;
25  rtems_id mid;
26  rtems_id high;
27  rtems_id inversion;
28  rtems_id sem_a;
29  rtems_id sem_b;
30} test_context;
31
32static test_context test_instance;
33
34static void assert_prio(rtems_id task_id, rtems_task_priority expected_prio)
35{
36  rtems_status_code sc;
37  rtems_task_priority prio;
38
39  sc = rtems_task_set_priority(task_id, RTEMS_CURRENT_PRIORITY, &prio);
40  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
41  rtems_test_assert(prio == expected_prio);
42}
43
44static void create_task(rtems_id *id, rtems_task_priority prio)
45{
46  rtems_status_code sc;
47
48  sc = rtems_task_create(
49    rtems_build_name('T', 'A', 'S', 'K'),
50    prio,
51    RTEMS_MINIMUM_STACK_SIZE,
52    RTEMS_DEFAULT_MODES,
53    RTEMS_DEFAULT_ATTRIBUTES,
54    id
55  );
56  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
57}
58
59static void start_task(rtems_id id, rtems_task_entry entry)
60{
61  rtems_status_code sc;
62
63  sc = rtems_task_start(id, entry, 0);
64  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
65}
66
67static void create_sema(rtems_id *id)
68{
69  rtems_status_code sc;
70
71  sc = rtems_semaphore_create(
72    rtems_build_name('S', 'E', 'M', 'A'),
73    1,
74    RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
75    0,
76    id
77  );
78  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
79}
80
81static void obtain_sema(rtems_id id)
82{
83  rtems_status_code sc;
84
85  sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
86  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
87}
88
89static void inversion_task(rtems_task_argument arg)
90{
91  rtems_test_assert(0);
92}
93
94static void mid_task(rtems_task_argument arg)
95{
96  test_context *ctx = &test_instance;
97
98  obtain_sema(ctx->sem_b);
99  obtain_sema(ctx->sem_a);
100}
101
102static void high_task(rtems_task_argument arg)
103{
104  test_context *ctx = &test_instance;
105
106  start_task(ctx->inversion, inversion_task);
107  obtain_sema(ctx->sem_b);
108}
109
110static void Init(rtems_task_argument arg)
111{
112  test_context *ctx = &test_instance;
113
114  printf("*** BEGIN OF TEST SPSEM03 ***\n");
115
116  ctx->low = rtems_task_self();
117
118  create_task(&ctx->mid, 3);
119  create_task(&ctx->high, 1);
120  create_task(&ctx->inversion, 2);
121  create_sema(&ctx->sem_a);
122  create_sema(&ctx->sem_b);
123
124  obtain_sema(ctx->sem_a);
125  start_task(ctx->mid, mid_task);
126  start_task(ctx->high, high_task);
127
128  /*
129   * Here we see that the priority of the high priority task blocked on
130   * semaphore B propagated to the low priority task owning semaphore A
131   * on which the owner of semaphore B depends.
132   */
133  assert_prio(ctx->low, 1);
134  assert_prio(ctx->mid, 1);
135  assert_prio(ctx->high, 1);
136  assert_prio(ctx->inversion, 2);
137
138  printf("*** END OF TEST SPSEM03 ***\n");
139  rtems_test_exit(0);
140}
141
142#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
143#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
144
145#define CONFIGURE_MAXIMUM_TASKS 4
146#define CONFIGURE_MAXIMUM_SEMAPHORES 2
147
148#define CONFIGURE_INIT_TASK_PRIORITY 4
149#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
150
151#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
152
153#define CONFIGURE_INIT
154
155#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.