Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsUserextReqDelete
0007  */
0008 
0009 /*
0010  * Copyright (C) 2021 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 #include <string.h>
0057 
0058 #include <rtems/test.h>
0059 
0060 /**
0061  * @defgroup RtemsUserextReqDelete spec:/rtems/userext/req/delete
0062  *
0063  * @ingroup TestsuitesValidationNoClock0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   RtemsUserextReqDelete_Pre_Id_NoObj,
0070   RtemsUserextReqDelete_Pre_Id_ExtTdSw,
0071   RtemsUserextReqDelete_Pre_Id_ExtNoTdSw,
0072   RtemsUserextReqDelete_Pre_Id_NA
0073 } RtemsUserextReqDelete_Pre_Id;
0074 
0075 typedef enum {
0076   RtemsUserextReqDelete_Post_Status_Ok,
0077   RtemsUserextReqDelete_Post_Status_InvId,
0078   RtemsUserextReqDelete_Post_Status_NA
0079 } RtemsUserextReqDelete_Post_Status;
0080 
0081 typedef enum {
0082   RtemsUserextReqDelete_Post_Name_Valid,
0083   RtemsUserextReqDelete_Post_Name_Invalid,
0084   RtemsUserextReqDelete_Post_Name_NA
0085 } RtemsUserextReqDelete_Post_Name;
0086 
0087 typedef struct {
0088   uint8_t Skip : 1;
0089   uint8_t Pre_Id_NA : 1;
0090   uint8_t Post_Status : 2;
0091   uint8_t Post_Name : 2;
0092 } RtemsUserextReqDelete_Entry;
0093 
0094 /**
0095  * @brief Test context for spec:/rtems/userext/req/delete test case.
0096  */
0097 typedef struct {
0098   rtems_id extension_id;
0099 
0100   rtems_extensions_table table;
0101 
0102   rtems_id id;
0103 
0104   rtems_status_code status;
0105 
0106   struct {
0107     /**
0108      * @brief This member defines the pre-condition states for the next action.
0109      */
0110     size_t pcs[ 1 ];
0111 
0112     /**
0113      * @brief If this member is true, then the test action loop is executed.
0114      */
0115     bool in_action_loop;
0116 
0117     /**
0118      * @brief This member contains the next transition map index.
0119      */
0120     size_t index;
0121 
0122     /**
0123      * @brief This member contains the current transition map entry.
0124      */
0125     RtemsUserextReqDelete_Entry entry;
0126 
0127     /**
0128      * @brief If this member is true, then the current transition variant
0129      *   should be skipped.
0130      */
0131     bool skip;
0132   } Map;
0133 } RtemsUserextReqDelete_Context;
0134 
0135 static RtemsUserextReqDelete_Context
0136   RtemsUserextReqDelete_Instance;
0137 
0138 static const char * const RtemsUserextReqDelete_PreDesc_Id[] = {
0139   "NoObj",
0140   "ExtTdSw",
0141   "ExtNoTdSw",
0142   "NA"
0143 };
0144 
0145 static const char * const * const RtemsUserextReqDelete_PreDesc[] = {
0146   RtemsUserextReqDelete_PreDesc_Id,
0147   NULL
0148 };
0149 
0150 #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
0151 
0152 static void ThreadSwitch( rtems_tcb *executing,  rtems_tcb *heir)
0153 {
0154   (void) executing;
0155   (void) heir;
0156 }
0157 
0158 static void RtemsUserextReqDelete_Pre_Id_Prepare(
0159   RtemsUserextReqDelete_Context *ctx,
0160   RtemsUserextReqDelete_Pre_Id   state
0161 )
0162 {
0163   rtems_status_code sc;
0164   bool              valid_id;
0165 
0166   valid_id = false;
0167 
0168   switch ( state ) {
0169     case RtemsUserextReqDelete_Pre_Id_NoObj: {
0170       /*
0171        * While the ``id`` parameter is not associated with an extension set.
0172        */
0173       /* Already set by prologue */
0174       break;
0175     }
0176 
0177     case RtemsUserextReqDelete_Pre_Id_ExtTdSw: {
0178       /*
0179        * While the ``id`` parameter is associated with an extension set with a
0180        * thread switch extension.
0181        */
0182       valid_id = true;
0183       ctx->table.thread_switch = ThreadSwitch;
0184       break;
0185     }
0186 
0187     case RtemsUserextReqDelete_Pre_Id_ExtNoTdSw: {
0188       /*
0189        * While the ``id`` parameter is associated with an extension set without
0190        * a thread switch extension.
0191        */
0192       valid_id = true;
0193       ctx->table.thread_switch = NULL;
0194       break;
0195     }
0196 
0197     case RtemsUserextReqDelete_Pre_Id_NA:
0198       break;
0199   }
0200 
0201   sc = rtems_extension_create(
0202     NAME,
0203     &ctx->table,
0204     &ctx->extension_id
0205   );
0206   T_rsc_success( sc );
0207 
0208   if ( valid_id ) {
0209     ctx->id = ctx->extension_id;
0210   } else {
0211     ctx->id = 0;
0212   }
0213 }
0214 
0215 static void RtemsUserextReqDelete_Post_Status_Check(
0216   RtemsUserextReqDelete_Context    *ctx,
0217   RtemsUserextReqDelete_Post_Status state
0218 )
0219 {
0220   switch ( state ) {
0221     case RtemsUserextReqDelete_Post_Status_Ok: {
0222       /*
0223        * The return status of rtems_extension_delete() shall be
0224        * RTEMS_SUCCESSFUL.
0225        */
0226       ctx->extension_id = 0;
0227       T_rsc_success( ctx->status );
0228       break;
0229     }
0230 
0231     case RtemsUserextReqDelete_Post_Status_InvId: {
0232       /*
0233        * The return status of rtems_extension_delete() shall be
0234        * RTEMS_INVALID_ID.
0235        */
0236       T_rsc( ctx->status, RTEMS_INVALID_ID );
0237       break;
0238     }
0239 
0240     case RtemsUserextReqDelete_Post_Status_NA:
0241       break;
0242   }
0243 }
0244 
0245 static void RtemsUserextReqDelete_Post_Name_Check(
0246   RtemsUserextReqDelete_Context  *ctx,
0247   RtemsUserextReqDelete_Post_Name state
0248 )
0249 {
0250   rtems_status_code sc;
0251   rtems_id          id;
0252 
0253   switch ( state ) {
0254     case RtemsUserextReqDelete_Post_Name_Valid: {
0255       /*
0256        * The unique object name shall identify an extension set.
0257        */
0258       id = 0;
0259       sc = rtems_extension_ident( NAME, &id );
0260       T_rsc_success( sc );
0261       T_eq_u32( id, ctx->extension_id );
0262       break;
0263     }
0264 
0265     case RtemsUserextReqDelete_Post_Name_Invalid: {
0266       /*
0267        * The unique object name shall not identify an extension set.
0268        */
0269       sc = rtems_extension_ident( NAME, &id );
0270       T_rsc( sc, RTEMS_INVALID_NAME );
0271       break;
0272     }
0273 
0274     case RtemsUserextReqDelete_Post_Name_NA:
0275       break;
0276   }
0277 }
0278 
0279 static void RtemsUserextReqDelete_Setup( RtemsUserextReqDelete_Context *ctx )
0280 {
0281   memset( ctx, 0, sizeof( *ctx ) );
0282 }
0283 
0284 static void RtemsUserextReqDelete_Setup_Wrap( void *arg )
0285 {
0286   RtemsUserextReqDelete_Context *ctx;
0287 
0288   ctx = arg;
0289   ctx->Map.in_action_loop = false;
0290   RtemsUserextReqDelete_Setup( ctx );
0291 }
0292 
0293 static void RtemsUserextReqDelete_Action( RtemsUserextReqDelete_Context *ctx )
0294 {
0295   ctx->status = rtems_extension_delete( ctx->id );
0296 }
0297 
0298 static void RtemsUserextReqDelete_Cleanup( RtemsUserextReqDelete_Context *ctx )
0299 {
0300   if ( ctx->extension_id != 0 ) {
0301     rtems_status_code sc;
0302 
0303     sc = rtems_extension_delete( ctx->extension_id );
0304     T_rsc_success( sc );
0305   }
0306 }
0307 
0308 static const RtemsUserextReqDelete_Entry
0309 RtemsUserextReqDelete_Entries[] = {
0310   { 0, 0, RtemsUserextReqDelete_Post_Status_Ok,
0311     RtemsUserextReqDelete_Post_Name_Invalid },
0312   { 0, 0, RtemsUserextReqDelete_Post_Status_InvId,
0313     RtemsUserextReqDelete_Post_Name_Valid }
0314 };
0315 
0316 static const uint8_t
0317 RtemsUserextReqDelete_Map[] = {
0318   1, 0, 0
0319 };
0320 
0321 static size_t RtemsUserextReqDelete_Scope( void *arg, char *buf, size_t n )
0322 {
0323   RtemsUserextReqDelete_Context *ctx;
0324 
0325   ctx = arg;
0326 
0327   if ( ctx->Map.in_action_loop ) {
0328     return T_get_scope( RtemsUserextReqDelete_PreDesc, buf, n, ctx->Map.pcs );
0329   }
0330 
0331   return 0;
0332 }
0333 
0334 static T_fixture RtemsUserextReqDelete_Fixture = {
0335   .setup = RtemsUserextReqDelete_Setup_Wrap,
0336   .stop = NULL,
0337   .teardown = NULL,
0338   .scope = RtemsUserextReqDelete_Scope,
0339   .initial_context = &RtemsUserextReqDelete_Instance
0340 };
0341 
0342 static inline RtemsUserextReqDelete_Entry RtemsUserextReqDelete_PopEntry(
0343   RtemsUserextReqDelete_Context *ctx
0344 )
0345 {
0346   size_t index;
0347 
0348   index = ctx->Map.index;
0349   ctx->Map.index = index + 1;
0350   return RtemsUserextReqDelete_Entries[
0351     RtemsUserextReqDelete_Map[ index ]
0352   ];
0353 }
0354 
0355 static void RtemsUserextReqDelete_TestVariant(
0356   RtemsUserextReqDelete_Context *ctx
0357 )
0358 {
0359   RtemsUserextReqDelete_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0360   RtemsUserextReqDelete_Action( ctx );
0361   RtemsUserextReqDelete_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0362   RtemsUserextReqDelete_Post_Name_Check( ctx, ctx->Map.entry.Post_Name );
0363 }
0364 
0365 /**
0366  * @fn void T_case_body_RtemsUserextReqDelete( void )
0367  */
0368 T_TEST_CASE_FIXTURE( RtemsUserextReqDelete, &RtemsUserextReqDelete_Fixture )
0369 {
0370   RtemsUserextReqDelete_Context *ctx;
0371 
0372   ctx = T_fixture_context();
0373   ctx->Map.in_action_loop = true;
0374   ctx->Map.index = 0;
0375 
0376   for (
0377     ctx->Map.pcs[ 0 ] = RtemsUserextReqDelete_Pre_Id_NoObj;
0378     ctx->Map.pcs[ 0 ] < RtemsUserextReqDelete_Pre_Id_NA;
0379     ++ctx->Map.pcs[ 0 ]
0380   ) {
0381     ctx->Map.entry = RtemsUserextReqDelete_PopEntry( ctx );
0382     RtemsUserextReqDelete_TestVariant( ctx );
0383     RtemsUserextReqDelete_Cleanup( ctx );
0384   }
0385 }
0386 
0387 /** @} */