source: rtems/testsuites/sptests/spsem_err01/init.c @ 39bcf741

5
Last change on this file since 39bcf741 was 39bcf741, checked in by Sebastian Huber <sebastian.huber@…>, on 05/25/16 at 12:23:48

Fix semaphore post overflow status

Close #2720.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 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#define MESSAGE_SIZE (sizeof(long) * 4)
18
19const char rtems_test_name[] = "SP SEMAPHORE ERROR 01";
20
21rtems_task Init(
22  rtems_task_argument argument
23)
24{
25  rtems_status_code status;
26
27  TEST_BEGIN();
28 
29  Semaphore_name[ 1 ]  =  rtems_build_name( 'S', 'M', '1', ' ' );
30  Semaphore_name[ 2 ]  =  rtems_build_name( 'S', 'M', '2', ' ' );
31  Semaphore_name[ 3 ]  =  rtems_build_name( 'S', 'M', '3', ' ' );
32
33  /* release overflow */
34  status = rtems_semaphore_create(
35    Semaphore_name[ 1 ],
36    UINT32_MAX,
37    RTEMS_COUNTING_SEMAPHORE,
38    0,
39    &Semaphore_id[ 1 ]
40  );
41  fatal_directive_status(
42    status,
43    RTEMS_SUCCESSFUL,
44    "rtems_semaphore_create"
45  );
46  puts( "TA1 - rtems_semaphore_create - RTEMS_SUCCESSFUL" );
47  status = rtems_semaphore_release( Semaphore_id[ 1 ] );
48  fatal_directive_status(
49    status,
50    RTEMS_UNSATISFIED,
51    "rtems_semaphore_release"
52  );
53  puts( "TA1 - rtems_semaphore_release - RTEMS_UNSATISFIED" );
54  status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
55  fatal_directive_status(
56    status,
57    RTEMS_SUCCESSFUL,
58    "rtems_semaphore_delete"
59  );
60  puts( "TA1 - rtems_semaphore_delete - RTEMS_SUCCESSFUL" );
61
62  /* invalid name */
63  status = rtems_semaphore_create(
64    0,
65    1,
66    RTEMS_DEFAULT_ATTRIBUTES,
67    RTEMS_NO_PRIORITY,
68    &Junk_id
69  );
70  fatal_directive_status(
71    status,
72    RTEMS_INVALID_NAME,
73    "rtems_semaphore_create with illegal name"
74  );
75  puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_NAME" );
76
77  /* NULL Id parameter */
78  status = rtems_semaphore_create(
79    Semaphore_name[ 1 ],
80    1,
81    RTEMS_DEFAULT_ATTRIBUTES,
82    RTEMS_NO_PRIORITY,
83    NULL
84  );
85  fatal_directive_status(
86    status,
87    RTEMS_INVALID_ADDRESS,
88    "rtems_semaphore_create with NULL param"
89  );
90  puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_ADDRESS" );
91
92  /* OK */
93  status = rtems_semaphore_create(
94    Semaphore_name[ 1 ],
95    1,
96    RTEMS_DEFAULT_ATTRIBUTES,
97    RTEMS_NO_PRIORITY,
98    &Semaphore_id[ 1 ]
99  );
100  directive_failed( status, "rtems_semaphore_create" );
101  puts( "TA1 - rtems_semaphore_create - 1 - RTEMS_SUCCESSFUL" );
102
103  status = rtems_semaphore_create(
104    Semaphore_name[ 2 ],
105    1,
106    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
107    RTEMS_NO_PRIORITY,
108    &Semaphore_id[ 2 ]
109  );
110  directive_failed( status, "rtems_semaphore_create" );
111  puts( "TA1 - rtems_semaphore_create - 2 - RTEMS_SUCCESSFUL" );
112
113  do {
114      status = rtems_semaphore_create(
115          Semaphore_name[ 3 ],
116          1,
117          RTEMS_DEFAULT_ATTRIBUTES,
118          RTEMS_NO_PRIORITY,
119          &Junk_id
120      );
121  } while (status == RTEMS_SUCCESSFUL);
122
123  fatal_directive_status(
124    status,
125    RTEMS_TOO_MANY,
126    "rtems_semaphore_create of too many"
127  );
128  puts( "TA1 - rtems_semaphore_create - 3 - RTEMS_TOO_MANY" );
129
130  status = rtems_semaphore_create(
131    Semaphore_name[ 1 ],
132    1,
133    RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
134    RTEMS_NO_PRIORITY,
135    &Junk_id
136  );
137  fatal_directive_status(
138    status,
139    RTEMS_NOT_DEFINED,
140    "rtems_semaphore_create of RTEMS_FIFO RTEMS_INHERIT_PRIORITY"
141  );
142  puts( "TA1 - rtems_semaphore_create - FIFO and inherit - RTEMS_NOT_DEFINED" );
143
144  status = rtems_semaphore_create(
145    Semaphore_name[ 1 ],
146    1,
147    RTEMS_PRIORITY_CEILING | RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
148    RTEMS_NO_PRIORITY,
149    &Junk_id
150  );
151  fatal_directive_status(
152    status,
153    RTEMS_NOT_DEFINED,
154    "rtems_semaphore_create of RTEMS_FIFO RTEMS_CEILING_PRIORITY"
155  );
156  puts( "TA1 - rtems_semaphore_create - FIFO and ceiling - RTEMS_NOT_DEFINED" );
157
158  status = rtems_semaphore_create(
159    Semaphore_name[ 1 ],
160    1,
161    RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY_CEILING |
162      RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY,
163    10,
164    &Junk_id
165  );
166  fatal_directive_status(
167    status,
168    RTEMS_NOT_DEFINED,
169    "rtems_semaphore_create of binary with ceiling and inherit"
170  );
171  puts(
172    "TA1 - rtems_semaphore_create - ceiling and inherit - RTEMS_NOT_DEFINED" );
173
174  status = rtems_semaphore_create(
175    Semaphore_name[ 1 ],
176    1,
177    RTEMS_INHERIT_PRIORITY | RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY,
178    RTEMS_NO_PRIORITY,
179    &Junk_id
180  );
181  fatal_directive_status(
182    status,
183    RTEMS_NOT_DEFINED,
184    "rtems_semaphore_create of RTEMS_COUNTING_SEMAPHORE RTEMS_INHERIT_PRIORITY"
185  );
186  puts( "TA1 - rtems_semaphore_create - RTEMS_NOT_DEFINED" );
187
188  status = rtems_semaphore_create(
189    Semaphore_name[ 1 ],
190    2,
191    RTEMS_BINARY_SEMAPHORE,
192    RTEMS_NO_PRIORITY,
193    &Junk_id
194  );
195  fatal_directive_status(
196    status,
197    RTEMS_INVALID_NUMBER,
198    "rtems_semaphore_create of binary semaphore with count > 1"
199  );
200  puts( "TA1 - rtems_semaphore_create - RTEMS_INVALID_NUMBER" );
201
202  /*
203   *  The check for an object being global is only made if
204   *  multiprocessing is enabled.
205   */
206
207#if defined(RTEMS_MULTIPROCESSING)
208  status = rtems_semaphore_create(
209    Semaphore_name[ 3 ],
210    1,
211    RTEMS_GLOBAL,
212    RTEMS_NO_PRIORITY,
213    &Junk_id
214  );
215  fatal_directive_status(
216    status,
217    RTEMS_MP_NOT_CONFIGURED,
218    "rtems_semaphore_create of mp not configured"
219  );
220#endif
221  puts( "TA1 - rtems_semaphore_create - RTEMS_MP_NOT_CONFIGURED" );
222
223  status = rtems_semaphore_delete( 100 );
224  fatal_directive_status(
225    status,
226    RTEMS_INVALID_ID,
227    "rtems_semaphore_delete with illegal id"
228  );
229  puts( "TA1 - rtems_semaphore_delete - RTEMS_INVALID_ID" );
230
231  status = rtems_semaphore_delete( rtems_build_id( 1, 0, 0, 0 ) );
232  fatal_directive_status(
233    status,
234    RTEMS_INVALID_ID,
235    "rtems_semaphore_delete with local illegal id"
236  );
237  puts( "TA1 - rtems_semaphore_delete - local RTEMS_INVALID_ID" );
238
239  status = rtems_semaphore_ident( 100, RTEMS_SEARCH_ALL_NODES, &Junk_id );
240  fatal_directive_status(
241    status,
242    RTEMS_INVALID_NAME,
243    "rtems_semaphore_ident will illegal name (local)"
244  );
245  puts( "TA1 - rtems_semaphore_ident - global RTEMS_INVALID_NAME" );
246
247  status = rtems_semaphore_ident( 100, 1, &Junk_id );
248  fatal_directive_status(
249    status,
250    RTEMS_INVALID_NAME,
251    "rtems_semaphore_ident will illegal name (global)"
252  );
253  puts( "TA1 - rtems_semaphore_ident - local RTEMS_INVALID_NAME" );
254
255  status = rtems_semaphore_release( 100 );
256  fatal_directive_status(
257    status,
258    RTEMS_INVALID_ID,
259    "rtems_semaphore_release with illegal id"
260  );
261  puts( "TA1 - rtems_semaphore_release - RTEMS_INVALID_ID" );
262
263  status = rtems_semaphore_flush( 100 );
264  fatal_directive_status(
265    status,
266    RTEMS_INVALID_ID,
267    "rtems_semaphore_flush with illegal id"
268  );
269  puts( "TA1 - rtems_semaphore_flush - RTEMS_INVALID_ID" );
270
271  TEST_END();
272}
Note: See TracBrowser for help on using the repository browser.