From 5528750a6b51ace6537e926fb48e197f7a905a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20K=C3=BChndel?= Date: Thu, 8 Apr 2021 15:07:22 +0200 Subject: validation: Add tests for clock manager --- spec/build/testsuites/validation/validation-0.yml | 4 + testsuites/validation/tc-clock-get-tod.c | 501 +++++++++++++++ testsuites/validation/tc-clock-get-tod.h | 72 +++ testsuites/validation/tc-clock-get-uptime.c | 316 +++++++++ testsuites/validation/tc-clock-set.c | 751 ++++++++++++++++++++++ testsuites/validation/tc-clock.c | 137 ++++ 6 files changed, 1781 insertions(+) create mode 100644 testsuites/validation/tc-clock-get-tod.c create mode 100644 testsuites/validation/tc-clock-get-tod.h create mode 100644 testsuites/validation/tc-clock-get-uptime.c create mode 100644 testsuites/validation/tc-clock-set.c create mode 100644 testsuites/validation/tc-clock.c diff --git a/spec/build/testsuites/validation/validation-0.yml b/spec/build/testsuites/validation/validation-0.yml index 64235fded2..b89e478d3a 100644 --- a/spec/build/testsuites/validation/validation-0.yml +++ b/spec/build/testsuites/validation/validation-0.yml @@ -20,6 +20,10 @@ source: - testsuites/validation/tc-barrier-wait.c - testsuites/validation/tc-basedefs.c - testsuites/validation/tc-basedefs-pendant.c +- testsuites/validation/tc-clock.c +- testsuites/validation/tc-clock-set.c +- testsuites/validation/tc-clock-get-tod.c +- testsuites/validation/tc-clock-get-uptime.c - testsuites/validation/tc-events.c - testsuites/validation/tc-event-send-receive.c - testsuites/validation/tc-intr-cause.c diff --git a/testsuites/validation/tc-clock-get-tod.c b/testsuites/validation/tc-clock-get-tod.c new file mode 100644 index 0000000000..2e3f836078 --- /dev/null +++ b/testsuites/validation/tc-clock-get-tod.c @@ -0,0 +1,501 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsClockReqGetTod + */ + +/* + * 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 + +#include "tc-clock-get-tod.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsClockReqGetTod spec:/rtems/clock/req/get-tod + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsClockReqGetTod_Pre_ToD_Arbitrary, + RtemsClockReqGetTod_Pre_ToD_Leap4, + RtemsClockReqGetTod_Pre_ToD_Leap100, + RtemsClockReqGetTod_Pre_ToD_Leap400, + RtemsClockReqGetTod_Pre_ToD_Youngest, + RtemsClockReqGetTod_Pre_ToD_Oldest, + RtemsClockReqGetTod_Pre_ToD_NotSet, + RtemsClockReqGetTod_Pre_ToD_NA +} RtemsClockReqGetTod_Pre_ToD; + +typedef enum { + RtemsClockReqGetTod_Pre_Param_Valid, + RtemsClockReqGetTod_Pre_Param_Null, + RtemsClockReqGetTod_Pre_Param_NA +} RtemsClockReqGetTod_Pre_Param; + +typedef enum { + RtemsClockReqGetTod_Post_Status_Ok, + RtemsClockReqGetTod_Post_Status_InvAddr, + RtemsClockReqGetTod_Post_Status_NotDef, + RtemsClockReqGetTod_Post_Status_NA +} RtemsClockReqGetTod_Post_Status; + +typedef enum { + RtemsClockReqGetTod_Post_Value_TimeOfDay, + RtemsClockReqGetTod_Post_Value_Unchanged, + RtemsClockReqGetTod_Post_Value_NA +} RtemsClockReqGetTod_Post_Value; + +/** + * @brief Test context for spec:/rtems/clock/req/get-tod test case. + */ +typedef struct { + rtems_status_code set_tod_status; + + rtems_time_of_day set_tod_value; + + rtems_time_of_day *get_tod_ref; + + rtems_time_of_day get_tod_value; + + rtems_status_code get_tod_status; + + /** + * @brief Grace period in tick which may be passed between set and get ToD. + */ + uint32_t grace_ticks; + + bool isDef; + + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 2 ]; + + /** + * @brief This member indicates if the test action loop is currently + * executed. + */ + bool in_action_loop; +} RtemsClockReqGetTod_Context; + +static RtemsClockReqGetTod_Context + RtemsClockReqGetTod_Instance; + +static const char * const RtemsClockReqGetTod_PreDesc_ToD[] = { + "Arbitrary", + "Leap4", + "Leap100", + "Leap400", + "Youngest", + "Oldest", + "NotSet", + "NA" +}; + +static const char * const RtemsClockReqGetTod_PreDesc_Param[] = { + "Valid", + "Null", + "NA" +}; + +static const char * const * const RtemsClockReqGetTod_PreDesc[] = { + RtemsClockReqGetTod_PreDesc_ToD, + RtemsClockReqGetTod_PreDesc_Param, + NULL +}; + +rtems_status_code get_tod_before_set_tod( rtems_time_of_day *time_of_day ) +{ + static rtems_time_of_day tod_buf = { 1, 1, 1, 1, 1, 1, 1 }; + static rtems_status_code status; + static bool has_been_called = false; + + if ( ! has_been_called ) { + status = rtems_clock_get_tod( &tod_buf ); + has_been_called = true; + } + + if ( NULL != time_of_day ) { + *time_of_day = tod_buf; + } + + return status; +} + +/* + * How much time may pass between a call to rtems_clock_set() and + * a follow up call to rtems_clock_get_tod() in milliseconds? + */ +#define GRACE_PERIOD 5 + +static void RtemsClockReqGetTod_Pre_ToD_Prepare( + RtemsClockReqGetTod_Context *ctx, + RtemsClockReqGetTod_Pre_ToD state +) +{ + switch ( state ) { + case RtemsClockReqGetTod_Pre_ToD_Arbitrary: { + /* + * While the CLOCK_REALTIME indicates an arbitrary valid date and time + * between 1988-01-01T00:00:00.000000000Z and + * 2514-05-30T01:53:03.999999999Z. + */ + ctx->set_tod_value = + (rtems_time_of_day) { 2023, 12, 27, 6, 7, 8, + rtems_clock_get_ticks_per_second() / 4 }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_Leap4: { + /* + * While the CLOCK_REALTIME indicates a date for a leap year with the + * value of 29th of February. + */ + ctx->set_tod_value = + (rtems_time_of_day) { 2096, 2, 29, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_Leap100: { + /* + * While the CLOCK_REALTIME indicates a date for a non-leap year with the + * value of 28th of February. + */ + ctx->set_tod_value = + (rtems_time_of_day) { 2100, 2, 28, 23, 59, 59, + rtems_clock_get_ticks_per_second() - ctx->grace_ticks }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_Leap400: { + /* + * While the CLOCK_REALTIME indicates a date for a leap year with the + * value of 29th of February. + */ + ctx->set_tod_value = + (rtems_time_of_day) { 2000, 2, 29, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_Youngest: { + /* + * While the CLOCK_REALTIME indicates the youngest date and time accepted + * (1988-01-01T00:00:00.000000000Z). + */ + ctx->set_tod_value = + (rtems_time_of_day) { 1988, 1, 1, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_Oldest: { + /* + * While the CLOCK_REALTIME indicates the oldest date and time accepted + * (2105-12-31T23:59:59.999999999Z). + */ + ctx->set_tod_value = + (rtems_time_of_day) { 2105, 12, 31, 23, 59, 59, + rtems_clock_get_ticks_per_second() - ctx->grace_ticks }; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_NotSet: { + /* + * While the CLOCK_REALTIME has not been set before. + */ + ctx->isDef = false; + break; + } + + case RtemsClockReqGetTod_Pre_ToD_NA: + break; + } +} + +static void RtemsClockReqGetTod_Pre_Param_Prepare( + RtemsClockReqGetTod_Context *ctx, + RtemsClockReqGetTod_Pre_Param state +) +{ + switch ( state ) { + case RtemsClockReqGetTod_Pre_Param_Valid: { + /* + * While the ``time_of_day`` parameter references an object of type + * rtems_time_of_day. + */ + ctx->get_tod_ref = &ctx->get_tod_value; + break; + } + + case RtemsClockReqGetTod_Pre_Param_Null: { + /* + * While the ``time_of_day`` parameter is NULL. + */ + ctx->get_tod_ref = NULL; + break; + } + + case RtemsClockReqGetTod_Pre_Param_NA: + break; + } +} + +static void RtemsClockReqGetTod_Post_Status_Check( + RtemsClockReqGetTod_Context *ctx, + RtemsClockReqGetTod_Post_Status state +) +{ + switch ( state ) { + case RtemsClockReqGetTod_Post_Status_Ok: { + /* + * The return status of rtems_clock_get_tod() shall be RTEMS_SUCCESSFUL + */ + T_rsc_success( ctx->set_tod_status ); + T_rsc_success( ctx->get_tod_status ); + break; + } + + case RtemsClockReqGetTod_Post_Status_InvAddr: { + /* + * The return status of rtems_clock_get_tod() shall be + * RTEMS_INVALID_ADDRESS. + */ + T_rsc( ctx->get_tod_status, RTEMS_INVALID_ADDRESS ); + break; + } + + case RtemsClockReqGetTod_Post_Status_NotDef: { + /* + * The return status of rtems_clock_get_tod() shall be RTEMS_NOT_DEFINED. + */ + T_rsc( ctx->get_tod_status, RTEMS_NOT_DEFINED ); + break; + } + + case RtemsClockReqGetTod_Post_Status_NA: + break; + } +} + +static void RtemsClockReqGetTod_Post_Value_Check( + RtemsClockReqGetTod_Context *ctx, + RtemsClockReqGetTod_Post_Value state +) +{ + switch ( state ) { + case RtemsClockReqGetTod_Post_Value_TimeOfDay: { + /* + * The value of the object referenced by the ``time_of_day`` parameter + * shall be set to the value of the CLOCK_REALTIME at a point in time + * during the call to rtems_clock_get_tod(). + */ + T_eq_ptr( ctx->get_tod_ref, &ctx->get_tod_value ); + T_eq_u32( ctx->get_tod_value.year, ctx->set_tod_value.year ); + T_eq_u32( ctx->get_tod_value.month, ctx->set_tod_value.month ); + T_eq_u32( ctx->get_tod_value.day, ctx->set_tod_value.day ); + T_eq_u32( ctx->get_tod_value.hour, ctx->set_tod_value.hour ); + T_eq_u32( ctx->get_tod_value.minute, ctx->set_tod_value.minute ); + T_eq_u32( ctx->get_tod_value.second, ctx->set_tod_value.second ); + T_ge_u32( ctx->get_tod_value.ticks, ctx->set_tod_value.ticks ); + T_lt_u32( ctx->get_tod_value.ticks, + ctx->set_tod_value.ticks + ctx->grace_ticks ); + break; + } + + case RtemsClockReqGetTod_Post_Value_Unchanged: { + /* + * Object referenced by the ``time_of_day`` parameter in past call to + * rtems_clock_get_tod() shall not be modified by the + * rtems_clock_get_tod() call. + */ + T_eq_u32( ctx->get_tod_value.year, 1 ); + T_eq_u32( ctx->get_tod_value.month, 1 ); + T_eq_u32( ctx->get_tod_value.day, 1 ); + T_eq_u32( ctx->get_tod_value.hour, 1 ); + T_eq_u32( ctx->get_tod_value.minute, 1 ); + T_eq_u32( ctx->get_tod_value.second, 1 ); + T_eq_u32( ctx->get_tod_value.ticks, 1 ); + break; + } + + case RtemsClockReqGetTod_Post_Value_NA: + break; + } +} + +static void RtemsClockReqGetTod_Setup( RtemsClockReqGetTod_Context *ctx ) +{ + /* Call rtems_clock_get_tod() once before rtems_clock_set() gets called */ + get_tod_before_set_tod( NULL ); + + ctx->grace_ticks = rtems_clock_get_ticks_per_second() * GRACE_PERIOD / 1000; +} + +static void RtemsClockReqGetTod_Setup_Wrap( void *arg ) +{ + RtemsClockReqGetTod_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsClockReqGetTod_Setup( ctx ); +} + +static void RtemsClockReqGetTod_Prepare( RtemsClockReqGetTod_Context *ctx ) +{ + ctx->get_tod_value = (rtems_time_of_day) { 1, 1, 1, 1, 1, 1, 1 }; + ctx->get_tod_ref = &ctx->get_tod_value; + ctx->set_tod_value = (rtems_time_of_day) { 2023, 4, 5, 6, 7, 8, 0 }; + ctx->isDef = true; +} + +static void RtemsClockReqGetTod_Action( RtemsClockReqGetTod_Context *ctx ) +{ + if ( ctx->isDef ) { + ctx->set_tod_status = rtems_clock_set( &ctx->set_tod_value ); + ctx->get_tod_status = rtems_clock_get_tod( ctx->get_tod_ref ); + } else { + ctx->get_tod_status = get_tod_before_set_tod( ctx->get_tod_ref ); + } +} + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_ToD_NA : 1; + uint8_t Pre_Param_NA : 1; + uint8_t Post_Status : 2; + uint8_t Post_Value : 2; +} RtemsClockReqGetTod_Entry; + +static const RtemsClockReqGetTod_Entry +RtemsClockReqGetTod_Entries[] = { + { 0, 0, 0, RtemsClockReqGetTod_Post_Status_Ok, + RtemsClockReqGetTod_Post_Value_TimeOfDay }, + { 0, 0, 0, RtemsClockReqGetTod_Post_Status_InvAddr, + RtemsClockReqGetTod_Post_Value_Unchanged }, + { 0, 0, 0, RtemsClockReqGetTod_Post_Status_NotDef, + RtemsClockReqGetTod_Post_Value_Unchanged } +}; + +static const uint8_t +RtemsClockReqGetTod_Map[] = { + 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2 +}; + +static size_t RtemsClockReqGetTod_Scope( void *arg, char *buf, size_t n ) +{ + RtemsClockReqGetTod_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsClockReqGetTod_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsClockReqGetTod_Fixture = { + .setup = RtemsClockReqGetTod_Setup_Wrap, + .stop = NULL, + .teardown = NULL, + .scope = RtemsClockReqGetTod_Scope, + .initial_context = &RtemsClockReqGetTod_Instance +}; + +static inline RtemsClockReqGetTod_Entry RtemsClockReqGetTod_GetEntry( + size_t index +) +{ + return RtemsClockReqGetTod_Entries[ + RtemsClockReqGetTod_Map[ index ] + ]; +} + +/** + * @fn void T_case_body_RtemsClockReqGetTod( void ) + */ +T_TEST_CASE_FIXTURE( RtemsClockReqGetTod, &RtemsClockReqGetTod_Fixture ) +{ + RtemsClockReqGetTod_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsClockReqGetTod_Pre_ToD_Arbitrary; + ctx->pcs[ 0 ] < RtemsClockReqGetTod_Pre_ToD_NA; + ++ctx->pcs[ 0 ] + ) { + for ( + ctx->pcs[ 1 ] = RtemsClockReqGetTod_Pre_Param_Valid; + ctx->pcs[ 1 ] < RtemsClockReqGetTod_Pre_Param_NA; + ++ctx->pcs[ 1 ] + ) { + RtemsClockReqGetTod_Entry entry; + + entry = RtemsClockReqGetTod_GetEntry( index ); + ++index; + + RtemsClockReqGetTod_Prepare( ctx ); + RtemsClockReqGetTod_Pre_ToD_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsClockReqGetTod_Pre_Param_Prepare( ctx, ctx->pcs[ 1 ] ); + RtemsClockReqGetTod_Action( ctx ); + RtemsClockReqGetTod_Post_Status_Check( ctx, entry.Post_Status ); + RtemsClockReqGetTod_Post_Value_Check( ctx, entry.Post_Value ); + } + } +} + +/** @} */ diff --git a/testsuites/validation/tc-clock-get-tod.h b/testsuites/validation/tc-clock-get-tod.h new file mode 100644 index 0000000000..c62e03b76a --- /dev/null +++ b/testsuites/validation/tc-clock-get-tod.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsClockReqGetTod + * + * @brief Helper file to export a local function for use in other tests. + * + */ + +/* + * 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. + */ + +#ifndef _TC_CLOCK_GET_TOD_H +#define _TC_CLOCK_GET_TOD_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Calls rtems_clock_get_tod() for the first time. + * + * The validation test tc-clock-get-tod.c must check the behavior of + * rtems_clock_get_tod() before rtems_clock_set() is called for the + * first time. This function calls rtems_clock_get_tod() if it has + * not been called earlier and records the returned values for later use. + * + * The idea is that any code using rtems_clock_set() in the test suite + * simply invokes get_tod_before_set_tod( NULL ) before it first calls + * rtems_clock_set(). + * + * @param[out] time_of_day The time of day returned by the very first call + * to rtems_clock_get_tod(). If NULL, the parameter is ignored. Otherwise, + * the parameter references a buffer into which the values of the very + * first call will be stored. If rtems_clock_get_tod() did not write into + * the provided buffer, all values will be 1. + * + * @return The status returned by the very first call to rtems_clock_get_tod(). + */ +rtems_status_code get_tod_before_set_tod( rtems_time_of_day *time_of_day ); + +#ifdef __cplusplus +} +#endif + +#endif /* _TC_CLOCK_GET_TOD_H */ 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 + +#include + +/** + * @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 ); + } +} + +/** @} */ diff --git a/testsuites/validation/tc-clock-set.c b/testsuites/validation/tc-clock-set.c new file mode 100644 index 0000000000..0fadbd2e49 --- /dev/null +++ b/testsuites/validation/tc-clock-set.c @@ -0,0 +1,751 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsClockReqSet + */ + +/* + * 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 + +#include "tc-clock-get-tod.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsClockReqSet spec:/rtems/clock/req/set + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsClockReqSet_Pre_ToD_Valid, + RtemsClockReqSet_Pre_ToD_ValidLeap4, + RtemsClockReqSet_Pre_ToD_ValidLeap100, + RtemsClockReqSet_Pre_ToD_ValidNoneLeap100, + RtemsClockReqSet_Pre_ToD_ValidLeap400, + RtemsClockReqSet_Pre_ToD_Youngest, + RtemsClockReqSet_Pre_ToD_Oldest, + RtemsClockReqSet_Pre_ToD_TooJung, + RtemsClockReqSet_Pre_ToD_TooOld, + RtemsClockReqSet_Pre_ToD_InvMonth0, + RtemsClockReqSet_Pre_ToD_InvMonth, + RtemsClockReqSet_Pre_ToD_InvDay0, + RtemsClockReqSet_Pre_ToD_InvDay, + RtemsClockReqSet_Pre_ToD_InvHour, + RtemsClockReqSet_Pre_ToD_InvMinute, + RtemsClockReqSet_Pre_ToD_InvSecond, + RtemsClockReqSet_Pre_ToD_InvTicks, + RtemsClockReqSet_Pre_ToD_InvLeap4, + RtemsClockReqSet_Pre_ToD_InvLeap100, + RtemsClockReqSet_Pre_ToD_InvLeap400, + RtemsClockReqSet_Pre_ToD_AtTimer, + RtemsClockReqSet_Pre_ToD_BeforeTimer, + RtemsClockReqSet_Pre_ToD_AfterTimer, + RtemsClockReqSet_Pre_ToD_Null, + RtemsClockReqSet_Pre_ToD_NA +} RtemsClockReqSet_Pre_ToD; + +typedef enum { + RtemsClockReqSet_Post_Status_Ok, + RtemsClockReqSet_Post_Status_InvAddr, + RtemsClockReqSet_Post_Status_InvClk, + RtemsClockReqSet_Post_Status_NA +} RtemsClockReqSet_Post_Status; + +typedef enum { + RtemsClockReqSet_Post_Clock_Set, + RtemsClockReqSet_Post_Clock_Unchanged, + RtemsClockReqSet_Post_Clock_NA +} RtemsClockReqSet_Post_Clock; + +typedef enum { + RtemsClockReqSet_Post_Timer_Triggered, + RtemsClockReqSet_Post_Timer_Uncalled, + RtemsClockReqSet_Post_Timer_NA +} RtemsClockReqSet_Post_Timer; + +/** + * @brief Test context for spec:/rtems/clock/req/set test case. + */ +typedef struct { + rtems_status_code status; + + rtems_time_of_day *target_tod; + + rtems_time_of_day target_tod_value; + + rtems_time_of_day tod_before; + + rtems_status_code get_tod_before_status; + + rtems_time_of_day tod_after; + + rtems_status_code get_tod_after_status; + + rtems_id timer_id; + + int timer_routine_counter; + + rtems_time_of_day timer_routine_tod; + + /** + * @brief Grace period in tick which may be passed between set and get ToD. + */ + uint32_t grace_ticks; + + /** + * @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; +} RtemsClockReqSet_Context; + +static RtemsClockReqSet_Context + RtemsClockReqSet_Instance; + +static const char * const RtemsClockReqSet_PreDesc_ToD[] = { + "Valid", + "ValidLeap4", + "ValidLeap100", + "ValidNoneLeap100", + "ValidLeap400", + "Youngest", + "Oldest", + "TooJung", + "TooOld", + "InvMonth0", + "InvMonth", + "InvDay0", + "InvDay", + "InvHour", + "InvMinute", + "InvSecond", + "InvTicks", + "InvLeap4", + "InvLeap100", + "InvLeap400", + "AtTimer", + "BeforeTimer", + "AfterTimer", + "Null", + "NA" +}; + +static const char * const * const RtemsClockReqSet_PreDesc[] = { + RtemsClockReqSet_PreDesc_ToD, + NULL +}; + +/* + * How much time may pass between a call to rtems_clock_set() and + * a follow up call to rtems_clock_get_tod() in millisecond? + */ +#define GRACE_PERIOD 5 + +static rtems_timer_service_routine _TOD_timer_routine( + rtems_id timer_id, + void *user_data +) +{ + RtemsClockReqSet_Context *ctx = user_data; + rtems_status_code status; + ++ctx->timer_routine_counter; + status = rtems_clock_get_tod( &ctx->timer_routine_tod ); + T_rsc_success( status ); +} + +static void _TOD_prepare_timer( RtemsClockReqSet_Context *ctx ) +{ + rtems_status_code status; + rtems_time_of_day tod = { 1988, 1, 1, 0, 0, 0, 0 }; + + status = rtems_clock_set( &tod ); + T_rsc_success( status ); + + tod.year = 1989; + status = rtems_timer_fire_when( + ctx->timer_id, + &tod, + _TOD_timer_routine, + ctx + ); + T_rsc_success( status ); +} + +static void RtemsClockReqSet_Pre_ToD_Prepare( + RtemsClockReqSet_Context *ctx, + RtemsClockReqSet_Pre_ToD state +) +{ + switch ( state ) { + case RtemsClockReqSet_Pre_ToD_Valid: { + /* + * While the ``time_of_day`` parameter references an arbitrary valid date + * and time between 1988-01-01T00:00:00.000000000Z and + * 2105-12-31T23:59:59.999999999Z. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 11, 11, 10, 59, + rtems_clock_get_ticks_per_second() / 2 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_ValidLeap4: { + /* + * While the ``time_of_day`` parameter references a date for a leap year + * with the value of 29th of February. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2104, 2, 29, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_ValidLeap100: { + /* + * While the ``time_of_day`` parameter references a date for a non-leap + * century year with the value of 28th of February. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2100, 2, 28, 23, 59, 59, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_ValidNoneLeap100: { + /* + * While the ``time_of_day`` parameter references a date for a non-leap + * century year with the value of 1st of March. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2100, 3, 1, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_ValidLeap400: { + /* + * While the ``time_of_day`` parameter references a date for a leap year + * with the value of 29th of February. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2000, 2, 29, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_Youngest: { + /* + * While the ``time_of_day`` parameter references the youngest date and + * time accepted (1988-01-01T00:00:00.000000000Z). + */ + ctx->target_tod_value = + (rtems_time_of_day) { 1988, 1, 1, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_Oldest: { + /* + * While the ``time_of_day`` parameter references the oldest date and + * time accepted (2105-12-31T23:59:59.999999999Z). + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2105, 12, 31, 23, 59, 59, + rtems_clock_get_ticks_per_second() - ctx->grace_ticks }; + break; + } + + case RtemsClockReqSet_Pre_ToD_TooJung: { + /* + * While the ``time_of_day`` parameter references a valid date and time + * younger than 1988-01-01T00:00:00.000000000Z. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 1987, 12, 31, 23, 59, 59, + rtems_clock_get_ticks_per_second() - 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_TooOld: { + /* + * While the ``time_of_day`` parameter references a valid date and time + * older than 2105-12-31T23:59:59.999999999Z. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2106, 1, 1, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvMonth0: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the month is 0. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 0, 11, 11, 10, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvMonth: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the month is larger than 12. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 13, 11, 11, 10, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvDay0: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the day is 0. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 0, 11, 10, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvDay: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the day is larger than the days of the month. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 2, 29, 11, 10, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvHour: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the hour is larger than 23. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 11, 24, 10, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvMinute: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the minute is larger than 59. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 11, 11, 60, 59, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvSecond: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the second is larger than 59. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 11, 11, 10, 60, 1 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvTicks: { + /* + * While the ``time_of_day`` parameter is invalid because the value of + * the ticks are larger or equal to the ticks per second. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2021, 3, 11, 11, 10, 60, + rtems_clock_get_ticks_per_second() }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvLeap4: { + /* + * While the ``time_of_day`` parameter is invalid because the value 30th + * of February does not exist in a leap year. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2104, 2, 30, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvLeap100: { + /* + * While the ``time_of_day`` parameter is invalid because the value 29th + * of February does not exist in a non-leap year. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2100, 2, 29, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_InvLeap400: { + /* + * While the ``time_of_day`` parameter is invalid because the value 30th + * of February does not exist in a leap year. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 2000, 2, 30, 0, 0, 0, 0 }; + break; + } + + case RtemsClockReqSet_Pre_ToD_AtTimer: { + /* + * While the ``time_of_day`` parameter references the same point in time + * when a timer should fire. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 1989, 1, 1, 0, 0, 0, 0 }; + _TOD_prepare_timer( ctx ); + break; + } + + case RtemsClockReqSet_Pre_ToD_BeforeTimer: { + /* + * While the ``time_of_day`` parameter references a point in time before + * a timer should fire. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 1988, 12, 31, 23, 59, 59, 0 }; + _TOD_prepare_timer( ctx ); + break; + } + + case RtemsClockReqSet_Pre_ToD_AfterTimer: { + /* + * While the ``time_of_day`` parameter references a point in time after a + * timer should fire. + */ + ctx->target_tod_value = + (rtems_time_of_day) { 1989, 1, 1, 1, 0, 0, 0 }; + _TOD_prepare_timer( ctx ); + break; + } + + case RtemsClockReqSet_Pre_ToD_Null: { + /* + * WHile the ``time_of_day`` parameter is NULL. + */ + ctx->target_tod = NULL; + break; + } + + case RtemsClockReqSet_Pre_ToD_NA: + break; + } +} + +static void RtemsClockReqSet_Post_Status_Check( + RtemsClockReqSet_Context *ctx, + RtemsClockReqSet_Post_Status state +) +{ + switch ( state ) { + case RtemsClockReqSet_Post_Status_Ok: { + /* + * The return status of rtems_clock_set() shall be RTEMS_SUCCESSFUL + */ + T_rsc_success( ctx->status ); + break; + } + + case RtemsClockReqSet_Post_Status_InvAddr: { + /* + * The return status of rtems_clock_set() shall be RTEMS_INVALID_ADDRESS. + */ + T_rsc( ctx->status, RTEMS_INVALID_ADDRESS ); + break; + } + + case RtemsClockReqSet_Post_Status_InvClk: { + /* + * The return status of rtems_clock_set() shall be RTEMS_INVALID_CLOCK. + */ + T_rsc( ctx->status, RTEMS_INVALID_CLOCK ); + break; + } + + case RtemsClockReqSet_Post_Status_NA: + break; + } +} + +static void RtemsClockReqSet_Post_Clock_Check( + RtemsClockReqSet_Context *ctx, + RtemsClockReqSet_Post_Clock state +) +{ + switch ( state ) { + case RtemsClockReqSet_Post_Clock_Set: { + /* + * The CLOCK_REALTIME shall be set to the values of the object referenced + * by the ``time_of_day`` parameter during the rtems_clock_set() call. + */ + T_eq_ptr( ctx->target_tod, &ctx->target_tod_value ); + T_rsc_success( ctx->get_tod_after_status ); + T_eq_u32( ctx->tod_after.year, ctx->target_tod_value.year ); + T_eq_u32( ctx->tod_after.month, ctx->target_tod_value.month ); + T_eq_u32( ctx->tod_after.day, ctx->target_tod_value.day ); + T_eq_u32( ctx->tod_after.hour, ctx->target_tod_value.hour ); + T_eq_u32( ctx->tod_after.minute, ctx->target_tod_value.minute ); + T_eq_u32( ctx->tod_after.second, ctx->target_tod_value.second ); + T_ge_u32( ctx->tod_after.ticks, ctx->target_tod_value.ticks ); + T_lt_u32( ctx->tod_after.ticks, + ctx->target_tod_value.ticks + ctx->grace_ticks ); + break; + } + + case RtemsClockReqSet_Post_Clock_Unchanged: { + /* + * The state of the CLOCK_REALTIME shall not be changed by the + * rtems_clock_set() call. + */ + T_rsc_success( ctx->get_tod_before_status ); + T_eq_u32( ctx->tod_after.year, ctx->tod_before.year ); + T_eq_u32( ctx->tod_after.month, ctx->tod_before.month ); + T_eq_u32( ctx->tod_after.day, ctx->tod_before.day ); + T_eq_u32( ctx->tod_after.hour, ctx->tod_before.hour ); + T_eq_u32( ctx->tod_after.minute, ctx->tod_before.minute ); + T_eq_u32( ctx->tod_after.second, ctx->tod_before.second ); + T_ge_u32( ctx->tod_after.ticks, ctx->tod_before.ticks ); + T_lt_u32( ctx->tod_after.ticks, + ctx->tod_before.ticks + 2 * ctx->grace_ticks ); + break; + } + + case RtemsClockReqSet_Post_Clock_NA: + break; + } +} + +static void RtemsClockReqSet_Post_Timer_Check( + RtemsClockReqSet_Context *ctx, + RtemsClockReqSet_Post_Timer state +) +{ + switch ( state ) { + case RtemsClockReqSet_Post_Timer_Triggered: { + /* + * The timer routine shall be executed once after the CLOCK_REALTIME has + * been set and before the execution of the rtems_clock_set() call + * terminates. + */ + T_eq_int( ctx->timer_routine_counter, 1 ); + T_eq_u32( ctx->timer_routine_tod.year, 1989 ); + T_eq_u32( ctx->timer_routine_tod.month, 1 ); + T_eq_u32( ctx->timer_routine_tod.day, 1 ); + T_eq_u32( ctx->timer_routine_tod.minute, 0 ); + T_eq_u32( ctx->timer_routine_tod.second, 0 ); + T_ge_u32( ctx->timer_routine_tod.ticks, 0 ); + T_lt_u32( ctx->timer_routine_tod.ticks, 0 + ctx->grace_ticks ); + break; + } + + case RtemsClockReqSet_Post_Timer_Uncalled: { + /* + * The the timer routine shall not be invoked during the + * rtems_clock_set() call. + */ + T_eq_int( ctx->timer_routine_counter, 0 ); + break; + } + + case RtemsClockReqSet_Post_Timer_NA: + break; + } +} + +static void RtemsClockReqSet_Setup( RtemsClockReqSet_Context *ctx ) +{ + rtems_status_code status; + rtems_name timer_name = rtems_build_name( 'T', 'M', 'R', '0' ); + ctx->timer_id = RTEMS_ID_NONE; + + /* Call rtems_clock_get_tod() once before rtems_clock_set() gets called */ + get_tod_before_set_tod( NULL ); + + ctx->grace_ticks = rtems_clock_get_ticks_per_second() * GRACE_PERIOD / 1000; + ctx->target_tod = &ctx->target_tod_value; + + status = rtems_timer_create( timer_name, &ctx->timer_id ); + T_rsc_success( status ); +} + +static void RtemsClockReqSet_Setup_Wrap( void *arg ) +{ + RtemsClockReqSet_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsClockReqSet_Setup( ctx ); +} + +static void RtemsClockReqSet_Teardown( RtemsClockReqSet_Context *ctx ) +{ + rtems_status_code status; + + if ( RTEMS_ID_NONE != ctx->timer_id ) { + status = rtems_timer_delete( ctx->timer_id ); + T_rsc_success( status ); + } +} + +static void RtemsClockReqSet_Teardown_Wrap( void *arg ) +{ + RtemsClockReqSet_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsClockReqSet_Teardown( ctx ); +} + +static void RtemsClockReqSet_Prepare( RtemsClockReqSet_Context *ctx ) +{ + rtems_status_code status; + + status = rtems_timer_cancel( ctx->timer_id ); + T_rsc_success( status ); + ctx->timer_routine_counter = 0; + ctx->timer_routine_tod = (rtems_time_of_day) { 0, 0, 0, 0, 0, 0, 0 }; +} + +static void RtemsClockReqSet_Action( RtemsClockReqSet_Context *ctx ) +{ + ctx->get_tod_before_status = rtems_clock_get_tod( &ctx->tod_before ); + ctx->status = rtems_clock_set( ctx->target_tod ); + ctx->get_tod_after_status = rtems_clock_get_tod( &ctx->tod_after ); +} + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_ToD_NA : 1; + uint8_t Post_Status : 2; + uint8_t Post_Clock : 2; + uint8_t Post_Timer : 2; +} RtemsClockReqSet_Entry; + +static const RtemsClockReqSet_Entry +RtemsClockReqSet_Entries[] = { + { 0, 0, RtemsClockReqSet_Post_Status_InvClk, + RtemsClockReqSet_Post_Clock_Unchanged, RtemsClockReqSet_Post_Timer_Uncalled }, + { 0, 0, RtemsClockReqSet_Post_Status_Ok, RtemsClockReqSet_Post_Clock_Set, + RtemsClockReqSet_Post_Timer_Uncalled }, + { 0, 0, RtemsClockReqSet_Post_Status_Ok, RtemsClockReqSet_Post_Clock_Set, + RtemsClockReqSet_Post_Timer_Triggered }, + { 0, 0, RtemsClockReqSet_Post_Status_InvAddr, + RtemsClockReqSet_Post_Clock_Unchanged, RtemsClockReqSet_Post_Timer_Uncalled } +}; + +static const uint8_t +RtemsClockReqSet_Map[] = { + 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 3 +}; + +static size_t RtemsClockReqSet_Scope( void *arg, char *buf, size_t n ) +{ + RtemsClockReqSet_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsClockReqSet_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsClockReqSet_Fixture = { + .setup = RtemsClockReqSet_Setup_Wrap, + .stop = NULL, + .teardown = RtemsClockReqSet_Teardown_Wrap, + .scope = RtemsClockReqSet_Scope, + .initial_context = &RtemsClockReqSet_Instance +}; + +static inline RtemsClockReqSet_Entry RtemsClockReqSet_GetEntry( size_t index ) +{ + return RtemsClockReqSet_Entries[ + RtemsClockReqSet_Map[ index ] + ]; +} + +/** + * @fn void T_case_body_RtemsClockReqSet( void ) + */ +T_TEST_CASE_FIXTURE( RtemsClockReqSet, &RtemsClockReqSet_Fixture ) +{ + RtemsClockReqSet_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsClockReqSet_Pre_ToD_Valid; + ctx->pcs[ 0 ] < RtemsClockReqSet_Pre_ToD_NA; + ++ctx->pcs[ 0 ] + ) { + RtemsClockReqSet_Entry entry; + + entry = RtemsClockReqSet_GetEntry( index ); + ++index; + + RtemsClockReqSet_Prepare( ctx ); + RtemsClockReqSet_Pre_ToD_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsClockReqSet_Action( ctx ); + RtemsClockReqSet_Post_Status_Check( ctx, entry.Post_Status ); + RtemsClockReqSet_Post_Clock_Check( ctx, entry.Post_Clock ); + RtemsClockReqSet_Post_Timer_Check( ctx, entry.Post_Timer ); + } +} + +/** @} */ diff --git a/testsuites/validation/tc-clock.c b/testsuites/validation/tc-clock.c new file mode 100644 index 0000000000..21fbf7a688 --- /dev/null +++ b/testsuites/validation/tc-clock.c @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsClockValClock + */ + +/* + * 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 + +#include "ts-config.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsClockValClock spec:/rtems/clock/val/clock + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @brief Tests the Clock Manager from RTEMS the Classic API. + * + * These tests cover only the elements of the Clock Manager API which are + * listed in the Space Profile. + * + * This test case performs the following actions: + * + * - Use the rtems_clock_get_ticks_since_boot() function. + * + * - Check that clock tick gets incremented. + * + * - Use the rtems_clock_get_ticks_per_second() function. + * + * - Check that rtems_clock_get_ticks_per_second() actually returns 1us / + * CONFIGURE_MICROSECONDS_PER_TICK. + * + * @{ + */ + +/** + * @brief Use the rtems_clock_get_ticks_since_boot() function. + */ +static void RtemsClockValClock_Action_0( void ) +{ + rtems_interval result_0; + rtems_interval result_1; + int32_t difference; /* Note: rtems_interval = uint32_t (unsigned!) */ + + result_0 = rtems_clock_get_ticks_since_boot(); + do { + result_1 = rtems_clock_get_ticks_since_boot(); + } while( result_0 == result_1 ); + /* + * Because of the ones-complement, the overflow + * is handled correctly. result_0 = 0xFFFFFFFF will become -1 + * and result_1 = 0x0 will become 0. + */ + difference = (int32_t) result_1 - (int32_t) result_0; + + /* + * Check that clock tick gets incremented. + */ + T_step_eq_i32( 0, difference, 1 ); +} + +/** + * @brief Use the rtems_clock_get_ticks_per_second() function. + */ +static void RtemsClockValClock_Action_1( void ) +{ + rtems_interval result; + result = rtems_clock_get_ticks_per_second(); + + /* + * Check that rtems_clock_get_ticks_per_second() actually returns 1us / + * CONFIGURE_MICROSECONDS_PER_TICK. + */ + T_step_eq_u32( 1, result, 1000000UL / TEST_MICROSECONDS_PER_TICK ); +} + +/** + * @fn void T_case_body_RtemsClockValClock( void ) + */ +T_TEST_CASE( RtemsClockValClock ) +{ + T_plan( 2 ); + + RtemsClockValClock_Action_0(); + RtemsClockValClock_Action_1(); +} + +/** @} */ -- cgit v1.2.3