RTEMS
tc-part-delete.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  RtemsPartReqDelete_Pre_Id_Id,
66  RtemsPartReqDelete_Pre_Id_Invalid,
67  RtemsPartReqDelete_Pre_Id_NA
68 } RtemsPartReqDelete_Pre_Id;
69 
70 typedef enum {
71  RtemsPartReqDelete_Pre_InUse_True,
72  RtemsPartReqDelete_Pre_InUse_False,
73  RtemsPartReqDelete_Pre_InUse_NA
74 } RtemsPartReqDelete_Pre_InUse;
75 
76 typedef enum {
77  RtemsPartReqDelete_Post_Status_Ok,
78  RtemsPartReqDelete_Post_Status_InvId,
79  RtemsPartReqDelete_Post_Status_InUse,
80  RtemsPartReqDelete_Post_Status_NA
81 } RtemsPartReqDelete_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  RtemsPartReqDelete_Instance;
109 
110 static const char * const RtemsPartReqDelete_PreDesc_Id[] = {
111  "Id",
112  "Invalid",
113  "NA"
114 };
115 
116 static const char * const RtemsPartReqDelete_PreDesc_InUse[] = {
117  "True",
118  "False",
119  "NA"
120 };
121 
122 static const char * const * const RtemsPartReqDelete_PreDesc[] = {
123  RtemsPartReqDelete_PreDesc_Id,
124  RtemsPartReqDelete_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 RtemsPartReqDelete_Pre_Id_Prepare(
139  RtemsPartReqDelete_Pre_Id state
140 )
141 {
142  switch ( state ) {
143  case RtemsPartReqDelete_Pre_Id_Id: {
144  ctx->id = ctx->id_value;
145  break;
146  }
147 
148  case RtemsPartReqDelete_Pre_Id_Invalid: {
149  ctx->id = 0;
150  break;
151  }
152 
153  case RtemsPartReqDelete_Pre_Id_NA:
154  break;
155  }
156 }
157 
158 static void RtemsPartReqDelete_Pre_InUse_Prepare(
160  RtemsPartReqDelete_Pre_InUse state
161 )
162 {
164 
165  switch ( state ) {
166  case RtemsPartReqDelete_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 RtemsPartReqDelete_Pre_InUse_False: {
175  ctx->buffer = NULL;
176  break;
177  }
178 
179  case RtemsPartReqDelete_Pre_InUse_NA:
180  break;
181  }
182 }
183 
184 static void RtemsPartReqDelete_Post_Status_Check(
186  RtemsPartReqDelete_Post_Status state
187 )
188 {
190  rtems_id id;
191 
192  switch ( state ) {
193  case RtemsPartReqDelete_Post_Status_Ok: {
194  T_rsc_success( ctx->status );
195  ctx->id_value = 0xffffffff;
196 
197  id = 0xffffffff;
198  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
199  T_rsc( sc, RTEMS_INVALID_NAME );
200  T_eq_u32( id, 0xffffffff );
201  break;
202  }
203 
204  case RtemsPartReqDelete_Post_Status_InvId: {
205  T_rsc( ctx->status, RTEMS_INVALID_ID );
206 
207  id = 0xffffffff;
208  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
209  T_rsc_success( sc);
210  T_eq_u32( id, ctx->id_value );
211  break;
212  }
213 
214  case RtemsPartReqDelete_Post_Status_InUse: {
215  T_rsc( ctx->status, RTEMS_RESOURCE_IN_USE );
216 
217  id = 0xffffffff;
218  sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
219  T_rsc_success( sc);
220  T_eq_u32( id, ctx->id_value );
221  break;
222  }
223 
224  case RtemsPartReqDelete_Post_Status_NA:
225  break;
226  }
227 }
228 
229 static size_t RtemsPartReqDelete_Scope( void *arg, char *buf, size_t n )
230 {
232 
233  ctx = arg;
234 
235  if ( ctx->in_action_loop ) {
236  return T_get_scope( RtemsPartReqDelete_PreDesc, buf, n, ctx->pcs );
237  }
238 
239  return 0;
240 }
241 
242 static T_fixture RtemsPartReqDelete_Fixture = {
243  .setup = NULL,
244  .stop = NULL,
245  .teardown = NULL,
246  .scope = RtemsPartReqDelete_Scope,
247  .initial_context = &RtemsPartReqDelete_Instance
248 };
249 
250 static const uint8_t RtemsPartReqDelete_TransitionMap[][ 1 ] = {
251  {
252  RtemsPartReqDelete_Post_Status_InUse
253  }, {
254  RtemsPartReqDelete_Post_Status_Ok
255  }, {
256  RtemsPartReqDelete_Post_Status_InvId
257  }, {
258  RtemsPartReqDelete_Post_Status_InvId
259  }
260 };
261 
262 static const struct {
263  uint8_t Skip : 1;
264  uint8_t Pre_Id_NA : 1;
265  uint8_t Pre_InUse_NA : 1;
266 } RtemsPartReqDelete_TransitionInfo[] = {
267  {
268  0, 0, 0
269  }, {
270  0, 0, 0
271  }, {
272  0, 0, 0
273  }, {
274  0, 0, 0
275  }
276 };
277 
278 static void RtemsPartReqDelete_Prepare( RtemsPartReqDelete_Context *ctx )
279 {
281 
283  PART_NAME,
284  buffers,
285  sizeof( buffers ),
286  sizeof( buffers[ 0 ] ),
288  &ctx->id_value
289  );
290  T_rsc_success( sc );
291 }
292 
293 static void RtemsPartReqDelete_Action( RtemsPartReqDelete_Context *ctx )
294 {
295  ctx->status = rtems_partition_delete( ctx->id );
296 }
297 
298 static void RtemsPartReqDelete_Cleanup( RtemsPartReqDelete_Context *ctx )
299 {
301 
302  if ( ctx->buffer != NULL ) {
303  sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer );
304  T_rsc_success( sc );
305  }
306 
307  if ( ctx->id_value != 0xffffffff ) {
308  sc = rtems_partition_delete( ctx->id_value );
309  T_rsc_success( sc );
310  }
311 }
312 
316 T_TEST_CASE_FIXTURE( RtemsPartReqDelete, &RtemsPartReqDelete_Fixture )
317 {
319  size_t index;
320 
321  ctx = T_fixture_context();
322  ctx->in_action_loop = true;
323  index = 0;
324 
325  for (
326  ctx->pcs[ 0 ] = RtemsPartReqDelete_Pre_Id_Id;
327  ctx->pcs[ 0 ] < RtemsPartReqDelete_Pre_Id_NA;
328  ++ctx->pcs[ 0 ]
329  ) {
330  if ( RtemsPartReqDelete_TransitionInfo[ index ].Pre_Id_NA ) {
331  ctx->pcs[ 0 ] = RtemsPartReqDelete_Pre_Id_NA;
332  index += ( RtemsPartReqDelete_Pre_Id_NA - 1 )
333  * RtemsPartReqDelete_Pre_InUse_NA;
334  }
335 
336  for (
337  ctx->pcs[ 1 ] = RtemsPartReqDelete_Pre_InUse_True;
338  ctx->pcs[ 1 ] < RtemsPartReqDelete_Pre_InUse_NA;
339  ++ctx->pcs[ 1 ]
340  ) {
341  if ( RtemsPartReqDelete_TransitionInfo[ index ].Pre_InUse_NA ) {
342  ctx->pcs[ 1 ] = RtemsPartReqDelete_Pre_InUse_NA;
343  index += ( RtemsPartReqDelete_Pre_InUse_NA - 1 );
344  }
345 
346  if ( RtemsPartReqDelete_TransitionInfo[ index ].Skip ) {
347  ++index;
348  continue;
349  }
350 
351  RtemsPartReqDelete_Prepare( ctx );
352  RtemsPartReqDelete_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] );
353  RtemsPartReqDelete_Pre_InUse_Prepare( ctx, ctx->pcs[ 1 ] );
354  RtemsPartReqDelete_Action( ctx );
355  RtemsPartReqDelete_Post_Status_Check(
356  ctx,
357  RtemsPartReqDelete_TransitionMap[ index ][ 0 ]
358  );
359  RtemsPartReqDelete_Cleanup( ctx );
360  ++index;
361  }
362  }
363 }
364 
bool in_action_loop
This member indicates if the test action loop is currently executed.
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
Test context for spec:/rtems/part/req/delete test case.
rtems_status_code rtems_partition_delete(rtems_id id)
Deletes the specified partition.
Definition: partdelete.c:24
size_t pcs[2]
This member defines the pre-condition states for the next action.
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
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
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