RTEMS
tc-part-get.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 
64 typedef enum {
65  RtemsPartReqGetBuffer_Pre_Id_Id,
66  RtemsPartReqGetBuffer_Pre_Id_Invalid,
67  RtemsPartReqGetBuffer_Pre_Id_NA
68 } RtemsPartReqGetBuffer_Pre_Id;
69 
70 typedef enum {
71  RtemsPartReqGetBuffer_Pre_InUse_True,
72  RtemsPartReqGetBuffer_Pre_InUse_False,
73  RtemsPartReqGetBuffer_Pre_InUse_NA
74 } RtemsPartReqGetBuffer_Pre_InUse;
75 
76 typedef enum {
77  RtemsPartReqGetBuffer_Post_Status_Ok,
78  RtemsPartReqGetBuffer_Post_Status_InvId,
79  RtemsPartReqGetBuffer_Post_Status_InUse,
80  RtemsPartReqGetBuffer_Post_Status_NA
81 } RtemsPartReqGetBuffer_Post_Status;
82 
86 typedef struct {
87  rtems_status_code status;
88 
89  rtems_id id;
90 
91  rtems_id id_value;
92 
93  void *buffer;
94 
98  size_t pcs[ 2 ];
99 
106 
108  RtemsPartReqGetBuffer_Instance;
109 
110 static const char * const RtemsPartReqGetBuffer_PreDesc_Id[] = {
111  "Id",
112  "Invalid",
113  "NA"
114 };
115 
116 static const char * const RtemsPartReqGetBuffer_PreDesc_InUse[] = {
117  "True",
118  "False",
119  "NA"
120 };
121 
122 static const char * const * const RtemsPartReqGetBuffer_PreDesc[] = {
123  RtemsPartReqGetBuffer_PreDesc_Id,
124  RtemsPartReqGetBuffer_PreDesc_InUse,
125  NULL
126 };
127 
128 #define PART_NAME rtems_build_name( 'N', 'A', 'M', 'E' )
129 
130 #define BUFFER_COUNT 1
131 
132 #define BUFFER_SIZE ( 2 * sizeof( void * ) )
133 
135  buffers[ BUFFER_COUNT ][ BUFFER_SIZE ];
136 
137 static void RtemsPartReqGetBuffer_Pre_Id_Prepare(
139  RtemsPartReqGetBuffer_Pre_Id state
140 )
141 {
142  switch ( state ) {
143  case RtemsPartReqGetBuffer_Pre_Id_Id: {
144  ctx->id = ctx->id_value;
145  break;
146  }
147 
148  case RtemsPartReqGetBuffer_Pre_Id_Invalid: {
149  ctx->id = 0;
150  break;
151  }
152 
153  case RtemsPartReqGetBuffer_Pre_Id_NA:
154  break;
155  }
156 }
157 
158 static void RtemsPartReqGetBuffer_Pre_InUse_Prepare(
160  RtemsPartReqGetBuffer_Pre_InUse state
161 )
162 {
164 
165  switch ( state ) {
166  case RtemsPartReqGetBuffer_Pre_InUse_True: {
167  ctx->buffer = NULL;
168  sc = rtems_partition_get_buffer( ctx->id_value, &ctx->buffer );
169  T_rsc_success( sc );
170  T_not_null( ctx->buffer );
171  break;
172  }
173 
174  case RtemsPartReqGetBuffer_Pre_InUse_False: {
175  ctx->buffer = NULL;
176  break;
177  }
178 
179  case RtemsPartReqGetBuffer_Pre_InUse_NA:
180  break;
181  }
182 }
183 
184 static void RtemsPartReqGetBuffer_Post_Status_Check(
186  RtemsPartReqGetBuffer_Post_Status state
187 )
188 {
190  rtems_id id;
191 
192  switch ( state ) {
193  case RtemsPartReqGetBuffer_Post_Status_Ok: {
194  T_rsc_success( ctx->status );
195  T_not_null( ctx->buffer );
196  break;
197  }
198 
199  case RtemsPartReqGetBuffer_Post_Status_InvId: {
200  T_rsc( ctx->status, RTEMS_INVALID_ID );
201 
202  id = 0xffffffff;
203  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
204  T_rsc_success( sc);
205  T_eq_u32( id, ctx->id_value );
206  break;
207  }
208 
209  case RtemsPartReqGetBuffer_Post_Status_InUse: {
210  T_rsc( ctx->status, RTEMS_RESOURCE_IN_USE );
211 
212  id = 0xffffffff;
213  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
214  T_rsc_success( sc);
215  T_eq_u32( id, ctx->id_value );
216  break;
217  }
218 
219  case RtemsPartReqGetBuffer_Post_Status_NA:
220  break;
221  }
222 }
223 
224 static size_t RtemsPartReqGetBuffer_Scope( void *arg, char *buf, size_t n )
225 {
227 
228  ctx = arg;
229 
230  if ( ctx->in_action_loop ) {
231  return T_get_scope( RtemsPartReqGetBuffer_PreDesc, buf, n, ctx->pcs );
232  }
233 
234  return 0;
235 }
236 
237 static T_fixture RtemsPartReqGetBuffer_Fixture = {
238  .setup = NULL,
239  .stop = NULL,
240  .teardown = NULL,
241  .scope = RtemsPartReqGetBuffer_Scope,
242  .initial_context = &RtemsPartReqGetBuffer_Instance
243 };
244 
245 static const uint8_t RtemsPartReqGetBuffer_TransitionMap[][ 1 ] = {
246  {
247  RtemsPartReqGetBuffer_Post_Status_InUse
248  }, {
249  RtemsPartReqGetBuffer_Post_Status_Ok
250  }, {
251  RtemsPartReqGetBuffer_Post_Status_InvId
252  }, {
253  RtemsPartReqGetBuffer_Post_Status_InvId
254  }
255 };
256 
257 static const struct {
258  uint8_t Skip : 1;
259  uint8_t Pre_Id_NA : 1;
260  uint8_t Pre_InUse_NA : 1;
261 } RtemsPartReqGetBuffer_TransitionInfo[] = {
262  {
263  0, 0, 0
264  }, {
265  0, 0, 0
266  }, {
267  0, 0, 0
268  }, {
269  0, 0, 0
270  }
271 };
272 
273 static void RtemsPartReqGetBuffer_Prepare( RtemsPartReqGetBuffer_Context *ctx )
274 {
276 
278  PART_NAME,
279  buffers,
280  sizeof( buffers ),
281  sizeof( buffers[ 0 ] ),
283  &ctx->id_value
284  );
285  T_rsc_success( sc );
286 }
287 
288 static void RtemsPartReqGetBuffer_Action( RtemsPartReqGetBuffer_Context *ctx )
289 {
290  ctx->status = rtems_partition_delete( ctx->id );
291 }
292 
293 static void RtemsPartReqGetBuffer_Cleanup( RtemsPartReqGetBuffer_Context *ctx )
294 {
296 
297  if ( ctx->buffer != NULL ) {
298  sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer );
299  T_rsc_success( sc );
300  }
301 
302  if ( ctx->id_value != 0xffffffff ) {
303  sc = rtems_partition_delete( ctx->id_value );
304  T_rsc_success( sc );
305  }
306 }
307 
311 T_TEST_CASE_FIXTURE( RtemsPartReqGetBuffer, &RtemsPartReqGetBuffer_Fixture )
312 {
314  size_t index;
315 
316  ctx = T_fixture_context();
317  ctx->in_action_loop = true;
318  index = 0;
319 
320  for (
321  ctx->pcs[ 0 ] = RtemsPartReqGetBuffer_Pre_Id_Id;
322  ctx->pcs[ 0 ] < RtemsPartReqGetBuffer_Pre_Id_NA;
323  ++ctx->pcs[ 0 ]
324  ) {
325  if ( RtemsPartReqGetBuffer_TransitionInfo[ index ].Pre_Id_NA ) {
326  ctx->pcs[ 0 ] = RtemsPartReqGetBuffer_Pre_Id_NA;
327  index += ( RtemsPartReqGetBuffer_Pre_Id_NA - 1 )
328  * RtemsPartReqGetBuffer_Pre_InUse_NA;
329  }
330 
331  for (
332  ctx->pcs[ 1 ] = RtemsPartReqGetBuffer_Pre_InUse_True;
333  ctx->pcs[ 1 ] < RtemsPartReqGetBuffer_Pre_InUse_NA;
334  ++ctx->pcs[ 1 ]
335  ) {
336  if ( RtemsPartReqGetBuffer_TransitionInfo[ index ].Pre_InUse_NA ) {
337  ctx->pcs[ 1 ] = RtemsPartReqGetBuffer_Pre_InUse_NA;
338  index += ( RtemsPartReqGetBuffer_Pre_InUse_NA - 1 );
339  }
340 
341  if ( RtemsPartReqGetBuffer_TransitionInfo[ index ].Skip ) {
342  ++index;
343  continue;
344  }
345 
346  RtemsPartReqGetBuffer_Prepare( ctx );
347  RtemsPartReqGetBuffer_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] );
348  RtemsPartReqGetBuffer_Pre_InUse_Prepare( ctx, ctx->pcs[ 1 ] );
349  RtemsPartReqGetBuffer_Action( ctx );
350  RtemsPartReqGetBuffer_Post_Status_Check(
351  ctx,
352  RtemsPartReqGetBuffer_TransitionMap[ index ][ 0 ]
353  );
354  RtemsPartReqGetBuffer_Cleanup( ctx );
355  ++index;
356  }
357  }
358 }
359 
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
bool in_action_loop
This member indicates if the test action loop is currently executed.
Definition: tc-part-get.c:104
Definition: test.h:61
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.
Definition: tc-part-get.c:98
Test context for spec:/rtems/part/req/get-buffer test case.
Definition: tc-part-get.c:86
#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