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 RtemsRatemonReqDelete
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 RtemsRatemonReqDelete spec:/rtems/ratemon/req/delete
0062  *
0063  * @ingroup TestsuitesValidationNoClock0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   RtemsRatemonReqDelete_Pre_Id_NoObj,
0070   RtemsRatemonReqDelete_Pre_Id_Period,
0071   RtemsRatemonReqDelete_Pre_Id_NA
0072 } RtemsRatemonReqDelete_Pre_Id;
0073 
0074 typedef enum {
0075   RtemsRatemonReqDelete_Post_Status_Ok,
0076   RtemsRatemonReqDelete_Post_Status_InvId,
0077   RtemsRatemonReqDelete_Post_Status_NA
0078 } RtemsRatemonReqDelete_Post_Status;
0079 
0080 typedef enum {
0081   RtemsRatemonReqDelete_Post_Name_Valid,
0082   RtemsRatemonReqDelete_Post_Name_Invalid,
0083   RtemsRatemonReqDelete_Post_Name_NA
0084 } RtemsRatemonReqDelete_Post_Name;
0085 
0086 typedef struct {
0087   uint8_t Skip : 1;
0088   uint8_t Pre_Id_NA : 1;
0089   uint8_t Post_Status : 2;
0090   uint8_t Post_Name : 2;
0091 } RtemsRatemonReqDelete_Entry;
0092 
0093 /**
0094  * @brief Test context for spec:/rtems/ratemon/req/delete test case.
0095  */
0096 typedef struct {
0097   rtems_id period_id;
0098 
0099   rtems_id id;
0100 
0101   rtems_status_code status;
0102 
0103   struct {
0104     /**
0105      * @brief This member defines the pre-condition states for the next action.
0106      */
0107     size_t pcs[ 1 ];
0108 
0109     /**
0110      * @brief If this member is true, then the test action loop is executed.
0111      */
0112     bool in_action_loop;
0113 
0114     /**
0115      * @brief This member contains the next transition map index.
0116      */
0117     size_t index;
0118 
0119     /**
0120      * @brief This member contains the current transition map entry.
0121      */
0122     RtemsRatemonReqDelete_Entry entry;
0123 
0124     /**
0125      * @brief If this member is true, then the current transition variant
0126      *   should be skipped.
0127      */
0128     bool skip;
0129   } Map;
0130 } RtemsRatemonReqDelete_Context;
0131 
0132 static RtemsRatemonReqDelete_Context
0133   RtemsRatemonReqDelete_Instance;
0134 
0135 static const char * const RtemsRatemonReqDelete_PreDesc_Id[] = {
0136   "NoObj",
0137   "Period",
0138   "NA"
0139 };
0140 
0141 static const char * const * const RtemsRatemonReqDelete_PreDesc[] = {
0142   RtemsRatemonReqDelete_PreDesc_Id,
0143   NULL
0144 };
0145 
0146 #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
0147 
0148 static void RtemsRatemonReqDelete_Pre_Id_Prepare(
0149   RtemsRatemonReqDelete_Context *ctx,
0150   RtemsRatemonReqDelete_Pre_Id   state
0151 )
0152 {
0153   switch ( state ) {
0154     case RtemsRatemonReqDelete_Pre_Id_NoObj: {
0155       /*
0156        * While the ``id`` parameter is not associated with a period.
0157        */
0158       ctx->id = 0;
0159       break;
0160     }
0161 
0162     case RtemsRatemonReqDelete_Pre_Id_Period: {
0163       /*
0164        * While the ``id`` parameter is associated with a period.
0165        */
0166       ctx->id = ctx->period_id;
0167       break;
0168     }
0169 
0170     case RtemsRatemonReqDelete_Pre_Id_NA:
0171       break;
0172   }
0173 }
0174 
0175 static void RtemsRatemonReqDelete_Post_Status_Check(
0176   RtemsRatemonReqDelete_Context    *ctx,
0177   RtemsRatemonReqDelete_Post_Status state
0178 )
0179 {
0180   switch ( state ) {
0181     case RtemsRatemonReqDelete_Post_Status_Ok: {
0182       /*
0183        * The return status of rtems_rate_monotonic_delete() shall be
0184        * RTEMS_SUCCESSFUL.
0185        */
0186       ctx->period_id = 0;
0187       T_rsc_success( ctx->status );
0188       break;
0189     }
0190 
0191     case RtemsRatemonReqDelete_Post_Status_InvId: {
0192       /*
0193        * The return status of rtems_rate_monotonic_delete() shall be
0194        * RTEMS_INVALID_ID.
0195        */
0196       T_rsc( ctx->status, RTEMS_INVALID_ID );
0197       break;
0198     }
0199 
0200     case RtemsRatemonReqDelete_Post_Status_NA:
0201       break;
0202   }
0203 }
0204 
0205 static void RtemsRatemonReqDelete_Post_Name_Check(
0206   RtemsRatemonReqDelete_Context  *ctx,
0207   RtemsRatemonReqDelete_Post_Name state
0208 )
0209 {
0210   rtems_status_code sc;
0211   rtems_id          id;
0212 
0213   switch ( state ) {
0214     case RtemsRatemonReqDelete_Post_Name_Valid: {
0215       /*
0216        * The unique object name shall identify a period.
0217        */
0218       id = 0;
0219       sc = rtems_rate_monotonic_ident( NAME, &id );
0220       T_rsc_success( sc );
0221       T_eq_u32( id, ctx->period_id );
0222       break;
0223     }
0224 
0225     case RtemsRatemonReqDelete_Post_Name_Invalid: {
0226       /*
0227        * The unique object name shall not identify a period.
0228        */
0229       sc = rtems_rate_monotonic_ident( NAME, &id );
0230       T_rsc( sc, RTEMS_INVALID_NAME );
0231       break;
0232     }
0233 
0234     case RtemsRatemonReqDelete_Post_Name_NA:
0235       break;
0236   }
0237 }
0238 
0239 static void RtemsRatemonReqDelete_Setup( RtemsRatemonReqDelete_Context *ctx )
0240 {
0241   memset( ctx, 0, sizeof( *ctx ) );
0242 }
0243 
0244 static void RtemsRatemonReqDelete_Setup_Wrap( void *arg )
0245 {
0246   RtemsRatemonReqDelete_Context *ctx;
0247 
0248   ctx = arg;
0249   ctx->Map.in_action_loop = false;
0250   RtemsRatemonReqDelete_Setup( ctx );
0251 }
0252 
0253 static void RtemsRatemonReqDelete_Teardown(
0254   RtemsRatemonReqDelete_Context *ctx
0255 )
0256 {
0257   if ( ctx->period_id != 0 ) {
0258     rtems_status_code sc;
0259 
0260     sc = rtems_rate_monotonic_delete( ctx->period_id );
0261     T_rsc_success( sc );
0262   }
0263 }
0264 
0265 static void RtemsRatemonReqDelete_Teardown_Wrap( void *arg )
0266 {
0267   RtemsRatemonReqDelete_Context *ctx;
0268 
0269   ctx = arg;
0270   ctx->Map.in_action_loop = false;
0271   RtemsRatemonReqDelete_Teardown( ctx );
0272 }
0273 
0274 static void RtemsRatemonReqDelete_Prepare( RtemsRatemonReqDelete_Context *ctx )
0275 {
0276   if ( ctx->period_id == 0 ) {
0277     rtems_status_code sc;
0278 
0279     sc = rtems_rate_monotonic_create( NAME, &ctx->period_id );
0280     T_rsc_success( sc );
0281   }
0282 }
0283 
0284 static void RtemsRatemonReqDelete_Action( RtemsRatemonReqDelete_Context *ctx )
0285 {
0286   ctx->status = rtems_rate_monotonic_delete( ctx->id );
0287 }
0288 
0289 static const RtemsRatemonReqDelete_Entry
0290 RtemsRatemonReqDelete_Entries[] = {
0291   { 0, 0, RtemsRatemonReqDelete_Post_Status_InvId,
0292     RtemsRatemonReqDelete_Post_Name_Valid },
0293   { 0, 0, RtemsRatemonReqDelete_Post_Status_Ok,
0294     RtemsRatemonReqDelete_Post_Name_Invalid }
0295 };
0296 
0297 static const uint8_t
0298 RtemsRatemonReqDelete_Map[] = {
0299   0, 1
0300 };
0301 
0302 static size_t RtemsRatemonReqDelete_Scope( void *arg, char *buf, size_t n )
0303 {
0304   RtemsRatemonReqDelete_Context *ctx;
0305 
0306   ctx = arg;
0307 
0308   if ( ctx->Map.in_action_loop ) {
0309     return T_get_scope( RtemsRatemonReqDelete_PreDesc, buf, n, ctx->Map.pcs );
0310   }
0311 
0312   return 0;
0313 }
0314 
0315 static T_fixture RtemsRatemonReqDelete_Fixture = {
0316   .setup = RtemsRatemonReqDelete_Setup_Wrap,
0317   .stop = NULL,
0318   .teardown = RtemsRatemonReqDelete_Teardown_Wrap,
0319   .scope = RtemsRatemonReqDelete_Scope,
0320   .initial_context = &RtemsRatemonReqDelete_Instance
0321 };
0322 
0323 static inline RtemsRatemonReqDelete_Entry RtemsRatemonReqDelete_PopEntry(
0324   RtemsRatemonReqDelete_Context *ctx
0325 )
0326 {
0327   size_t index;
0328 
0329   index = ctx->Map.index;
0330   ctx->Map.index = index + 1;
0331   return RtemsRatemonReqDelete_Entries[
0332     RtemsRatemonReqDelete_Map[ index ]
0333   ];
0334 }
0335 
0336 static void RtemsRatemonReqDelete_TestVariant(
0337   RtemsRatemonReqDelete_Context *ctx
0338 )
0339 {
0340   RtemsRatemonReqDelete_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0341   RtemsRatemonReqDelete_Action( ctx );
0342   RtemsRatemonReqDelete_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0343   RtemsRatemonReqDelete_Post_Name_Check( ctx, ctx->Map.entry.Post_Name );
0344 }
0345 
0346 /**
0347  * @fn void T_case_body_RtemsRatemonReqDelete( void )
0348  */
0349 T_TEST_CASE_FIXTURE( RtemsRatemonReqDelete, &RtemsRatemonReqDelete_Fixture )
0350 {
0351   RtemsRatemonReqDelete_Context *ctx;
0352 
0353   ctx = T_fixture_context();
0354   ctx->Map.in_action_loop = true;
0355   ctx->Map.index = 0;
0356 
0357   for (
0358     ctx->Map.pcs[ 0 ] = RtemsRatemonReqDelete_Pre_Id_NoObj;
0359     ctx->Map.pcs[ 0 ] < RtemsRatemonReqDelete_Pre_Id_NA;
0360     ++ctx->Map.pcs[ 0 ]
0361   ) {
0362     ctx->Map.entry = RtemsRatemonReqDelete_PopEntry( ctx );
0363     RtemsRatemonReqDelete_Prepare( ctx );
0364     RtemsRatemonReqDelete_TestVariant( ctx );
0365   }
0366 }
0367 
0368 /** @} */