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 CReqFlsl
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 <limits.h>
0056 #include <strings.h>
0057 
0058 #include <rtems/test.h>
0059 
0060 /**
0061  * @defgroup CReqFlsl spec:/c/req/flsl
0062  *
0063  * @ingroup TestsuitesValidationNoClock0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   CReqFlsl_Pre_Value_Zero,
0070   CReqFlsl_Pre_Value_NonZero,
0071   CReqFlsl_Pre_Value_NA
0072 } CReqFlsl_Pre_Value;
0073 
0074 typedef enum {
0075   CReqFlsl_Post_Result_Zero,
0076   CReqFlsl_Post_Result_LastBitSet,
0077   CReqFlsl_Post_Result_NA
0078 } CReqFlsl_Post_Result;
0079 
0080 typedef struct {
0081   uint8_t Skip : 1;
0082   uint8_t Pre_Value_NA : 1;
0083   uint8_t Post_Result : 2;
0084 } CReqFlsl_Entry;
0085 
0086 /**
0087  * @brief Test context for spec:/c/req/flsl test case.
0088  */
0089 typedef struct {
0090   struct {
0091     /**
0092      * @brief This member defines the pre-condition states for the next action.
0093      */
0094     size_t pcs[ 1 ];
0095 
0096     /**
0097      * @brief If this member is true, then the test action loop is executed.
0098      */
0099     bool in_action_loop;
0100 
0101     /**
0102      * @brief This member contains the next transition map index.
0103      */
0104     size_t index;
0105 
0106     /**
0107      * @brief This member contains the current transition map entry.
0108      */
0109     CReqFlsl_Entry entry;
0110 
0111     /**
0112      * @brief If this member is true, then the current transition variant
0113      *   should be skipped.
0114      */
0115     bool skip;
0116   } Map;
0117 } CReqFlsl_Context;
0118 
0119 static CReqFlsl_Context
0120   CReqFlsl_Instance;
0121 
0122 static const char * const CReqFlsl_PreDesc_Value[] = {
0123   "Zero",
0124   "NonZero",
0125   "NA"
0126 };
0127 
0128 static const char * const * const CReqFlsl_PreDesc[] = {
0129   CReqFlsl_PreDesc_Value,
0130   NULL
0131 };
0132 
0133 static void CReqFlsl_Pre_Value_Prepare(
0134   CReqFlsl_Context  *ctx,
0135   CReqFlsl_Pre_Value state
0136 )
0137 {
0138   switch ( state ) {
0139     case CReqFlsl_Pre_Value_Zero: {
0140       /*
0141        * While the parameter value is equal to zero.
0142        */
0143       /* Nothing to prepare */
0144       break;
0145     }
0146 
0147     case CReqFlsl_Pre_Value_NonZero: {
0148       /*
0149        * While the parameter value is not equal to zero.
0150        */
0151       /* Nothing to prepare */
0152       break;
0153     }
0154 
0155     case CReqFlsl_Pre_Value_NA:
0156       break;
0157   }
0158 }
0159 
0160 static void CReqFlsl_Post_Result_Check(
0161   CReqFlsl_Context    *ctx,
0162   CReqFlsl_Post_Result state
0163 )
0164 {
0165   int    expected_result;
0166   long   value;
0167   size_t i;
0168 
0169   switch ( state ) {
0170     case CReqFlsl_Post_Result_Zero: {
0171       /*
0172        * The return value of flsl() shall be equal to zero.
0173        */
0174       T_eq_int( flsl( 0 ), 0 );
0175       break;
0176     }
0177 
0178     case CReqFlsl_Post_Result_LastBitSet: {
0179       /*
0180        * The return value of flsl() shall be equal to the index of the
0181        * most-significant bit set in the parameter value.
0182        */
0183       expected_result = 1;
0184       value = 1;
0185 
0186       for ( i = 0; i < sizeof( long ) * CHAR_BIT; ++i ) {
0187         T_eq_int( flsl( value ), expected_result );
0188         ++expected_result;
0189         value <<= 1;
0190       }
0191       break;
0192     }
0193 
0194     case CReqFlsl_Post_Result_NA:
0195       break;
0196   }
0197 }
0198 
0199 static void CReqFlsl_Action( CReqFlsl_Context *ctx )
0200 {
0201   /* The action is performed in the post-condition states */
0202 }
0203 
0204 static const CReqFlsl_Entry
0205 CReqFlsl_Entries[] = {
0206   { 0, 0, CReqFlsl_Post_Result_Zero },
0207   { 0, 0, CReqFlsl_Post_Result_LastBitSet }
0208 };
0209 
0210 static const uint8_t
0211 CReqFlsl_Map[] = {
0212   0, 1
0213 };
0214 
0215 static size_t CReqFlsl_Scope( void *arg, char *buf, size_t n )
0216 {
0217   CReqFlsl_Context *ctx;
0218 
0219   ctx = arg;
0220 
0221   if ( ctx->Map.in_action_loop ) {
0222     return T_get_scope( CReqFlsl_PreDesc, buf, n, ctx->Map.pcs );
0223   }
0224 
0225   return 0;
0226 }
0227 
0228 static T_fixture CReqFlsl_Fixture = {
0229   .setup = NULL,
0230   .stop = NULL,
0231   .teardown = NULL,
0232   .scope = CReqFlsl_Scope,
0233   .initial_context = &CReqFlsl_Instance
0234 };
0235 
0236 static inline CReqFlsl_Entry CReqFlsl_PopEntry( CReqFlsl_Context *ctx )
0237 {
0238   size_t index;
0239 
0240   index = ctx->Map.index;
0241   ctx->Map.index = index + 1;
0242   return CReqFlsl_Entries[
0243     CReqFlsl_Map[ index ]
0244   ];
0245 }
0246 
0247 static void CReqFlsl_TestVariant( CReqFlsl_Context *ctx )
0248 {
0249   CReqFlsl_Pre_Value_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0250   CReqFlsl_Action( ctx );
0251   CReqFlsl_Post_Result_Check( ctx, ctx->Map.entry.Post_Result );
0252 }
0253 
0254 /**
0255  * @fn void T_case_body_CReqFlsl( void )
0256  */
0257 T_TEST_CASE_FIXTURE( CReqFlsl, &CReqFlsl_Fixture )
0258 {
0259   CReqFlsl_Context *ctx;
0260 
0261   ctx = T_fixture_context();
0262   ctx->Map.in_action_loop = true;
0263   ctx->Map.index = 0;
0264 
0265   for (
0266     ctx->Map.pcs[ 0 ] = CReqFlsl_Pre_Value_Zero;
0267     ctx->Map.pcs[ 0 ] < CReqFlsl_Pre_Value_NA;
0268     ++ctx->Map.pcs[ 0 ]
0269   ) {
0270     ctx->Map.entry = CReqFlsl_PopEntry( ctx );
0271     CReqFlsl_TestVariant( ctx );
0272   }
0273 }
0274 
0275 /** @} */