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 RtemsReqIdentLocal
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 "tr-object-ident-local.h"
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsReqIdentLocal spec:/rtems/req/ident-local
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef struct {
0068   uint8_t Skip : 1;
0069   uint8_t Pre_Name_NA : 1;
0070   uint8_t Pre_Id_NA : 1;
0071   uint8_t Post_Status : 2;
0072   uint8_t Post_Id : 2;
0073 } RtemsReqIdentLocal_Entry;
0074 
0075 /**
0076  * @brief Test context for spec:/rtems/req/ident-local test case.
0077  */
0078 typedef struct {
0079   rtems_status_code status;
0080 
0081   rtems_name name;
0082 
0083   rtems_id *id;
0084 
0085   rtems_id id_value;
0086 
0087   /**
0088    * @brief This member contains a copy of the corresponding
0089    *   RtemsReqIdentLocal_Run() parameter.
0090    */
0091   rtems_id id_local_object;
0092 
0093   /**
0094    * @brief This member contains a copy of the corresponding
0095    *   RtemsReqIdentLocal_Run() parameter.
0096    */
0097   rtems_name name_local_object;
0098 
0099   /**
0100    * @brief This member contains a copy of the corresponding
0101    *   RtemsReqIdentLocal_Run() parameter.
0102    */
0103   rtems_status_code ( *action )( rtems_name, rtems_id * );
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     RtemsReqIdentLocal_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 } RtemsReqIdentLocal_Context;
0133 
0134 static RtemsReqIdentLocal_Context
0135   RtemsReqIdentLocal_Instance;
0136 
0137 static const char * const RtemsReqIdentLocal_PreDesc_Name[] = {
0138   "Invalid",
0139   "Valid",
0140   "NA"
0141 };
0142 
0143 static const char * const RtemsReqIdentLocal_PreDesc_Id[] = {
0144   "Valid",
0145   "Null",
0146   "NA"
0147 };
0148 
0149 static const char * const * const RtemsReqIdentLocal_PreDesc[] = {
0150   RtemsReqIdentLocal_PreDesc_Name,
0151   RtemsReqIdentLocal_PreDesc_Id,
0152   NULL
0153 };
0154 
0155 static void RtemsReqIdentLocal_Pre_Name_Prepare(
0156   RtemsReqIdentLocal_Context *ctx,
0157   RtemsReqIdentLocal_Pre_Name state
0158 )
0159 {
0160   switch ( state ) {
0161     case RtemsReqIdentLocal_Pre_Name_Invalid: {
0162       /*
0163        * While the ``name`` parameter is not associated with an active object
0164        * of the specified class .
0165        */
0166       ctx->name = 1;
0167       break;
0168     }
0169 
0170     case RtemsReqIdentLocal_Pre_Name_Valid: {
0171       /*
0172        * While the ``name`` parameter is associated with an active object of
0173        * the specified class .
0174        */
0175       ctx->name = ctx->name_local_object;
0176       break;
0177     }
0178 
0179     case RtemsReqIdentLocal_Pre_Name_NA:
0180       break;
0181   }
0182 }
0183 
0184 static void RtemsReqIdentLocal_Pre_Id_Prepare(
0185   RtemsReqIdentLocal_Context *ctx,
0186   RtemsReqIdentLocal_Pre_Id   state
0187 )
0188 {
0189   switch ( state ) {
0190     case RtemsReqIdentLocal_Pre_Id_Valid: {
0191       /*
0192        * While the ``id`` parameter references an object of type rtems_id.
0193        */
0194       ctx->id_value = 0xffffffff;
0195       ctx->id = &ctx->id_value;
0196       break;
0197     }
0198 
0199     case RtemsReqIdentLocal_Pre_Id_Null: {
0200       /*
0201        * While the ``id`` parameter is NULL.
0202        */
0203       ctx->id = NULL;
0204       break;
0205     }
0206 
0207     case RtemsReqIdentLocal_Pre_Id_NA:
0208       break;
0209   }
0210 }
0211 
0212 static void RtemsReqIdentLocal_Post_Status_Check(
0213   RtemsReqIdentLocal_Context    *ctx,
0214   RtemsReqIdentLocal_Post_Status state
0215 )
0216 {
0217   switch ( state ) {
0218     case RtemsReqIdentLocal_Post_Status_Ok: {
0219       /*
0220        * The return status shall be RTEMS_SUCCESSFUL.
0221        */
0222       T_rsc( ctx->status, RTEMS_SUCCESSFUL );
0223       break;
0224     }
0225 
0226     case RtemsReqIdentLocal_Post_Status_InvAddr: {
0227       /*
0228        * The return status shall be RTEMS_INVALID_ADDRESS.
0229        */
0230       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0231       break;
0232     }
0233 
0234     case RtemsReqIdentLocal_Post_Status_InvName: {
0235       /*
0236        * The return status shall be RTEMS_INVALID_NAME.
0237        */
0238       T_rsc( ctx->status, RTEMS_INVALID_NAME );
0239       break;
0240     }
0241 
0242     case RtemsReqIdentLocal_Post_Status_NA:
0243       break;
0244   }
0245 }
0246 
0247 static void RtemsReqIdentLocal_Post_Id_Check(
0248   RtemsReqIdentLocal_Context *ctx,
0249   RtemsReqIdentLocal_Post_Id  state
0250 )
0251 {
0252   switch ( state ) {
0253     case RtemsReqIdentLocal_Post_Id_Nop: {
0254       /*
0255        * The value of the object identifier referenced by the id parameter
0256        * shall be the value before the action.
0257        */
0258       T_eq_ptr( ctx->id, &ctx->id_value );
0259       T_eq_u32( ctx->id_value, 0xffffffff );
0260       break;
0261     }
0262 
0263     case RtemsReqIdentLocal_Post_Id_Null: {
0264       /*
0265        * While the id is NULL.
0266        */
0267       T_null( ctx->id )
0268       break;
0269     }
0270 
0271     case RtemsReqIdentLocal_Post_Id_Id: {
0272       /*
0273        * The value of the object identifier referenced by the id parameter
0274        * shall be the identifier of a local object of the specified class with
0275        * a name equal to the name parameter.  If more than one local object of
0276        * the specified class with such a name exists, then it shall be the
0277        * identifier of the object with the lowest object index.
0278        */
0279       T_eq_ptr( ctx->id, &ctx->id_value );
0280       T_eq_u32( ctx->id_value, ctx->id_local_object );
0281       break;
0282     }
0283 
0284     case RtemsReqIdentLocal_Post_Id_NA:
0285       break;
0286   }
0287 }
0288 
0289 static void RtemsReqIdentLocal_Action( RtemsReqIdentLocal_Context *ctx )
0290 {
0291   ctx->status = ( *ctx->action )( ctx->name, ctx->id );
0292 }
0293 
0294 static const RtemsReqIdentLocal_Entry
0295 RtemsReqIdentLocal_Entries[] = {
0296   { 0, 0, 0, RtemsReqIdentLocal_Post_Status_InvAddr,
0297     RtemsReqIdentLocal_Post_Id_Null },
0298   { 0, 0, 0, RtemsReqIdentLocal_Post_Status_InvName,
0299     RtemsReqIdentLocal_Post_Id_Nop },
0300   { 0, 0, 0, RtemsReqIdentLocal_Post_Status_Ok, RtemsReqIdentLocal_Post_Id_Id }
0301 };
0302 
0303 static const uint8_t
0304 RtemsReqIdentLocal_Map[] = {
0305   1, 0, 2, 0
0306 };
0307 
0308 static size_t RtemsReqIdentLocal_Scope( void *arg, char *buf, size_t n )
0309 {
0310   RtemsReqIdentLocal_Context *ctx;
0311 
0312   ctx = arg;
0313 
0314   if ( ctx->Map.in_action_loop ) {
0315     return T_get_scope( RtemsReqIdentLocal_PreDesc, buf, n, ctx->Map.pcs );
0316   }
0317 
0318   return 0;
0319 }
0320 
0321 static T_fixture RtemsReqIdentLocal_Fixture = {
0322   .setup = NULL,
0323   .stop = NULL,
0324   .teardown = NULL,
0325   .scope = RtemsReqIdentLocal_Scope,
0326   .initial_context = &RtemsReqIdentLocal_Instance
0327 };
0328 
0329 static inline RtemsReqIdentLocal_Entry RtemsReqIdentLocal_PopEntry(
0330   RtemsReqIdentLocal_Context *ctx
0331 )
0332 {
0333   size_t index;
0334 
0335   index = ctx->Map.index;
0336   ctx->Map.index = index + 1;
0337   return RtemsReqIdentLocal_Entries[
0338     RtemsReqIdentLocal_Map[ index ]
0339   ];
0340 }
0341 
0342 static void RtemsReqIdentLocal_TestVariant( RtemsReqIdentLocal_Context *ctx )
0343 {
0344   RtemsReqIdentLocal_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0345   RtemsReqIdentLocal_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0346   RtemsReqIdentLocal_Action( ctx );
0347   RtemsReqIdentLocal_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0348   RtemsReqIdentLocal_Post_Id_Check( ctx, ctx->Map.entry.Post_Id );
0349 }
0350 
0351 static T_fixture_node RtemsReqIdentLocal_Node;
0352 
0353 static T_remark RtemsReqIdentLocal_Remark = {
0354   .next = NULL,
0355   .remark = "RtemsReqIdentLocal"
0356 };
0357 
0358 void RtemsReqIdentLocal_Run(
0359   rtems_id             id_local_object,
0360   rtems_name           name_local_object,
0361   rtems_status_code ( *action )( rtems_name, rtems_id * )
0362 )
0363 {
0364   RtemsReqIdentLocal_Context *ctx;
0365 
0366   ctx = &RtemsReqIdentLocal_Instance;
0367   ctx->id_local_object = id_local_object;
0368   ctx->name_local_object = name_local_object;
0369   ctx->action = action;
0370 
0371   ctx = T_push_fixture( &RtemsReqIdentLocal_Node, &RtemsReqIdentLocal_Fixture );
0372   ctx->Map.in_action_loop = true;
0373   ctx->Map.index = 0;
0374 
0375   for (
0376     ctx->Map.pcs[ 0 ] = RtemsReqIdentLocal_Pre_Name_Invalid;
0377     ctx->Map.pcs[ 0 ] < RtemsReqIdentLocal_Pre_Name_NA;
0378     ++ctx->Map.pcs[ 0 ]
0379   ) {
0380     for (
0381       ctx->Map.pcs[ 1 ] = RtemsReqIdentLocal_Pre_Id_Valid;
0382       ctx->Map.pcs[ 1 ] < RtemsReqIdentLocal_Pre_Id_NA;
0383       ++ctx->Map.pcs[ 1 ]
0384     ) {
0385       ctx->Map.entry = RtemsReqIdentLocal_PopEntry( ctx );
0386       RtemsReqIdentLocal_TestVariant( ctx );
0387     }
0388   }
0389 
0390   T_add_remark( &RtemsReqIdentLocal_Remark );
0391   T_pop_fixture();
0392 }
0393 
0394 /** @} */