summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-09-08 08:28:47 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-09-08 13:35:45 +0200
commit4e5ce1eb8766ebf044f4b18bd29a06b3e554f744 (patch)
tree6d1b3ccb4260eac1e60c5e0b2cd8e06af12d54a7
parent7dc808ffe59a1b4d2903c63e8ab08fb8be4b9692 (diff)
validation: Test bad sticky thread queue enqueue
-rw-r--r--spec/build/testsuites/validation/validation-smp-only-0.yml1
-rw-r--r--testsuites/validation/tc-sem-smp.c221
2 files changed, 222 insertions, 0 deletions
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..24ced13333
--- /dev/null
+++ b/testsuites/validation/tc-sem-smp.c
@@ -0,0 +1,221 @@
+/* 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 <rtems.h>
+#include <setjmp.h>
+#include <rtems/score/threaddispatch.h>
+
+#include "ts-config.h"
+#include "tx-support.h"
+
+#include <rtems/test.h>
+
+/**
+ * @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,
+ bool always_set_to_false,
+ rtems_fatal_code code
+)
+{
+ Per_CPU_Control *cpu_self;
+ Context *ctx;
+
+ T_eq_int( source, INTERNAL_ERROR_CORE );
+ T_false( always_set_to_false );
+ T_eq_ulong(
+ code,
+ INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_STICKY_FROM_BAD_STATE
+ );
+
+ SetFatalExtension( NULL );
+
+ cpu_self = _Per_CPU_Get();
+ _Thread_Dispatch_unnest( cpu_self );
+ _Thread_Dispatch_unnest( cpu_self );
+
+ ctx = T_fixture_context();
+ 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 );
+ SetFatalExtension( BadEnqueueFatal );
+ 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 );
+}
+
+/** @} */