diff options
Diffstat (limited to 'testsuites/validation/tc-clock-get-uptime.c')
-rw-r--r-- | testsuites/validation/tc-clock-get-uptime.c | 316 |
1 files changed, 316 insertions, 0 deletions
diff --git a/testsuites/validation/tc-clock-get-uptime.c b/testsuites/validation/tc-clock-get-uptime.c new file mode 100644 index 0000000000..c5aec837e3 --- /dev/null +++ b/testsuites/validation/tc-clock-get-uptime.c @@ -0,0 +1,316 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsClockReqGetUptime + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems.h> + +#include <rtems/test.h> + +/** + * @defgroup RTEMSTestCaseRtemsClockReqGetUptime \ + * spec:/rtems/clock/req/get-uptime + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsClockReqGetUptime_Pre_Uptime_Valid, + RtemsClockReqGetUptime_Pre_Uptime_Null, + RtemsClockReqGetUptime_Pre_Uptime_NA +} RtemsClockReqGetUptime_Pre_Uptime; + +typedef enum { + RtemsClockReqGetUptime_Post_Status_Ok, + RtemsClockReqGetUptime_Post_Status_InvAddr, + RtemsClockReqGetUptime_Post_Status_NA +} RtemsClockReqGetUptime_Post_Status; + +typedef enum { + RtemsClockReqGetUptime_Post_Uptime_Set, + RtemsClockReqGetUptime_Post_Uptime_Unchanged, + RtemsClockReqGetUptime_Post_Uptime_NA +} RtemsClockReqGetUptime_Post_Uptime; + +/** + * @brief Test context for spec:/rtems/clock/req/get-uptime test case. + */ +typedef struct { + rtems_status_code status; + + struct timespec *uptime; + + struct timespec uptime_value; + + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 1 ]; + + /** + * @brief This member indicates if the test action loop is currently + * executed. + */ + bool in_action_loop; +} RtemsClockReqGetUptime_Context; + +static RtemsClockReqGetUptime_Context + RtemsClockReqGetUptime_Instance; + +static const char * const RtemsClockReqGetUptime_PreDesc_Uptime[] = { + "Valid", + "Null", + "NA" +}; + +static const char * const * const RtemsClockReqGetUptime_PreDesc[] = { + RtemsClockReqGetUptime_PreDesc_Uptime, + NULL +}; + +static void RtemsClockReqGetUptime_Pre_Uptime_Prepare( + RtemsClockReqGetUptime_Context *ctx, + RtemsClockReqGetUptime_Pre_Uptime state +) +{ + switch ( state ) { + case RtemsClockReqGetUptime_Pre_Uptime_Valid: { + /* + * While the ``uptime`` parameter references an object of type struct + * timespec. + */ + ctx->uptime = &ctx->uptime_value; + break; + } + + case RtemsClockReqGetUptime_Pre_Uptime_Null: { + /* + * While the ``uptime`` parameter is NULL. + */ + ctx->uptime = NULL; + break; + } + + case RtemsClockReqGetUptime_Pre_Uptime_NA: + break; + } +} + +static void RtemsClockReqGetUptime_Post_Status_Check( + RtemsClockReqGetUptime_Context *ctx, + RtemsClockReqGetUptime_Post_Status state +) +{ + switch ( state ) { + case RtemsClockReqGetUptime_Post_Status_Ok: { + /* + * The return status of rtems_clock_get_uptime() shall be + * RTEMS_SUCCESSFUL + */ + T_rsc_success( ctx->status ); + break; + } + + case RtemsClockReqGetUptime_Post_Status_InvAddr: { + /* + * The return status of rtems_clock_get_uptime() shall be + * RTEMS_INVALID_ADDRESS. + */ + T_rsc( ctx->status, RTEMS_INVALID_ADDRESS ); + break; + } + + case RtemsClockReqGetUptime_Post_Status_NA: + break; + } +} + +static void RtemsClockReqGetUptime_Post_Uptime_Check( + RtemsClockReqGetUptime_Context *ctx, + RtemsClockReqGetUptime_Post_Uptime state +) +{ + switch ( state ) { + case RtemsClockReqGetUptime_Post_Uptime_Set: { + /* + * The value of the object referenced by the ``uptime`` parameter shall + * be set to seconds and nanoseconds elapsed since a point in time during + * the system initialization and a point in time during the call of + * rtems_clock_get_uptime() using CLOCK_MONOTONIC as result of the + * rtems_clock_get_uptime() call. + */ + T_eq_ptr( ctx->uptime, &ctx->uptime_value ); + T_gt_i64( ctx->uptime_value.tv_sec, 0LL ); + T_gt_long( ctx->uptime_value.tv_nsec, 0L ); + T_lt_long( ctx->uptime_value.tv_nsec, 1000000000L ); + break; + } + + case RtemsClockReqGetUptime_Post_Uptime_Unchanged: { + /* + * Objects referenced by the ``uptime`` parameter in calls to + * rtems_clock_get_uptime() shall not be modified by the + * rtems_clock_get_uptime() call. + */ + T_null( ctx->uptime ); + break; + } + + case RtemsClockReqGetUptime_Post_Uptime_NA: + break; + } +} + +static void RtemsClockReqGetUptime_Setup( RtemsClockReqGetUptime_Context *ctx ) +{ + ctx->uptime_value.tv_sec = -1; + ctx->uptime_value.tv_nsec = -1; +} + +static void RtemsClockReqGetUptime_Setup_Wrap( void *arg ) +{ + RtemsClockReqGetUptime_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsClockReqGetUptime_Setup( ctx ); +} + +static void RtemsClockReqGetUptime_Action( + RtemsClockReqGetUptime_Context *ctx +) +{ + ctx->status = rtems_clock_get_uptime( ctx->uptime ); +} + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_Uptime_NA : 1; + uint8_t Post_Status : 2; + uint8_t Post_Uptime : 2; +} RtemsClockReqGetUptime_Entry; + +static const RtemsClockReqGetUptime_Entry +RtemsClockReqGetUptime_Entries[] = { + { 0, 0, RtemsClockReqGetUptime_Post_Status_Ok, + RtemsClockReqGetUptime_Post_Uptime_Set }, + { 0, 0, RtemsClockReqGetUptime_Post_Status_InvAddr, + RtemsClockReqGetUptime_Post_Uptime_Unchanged } +}; + +static const uint8_t +RtemsClockReqGetUptime_Map[] = { + 0, 1 +}; + +static size_t RtemsClockReqGetUptime_Scope( void *arg, char *buf, size_t n ) +{ + RtemsClockReqGetUptime_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsClockReqGetUptime_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsClockReqGetUptime_Fixture = { + .setup = RtemsClockReqGetUptime_Setup_Wrap, + .stop = NULL, + .teardown = NULL, + .scope = RtemsClockReqGetUptime_Scope, + .initial_context = &RtemsClockReqGetUptime_Instance +}; + +static inline RtemsClockReqGetUptime_Entry RtemsClockReqGetUptime_GetEntry( + size_t index +) +{ + return RtemsClockReqGetUptime_Entries[ + RtemsClockReqGetUptime_Map[ index ] + ]; +} + +/** + * @fn void T_case_body_RtemsClockReqGetUptime( void ) + */ +T_TEST_CASE_FIXTURE( RtemsClockReqGetUptime, &RtemsClockReqGetUptime_Fixture ) +{ + RtemsClockReqGetUptime_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsClockReqGetUptime_Pre_Uptime_Valid; + ctx->pcs[ 0 ] < RtemsClockReqGetUptime_Pre_Uptime_NA; + ++ctx->pcs[ 0 ] + ) { + RtemsClockReqGetUptime_Entry entry; + + entry = RtemsClockReqGetUptime_GetEntry( index ); + ++index; + + RtemsClockReqGetUptime_Pre_Uptime_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsClockReqGetUptime_Action( ctx ); + RtemsClockReqGetUptime_Post_Status_Check( ctx, entry.Post_Status ); + RtemsClockReqGetUptime_Post_Uptime_Check( ctx, entry.Post_Uptime ); + } +} + +/** @} */ |