/* SPDX-License-Identifier: BSD-2-Clause */ /** * @file * * @ingroup RTEMSTestCaseRtemsSchedulerReqRemoveProcessor */ /* * 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 "ts-config.h" #include "tx-support.h" #include /** * @defgroup RTEMSTestCaseRtemsSchedulerReqRemoveProcessor \ * spec:/rtems/scheduler/req/remove-processor * * @ingroup RTEMSTestSuiteTestsuitesValidation0 * * @{ */ typedef enum { RtemsSchedulerReqRemoveProcessor_Pre_CPUState_Idle, RtemsSchedulerReqRemoveProcessor_Pre_CPUState_InUse, RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NotOwned, RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NA } RtemsSchedulerReqRemoveProcessor_Pre_CPUState; typedef enum { RtemsSchedulerReqRemoveProcessor_Pre_Id_Invalid, RtemsSchedulerReqRemoveProcessor_Pre_Id_Scheduler, RtemsSchedulerReqRemoveProcessor_Pre_Id_NA } RtemsSchedulerReqRemoveProcessor_Pre_Id; typedef enum { RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Valid, RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Invalid, RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_NA } RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex; typedef enum { RtemsSchedulerReqRemoveProcessor_Post_Status_Ok, RtemsSchedulerReqRemoveProcessor_Post_Status_InvId, RtemsSchedulerReqRemoveProcessor_Post_Status_InvNum, RtemsSchedulerReqRemoveProcessor_Post_Status_InUse, RtemsSchedulerReqRemoveProcessor_Post_Status_NA } RtemsSchedulerReqRemoveProcessor_Post_Status; typedef enum { RtemsSchedulerReqRemoveProcessor_Post_Removed_Yes, RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop, RtemsSchedulerReqRemoveProcessor_Post_Removed_NA } RtemsSchedulerReqRemoveProcessor_Post_Removed; /** * @brief Test context for spec:/rtems/scheduler/req/remove-processor test * case. */ typedef struct { /** * @brief This member specifies the scheduler used to add the processor. */ rtems_id scheduler_id; /** * @brief This member contains the identifier of scheduler A. */ rtems_id scheduler_a_id; /** * @brief This member contains the identifier of scheduler B. */ rtems_id scheduler_b_id; /** * @brief This member specifies the processor to remove. */ uint32_t cpu_to_remove; /** * @brief This member provides the scheduler operation records. */ T_scheduler_log_2 scheduler_log;; /** * @brief This member contains the return value of the * rtems_scheduler_remove_processor() call. */ rtems_status_code status; /** * @brief This member specifies if the ``scheduler_id`` parameter value. */ rtems_id id; /** * @brief This member specifies if the ``cpu_index`` parameter value. */ uint32_t cpu_index; /** * @brief This member defines the pre-condition states for the next action. */ size_t pcs[ 3 ]; /** * @brief This member indicates if the test action loop is currently * executed. */ bool in_action_loop; } RtemsSchedulerReqRemoveProcessor_Context; static RtemsSchedulerReqRemoveProcessor_Context RtemsSchedulerReqRemoveProcessor_Instance; static const char * const RtemsSchedulerReqRemoveProcessor_PreDesc_CPUState[] = { "Idle", "InUse", "NotOwned", "NA" }; static const char * const RtemsSchedulerReqRemoveProcessor_PreDesc_Id[] = { "Invalid", "Scheduler", "NA" }; static const char * const RtemsSchedulerReqRemoveProcessor_PreDesc_CPUIndex[] = { "Valid", "Invalid", "NA" }; static const char * const * const RtemsSchedulerReqRemoveProcessor_PreDesc[] = { RtemsSchedulerReqRemoveProcessor_PreDesc_CPUState, RtemsSchedulerReqRemoveProcessor_PreDesc_Id, RtemsSchedulerReqRemoveProcessor_PreDesc_CPUIndex, NULL }; static void RtemsSchedulerReqRemoveProcessor_Pre_CPUState_Prepare( RtemsSchedulerReqRemoveProcessor_Context *ctx, RtemsSchedulerReqRemoveProcessor_Pre_CPUState state ) { ctx->scheduler_id = ctx->scheduler_a_id; ctx->cpu_to_remove = 0; switch ( state ) { case RtemsSchedulerReqRemoveProcessor_Pre_CPUState_Idle: { /* * While the processor associated with the ``cpu_index`` parameter is * owned by the scheduler specified by the ``scheduler_id`` parameter, * while no task exists which uses the scheduler as its home scheduler * and the affinity set of this task would require the processor * specified by the ``cpu_index`` parameter. */ ctx->scheduler_id = ctx->scheduler_b_id; ctx->cpu_to_remove = 1; break; } case RtemsSchedulerReqRemoveProcessor_Pre_CPUState_InUse: { /* * While the processor associated with the ``cpu_index`` parameter is * owned by the scheduler specified by the ``scheduler_id`` parameter, * while the scheduler is used by at least one task as its home scheduler * and the affinity set of this task requires the processor specified by * the ``cpu_index`` parameter. */ /* Set by prologue */ break; } case RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NotOwned: { /* * While the processor associated with the ``cpu_index`` parameter is not * owned by the scheduler specified by the ``scheduler_id`` parameter. */ ctx->scheduler_id = ctx->scheduler_a_id; ctx->cpu_to_remove = 1; break; } case RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NA: break; } } static void RtemsSchedulerReqRemoveProcessor_Pre_Id_Prepare( RtemsSchedulerReqRemoveProcessor_Context *ctx, RtemsSchedulerReqRemoveProcessor_Pre_Id state ) { switch ( state ) { case RtemsSchedulerReqRemoveProcessor_Pre_Id_Invalid: { /* * While the ``scheduler_id`` parameter is not associated with a * scheduler. */ ctx->id = INVALID_ID; break; } case RtemsSchedulerReqRemoveProcessor_Pre_Id_Scheduler: { /* * While the ``scheduler_id`` parameter is associated with a scheduler. */ ctx->id = ctx->scheduler_id; break; } case RtemsSchedulerReqRemoveProcessor_Pre_Id_NA: break; } } static void RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Prepare( RtemsSchedulerReqRemoveProcessor_Context *ctx, RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex state ) { switch ( state ) { case RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Valid: { /* * While the ``cpu_index`` parameter is less than the configured * processor maximum. */ ctx->cpu_index = ctx->cpu_to_remove; break; } case RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Invalid: { /* * While the ``cpu_index`` parameter is greater than or equal to the * configured processor maximum. */ ctx->cpu_index = rtems_configuration_get_maximum_processors(); break; } case RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_NA: break; } } static void RtemsSchedulerReqRemoveProcessor_Post_Status_Check( RtemsSchedulerReqRemoveProcessor_Context *ctx, RtemsSchedulerReqRemoveProcessor_Post_Status state ) { switch ( state ) { case RtemsSchedulerReqRemoveProcessor_Post_Status_Ok: { /* * The return status of rtems_scheduler_remove_processor() shall be * RTEMS_SUCCESSFUL. */ T_rsc_success( ctx->status ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Status_InvId: { /* * The return status of rtems_scheduler_remove_processor() shall be * RTEMS_INVALID_ID. */ T_rsc( ctx->status, RTEMS_INVALID_ID ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Status_InvNum: { /* * The return status of rtems_scheduler_remove_processor() shall be * RTEMS_INVALID_NUMBER. */ T_rsc( ctx->status, RTEMS_INVALID_NUMBER ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Status_InUse: { /* * The return status of rtems_scheduler_remove_processor() shall be * RTEMS_RESOURCE_IN_USE. */ T_rsc( ctx->status, RTEMS_RESOURCE_IN_USE ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Status_NA: break; } } static void RtemsSchedulerReqRemoveProcessor_Post_Removed_Check( RtemsSchedulerReqRemoveProcessor_Context *ctx, RtemsSchedulerReqRemoveProcessor_Post_Removed state ) { switch ( state ) { case RtemsSchedulerReqRemoveProcessor_Post_Removed_Yes: { /* * The processor specified by the ``cpu_index`` parameter shall be * removed from the scheduler specified by the ``scheduler_id`` by the * rtems_scheduler_remove_processor() call. */ T_eq_sz( ctx->scheduler_log.header.recorded, 1 ); T_eq_int( ctx->scheduler_log.events[ 0 ].operation, T_SCHEDULER_REMOVE_PROCESSOR ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop: { /* * No processor shall be removed from a scheduler by the * rtems_scheduler_remove_processor() call. */ T_eq_sz( ctx->scheduler_log.header.recorded, 0 ); break; } case RtemsSchedulerReqRemoveProcessor_Post_Removed_NA: break; } } static void RtemsSchedulerReqRemoveProcessor_Setup( RtemsSchedulerReqRemoveProcessor_Context *ctx ) { rtems_status_code sc; sc = rtems_scheduler_ident( TEST_SCHEDULER_A_NAME, &ctx->scheduler_a_id ); T_rsc_success( sc ); #if defined(RTEMS_SMP) sc = rtems_scheduler_ident( TEST_SCHEDULER_B_NAME, &ctx->scheduler_b_id ); T_rsc_success( sc ); #else ctx->scheduler_b_id = INVALID_ID; #endif } static void RtemsSchedulerReqRemoveProcessor_Setup_Wrap( void *arg ) { RtemsSchedulerReqRemoveProcessor_Context *ctx; ctx = arg; ctx->in_action_loop = false; RtemsSchedulerReqRemoveProcessor_Setup( ctx ); } static void RtemsSchedulerReqRemoveProcessor_Action( RtemsSchedulerReqRemoveProcessor_Context *ctx ) { T_scheduler_log *log; log = T_scheduler_record_2( &ctx->scheduler_log ); T_null( log ); ctx->status = rtems_scheduler_remove_processor( ctx->id, ctx->cpu_index ); log = T_scheduler_record( NULL ); T_eq_ptr( &log->header, &ctx->scheduler_log.header ); } static void RtemsSchedulerReqRemoveProcessor_Cleanup( RtemsSchedulerReqRemoveProcessor_Context *ctx ) { #if defined(RTEMS_SMP) if ( ctx->status == RTEMS_SUCCESSFUL ) { rtems_status_code sc; sc = rtems_scheduler_add_processor( ctx->scheduler_id, ctx->cpu_to_remove ); T_rsc_success( sc ); } #endif } typedef struct { uint16_t Skip : 1; uint16_t Pre_CPUState_NA : 1; uint16_t Pre_Id_NA : 1; uint16_t Pre_CPUIndex_NA : 1; uint16_t Post_Status : 3; uint16_t Post_Removed : 2; } RtemsSchedulerReqRemoveProcessor_Entry; static const RtemsSchedulerReqRemoveProcessor_Entry RtemsSchedulerReqRemoveProcessor_Entries[] = { { 0, 1, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_InvId, RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop }, { 0, 1, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_InvNum, RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop }, #if defined(RTEMS_SMP) { 0, 0, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_Ok, RtemsSchedulerReqRemoveProcessor_Post_Removed_Yes }, #else { 1, 0, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_NA, RtemsSchedulerReqRemoveProcessor_Post_Removed_NA }, #endif { 0, 0, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_InUse, RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop }, #if defined(RTEMS_SMP) { 0, 0, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_InvNum, RtemsSchedulerReqRemoveProcessor_Post_Removed_Nop } #else { 1, 0, 0, 0, RtemsSchedulerReqRemoveProcessor_Post_Status_NA, RtemsSchedulerReqRemoveProcessor_Post_Removed_NA } #endif }; static const uint8_t RtemsSchedulerReqRemoveProcessor_Map[] = { 0, 0, 2, 1, 0, 0, 3, 1, 0, 0, 4, 1 }; static size_t RtemsSchedulerReqRemoveProcessor_Scope( void *arg, char *buf, size_t n ) { RtemsSchedulerReqRemoveProcessor_Context *ctx; ctx = arg; if ( ctx->in_action_loop ) { return T_get_scope( RtemsSchedulerReqRemoveProcessor_PreDesc, buf, n, ctx->pcs ); } return 0; } static T_fixture RtemsSchedulerReqRemoveProcessor_Fixture = { .setup = RtemsSchedulerReqRemoveProcessor_Setup_Wrap, .stop = NULL, .teardown = NULL, .scope = RtemsSchedulerReqRemoveProcessor_Scope, .initial_context = &RtemsSchedulerReqRemoveProcessor_Instance }; static inline RtemsSchedulerReqRemoveProcessor_Entry RtemsSchedulerReqRemoveProcessor_GetEntry( size_t index ) { return RtemsSchedulerReqRemoveProcessor_Entries[ RtemsSchedulerReqRemoveProcessor_Map[ index ] ]; } /** * @fn void T_case_body_RtemsSchedulerReqRemoveProcessor( void ) */ T_TEST_CASE_FIXTURE( RtemsSchedulerReqRemoveProcessor, &RtemsSchedulerReqRemoveProcessor_Fixture ) { RtemsSchedulerReqRemoveProcessor_Context *ctx; size_t index; ctx = T_fixture_context(); ctx->in_action_loop = true; index = 0; for ( ctx->pcs[ 0 ] = RtemsSchedulerReqRemoveProcessor_Pre_CPUState_Idle; ctx->pcs[ 0 ] < RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NA; ++ctx->pcs[ 0 ] ) { for ( ctx->pcs[ 1 ] = RtemsSchedulerReqRemoveProcessor_Pre_Id_Invalid; ctx->pcs[ 1 ] < RtemsSchedulerReqRemoveProcessor_Pre_Id_NA; ++ctx->pcs[ 1 ] ) { for ( ctx->pcs[ 2 ] = RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Valid; ctx->pcs[ 2 ] < RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_NA; ++ctx->pcs[ 2 ] ) { RtemsSchedulerReqRemoveProcessor_Entry entry; size_t pcs[ 3 ]; entry = RtemsSchedulerReqRemoveProcessor_GetEntry( index ); ++index; if ( entry.Skip ) { continue; } memcpy( pcs, ctx->pcs, sizeof( pcs ) ); if ( entry.Pre_CPUState_NA ) { ctx->pcs[ 0 ] = RtemsSchedulerReqRemoveProcessor_Pre_CPUState_NA; } RtemsSchedulerReqRemoveProcessor_Pre_CPUState_Prepare( ctx, ctx->pcs[ 0 ] ); RtemsSchedulerReqRemoveProcessor_Pre_Id_Prepare( ctx, ctx->pcs[ 1 ] ); RtemsSchedulerReqRemoveProcessor_Pre_CPUIndex_Prepare( ctx, ctx->pcs[ 2 ] ); RtemsSchedulerReqRemoveProcessor_Action( ctx ); RtemsSchedulerReqRemoveProcessor_Post_Status_Check( ctx, entry.Post_Status ); RtemsSchedulerReqRemoveProcessor_Post_Removed_Check( ctx, entry.Post_Removed ); RtemsSchedulerReqRemoveProcessor_Cleanup( ctx ); memcpy( ctx->pcs, pcs, sizeof( ctx->pcs ) ); } } } } /** @} */