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 "tx-support.h"
0058
0059 #include <rtems/test.h>
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 typedef enum {
0070 RtemsClockReqGetTod_Pre_ToD_Arbitrary,
0071 RtemsClockReqGetTod_Pre_ToD_Leap4,
0072 RtemsClockReqGetTod_Pre_ToD_Leap400,
0073 RtemsClockReqGetTod_Pre_ToD_Youngest,
0074 RtemsClockReqGetTod_Pre_ToD_Oldest,
0075 RtemsClockReqGetTod_Pre_ToD_NotSet,
0076 RtemsClockReqGetTod_Pre_ToD_NA
0077 } RtemsClockReqGetTod_Pre_ToD;
0078
0079 typedef enum {
0080 RtemsClockReqGetTod_Pre_Param_Valid,
0081 RtemsClockReqGetTod_Pre_Param_Null,
0082 RtemsClockReqGetTod_Pre_Param_NA
0083 } RtemsClockReqGetTod_Pre_Param;
0084
0085 typedef enum {
0086 RtemsClockReqGetTod_Post_Status_Ok,
0087 RtemsClockReqGetTod_Post_Status_InvAddr,
0088 RtemsClockReqGetTod_Post_Status_NotDef,
0089 RtemsClockReqGetTod_Post_Status_NA
0090 } RtemsClockReqGetTod_Post_Status;
0091
0092 typedef enum {
0093 RtemsClockReqGetTod_Post_Value_TimeOfDay,
0094 RtemsClockReqGetTod_Post_Value_Unchanged,
0095 RtemsClockReqGetTod_Post_Value_NA
0096 } RtemsClockReqGetTod_Post_Value;
0097
0098 typedef struct {
0099 uint8_t Skip : 1;
0100 uint8_t Pre_ToD_NA : 1;
0101 uint8_t Pre_Param_NA : 1;
0102 uint8_t Post_Status : 2;
0103 uint8_t Post_Value : 2;
0104 } RtemsClockReqGetTod_Entry;
0105
0106
0107
0108
0109 typedef struct {
0110 rtems_status_code set_tod_status;
0111
0112 rtems_time_of_day set_tod_value;
0113
0114 rtems_time_of_day *get_tod_ref;
0115
0116 rtems_time_of_day get_tod_value;
0117
0118 rtems_status_code get_tod_status;
0119
0120 bool isDef;
0121
0122 struct {
0123
0124
0125
0126 size_t pcs[ 2 ];
0127
0128
0129
0130
0131 bool in_action_loop;
0132
0133
0134
0135
0136 size_t index;
0137
0138
0139
0140
0141 RtemsClockReqGetTod_Entry entry;
0142
0143
0144
0145
0146
0147 bool skip;
0148 } Map;
0149 } RtemsClockReqGetTod_Context;
0150
0151 static RtemsClockReqGetTod_Context
0152 RtemsClockReqGetTod_Instance;
0153
0154 static const char * const RtemsClockReqGetTod_PreDesc_ToD[] = {
0155 "Arbitrary",
0156 "Leap4",
0157 "Leap400",
0158 "Youngest",
0159 "Oldest",
0160 "NotSet",
0161 "NA"
0162 };
0163
0164 static const char * const RtemsClockReqGetTod_PreDesc_Param[] = {
0165 "Valid",
0166 "Null",
0167 "NA"
0168 };
0169
0170 static const char * const * const RtemsClockReqGetTod_PreDesc[] = {
0171 RtemsClockReqGetTod_PreDesc_ToD,
0172 RtemsClockReqGetTod_PreDesc_Param,
0173 NULL
0174 };
0175
0176 static void RtemsClockReqGetTod_Pre_ToD_Prepare(
0177 RtemsClockReqGetTod_Context *ctx,
0178 RtemsClockReqGetTod_Pre_ToD state
0179 )
0180 {
0181 switch ( state ) {
0182 case RtemsClockReqGetTod_Pre_ToD_Arbitrary: {
0183
0184
0185
0186
0187
0188 ctx->set_tod_value =
0189 (rtems_time_of_day) { 2023, 12, 27, 6, 7, 8,
0190 rtems_clock_get_ticks_per_second() / 4 };
0191 break;
0192 }
0193
0194 case RtemsClockReqGetTod_Pre_ToD_Leap4: {
0195
0196
0197
0198
0199 ctx->set_tod_value =
0200 (rtems_time_of_day) { 2096, 2, 29, 0, 0, 0, 0 };
0201 break;
0202 }
0203
0204 case RtemsClockReqGetTod_Pre_ToD_Leap400: {
0205
0206
0207
0208
0209 ctx->set_tod_value =
0210 (rtems_time_of_day) { 2000, 2, 29, 0, 0, 0, 0 };
0211 break;
0212 }
0213
0214 case RtemsClockReqGetTod_Pre_ToD_Youngest: {
0215
0216
0217
0218
0219 ctx->set_tod_value =
0220 (rtems_time_of_day) { 1988, 1, 1, 0, 0, 0, 0 };
0221 break;
0222 }
0223
0224 case RtemsClockReqGetTod_Pre_ToD_Oldest: {
0225
0226
0227
0228
0229 ctx->set_tod_value =
0230 (rtems_time_of_day) { 2099, 12, 31, 23, 59, 59,
0231 rtems_clock_get_ticks_per_second() - 1 };
0232 break;
0233 }
0234
0235 case RtemsClockReqGetTod_Pre_ToD_NotSet: {
0236
0237
0238
0239 ctx->isDef = false;
0240 break;
0241 }
0242
0243 case RtemsClockReqGetTod_Pre_ToD_NA:
0244 break;
0245 }
0246 }
0247
0248 static void RtemsClockReqGetTod_Pre_Param_Prepare(
0249 RtemsClockReqGetTod_Context *ctx,
0250 RtemsClockReqGetTod_Pre_Param state
0251 )
0252 {
0253 switch ( state ) {
0254 case RtemsClockReqGetTod_Pre_Param_Valid: {
0255
0256
0257
0258
0259 ctx->get_tod_ref = &ctx->get_tod_value;
0260 break;
0261 }
0262
0263 case RtemsClockReqGetTod_Pre_Param_Null: {
0264
0265
0266
0267 ctx->get_tod_ref = NULL;
0268 break;
0269 }
0270
0271 case RtemsClockReqGetTod_Pre_Param_NA:
0272 break;
0273 }
0274 }
0275
0276 static void RtemsClockReqGetTod_Post_Status_Check(
0277 RtemsClockReqGetTod_Context *ctx,
0278 RtemsClockReqGetTod_Post_Status state
0279 )
0280 {
0281 switch ( state ) {
0282 case RtemsClockReqGetTod_Post_Status_Ok: {
0283
0284
0285
0286 T_rsc_success( ctx->set_tod_status );
0287 T_rsc_success( ctx->get_tod_status );
0288 break;
0289 }
0290
0291 case RtemsClockReqGetTod_Post_Status_InvAddr: {
0292
0293
0294
0295
0296 T_rsc( ctx->get_tod_status, RTEMS_INVALID_ADDRESS );
0297 break;
0298 }
0299
0300 case RtemsClockReqGetTod_Post_Status_NotDef: {
0301
0302
0303
0304 T_rsc( ctx->get_tod_status, RTEMS_NOT_DEFINED );
0305 break;
0306 }
0307
0308 case RtemsClockReqGetTod_Post_Status_NA:
0309 break;
0310 }
0311 }
0312
0313 static void RtemsClockReqGetTod_Post_Value_Check(
0314 RtemsClockReqGetTod_Context *ctx,
0315 RtemsClockReqGetTod_Post_Value state
0316 )
0317 {
0318 switch ( state ) {
0319 case RtemsClockReqGetTod_Post_Value_TimeOfDay: {
0320
0321
0322
0323
0324
0325 T_eq_ptr( ctx->get_tod_ref, &ctx->get_tod_value );
0326 T_eq_u32( ctx->get_tod_value.year, ctx->set_tod_value.year );
0327 T_eq_u32( ctx->get_tod_value.month, ctx->set_tod_value.month );
0328 T_eq_u32( ctx->get_tod_value.day, ctx->set_tod_value.day );
0329 T_eq_u32( ctx->get_tod_value.hour, ctx->set_tod_value.hour );
0330 T_eq_u32( ctx->get_tod_value.minute, ctx->set_tod_value.minute );
0331 T_eq_u32( ctx->get_tod_value.second, ctx->set_tod_value.second );
0332
0333 T_ge_u32( ctx->get_tod_value.ticks + 1, ctx->set_tod_value.ticks );
0334 T_le_u32( ctx->get_tod_value.ticks, ctx->set_tod_value.ticks );
0335 break;
0336 }
0337
0338 case RtemsClockReqGetTod_Post_Value_Unchanged: {
0339
0340
0341
0342
0343
0344 T_eq_u32( ctx->get_tod_value.year, 1 );
0345 T_eq_u32( ctx->get_tod_value.month, 1 );
0346 T_eq_u32( ctx->get_tod_value.day, 1 );
0347 T_eq_u32( ctx->get_tod_value.hour, 1 );
0348 T_eq_u32( ctx->get_tod_value.minute, 1 );
0349 T_eq_u32( ctx->get_tod_value.second, 1 );
0350 T_eq_u32( ctx->get_tod_value.ticks, 1 );
0351 break;
0352 }
0353
0354 case RtemsClockReqGetTod_Post_Value_NA:
0355 break;
0356 }
0357 }
0358
0359 static void RtemsClockReqGetTod_Prepare( RtemsClockReqGetTod_Context *ctx )
0360 {
0361 ctx->get_tod_value = (rtems_time_of_day) { 1, 1, 1, 1, 1, 1, 1 };
0362 ctx->get_tod_ref = &ctx->get_tod_value;
0363 ctx->set_tod_value = (rtems_time_of_day) { 2023, 4, 5, 6, 7, 8, 0 };
0364 ctx->isDef = true;
0365 }
0366
0367 static void RtemsClockReqGetTod_Action( RtemsClockReqGetTod_Context *ctx )
0368 {
0369 if ( ctx->isDef ) {
0370 ctx->set_tod_status = rtems_clock_set( &ctx->set_tod_value );
0371 ctx->get_tod_status = rtems_clock_get_tod( ctx->get_tod_ref );
0372 } else {
0373 UnsetClock();
0374 ctx->get_tod_status = rtems_clock_get_tod( ctx->get_tod_ref );
0375 }
0376 }
0377
0378 static void RtemsClockReqGetTod_Cleanup( RtemsClockReqGetTod_Context *ctx )
0379 {
0380 UnsetClock();
0381 }
0382
0383 static const RtemsClockReqGetTod_Entry
0384 RtemsClockReqGetTod_Entries[] = {
0385 { 0, 0, 0, RtemsClockReqGetTod_Post_Status_InvAddr,
0386 RtemsClockReqGetTod_Post_Value_Unchanged },
0387 { 0, 0, 0, RtemsClockReqGetTod_Post_Status_Ok,
0388 RtemsClockReqGetTod_Post_Value_TimeOfDay },
0389 { 0, 0, 0, RtemsClockReqGetTod_Post_Status_NotDef,
0390 RtemsClockReqGetTod_Post_Value_Unchanged }
0391 };
0392
0393 static const uint8_t
0394 RtemsClockReqGetTod_Map[] = {
0395 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0
0396 };
0397
0398 static size_t RtemsClockReqGetTod_Scope( void *arg, char *buf, size_t n )
0399 {
0400 RtemsClockReqGetTod_Context *ctx;
0401
0402 ctx = arg;
0403
0404 if ( ctx->Map.in_action_loop ) {
0405 return T_get_scope( RtemsClockReqGetTod_PreDesc, buf, n, ctx->Map.pcs );
0406 }
0407
0408 return 0;
0409 }
0410
0411 static T_fixture RtemsClockReqGetTod_Fixture = {
0412 .setup = NULL,
0413 .stop = NULL,
0414 .teardown = NULL,
0415 .scope = RtemsClockReqGetTod_Scope,
0416 .initial_context = &RtemsClockReqGetTod_Instance
0417 };
0418
0419 static inline RtemsClockReqGetTod_Entry RtemsClockReqGetTod_PopEntry(
0420 RtemsClockReqGetTod_Context *ctx
0421 )
0422 {
0423 size_t index;
0424
0425 index = ctx->Map.index;
0426 ctx->Map.index = index + 1;
0427 return RtemsClockReqGetTod_Entries[
0428 RtemsClockReqGetTod_Map[ index ]
0429 ];
0430 }
0431
0432 static void RtemsClockReqGetTod_TestVariant( RtemsClockReqGetTod_Context *ctx )
0433 {
0434 RtemsClockReqGetTod_Pre_ToD_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0435 RtemsClockReqGetTod_Pre_Param_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0436 RtemsClockReqGetTod_Action( ctx );
0437 RtemsClockReqGetTod_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0438 RtemsClockReqGetTod_Post_Value_Check( ctx, ctx->Map.entry.Post_Value );
0439 }
0440
0441
0442
0443
0444 T_TEST_CASE_FIXTURE( RtemsClockReqGetTod, &RtemsClockReqGetTod_Fixture )
0445 {
0446 RtemsClockReqGetTod_Context *ctx;
0447
0448 ctx = T_fixture_context();
0449 ctx->Map.in_action_loop = true;
0450 ctx->Map.index = 0;
0451
0452 for (
0453 ctx->Map.pcs[ 0 ] = RtemsClockReqGetTod_Pre_ToD_Arbitrary;
0454 ctx->Map.pcs[ 0 ] < RtemsClockReqGetTod_Pre_ToD_NA;
0455 ++ctx->Map.pcs[ 0 ]
0456 ) {
0457 for (
0458 ctx->Map.pcs[ 1 ] = RtemsClockReqGetTod_Pre_Param_Valid;
0459 ctx->Map.pcs[ 1 ] < RtemsClockReqGetTod_Pre_Param_NA;
0460 ++ctx->Map.pcs[ 1 ]
0461 ) {
0462 ctx->Map.entry = RtemsClockReqGetTod_PopEntry( ctx );
0463 RtemsClockReqGetTod_Prepare( ctx );
0464 RtemsClockReqGetTod_TestVariant( ctx );
0465 RtemsClockReqGetTod_Cleanup( ctx );
0466 }
0467 }
0468 }
0469
0470