Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsStatusReqIsSuccessful
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 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsStatusReqIsSuccessful spec:/rtems/status/req/is-successful
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef enum {
0068   RtemsStatusReqIsSuccessful_Pre_Status_Successful,
0069   RtemsStatusReqIsSuccessful_Pre_Status_Other,
0070   RtemsStatusReqIsSuccessful_Pre_Status_NA
0071 } RtemsStatusReqIsSuccessful_Pre_Status;
0072 
0073 typedef enum {
0074   RtemsStatusReqIsSuccessful_Post_Result_True,
0075   RtemsStatusReqIsSuccessful_Post_Result_False,
0076   RtemsStatusReqIsSuccessful_Post_Result_NA
0077 } RtemsStatusReqIsSuccessful_Post_Result;
0078 
0079 typedef struct {
0080   uint8_t Skip : 1;
0081   uint8_t Pre_Status_NA : 1;
0082   uint8_t Post_Result : 2;
0083 } RtemsStatusReqIsSuccessful_Entry;
0084 
0085 /**
0086  * @brief Test context for spec:/rtems/status/req/is-successful test case.
0087  */
0088 typedef struct {
0089   /**
0090    * @brief This member contains the return value of the
0091    *   rtems_is_status_successful() call.
0092    */
0093   bool result;
0094 
0095   /**
0096    * @brief This member specifies if the ``status_code`` parameter value.
0097    */
0098   rtems_status_code status;
0099 
0100   struct {
0101     /**
0102      * @brief This member defines the pre-condition states for the next action.
0103      */
0104     size_t pcs[ 1 ];
0105 
0106     /**
0107      * @brief If this member is true, then the test action loop is executed.
0108      */
0109     bool in_action_loop;
0110 
0111     /**
0112      * @brief This member contains the next transition map index.
0113      */
0114     size_t index;
0115 
0116     /**
0117      * @brief This member contains the current transition map entry.
0118      */
0119     RtemsStatusReqIsSuccessful_Entry entry;
0120 
0121     /**
0122      * @brief If this member is true, then the current transition variant
0123      *   should be skipped.
0124      */
0125     bool skip;
0126   } Map;
0127 } RtemsStatusReqIsSuccessful_Context;
0128 
0129 static RtemsStatusReqIsSuccessful_Context
0130   RtemsStatusReqIsSuccessful_Instance;
0131 
0132 static const char * const RtemsStatusReqIsSuccessful_PreDesc_Status[] = {
0133   "Successful",
0134   "Other",
0135   "NA"
0136 };
0137 
0138 static const char * const * const RtemsStatusReqIsSuccessful_PreDesc[] = {
0139   RtemsStatusReqIsSuccessful_PreDesc_Status,
0140   NULL
0141 };
0142 
0143 static void RtemsStatusReqIsSuccessful_Pre_Status_Prepare(
0144   RtemsStatusReqIsSuccessful_Context   *ctx,
0145   RtemsStatusReqIsSuccessful_Pre_Status state
0146 )
0147 {
0148   switch ( state ) {
0149     case RtemsStatusReqIsSuccessful_Pre_Status_Successful: {
0150       /*
0151        * While the ``status_code`` parameter is equal to RTEMS_SUCCESSFUL.
0152        */
0153       ctx->status = RTEMS_SUCCESSFUL;
0154       break;
0155     }
0156 
0157     case RtemsStatusReqIsSuccessful_Pre_Status_Other: {
0158       /*
0159        * While the ``status_code`` parameter is not equal to RTEMS_SUCCESSFUL.
0160        */
0161       ctx->status = RTEMS_INVALID_ID;
0162       break;
0163     }
0164 
0165     case RtemsStatusReqIsSuccessful_Pre_Status_NA:
0166       break;
0167   }
0168 }
0169 
0170 static void RtemsStatusReqIsSuccessful_Post_Result_Check(
0171   RtemsStatusReqIsSuccessful_Context    *ctx,
0172   RtemsStatusReqIsSuccessful_Post_Result state
0173 )
0174 {
0175   switch ( state ) {
0176     case RtemsStatusReqIsSuccessful_Post_Result_True: {
0177       /*
0178        * The return value of rtems_is_status_successful() shall be true.
0179        */
0180       T_true( ctx->result );
0181       break;
0182     }
0183 
0184     case RtemsStatusReqIsSuccessful_Post_Result_False: {
0185       /*
0186        * The return value of rtems_is_status_successful() shall be false.
0187        */
0188       T_false( ctx->result );
0189       break;
0190     }
0191 
0192     case RtemsStatusReqIsSuccessful_Post_Result_NA:
0193       break;
0194   }
0195 }
0196 
0197 static void RtemsStatusReqIsSuccessful_Action(
0198   RtemsStatusReqIsSuccessful_Context *ctx
0199 )
0200 {
0201   ctx->result = rtems_is_status_successful( ctx->status );
0202 }
0203 
0204 static const RtemsStatusReqIsSuccessful_Entry
0205 RtemsStatusReqIsSuccessful_Entries[] = {
0206   { 0, 0, RtemsStatusReqIsSuccessful_Post_Result_True },
0207   { 0, 0, RtemsStatusReqIsSuccessful_Post_Result_False }
0208 };
0209 
0210 static const uint8_t
0211 RtemsStatusReqIsSuccessful_Map[] = {
0212   0, 1
0213 };
0214 
0215 static size_t RtemsStatusReqIsSuccessful_Scope(
0216   void  *arg,
0217   char  *buf,
0218   size_t n
0219 )
0220 {
0221   RtemsStatusReqIsSuccessful_Context *ctx;
0222 
0223   ctx = arg;
0224 
0225   if ( ctx->Map.in_action_loop ) {
0226     return T_get_scope(
0227       RtemsStatusReqIsSuccessful_PreDesc,
0228       buf,
0229       n,
0230       ctx->Map.pcs
0231     );
0232   }
0233 
0234   return 0;
0235 }
0236 
0237 static T_fixture RtemsStatusReqIsSuccessful_Fixture = {
0238   .setup = NULL,
0239   .stop = NULL,
0240   .teardown = NULL,
0241   .scope = RtemsStatusReqIsSuccessful_Scope,
0242   .initial_context = &RtemsStatusReqIsSuccessful_Instance
0243 };
0244 
0245 static inline RtemsStatusReqIsSuccessful_Entry
0246 RtemsStatusReqIsSuccessful_PopEntry( RtemsStatusReqIsSuccessful_Context *ctx )
0247 {
0248   size_t index;
0249 
0250   index = ctx->Map.index;
0251   ctx->Map.index = index + 1;
0252   return RtemsStatusReqIsSuccessful_Entries[
0253     RtemsStatusReqIsSuccessful_Map[ index ]
0254   ];
0255 }
0256 
0257 static void RtemsStatusReqIsSuccessful_TestVariant(
0258   RtemsStatusReqIsSuccessful_Context *ctx
0259 )
0260 {
0261   RtemsStatusReqIsSuccessful_Pre_Status_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0262   RtemsStatusReqIsSuccessful_Action( ctx );
0263   RtemsStatusReqIsSuccessful_Post_Result_Check(
0264     ctx,
0265     ctx->Map.entry.Post_Result
0266   );
0267 }
0268 
0269 /**
0270  * @fn void T_case_body_RtemsStatusReqIsSuccessful( void )
0271  */
0272 T_TEST_CASE_FIXTURE(
0273   RtemsStatusReqIsSuccessful,
0274   &RtemsStatusReqIsSuccessful_Fixture
0275 )
0276 {
0277   RtemsStatusReqIsSuccessful_Context *ctx;
0278 
0279   ctx = T_fixture_context();
0280   ctx->Map.in_action_loop = true;
0281   ctx->Map.index = 0;
0282 
0283   for (
0284     ctx->Map.pcs[ 0 ] = RtemsStatusReqIsSuccessful_Pre_Status_Successful;
0285     ctx->Map.pcs[ 0 ] < RtemsStatusReqIsSuccessful_Pre_Status_NA;
0286     ++ctx->Map.pcs[ 0 ]
0287   ) {
0288     ctx->Map.entry = RtemsStatusReqIsSuccessful_PopEntry( ctx );
0289     RtemsStatusReqIsSuccessful_TestVariant( ctx );
0290   }
0291 }
0292 
0293 /** @} */