source: rtems/testsuites/sptests/sppartition_err01/init.c @ 97e9728

Last change on this file since 97e9728 was 97e9728, checked in by Sebastian Huber <sebastian.huber@…>, on 09/30/20 at 12:21:32

rtems: Add RTEMS_PARTITION_ALIGNMENT

Update #4105.

  • Property mode set to 100644
File size: 8.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
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
17const char rtems_test_name[] = "SPPARTITION_ERR 1";
18
19static uint32_t Other_Memory;
20
21static rtems_name Partition_name[ 2 ]; /* array of partition names */
22
23static rtems_id   Partition_id[ 2 ];   /* array of partition ids */
24
25static RTEMS_ALIGNED( RTEMS_PARTITION_ALIGNMENT ) uint8_t
26  Partition_good_area[ 256 ];
27
28#define Partition_bad_area (void *) 0x00000005
29
30static void test_partition_errors(void)
31{
32  void              *buffer_address_1;
33  void              *buffer_address_2;
34  void              *buffer_address_3;
35  rtems_status_code  status;
36  size_t             size;
37  rtems_id           junk_id;
38
39  Partition_name[ 1 ]  =  rtems_build_name( 'P', 'T', '1', ' ' );
40
41  status = rtems_partition_create(
42    0,
43    Partition_good_area,
44    128,
45    40,
46    RTEMS_DEFAULT_ATTRIBUTES,
47    &junk_id
48  );
49  fatal_directive_status(
50    status,
51    RTEMS_INVALID_NAME,
52    "rtems_partition_create with illegal name"
53  );
54  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_NAME" );
55
56  status = rtems_partition_create(
57    Partition_name[ 1 ],
58    Partition_good_area,
59    0,
60    71,
61    RTEMS_DEFAULT_ATTRIBUTES,
62    &junk_id
63  );
64  fatal_directive_status(
65    status,
66    RTEMS_INVALID_SIZE,
67    "rtems_partition_create with illegal length"
68  );
69  puts( "TA1 - rtems_partition_create - length - RTEMS_INVALID_SIZE" );
70
71  status = rtems_partition_create(
72    Partition_name[ 1 ],
73    Partition_good_area,
74    128,
75    0,
76    RTEMS_DEFAULT_ATTRIBUTES,
77    &junk_id
78  );
79  fatal_directive_status(
80    status,
81    RTEMS_INVALID_SIZE,
82    "rtems_partition_create with illegal buffer size"
83  );
84  puts( "TA1 - rtems_partition_create - buffer size - RTEMS_INVALID_SIZE" );
85
86  status = rtems_partition_create(
87    Partition_name[ 1 ],
88    Partition_good_area,
89    128,
90    256,
91    RTEMS_DEFAULT_ATTRIBUTES,
92    &junk_id
93  );
94  fatal_directive_status(
95    status,
96    RTEMS_INVALID_SIZE,
97    "rtems_partition_create with buffer_size > length"
98  );
99  puts(
100    "TA1 - rtems_partition_create - length < buffer size - RTEMS_INVALID_SIZE"
101  );
102
103  /*
104   * Attempt to create a partition with a buffer size that is not large
105   * enough to account for the overhead.
106   */
107  puts(
108    "TA1 - rtems_partition_create - buffer size < overhead - RTEMS_INVALID_SIZE"
109  );
110#define SIZEOF_CHAIN_NODE 2 * sizeof(void *)
111  for ( size=0 ; size < SIZEOF_CHAIN_NODE ; size++) {
112    status = rtems_partition_create(
113      Partition_name[ 1 ],
114      Partition_good_area,
115      size,
116      256,
117      RTEMS_DEFAULT_ATTRIBUTES,
118      &junk_id
119    );
120    if ( status != RTEMS_INVALID_SIZE )
121      printf( "ERROR when size == %zu\n", size );
122
123    fatal_directive_status(
124      status,
125      RTEMS_INVALID_SIZE,
126      "rtems_partition_create with buffer_size > length"
127    );
128  }
129
130#if defined(_C3x) || defined(_C4x)
131  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_ADDRESS - SKIPPED" );
132#else
133  status = rtems_partition_create(
134    Partition_name[ 1 ],
135    Partition_bad_area,
136    128,
137    64,
138    RTEMS_GLOBAL,
139    &junk_id
140  );
141  fatal_directive_status(
142    status,
143    RTEMS_INVALID_ADDRESS,
144    "rtems_partition_create with bad address"
145  );
146  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_ADDRESS" );
147#endif
148
149#if defined(_C3x) || defined(_C4x)
150  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_SIZE - SKIPPED" );
151#else
152  status = rtems_partition_create(
153    Partition_name[ 1 ],
154    Partition_good_area,
155    128,
156    RTEMS_PARTITION_ALIGNMENT - 1,
157    RTEMS_DEFAULT_ATTRIBUTES,
158    &junk_id
159  );
160  fatal_directive_status(
161    status,
162    RTEMS_INVALID_SIZE,
163    "rtems_partition_create with unaligned buffer_size"
164  );
165  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_SIZE" );
166#endif
167
168  status = rtems_partition_delete( 100 );
169  fatal_directive_status(
170    status,
171    RTEMS_INVALID_ID,
172    "rtems_partition_delete with illegal id"
173  );
174  puts( "TA1 - rtems_partition_delete - unknown RTEMS_INVALID_ID" );
175
176  status = rtems_partition_delete( rtems_build_id( 1, 1, 1, 256 ) );
177  fatal_directive_status(
178    status,
179    RTEMS_INVALID_ID,
180    "rtems_partition_delete with illegal id"
181  );
182  puts( "TA1 - rtems_partition_delete - local RTEMS_INVALID_ID" );
183
184  /* get bad address */
185  status = rtems_partition_get_buffer( 100, NULL );
186  fatal_directive_status(
187    status,
188    RTEMS_INVALID_ADDRESS,
189    "rtems_partition_get_buffer with NULL param"
190  );
191  puts( "TA1 - rtems_partition_get_buffer - RTEMS_INVALID_ADDRESS" );
192
193  /* get bad Id */
194  status = rtems_partition_get_buffer( 100, &buffer_address_1 );
195  fatal_directive_status(
196    status,
197    RTEMS_INVALID_ID,
198    "rtems_partition_get_buffer with illegal id"
199  );
200  puts( "TA1 - rtems_partition_get_buffer - RTEMS_INVALID_ID" );
201
202  status = rtems_partition_ident( 0, RTEMS_SEARCH_ALL_NODES, &junk_id );
203  fatal_directive_status(
204    status,
205    RTEMS_INVALID_NAME,
206    "rtems_partition_ident with illegal name"
207  );
208  puts( "TA1 - rtems_partition_ident - RTEMS_INVALID_NAME" );
209
210  status = rtems_partition_return_buffer( 100, buffer_address_1 );
211  fatal_directive_status(
212    status,
213    RTEMS_INVALID_ID,
214    "rtems_partition_return_buffer with illegal id"
215  );
216  puts( "TA1 - rtems_partition_return_buffer - RTEMS_INVALID_ID" );
217
218  /* create bad area */
219  status = rtems_partition_create(
220    Partition_name[ 1 ],
221    NULL,
222    128,
223    64,
224    RTEMS_DEFAULT_ATTRIBUTES,
225    &junk_id
226  );
227  fatal_directive_status(
228    status,
229    RTEMS_INVALID_ADDRESS,
230    "rtems_partition_return_buffer with NULL area"
231  );
232  puts( "TA1 - rtems_partition_create - RTEMS_INVALID_ADDRESS" );
233
234  /* create OK */
235  status = rtems_partition_create(
236    Partition_name[ 1 ],
237    Partition_good_area,
238    128,
239    64,
240    RTEMS_DEFAULT_ATTRIBUTES,
241    &Partition_id[ 1 ]
242  );
243  directive_failed( status, "rtems_partition_create" );
244  puts( "TA1 - rtems_partition_create - RTEMS_SUCCESSFUL" );
245
246  status = rtems_partition_create(
247    Partition_name[ 1 ],
248    Partition_good_area,
249    128,
250    32,
251    RTEMS_DEFAULT_ATTRIBUTES,
252    &junk_id
253  );
254  fatal_directive_status(
255    status,
256    RTEMS_TOO_MANY,
257    "rtems_partition_create of too many"
258  );
259  puts( "TA1 - rtems_partition_create - RTEMS_TOO_MANY" );
260
261  status = rtems_partition_get_buffer( Partition_id[ 1 ], &buffer_address_1 );
262  directive_failed( status, "rtems_partition_get_buffer");
263  puts( "TA1 - rtems_partition_get_buffer - RTEMS_SUCCESSFUL" );
264
265  status = rtems_partition_get_buffer( Partition_id[ 1 ], &buffer_address_2 );
266  directive_failed( status, "rtems_partition_get_buffer" );
267  puts( "TA1 - rtems_partition_get_buffer - RTEMS_SUCCESSFUL" );
268
269  status = rtems_partition_get_buffer( Partition_id[ 1 ], &buffer_address_3 );
270  fatal_directive_status(
271    status,
272    RTEMS_UNSATISFIED,
273    "rtems_partition_get_buffer unsatisfied"
274  );
275  puts( "TA1 - rtems_partition_get_buffer - RTEMS_UNSATISFIED" );
276
277  status = rtems_partition_delete( Partition_id[ 1 ] );
278  fatal_directive_status(
279    status,
280    RTEMS_RESOURCE_IN_USE,
281    "rtems_partition_delete with buffers in use"
282  );
283  puts( "TA1 - rtems_partition_delete - RTEMS_RESOURCE_IN_USE" );
284
285  status = rtems_partition_return_buffer(
286    Partition_id[ 1 ],
287    &Other_Memory
288  );
289  fatal_directive_status(
290    status,
291    RTEMS_INVALID_ADDRESS,
292    "rtems_partition_return_buffer with buffer address out of partition"
293  );
294  puts(
295    "TA1 - rtems_partition_return_buffer - RTEMS_INVALID_ADDRESS - out of range"
296  );
297
298  status = rtems_partition_return_buffer(
299    Partition_id[ 1 ],
300    &Partition_good_area[ 7 ]
301  );
302  fatal_directive_status(
303    status,
304    RTEMS_INVALID_ADDRESS,
305    "rtems_partition_return_buffer with buffer address not on boundary"
306  );
307  puts_nocr( "TA1 - rtems_partition_return_buffer - " );
308  puts     ( "RTEMS_INVALID_ADDRESS - not on boundary");
309}
310
311rtems_task Init(
312  rtems_task_argument argument
313)
314{
315  TEST_BEGIN();
316
317  test_partition_errors();
318
319  TEST_END();
320  rtems_test_exit( 0 );
321}
Note: See TracBrowser for help on using the repository browser.