From 5d0413e197175707bc0263cafd07e6b099abd21e Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 9 Sep 2021 09:10:52 +0200 Subject: validation: Test semaphore obtain timeout --- .../validation/validation-no-clock-0.yml | 2 + testsuites/validation/tc-sem-timeout.c | 436 ++++++++++++++++ testsuites/validation/tr-tq-timeout.c | 566 +++++++++++++++++++++ testsuites/validation/tr-tq-timeout.h | 104 ++++ 4 files changed, 1108 insertions(+) create mode 100644 testsuites/validation/tc-sem-timeout.c create mode 100644 testsuites/validation/tr-tq-timeout.c create mode 100644 testsuites/validation/tr-tq-timeout.h diff --git a/spec/build/testsuites/validation/validation-no-clock-0.yml b/spec/build/testsuites/validation/validation-no-clock-0.yml index 8d6cfbe91d..d89380a973 100644 --- a/spec/build/testsuites/validation/validation-no-clock-0.yml +++ b/spec/build/testsuites/validation/validation-no-clock-0.yml @@ -24,6 +24,7 @@ source: - testsuites/validation/tc-ratemon-cancel.c - testsuites/validation/tc-ratemon-get-status.c - testsuites/validation/tc-ratemon-period.c +- testsuites/validation/tc-sem-timeout.c - testsuites/validation/tc-task-wake-after.c - testsuites/validation/tc-task-wake-when.c - testsuites/validation/tc-timer.c @@ -36,6 +37,7 @@ source: - testsuites/validation/tc-timer-server-fire-when.c - testsuites/validation/tr-tq-enqueue-fifo.c - testsuites/validation/tr-tq-enqueue-priority.c +- testsuites/validation/tr-tq-timeout.c - testsuites/validation/ts-validation-no-clock-0.c stlib: [] target: testsuites/validation/ts-validation-no-clock-0.exe diff --git a/testsuites/validation/tc-sem-timeout.c b/testsuites/validation/tc-sem-timeout.c new file mode 100644 index 0000000000..b70599a200 --- /dev/null +++ b/testsuites/validation/tc-sem-timeout.c @@ -0,0 +1,436 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsSemReqTimeout + */ + +/* + * 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 + +#include "tr-tq-timeout.h" +#include "tx-support.h" +#include "tx-thread-queue.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsSemReqTimeout spec:/rtems/sem/req/timeout + * + * @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0 + * + * @{ + */ + +typedef enum { + RtemsSemReqTimeout_Pre_Class_Counting, + RtemsSemReqTimeout_Pre_Class_Simple, + RtemsSemReqTimeout_Pre_Class_Binary, + RtemsSemReqTimeout_Pre_Class_PrioCeiling, + RtemsSemReqTimeout_Pre_Class_PrioInherit, + RtemsSemReqTimeout_Pre_Class_MrsP, + RtemsSemReqTimeout_Pre_Class_NA +} RtemsSemReqTimeout_Pre_Class; + +typedef enum { + RtemsSemReqTimeout_Pre_Discipline_FIFO, + RtemsSemReqTimeout_Pre_Discipline_Priority, + RtemsSemReqTimeout_Pre_Discipline_NA +} RtemsSemReqTimeout_Pre_Discipline; + +typedef enum { + RtemsSemReqTimeout_Post_Action_Timeout, + RtemsSemReqTimeout_Post_Action_NA +} RtemsSemReqTimeout_Post_Action; + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_Class_NA : 1; + uint8_t Pre_Discipline_NA : 1; + uint8_t Post_Action : 1; +} RtemsSemReqTimeout_Entry; + +/** + * @brief Test context for spec:/rtems/sem/req/timeout test case. + */ +typedef struct { + /** + * @brief This member contains the thread queue test context. + */ + TQContext tq_ctx;; + + /** + * @brief This member specifies if the attribute set of the semaphore. + */ + rtems_attribute attribute_set; + + struct { + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 2 ]; + + /** + * @brief If this member is true, then the test action loop is executed. + */ + bool in_action_loop; + + /** + * @brief This member contains the next transition map index. + */ + size_t index; + + /** + * @brief This member contains the current transition map entry. + */ + RtemsSemReqTimeout_Entry entry; + + /** + * @brief If this member is true, then the current transition variant + * should be skipped. + */ + bool skip; + } Map; +} RtemsSemReqTimeout_Context; + +static RtemsSemReqTimeout_Context + RtemsSemReqTimeout_Instance; + +static const char * const RtemsSemReqTimeout_PreDesc_Class[] = { + "Counting", + "Simple", + "Binary", + "PrioCeiling", + "PrioInherit", + "MrsP", + "NA" +}; + +static const char * const RtemsSemReqTimeout_PreDesc_Discipline[] = { + "FIFO", + "Priority", + "NA" +}; + +static const char * const * const RtemsSemReqTimeout_PreDesc[] = { + RtemsSemReqTimeout_PreDesc_Class, + RtemsSemReqTimeout_PreDesc_Discipline, + NULL +}; + +static void RtemsSemReqTimeout_Pre_Class_Prepare( + RtemsSemReqTimeout_Context *ctx, + RtemsSemReqTimeout_Pre_Class state +) +{ + switch ( state ) { + case RtemsSemReqTimeout_Pre_Class_Counting: { + /* + * While the semaphore object is a counting semaphore. + */ + ctx->attribute_set |= RTEMS_COUNTING_SEMAPHORE; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_BLOCKS; + break; + } + + case RtemsSemReqTimeout_Pre_Class_Simple: { + /* + * While the semaphore object is a simple binary semaphore. + */ + ctx->attribute_set |= RTEMS_SIMPLE_BINARY_SEMAPHORE; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_BLOCKS; + break; + } + + case RtemsSemReqTimeout_Pre_Class_Binary: { + /* + * While the semaphore object is a binary semaphore. + */ + ctx->attribute_set |= RTEMS_BINARY_SEMAPHORE; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_BLOCKS; + break; + } + + case RtemsSemReqTimeout_Pre_Class_PrioCeiling: { + /* + * While the semaphore object is a priority ceiling semaphore. + */ + ctx->attribute_set |= RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_BLOCKS; + break; + } + + case RtemsSemReqTimeout_Pre_Class_PrioInherit: { + /* + * While the semaphore object is a priority inheritance semaphore. + */ + ctx->attribute_set |= RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_BLOCKS; + break; + } + + case RtemsSemReqTimeout_Pre_Class_MrsP: { + /* + * While the semaphore object is a MrsP semaphore. + */ + ctx->attribute_set |= RTEMS_BINARY_SEMAPHORE | + RTEMS_MULTIPROCESSOR_RESOURCE_SHARING; + ctx->tq_ctx.enqueue_variant = TQ_ENQUEUE_STICKY; + break; + } + + case RtemsSemReqTimeout_Pre_Class_NA: + break; + } +} + +static void RtemsSemReqTimeout_Pre_Discipline_Prepare( + RtemsSemReqTimeout_Context *ctx, + RtemsSemReqTimeout_Pre_Discipline state +) +{ + switch ( state ) { + case RtemsSemReqTimeout_Pre_Discipline_FIFO: { + /* + * While the semaphore uses the FIFO task wait queue discipline. + */ + ctx->attribute_set |= RTEMS_FIFO; + ctx->tq_ctx.discipline = TQ_FIFO; + break; + } + + case RtemsSemReqTimeout_Pre_Discipline_Priority: { + /* + * While the semaphore uses the priority task wait queue discipline. + */ + ctx->attribute_set |= RTEMS_PRIORITY; + ctx->tq_ctx.discipline = TQ_PRIORITY; + break; + } + + case RtemsSemReqTimeout_Pre_Discipline_NA: + break; + } +} + +static void RtemsSemReqTimeout_Post_Action_Check( + RtemsSemReqTimeout_Context *ctx, + RtemsSemReqTimeout_Post_Action state +) +{ + switch ( state ) { + case RtemsSemReqTimeout_Post_Action_Timeout: { + /* + * The semaphore obtain timeout actions shall be done as specified by + * /score/tq/req/timeout. + */ + ScoreTqReqTimeout_Run( &ctx->tq_ctx ); + break; + } + + case RtemsSemReqTimeout_Post_Action_NA: + break; + } +} + +static void RtemsSemReqTimeout_Setup( RtemsSemReqTimeout_Context *ctx ) +{ + memset( ctx, 0, sizeof( *ctx ) ); + ctx->tq_ctx.wait = TQ_WAIT_TICKS; + ctx->tq_ctx.enqueue_prepare = TQEnqueuePrepareClassicSem; + ctx->tq_ctx.enqueue_done = TQSurrenderClassicSem; + ctx->tq_ctx.enqueue = TQEnqueueClassicSem; + ctx->tq_ctx.surrender = TQSurrenderClassicSem; + ctx->tq_ctx.convert_status = TQConvertStatusClassic; + TQInitialize( &ctx->tq_ctx ); +} + +static void RtemsSemReqTimeout_Setup_Wrap( void *arg ) +{ + RtemsSemReqTimeout_Context *ctx; + + ctx = arg; + ctx->Map.in_action_loop = false; + RtemsSemReqTimeout_Setup( ctx ); +} + +static void RtemsSemReqTimeout_Teardown( RtemsSemReqTimeout_Context *ctx ) +{ + TQDestroy( &ctx->tq_ctx ); +} + +static void RtemsSemReqTimeout_Teardown_Wrap( void *arg ) +{ + RtemsSemReqTimeout_Context *ctx; + + ctx = arg; + ctx->Map.in_action_loop = false; + RtemsSemReqTimeout_Teardown( ctx ); +} + +static void RtemsSemReqTimeout_Prepare( RtemsSemReqTimeout_Context *ctx ) +{ + ctx->attribute_set = RTEMS_DEFAULT_ATTRIBUTES; + ctx->tq_ctx.thread_queue_id = 0; +} + +static void RtemsSemReqTimeout_Action( RtemsSemReqTimeout_Context *ctx ) +{ + rtems_status_code sc; + + sc = rtems_semaphore_create( + OBJECT_NAME, + 1, + ctx->attribute_set, + PRIO_HIGH, + &ctx->tq_ctx.thread_queue_id + ); + T_rsc_success( sc ); +} + +static void RtemsSemReqTimeout_Cleanup( RtemsSemReqTimeout_Context *ctx ) +{ + if ( ctx->tq_ctx.thread_queue_id != 0 ) { rtems_status_code sc; + sc = rtems_semaphore_delete( ctx->tq_ctx.thread_queue_id ); T_rsc_success( sc ); } +} + +static const RtemsSemReqTimeout_Entry +RtemsSemReqTimeout_Entries[] = { + { 0, 0, 0, RtemsSemReqTimeout_Post_Action_Timeout }, + { 1, 0, 0, RtemsSemReqTimeout_Post_Action_NA }, +#if defined(RTEMS_SMP) + { 0, 0, 0, RtemsSemReqTimeout_Post_Action_Timeout } +#else + { 1, 0, 0, RtemsSemReqTimeout_Post_Action_NA } +#endif +}; + +static const uint8_t +RtemsSemReqTimeout_Map[] = { + 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2 +}; + +static size_t RtemsSemReqTimeout_Scope( void *arg, char *buf, size_t n ) +{ + RtemsSemReqTimeout_Context *ctx; + + ctx = arg; + + if ( ctx->Map.in_action_loop ) { + return T_get_scope( RtemsSemReqTimeout_PreDesc, buf, n, ctx->Map.pcs ); + } + + return 0; +} + +static T_fixture RtemsSemReqTimeout_Fixture = { + .setup = RtemsSemReqTimeout_Setup_Wrap, + .stop = NULL, + .teardown = RtemsSemReqTimeout_Teardown_Wrap, + .scope = RtemsSemReqTimeout_Scope, + .initial_context = &RtemsSemReqTimeout_Instance +}; + +static inline RtemsSemReqTimeout_Entry RtemsSemReqTimeout_PopEntry( + RtemsSemReqTimeout_Context *ctx +) +{ + size_t index; + + index = ctx->Map.index; + ctx->Map.index = index + 1; + return RtemsSemReqTimeout_Entries[ + RtemsSemReqTimeout_Map[ index ] + ]; +} + +static void RtemsSemReqTimeout_TestVariant( RtemsSemReqTimeout_Context *ctx ) +{ + RtemsSemReqTimeout_Pre_Class_Prepare( ctx, ctx->Map.pcs[ 0 ] ); + RtemsSemReqTimeout_Pre_Discipline_Prepare( ctx, ctx->Map.pcs[ 1 ] ); + RtemsSemReqTimeout_Action( ctx ); + RtemsSemReqTimeout_Post_Action_Check( ctx, ctx->Map.entry.Post_Action ); +} + +/** + * @fn void T_case_body_RtemsSemReqTimeout( void ) + */ +T_TEST_CASE_FIXTURE( RtemsSemReqTimeout, &RtemsSemReqTimeout_Fixture ) +{ + RtemsSemReqTimeout_Context *ctx; + + ctx = T_fixture_context(); + ctx->Map.in_action_loop = true; + ctx->Map.index = 0; + + for ( + ctx->Map.pcs[ 0 ] = RtemsSemReqTimeout_Pre_Class_Counting; + ctx->Map.pcs[ 0 ] < RtemsSemReqTimeout_Pre_Class_NA; + ++ctx->Map.pcs[ 0 ] + ) { + for ( + ctx->Map.pcs[ 1 ] = RtemsSemReqTimeout_Pre_Discipline_FIFO; + ctx->Map.pcs[ 1 ] < RtemsSemReqTimeout_Pre_Discipline_NA; + ++ctx->Map.pcs[ 1 ] + ) { + ctx->Map.entry = RtemsSemReqTimeout_PopEntry( ctx ); + + if ( ctx->Map.entry.Skip ) { + continue; + } + + RtemsSemReqTimeout_Prepare( ctx ); + RtemsSemReqTimeout_TestVariant( ctx ); + RtemsSemReqTimeout_Cleanup( ctx ); + } + } +} + +/** @} */ diff --git a/testsuites/validation/tr-tq-timeout.c b/testsuites/validation/tr-tq-timeout.c new file mode 100644 index 0000000000..f66f01581e --- /dev/null +++ b/testsuites/validation/tr-tq-timeout.c @@ -0,0 +1,566 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreTqReqTimeout + */ + +/* + * 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 "tr-tq-timeout.h" +#include "tx-support.h" + +#include + +/** + * @defgroup RTEMSTestCaseScoreTqReqTimeout spec:/score/tq/req/timeout + * + * @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0 + * + * @{ + */ + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_EnqueueVariant_NA : 1; + uint8_t Pre_WaitState_NA : 1; + uint8_t Post_Status : 2; + uint8_t Post_Unblock : 2; +} ScoreTqReqTimeout_Entry; + +/** + * @brief Test context for spec:/score/tq/req/timeout test case. + */ +typedef struct { + /** + * @brief This member contains the call within ISR request. + */ + CallWithinISRRequest request;; + + /** + * @brief This member contains a copy of the corresponding + * ScoreTqReqTimeout_Run() parameter. + */ + TQContext *tq_ctx; + + struct { + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 2 ]; + + /** + * @brief If this member is true, then the test action loop is executed. + */ + bool in_action_loop; + + /** + * @brief This member contains the next transition map index. + */ + size_t index; + + /** + * @brief This member contains the current transition map entry. + */ + ScoreTqReqTimeout_Entry entry; + + /** + * @brief If this member is true, then the current transition variant + * should be skipped. + */ + bool skip; + } Map; +} ScoreTqReqTimeout_Context; + +static ScoreTqReqTimeout_Context + ScoreTqReqTimeout_Instance; + +static const char * const ScoreTqReqTimeout_PreDesc_EnqueueVariant[] = { + "Blocking", + "Sticky", + "NA" +}; + +static const char * const ScoreTqReqTimeout_PreDesc_WaitState[] = { + "Blocked", + "IntendToBlock", + "ReadyAgain", + "NA" +}; + +static const char * const * const ScoreTqReqTimeout_PreDesc[] = { + ScoreTqReqTimeout_PreDesc_EnqueueVariant, + ScoreTqReqTimeout_PreDesc_WaitState, + NULL +}; + +typedef ScoreTqReqTimeout_Context Context; + +static const rtems_tcb *GetUnblock( Context *ctx, size_t *index ) +{ + return TQGetNextUnblock( ctx->tq_ctx, index )->thread; +} + +static const rtems_tcb *GetTCB( Context *ctx, TQWorkerKind worker ) +{ + return ctx->tq_ctx->worker_tcb[ worker ]; +} + +static void Tick( void *arg ) +{ + Context *ctx; + + ctx = arg; + TQSchedulerRecordStart( ctx->tq_ctx ); + FinalClockTick(); + TQSchedulerRecordStop( ctx->tq_ctx ); +} + +static void SchedulerBlock( void *arg, const T_scheduler_event *event ) +{ + Context *ctx; + + ctx = arg; + + if ( event->operation == T_SCHEDULER_BLOCK ) { + T_scheduler_set_event_handler( NULL, NULL ); + ctx->request.handler = Tick; + CallWithinISRSubmit( &ctx->request ); + } +} + +static void ThreadTimeout( void *arg ) +{ + Context *ctx; + + ctx = arg; + TQSchedulerRecordStart( ctx->tq_ctx ); + _Thread_Timeout( + &ctx->tq_ctx->worker_tcb[ TQ_BLOCKER_A ]->Timer.Watchdog + ); + TQSchedulerRecordStop( ctx->tq_ctx ); +} + +static void SchedulerUnblock( void *arg, const T_scheduler_event *event ) +{ + Context *ctx; + + ctx = arg; + + if ( event->operation == T_SCHEDULER_UNBLOCK ) { + T_scheduler_set_event_handler( NULL, NULL ); + ctx->request.handler = ThreadTimeout; + CallWithinISRSubmit( &ctx->request ); + } +} + +static void ScoreTqReqTimeout_Pre_EnqueueVariant_Prepare( + ScoreTqReqTimeout_Context *ctx, + ScoreTqReqTimeout_Pre_EnqueueVariant state +) +{ + switch ( state ) { + case ScoreTqReqTimeout_Pre_EnqueueVariant_Blocking: { + /* + * Where the thread queue enqueue operation is blocking. + */ + if ( ctx->tq_ctx->enqueue_variant != TQ_ENQUEUE_BLOCKS ) { + ctx->Map.skip = true; + } + break; + } + + case ScoreTqReqTimeout_Pre_EnqueueVariant_Sticky: { + /* + * Where the thread queue enqueue operation is sticky. + */ + if ( ctx->tq_ctx->enqueue_variant != TQ_ENQUEUE_STICKY ) { + ctx->Map.skip = true; + } + break; + } + + case ScoreTqReqTimeout_Pre_EnqueueVariant_NA: + break; + } +} + +static void ScoreTqReqTimeout_Pre_WaitState_Prepare( + ScoreTqReqTimeout_Context *ctx, + ScoreTqReqTimeout_Pre_WaitState state +) +{ + switch ( state ) { + case ScoreTqReqTimeout_Pre_WaitState_Blocked: { + /* + * While the thread of the timeout operation is in the blocked wait + * state. + */ + if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) { + T_unreachable(); + } else { + TQEnqueuePrepare( ctx->tq_ctx ); + TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE ); + Yield(); + Tick( ctx ); + TQEnqueueDone( ctx->tq_ctx ); + } + break; + } + + case ScoreTqReqTimeout_Pre_WaitState_IntendToBlock: { + /* + * While the thread of the timeout operation is in the intend to block + * wait state. + */ + TQEnqueuePrepare( ctx->tq_ctx ); + + if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) { + Per_CPU_Control *cpu; + + TQSendAndWaitForIntendToBlock( + ctx->tq_ctx, + TQ_BLOCKER_A, + TQ_EVENT_ENQUEUE + ); + cpu = _Thread_Get_CPU( ctx->tq_ctx->worker_tcb[ TQ_BLOCKER_A ] ); + + /* + * We have to make sure that the worker thread inserted its thread + * timer. Checking the intend to block wait state is not enough to + * ensure this. + */ + while ( cpu->thread_dispatch_disable_level != 0 ) { + /* Wait */ + } + + Tick( ctx ); + WaitForExecutionStop( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] ); + } else { + T_scheduler_set_event_handler( SchedulerBlock, ctx ); + TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE ); + Yield(); + } + + TQEnqueueDone( ctx->tq_ctx ); + break; + } + + case ScoreTqReqTimeout_Pre_WaitState_ReadyAgain: { + /* + * While the thread of the timeout operation is in the ready again wait + * state. + */ + TQEnqueuePrepare( ctx->tq_ctx ); + + if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) { + TQSendAndWaitForIntendToBlock( + ctx->tq_ctx, + TQ_BLOCKER_A, + TQ_EVENT_ENQUEUE | TQ_EVENT_TIMEOUT | TQ_EVENT_SURRENDER | + TQ_EVENT_SCHEDULER_RECORD_STOP + ); + TQSchedulerRecordStart( ctx->tq_ctx ); + TQEnqueueDone( ctx->tq_ctx ); + WaitForExecutionStop( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] ); + } else { + TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE ); + Yield(); + T_scheduler_set_event_handler( SchedulerUnblock, ctx ); + TQEnqueueDone( ctx->tq_ctx ); + TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_SURRENDER ); + } + break; + } + + case ScoreTqReqTimeout_Pre_WaitState_NA: + break; + } +} + +static void ScoreTqReqTimeout_Post_Status_Check( + ScoreTqReqTimeout_Context *ctx, + ScoreTqReqTimeout_Post_Status state +) +{ + switch ( state ) { + case ScoreTqReqTimeout_Post_Status_Ok: { + /* + * The return status of the directive call shall be derived from + * STATUS_SUCCESSFUL. + */ + T_eq_int( + ctx->tq_ctx->status[ TQ_BLOCKER_A ], + TQConvertStatus( ctx->tq_ctx, STATUS_SUCCESSFUL ) + ); + break; + } + + case ScoreTqReqTimeout_Post_Status_Timeout: { + /* + * The return status of the directive call shall be derived from + * STATUS_TIMEOUT. + */ + T_eq_int( + ctx->tq_ctx->status[ TQ_BLOCKER_A ], + TQConvertStatus( ctx->tq_ctx, STATUS_TIMEOUT ) + ); + break; + } + + case ScoreTqReqTimeout_Post_Status_NA: + break; + } +} + +static void ScoreTqReqTimeout_Post_Unblock_Check( + ScoreTqReqTimeout_Context *ctx, + ScoreTqReqTimeout_Post_Unblock state +) +{ + size_t i; + + i = 0; + + switch ( state ) { + case ScoreTqReqTimeout_Post_Unblock_Yes: { + /* + * The thread of the timeout operation shall not be unblocked by the + * timeout operation. + */ + T_eq_ptr( GetUnblock( ctx, &i ), GetTCB( ctx, TQ_BLOCKER_A ) ); + T_eq_ptr( GetUnblock( ctx, &i ), NULL ); + break; + } + + case ScoreTqReqTimeout_Post_Unblock_No: { + /* + * The thread of the timeout operation shall be unblocked by the timeout + * operation. + */ + T_eq_ptr( GetUnblock( ctx, &i ), NULL ); + break; + } + + case ScoreTqReqTimeout_Post_Unblock_NA: + break; + } +} + +static void ScoreTqReqTimeout_Setup( ScoreTqReqTimeout_Context *ctx ) +{ + ctx->request.arg = ctx; + TQReset( ctx->tq_ctx ); + + if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) { + TQSetScheduler( + ctx->tq_ctx, + TQ_BLOCKER_A, + ctx->tq_ctx->other_scheduler_id, + PRIO_NORMAL + ); + } else { + TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_A, PRIO_HIGH ); + } +} + +static void ScoreTqReqTimeout_Setup_Wrap( void *arg ) +{ + ScoreTqReqTimeout_Context *ctx; + + ctx = arg; + ctx->Map.in_action_loop = false; + ScoreTqReqTimeout_Setup( ctx ); +} + +static void ScoreTqReqTimeout_Teardown( ScoreTqReqTimeout_Context *ctx ) +{ + TQReset( ctx->tq_ctx ); +} + +static void ScoreTqReqTimeout_Teardown_Wrap( void *arg ) +{ + ScoreTqReqTimeout_Context *ctx; + + ctx = arg; + ctx->Map.in_action_loop = false; + ScoreTqReqTimeout_Teardown( ctx ); +} + +static void ScoreTqReqTimeout_Action( ScoreTqReqTimeout_Context *ctx ) +{ + /* + * The action is performed by the ``WaitState`` pre-condition preparation. + */ +} + +static const ScoreTqReqTimeout_Entry +ScoreTqReqTimeout_Entries[] = { + { 0, 0, 0, ScoreTqReqTimeout_Post_Status_Timeout, + ScoreTqReqTimeout_Post_Unblock_No }, + { 0, 0, 0, ScoreTqReqTimeout_Post_Status_Ok, + ScoreTqReqTimeout_Post_Unblock_No }, + { 0, 0, 0, ScoreTqReqTimeout_Post_Status_Timeout, + ScoreTqReqTimeout_Post_Unblock_Yes }, + { 1, 0, 0, ScoreTqReqTimeout_Post_Status_NA, + ScoreTqReqTimeout_Post_Unblock_NA } +}; + +static const uint8_t +ScoreTqReqTimeout_Map[] = { + 2, 0, 1, 3, 0, 1 +}; + +static size_t ScoreTqReqTimeout_Scope( void *arg, char *buf, size_t n ) +{ + ScoreTqReqTimeout_Context *ctx; + + ctx = arg; + + if ( ctx->Map.in_action_loop ) { + return T_get_scope( ScoreTqReqTimeout_PreDesc, buf, n, ctx->Map.pcs ); + } + + return 0; +} + +static T_fixture ScoreTqReqTimeout_Fixture = { + .setup = ScoreTqReqTimeout_Setup_Wrap, + .stop = NULL, + .teardown = ScoreTqReqTimeout_Teardown_Wrap, + .scope = ScoreTqReqTimeout_Scope, + .initial_context = &ScoreTqReqTimeout_Instance +}; + +static inline ScoreTqReqTimeout_Entry ScoreTqReqTimeout_PopEntry( + ScoreTqReqTimeout_Context *ctx +) +{ + size_t index; + + index = ctx->Map.index; + ctx->Map.index = index + 1; + return ScoreTqReqTimeout_Entries[ + ScoreTqReqTimeout_Map[ index ] + ]; +} + +static void ScoreTqReqTimeout_Skip( + ScoreTqReqTimeout_Context *ctx, + size_t index +) +{ + size_t increment; + + ctx->Map.skip = false; + increment = 1; + + switch ( index + 1 ) { + case 1: + increment *= ScoreTqReqTimeout_Pre_WaitState_NA - ctx->Map.pcs[ 1 ]; + ctx->Map.pcs[ 1 ] = ScoreTqReqTimeout_Pre_WaitState_NA - 1; + break; + } + + ctx->Map.index += increment - 1; +} + +static void ScoreTqReqTimeout_TestVariant( ScoreTqReqTimeout_Context *ctx ) +{ + ScoreTqReqTimeout_Pre_EnqueueVariant_Prepare( ctx, ctx->Map.pcs[ 0 ] ); + + if ( ctx->Map.skip ) { + ScoreTqReqTimeout_Skip( ctx, 0 ); + return; + } + + ScoreTqReqTimeout_Pre_WaitState_Prepare( ctx, ctx->Map.pcs[ 1 ] ); + ScoreTqReqTimeout_Action( ctx ); + ScoreTqReqTimeout_Post_Status_Check( ctx, ctx->Map.entry.Post_Status ); + ScoreTqReqTimeout_Post_Unblock_Check( ctx, ctx->Map.entry.Post_Unblock ); +} + +static T_fixture_node ScoreTqReqTimeout_Node; + +void ScoreTqReqTimeout_Run( TQContext *tq_ctx ) +{ + ScoreTqReqTimeout_Context *ctx; + + ctx = &ScoreTqReqTimeout_Instance; + ctx->tq_ctx = tq_ctx; + + ctx = T_push_fixture( &ScoreTqReqTimeout_Node, &ScoreTqReqTimeout_Fixture ); + ctx->Map.in_action_loop = true; + ctx->Map.index = 0; + + for ( + ctx->Map.pcs[ 0 ] = ScoreTqReqTimeout_Pre_EnqueueVariant_Blocking; + ctx->Map.pcs[ 0 ] < ScoreTqReqTimeout_Pre_EnqueueVariant_NA; + ++ctx->Map.pcs[ 0 ] + ) { + for ( + ctx->Map.pcs[ 1 ] = ScoreTqReqTimeout_Pre_WaitState_Blocked; + ctx->Map.pcs[ 1 ] < ScoreTqReqTimeout_Pre_WaitState_NA; + ++ctx->Map.pcs[ 1 ] + ) { + ctx->Map.entry = ScoreTqReqTimeout_PopEntry( ctx ); + + if ( ctx->Map.entry.Skip ) { + continue; + } + + ScoreTqReqTimeout_TestVariant( ctx ); + } + } + + T_pop_fixture(); +} + +/** @} */ diff --git a/testsuites/validation/tr-tq-timeout.h b/testsuites/validation/tr-tq-timeout.h new file mode 100644 index 0000000000..9d111be64b --- /dev/null +++ b/testsuites/validation/tr-tq-timeout.h @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreTqReqTimeout + */ + +/* + * 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 + */ + +#ifndef _TR_TQ_TIMEOUT_H +#define _TR_TQ_TIMEOUT_H + +#include "tx-thread-queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup RTEMSTestCaseScoreTqReqTimeout + * + * @{ + */ + +typedef enum { + ScoreTqReqTimeout_Pre_EnqueueVariant_Blocking, + ScoreTqReqTimeout_Pre_EnqueueVariant_Sticky, + ScoreTqReqTimeout_Pre_EnqueueVariant_NA +} ScoreTqReqTimeout_Pre_EnqueueVariant; + +typedef enum { + ScoreTqReqTimeout_Pre_WaitState_Blocked, + ScoreTqReqTimeout_Pre_WaitState_IntendToBlock, + ScoreTqReqTimeout_Pre_WaitState_ReadyAgain, + ScoreTqReqTimeout_Pre_WaitState_NA +} ScoreTqReqTimeout_Pre_WaitState; + +typedef enum { + ScoreTqReqTimeout_Post_Status_Ok, + ScoreTqReqTimeout_Post_Status_Timeout, + ScoreTqReqTimeout_Post_Status_NA +} ScoreTqReqTimeout_Post_Status; + +typedef enum { + ScoreTqReqTimeout_Post_Unblock_Yes, + ScoreTqReqTimeout_Post_Unblock_No, + ScoreTqReqTimeout_Post_Unblock_NA +} ScoreTqReqTimeout_Post_Unblock; + +/** + * @brief Runs the parameterized test case. + * + * @param[in,out] tq_ctx is the thread queue test context. + */ +void ScoreTqReqTimeout_Run( TQContext *tq_ctx ); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TR_TQ_TIMEOUT_H */ -- cgit v1.2.3