Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:51

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsClockReqGetTod
0007  */
0008 
0009 /*
0010  * Copyright (C) 2021 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
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  * @defgroup RtemsClockReqGetTod spec:/rtems/clock/req/get-tod
0063  *
0064  * @ingroup TestsuitesValidationNoClock0
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  * @brief Test context for spec:/rtems/clock/req/get-tod test case.
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      * @brief This member defines the pre-condition states for the next action.
0125      */
0126     size_t pcs[ 2 ];
0127 
0128     /**
0129      * @brief If this member is true, then the test action loop is executed.
0130      */
0131     bool in_action_loop;
0132 
0133     /**
0134      * @brief This member contains the next transition map index.
0135      */
0136     size_t index;
0137 
0138     /**
0139      * @brief This member contains the current transition map entry.
0140      */
0141     RtemsClockReqGetTod_Entry entry;
0142 
0143     /**
0144      * @brief If this member is true, then the current transition variant
0145      *   should be skipped.
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        * While the CLOCK_REALTIME indicates an arbitrary valid date and time
0185        * between 1988-01-01T00:00:00.000000000Z and
0186        * 2514-05-30T01:53:03.999999999Z.
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        * While the CLOCK_REALTIME indicates a date for a leap year with the
0197        * value of 29th of February.
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        * While the CLOCK_REALTIME indicates a date for a leap year with the
0207        * value of 29th of February.
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        * While the CLOCK_REALTIME indicates the youngest date and time accepted
0217        * (1988-01-01T00:00:00.000000000Z).
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        * While the CLOCK_REALTIME indicates the oldest date and time accepted
0227        * (2099-12-31T23:59:59.999999999Z).
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        * While the CLOCK_REALTIME has not been set before.
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        * While the ``time_of_day`` parameter references an object of type
0257        * rtems_time_of_day.
0258        */
0259       ctx->get_tod_ref = &ctx->get_tod_value;
0260       break;
0261     }
0262 
0263     case RtemsClockReqGetTod_Pre_Param_Null: {
0264       /*
0265        * While the ``time_of_day`` parameter is NULL.
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        * The return status of rtems_clock_get_tod() shall be RTEMS_SUCCESSFUL
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        * The return status of rtems_clock_get_tod() shall be
0294        * RTEMS_INVALID_ADDRESS.
0295        */
0296       T_rsc( ctx->get_tod_status, RTEMS_INVALID_ADDRESS );
0297       break;
0298     }
0299 
0300     case RtemsClockReqGetTod_Post_Status_NotDef: {
0301       /*
0302        * The return status of rtems_clock_get_tod() shall be RTEMS_NOT_DEFINED.
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        * The value of the object referenced by the ``time_of_day`` parameter
0322        * shall be set to the value of the CLOCK_REALTIME at a point in time
0323        * during the call to rtems_clock_get_tod().
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       /* rtems_clock_set() or rtems_clock_get_tod() cause an error of 1 tick */
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        * Object referenced by the ``time_of_day`` parameter in past call to
0341        * rtems_clock_get_tod() shall not be modified by the
0342        * rtems_clock_get_tod() call.
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  * @fn void T_case_body_RtemsClockReqGetTod( void )
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 /** @} */