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 <rtems/bspIo.h>
0056
0057 #include <rtems/test.h>
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 typedef enum {
0068 RtemsIoReqGetchark_Pre_PollChar_Valid,
0069 RtemsIoReqGetchark_Pre_PollChar_Null,
0070 RtemsIoReqGetchark_Pre_PollChar_NA
0071 } RtemsIoReqGetchark_Pre_PollChar;
0072
0073 typedef enum {
0074 RtemsIoReqGetchark_Post_Result_PollChar,
0075 RtemsIoReqGetchark_Post_Result_MinusOne,
0076 RtemsIoReqGetchark_Post_Result_NA
0077 } RtemsIoReqGetchark_Post_Result;
0078
0079 typedef enum {
0080 RtemsIoReqGetchark_Post_Calls_Once,
0081 RtemsIoReqGetchark_Post_Calls_NA
0082 } RtemsIoReqGetchark_Post_Calls;
0083
0084 typedef struct {
0085 uint8_t Skip : 1;
0086 uint8_t Pre_PollChar_NA : 1;
0087 uint8_t Post_Result : 2;
0088 uint8_t Post_Calls : 1;
0089 } RtemsIoReqGetchark_Entry;
0090
0091
0092
0093
0094 typedef struct {
0095
0096
0097
0098 size_t input_count;
0099
0100
0101
0102
0103 BSP_polling_getchar_function_type poll_char;
0104
0105
0106
0107
0108 int result;
0109
0110 struct {
0111
0112
0113
0114 size_t pcs[ 1 ];
0115
0116
0117
0118
0119 bool in_action_loop;
0120
0121
0122
0123
0124 size_t index;
0125
0126
0127
0128
0129 RtemsIoReqGetchark_Entry entry;
0130
0131
0132
0133
0134
0135 bool skip;
0136 } Map;
0137 } RtemsIoReqGetchark_Context;
0138
0139 static RtemsIoReqGetchark_Context
0140 RtemsIoReqGetchark_Instance;
0141
0142 static const char * const RtemsIoReqGetchark_PreDesc_PollChar[] = {
0143 "Valid",
0144 "Null",
0145 "NA"
0146 };
0147
0148 static const char * const * const RtemsIoReqGetchark_PreDesc[] = {
0149 RtemsIoReqGetchark_PreDesc_PollChar,
0150 NULL
0151 };
0152
0153 typedef RtemsIoReqGetchark_Context Context;
0154
0155 static int PollChar( void )
0156 {
0157 Context *ctx;
0158
0159 ctx = T_fixture_context();
0160 ++ctx->input_count;
0161
0162 return 123;
0163 }
0164
0165 static void RtemsIoReqGetchark_Pre_PollChar_Prepare(
0166 RtemsIoReqGetchark_Context *ctx,
0167 RtemsIoReqGetchark_Pre_PollChar state
0168 )
0169 {
0170 switch ( state ) {
0171 case RtemsIoReqGetchark_Pre_PollChar_Valid: {
0172
0173
0174
0175 ctx->poll_char = PollChar;
0176 break;
0177 }
0178
0179 case RtemsIoReqGetchark_Pre_PollChar_Null: {
0180
0181
0182
0183 ctx->poll_char = NULL;
0184 break;
0185 }
0186
0187 case RtemsIoReqGetchark_Pre_PollChar_NA:
0188 break;
0189 }
0190 }
0191
0192 static void RtemsIoReqGetchark_Post_Result_Check(
0193 RtemsIoReqGetchark_Context *ctx,
0194 RtemsIoReqGetchark_Post_Result state
0195 )
0196 {
0197 switch ( state ) {
0198 case RtemsIoReqGetchark_Post_Result_PollChar: {
0199
0200
0201
0202
0203 T_eq_int( ctx->result, 123 );
0204 break;
0205 }
0206
0207 case RtemsIoReqGetchark_Post_Result_MinusOne: {
0208
0209
0210
0211 T_eq_int( ctx->result, -1 );
0212 T_eq_u32( ctx->input_count, 0 );
0213 break;
0214 }
0215
0216 case RtemsIoReqGetchark_Post_Result_NA:
0217 break;
0218 }
0219 }
0220
0221 static void RtemsIoReqGetchark_Post_Calls_Check(
0222 RtemsIoReqGetchark_Context *ctx,
0223 RtemsIoReqGetchark_Post_Calls state
0224 )
0225 {
0226 switch ( state ) {
0227 case RtemsIoReqGetchark_Post_Calls_Once: {
0228
0229
0230
0231
0232 T_eq_u32( ctx->input_count, 1 );
0233 break;
0234 }
0235
0236 case RtemsIoReqGetchark_Post_Calls_NA:
0237 break;
0238 }
0239 }
0240
0241 static void RtemsIoReqGetchark_Action( RtemsIoReqGetchark_Context *ctx )
0242 {
0243 BSP_polling_getchar_function_type poll_char;
0244
0245 ctx->input_count = 0;
0246 poll_char = BSP_poll_char;
0247 BSP_poll_char = ctx->poll_char;
0248 ctx->result = getchark();
0249 BSP_poll_char = poll_char;
0250 }
0251
0252 static const RtemsIoReqGetchark_Entry
0253 RtemsIoReqGetchark_Entries[] = {
0254 { 0, 0, RtemsIoReqGetchark_Post_Result_PollChar,
0255 RtemsIoReqGetchark_Post_Calls_Once },
0256 { 0, 0, RtemsIoReqGetchark_Post_Result_MinusOne,
0257 RtemsIoReqGetchark_Post_Calls_NA }
0258 };
0259
0260 static const uint8_t
0261 RtemsIoReqGetchark_Map[] = {
0262 0, 1
0263 };
0264
0265 static size_t RtemsIoReqGetchark_Scope( void *arg, char *buf, size_t n )
0266 {
0267 RtemsIoReqGetchark_Context *ctx;
0268
0269 ctx = arg;
0270
0271 if ( ctx->Map.in_action_loop ) {
0272 return T_get_scope( RtemsIoReqGetchark_PreDesc, buf, n, ctx->Map.pcs );
0273 }
0274
0275 return 0;
0276 }
0277
0278 static T_fixture RtemsIoReqGetchark_Fixture = {
0279 .setup = NULL,
0280 .stop = NULL,
0281 .teardown = NULL,
0282 .scope = RtemsIoReqGetchark_Scope,
0283 .initial_context = &RtemsIoReqGetchark_Instance
0284 };
0285
0286 static inline RtemsIoReqGetchark_Entry RtemsIoReqGetchark_PopEntry(
0287 RtemsIoReqGetchark_Context *ctx
0288 )
0289 {
0290 size_t index;
0291
0292 index = ctx->Map.index;
0293 ctx->Map.index = index + 1;
0294 return RtemsIoReqGetchark_Entries[
0295 RtemsIoReqGetchark_Map[ index ]
0296 ];
0297 }
0298
0299 static void RtemsIoReqGetchark_TestVariant( RtemsIoReqGetchark_Context *ctx )
0300 {
0301 RtemsIoReqGetchark_Pre_PollChar_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0302 RtemsIoReqGetchark_Action( ctx );
0303 RtemsIoReqGetchark_Post_Result_Check( ctx, ctx->Map.entry.Post_Result );
0304 RtemsIoReqGetchark_Post_Calls_Check( ctx, ctx->Map.entry.Post_Calls );
0305 }
0306
0307
0308
0309
0310 T_TEST_CASE_FIXTURE( RtemsIoReqGetchark, &RtemsIoReqGetchark_Fixture )
0311 {
0312 RtemsIoReqGetchark_Context *ctx;
0313
0314 ctx = T_fixture_context();
0315 ctx->Map.in_action_loop = true;
0316 ctx->Map.index = 0;
0317
0318 for (
0319 ctx->Map.pcs[ 0 ] = RtemsIoReqGetchark_Pre_PollChar_Valid;
0320 ctx->Map.pcs[ 0 ] < RtemsIoReqGetchark_Pre_PollChar_NA;
0321 ++ctx->Map.pcs[ 0 ]
0322 ) {
0323 ctx->Map.entry = RtemsIoReqGetchark_PopEntry( ctx );
0324 RtemsIoReqGetchark_TestVariant( ctx );
0325 }
0326 }
0327
0328