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 RtemsReqIdent
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.h"
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsReqIdent spec:/rtems/req/ident
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef struct {
0068   uint16_t Skip : 1;
0069   uint16_t Pre_Name_NA : 1;
0070   uint16_t Pre_Node_NA : 1;
0071   uint16_t Pre_Id_NA : 1;
0072   uint16_t Post_Status : 3;
0073   uint16_t Post_Id : 3;
0074 } RtemsReqIdent_Entry;
0075 
0076 /**
0077  * @brief Test context for spec:/rtems/req/ident test case.
0078  */
0079 typedef struct {
0080   rtems_status_code status;
0081 
0082   rtems_name name;
0083 
0084   uint32_t node;
0085 
0086   rtems_id *id;
0087 
0088   rtems_id id_value;
0089 
0090   rtems_id id_remote_object;
0091 
0092   /**
0093    * @brief This member contains a copy of the corresponding
0094    *   RtemsReqIdent_Run() parameter.
0095    */
0096   rtems_id id_local_object;
0097 
0098   /**
0099    * @brief This member contains a copy of the corresponding
0100    *   RtemsReqIdent_Run() parameter.
0101    */
0102   rtems_name name_local_object;
0103 
0104   /**
0105    * @brief This member contains a copy of the corresponding
0106    *   RtemsReqIdent_Run() parameter.
0107    */
0108   rtems_status_code ( *action )( rtems_name, uint32_t, rtems_id * );
0109 
0110   struct {
0111     /**
0112      * @brief This member defines the pre-condition states for the next action.
0113      */
0114     size_t pcs[ 3 ];
0115 
0116     /**
0117      * @brief If this member is true, then the test action loop is executed.
0118      */
0119     bool in_action_loop;
0120 
0121     /**
0122      * @brief This member contains the next transition map index.
0123      */
0124     size_t index;
0125 
0126     /**
0127      * @brief This member contains the current transition map entry.
0128      */
0129     RtemsReqIdent_Entry entry;
0130 
0131     /**
0132      * @brief If this member is true, then the current transition variant
0133      *   should be skipped.
0134      */
0135     bool skip;
0136   } Map;
0137 } RtemsReqIdent_Context;
0138 
0139 static RtemsReqIdent_Context
0140   RtemsReqIdent_Instance;
0141 
0142 static const char * const RtemsReqIdent_PreDesc_Name[] = {
0143   "Invalid",
0144   "Valid",
0145   "NA"
0146 };
0147 
0148 static const char * const RtemsReqIdent_PreDesc_Node[] = {
0149   "Local",
0150   "Remote",
0151   "Invalid",
0152   "SearchAll",
0153   "SearchOther",
0154   "SearchLocal",
0155   "NA"
0156 };
0157 
0158 static const char * const RtemsReqIdent_PreDesc_Id[] = {
0159   "Valid",
0160   "Null",
0161   "NA"
0162 };
0163 
0164 static const char * const * const RtemsReqIdent_PreDesc[] = {
0165   RtemsReqIdent_PreDesc_Name,
0166   RtemsReqIdent_PreDesc_Node,
0167   RtemsReqIdent_PreDesc_Id,
0168   NULL
0169 };
0170 
0171 static void RtemsReqIdent_Pre_Name_Prepare(
0172   RtemsReqIdent_Context *ctx,
0173   RtemsReqIdent_Pre_Name state
0174 )
0175 {
0176   switch ( state ) {
0177     case RtemsReqIdent_Pre_Name_Invalid: {
0178       /*
0179        * While the ``name`` parameter is not associated with an active object
0180        * of the specified class .
0181        */
0182       ctx->name = 1;
0183       break;
0184     }
0185 
0186     case RtemsReqIdent_Pre_Name_Valid: {
0187       /*
0188        * While the ``name`` parameter is associated with an active object of
0189        * the specified class .
0190        */
0191       ctx->name = ctx->name_local_object;
0192       break;
0193     }
0194 
0195     case RtemsReqIdent_Pre_Name_NA:
0196       break;
0197   }
0198 }
0199 
0200 static void RtemsReqIdent_Pre_Node_Prepare(
0201   RtemsReqIdent_Context *ctx,
0202   RtemsReqIdent_Pre_Node state
0203 )
0204 {
0205   switch ( state ) {
0206     case RtemsReqIdent_Pre_Node_Local: {
0207       /*
0208        * While the ``node`` parameter is the local node number.
0209        */
0210       ctx->node = 1;
0211       break;
0212     }
0213 
0214     case RtemsReqIdent_Pre_Node_Remote: {
0215       /*
0216        * While the ``node`` parameter is a remote node number.
0217        */
0218       ctx->node = 2;
0219       break;
0220     }
0221 
0222     case RtemsReqIdent_Pre_Node_Invalid: {
0223       /*
0224        * While the ``node`` parameter is an invalid node number.
0225        */
0226       ctx->node = 256;
0227       break;
0228     }
0229 
0230     case RtemsReqIdent_Pre_Node_SearchAll: {
0231       /*
0232        * While the ``node`` parameter is RTEMS_SEARCH_ALL_NODES.
0233        */
0234       ctx->node = RTEMS_SEARCH_ALL_NODES;
0235       break;
0236     }
0237 
0238     case RtemsReqIdent_Pre_Node_SearchOther: {
0239       /*
0240        * While the ``node`` parameter is RTEMS_SEARCH_OTHER_NODES.
0241        */
0242       ctx->node = RTEMS_SEARCH_OTHER_NODES;
0243       break;
0244     }
0245 
0246     case RtemsReqIdent_Pre_Node_SearchLocal: {
0247       /*
0248        * While the ``node`` parameter is RTEMS_SEARCH_LOCAL_NODE.
0249        */
0250       ctx->node = RTEMS_SEARCH_LOCAL_NODE;
0251       break;
0252     }
0253 
0254     case RtemsReqIdent_Pre_Node_NA:
0255       break;
0256   }
0257 }
0258 
0259 static void RtemsReqIdent_Pre_Id_Prepare(
0260   RtemsReqIdent_Context *ctx,
0261   RtemsReqIdent_Pre_Id   state
0262 )
0263 {
0264   switch ( state ) {
0265     case RtemsReqIdent_Pre_Id_Valid: {
0266       /*
0267        * While the ``id`` parameter references an object of type rtems_id.
0268        */
0269       ctx->id_value = 0xffffffff;
0270       ctx->id = &ctx->id_value;
0271       break;
0272     }
0273 
0274     case RtemsReqIdent_Pre_Id_Null: {
0275       /*
0276        * While the ``id`` parameter is NULL.
0277        */
0278       ctx->id = NULL;
0279       break;
0280     }
0281 
0282     case RtemsReqIdent_Pre_Id_NA:
0283       break;
0284   }
0285 }
0286 
0287 static void RtemsReqIdent_Post_Status_Check(
0288   RtemsReqIdent_Context    *ctx,
0289   RtemsReqIdent_Post_Status state
0290 )
0291 {
0292   switch ( state ) {
0293     case RtemsReqIdent_Post_Status_Ok: {
0294       /*
0295        * The return status shall be RTEMS_SUCCESSFUL.
0296        */
0297       T_rsc(ctx->status, RTEMS_SUCCESSFUL);
0298       break;
0299     }
0300 
0301     case RtemsReqIdent_Post_Status_InvAddr: {
0302       /*
0303        * The return status shall be RTEMS_INVALID_ADDRESS.
0304        */
0305       T_rsc(ctx->status, RTEMS_INVALID_ADDRESS);
0306       break;
0307     }
0308 
0309     case RtemsReqIdent_Post_Status_InvName: {
0310       /*
0311        * The return status shall be RTEMS_INVALID_NAME.
0312        */
0313       T_rsc(ctx->status, RTEMS_INVALID_NAME);
0314       break;
0315     }
0316 
0317     case RtemsReqIdent_Post_Status_InvNode: {
0318       /*
0319        * The return status shall be RTEMS_INVALID_NODE.
0320        */
0321       T_rsc(ctx->status, RTEMS_INVALID_NODE);
0322       break;
0323     }
0324 
0325     case RtemsReqIdent_Post_Status_NA:
0326       break;
0327   }
0328 }
0329 
0330 static void RtemsReqIdent_Post_Id_Check(
0331   RtemsReqIdent_Context *ctx,
0332   RtemsReqIdent_Post_Id  state
0333 )
0334 {
0335   switch ( state ) {
0336     case RtemsReqIdent_Post_Id_Nop: {
0337       /*
0338        * The value of the object identifier referenced by the id parameter
0339        * shall be the value before the action.
0340        */
0341       T_eq_ptr(ctx->id, &ctx->id_value);
0342       T_eq_u32(ctx->id_value, 0xffffffff);
0343       break;
0344     }
0345 
0346     case RtemsReqIdent_Post_Id_Null: {
0347       /*
0348        * While the id is NULL.
0349        */
0350       T_null(ctx->id)
0351       break;
0352     }
0353 
0354     case RtemsReqIdent_Post_Id_LocalObj: {
0355       /*
0356        * The value of the object identifier referenced by the id parameter
0357        * shall be the identifier of a local object of the specified class with
0358        * a name equal to the name parameter.  If more than one local object of
0359        * the specified class with such a name exists, then it shall be the
0360        * identifier of the object with the lowest object index.
0361        */
0362       T_eq_ptr(ctx->id, &ctx->id_value);
0363       T_eq_u32(ctx->id_value, ctx->id_local_object);
0364       break;
0365     }
0366 
0367     case RtemsReqIdent_Post_Id_RemoteObj: {
0368       /*
0369        * The value of the object identifier referenced by the id parameter
0370        * shall be the identifier of a remote object of the specified class on a
0371        * eligible node defined by the node parameter with a name equal to the
0372        * name parameter.  If more than one local object of the specified class
0373        * with such a name exists, then it shall be the identifier of the object
0374        * with the lowest object index.  Otherwise, if more than one object of
0375        * the specified class with such a name exists on remote eligible nodes,
0376        * then it shall be the identifier of the object with the lowest node
0377        * index and the lowest object index on this node.
0378        */
0379       T_eq_ptr(ctx->id, &ctx->id_value);
0380       T_eq_u32(ctx->id_value, ctx->id_remote_object);
0381       break;
0382     }
0383 
0384     case RtemsReqIdent_Post_Id_NA:
0385       break;
0386   }
0387 }
0388 
0389 static void RtemsReqIdent_Action( RtemsReqIdent_Context *ctx )
0390 {
0391   ctx->status = ( *ctx->action )( ctx->name, ctx->node, ctx->id );
0392 }
0393 
0394 static const RtemsReqIdent_Entry
0395 RtemsReqIdent_Entries[] = {
0396   { 0, 0, 0, 0, RtemsReqIdent_Post_Status_InvAddr, RtemsReqIdent_Post_Id_Null },
0397   { 0, 0, 0, 0, RtemsReqIdent_Post_Status_InvName, RtemsReqIdent_Post_Id_Nop },
0398   { 0, 0, 0, 0, RtemsReqIdent_Post_Status_Ok, RtemsReqIdent_Post_Id_LocalObj },
0399 #if defined(RTEMS_MULTIPROCESSING)
0400   { 0, 0, 0, 0, RtemsReqIdent_Post_Status_Ok, RtemsReqIdent_Post_Id_RemoteObj }
0401 #else
0402   { 0, 0, 0, 0, RtemsReqIdent_Post_Status_InvName, RtemsReqIdent_Post_Id_Nop }
0403 #endif
0404 };
0405 
0406 static const uint8_t
0407 RtemsReqIdent_Map[] = {
0408   1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 2, 0
0409 };
0410 
0411 static size_t RtemsReqIdent_Scope( void *arg, char *buf, size_t n )
0412 {
0413   RtemsReqIdent_Context *ctx;
0414 
0415   ctx = arg;
0416 
0417   if ( ctx->Map.in_action_loop ) {
0418     return T_get_scope( RtemsReqIdent_PreDesc, buf, n, ctx->Map.pcs );
0419   }
0420 
0421   return 0;
0422 }
0423 
0424 static T_fixture RtemsReqIdent_Fixture = {
0425   .setup = NULL,
0426   .stop = NULL,
0427   .teardown = NULL,
0428   .scope = RtemsReqIdent_Scope,
0429   .initial_context = &RtemsReqIdent_Instance
0430 };
0431 
0432 static inline RtemsReqIdent_Entry RtemsReqIdent_PopEntry(
0433   RtemsReqIdent_Context *ctx
0434 )
0435 {
0436   size_t index;
0437 
0438   index = ctx->Map.index;
0439   ctx->Map.index = index + 1;
0440   return RtemsReqIdent_Entries[
0441     RtemsReqIdent_Map[ index ]
0442   ];
0443 }
0444 
0445 static void RtemsReqIdent_TestVariant( RtemsReqIdent_Context *ctx )
0446 {
0447   RtemsReqIdent_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0448   RtemsReqIdent_Pre_Node_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0449   RtemsReqIdent_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 2 ] );
0450   RtemsReqIdent_Action( ctx );
0451   RtemsReqIdent_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0452   RtemsReqIdent_Post_Id_Check( ctx, ctx->Map.entry.Post_Id );
0453 }
0454 
0455 static T_fixture_node RtemsReqIdent_Node;
0456 
0457 static T_remark RtemsReqIdent_Remark = {
0458   .next = NULL,
0459   .remark = "RtemsReqIdent"
0460 };
0461 
0462 void RtemsReqIdent_Run(
0463   rtems_id             id_local_object,
0464   rtems_name           name_local_object,
0465   rtems_status_code ( *action )( rtems_name, uint32_t, rtems_id * )
0466 )
0467 {
0468   RtemsReqIdent_Context *ctx;
0469 
0470   ctx = &RtemsReqIdent_Instance;
0471   ctx->id_local_object = id_local_object;
0472   ctx->name_local_object = name_local_object;
0473   ctx->action = action;
0474 
0475   ctx = T_push_fixture( &RtemsReqIdent_Node, &RtemsReqIdent_Fixture );
0476   ctx->Map.in_action_loop = true;
0477   ctx->Map.index = 0;
0478 
0479   for (
0480     ctx->Map.pcs[ 0 ] = RtemsReqIdent_Pre_Name_Invalid;
0481     ctx->Map.pcs[ 0 ] < RtemsReqIdent_Pre_Name_NA;
0482     ++ctx->Map.pcs[ 0 ]
0483   ) {
0484     for (
0485       ctx->Map.pcs[ 1 ] = RtemsReqIdent_Pre_Node_Local;
0486       ctx->Map.pcs[ 1 ] < RtemsReqIdent_Pre_Node_NA;
0487       ++ctx->Map.pcs[ 1 ]
0488     ) {
0489       for (
0490         ctx->Map.pcs[ 2 ] = RtemsReqIdent_Pre_Id_Valid;
0491         ctx->Map.pcs[ 2 ] < RtemsReqIdent_Pre_Id_NA;
0492         ++ctx->Map.pcs[ 2 ]
0493       ) {
0494         ctx->Map.entry = RtemsReqIdent_PopEntry( ctx );
0495         RtemsReqIdent_TestVariant( ctx );
0496       }
0497     }
0498   }
0499 
0500   T_add_remark( &RtemsReqIdent_Remark );
0501   T_pop_fixture();
0502 }
0503 
0504 /** @} */