From eafa9b91882f4d33972dd237db8c3fdf6cd35399 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 11 Mar 2021 21:39:04 +0100 Subject: validation: Add tests for message manager --- spec/build/testsuites/validation/validation-0.yml | 1 + testsuites/validation/tc-message-delete.c | 456 ++++++++++++++++++++++ 2 files changed, 457 insertions(+) create mode 100644 testsuites/validation/tc-message-delete.c diff --git a/spec/build/testsuites/validation/validation-0.yml b/spec/build/testsuites/validation/validation-0.yml index aa2cb4441c..5d59588c3a 100644 --- a/spec/build/testsuites/validation/validation-0.yml +++ b/spec/build/testsuites/validation/validation-0.yml @@ -35,6 +35,7 @@ source: - testsuites/validation/tc-intr-vector-enable.c - testsuites/validation/tc-intr-vector-is-enabled.c - testsuites/validation/tc-message-construct-errors.c +- testsuites/validation/tc-message-delete.c - testsuites/validation/tc-message-ident.c - testsuites/validation/tc-modes.c - testsuites/validation/tc-object.c diff --git a/testsuites/validation/tc-message-delete.c b/testsuites/validation/tc-message-delete.c new file mode 100644 index 0000000000..ca4f69d722 --- /dev/null +++ b/testsuites/validation/tc-message-delete.c @@ -0,0 +1,456 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsMessageReqDelete + */ + +/* + * 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 "tx-support.h" + +#include + +/** + * @defgroup RTEMSTestCaseRtemsMessageReqDelete spec:/rtems/message/req/delete + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsMessageReqDelete_Pre_Id_NoObj, + RtemsMessageReqDelete_Pre_Id_MsgQueue, + RtemsMessageReqDelete_Pre_Id_NA +} RtemsMessageReqDelete_Pre_Id; + +typedef enum { + RtemsMessageReqDelete_Post_Status_Ok, + RtemsMessageReqDelete_Post_Status_InvId, + RtemsMessageReqDelete_Post_Status_NA +} RtemsMessageReqDelete_Post_Status; + +typedef enum { + RtemsMessageReqDelete_Post_Name_Valid, + RtemsMessageReqDelete_Post_Name_Invalid, + RtemsMessageReqDelete_Post_Name_NA +} RtemsMessageReqDelete_Post_Name; + +typedef enum { + RtemsMessageReqDelete_Post_Flush_Yes, + RtemsMessageReqDelete_Post_Flush_No, + RtemsMessageReqDelete_Post_Flush_NA +} RtemsMessageReqDelete_Post_Flush; + +/** + * @brief Test context for spec:/rtems/message/req/delete test case. + */ +typedef struct { + rtems_id worker_id; + + rtems_id message_queue_id; + + uint32_t wait_done; + + uint32_t wait_expected; + + rtems_id id; + + rtems_status_code status; + + /** + * @brief This member defines the pre-condition states for the next action. + */ + size_t pcs[ 1 ]; + + /** + * @brief This member indicates if the test action loop is currently + * executed. + */ + bool in_action_loop; +} RtemsMessageReqDelete_Context; + +static RtemsMessageReqDelete_Context + RtemsMessageReqDelete_Instance; + +static const char * const RtemsMessageReqDelete_PreDesc_Id[] = { + "NoObj", + "MsgQueue", + "NA" +}; + +static const char * const * const RtemsMessageReqDelete_PreDesc[] = { + RtemsMessageReqDelete_PreDesc_Id, + NULL +}; + +#define NAME rtems_build_name( 'T', 'E', 'S', 'T' ) + +#define MAX_PENDING_MESSAGES 1 + +#define MAX_MESSAGE_SIZE 1 + +typedef RtemsMessageReqDelete_Context Context; + +static RTEMS_MESSAGE_QUEUE_BUFFER( MAX_MESSAGE_SIZE ) + buffers[ MAX_PENDING_MESSAGES ]; + +static void Worker( rtems_task_argument arg ) +{ + Context *ctx; + + ctx = (Context *) arg; + + while ( true ) { + rtems_status_code sc; + rtems_message_queue_config config; + char buffer[ MAX_MESSAGE_SIZE ]; + size_t size; + rtems_task_priority prio; + + memset( &config, 0, sizeof( config ) ); + config.name = NAME; + config.maximum_pending_messages = MAX_PENDING_MESSAGES; + config.maximum_message_size = MAX_MESSAGE_SIZE; + config.storage_size = sizeof( buffers ); + config.storage_area = buffers; + config.attributes = RTEMS_DEFAULT_ATTRIBUTES; + + T_eq_u32( ctx->message_queue_id, 0 ); + + sc = rtems_message_queue_construct( &config, &ctx->message_queue_id ); + T_rsc_success( sc ); + + size = SIZE_MAX; + sc = rtems_message_queue_receive( + ctx->message_queue_id, + buffer, + &size, + RTEMS_WAIT, + RTEMS_NO_TIMEOUT + ); + T_rsc( sc, RTEMS_OBJECT_WAS_DELETED ); + T_eq_sz( size, SIZE_MAX ); + + ++ctx->wait_done; + + prio = SetSelfPriority( PRIO_LOW ); + T_eq_u32( prio, PRIO_HIGH ); + } +} + +static void RtemsMessageReqDelete_Pre_Id_Prepare( + RtemsMessageReqDelete_Context *ctx, + RtemsMessageReqDelete_Pre_Id state +) +{ + switch ( state ) { + case RtemsMessageReqDelete_Pre_Id_NoObj: { + /* + * While the ``id`` parameter is not associated with a message queue. + */ + ctx->id = 0; + break; + } + + case RtemsMessageReqDelete_Pre_Id_MsgQueue: { + /* + * While the ``id`` parameter is associated with a message queue. + */ + ctx->id = ctx->message_queue_id; + break; + } + + case RtemsMessageReqDelete_Pre_Id_NA: + break; + } +} + +static void RtemsMessageReqDelete_Post_Status_Check( + RtemsMessageReqDelete_Context *ctx, + RtemsMessageReqDelete_Post_Status state +) +{ + switch ( state ) { + case RtemsMessageReqDelete_Post_Status_Ok: { + /* + * The return status of rtems_message_queue_delete() shall be + * RTEMS_SUCCESSFUL. + */ + ctx->message_queue_id = 0; + T_rsc_success( ctx->status ); + break; + } + + case RtemsMessageReqDelete_Post_Status_InvId: { + /* + * The return status of rtems_message_queue_delete() shall be + * RTEMS_INVALID_ID. + */ + T_rsc( ctx->status, RTEMS_INVALID_ID ); + break; + } + + case RtemsMessageReqDelete_Post_Status_NA: + break; + } +} + +static void RtemsMessageReqDelete_Post_Name_Check( + RtemsMessageReqDelete_Context *ctx, + RtemsMessageReqDelete_Post_Name state +) +{ + rtems_status_code sc; + rtems_id id; + + switch ( state ) { + case RtemsMessageReqDelete_Post_Name_Valid: { + /* + * The unique object name shall identify a message queue. + */ + id = 0; + sc = rtems_message_queue_ident( NAME, RTEMS_SEARCH_LOCAL_NODE, &id ); + T_rsc_success( sc ); + T_eq_u32( id, ctx->message_queue_id ); + break; + } + + case RtemsMessageReqDelete_Post_Name_Invalid: { + /* + * The unique object name shall not identify a message queue. + */ + sc = rtems_message_queue_ident( NAME, RTEMS_SEARCH_LOCAL_NODE, &id ); + T_rsc( sc, RTEMS_INVALID_NAME ); + break; + } + + case RtemsMessageReqDelete_Post_Name_NA: + break; + } +} + +static void RtemsMessageReqDelete_Post_Flush_Check( + RtemsMessageReqDelete_Context *ctx, + RtemsMessageReqDelete_Post_Flush state +) +{ + switch ( state ) { + case RtemsMessageReqDelete_Post_Flush_Yes: { + /* + * Tasks waiting at the message queue shall be unblocked. + */ + ++ctx->wait_expected; + T_eq_u32( ctx->wait_done, ctx->wait_expected ); + break; + } + + case RtemsMessageReqDelete_Post_Flush_No: { + /* + * Tasks waiting at the message queue shall remain blocked. + */ + T_eq_u32( ctx->wait_done, ctx->wait_expected ); + break; + } + + case RtemsMessageReqDelete_Post_Flush_NA: + break; + } +} + +static void RtemsMessageReqDelete_Setup( RtemsMessageReqDelete_Context *ctx ) +{ + memset( ctx, 0, sizeof( *ctx ) ); + SetSelfPriority( PRIO_NORMAL ); + ctx->worker_id = CreateTask( "WORK", PRIO_LOW ); + StartTask( ctx->worker_id, Worker, ctx ); +} + +static void RtemsMessageReqDelete_Setup_Wrap( void *arg ) +{ + RtemsMessageReqDelete_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsMessageReqDelete_Setup( ctx ); +} + +static void RtemsMessageReqDelete_Teardown( + RtemsMessageReqDelete_Context *ctx +) +{ + DeleteTask( ctx->worker_id ); + RestoreRunnerPriority(); +} + +static void RtemsMessageReqDelete_Teardown_Wrap( void *arg ) +{ + RtemsMessageReqDelete_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsMessageReqDelete_Teardown( ctx ); +} + +static void RtemsMessageReqDelete_Prepare( RtemsMessageReqDelete_Context *ctx ) +{ + rtems_task_priority prio; + + prio = SetPriority( ctx->worker_id, PRIO_HIGH ); + T_true( prio == PRIO_LOW || prio == PRIO_HIGH ); +} + +static void RtemsMessageReqDelete_Action( RtemsMessageReqDelete_Context *ctx ) +{ + ctx->status = rtems_message_queue_delete( ctx->id ); +} + +static void RtemsMessageReqDelete_Cleanup( RtemsMessageReqDelete_Context *ctx ) +{ + if ( ctx->message_queue_id != 0 ) { + rtems_status_code sc; + + sc = rtems_message_queue_delete( ctx->message_queue_id ); + T_rsc_success( sc ); + + ++ctx->wait_expected; + T_eq_u32( ctx->wait_done, ctx->wait_expected ); + + ctx->message_queue_id = 0; + } +} + +typedef struct { + uint8_t Skip : 1; + uint8_t Pre_Id_NA : 1; + uint8_t Post_Status : 2; + uint8_t Post_Name : 2; + uint8_t Post_Flush : 2; +} RtemsMessageReqDelete_Entry; + +static const RtemsMessageReqDelete_Entry +RtemsMessageReqDelete_Entries[] = { + { 0, 0, RtemsMessageReqDelete_Post_Status_InvId, + RtemsMessageReqDelete_Post_Name_Valid, RtemsMessageReqDelete_Post_Flush_No }, + { 0, 0, RtemsMessageReqDelete_Post_Status_Ok, + RtemsMessageReqDelete_Post_Name_Invalid, + RtemsMessageReqDelete_Post_Flush_Yes } +}; + +static const uint8_t +RtemsMessageReqDelete_Map[] = { + 0, 1 +}; + +static size_t RtemsMessageReqDelete_Scope( void *arg, char *buf, size_t n ) +{ + RtemsMessageReqDelete_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsMessageReqDelete_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsMessageReqDelete_Fixture = { + .setup = RtemsMessageReqDelete_Setup_Wrap, + .stop = NULL, + .teardown = RtemsMessageReqDelete_Teardown_Wrap, + .scope = RtemsMessageReqDelete_Scope, + .initial_context = &RtemsMessageReqDelete_Instance +}; + +static inline RtemsMessageReqDelete_Entry RtemsMessageReqDelete_GetEntry( + size_t index +) +{ + return RtemsMessageReqDelete_Entries[ + RtemsMessageReqDelete_Map[ index ] + ]; +} + +/** + * @fn void T_case_body_RtemsMessageReqDelete( void ) + */ +T_TEST_CASE_FIXTURE( RtemsMessageReqDelete, &RtemsMessageReqDelete_Fixture ) +{ + RtemsMessageReqDelete_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsMessageReqDelete_Pre_Id_NoObj; + ctx->pcs[ 0 ] < RtemsMessageReqDelete_Pre_Id_NA; + ++ctx->pcs[ 0 ] + ) { + RtemsMessageReqDelete_Entry entry; + + entry = RtemsMessageReqDelete_GetEntry( index ); + ++index; + + RtemsMessageReqDelete_Prepare( ctx ); + RtemsMessageReqDelete_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsMessageReqDelete_Action( ctx ); + RtemsMessageReqDelete_Post_Status_Check( ctx, entry.Post_Status ); + RtemsMessageReqDelete_Post_Name_Check( ctx, entry.Post_Name ); + RtemsMessageReqDelete_Post_Flush_Check( ctx, entry.Post_Flush ); + RtemsMessageReqDelete_Cleanup( ctx ); + } +} + +/** @} */ -- cgit v1.2.3