RTEMS
tc-part-return.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
9 /*
10  * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Do not manually edit this file. It is part of the RTEMS quality process
36  * and was automatically generated.
37  *
38  * If you find something that needs to be fixed or worded better please
39  * post a report to an RTEMS mailing list or raise a bug report:
40  *
41  * https://docs.rtems.org/branches/master/user/support/bugs.html
42  *
43  * For information on updating and regenerating please refer to:
44  *
45  * https://docs.rtems.org/branches/master/eng/req/howto.html
46  */
47 
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51 
52 #include <rtems.h>
53 
54 #include <rtems/test.h>
55 
65 typedef enum {
66  RtemsPartReqReturnBuffer_Pre_Id_Id,
67  RtemsPartReqReturnBuffer_Pre_Id_Invalid,
68  RtemsPartReqReturnBuffer_Pre_Id_NA
69 } RtemsPartReqReturnBuffer_Pre_Id;
70 
71 typedef enum {
72  RtemsPartReqReturnBuffer_Pre_InUse_True,
73  RtemsPartReqReturnBuffer_Pre_InUse_False,
74  RtemsPartReqReturnBuffer_Pre_InUse_NA
75 } RtemsPartReqReturnBuffer_Pre_InUse;
76 
77 typedef enum {
78  RtemsPartReqReturnBuffer_Post_Status_Ok,
79  RtemsPartReqReturnBuffer_Post_Status_InvId,
80  RtemsPartReqReturnBuffer_Post_Status_InUse,
81  RtemsPartReqReturnBuffer_Post_Status_NA
82 } RtemsPartReqReturnBuffer_Post_Status;
83 
87 typedef struct {
88  rtems_status_code status;
89 
90  rtems_id id;
91 
92  rtems_id id_value;
93 
94  void *buffer;
95 
99  size_t pcs[ 2 ];
100 
107 
109  RtemsPartReqReturnBuffer_Instance;
110 
111 static const char * const RtemsPartReqReturnBuffer_PreDesc_Id[] = {
112  "Id",
113  "Invalid",
114  "NA"
115 };
116 
117 static const char * const RtemsPartReqReturnBuffer_PreDesc_InUse[] = {
118  "True",
119  "False",
120  "NA"
121 };
122 
123 static const char * const * const RtemsPartReqReturnBuffer_PreDesc[] = {
124  RtemsPartReqReturnBuffer_PreDesc_Id,
125  RtemsPartReqReturnBuffer_PreDesc_InUse,
126  NULL
127 };
128 
129 #define PART_NAME rtems_build_name( 'N', 'A', 'M', 'E' )
130 
131 #define BUFFER_COUNT 1
132 
133 #define BUFFER_SIZE ( 2 * sizeof( void * ) )
134 
136  buffers[ BUFFER_COUNT ][ BUFFER_SIZE ];
137 
138 static void RtemsPartReqReturnBuffer_Pre_Id_Prepare(
140  RtemsPartReqReturnBuffer_Pre_Id state
141 )
142 {
143  switch ( state ) {
144  case RtemsPartReqReturnBuffer_Pre_Id_Id: {
145  ctx->id = ctx->id_value;
146  break;
147  }
148 
149  case RtemsPartReqReturnBuffer_Pre_Id_Invalid: {
150  ctx->id = 0;
151  break;
152  }
153 
154  case RtemsPartReqReturnBuffer_Pre_Id_NA:
155  break;
156  }
157 }
158 
159 static void RtemsPartReqReturnBuffer_Pre_InUse_Prepare(
161  RtemsPartReqReturnBuffer_Pre_InUse state
162 )
163 {
165 
166  switch ( state ) {
167  case RtemsPartReqReturnBuffer_Pre_InUse_True: {
168  ctx->buffer = NULL;
169  sc = rtems_partition_get_buffer( ctx->id_value, &ctx->buffer );
170  T_rsc_success( sc );
171  T_not_null( ctx->buffer );
172  break;
173  }
174 
175  case RtemsPartReqReturnBuffer_Pre_InUse_False: {
176  ctx->buffer = NULL;
177  break;
178  }
179 
180  case RtemsPartReqReturnBuffer_Pre_InUse_NA:
181  break;
182  }
183 }
184 
185 static void RtemsPartReqReturnBuffer_Post_Status_Check(
187  RtemsPartReqReturnBuffer_Post_Status state
188 )
189 {
191  rtems_id id;
192 
193  switch ( state ) {
194  case RtemsPartReqReturnBuffer_Post_Status_Ok: {
195  T_rsc_success( ctx->status );
196  ctx->id_value = 0xffffffff;
197 
198  id = 0xffffffff;
199  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
200  T_rsc( sc, RTEMS_INVALID_NAME );
201  T_eq_u32( id, 0xffffffff );
202  break;
203  }
204 
205  case RtemsPartReqReturnBuffer_Post_Status_InvId: {
206  T_rsc( ctx->status, RTEMS_INVALID_ID );
207 
208  id = 0xffffffff;
209  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
210  T_rsc_success( sc);
211  T_eq_u32( id, ctx->id_value );
212  break;
213  }
214 
215  case RtemsPartReqReturnBuffer_Post_Status_InUse: {
216  T_rsc( ctx->status, RTEMS_RESOURCE_IN_USE );
217 
218  id = 0xffffffff;
219  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
220  T_rsc_success( sc);
221  T_eq_u32( id, ctx->id_value );
222  break;
223  }
224 
225  case RtemsPartReqReturnBuffer_Post_Status_NA:
226  break;
227  }
228 }
229 
230 static size_t RtemsPartReqReturnBuffer_Scope( void *arg, char *buf, size_t n )
231 {
233 
234  ctx = arg;
235 
236  if ( ctx->in_action_loop ) {
237  return T_get_scope( RtemsPartReqReturnBuffer_PreDesc, buf, n, ctx->pcs );
238  }
239 
240  return 0;
241 }
242 
243 static T_fixture RtemsPartReqReturnBuffer_Fixture = {
244  .setup = NULL,
245  .stop = NULL,
246  .teardown = NULL,
247  .scope = RtemsPartReqReturnBuffer_Scope,
248  .initial_context = &RtemsPartReqReturnBuffer_Instance
249 };
250 
251 static const uint8_t RtemsPartReqReturnBuffer_TransitionMap[][ 1 ] = {
252  {
253  RtemsPartReqReturnBuffer_Post_Status_InUse
254  }, {
255  RtemsPartReqReturnBuffer_Post_Status_Ok
256  }, {
257  RtemsPartReqReturnBuffer_Post_Status_InvId
258  }, {
259  RtemsPartReqReturnBuffer_Post_Status_InvId
260  }
261 };
262 
263 static const struct {
264  uint8_t Skip : 1;
265  uint8_t Pre_Id_NA : 1;
266  uint8_t Pre_InUse_NA : 1;
267 } RtemsPartReqReturnBuffer_TransitionInfo[] = {
268  {
269  0, 0, 0
270  }, {
271  0, 0, 0
272  }, {
273  0, 0, 0
274  }, {
275  0, 0, 0
276  }
277 };
278 
279 static void RtemsPartReqReturnBuffer_Prepare(
281 )
282 {
284 
286  PART_NAME,
287  buffers,
288  sizeof( buffers ),
289  sizeof( buffers[ 0 ] ),
291  &ctx->id_value
292  );
293  T_rsc_success( sc );
294 }
295 
296 static void RtemsPartReqReturnBuffer_Action(
298 )
299 {
300  ctx->status = rtems_partition_delete( ctx->id );
301 }
302 
303 static void RtemsPartReqReturnBuffer_Cleanup(
305 )
306 {
308 
309  if ( ctx->buffer != NULL ) {
310  sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer );
311  T_rsc_success( sc );
312  }
313 
314  if ( ctx->id_value != 0xffffffff ) {
315  sc = rtems_partition_delete( ctx->id_value );
316  T_rsc_success( sc );
317  }
318 }
319 
323 T_TEST_CASE_FIXTURE(
324  RtemsPartReqReturnBuffer,
325  &RtemsPartReqReturnBuffer_Fixture
326 )
327 {
329  size_t index;
330 
331  ctx = T_fixture_context();
332  ctx->in_action_loop = true;
333  index = 0;
334 
335  for (
336  ctx->pcs[ 0 ] = RtemsPartReqReturnBuffer_Pre_Id_Id;
337  ctx->pcs[ 0 ] < RtemsPartReqReturnBuffer_Pre_Id_NA;
338  ++ctx->pcs[ 0 ]
339  ) {
340  if ( RtemsPartReqReturnBuffer_TransitionInfo[ index ].Pre_Id_NA ) {
341  ctx->pcs[ 0 ] = RtemsPartReqReturnBuffer_Pre_Id_NA;
342  index += ( RtemsPartReqReturnBuffer_Pre_Id_NA - 1 )
343  * RtemsPartReqReturnBuffer_Pre_InUse_NA;
344  }
345 
346  for (
347  ctx->pcs[ 1 ] = RtemsPartReqReturnBuffer_Pre_InUse_True;
348  ctx->pcs[ 1 ] < RtemsPartReqReturnBuffer_Pre_InUse_NA;
349  ++ctx->pcs[ 1 ]
350  ) {
351  if ( RtemsPartReqReturnBuffer_TransitionInfo[ index ].Pre_InUse_NA ) {
352  ctx->pcs[ 1 ] = RtemsPartReqReturnBuffer_Pre_InUse_NA;
353  index += ( RtemsPartReqReturnBuffer_Pre_InUse_NA - 1 );
354  }
355 
356  if ( RtemsPartReqReturnBuffer_TransitionInfo[ index ].Skip ) {
357  ++index;
358  continue;
359  }
360 
361  RtemsPartReqReturnBuffer_Prepare( ctx );
362  RtemsPartReqReturnBuffer_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] );
363  RtemsPartReqReturnBuffer_Pre_InUse_Prepare( ctx, ctx->pcs[ 1 ] );
364  RtemsPartReqReturnBuffer_Action( ctx );
365  RtemsPartReqReturnBuffer_Post_Status_Check(
366  ctx,
367  RtemsPartReqReturnBuffer_TransitionMap[ index ][ 0 ]
368  );
369  RtemsPartReqReturnBuffer_Cleanup( ctx );
370  ++index;
371  }
372  }
373 }
374 
rtems_status_code rtems_partition_get_buffer(rtems_id id, void **buffer)
Tries to get a buffer from the specified partition.
Definition: partgetbuffer.c:23
This status code indicates that the object still had resources in use.
Definition: status.h:149
#define RTEMS_DEFAULT_ATTRIBUTES
This is the default value for an attribute set.
Definition: attr.h:140
rtems_status_code rtems_partition_create(rtems_name name, void *starting_address, uintptr_t length, size_t buffer_size, rtems_attribute attribute_set, rtems_id *id)
Creates a partition.
Definition: partcreate.c:30
rtems_status_code rtems_partition_delete(rtems_id id)
Deletes the specified partition.
Definition: partdelete.c:24
rtems_status_code rtems_partition_return_buffer(rtems_id id, void *buffer)
Returns a buffer to the specified partition.
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
#define RTEMS_ALIGNED(_alignment)
Instructs the compiler in a declaration or definition to enforce the specified alignment.
Definition: basedefs.h:389
Definition: test.h:61
bool in_action_loop
This member indicates if the test action loop is currently executed.
This header file defines the RTEMS Classic API.
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
rtems_status_code rtems_partition_ident(rtems_name name, uint32_t node, rtems_id *id)
Identifies a partition object by the specified object name.
Definition: partident.c:44
size_t pcs[2]
This member defines the pre-condition states for the next action.
Test context for spec:/rtems/part/req/return-buffer test case.
This status code indicates that an object name was invalid.
Definition: status.h:101
#define RTEMS_SEARCH_LOCAL_NODE
%
Definition: object.h:400
#define RTEMS_PARTITION_ALIGNMENT
This constant defines the minimum alignment of a partition buffer in bytes.
Definition: part.h:89