diff options
Diffstat (limited to 'testsuites/validation/tc-task-restart.c')
-rw-r--r-- | testsuites/validation/tc-task-restart.c | 719 |
1 files changed, 719 insertions, 0 deletions
diff --git a/testsuites/validation/tc-task-restart.c b/testsuites/validation/tc-task-restart.c new file mode 100644 index 0000000000..da27412285 --- /dev/null +++ b/testsuites/validation/tc-task-restart.c @@ -0,0 +1,719 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsTaskReqRestart + */ + +/* + * 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-scheduler.h> + +#include "tx-support.h" + +#include <rtems/test.h> + +/** + * @defgroup RTEMSTestCaseRtemsTaskReqRestart spec:/rtems/task/req/restart + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsTaskReqRestart_Pre_Id_Invalid, + RtemsTaskReqRestart_Pre_Id_Task, + RtemsTaskReqRestart_Pre_Id_NA +} RtemsTaskReqRestart_Pre_Id; + +typedef enum { + RtemsTaskReqRestart_Pre_Argument_Pointer, + RtemsTaskReqRestart_Pre_Argument_Number, + RtemsTaskReqRestart_Pre_Argument_NA +} RtemsTaskReqRestart_Pre_Argument; + +typedef enum { + RtemsTaskReqRestart_Pre_Dormant_Yes, + RtemsTaskReqRestart_Pre_Dormant_No, + RtemsTaskReqRestart_Pre_Dormant_NA +} RtemsTaskReqRestart_Pre_Dormant; + +typedef enum { + RtemsTaskReqRestart_Pre_Suspended_Yes, + RtemsTaskReqRestart_Pre_Suspended_No, + RtemsTaskReqRestart_Pre_Suspended_NA +} RtemsTaskReqRestart_Pre_Suspended; + +typedef enum { + RtemsTaskReqRestart_Post_Status_Ok, + RtemsTaskReqRestart_Post_Status_InvId, + RtemsTaskReqRestart_Post_Status_IncStat, + RtemsTaskReqRestart_Post_Status_NA +} RtemsTaskReqRestart_Post_Status; + +typedef enum { + RtemsTaskReqRestart_Post_Argument_Set, + RtemsTaskReqRestart_Post_Argument_Nop, + RtemsTaskReqRestart_Post_Argument_NA +} RtemsTaskReqRestart_Post_Argument; + +typedef enum { + RtemsTaskReqRestart_Post_Unblock_Yes, + RtemsTaskReqRestart_Post_Unblock_Nop, + RtemsTaskReqRestart_Post_Unblock_NA +} RtemsTaskReqRestart_Post_Unblock; + +typedef enum { + RtemsTaskReqRestart_Post_RestartExtensions_Yes, + RtemsTaskReqRestart_Post_RestartExtensions_Nop, + RtemsTaskReqRestart_Post_RestartExtensions_NA +} RtemsTaskReqRestart_Post_RestartExtensions; + +/** + * @brief Test context for spec:/rtems/task/req/restart test case. + */ +typedef struct { + /** + * @brief This member provides the scheduler operation records. + */ + T_scheduler_log_2 scheduler_log; + + /** + * @brief This member contains the identifier of a task. + */ + rtems_id worker_id; + + /** + * @brief This member contains the identifier of the test user extensions. + */ + rtems_id extension_id; + + /** + * @brief This member contains the count of thread restart extension calls. + */ + uint32_t restart_extension_calls; + + /** + * @brief This member contains the actual argument passed to the entry point. + */ + rtems_task_argument actual_argument; + + /** + * @brief This member contains the entry point counter. + */ + uint32_t counter; + + /** + * @brief If this member is true, then the worker is started before the + * rtems_task_restart() call. + */ + bool start; + + /** + * @brief If this member is true, then the worker is suspended before the + * rtems_task_restart() call. + */ + bool suspend; + + /** + * @brief This member contains the return value of the rtems_task_restart() + * call. + */ + rtems_status_code status; + + /** + * @brief This member specifies if the ``id`` parameter value. + */ + rtems_id id; + + /** + * @brief This member specifies if the ``argument`` parameter value. + */ + rtems_task_argument argument; + + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 4 ]; + + /** + * @brief This member indicates if the test action loop is currently + * executed. + */ + bool in_action_loop; +} RtemsTaskReqRestart_Context; + +static RtemsTaskReqRestart_Context + RtemsTaskReqRestart_Instance; + +static const char * const RtemsTaskReqRestart_PreDesc_Id[] = { + "Invalid", + "Task", + "NA" +}; + +static const char * const RtemsTaskReqRestart_PreDesc_Argument[] = { + "Pointer", + "Number", + "NA" +}; + +static const char * const RtemsTaskReqRestart_PreDesc_Dormant[] = { + "Yes", + "No", + "NA" +}; + +static const char * const RtemsTaskReqRestart_PreDesc_Suspended[] = { + "Yes", + "No", + "NA" +}; + +static const char * const * const RtemsTaskReqRestart_PreDesc[] = { + RtemsTaskReqRestart_PreDesc_Id, + RtemsTaskReqRestart_PreDesc_Argument, + RtemsTaskReqRestart_PreDesc_Dormant, + RtemsTaskReqRestart_PreDesc_Suspended, + NULL +}; + +typedef RtemsTaskReqRestart_Context Context; + +static void Worker( rtems_task_argument arg ) +{ + Context *ctx; + + ctx = &RtemsTaskReqRestart_Instance; + + while ( true ) { + ctx->actual_argument += arg; + ++ctx->counter; + Yield(); + } +} + +static void ThreadRestart( rtems_tcb *executing, rtems_tcb *restarted ) +{ + (void) executing; + (void) restarted; + + ++RtemsTaskReqRestart_Instance.restart_extension_calls; +} + +static const rtems_extensions_table extensions = { + .thread_restart = ThreadRestart +}; + +static void RtemsTaskReqRestart_Pre_Id_Prepare( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Pre_Id state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Pre_Id_Invalid: { + /* + * While the ``id`` parameter is not associated with a task. + */ + ctx->id = INVALID_ID; + break; + } + + case RtemsTaskReqRestart_Pre_Id_Task: { + /* + * While the ``id`` parameter is associated with a task. + */ + ctx->id = ctx->worker_id; + break; + } + + case RtemsTaskReqRestart_Pre_Id_NA: + break; + } +} + +static void RtemsTaskReqRestart_Pre_Argument_Prepare( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Pre_Argument state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Pre_Argument_Pointer: { + /* + * While the entry point argument specified by the ``argument`` parameter + * is a pointer. + */ + ctx->argument = (rtems_task_argument) ctx; + break; + } + + case RtemsTaskReqRestart_Pre_Argument_Number: { + /* + * While the entry point argument specified by the ``argument`` parameter + * is a 32-bit number. + */ + ctx->argument = UINT32_C( 0x87654321 ); + break; + } + + case RtemsTaskReqRestart_Pre_Argument_NA: + break; + } +} + +static void RtemsTaskReqRestart_Pre_Dormant_Prepare( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Pre_Dormant state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Pre_Dormant_Yes: { + /* + * While the task specified by the ``id`` parameter is dormant. + */ + ctx->start = false; + break; + } + + case RtemsTaskReqRestart_Pre_Dormant_No: { + /* + * While the task specified by the ``id`` parameter is not dormant. + */ + ctx->start = true; + break; + } + + case RtemsTaskReqRestart_Pre_Dormant_NA: + break; + } +} + +static void RtemsTaskReqRestart_Pre_Suspended_Prepare( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Pre_Suspended state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Pre_Suspended_Yes: { + /* + * While the task specified by the ``id`` parameter is suspended. + */ + ctx->suspend = true; + break; + } + + case RtemsTaskReqRestart_Pre_Suspended_No: { + /* + * While the task specified by the ``id`` parameter is not suspended. + */ + ctx->suspend = false; + break; + } + + case RtemsTaskReqRestart_Pre_Suspended_NA: + break; + } +} + +static void RtemsTaskReqRestart_Post_Status_Check( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Post_Status state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Post_Status_Ok: { + /* + * The return status of rtems_task_restart() shall be RTEMS_SUCCESSFUL. + */ + T_rsc_success( ctx->status ); + break; + } + + case RtemsTaskReqRestart_Post_Status_InvId: { + /* + * The return status of rtems_task_restart() shall be RTEMS_INVALID_ID. + */ + T_rsc( ctx->status, RTEMS_INVALID_ID ); + break; + } + + case RtemsTaskReqRestart_Post_Status_IncStat: { + /* + * The return status of rtems_task_restart() shall be + * RTEMS_INCORRECT_STATE. + */ + T_rsc( ctx->status, RTEMS_INCORRECT_STATE ); + break; + } + + case RtemsTaskReqRestart_Post_Status_NA: + break; + } +} + +static void RtemsTaskReqRestart_Post_Argument_Check( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Post_Argument state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Post_Argument_Set: { + /* + * The entry point argument of the task specified by the ``id`` parameter + * shall be set to the value specified by the ``argument`` parameter + * before the task is unblocked by the rtems_task_restart() call. + */ + T_eq_u32( ctx->actual_argument, ctx->argument ); + T_eq_u32( ctx->counter, 2 ); + break; + } + + case RtemsTaskReqRestart_Post_Argument_Nop: { + /* + * No entry point argument of a task shall be modified by the + * rtems_task_restart() call. + */ + T_eq_u32( ctx->actual_argument, 0 ); + + if ( ctx->start ) { + T_eq_u32( ctx->counter, 1 ); + } else { + T_eq_u32( ctx->counter, 0 ); + } + break; + } + + case RtemsTaskReqRestart_Post_Argument_NA: + break; + } +} + +static void RtemsTaskReqRestart_Post_Unblock_Check( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Post_Unblock state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Post_Unblock_Yes: { + /* + * The task specified by the ``id`` parameter shall be unblocked by the + * rtems_task_restart() call. + */ + if ( ctx->suspend ) { + T_eq_sz( ctx->scheduler_log.header.recorded, 1 ); + T_eq_int( + ctx->scheduler_log.events[ 0 ].operation, + T_SCHEDULER_UNBLOCK + ); + } else { + T_eq_sz( ctx->scheduler_log.header.recorded, 2 ); + T_eq_int( + ctx->scheduler_log.events[ 0 ].operation, + T_SCHEDULER_BLOCK + ); + T_eq_int( + ctx->scheduler_log.events[ 1 ].operation, + T_SCHEDULER_UNBLOCK + ); + } + break; + } + + case RtemsTaskReqRestart_Post_Unblock_Nop: { + /* + * No task shall be unblocked by the rtems_task_restart() call. + */ + T_eq_sz( ctx->scheduler_log.header.recorded, 0 ); + break; + } + + case RtemsTaskReqRestart_Post_Unblock_NA: + break; + } +} + +static void RtemsTaskReqRestart_Post_RestartExtensions_Check( + RtemsTaskReqRestart_Context *ctx, + RtemsTaskReqRestart_Post_RestartExtensions state +) +{ + switch ( state ) { + case RtemsTaskReqRestart_Post_RestartExtensions_Yes: { + /* + * The thread restart user extensions shall be invoked by the + * rtems_task_restart() call. + */ + T_eq_u32( ctx->restart_extension_calls, 1 ); + break; + } + + case RtemsTaskReqRestart_Post_RestartExtensions_Nop: { + /* + * The thread restart user extensions shall not be invoked by the + * rtems_task_restart() call. + */ + T_eq_u32( ctx->restart_extension_calls, 0 ); + break; + } + + case RtemsTaskReqRestart_Post_RestartExtensions_NA: + break; + } +} + +static void RtemsTaskReqRestart_Setup( RtemsTaskReqRestart_Context *ctx ) +{ + rtems_status_code sc; + + sc = rtems_extension_create( + rtems_build_name( 'T', 'E', 'S', 'T' ), + &extensions, + &ctx->extension_id + ); + T_rsc_success( sc ); +} + +static void RtemsTaskReqRestart_Setup_Wrap( void *arg ) +{ + RtemsTaskReqRestart_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsTaskReqRestart_Setup( ctx ); +} + +static void RtemsTaskReqRestart_Teardown( RtemsTaskReqRestart_Context *ctx ) +{ + rtems_status_code sc; + + sc = rtems_extension_delete( ctx->extension_id ); + T_rsc_success( sc ); +} + +static void RtemsTaskReqRestart_Teardown_Wrap( void *arg ) +{ + RtemsTaskReqRestart_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsTaskReqRestart_Teardown( ctx ); +} + +static void RtemsTaskReqRestart_Prepare( RtemsTaskReqRestart_Context *ctx ) +{ + ctx->actual_argument = 0; + ctx->counter = 0; + ctx->worker_id = CreateTask( "WORK", PRIO_DEFAULT ); +} + +static void RtemsTaskReqRestart_Action( RtemsTaskReqRestart_Context *ctx ) +{ + T_scheduler_log *log; + + if ( ctx->start ) { + StartTask( ctx->worker_id, Worker, 0 ); + Yield(); + } + + if ( ctx->suspend ) { + SuspendTask( ctx->worker_id ); + } + + ctx->restart_extension_calls = 0; + + log = T_scheduler_record_2( &ctx->scheduler_log ); + T_null( log ); + + ctx->status = rtems_task_restart( ctx->id, ctx->argument ); + + log = T_scheduler_record( NULL ); + T_eq_ptr( &log->header, &ctx->scheduler_log.header ); + + Yield(); +} + +static void RtemsTaskReqRestart_Cleanup( RtemsTaskReqRestart_Context *ctx ) +{ + DeleteTask( ctx->worker_id ); +} + +typedef struct { + uint16_t Skip : 1; + uint16_t Pre_Id_NA : 1; + uint16_t Pre_Argument_NA : 1; + uint16_t Pre_Dormant_NA : 1; + uint16_t Pre_Suspended_NA : 1; + uint16_t Post_Status : 2; + uint16_t Post_Argument : 2; + uint16_t Post_Unblock : 2; + uint16_t Post_RestartExtensions : 2; +} RtemsTaskReqRestart_Entry; + +static const RtemsTaskReqRestart_Entry +RtemsTaskReqRestart_Entries[] = { + { 0, 0, 0, 1, 1, RtemsTaskReqRestart_Post_Status_InvId, + RtemsTaskReqRestart_Post_Argument_Nop, + RtemsTaskReqRestart_Post_Unblock_Nop, + RtemsTaskReqRestart_Post_RestartExtensions_Nop }, + { 0, 0, 0, 0, 0, RtemsTaskReqRestart_Post_Status_IncStat, + RtemsTaskReqRestart_Post_Argument_Nop, + RtemsTaskReqRestart_Post_Unblock_Nop, + RtemsTaskReqRestart_Post_RestartExtensions_Nop }, + { 0, 0, 0, 0, 0, RtemsTaskReqRestart_Post_Status_Ok, + RtemsTaskReqRestart_Post_Argument_Set, + RtemsTaskReqRestart_Post_Unblock_Yes, + RtemsTaskReqRestart_Post_RestartExtensions_Yes } +}; + +static const uint8_t +RtemsTaskReqRestart_Map[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2 +}; + +static size_t RtemsTaskReqRestart_Scope( void *arg, char *buf, size_t n ) +{ + RtemsTaskReqRestart_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsTaskReqRestart_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsTaskReqRestart_Fixture = { + .setup = RtemsTaskReqRestart_Setup_Wrap, + .stop = NULL, + .teardown = RtemsTaskReqRestart_Teardown_Wrap, + .scope = RtemsTaskReqRestart_Scope, + .initial_context = &RtemsTaskReqRestart_Instance +}; + +static inline RtemsTaskReqRestart_Entry RtemsTaskReqRestart_GetEntry( + size_t index +) +{ + return RtemsTaskReqRestart_Entries[ + RtemsTaskReqRestart_Map[ index ] + ]; +} + +/** + * @fn void T_case_body_RtemsTaskReqRestart( void ) + */ +T_TEST_CASE_FIXTURE( RtemsTaskReqRestart, &RtemsTaskReqRestart_Fixture ) +{ + RtemsTaskReqRestart_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsTaskReqRestart_Pre_Id_Invalid; + ctx->pcs[ 0 ] < RtemsTaskReqRestart_Pre_Id_NA; + ++ctx->pcs[ 0 ] + ) { + for ( + ctx->pcs[ 1 ] = RtemsTaskReqRestart_Pre_Argument_Pointer; + ctx->pcs[ 1 ] < RtemsTaskReqRestart_Pre_Argument_NA; + ++ctx->pcs[ 1 ] + ) { + for ( + ctx->pcs[ 2 ] = RtemsTaskReqRestart_Pre_Dormant_Yes; + ctx->pcs[ 2 ] < RtemsTaskReqRestart_Pre_Dormant_NA; + ++ctx->pcs[ 2 ] + ) { + for ( + ctx->pcs[ 3 ] = RtemsTaskReqRestart_Pre_Suspended_Yes; + ctx->pcs[ 3 ] < RtemsTaskReqRestart_Pre_Suspended_NA; + ++ctx->pcs[ 3 ] + ) { + RtemsTaskReqRestart_Entry entry; + size_t pcs[ 4 ]; + + entry = RtemsTaskReqRestart_GetEntry( index ); + ++index; + + memcpy( pcs, ctx->pcs, sizeof( pcs ) ); + + if ( entry.Pre_Dormant_NA ) { + ctx->pcs[ 2 ] = RtemsTaskReqRestart_Pre_Dormant_NA; + } + + if ( entry.Pre_Suspended_NA ) { + ctx->pcs[ 3 ] = RtemsTaskReqRestart_Pre_Suspended_NA; + } + + RtemsTaskReqRestart_Prepare( ctx ); + RtemsTaskReqRestart_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsTaskReqRestart_Pre_Argument_Prepare( ctx, ctx->pcs[ 1 ] ); + RtemsTaskReqRestart_Pre_Dormant_Prepare( ctx, ctx->pcs[ 2 ] ); + RtemsTaskReqRestart_Pre_Suspended_Prepare( ctx, ctx->pcs[ 3 ] ); + RtemsTaskReqRestart_Action( ctx ); + RtemsTaskReqRestart_Post_Status_Check( ctx, entry.Post_Status ); + RtemsTaskReqRestart_Post_Argument_Check( ctx, entry.Post_Argument ); + RtemsTaskReqRestart_Post_Unblock_Check( ctx, entry.Post_Unblock ); + RtemsTaskReqRestart_Post_RestartExtensions_Check( + ctx, + entry.Post_RestartExtensions + ); + RtemsTaskReqRestart_Cleanup( ctx ); + memcpy( ctx->pcs, pcs, sizeof( ctx->pcs ) ); + } + } + } + } +} + +/** @} */ |