summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-04-07 14:13:41 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-04-13 09:35:11 +0200
commit4b7b3bafc3dfcf7d53b62289ea76df99da564750 (patch)
tree33dfe5b391e63464deb63e88610235e84cee0153
parent14515cedda5b7299e38627bd2ef14830f1d76ac0 (diff)
validation: Test rtems_semaphore_obtain()
-rw-r--r--spec/build/testsuites/validation/validation-0.yml1
-rw-r--r--testsuites/validation/tc-sem-obtain.c530
2 files changed, 531 insertions, 0 deletions
diff --git a/spec/build/testsuites/validation/validation-0.yml b/spec/build/testsuites/validation/validation-0.yml
index 11ce470c1a..4262bc375a 100644
--- a/spec/build/testsuites/validation/validation-0.yml
+++ b/spec/build/testsuites/validation/validation-0.yml
@@ -42,6 +42,7 @@ source:
- testsuites/validation/tc-ratemon-ident.c
- testsuites/validation/tc-sem-create.c
- testsuites/validation/tc-sem-ident.c
+- testsuites/validation/tc-sem-obtain.c
- testsuites/validation/tc-sem-release.c
- testsuites/validation/tc-sem-set-priority.c
- testsuites/validation/tc-signal-catch.c
diff --git a/testsuites/validation/tc-sem-obtain.c b/testsuites/validation/tc-sem-obtain.c
new file mode 100644
index 0000000000..9897a6815b
--- /dev/null
+++ b/testsuites/validation/tc-sem-obtain.c
@@ -0,0 +1,530 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTestCaseRtemsSemReqObtain
+ */
+
+/*
+ * 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 <string.h>
+
+#include "tr-sem-seize-try.h"
+#include "tr-sem-seize-wait.h"
+#include "tx-support.h"
+#include "tx-thread-queue.h"
+
+#include <rtems/test.h>
+
+/**
+ * @defgroup RTEMSTestCaseRtemsSemReqObtain spec:/rtems/sem/req/obtain
+ *
+ * @ingroup RTEMSTestSuiteTestsuitesValidation0
+ *
+ * @{
+ */
+
+typedef enum {
+ RtemsSemReqObtain_Pre_Class_Counting,
+ RtemsSemReqObtain_Pre_Class_Simple,
+ RtemsSemReqObtain_Pre_Class_NA
+} RtemsSemReqObtain_Pre_Class;
+
+typedef enum {
+ RtemsSemReqObtain_Pre_Discipline_FIFO,
+ RtemsSemReqObtain_Pre_Discipline_Priority,
+ RtemsSemReqObtain_Pre_Discipline_NA
+} RtemsSemReqObtain_Pre_Discipline;
+
+typedef enum {
+ RtemsSemReqObtain_Pre_Id_Valid,
+ RtemsSemReqObtain_Pre_Id_Invalid,
+ RtemsSemReqObtain_Pre_Id_NA
+} RtemsSemReqObtain_Pre_Id;
+
+typedef enum {
+ RtemsSemReqObtain_Pre_Wait_No,
+ RtemsSemReqObtain_Pre_Wait_Timeout,
+ RtemsSemReqObtain_Pre_Wait_Forever,
+ RtemsSemReqObtain_Pre_Wait_NA
+} RtemsSemReqObtain_Pre_Wait;
+
+typedef enum {
+ RtemsSemReqObtain_Post_Action_InvId,
+ RtemsSemReqObtain_Post_Action_SemSeizeTry,
+ RtemsSemReqObtain_Post_Action_SemSeizeWait,
+ RtemsSemReqObtain_Post_Action_NA
+} RtemsSemReqObtain_Post_Action;
+
+/**
+ * @brief Test context for spec:/rtems/sem/req/obtain test case.
+ */
+typedef struct {
+ /**
+ * @brief This member contains the thread queue test context.
+ */
+ union {
+ TQContext tq_ctx;
+ TQSemContext tq_sem_ctx;
+ };
+
+ /**
+ * @brief This member specifies if the attribute set of the semaphore.
+ */
+ rtems_attribute attribute_set;
+
+ /**
+ * @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;
+} RtemsSemReqObtain_Context;
+
+static RtemsSemReqObtain_Context
+ RtemsSemReqObtain_Instance;
+
+static const char * const RtemsSemReqObtain_PreDesc_Class[] = {
+ "Counting",
+ "Simple",
+ "NA"
+};
+
+static const char * const RtemsSemReqObtain_PreDesc_Discipline[] = {
+ "FIFO",
+ "Priority",
+ "NA"
+};
+
+static const char * const RtemsSemReqObtain_PreDesc_Id[] = {
+ "Valid",
+ "Invalid",
+ "NA"
+};
+
+static const char * const RtemsSemReqObtain_PreDesc_Wait[] = {
+ "No",
+ "Timeout",
+ "Forever",
+ "NA"
+};
+
+static const char * const * const RtemsSemReqObtain_PreDesc[] = {
+ RtemsSemReqObtain_PreDesc_Class,
+ RtemsSemReqObtain_PreDesc_Discipline,
+ RtemsSemReqObtain_PreDesc_Id,
+ RtemsSemReqObtain_PreDesc_Wait,
+ NULL
+};
+
+#define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
+
+typedef RtemsSemReqObtain_Context Context;
+
+static void RtemsSemReqObtain_Pre_Class_Prepare(
+ RtemsSemReqObtain_Context *ctx,
+ RtemsSemReqObtain_Pre_Class state
+)
+{
+ switch ( state ) {
+ case RtemsSemReqObtain_Pre_Class_Counting: {
+ /*
+ * While the semaphore object is a counting semaphore.
+ */
+ ctx->attribute_set |= RTEMS_COUNTING_SEMAPHORE;
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Class_Simple: {
+ /*
+ * While the semaphore object is a simple binary semaphore.
+ */
+ ctx->attribute_set |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Class_NA:
+ break;
+ }
+}
+
+static void RtemsSemReqObtain_Pre_Discipline_Prepare(
+ RtemsSemReqObtain_Context *ctx,
+ RtemsSemReqObtain_Pre_Discipline state
+)
+{
+ switch ( state ) {
+ case RtemsSemReqObtain_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 RtemsSemReqObtain_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 RtemsSemReqObtain_Pre_Discipline_NA:
+ break;
+ }
+}
+
+static void RtemsSemReqObtain_Pre_Id_Prepare(
+ RtemsSemReqObtain_Context *ctx,
+ RtemsSemReqObtain_Pre_Id state
+)
+{
+ switch ( state ) {
+ case RtemsSemReqObtain_Pre_Id_Valid: {
+ /*
+ * While the ``id`` parameter is associated with the semaphore.
+ */
+ /* Nothing to prepare */
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Id_Invalid: {
+ /*
+ * While the ``id`` parameter is not associated with a semaphore.
+ */
+ /* Nothing to prepare */
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Id_NA:
+ break;
+ }
+}
+
+static void RtemsSemReqObtain_Pre_Wait_Prepare(
+ RtemsSemReqObtain_Context *ctx,
+ RtemsSemReqObtain_Pre_Wait state
+)
+{
+ switch ( state ) {
+ case RtemsSemReqObtain_Pre_Wait_No: {
+ /*
+ * While the ``option_set`` parameter indicates the
+ * /rtems/option/if/no-wait option.
+ */
+ ctx->tq_ctx.wait = TQ_NO_WAIT;
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Wait_Timeout: {
+ /*
+ * While the ``option_set`` parameter indicates the RTEMS_WAIT option,
+ * while the ``timeout`` parameter is not equal to RTEMS_NO_TIMEOUT.
+ */
+ ctx->tq_ctx.wait = TQ_WAIT_TICKS;
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Wait_Forever: {
+ /*
+ * While the ``option_set`` parameter indicates the RTEMS_WAIT option,
+ * while the ``timeout`` parameter is equal to RTEMS_NO_TIMEOUT.
+ */
+ ctx->tq_ctx.wait = TQ_WAIT_FOREVER;
+ break;
+ }
+
+ case RtemsSemReqObtain_Pre_Wait_NA:
+ break;
+ }
+}
+
+static void RtemsSemReqObtain_Post_Action_Check(
+ RtemsSemReqObtain_Context *ctx,
+ RtemsSemReqObtain_Post_Action state
+)
+{
+ rtems_status_code sc;
+
+ switch ( state ) {
+ case RtemsSemReqObtain_Post_Action_InvId: {
+ /*
+ * The return status of rtems_semaphore_obtain() shall be
+ * RTEMS_INVALID_ID.
+ */
+ sc = rtems_semaphore_obtain( 0xffffffff, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+ T_rsc( sc, RTEMS_INVALID_ID );
+ break;
+ }
+
+ case RtemsSemReqObtain_Post_Action_SemSeizeTry: {
+ /*
+ * The calling task shall try to seize the semaphore as specified by
+ * /score/sem/req/seize-try.
+ */
+ ctx->tq_sem_ctx.get_count = TQSemGetCountClassic;
+ ctx->tq_sem_ctx.set_count = TQSemSetCountClassic;
+ ScoreSemReqSeizeTry_Run( &ctx->tq_sem_ctx );
+ break;
+ }
+
+ case RtemsSemReqObtain_Post_Action_SemSeizeWait: {
+ /*
+ * The calling task shall wait to seize the semaphore as specified by
+ * /score/sem/req/seize-wait.
+ */
+ ctx->tq_sem_ctx.get_count = TQSemGetCountClassic;
+ ctx->tq_sem_ctx.set_count = TQSemSetCountClassic;
+ ScoreSemReqSeizeWait_Run( &ctx->tq_sem_ctx );
+ break;
+ }
+
+ case RtemsSemReqObtain_Post_Action_NA:
+ break;
+ }
+}
+
+static void RtemsSemReqObtain_Setup( RtemsSemReqObtain_Context *ctx )
+{
+ memset( ctx, 0, sizeof( *ctx ) );
+ ctx->tq_ctx.enqueue = TQEnqueueClassicSem;
+ ctx->tq_ctx.dequeue_one = TQDequeueClassicSem;
+ ctx->tq_ctx.dequeue_all = TQDequeueClassicSem;
+ ctx->tq_ctx.convert_status = TQConvertStatusClassic;
+ TQInitialize( &ctx->tq_ctx );
+}
+
+static void RtemsSemReqObtain_Setup_Wrap( void *arg )
+{
+ RtemsSemReqObtain_Context *ctx;
+
+ ctx = arg;
+ ctx->in_action_loop = false;
+ RtemsSemReqObtain_Setup( ctx );
+}
+
+static void RtemsSemReqObtain_Teardown( RtemsSemReqObtain_Context *ctx )
+{
+ TQDestroy( &ctx->tq_ctx );
+}
+
+static void RtemsSemReqObtain_Teardown_Wrap( void *arg )
+{
+ RtemsSemReqObtain_Context *ctx;
+
+ ctx = arg;
+ ctx->in_action_loop = false;
+ RtemsSemReqObtain_Teardown( ctx );
+}
+
+static void RtemsSemReqObtain_Action( RtemsSemReqObtain_Context *ctx )
+{
+ rtems_status_code sc;
+
+ sc = rtems_semaphore_create(
+ NAME,
+ 1,
+ ctx->attribute_set,
+ PRIO_ULTRA_HIGH,
+ &ctx->tq_ctx.thread_queue_id
+ );
+ T_rsc_success( sc );
+}
+
+static void RtemsSemReqObtain_Cleanup( RtemsSemReqObtain_Context *ctx )
+{
+ rtems_status_code sc;
+ sc = rtems_semaphore_delete( ctx->tq_ctx.thread_queue_id ); T_rsc_success( sc );
+}
+
+typedef struct {
+ uint8_t Skip : 1;
+ uint8_t Pre_Class_NA : 1;
+ uint8_t Pre_Discipline_NA : 1;
+ uint8_t Pre_Id_NA : 1;
+ uint8_t Pre_Wait_NA : 1;
+ uint8_t Post_Action : 2;
+} RtemsSemReqObtain_Entry;
+
+static const RtemsSemReqObtain_Entry
+RtemsSemReqObtain_Entries[] = {
+ { 0, 0, 0, 0, 0, RtemsSemReqObtain_Post_Action_InvId },
+ { 0, 0, 0, 0, 0, RtemsSemReqObtain_Post_Action_SemSeizeWait },
+ { 0, 0, 0, 0, 0, RtemsSemReqObtain_Post_Action_SemSeizeTry }
+};
+
+static const uint8_t
+RtemsSemReqObtain_Map[] = {
+ 2, 1, 1, 0, 0, 0, 2, 1, 1, 0, 0, 0, 2, 1, 1, 0, 0, 0, 2, 1, 1, 0, 0, 0
+};
+
+static size_t RtemsSemReqObtain_Scope( void *arg, char *buf, size_t n )
+{
+ RtemsSemReqObtain_Context *ctx;
+
+ ctx = arg;
+
+ if ( ctx->in_action_loop ) {
+ return T_get_scope( RtemsSemReqObtain_PreDesc, buf, n, ctx->pcs );
+ }
+
+ return 0;
+}
+
+static T_fixture RtemsSemReqObtain_Fixture = {
+ .setup = RtemsSemReqObtain_Setup_Wrap,
+ .stop = NULL,
+ .teardown = RtemsSemReqObtain_Teardown_Wrap,
+ .scope = RtemsSemReqObtain_Scope,
+ .initial_context = &RtemsSemReqObtain_Instance
+};
+
+static inline RtemsSemReqObtain_Entry RtemsSemReqObtain_GetEntry(
+ size_t index
+)
+{
+ return RtemsSemReqObtain_Entries[
+ RtemsSemReqObtain_Map[ index ]
+ ];
+}
+
+/**
+ * @fn void T_case_body_RtemsSemReqObtain( void )
+ */
+T_TEST_CASE_FIXTURE( RtemsSemReqObtain, &RtemsSemReqObtain_Fixture )
+{
+ RtemsSemReqObtain_Context *ctx;
+ RtemsSemReqObtain_Entry entry;
+ size_t index;
+
+ ctx = T_fixture_context();
+ ctx->in_action_loop = true;
+ index = 0;
+
+ for (
+ ctx->pcs[ 0 ] = RtemsSemReqObtain_Pre_Class_Counting;
+ ctx->pcs[ 0 ] < RtemsSemReqObtain_Pre_Class_NA;
+ ++ctx->pcs[ 0 ]
+ ) {
+ entry = RtemsSemReqObtain_GetEntry( index );
+
+ if ( entry.Pre_Class_NA ) {
+ ctx->pcs[ 0 ] = RtemsSemReqObtain_Pre_Class_NA;
+ index += ( RtemsSemReqObtain_Pre_Class_NA - 1 )
+ * RtemsSemReqObtain_Pre_Discipline_NA
+ * RtemsSemReqObtain_Pre_Id_NA
+ * RtemsSemReqObtain_Pre_Wait_NA;
+ }
+
+ for (
+ ctx->pcs[ 1 ] = RtemsSemReqObtain_Pre_Discipline_FIFO;
+ ctx->pcs[ 1 ] < RtemsSemReqObtain_Pre_Discipline_NA;
+ ++ctx->pcs[ 1 ]
+ ) {
+ entry = RtemsSemReqObtain_GetEntry( index );
+
+ if ( entry.Pre_Discipline_NA ) {
+ ctx->pcs[ 1 ] = RtemsSemReqObtain_Pre_Discipline_NA;
+ index += ( RtemsSemReqObtain_Pre_Discipline_NA - 1 )
+ * RtemsSemReqObtain_Pre_Id_NA
+ * RtemsSemReqObtain_Pre_Wait_NA;
+ }
+
+ for (
+ ctx->pcs[ 2 ] = RtemsSemReqObtain_Pre_Id_Valid;
+ ctx->pcs[ 2 ] < RtemsSemReqObtain_Pre_Id_NA;
+ ++ctx->pcs[ 2 ]
+ ) {
+ entry = RtemsSemReqObtain_GetEntry( index );
+
+ if ( entry.Pre_Id_NA ) {
+ ctx->pcs[ 2 ] = RtemsSemReqObtain_Pre_Id_NA;
+ index += ( RtemsSemReqObtain_Pre_Id_NA - 1 )
+ * RtemsSemReqObtain_Pre_Wait_NA;
+ }
+
+ for (
+ ctx->pcs[ 3 ] = RtemsSemReqObtain_Pre_Wait_No;
+ ctx->pcs[ 3 ] < RtemsSemReqObtain_Pre_Wait_NA;
+ ++ctx->pcs[ 3 ]
+ ) {
+ entry = RtemsSemReqObtain_GetEntry( index );
+
+ if ( entry.Pre_Wait_NA ) {
+ ctx->pcs[ 3 ] = RtemsSemReqObtain_Pre_Wait_NA;
+ index += ( RtemsSemReqObtain_Pre_Wait_NA - 1 );
+ }
+
+ if ( entry.Skip ) {
+ ++index;
+ continue;
+ }
+
+ RtemsSemReqObtain_Pre_Class_Prepare( ctx, ctx->pcs[ 0 ] );
+ RtemsSemReqObtain_Pre_Discipline_Prepare( ctx, ctx->pcs[ 1 ] );
+ RtemsSemReqObtain_Pre_Id_Prepare( ctx, ctx->pcs[ 2 ] );
+ RtemsSemReqObtain_Pre_Wait_Prepare( ctx, ctx->pcs[ 3 ] );
+ RtemsSemReqObtain_Action( ctx );
+ RtemsSemReqObtain_Post_Action_Check( ctx, entry.Post_Action );
+ RtemsSemReqObtain_Cleanup( ctx );
+ ++index;
+ }
+ }
+ }
+ }
+}
+
+/** @} */