source: rtems/testsuites/tmtests/tm02/task1.c @ 6e31b56f

5
Last change on this file since 6e31b56f was 6e31b56f, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/16 at 09:52:53

rtems: Fix binary semaphore resource count

Binary semaphores (not simple binary semaphores) maintain the resource
count since 8797c76addf22a2f0ffc3717ff977695e35b9b0b. Do this also for
initially locked binary semaphores.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2014.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17#if defined(TM02)
18const char rtems_test_name[] = "TIME TEST 2";
19#define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO)
20#define ATTR_DESC "counting/FIFO"
21
22#elif defined(TM31)
23const char rtems_test_name[] = "TIME TEST 31";
24#define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY)
25#define ATTR_DESC "counting/priority"
26
27#elif defined(TM33)
28const char rtems_test_name[] = "TIME TEST 33";
29#define SEMAPHORE_ATTRIBUTES RTEMS_BINARY_SEMAPHORE
30#define ATTR_DESC "binary/FIFO"
31
32#elif defined(TM35)
33const char rtems_test_name[] = "TIME TEST 35";
34#define SEMAPHORE_ATTRIBUTES (RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY)
35#define ATTR_DESC "binary/priority"
36
37#else
38#error "Unknown test configuration"
39#endif
40
41rtems_id High_id;
42rtems_id Low_id;
43rtems_id Semaphore_id;
44
45rtems_task High_task(
46  rtems_task_argument argument
47);
48
49rtems_task Middle_tasks(
50  rtems_task_argument argument
51);
52
53rtems_task Low_task(
54  rtems_task_argument argument
55);
56
57int operation_count = OPERATION_COUNT;
58
59void test_init(void);
60
61rtems_task Init(
62  rtems_task_argument argument
63)
64{
65  rtems_status_code status;
66
67  Print_Warning();
68
69  TEST_BEGIN();
70
71  test_init();
72
73  status = rtems_task_suspend( RTEMS_SELF );
74  directive_failed( status, "rtems_task_suspend" );
75}
76
77void test_init(void)
78{
79  rtems_status_code   status;
80  int                 index;
81  rtems_task_priority priority;
82
83  priority = 2;
84
85  status = rtems_task_create(
86    rtems_build_name( 'H', 'I', 'G', 'H' ),
87    priority,
88    RTEMS_MINIMUM_STACK_SIZE,
89    RTEMS_DEFAULT_MODES,
90    RTEMS_DEFAULT_ATTRIBUTES,
91    &High_id
92  );
93  directive_failed( status, "rtems_task_create of high task" );
94
95  priority++;
96
97  status = rtems_task_start( High_id, High_task, 0 );
98  directive_failed( status, "rtems_task_start of high task" );
99
100  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
101    operation_count = (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
102  for ( index=2 ; index < operation_count ; index++ ) {
103    status = rtems_task_create(
104      rtems_build_name( 'M', 'I', 'D', ' ' ),
105      priority,
106      RTEMS_MINIMUM_STACK_SIZE,
107      RTEMS_DEFAULT_MODES,
108      RTEMS_DEFAULT_ATTRIBUTES,
109      &Low_id
110    );
111    directive_failed( status, "rtems_task_create middle" );
112
113    priority++;
114
115    status = rtems_task_start( Low_id, Middle_tasks, 0 );
116    directive_failed( status, "rtems_task_start middle" );
117  }
118
119  status = rtems_task_create(
120    rtems_build_name( 'L', 'O', 'W', ' ' ),
121    priority,
122    RTEMS_MINIMUM_STACK_SIZE,
123    RTEMS_DEFAULT_MODES,
124    RTEMS_DEFAULT_ATTRIBUTES,
125    &Low_id
126  );
127  directive_failed( status, "rtems_task_create low" );
128
129  status = rtems_task_start( Low_id, Low_task, 0 );
130  directive_failed( status, "rtems_task_start low" );
131
132  status = rtems_semaphore_create(
133    rtems_build_name( 'S', 'M', '1', ' '),
134    0,
135    SEMAPHORE_ATTRIBUTES,
136    RTEMS_NO_PRIORITY,
137    &Semaphore_id
138  );
139  directive_failed( status, "rtems_semaphore_create of SM1" );
140}
141
142rtems_task High_task(
143  rtems_task_argument argument
144)
145{
146  /* start blocking rtems_semaphore_obtain time */
147  benchmark_timer_initialize();
148
149  (void) rtems_semaphore_obtain(
150    Semaphore_id,
151    RTEMS_DEFAULT_OPTIONS,
152    RTEMS_NO_TIMEOUT
153  );
154}
155
156rtems_task Middle_tasks(
157  rtems_task_argument argument
158)
159{
160  (void) rtems_semaphore_obtain(
161    Semaphore_id,
162    RTEMS_DEFAULT_OPTIONS,
163    RTEMS_NO_TIMEOUT
164  );
165}
166
167rtems_task Low_task(
168  rtems_task_argument argument
169)
170{
171  end_time = benchmark_timer_read();
172
173  put_time(
174    "rtems_semaphore_obtain: " ATTR_DESC " not available caller blocks",
175    end_time,
176    operation_count - 1,
177    0,
178    CALLING_OVERHEAD_SEMAPHORE_OBTAIN
179  );
180
181  TEST_END();
182  rtems_test_exit( 0 );
183}
Note: See TracBrowser for help on using the repository browser.