diff options
Diffstat (limited to 'testsuites/validation/tc-task-ident.c')
-rw-r--r-- | testsuites/validation/tc-task-ident.c | 338 |
1 files changed, 338 insertions, 0 deletions
diff --git a/testsuites/validation/tc-task-ident.c b/testsuites/validation/tc-task-ident.c new file mode 100644 index 0000000000..a084493a07 --- /dev/null +++ b/testsuites/validation/tc-task-ident.c @@ -0,0 +1,338 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsTaskReqIdent + */ + +/* + * Copyright (C) 2020 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 "tr-object-ident.h" + +#include <rtems/test.h> + +/** + * @defgroup RTEMSTestCaseRtemsTaskReqIdent spec:/rtems/task/req/ident + * + * @ingroup RTEMSTestSuiteTestsuitesValidation0 + * + * @{ + */ + +typedef enum { + RtemsTaskReqIdent_Pre_Name_Self, + RtemsTaskReqIdent_Pre_Name_NotSelf, + RtemsTaskReqIdent_Pre_Name_NA +} RtemsTaskReqIdent_Pre_Name; + +typedef enum { + RtemsTaskReqIdent_Post_Status_OkAndSelfId, + RtemsTaskReqIdent_Post_Status_Skip, + RtemsTaskReqIdent_Post_Status_NA +} RtemsTaskReqIdent_Post_Status; + +/** + * @brief Test context for spec:/rtems/task/req/ident test case. + */ +typedef struct { + rtems_status_code status; + + rtems_id *id; + + rtems_id id_value; + + rtems_id id_local_object; + + /** + * @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; +} RtemsTaskReqIdent_Context; + +static RtemsTaskReqIdent_Context + RtemsTaskReqIdent_Instance; + +static const char * const RtemsTaskReqIdent_PreDesc_Name[] = { + "Self", + "NotSelf", + "NA" +}; + +static const char * const * const RtemsTaskReqIdent_PreDesc[] = { + RtemsTaskReqIdent_PreDesc_Name, + NULL +}; + +static rtems_status_code ClassicTaskIdentAction( + rtems_name name, + uint32_t node, + rtems_id *id +) +{ + return rtems_task_ident( name, node, id ); +} + +#define TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES + +#define MAX_TLS_SIZE RTEMS_ALIGN_UP( 64, RTEMS_TASK_STORAGE_ALIGNMENT ) + +RTEMS_ALIGNED( RTEMS_TASK_STORAGE_ALIGNMENT ) +static char ClassicTaskIdentStorage[ + RTEMS_TASK_STORAGE_SIZE( + MAX_TLS_SIZE + RTEMS_MINIMUM_STACK_SIZE, + TASK_ATTRIBUTES + ) +]; + +static const rtems_task_config ClassicTaskIdentConfig = { + .name = ClassicObjectIdentName, + .initial_priority = 1, + .storage_area = ClassicTaskIdentStorage, + .storage_size = sizeof( ClassicTaskIdentStorage ), + .maximum_thread_local_storage_size = MAX_TLS_SIZE, + .initial_modes = RTEMS_DEFAULT_MODES, + .attributes = TASK_ATTRIBUTES +}; + +static void RtemsTaskReqIdent_Pre_Name_Prepare( + RtemsTaskReqIdent_Context *ctx, + RtemsTaskReqIdent_Pre_Name state +) +{ + switch ( state ) { + case RtemsTaskReqIdent_Pre_Name_Self: { + /* + * The ``name`` parameter shall be rtems_task_self(). + */ + ctx->id_value = 0xffffffff; + ctx->id = &ctx->id_value; + break; + } + + case RtemsTaskReqIdent_Pre_Name_NotSelf: { + /* + * When the ``name`` is not rtems_task_self() or ``id`` parameter is + * NULL, the behaviour of rtems_task_ident() shall be specified by + * /rtems/req/ident. + */ + ctx->id = NULL; + /* Preparation performed by RtemsReqIdent_Run() */ + break; + } + + case RtemsTaskReqIdent_Pre_Name_NA: + break; + } +} + +static void RtemsTaskReqIdent_Post_Status_Check( + RtemsTaskReqIdent_Context *ctx, + RtemsTaskReqIdent_Post_Status state +) +{ + switch ( state ) { + case RtemsTaskReqIdent_Post_Status_OkAndSelfId: { + /* + * The return status of rtems_task_ident() shall be RTEMS_SUCCESSFUL. + * The value of the object identifier referenced by the ``name`` + * parameter shall be the identifier of the executing thread. + */ + T_rsc( ctx->status, RTEMS_SUCCESSFUL ); + T_eq_ptr( ctx->id, &ctx->id_value ); + T_eq_u32( ctx->id_value, rtems_task_self() ); + break; + } + + case RtemsTaskReqIdent_Post_Status_Skip: { + /* + * There is no status to validate. + */ + /* Checks performed by RtemsReqIdent_Run() */ + break; + } + + case RtemsTaskReqIdent_Post_Status_NA: + break; + } +} + +static void RtemsTaskReqIdent_Setup( RtemsTaskReqIdent_Context *ctx ) +{ + rtems_status_code sc; + + sc = rtems_task_construct( + &ClassicTaskIdentConfig, + &ctx->id_local_object + ); + T_assert_rsc_success( sc ); +} + +static void RtemsTaskReqIdent_Setup_Wrap( void *arg ) +{ + RtemsTaskReqIdent_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsTaskReqIdent_Setup( ctx ); +} + +static void RtemsTaskReqIdent_Teardown( RtemsTaskReqIdent_Context *ctx ) +{ + if ( ctx->id_local_object != 0 ) { + rtems_status_code sc; + + sc = rtems_task_delete( ctx->id_local_object ); + T_rsc_success( sc ); + } +} + +static void RtemsTaskReqIdent_Teardown_Wrap( void *arg ) +{ + RtemsTaskReqIdent_Context *ctx; + + ctx = arg; + ctx->in_action_loop = false; + RtemsTaskReqIdent_Teardown( ctx ); +} + +static size_t RtemsTaskReqIdent_Scope( void *arg, char *buf, size_t n ) +{ + RtemsTaskReqIdent_Context *ctx; + + ctx = arg; + + if ( ctx->in_action_loop ) { + return T_get_scope( RtemsTaskReqIdent_PreDesc, buf, n, ctx->pcs ); + } + + return 0; +} + +static T_fixture RtemsTaskReqIdent_Fixture = { + .setup = RtemsTaskReqIdent_Setup_Wrap, + .stop = NULL, + .teardown = RtemsTaskReqIdent_Teardown_Wrap, + .scope = RtemsTaskReqIdent_Scope, + .initial_context = &RtemsTaskReqIdent_Instance +}; + +static const uint8_t RtemsTaskReqIdent_TransitionMap[][ 1 ] = { + { + RtemsTaskReqIdent_Post_Status_OkAndSelfId + }, { + RtemsTaskReqIdent_Post_Status_Skip + } +}; + +static const struct { + uint8_t Skip : 1; + uint8_t Pre_Name_NA : 1; +} RtemsTaskReqIdent_TransitionInfo[] = { + { + 0, 0 + }, { + 0, 0 + } +}; + +static void RtemsTaskReqIdent_Action( RtemsTaskReqIdent_Context *ctx ) +{ + if ( ctx->id != NULL ) { + ctx->status = rtems_task_ident( RTEMS_SELF, 0xdeadbeef, ctx->id ); + } else { + RtemsReqIdent_Run( + ctx->id_local_object, + ClassicTaskIdentAction + ); + } +} + +/** + * @fn void T_case_body_RtemsTaskReqIdent( void ) + */ +T_TEST_CASE_FIXTURE( RtemsTaskReqIdent, &RtemsTaskReqIdent_Fixture ) +{ + RtemsTaskReqIdent_Context *ctx; + size_t index; + + ctx = T_fixture_context(); + ctx->in_action_loop = true; + index = 0; + + for ( + ctx->pcs[ 0 ] = RtemsTaskReqIdent_Pre_Name_Self; + ctx->pcs[ 0 ] < RtemsTaskReqIdent_Pre_Name_NA; + ++ctx->pcs[ 0 ] + ) { + if ( RtemsTaskReqIdent_TransitionInfo[ index ].Pre_Name_NA ) { + ctx->pcs[ 0 ] = RtemsTaskReqIdent_Pre_Name_NA; + index += ( RtemsTaskReqIdent_Pre_Name_NA - 1 ); + } + + if ( RtemsTaskReqIdent_TransitionInfo[ index ].Skip ) { + ++index; + continue; + } + + RtemsTaskReqIdent_Pre_Name_Prepare( ctx, ctx->pcs[ 0 ] ); + RtemsTaskReqIdent_Action( ctx ); + RtemsTaskReqIdent_Post_Status_Check( + ctx, + RtemsTaskReqIdent_TransitionMap[ index ][ 0 ] + ); + ++index; + } +} + +/** @} */ |