Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:51

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsPartReqDelete
0007  */
0008 
0009 /*
0010  * Copyright (C) 2020 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
0049  */
0050 
0051 #ifdef HAVE_CONFIG_H
0052 #include "config.h"
0053 #endif
0054 
0055 #include <rtems.h>
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsPartReqDelete spec:/rtems/part/req/delete
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef enum {
0068   RtemsPartReqDelete_Pre_Id_NoObj,
0069   RtemsPartReqDelete_Pre_Id_Part,
0070   RtemsPartReqDelete_Pre_Id_NA
0071 } RtemsPartReqDelete_Pre_Id;
0072 
0073 typedef enum {
0074   RtemsPartReqDelete_Pre_InUse_Yes,
0075   RtemsPartReqDelete_Pre_InUse_No,
0076   RtemsPartReqDelete_Pre_InUse_NA
0077 } RtemsPartReqDelete_Pre_InUse;
0078 
0079 typedef enum {
0080   RtemsPartReqDelete_Post_Status_Ok,
0081   RtemsPartReqDelete_Post_Status_InvId,
0082   RtemsPartReqDelete_Post_Status_InUse,
0083   RtemsPartReqDelete_Post_Status_NA
0084 } RtemsPartReqDelete_Post_Status;
0085 
0086 typedef struct {
0087   uint8_t Skip : 1;
0088   uint8_t Pre_Id_NA : 1;
0089   uint8_t Pre_InUse_NA : 1;
0090   uint8_t Post_Status : 2;
0091 } RtemsPartReqDelete_Entry;
0092 
0093 /**
0094  * @brief Test context for spec:/rtems/part/req/delete test case.
0095  */
0096 typedef struct {
0097   rtems_status_code status;
0098 
0099   rtems_id id;
0100 
0101   rtems_id id_value;
0102 
0103   void *buffer;
0104 
0105   struct {
0106     /**
0107      * @brief This member defines the pre-condition states for the next action.
0108      */
0109     size_t pcs[ 2 ];
0110 
0111     /**
0112      * @brief If this member is true, then the test action loop is executed.
0113      */
0114     bool in_action_loop;
0115 
0116     /**
0117      * @brief This member contains the next transition map index.
0118      */
0119     size_t index;
0120 
0121     /**
0122      * @brief This member contains the current transition map entry.
0123      */
0124     RtemsPartReqDelete_Entry entry;
0125 
0126     /**
0127      * @brief If this member is true, then the current transition variant
0128      *   should be skipped.
0129      */
0130     bool skip;
0131   } Map;
0132 } RtemsPartReqDelete_Context;
0133 
0134 static RtemsPartReqDelete_Context
0135   RtemsPartReqDelete_Instance;
0136 
0137 static const char * const RtemsPartReqDelete_PreDesc_Id[] = {
0138   "NoObj",
0139   "Part",
0140   "NA"
0141 };
0142 
0143 static const char * const RtemsPartReqDelete_PreDesc_InUse[] = {
0144   "Yes",
0145   "No",
0146   "NA"
0147 };
0148 
0149 static const char * const * const RtemsPartReqDelete_PreDesc[] = {
0150   RtemsPartReqDelete_PreDesc_Id,
0151   RtemsPartReqDelete_PreDesc_InUse,
0152   NULL
0153 };
0154 
0155 #define PART_NAME rtems_build_name( 'N', 'A', 'M', 'E' )
0156 
0157 #define BUFFER_COUNT 1
0158 
0159 #define BUFFER_SIZE ( 2 * sizeof( void * ) )
0160 
0161 static RTEMS_ALIGNED( RTEMS_PARTITION_ALIGNMENT ) uint8_t
0162   buffers[ BUFFER_COUNT ][ BUFFER_SIZE ];
0163 
0164 static void RtemsPartReqDelete_Pre_Id_Prepare(
0165   RtemsPartReqDelete_Context *ctx,
0166   RtemsPartReqDelete_Pre_Id   state
0167 )
0168 {
0169   switch ( state ) {
0170     case RtemsPartReqDelete_Pre_Id_NoObj: {
0171       /*
0172        * While the ``id`` parameter is not associated with a partition.
0173        */
0174       ctx->id = 0xffffffff;
0175       break;
0176     }
0177 
0178     case RtemsPartReqDelete_Pre_Id_Part: {
0179       /*
0180        * While the ``id`` parameter is associated with a partition.
0181        */
0182       ctx->id = ctx->id_value;
0183       break;
0184     }
0185 
0186     case RtemsPartReqDelete_Pre_Id_NA:
0187       break;
0188   }
0189 }
0190 
0191 static void RtemsPartReqDelete_Pre_InUse_Prepare(
0192   RtemsPartReqDelete_Context  *ctx,
0193   RtemsPartReqDelete_Pre_InUse state
0194 )
0195 {
0196   rtems_status_code sc;
0197 
0198   switch ( state ) {
0199     case RtemsPartReqDelete_Pre_InUse_Yes: {
0200       /*
0201        * While the partition has at least one buffer in use.
0202        */
0203       ctx->buffer = NULL;
0204       sc = rtems_partition_get_buffer( ctx->id_value, &ctx->buffer );
0205       T_rsc_success( sc );
0206       T_not_null( ctx->buffer );
0207       break;
0208     }
0209 
0210     case RtemsPartReqDelete_Pre_InUse_No: {
0211       /*
0212        * While the partition does not have a buffer in use.
0213        */
0214       ctx->buffer = NULL;
0215       break;
0216     }
0217 
0218     case RtemsPartReqDelete_Pre_InUse_NA:
0219       break;
0220   }
0221 }
0222 
0223 static void RtemsPartReqDelete_Post_Status_Check(
0224   RtemsPartReqDelete_Context    *ctx,
0225   RtemsPartReqDelete_Post_Status state
0226 )
0227 {
0228   rtems_status_code sc;
0229   rtems_id          id;
0230 
0231   switch ( state ) {
0232     case RtemsPartReqDelete_Post_Status_Ok: {
0233       /*
0234        * The status shall be RTEMS_SUCCESSFUL.  The deleted partition object
0235        * shall be inactive.
0236        */
0237       T_rsc_success( ctx->status );
0238       ctx->id_value = 0xffffffff;
0239 
0240       id = 0xffffffff;
0241       sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
0242       T_rsc( sc, RTEMS_INVALID_NAME );
0243       T_eq_u32( id, 0xffffffff );
0244       break;
0245     }
0246 
0247     case RtemsPartReqDelete_Post_Status_InvId: {
0248       /*
0249        * The status shall be RTEMS_INVALID_ID.
0250        */
0251       T_rsc( ctx->status, RTEMS_INVALID_ID );
0252 
0253       id = 0xffffffff;
0254       sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
0255       T_rsc_success( sc);
0256       T_eq_u32( id, ctx->id_value );
0257       break;
0258     }
0259 
0260     case RtemsPartReqDelete_Post_Status_InUse: {
0261       /*
0262        * The status shall be RTEMS_RESOURCE_IN_USE.
0263        */
0264       T_rsc( ctx->status, RTEMS_RESOURCE_IN_USE );
0265 
0266       id = 0xffffffff;
0267       sc = rtems_partition_ident( PART_NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
0268       T_rsc_success( sc);
0269       T_eq_u32( id, ctx->id_value );
0270       break;
0271     }
0272 
0273     case RtemsPartReqDelete_Post_Status_NA:
0274       break;
0275   }
0276 }
0277 
0278 static void RtemsPartReqDelete_Prepare( RtemsPartReqDelete_Context *ctx )
0279 {
0280   rtems_status_code sc;
0281 
0282   sc = rtems_partition_create(
0283     PART_NAME,
0284     buffers,
0285     sizeof( buffers ),
0286     sizeof( buffers[ 0 ] ),
0287     RTEMS_DEFAULT_ATTRIBUTES,
0288     &ctx->id_value
0289   );
0290   T_rsc_success( sc );
0291 }
0292 
0293 static void RtemsPartReqDelete_Action( RtemsPartReqDelete_Context *ctx )
0294 {
0295   ctx->status = rtems_partition_delete( ctx->id );
0296 }
0297 
0298 static void RtemsPartReqDelete_Cleanup( RtemsPartReqDelete_Context *ctx )
0299 {
0300   rtems_status_code sc;
0301 
0302   if ( ctx->buffer != NULL ) {
0303     sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer );
0304     T_rsc_success( sc );
0305   }
0306 
0307   if ( ctx->id_value != 0xffffffff ) {
0308     sc = rtems_partition_delete( ctx->id_value );
0309     T_rsc_success( sc );
0310   }
0311 }
0312 
0313 static const RtemsPartReqDelete_Entry
0314 RtemsPartReqDelete_Entries[] = {
0315   { 0, 0, 0, RtemsPartReqDelete_Post_Status_InvId },
0316   { 0, 0, 0, RtemsPartReqDelete_Post_Status_InUse },
0317   { 0, 0, 0, RtemsPartReqDelete_Post_Status_Ok }
0318 };
0319 
0320 static const uint8_t
0321 RtemsPartReqDelete_Map[] = {
0322   0, 0, 1, 2
0323 };
0324 
0325 static size_t RtemsPartReqDelete_Scope( void *arg, char *buf, size_t n )
0326 {
0327   RtemsPartReqDelete_Context *ctx;
0328 
0329   ctx = arg;
0330 
0331   if ( ctx->Map.in_action_loop ) {
0332     return T_get_scope( RtemsPartReqDelete_PreDesc, buf, n, ctx->Map.pcs );
0333   }
0334 
0335   return 0;
0336 }
0337 
0338 static T_fixture RtemsPartReqDelete_Fixture = {
0339   .setup = NULL,
0340   .stop = NULL,
0341   .teardown = NULL,
0342   .scope = RtemsPartReqDelete_Scope,
0343   .initial_context = &RtemsPartReqDelete_Instance
0344 };
0345 
0346 static inline RtemsPartReqDelete_Entry RtemsPartReqDelete_PopEntry(
0347   RtemsPartReqDelete_Context *ctx
0348 )
0349 {
0350   size_t index;
0351 
0352   index = ctx->Map.index;
0353   ctx->Map.index = index + 1;
0354   return RtemsPartReqDelete_Entries[
0355     RtemsPartReqDelete_Map[ index ]
0356   ];
0357 }
0358 
0359 static void RtemsPartReqDelete_TestVariant( RtemsPartReqDelete_Context *ctx )
0360 {
0361   RtemsPartReqDelete_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0362   RtemsPartReqDelete_Pre_InUse_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0363   RtemsPartReqDelete_Action( ctx );
0364   RtemsPartReqDelete_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0365 }
0366 
0367 /**
0368  * @fn void T_case_body_RtemsPartReqDelete( void )
0369  */
0370 T_TEST_CASE_FIXTURE( RtemsPartReqDelete, &RtemsPartReqDelete_Fixture )
0371 {
0372   RtemsPartReqDelete_Context *ctx;
0373 
0374   ctx = T_fixture_context();
0375   ctx->Map.in_action_loop = true;
0376   ctx->Map.index = 0;
0377 
0378   for (
0379     ctx->Map.pcs[ 0 ] = RtemsPartReqDelete_Pre_Id_NoObj;
0380     ctx->Map.pcs[ 0 ] < RtemsPartReqDelete_Pre_Id_NA;
0381     ++ctx->Map.pcs[ 0 ]
0382   ) {
0383     for (
0384       ctx->Map.pcs[ 1 ] = RtemsPartReqDelete_Pre_InUse_Yes;
0385       ctx->Map.pcs[ 1 ] < RtemsPartReqDelete_Pre_InUse_NA;
0386       ++ctx->Map.pcs[ 1 ]
0387     ) {
0388       ctx->Map.entry = RtemsPartReqDelete_PopEntry( ctx );
0389       RtemsPartReqDelete_Prepare( ctx );
0390       RtemsPartReqDelete_TestVariant( ctx );
0391       RtemsPartReqDelete_Cleanup( ctx );
0392     }
0393   }
0394 }
0395 
0396 /** @} */