From fc26689b91fff4d6155e08c7811363f43db768fb Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 8 Sep 2021 08:28:47 +0200 Subject: validation: Test bad sticky thread queue enqueue --- .../validation/validation-smp-only-0.yml | 1 + testsuites/validation/tc-sem-smp.c | 220 +++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 testsuites/validation/tc-sem-smp.c diff --git a/spec/build/testsuites/validation/validation-smp-only-0.yml b/spec/build/testsuites/validation/validation-smp-only-0.yml index 493a838438..2beb8e0fd2 100644 --- a/spec/build/testsuites/validation/validation-smp-only-0.yml +++ b/spec/build/testsuites/validation/validation-smp-only-0.yml @@ -16,6 +16,7 @@ source: - testsuites/validation/tc-scheduler-smp-only.c - testsuites/validation/tc-score-smp-per-cpu-jobs.c - testsuites/validation/tc-score-smp-thread.c +- testsuites/validation/tc-sem-smp.c - testsuites/validation/ts-validation-smp-only-0.c stlib: [] target: testsuites/validation/ts-validation-smp-only-0.exe diff --git a/testsuites/validation/tc-sem-smp.c b/testsuites/validation/tc-sem-smp.c new file mode 100644 index 0000000000..8646b21016 --- /dev/null +++ b/testsuites/validation/tc-sem-smp.c @@ -0,0 +1,220 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsSemValSmp + */ + +/* + * 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 + +#include "ts-config.h" +#include "tx-support.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsSemValSmp spec:/rtems/sem/val/smp + * + * @ingroup RTEMSTestSuiteTestsuitesValidationSmpOnly0 + * + * @brief Tests SMP-specific semaphore behaviour. + * + * This test case performs the following actions: + * + * - Create a worker thread and a mutex. Use the mutex and the worker to + * perform a bad sticky thread queue enqueue. + * + * @{ + */ + +/** + * @brief Test context for spec:/rtems/sem/val/smp test case. + */ +typedef struct { + /** + * @brief This member contains the mutex identifier. + */ + rtems_id mutex_id;; + + /** + * @brief If this member is true, then the worker is done. + */ + volatile bool done; +} RtemsSemValSmp_Context; + +static RtemsSemValSmp_Context + RtemsSemValSmp_Instance; + +static void RtemsSemValSmp_Setup( RtemsSemValSmp_Context *ctx ) +{ + SetSelfPriority( PRIO_NORMAL ); +} + +static void RtemsSemValSmp_Setup_Wrap( void *arg ) +{ + RtemsSemValSmp_Context *ctx; + + ctx = arg; + RtemsSemValSmp_Setup( ctx ); +} + +static void RtemsSemValSmp_Teardown( RtemsSemValSmp_Context *ctx ) +{ + RestoreRunnerPriority(); +} + +static void RtemsSemValSmp_Teardown_Wrap( void *arg ) +{ + RtemsSemValSmp_Context *ctx; + + ctx = arg; + RtemsSemValSmp_Teardown( ctx ); +} + +static T_fixture RtemsSemValSmp_Fixture = { + .setup = RtemsSemValSmp_Setup_Wrap, + .stop = NULL, + .teardown = RtemsSemValSmp_Teardown_Wrap, + .scope = NULL, + .initial_context = &RtemsSemValSmp_Instance +}; + +typedef RtemsSemValSmp_Context Context; + +static void BadEnqueueFatal( + rtems_fatal_source source, + rtems_fatal_code code, + void *arg +) +{ + Per_CPU_Control *cpu_self; + Context *ctx; + + T_eq_int( source, INTERNAL_ERROR_CORE ); + T_eq_ulong( + code, + INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_STICKY_FROM_BAD_STATE + ); + + SetFatalHandler( NULL, NULL ); + + cpu_self = _Per_CPU_Get(); + _Thread_Dispatch_unnest( cpu_self ); + _Thread_Dispatch_unnest( cpu_self ); + + ctx = arg; + ctx->done = true; + SuspendSelf(); +} + +static void BadEnqueueTask( rtems_task_argument arg ) +{ + Context *ctx; + + ctx = (Context *) arg; + (void) _Thread_Dispatch_disable(); + ObtainMutex( ctx->mutex_id ); +} + +/** + * @brief Create a worker thread and a mutex. Use the mutex and the worker to + * perform a bad sticky thread queue enqueue. + */ +static void RtemsSemValSmp_Action_0( RtemsSemValSmp_Context *ctx ) +{ + rtems_status_code sc; + rtems_id worker_id; + rtems_id scheduler_b_id; + + ctx->done = false; + + sc = rtems_scheduler_ident( TEST_SCHEDULER_B_NAME, &scheduler_b_id ); + T_rsc_success( sc ); + + sc = rtems_semaphore_create( + rtems_build_name( 'M', 'U', 'T', 'X' ), + 1, + RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | + RTEMS_MULTIPROCESSOR_RESOURCE_SHARING, + PRIO_HIGH, + &ctx->mutex_id + ); + + worker_id = CreateTask( "WORK", PRIO_NORMAL ); + SetScheduler( worker_id, scheduler_b_id, PRIO_NORMAL ); + + ObtainMutex( ctx->mutex_id ); + SetFatalHandler( BadEnqueueFatal, ctx ); + StartTask( worker_id, BadEnqueueTask, ctx ); + + while ( !ctx->done ) { + /* Wait */ + } + + DeleteTask( worker_id ); + ReleaseMutex( ctx->mutex_id ); + DeleteMutex( ctx->mutex_id ); +} + +/** + * @fn void T_case_body_RtemsSemValSmp( void ) + */ +T_TEST_CASE_FIXTURE( RtemsSemValSmp, &RtemsSemValSmp_Fixture ) +{ + RtemsSemValSmp_Context *ctx; + + ctx = T_fixture_context(); + + RtemsSemValSmp_Action_0( ctx ); +} + +/** @} */ -- cgit v1.2.3