Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:52

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsSchedulerReqIdent
0007  */
0008 
0009 /*
0010  * Copyright (C) 2021 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
0049  */
0050 
0051 #ifdef HAVE_CONFIG_H
0052 #include "config.h"
0053 #endif
0054 
0055 #include <rtems.h>
0056 
0057 #include "ts-config.h"
0058 #include "tx-support.h"
0059 
0060 #include <rtems/test.h>
0061 
0062 /**
0063  * @defgroup RtemsSchedulerReqIdent spec:/rtems/scheduler/req/ident
0064  *
0065  * @ingroup TestsuitesValidationNoClock0
0066  *
0067  * @{
0068  */
0069 
0070 typedef enum {
0071   RtemsSchedulerReqIdent_Pre_Name_Invalid,
0072   RtemsSchedulerReqIdent_Pre_Name_Valid,
0073   RtemsSchedulerReqIdent_Pre_Name_NA
0074 } RtemsSchedulerReqIdent_Pre_Name;
0075 
0076 typedef enum {
0077   RtemsSchedulerReqIdent_Pre_Id_Valid,
0078   RtemsSchedulerReqIdent_Pre_Id_Null,
0079   RtemsSchedulerReqIdent_Pre_Id_NA
0080 } RtemsSchedulerReqIdent_Pre_Id;
0081 
0082 typedef enum {
0083   RtemsSchedulerReqIdent_Post_Status_Ok,
0084   RtemsSchedulerReqIdent_Post_Status_InvAddr,
0085   RtemsSchedulerReqIdent_Post_Status_InvName,
0086   RtemsSchedulerReqIdent_Post_Status_NA
0087 } RtemsSchedulerReqIdent_Post_Status;
0088 
0089 typedef enum {
0090   RtemsSchedulerReqIdent_Post_IdVar_Set,
0091   RtemsSchedulerReqIdent_Post_IdVar_Nop,
0092   RtemsSchedulerReqIdent_Post_IdVar_NA
0093 } RtemsSchedulerReqIdent_Post_IdVar;
0094 
0095 typedef struct {
0096   uint8_t Skip : 1;
0097   uint8_t Pre_Name_NA : 1;
0098   uint8_t Pre_Id_NA : 1;
0099   uint8_t Post_Status : 2;
0100   uint8_t Post_IdVar : 2;
0101 } RtemsSchedulerReqIdent_Entry;
0102 
0103 /**
0104  * @brief Test context for spec:/rtems/scheduler/req/ident test case.
0105  */
0106 typedef struct {
0107   /**
0108    * @brief This member provides the object referenced by the ``id`` parameter.
0109    */
0110   rtems_id id_value;
0111 
0112   /**
0113    * @brief This member contains the return value of the
0114    *   rtems_scheduler_ident() call.
0115    */
0116   rtems_status_code status;
0117 
0118   /**
0119    * @brief This member specifies if the ``name`` parameter value.
0120    */
0121   rtems_name name;
0122 
0123   /**
0124    * @brief This member specifies if the ``id`` parameter value.
0125    */
0126   rtems_id *id;
0127 
0128   struct {
0129     /**
0130      * @brief This member defines the pre-condition states for the next action.
0131      */
0132     size_t pcs[ 2 ];
0133 
0134     /**
0135      * @brief If this member is true, then the test action loop is executed.
0136      */
0137     bool in_action_loop;
0138 
0139     /**
0140      * @brief This member contains the next transition map index.
0141      */
0142     size_t index;
0143 
0144     /**
0145      * @brief This member contains the current transition map entry.
0146      */
0147     RtemsSchedulerReqIdent_Entry entry;
0148 
0149     /**
0150      * @brief If this member is true, then the current transition variant
0151      *   should be skipped.
0152      */
0153     bool skip;
0154   } Map;
0155 } RtemsSchedulerReqIdent_Context;
0156 
0157 static RtemsSchedulerReqIdent_Context
0158   RtemsSchedulerReqIdent_Instance;
0159 
0160 static const char * const RtemsSchedulerReqIdent_PreDesc_Name[] = {
0161   "Invalid",
0162   "Valid",
0163   "NA"
0164 };
0165 
0166 static const char * const RtemsSchedulerReqIdent_PreDesc_Id[] = {
0167   "Valid",
0168   "Null",
0169   "NA"
0170 };
0171 
0172 static const char * const * const RtemsSchedulerReqIdent_PreDesc[] = {
0173   RtemsSchedulerReqIdent_PreDesc_Name,
0174   RtemsSchedulerReqIdent_PreDesc_Id,
0175   NULL
0176 };
0177 
0178 static void RtemsSchedulerReqIdent_Pre_Name_Prepare(
0179   RtemsSchedulerReqIdent_Context *ctx,
0180   RtemsSchedulerReqIdent_Pre_Name state
0181 )
0182 {
0183   switch ( state ) {
0184     case RtemsSchedulerReqIdent_Pre_Name_Invalid: {
0185       /*
0186        * While the ``name`` parameter is not associated with a scheduler.
0187        */
0188       ctx->name = 0;
0189       break;
0190     }
0191 
0192     case RtemsSchedulerReqIdent_Pre_Name_Valid: {
0193       /*
0194        * While the ``name`` parameter is associated with a scheduler.
0195        */
0196       ctx->name = TEST_SCHEDULER_A_NAME;
0197       break;
0198     }
0199 
0200     case RtemsSchedulerReqIdent_Pre_Name_NA:
0201       break;
0202   }
0203 }
0204 
0205 static void RtemsSchedulerReqIdent_Pre_Id_Prepare(
0206   RtemsSchedulerReqIdent_Context *ctx,
0207   RtemsSchedulerReqIdent_Pre_Id   state
0208 )
0209 {
0210   switch ( state ) {
0211     case RtemsSchedulerReqIdent_Pre_Id_Valid: {
0212       /*
0213        * While the ``id`` parameter references an object of type rtems_id.
0214        */
0215       ctx->id = &ctx->id_value;
0216       break;
0217     }
0218 
0219     case RtemsSchedulerReqIdent_Pre_Id_Null: {
0220       /*
0221        * While the ``id`` parameter is equal to NULL.
0222        */
0223       ctx->id = NULL;
0224       break;
0225     }
0226 
0227     case RtemsSchedulerReqIdent_Pre_Id_NA:
0228       break;
0229   }
0230 }
0231 
0232 static void RtemsSchedulerReqIdent_Post_Status_Check(
0233   RtemsSchedulerReqIdent_Context    *ctx,
0234   RtemsSchedulerReqIdent_Post_Status state
0235 )
0236 {
0237   switch ( state ) {
0238     case RtemsSchedulerReqIdent_Post_Status_Ok: {
0239       /*
0240        * The return status of rtems_scheduler_ident() shall be
0241        * RTEMS_SUCCESSFUL.
0242        */
0243       T_rsc_success( ctx->status );
0244       break;
0245     }
0246 
0247     case RtemsSchedulerReqIdent_Post_Status_InvAddr: {
0248       /*
0249        * The return status of rtems_scheduler_ident() shall be
0250        * RTEMS_INVALID_ADDRESS.
0251        */
0252       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0253       break;
0254     }
0255 
0256     case RtemsSchedulerReqIdent_Post_Status_InvName: {
0257       /*
0258        * The return status of rtems_scheduler_ident() shall be
0259        * RTEMS_INVALID_NAME.
0260        */
0261       T_rsc( ctx->status, RTEMS_INVALID_NAME );
0262       break;
0263     }
0264 
0265     case RtemsSchedulerReqIdent_Post_Status_NA:
0266       break;
0267   }
0268 }
0269 
0270 static void RtemsSchedulerReqIdent_Post_IdVar_Check(
0271   RtemsSchedulerReqIdent_Context   *ctx,
0272   RtemsSchedulerReqIdent_Post_IdVar state
0273 )
0274 {
0275   switch ( state ) {
0276     case RtemsSchedulerReqIdent_Post_IdVar_Set: {
0277       /*
0278        * The value of the object referenced by the ``id`` parameter shall be
0279        * set to the identifier of the scheduler with the lowest scheduler index
0280        * and a name equal to the ``name`` parameter after the return of the
0281        * rtems_scheduler_ident() call.
0282        */
0283       T_eq_ptr( ctx->id, &ctx->id_value );
0284       T_eq_u32( ctx->id_value, 0x0f010001 );
0285       break;
0286     }
0287 
0288     case RtemsSchedulerReqIdent_Post_IdVar_Nop: {
0289       /*
0290        * Objects referenced by the ``id`` parameter in past calls to
0291        * rtems_scheduler_ident() shall not be accessed by the
0292        * rtems_scheduler_ident() call.
0293        */
0294       T_eq_u32( ctx->id_value, INVALID_ID );
0295       break;
0296     }
0297 
0298     case RtemsSchedulerReqIdent_Post_IdVar_NA:
0299       break;
0300   }
0301 }
0302 
0303 static void RtemsSchedulerReqIdent_Prepare(
0304   RtemsSchedulerReqIdent_Context *ctx
0305 )
0306 {
0307   ctx->id_value = INVALID_ID;
0308 }
0309 
0310 static void RtemsSchedulerReqIdent_Action(
0311   RtemsSchedulerReqIdent_Context *ctx
0312 )
0313 {
0314   ctx->status = rtems_scheduler_ident( ctx->name, ctx->id );
0315 }
0316 
0317 static const RtemsSchedulerReqIdent_Entry
0318 RtemsSchedulerReqIdent_Entries[] = {
0319   { 0, 0, 0, RtemsSchedulerReqIdent_Post_Status_InvAddr,
0320     RtemsSchedulerReqIdent_Post_IdVar_Nop },
0321   { 0, 0, 0, RtemsSchedulerReqIdent_Post_Status_InvName,
0322     RtemsSchedulerReqIdent_Post_IdVar_Nop },
0323   { 0, 0, 0, RtemsSchedulerReqIdent_Post_Status_Ok,
0324     RtemsSchedulerReqIdent_Post_IdVar_Set }
0325 };
0326 
0327 static const uint8_t
0328 RtemsSchedulerReqIdent_Map[] = {
0329   1, 0, 2, 0
0330 };
0331 
0332 static size_t RtemsSchedulerReqIdent_Scope( void *arg, char *buf, size_t n )
0333 {
0334   RtemsSchedulerReqIdent_Context *ctx;
0335 
0336   ctx = arg;
0337 
0338   if ( ctx->Map.in_action_loop ) {
0339     return T_get_scope( RtemsSchedulerReqIdent_PreDesc, buf, n, ctx->Map.pcs );
0340   }
0341 
0342   return 0;
0343 }
0344 
0345 static T_fixture RtemsSchedulerReqIdent_Fixture = {
0346   .setup = NULL,
0347   .stop = NULL,
0348   .teardown = NULL,
0349   .scope = RtemsSchedulerReqIdent_Scope,
0350   .initial_context = &RtemsSchedulerReqIdent_Instance
0351 };
0352 
0353 static inline RtemsSchedulerReqIdent_Entry RtemsSchedulerReqIdent_PopEntry(
0354   RtemsSchedulerReqIdent_Context *ctx
0355 )
0356 {
0357   size_t index;
0358 
0359   index = ctx->Map.index;
0360   ctx->Map.index = index + 1;
0361   return RtemsSchedulerReqIdent_Entries[
0362     RtemsSchedulerReqIdent_Map[ index ]
0363   ];
0364 }
0365 
0366 static void RtemsSchedulerReqIdent_TestVariant(
0367   RtemsSchedulerReqIdent_Context *ctx
0368 )
0369 {
0370   RtemsSchedulerReqIdent_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0371   RtemsSchedulerReqIdent_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0372   RtemsSchedulerReqIdent_Action( ctx );
0373   RtemsSchedulerReqIdent_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0374   RtemsSchedulerReqIdent_Post_IdVar_Check( ctx, ctx->Map.entry.Post_IdVar );
0375 }
0376 
0377 /**
0378  * @fn void T_case_body_RtemsSchedulerReqIdent( void )
0379  */
0380 T_TEST_CASE_FIXTURE( RtemsSchedulerReqIdent, &RtemsSchedulerReqIdent_Fixture )
0381 {
0382   RtemsSchedulerReqIdent_Context *ctx;
0383 
0384   ctx = T_fixture_context();
0385   ctx->Map.in_action_loop = true;
0386   ctx->Map.index = 0;
0387 
0388   for (
0389     ctx->Map.pcs[ 0 ] = RtemsSchedulerReqIdent_Pre_Name_Invalid;
0390     ctx->Map.pcs[ 0 ] < RtemsSchedulerReqIdent_Pre_Name_NA;
0391     ++ctx->Map.pcs[ 0 ]
0392   ) {
0393     for (
0394       ctx->Map.pcs[ 1 ] = RtemsSchedulerReqIdent_Pre_Id_Valid;
0395       ctx->Map.pcs[ 1 ] < RtemsSchedulerReqIdent_Pre_Id_NA;
0396       ++ctx->Map.pcs[ 1 ]
0397     ) {
0398       ctx->Map.entry = RtemsSchedulerReqIdent_PopEntry( ctx );
0399       RtemsSchedulerReqIdent_Prepare( ctx );
0400       RtemsSchedulerReqIdent_TestVariant( ctx );
0401     }
0402   }
0403 }
0404 
0405 /** @} */