File indexing completed on 2025-05-11 08:24:53
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 "tr-sem-seize-try.h"
0056
0057 #include <rtems/test.h>
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 typedef struct {
0068 uint8_t Skip : 1;
0069 uint8_t Pre_Count_NA : 1;
0070 uint8_t Post_Status : 2;
0071 uint8_t Post_Count : 2;
0072 } ScoreSemReqSeizeTry_Entry;
0073
0074
0075
0076
0077 typedef struct {
0078
0079
0080
0081
0082 uint32_t count_before;
0083
0084
0085
0086
0087 Status_Control status;
0088
0089
0090
0091
0092 uint32_t count_after;
0093
0094
0095
0096
0097
0098 TQSemContext *tq_ctx;
0099
0100 struct {
0101
0102
0103
0104 size_t pcs[ 1 ];
0105
0106
0107
0108
0109 bool in_action_loop;
0110
0111
0112
0113
0114 size_t index;
0115
0116
0117
0118
0119 ScoreSemReqSeizeTry_Entry entry;
0120
0121
0122
0123
0124
0125 bool skip;
0126 } Map;
0127 } ScoreSemReqSeizeTry_Context;
0128
0129 static ScoreSemReqSeizeTry_Context
0130 ScoreSemReqSeizeTry_Instance;
0131
0132 static const char * const ScoreSemReqSeizeTry_PreDesc_Count[] = {
0133 "Zero",
0134 "Positive",
0135 "NA"
0136 };
0137
0138 static const char * const * const ScoreSemReqSeizeTry_PreDesc[] = {
0139 ScoreSemReqSeizeTry_PreDesc_Count,
0140 NULL
0141 };
0142
0143 typedef ScoreSemReqSeizeTry_Context Context;
0144
0145 static Status_Control Status( const Context *ctx, Status_Control status )
0146 {
0147 return TQConvertStatus( &ctx->tq_ctx->base, status );
0148 }
0149
0150 static void ScoreSemReqSeizeTry_Pre_Count_Prepare(
0151 ScoreSemReqSeizeTry_Context *ctx,
0152 ScoreSemReqSeizeTry_Pre_Count state
0153 )
0154 {
0155 switch ( state ) {
0156 case ScoreSemReqSeizeTry_Pre_Count_Zero: {
0157
0158
0159
0160 ctx->count_before = 0;
0161 break;
0162 }
0163
0164 case ScoreSemReqSeizeTry_Pre_Count_Positive: {
0165
0166
0167
0168 ctx->count_before = 1;
0169 break;
0170 }
0171
0172 case ScoreSemReqSeizeTry_Pre_Count_NA:
0173 break;
0174 }
0175 }
0176
0177 static void ScoreSemReqSeizeTry_Post_Status_Check(
0178 ScoreSemReqSeizeTry_Context *ctx,
0179 ScoreSemReqSeizeTry_Post_Status state
0180 )
0181 {
0182 switch ( state ) {
0183 case ScoreSemReqSeizeTry_Post_Status_Ok: {
0184
0185
0186
0187
0188 T_eq_int( ctx->status, Status( ctx, STATUS_SUCCESSFUL ) );
0189 break;
0190 }
0191
0192 case ScoreSemReqSeizeTry_Post_Status_Unsat: {
0193
0194
0195
0196
0197 T_eq_int( ctx->status, Status( ctx, STATUS_UNSATISFIED ) );
0198 break;
0199 }
0200
0201 case ScoreSemReqSeizeTry_Post_Status_NA:
0202 break;
0203 }
0204 }
0205
0206 static void ScoreSemReqSeizeTry_Post_Count_Check(
0207 ScoreSemReqSeizeTry_Context *ctx,
0208 ScoreSemReqSeizeTry_Post_Count state
0209 )
0210 {
0211 switch ( state ) {
0212 case ScoreSemReqSeizeTry_Post_Count_Nop: {
0213
0214
0215
0216 T_eq_u32( ctx->count_after, ctx->count_before );
0217 break;
0218 }
0219
0220 case ScoreSemReqSeizeTry_Post_Count_MinusOne: {
0221
0222
0223
0224 T_eq_u32( ctx->count_after, ctx->count_before - 1 );
0225 break;
0226 }
0227
0228 case ScoreSemReqSeizeTry_Post_Count_NA:
0229 break;
0230 }
0231 }
0232
0233 static void ScoreSemReqSeizeTry_Action( ScoreSemReqSeizeTry_Context *ctx )
0234 {
0235 TQSemSetCount( ctx->tq_ctx, ctx->count_before );
0236 ctx->status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
0237 ctx->count_after = TQSemGetCount( ctx->tq_ctx );
0238 }
0239
0240 static const ScoreSemReqSeizeTry_Entry
0241 ScoreSemReqSeizeTry_Entries[] = {
0242 { 0, 0, ScoreSemReqSeizeTry_Post_Status_Unsat,
0243 ScoreSemReqSeizeTry_Post_Count_Nop },
0244 { 0, 0, ScoreSemReqSeizeTry_Post_Status_Ok,
0245 ScoreSemReqSeizeTry_Post_Count_MinusOne }
0246 };
0247
0248 static const uint8_t
0249 ScoreSemReqSeizeTry_Map[] = {
0250 0, 1
0251 };
0252
0253 static size_t ScoreSemReqSeizeTry_Scope( void *arg, char *buf, size_t n )
0254 {
0255 ScoreSemReqSeizeTry_Context *ctx;
0256
0257 ctx = arg;
0258
0259 if ( ctx->Map.in_action_loop ) {
0260 return T_get_scope( ScoreSemReqSeizeTry_PreDesc, buf, n, ctx->Map.pcs );
0261 }
0262
0263 return 0;
0264 }
0265
0266 static T_fixture ScoreSemReqSeizeTry_Fixture = {
0267 .setup = NULL,
0268 .stop = NULL,
0269 .teardown = NULL,
0270 .scope = ScoreSemReqSeizeTry_Scope,
0271 .initial_context = &ScoreSemReqSeizeTry_Instance
0272 };
0273
0274 static inline ScoreSemReqSeizeTry_Entry ScoreSemReqSeizeTry_PopEntry(
0275 ScoreSemReqSeizeTry_Context *ctx
0276 )
0277 {
0278 size_t index;
0279
0280 index = ctx->Map.index;
0281 ctx->Map.index = index + 1;
0282 return ScoreSemReqSeizeTry_Entries[
0283 ScoreSemReqSeizeTry_Map[ index ]
0284 ];
0285 }
0286
0287 static void ScoreSemReqSeizeTry_TestVariant( ScoreSemReqSeizeTry_Context *ctx )
0288 {
0289 ScoreSemReqSeizeTry_Pre_Count_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0290 ScoreSemReqSeizeTry_Action( ctx );
0291 ScoreSemReqSeizeTry_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0292 ScoreSemReqSeizeTry_Post_Count_Check( ctx, ctx->Map.entry.Post_Count );
0293 }
0294
0295 static T_fixture_node ScoreSemReqSeizeTry_Node;
0296
0297 static T_remark ScoreSemReqSeizeTry_Remark = {
0298 .next = NULL,
0299 .remark = "ScoreSemReqSeizeTry"
0300 };
0301
0302 void ScoreSemReqSeizeTry_Run( TQSemContext *tq_ctx )
0303 {
0304 ScoreSemReqSeizeTry_Context *ctx;
0305
0306 ctx = &ScoreSemReqSeizeTry_Instance;
0307 ctx->tq_ctx = tq_ctx;
0308
0309 ctx = T_push_fixture(
0310 &ScoreSemReqSeizeTry_Node,
0311 &ScoreSemReqSeizeTry_Fixture
0312 );
0313 ctx->Map.in_action_loop = true;
0314 ctx->Map.index = 0;
0315
0316 for (
0317 ctx->Map.pcs[ 0 ] = ScoreSemReqSeizeTry_Pre_Count_Zero;
0318 ctx->Map.pcs[ 0 ] < ScoreSemReqSeizeTry_Pre_Count_NA;
0319 ++ctx->Map.pcs[ 0 ]
0320 ) {
0321 ctx->Map.entry = ScoreSemReqSeizeTry_PopEntry( ctx );
0322 ScoreSemReqSeizeTry_TestVariant( ctx );
0323 }
0324
0325 T_add_remark( &ScoreSemReqSeizeTry_Remark );
0326 T_pop_fixture();
0327 }
0328
0329