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 RtemsClockReqGetUptime
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 <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsClockReqGetUptime spec:/rtems/clock/req/get-uptime
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef enum {
0068   RtemsClockReqGetUptime_Pre_Uptime_Valid,
0069   RtemsClockReqGetUptime_Pre_Uptime_Null,
0070   RtemsClockReqGetUptime_Pre_Uptime_NA
0071 } RtemsClockReqGetUptime_Pre_Uptime;
0072 
0073 typedef enum {
0074   RtemsClockReqGetUptime_Post_Status_Ok,
0075   RtemsClockReqGetUptime_Post_Status_InvAddr,
0076   RtemsClockReqGetUptime_Post_Status_NA
0077 } RtemsClockReqGetUptime_Post_Status;
0078 
0079 typedef enum {
0080   RtemsClockReqGetUptime_Post_Uptime_Set,
0081   RtemsClockReqGetUptime_Post_Uptime_Unchanged,
0082   RtemsClockReqGetUptime_Post_Uptime_NA
0083 } RtemsClockReqGetUptime_Post_Uptime;
0084 
0085 typedef struct {
0086   uint8_t Skip : 1;
0087   uint8_t Pre_Uptime_NA : 1;
0088   uint8_t Post_Status : 2;
0089   uint8_t Post_Uptime : 2;
0090 } RtemsClockReqGetUptime_Entry;
0091 
0092 /**
0093  * @brief Test context for spec:/rtems/clock/req/get-uptime test case.
0094  */
0095 typedef struct {
0096   rtems_status_code status;
0097 
0098   struct timespec *uptime;
0099 
0100   struct timespec uptime_value;
0101 
0102   struct {
0103     /**
0104      * @brief This member defines the pre-condition states for the next action.
0105      */
0106     size_t pcs[ 1 ];
0107 
0108     /**
0109      * @brief If this member is true, then the test action loop is executed.
0110      */
0111     bool in_action_loop;
0112 
0113     /**
0114      * @brief This member contains the next transition map index.
0115      */
0116     size_t index;
0117 
0118     /**
0119      * @brief This member contains the current transition map entry.
0120      */
0121     RtemsClockReqGetUptime_Entry entry;
0122 
0123     /**
0124      * @brief If this member is true, then the current transition variant
0125      *   should be skipped.
0126      */
0127     bool skip;
0128   } Map;
0129 } RtemsClockReqGetUptime_Context;
0130 
0131 static RtemsClockReqGetUptime_Context
0132   RtemsClockReqGetUptime_Instance;
0133 
0134 static const char * const RtemsClockReqGetUptime_PreDesc_Uptime[] = {
0135   "Valid",
0136   "Null",
0137   "NA"
0138 };
0139 
0140 static const char * const * const RtemsClockReqGetUptime_PreDesc[] = {
0141   RtemsClockReqGetUptime_PreDesc_Uptime,
0142   NULL
0143 };
0144 
0145 static void RtemsClockReqGetUptime_Pre_Uptime_Prepare(
0146   RtemsClockReqGetUptime_Context   *ctx,
0147   RtemsClockReqGetUptime_Pre_Uptime state
0148 )
0149 {
0150   switch ( state ) {
0151     case RtemsClockReqGetUptime_Pre_Uptime_Valid: {
0152       /*
0153        * While the ``uptime`` parameter references an object of type struct
0154        * timespec.
0155        */
0156       ctx->uptime = &ctx->uptime_value;
0157       break;
0158     }
0159 
0160     case RtemsClockReqGetUptime_Pre_Uptime_Null: {
0161       /*
0162        * While the ``uptime`` parameter is NULL.
0163        */
0164       ctx->uptime = NULL;
0165       break;
0166     }
0167 
0168     case RtemsClockReqGetUptime_Pre_Uptime_NA:
0169       break;
0170   }
0171 }
0172 
0173 static void RtemsClockReqGetUptime_Post_Status_Check(
0174   RtemsClockReqGetUptime_Context    *ctx,
0175   RtemsClockReqGetUptime_Post_Status state
0176 )
0177 {
0178   switch ( state ) {
0179     case RtemsClockReqGetUptime_Post_Status_Ok: {
0180       /*
0181        * The return status of rtems_clock_get_uptime() shall be
0182        * RTEMS_SUCCESSFUL
0183        */
0184       T_rsc_success( ctx->status );
0185       break;
0186     }
0187 
0188     case RtemsClockReqGetUptime_Post_Status_InvAddr: {
0189       /*
0190        * The return status of rtems_clock_get_uptime() shall be
0191        * RTEMS_INVALID_ADDRESS.
0192        */
0193       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0194       break;
0195     }
0196 
0197     case RtemsClockReqGetUptime_Post_Status_NA:
0198       break;
0199   }
0200 }
0201 
0202 static void RtemsClockReqGetUptime_Post_Uptime_Check(
0203   RtemsClockReqGetUptime_Context    *ctx,
0204   RtemsClockReqGetUptime_Post_Uptime state
0205 )
0206 {
0207   switch ( state ) {
0208     case RtemsClockReqGetUptime_Post_Uptime_Set: {
0209       /*
0210        * The value of the object referenced by the ``uptime`` parameter shall
0211        * be set to seconds and nanoseconds elapsed since a point in time during
0212        * the system initialization and a point in time during the call of
0213        * rtems_clock_get_uptime() using CLOCK_MONOTONIC as result of the
0214        * rtems_clock_get_uptime() call.
0215        */
0216       T_eq_ptr( ctx->uptime, &ctx->uptime_value );
0217       T_ge_i64( ctx->uptime_value.tv_sec, 0LL );
0218       T_ge_long( ctx->uptime_value.tv_nsec, 0L );
0219       T_lt_long( ctx->uptime_value.tv_nsec, 1000000000L );
0220       break;
0221     }
0222 
0223     case RtemsClockReqGetUptime_Post_Uptime_Unchanged: {
0224       /*
0225        * Objects referenced by the ``uptime`` parameter in calls to
0226        * rtems_clock_get_uptime() shall not be modified by the
0227        * rtems_clock_get_uptime() call.
0228        */
0229       T_null( ctx->uptime );
0230       break;
0231     }
0232 
0233     case RtemsClockReqGetUptime_Post_Uptime_NA:
0234       break;
0235   }
0236 }
0237 
0238 static void RtemsClockReqGetUptime_Setup( RtemsClockReqGetUptime_Context *ctx )
0239 {
0240   ctx->uptime_value.tv_sec  = -1;
0241   ctx->uptime_value.tv_nsec = -1;
0242 }
0243 
0244 static void RtemsClockReqGetUptime_Setup_Wrap( void *arg )
0245 {
0246   RtemsClockReqGetUptime_Context *ctx;
0247 
0248   ctx = arg;
0249   ctx->Map.in_action_loop = false;
0250   RtemsClockReqGetUptime_Setup( ctx );
0251 }
0252 
0253 static void RtemsClockReqGetUptime_Action(
0254   RtemsClockReqGetUptime_Context *ctx
0255 )
0256 {
0257   ctx->status = rtems_clock_get_uptime( ctx->uptime );
0258 }
0259 
0260 static const RtemsClockReqGetUptime_Entry
0261 RtemsClockReqGetUptime_Entries[] = {
0262   { 0, 0, RtemsClockReqGetUptime_Post_Status_Ok,
0263     RtemsClockReqGetUptime_Post_Uptime_Set },
0264   { 0, 0, RtemsClockReqGetUptime_Post_Status_InvAddr,
0265     RtemsClockReqGetUptime_Post_Uptime_Unchanged }
0266 };
0267 
0268 static const uint8_t
0269 RtemsClockReqGetUptime_Map[] = {
0270   0, 1
0271 };
0272 
0273 static size_t RtemsClockReqGetUptime_Scope( void *arg, char *buf, size_t n )
0274 {
0275   RtemsClockReqGetUptime_Context *ctx;
0276 
0277   ctx = arg;
0278 
0279   if ( ctx->Map.in_action_loop ) {
0280     return T_get_scope( RtemsClockReqGetUptime_PreDesc, buf, n, ctx->Map.pcs );
0281   }
0282 
0283   return 0;
0284 }
0285 
0286 static T_fixture RtemsClockReqGetUptime_Fixture = {
0287   .setup = RtemsClockReqGetUptime_Setup_Wrap,
0288   .stop = NULL,
0289   .teardown = NULL,
0290   .scope = RtemsClockReqGetUptime_Scope,
0291   .initial_context = &RtemsClockReqGetUptime_Instance
0292 };
0293 
0294 static inline RtemsClockReqGetUptime_Entry RtemsClockReqGetUptime_PopEntry(
0295   RtemsClockReqGetUptime_Context *ctx
0296 )
0297 {
0298   size_t index;
0299 
0300   index = ctx->Map.index;
0301   ctx->Map.index = index + 1;
0302   return RtemsClockReqGetUptime_Entries[
0303     RtemsClockReqGetUptime_Map[ index ]
0304   ];
0305 }
0306 
0307 static void RtemsClockReqGetUptime_TestVariant(
0308   RtemsClockReqGetUptime_Context *ctx
0309 )
0310 {
0311   RtemsClockReqGetUptime_Pre_Uptime_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0312   RtemsClockReqGetUptime_Action( ctx );
0313   RtemsClockReqGetUptime_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0314   RtemsClockReqGetUptime_Post_Uptime_Check( ctx, ctx->Map.entry.Post_Uptime );
0315 }
0316 
0317 /**
0318  * @fn void T_case_body_RtemsClockReqGetUptime( void )
0319  */
0320 T_TEST_CASE_FIXTURE( RtemsClockReqGetUptime, &RtemsClockReqGetUptime_Fixture )
0321 {
0322   RtemsClockReqGetUptime_Context *ctx;
0323 
0324   ctx = T_fixture_context();
0325   ctx->Map.in_action_loop = true;
0326   ctx->Map.index = 0;
0327 
0328   for (
0329     ctx->Map.pcs[ 0 ] = RtemsClockReqGetUptime_Pre_Uptime_Valid;
0330     ctx->Map.pcs[ 0 ] < RtemsClockReqGetUptime_Pre_Uptime_NA;
0331     ++ctx->Map.pcs[ 0 ]
0332   ) {
0333     ctx->Map.entry = RtemsClockReqGetUptime_PopEntry( ctx );
0334     RtemsClockReqGetUptime_TestVariant( ctx );
0335   }
0336 }
0337 
0338 /** @} */