File indexing completed on 2025-05-11 08:24:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
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
0062
0063
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
0088
0089 typedef struct {
0090 struct {
0091
0092
0093
0094 size_t pcs[ 1 ];
0095
0096
0097
0098
0099 bool in_action_loop;
0100
0101
0102
0103
0104 size_t index;
0105
0106
0107
0108
0109 CReqFlsl_Entry entry;
0110
0111
0112
0113
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
0142
0143
0144 break;
0145 }
0146
0147 case CReqFlsl_Pre_Value_NonZero: {
0148
0149
0150
0151
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
0173
0174 T_eq_int( flsl( 0 ), 0 );
0175 break;
0176 }
0177
0178 case CReqFlsl_Post_Result_LastBitSet: {
0179
0180
0181
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
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
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