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 RtemsRatemonReqCreate
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 "tx-support.h"
0059 
0060 #include <rtems/test.h>
0061 
0062 /**
0063  * @defgroup RtemsRatemonReqCreate spec:/rtems/ratemon/req/create
0064  *
0065  * @ingroup TestsuitesValidationNoClock0
0066  *
0067  * @{
0068  */
0069 
0070 typedef enum {
0071   RtemsRatemonReqCreate_Pre_Name_Valid,
0072   RtemsRatemonReqCreate_Pre_Name_Invalid,
0073   RtemsRatemonReqCreate_Pre_Name_NA
0074 } RtemsRatemonReqCreate_Pre_Name;
0075 
0076 typedef enum {
0077   RtemsRatemonReqCreate_Pre_Id_Valid,
0078   RtemsRatemonReqCreate_Pre_Id_Null,
0079   RtemsRatemonReqCreate_Pre_Id_NA
0080 } RtemsRatemonReqCreate_Pre_Id;
0081 
0082 typedef enum {
0083   RtemsRatemonReqCreate_Pre_Free_Yes,
0084   RtemsRatemonReqCreate_Pre_Free_No,
0085   RtemsRatemonReqCreate_Pre_Free_NA
0086 } RtemsRatemonReqCreate_Pre_Free;
0087 
0088 typedef enum {
0089   RtemsRatemonReqCreate_Post_Status_Ok,
0090   RtemsRatemonReqCreate_Post_Status_InvName,
0091   RtemsRatemonReqCreate_Post_Status_InvAddr,
0092   RtemsRatemonReqCreate_Post_Status_TooMany,
0093   RtemsRatemonReqCreate_Post_Status_NA
0094 } RtemsRatemonReqCreate_Post_Status;
0095 
0096 typedef enum {
0097   RtemsRatemonReqCreate_Post_Name_Valid,
0098   RtemsRatemonReqCreate_Post_Name_Invalid,
0099   RtemsRatemonReqCreate_Post_Name_NA
0100 } RtemsRatemonReqCreate_Post_Name;
0101 
0102 typedef enum {
0103   RtemsRatemonReqCreate_Post_IdVar_Set,
0104   RtemsRatemonReqCreate_Post_IdVar_Nop,
0105   RtemsRatemonReqCreate_Post_IdVar_NA
0106 } RtemsRatemonReqCreate_Post_IdVar;
0107 
0108 typedef struct {
0109   uint16_t Skip : 1;
0110   uint16_t Pre_Name_NA : 1;
0111   uint16_t Pre_Id_NA : 1;
0112   uint16_t Pre_Free_NA : 1;
0113   uint16_t Post_Status : 3;
0114   uint16_t Post_Name : 2;
0115   uint16_t Post_IdVar : 2;
0116 } RtemsRatemonReqCreate_Entry;
0117 
0118 /**
0119  * @brief Test context for spec:/rtems/ratemon/req/create test case.
0120  */
0121 typedef struct {
0122   void *seized_objects;
0123 
0124   rtems_id id_value;
0125 
0126   rtems_name name;
0127 
0128   rtems_id *id;
0129 
0130   rtems_status_code status;
0131 
0132   struct {
0133     /**
0134      * @brief This member defines the pre-condition states for the next action.
0135      */
0136     size_t pcs[ 3 ];
0137 
0138     /**
0139      * @brief If this member is true, then the test action loop is executed.
0140      */
0141     bool in_action_loop;
0142 
0143     /**
0144      * @brief This member contains the next transition map index.
0145      */
0146     size_t index;
0147 
0148     /**
0149      * @brief This member contains the current transition map entry.
0150      */
0151     RtemsRatemonReqCreate_Entry entry;
0152 
0153     /**
0154      * @brief If this member is true, then the current transition variant
0155      *   should be skipped.
0156      */
0157     bool skip;
0158   } Map;
0159 } RtemsRatemonReqCreate_Context;
0160 
0161 static RtemsRatemonReqCreate_Context
0162   RtemsRatemonReqCreate_Instance;
0163 
0164 static const char * const RtemsRatemonReqCreate_PreDesc_Name[] = {
0165   "Valid",
0166   "Invalid",
0167   "NA"
0168 };
0169 
0170 static const char * const RtemsRatemonReqCreate_PreDesc_Id[] = {
0171   "Valid",
0172   "Null",
0173   "NA"
0174 };
0175 
0176 static const char * const RtemsRatemonReqCreate_PreDesc_Free[] = {
0177   "Yes",
0178   "No",
0179   "NA"
0180 };
0181 
0182 static const char * const * const RtemsRatemonReqCreate_PreDesc[] = {
0183   RtemsRatemonReqCreate_PreDesc_Name,
0184   RtemsRatemonReqCreate_PreDesc_Id,
0185   RtemsRatemonReqCreate_PreDesc_Free,
0186   NULL
0187 };
0188 
0189 #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
0190 
0191 static rtems_status_code Create( void *arg, uint32_t *id )
0192 {
0193   return rtems_rate_monotonic_create(
0194     rtems_build_name( 'S', 'I', 'Z', 'E' ),
0195     id
0196   );
0197 }
0198 
0199 static void RtemsRatemonReqCreate_Pre_Name_Prepare(
0200   RtemsRatemonReqCreate_Context *ctx,
0201   RtemsRatemonReqCreate_Pre_Name state
0202 )
0203 {
0204   switch ( state ) {
0205     case RtemsRatemonReqCreate_Pre_Name_Valid: {
0206       /*
0207        * While the ``name`` parameter is valid.
0208        */
0209       ctx->name = NAME;
0210       break;
0211     }
0212 
0213     case RtemsRatemonReqCreate_Pre_Name_Invalid: {
0214       /*
0215        * While the ``name`` parameter is invalid.
0216        */
0217       ctx->name = 0;
0218       break;
0219     }
0220 
0221     case RtemsRatemonReqCreate_Pre_Name_NA:
0222       break;
0223   }
0224 }
0225 
0226 static void RtemsRatemonReqCreate_Pre_Id_Prepare(
0227   RtemsRatemonReqCreate_Context *ctx,
0228   RtemsRatemonReqCreate_Pre_Id   state
0229 )
0230 {
0231   switch ( state ) {
0232     case RtemsRatemonReqCreate_Pre_Id_Valid: {
0233       /*
0234        * While the ``id`` parameter references an object of type rtems_id.
0235        */
0236       ctx->id = &ctx->id_value;
0237       break;
0238     }
0239 
0240     case RtemsRatemonReqCreate_Pre_Id_Null: {
0241       /*
0242        * While the ``id`` parameter is NULL.
0243        */
0244       ctx->id = NULL;
0245       break;
0246     }
0247 
0248     case RtemsRatemonReqCreate_Pre_Id_NA:
0249       break;
0250   }
0251 }
0252 
0253 static void RtemsRatemonReqCreate_Pre_Free_Prepare(
0254   RtemsRatemonReqCreate_Context *ctx,
0255   RtemsRatemonReqCreate_Pre_Free state
0256 )
0257 {
0258   switch ( state ) {
0259     case RtemsRatemonReqCreate_Pre_Free_Yes: {
0260       /*
0261        * While the system has at least one inactive period object available.
0262        */
0263       /* Nothing to do */
0264       break;
0265     }
0266 
0267     case RtemsRatemonReqCreate_Pre_Free_No: {
0268       /*
0269        * While the system has no inactive period object available.
0270        */
0271       ctx->seized_objects = T_seize_objects( Create, NULL );
0272       break;
0273     }
0274 
0275     case RtemsRatemonReqCreate_Pre_Free_NA:
0276       break;
0277   }
0278 }
0279 
0280 static void RtemsRatemonReqCreate_Post_Status_Check(
0281   RtemsRatemonReqCreate_Context    *ctx,
0282   RtemsRatemonReqCreate_Post_Status state
0283 )
0284 {
0285   switch ( state ) {
0286     case RtemsRatemonReqCreate_Post_Status_Ok: {
0287       /*
0288        * The return status of rtems_rate_monotonic_create() shall be
0289        * RTEMS_SUCCESSFUL.
0290        */
0291       T_rsc_success( ctx->status );
0292       break;
0293     }
0294 
0295     case RtemsRatemonReqCreate_Post_Status_InvName: {
0296       /*
0297        * The return status of rtems_rate_monotonic_create() shall be
0298        * RTEMS_INVALID_NAME.
0299        */
0300       T_rsc( ctx->status, RTEMS_INVALID_NAME );
0301       break;
0302     }
0303 
0304     case RtemsRatemonReqCreate_Post_Status_InvAddr: {
0305       /*
0306        * The return status of rtems_rate_monotonic_create() shall be
0307        * RTEMS_INVALID_ADDRESS.
0308        */
0309       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0310       break;
0311     }
0312 
0313     case RtemsRatemonReqCreate_Post_Status_TooMany: {
0314       /*
0315        * The return status of rtems_rate_monotonic_create() shall be
0316        * RTEMS_TOO_MANY.
0317        */
0318       T_rsc( ctx->status, RTEMS_TOO_MANY );
0319       break;
0320     }
0321 
0322     case RtemsRatemonReqCreate_Post_Status_NA:
0323       break;
0324   }
0325 }
0326 
0327 static void RtemsRatemonReqCreate_Post_Name_Check(
0328   RtemsRatemonReqCreate_Context  *ctx,
0329   RtemsRatemonReqCreate_Post_Name state
0330 )
0331 {
0332   rtems_status_code sc;
0333   rtems_id          id;
0334 
0335   switch ( state ) {
0336     case RtemsRatemonReqCreate_Post_Name_Valid: {
0337       /*
0338        * The unique object name shall identify the period created by the
0339        * rtems_rate_monotonic_create() call.
0340        */
0341       id = 0;
0342       sc = rtems_rate_monotonic_ident( NAME, &id );
0343       T_rsc_success( sc );
0344       T_eq_u32( id, ctx->id_value );
0345       break;
0346     }
0347 
0348     case RtemsRatemonReqCreate_Post_Name_Invalid: {
0349       /*
0350        * The unique object name shall not identify a period.
0351        */
0352       sc = rtems_rate_monotonic_ident( NAME, &id );
0353       T_rsc( sc, RTEMS_INVALID_NAME );
0354       break;
0355     }
0356 
0357     case RtemsRatemonReqCreate_Post_Name_NA:
0358       break;
0359   }
0360 }
0361 
0362 static void RtemsRatemonReqCreate_Post_IdVar_Check(
0363   RtemsRatemonReqCreate_Context   *ctx,
0364   RtemsRatemonReqCreate_Post_IdVar state
0365 )
0366 {
0367   switch ( state ) {
0368     case RtemsRatemonReqCreate_Post_IdVar_Set: {
0369       /*
0370        * The value of the object referenced by the ``id`` parameter shall be
0371        * set to the object identifier of the created period after the return of
0372        * the rtems_rate_monotonic_create() call.
0373        */
0374       T_eq_ptr( ctx->id, &ctx->id_value );
0375       T_ne_u32( ctx->id_value, INVALID_ID );
0376       break;
0377     }
0378 
0379     case RtemsRatemonReqCreate_Post_IdVar_Nop: {
0380       /*
0381        * Objects referenced by the ``id`` parameter in past calls to
0382        * rtems_rate_monotonic_create() shall not be accessed by the
0383        * rtems_rate_monotonic_create() call.
0384        */
0385       T_eq_u32( ctx->id_value, INVALID_ID );
0386       break;
0387     }
0388 
0389     case RtemsRatemonReqCreate_Post_IdVar_NA:
0390       break;
0391   }
0392 }
0393 
0394 static void RtemsRatemonReqCreate_Setup( RtemsRatemonReqCreate_Context *ctx )
0395 {
0396   memset( ctx, 0, sizeof( *ctx ) );
0397   ctx->id_value = INVALID_ID;
0398 }
0399 
0400 static void RtemsRatemonReqCreate_Setup_Wrap( void *arg )
0401 {
0402   RtemsRatemonReqCreate_Context *ctx;
0403 
0404   ctx = arg;
0405   ctx->Map.in_action_loop = false;
0406   RtemsRatemonReqCreate_Setup( ctx );
0407 }
0408 
0409 static void RtemsRatemonReqCreate_Action( RtemsRatemonReqCreate_Context *ctx )
0410 {
0411   ctx->status = rtems_rate_monotonic_create( ctx->name, ctx->id );
0412 }
0413 
0414 static void RtemsRatemonReqCreate_Cleanup( RtemsRatemonReqCreate_Context *ctx )
0415 {
0416   if ( ctx->id_value != INVALID_ID ) {
0417     rtems_status_code sc;
0418 
0419     sc = rtems_rate_monotonic_delete( ctx->id_value );
0420     T_rsc_success( sc );
0421 
0422     ctx->id_value = INVALID_ID;
0423   }
0424 
0425   T_surrender_objects( &ctx->seized_objects, rtems_rate_monotonic_delete );
0426 }
0427 
0428 static const RtemsRatemonReqCreate_Entry
0429 RtemsRatemonReqCreate_Entries[] = {
0430   { 0, 0, 0, 0, RtemsRatemonReqCreate_Post_Status_InvName,
0431     RtemsRatemonReqCreate_Post_Name_Invalid,
0432     RtemsRatemonReqCreate_Post_IdVar_Nop },
0433   { 0, 0, 0, 0, RtemsRatemonReqCreate_Post_Status_InvAddr,
0434     RtemsRatemonReqCreate_Post_Name_Invalid,
0435     RtemsRatemonReqCreate_Post_IdVar_Nop },
0436   { 0, 0, 0, 0, RtemsRatemonReqCreate_Post_Status_Ok,
0437     RtemsRatemonReqCreate_Post_Name_Valid, RtemsRatemonReqCreate_Post_IdVar_Set },
0438   { 0, 0, 0, 0, RtemsRatemonReqCreate_Post_Status_TooMany,
0439     RtemsRatemonReqCreate_Post_Name_Invalid,
0440     RtemsRatemonReqCreate_Post_IdVar_Nop }
0441 };
0442 
0443 static const uint8_t
0444 RtemsRatemonReqCreate_Map[] = {
0445   2, 3, 1, 1, 0, 0, 0, 0
0446 };
0447 
0448 static size_t RtemsRatemonReqCreate_Scope( void *arg, char *buf, size_t n )
0449 {
0450   RtemsRatemonReqCreate_Context *ctx;
0451 
0452   ctx = arg;
0453 
0454   if ( ctx->Map.in_action_loop ) {
0455     return T_get_scope( RtemsRatemonReqCreate_PreDesc, buf, n, ctx->Map.pcs );
0456   }
0457 
0458   return 0;
0459 }
0460 
0461 static T_fixture RtemsRatemonReqCreate_Fixture = {
0462   .setup = RtemsRatemonReqCreate_Setup_Wrap,
0463   .stop = NULL,
0464   .teardown = NULL,
0465   .scope = RtemsRatemonReqCreate_Scope,
0466   .initial_context = &RtemsRatemonReqCreate_Instance
0467 };
0468 
0469 static inline RtemsRatemonReqCreate_Entry RtemsRatemonReqCreate_PopEntry(
0470   RtemsRatemonReqCreate_Context *ctx
0471 )
0472 {
0473   size_t index;
0474 
0475   index = ctx->Map.index;
0476   ctx->Map.index = index + 1;
0477   return RtemsRatemonReqCreate_Entries[
0478     RtemsRatemonReqCreate_Map[ index ]
0479   ];
0480 }
0481 
0482 static void RtemsRatemonReqCreate_TestVariant(
0483   RtemsRatemonReqCreate_Context *ctx
0484 )
0485 {
0486   RtemsRatemonReqCreate_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0487   RtemsRatemonReqCreate_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0488   RtemsRatemonReqCreate_Pre_Free_Prepare( ctx, ctx->Map.pcs[ 2 ] );
0489   RtemsRatemonReqCreate_Action( ctx );
0490   RtemsRatemonReqCreate_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0491   RtemsRatemonReqCreate_Post_Name_Check( ctx, ctx->Map.entry.Post_Name );
0492   RtemsRatemonReqCreate_Post_IdVar_Check( ctx, ctx->Map.entry.Post_IdVar );
0493 }
0494 
0495 /**
0496  * @fn void T_case_body_RtemsRatemonReqCreate( void )
0497  */
0498 T_TEST_CASE_FIXTURE( RtemsRatemonReqCreate, &RtemsRatemonReqCreate_Fixture )
0499 {
0500   RtemsRatemonReqCreate_Context *ctx;
0501 
0502   ctx = T_fixture_context();
0503   ctx->Map.in_action_loop = true;
0504   ctx->Map.index = 0;
0505 
0506   for (
0507     ctx->Map.pcs[ 0 ] = RtemsRatemonReqCreate_Pre_Name_Valid;
0508     ctx->Map.pcs[ 0 ] < RtemsRatemonReqCreate_Pre_Name_NA;
0509     ++ctx->Map.pcs[ 0 ]
0510   ) {
0511     for (
0512       ctx->Map.pcs[ 1 ] = RtemsRatemonReqCreate_Pre_Id_Valid;
0513       ctx->Map.pcs[ 1 ] < RtemsRatemonReqCreate_Pre_Id_NA;
0514       ++ctx->Map.pcs[ 1 ]
0515     ) {
0516       for (
0517         ctx->Map.pcs[ 2 ] = RtemsRatemonReqCreate_Pre_Free_Yes;
0518         ctx->Map.pcs[ 2 ] < RtemsRatemonReqCreate_Pre_Free_NA;
0519         ++ctx->Map.pcs[ 2 ]
0520       ) {
0521         ctx->Map.entry = RtemsRatemonReqCreate_PopEntry( ctx );
0522         RtemsRatemonReqCreate_TestVariant( ctx );
0523         RtemsRatemonReqCreate_Cleanup( ctx );
0524       }
0525     }
0526   }
0527 }
0528 
0529 /** @} */