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.h>
0056
0057 #include <rtems/test.h>
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 typedef enum {
0068 RtemsPartReqGetBuffer_Pre_Id_NoObj,
0069 RtemsPartReqGetBuffer_Pre_Id_Part,
0070 RtemsPartReqGetBuffer_Pre_Id_NA
0071 } RtemsPartReqGetBuffer_Pre_Id;
0072
0073 typedef enum {
0074 RtemsPartReqGetBuffer_Pre_Buf_Valid,
0075 RtemsPartReqGetBuffer_Pre_Buf_Null,
0076 RtemsPartReqGetBuffer_Pre_Buf_NA
0077 } RtemsPartReqGetBuffer_Pre_Buf;
0078
0079 typedef enum {
0080 RtemsPartReqGetBuffer_Pre_Avail_Yes,
0081 RtemsPartReqGetBuffer_Pre_Avail_No,
0082 RtemsPartReqGetBuffer_Pre_Avail_NA
0083 } RtemsPartReqGetBuffer_Pre_Avail;
0084
0085 typedef enum {
0086 RtemsPartReqGetBuffer_Post_Status_Ok,
0087 RtemsPartReqGetBuffer_Post_Status_InvId,
0088 RtemsPartReqGetBuffer_Post_Status_InvAddr,
0089 RtemsPartReqGetBuffer_Post_Status_Unsat,
0090 RtemsPartReqGetBuffer_Post_Status_NA
0091 } RtemsPartReqGetBuffer_Post_Status;
0092
0093 typedef enum {
0094 RtemsPartReqGetBuffer_Post_BufVar_Set,
0095 RtemsPartReqGetBuffer_Post_BufVar_Nop,
0096 RtemsPartReqGetBuffer_Post_BufVar_NA
0097 } RtemsPartReqGetBuffer_Post_BufVar;
0098
0099 typedef struct {
0100 uint16_t Skip : 1;
0101 uint16_t Pre_Id_NA : 1;
0102 uint16_t Pre_Buf_NA : 1;
0103 uint16_t Pre_Avail_NA : 1;
0104 uint16_t Post_Status : 3;
0105 uint16_t Post_BufVar : 2;
0106 } RtemsPartReqGetBuffer_Entry;
0107
0108
0109
0110
0111 typedef struct {
0112 rtems_status_code status;
0113
0114 rtems_id id;
0115
0116 rtems_id id_value;
0117
0118 void **buffer;
0119
0120 void *buffer_pointer;
0121
0122 void *stolen_buffer;
0123
0124 struct {
0125
0126
0127
0128 size_t pcs[ 3 ];
0129
0130
0131
0132
0133 bool in_action_loop;
0134
0135
0136
0137
0138 size_t index;
0139
0140
0141
0142
0143 RtemsPartReqGetBuffer_Entry entry;
0144
0145
0146
0147
0148
0149 bool skip;
0150 } Map;
0151 } RtemsPartReqGetBuffer_Context;
0152
0153 static RtemsPartReqGetBuffer_Context
0154 RtemsPartReqGetBuffer_Instance;
0155
0156 static const char * const RtemsPartReqGetBuffer_PreDesc_Id[] = {
0157 "NoObj",
0158 "Part",
0159 "NA"
0160 };
0161
0162 static const char * const RtemsPartReqGetBuffer_PreDesc_Buf[] = {
0163 "Valid",
0164 "Null",
0165 "NA"
0166 };
0167
0168 static const char * const RtemsPartReqGetBuffer_PreDesc_Avail[] = {
0169 "Yes",
0170 "No",
0171 "NA"
0172 };
0173
0174 static const char * const * const RtemsPartReqGetBuffer_PreDesc[] = {
0175 RtemsPartReqGetBuffer_PreDesc_Id,
0176 RtemsPartReqGetBuffer_PreDesc_Buf,
0177 RtemsPartReqGetBuffer_PreDesc_Avail,
0178 NULL
0179 };
0180
0181 #define BUFFER_COUNT 1
0182
0183 #define BUFFER_SIZE ( 2 * sizeof( void * ) )
0184
0185 static RTEMS_ALIGNED( RTEMS_PARTITION_ALIGNMENT ) uint8_t
0186 buffers[ BUFFER_COUNT ][ BUFFER_SIZE ];
0187
0188 static void RtemsPartReqGetBuffer_Pre_Id_Prepare(
0189 RtemsPartReqGetBuffer_Context *ctx,
0190 RtemsPartReqGetBuffer_Pre_Id state
0191 )
0192 {
0193 switch ( state ) {
0194 case RtemsPartReqGetBuffer_Pre_Id_NoObj: {
0195
0196
0197
0198 ctx->id = 0xffffffff;
0199 break;
0200 }
0201
0202 case RtemsPartReqGetBuffer_Pre_Id_Part: {
0203
0204
0205
0206 ctx->id = ctx->id_value;
0207 break;
0208 }
0209
0210 case RtemsPartReqGetBuffer_Pre_Id_NA:
0211 break;
0212 }
0213 }
0214
0215 static void RtemsPartReqGetBuffer_Pre_Buf_Prepare(
0216 RtemsPartReqGetBuffer_Context *ctx,
0217 RtemsPartReqGetBuffer_Pre_Buf state
0218 )
0219 {
0220 switch ( state ) {
0221 case RtemsPartReqGetBuffer_Pre_Buf_Valid: {
0222
0223
0224
0225
0226 ctx->buffer = &ctx->buffer_pointer;
0227 break;
0228 }
0229
0230 case RtemsPartReqGetBuffer_Pre_Buf_Null: {
0231
0232
0233
0234 ctx->buffer = NULL;
0235 break;
0236 }
0237
0238 case RtemsPartReqGetBuffer_Pre_Buf_NA:
0239 break;
0240 }
0241 }
0242
0243 static void RtemsPartReqGetBuffer_Pre_Avail_Prepare(
0244 RtemsPartReqGetBuffer_Context *ctx,
0245 RtemsPartReqGetBuffer_Pre_Avail state
0246 )
0247 {
0248 rtems_status_code sc;
0249
0250 switch ( state ) {
0251 case RtemsPartReqGetBuffer_Pre_Avail_Yes: {
0252
0253
0254
0255
0256 break;
0257 }
0258
0259 case RtemsPartReqGetBuffer_Pre_Avail_No: {
0260
0261
0262
0263 sc = rtems_partition_get_buffer( ctx->id_value, &ctx->stolen_buffer );
0264 T_rsc_success( sc );
0265 break;
0266 }
0267
0268 case RtemsPartReqGetBuffer_Pre_Avail_NA:
0269 break;
0270 }
0271 }
0272
0273 static void RtemsPartReqGetBuffer_Post_Status_Check(
0274 RtemsPartReqGetBuffer_Context *ctx,
0275 RtemsPartReqGetBuffer_Post_Status state
0276 )
0277 {
0278 switch ( state ) {
0279 case RtemsPartReqGetBuffer_Post_Status_Ok: {
0280
0281
0282
0283
0284 T_rsc_success( ctx->status );
0285 T_eq_ptr( ctx->buffer_pointer, buffers );
0286 break;
0287 }
0288
0289 case RtemsPartReqGetBuffer_Post_Status_InvId: {
0290
0291
0292
0293
0294 T_rsc( ctx->status, RTEMS_INVALID_ID );
0295 T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0296 break;
0297 }
0298
0299 case RtemsPartReqGetBuffer_Post_Status_InvAddr: {
0300
0301
0302
0303
0304 T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0305 break;
0306 }
0307
0308 case RtemsPartReqGetBuffer_Post_Status_Unsat: {
0309
0310
0311
0312
0313 T_rsc( ctx->status, RTEMS_UNSATISFIED );
0314 T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0315 break;
0316 }
0317
0318 case RtemsPartReqGetBuffer_Post_Status_NA:
0319 break;
0320 }
0321 }
0322
0323 static void RtemsPartReqGetBuffer_Post_BufVar_Check(
0324 RtemsPartReqGetBuffer_Context *ctx,
0325 RtemsPartReqGetBuffer_Post_BufVar state
0326 )
0327 {
0328 switch ( state ) {
0329 case RtemsPartReqGetBuffer_Post_BufVar_Set: {
0330
0331
0332
0333
0334
0335
0336 T_eq_ptr( ctx->buffer, &ctx->buffer_pointer );
0337 T_eq_ptr( ctx->buffer_pointer, buffers );
0338 break;
0339 }
0340
0341 case RtemsPartReqGetBuffer_Post_BufVar_Nop: {
0342
0343
0344
0345
0346
0347 T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0348 break;
0349 }
0350
0351 case RtemsPartReqGetBuffer_Post_BufVar_NA:
0352 break;
0353 }
0354 }
0355
0356 static void RtemsPartReqGetBuffer_Setup( RtemsPartReqGetBuffer_Context *ctx )
0357 {
0358 rtems_status_code sc;
0359
0360 ctx->id_value = 0;
0361 sc = rtems_partition_create(
0362 rtems_build_name( 'N', 'A', 'M', 'E' ),
0363 buffers,
0364 sizeof( buffers ),
0365 sizeof( buffers[ 0 ] ),
0366 RTEMS_DEFAULT_ATTRIBUTES,
0367 &ctx->id_value
0368 );
0369 T_assert_rsc_success( sc );
0370 }
0371
0372 static void RtemsPartReqGetBuffer_Setup_Wrap( void *arg )
0373 {
0374 RtemsPartReqGetBuffer_Context *ctx;
0375
0376 ctx = arg;
0377 ctx->Map.in_action_loop = false;
0378 RtemsPartReqGetBuffer_Setup( ctx );
0379 }
0380
0381 static void RtemsPartReqGetBuffer_Teardown(
0382 RtemsPartReqGetBuffer_Context *ctx
0383 )
0384 {
0385 if ( ctx->id_value != 0 ) {
0386 rtems_status_code sc;
0387
0388 sc = rtems_partition_delete( ctx->id_value );
0389 T_rsc_success( sc );
0390 }
0391 }
0392
0393 static void RtemsPartReqGetBuffer_Teardown_Wrap( void *arg )
0394 {
0395 RtemsPartReqGetBuffer_Context *ctx;
0396
0397 ctx = arg;
0398 ctx->Map.in_action_loop = false;
0399 RtemsPartReqGetBuffer_Teardown( ctx );
0400 }
0401
0402 static void RtemsPartReqGetBuffer_Prepare( RtemsPartReqGetBuffer_Context *ctx )
0403 {
0404 ctx->buffer_pointer = (void *) (uintptr_t) 1;
0405 ctx->stolen_buffer = NULL;
0406 }
0407
0408 static void RtemsPartReqGetBuffer_Action( RtemsPartReqGetBuffer_Context *ctx )
0409 {
0410 ctx->status = rtems_partition_get_buffer( ctx->id, ctx->buffer );
0411 }
0412
0413 static void RtemsPartReqGetBuffer_Cleanup( RtemsPartReqGetBuffer_Context *ctx )
0414 {
0415 rtems_status_code sc;
0416
0417 if ( (uintptr_t) ctx->buffer_pointer != 1 ) {
0418 sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer_pointer );
0419 T_rsc_success( sc );
0420 }
0421
0422 if ( ctx->stolen_buffer != NULL ) {
0423 sc = rtems_partition_return_buffer( ctx->id_value, ctx->stolen_buffer );
0424 T_rsc_success( sc );
0425 }
0426 }
0427
0428 static const RtemsPartReqGetBuffer_Entry
0429 RtemsPartReqGetBuffer_Entries[] = {
0430 { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_InvAddr,
0431 RtemsPartReqGetBuffer_Post_BufVar_Nop },
0432 { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_InvId,
0433 RtemsPartReqGetBuffer_Post_BufVar_Nop },
0434 { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_Ok,
0435 RtemsPartReqGetBuffer_Post_BufVar_Set },
0436 { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_Unsat,
0437 RtemsPartReqGetBuffer_Post_BufVar_Nop }
0438 };
0439
0440 static const uint8_t
0441 RtemsPartReqGetBuffer_Map[] = {
0442 1, 1, 0, 0, 2, 3, 0, 0
0443 };
0444
0445 static size_t RtemsPartReqGetBuffer_Scope( void *arg, char *buf, size_t n )
0446 {
0447 RtemsPartReqGetBuffer_Context *ctx;
0448
0449 ctx = arg;
0450
0451 if ( ctx->Map.in_action_loop ) {
0452 return T_get_scope( RtemsPartReqGetBuffer_PreDesc, buf, n, ctx->Map.pcs );
0453 }
0454
0455 return 0;
0456 }
0457
0458 static T_fixture RtemsPartReqGetBuffer_Fixture = {
0459 .setup = RtemsPartReqGetBuffer_Setup_Wrap,
0460 .stop = NULL,
0461 .teardown = RtemsPartReqGetBuffer_Teardown_Wrap,
0462 .scope = RtemsPartReqGetBuffer_Scope,
0463 .initial_context = &RtemsPartReqGetBuffer_Instance
0464 };
0465
0466 static inline RtemsPartReqGetBuffer_Entry RtemsPartReqGetBuffer_PopEntry(
0467 RtemsPartReqGetBuffer_Context *ctx
0468 )
0469 {
0470 size_t index;
0471
0472 index = ctx->Map.index;
0473 ctx->Map.index = index + 1;
0474 return RtemsPartReqGetBuffer_Entries[
0475 RtemsPartReqGetBuffer_Map[ index ]
0476 ];
0477 }
0478
0479 static void RtemsPartReqGetBuffer_TestVariant(
0480 RtemsPartReqGetBuffer_Context *ctx
0481 )
0482 {
0483 RtemsPartReqGetBuffer_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0484 RtemsPartReqGetBuffer_Pre_Buf_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0485 RtemsPartReqGetBuffer_Pre_Avail_Prepare( ctx, ctx->Map.pcs[ 2 ] );
0486 RtemsPartReqGetBuffer_Action( ctx );
0487 RtemsPartReqGetBuffer_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0488 RtemsPartReqGetBuffer_Post_BufVar_Check( ctx, ctx->Map.entry.Post_BufVar );
0489 }
0490
0491
0492
0493
0494 T_TEST_CASE_FIXTURE( RtemsPartReqGetBuffer, &RtemsPartReqGetBuffer_Fixture )
0495 {
0496 RtemsPartReqGetBuffer_Context *ctx;
0497
0498 ctx = T_fixture_context();
0499 ctx->Map.in_action_loop = true;
0500 ctx->Map.index = 0;
0501
0502 for (
0503 ctx->Map.pcs[ 0 ] = RtemsPartReqGetBuffer_Pre_Id_NoObj;
0504 ctx->Map.pcs[ 0 ] < RtemsPartReqGetBuffer_Pre_Id_NA;
0505 ++ctx->Map.pcs[ 0 ]
0506 ) {
0507 for (
0508 ctx->Map.pcs[ 1 ] = RtemsPartReqGetBuffer_Pre_Buf_Valid;
0509 ctx->Map.pcs[ 1 ] < RtemsPartReqGetBuffer_Pre_Buf_NA;
0510 ++ctx->Map.pcs[ 1 ]
0511 ) {
0512 for (
0513 ctx->Map.pcs[ 2 ] = RtemsPartReqGetBuffer_Pre_Avail_Yes;
0514 ctx->Map.pcs[ 2 ] < RtemsPartReqGetBuffer_Pre_Avail_NA;
0515 ++ctx->Map.pcs[ 2 ]
0516 ) {
0517 ctx->Map.entry = RtemsPartReqGetBuffer_PopEntry( ctx );
0518 RtemsPartReqGetBuffer_Prepare( ctx );
0519 RtemsPartReqGetBuffer_TestVariant( ctx );
0520 RtemsPartReqGetBuffer_Cleanup( ctx );
0521 }
0522 }
0523 }
0524 }
0525
0526