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 RtemsTaskReqGetScheduler
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 "tx-support.h"
0058 
0059 #include <rtems/test.h>
0060 
0061 /**
0062  * @defgroup RtemsTaskReqGetScheduler spec:/rtems/task/req/get-scheduler
0063  *
0064  * @ingroup TestsuitesValidationNoClock0
0065  *
0066  * @{
0067  */
0068 
0069 typedef enum {
0070   RtemsTaskReqGetScheduler_Pre_Id_Invalid,
0071   RtemsTaskReqGetScheduler_Pre_Id_Task,
0072   RtemsTaskReqGetScheduler_Pre_Id_NA
0073 } RtemsTaskReqGetScheduler_Pre_Id;
0074 
0075 typedef enum {
0076   RtemsTaskReqGetScheduler_Pre_SchedulerID_Valid,
0077   RtemsTaskReqGetScheduler_Pre_SchedulerID_Null,
0078   RtemsTaskReqGetScheduler_Pre_SchedulerID_NA
0079 } RtemsTaskReqGetScheduler_Pre_SchedulerID;
0080 
0081 typedef enum {
0082   RtemsTaskReqGetScheduler_Post_Status_Ok,
0083   RtemsTaskReqGetScheduler_Post_Status_InvAddr,
0084   RtemsTaskReqGetScheduler_Post_Status_InvId,
0085   RtemsTaskReqGetScheduler_Post_Status_NA
0086 } RtemsTaskReqGetScheduler_Post_Status;
0087 
0088 typedef enum {
0089   RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Set,
0090   RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Nop,
0091   RtemsTaskReqGetScheduler_Post_SchedulerIDObj_NA
0092 } RtemsTaskReqGetScheduler_Post_SchedulerIDObj;
0093 
0094 typedef struct {
0095   uint8_t Skip : 1;
0096   uint8_t Pre_Id_NA : 1;
0097   uint8_t Pre_SchedulerID_NA : 1;
0098   uint8_t Post_Status : 2;
0099   uint8_t Post_SchedulerIDObj : 2;
0100 } RtemsTaskReqGetScheduler_Entry;
0101 
0102 /**
0103  * @brief Test context for spec:/rtems/task/req/get-scheduler test case.
0104  */
0105 typedef struct {
0106   /**
0107    * @brief This member provides the object referenced by the ``scheduler_id``
0108    *   parameter.
0109    */
0110   rtems_id scheduler_id_obj;
0111 
0112   /**
0113    * @brief This member contains the return value of the
0114    *   rtems_task_get_scheduler() call.
0115    */
0116   rtems_status_code status;
0117 
0118   /**
0119    * @brief This member specifies if the ``task_id`` parameter value.
0120    */
0121   rtems_id id;
0122 
0123   /**
0124    * @brief This member specifies if the ``scheduler_id`` parameter value.
0125    */
0126   rtems_id *scheduler_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     RtemsTaskReqGetScheduler_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 } RtemsTaskReqGetScheduler_Context;
0156 
0157 static RtemsTaskReqGetScheduler_Context
0158   RtemsTaskReqGetScheduler_Instance;
0159 
0160 static const char * const RtemsTaskReqGetScheduler_PreDesc_Id[] = {
0161   "Invalid",
0162   "Task",
0163   "NA"
0164 };
0165 
0166 static const char * const RtemsTaskReqGetScheduler_PreDesc_SchedulerID[] = {
0167   "Valid",
0168   "Null",
0169   "NA"
0170 };
0171 
0172 static const char * const * const RtemsTaskReqGetScheduler_PreDesc[] = {
0173   RtemsTaskReqGetScheduler_PreDesc_Id,
0174   RtemsTaskReqGetScheduler_PreDesc_SchedulerID,
0175   NULL
0176 };
0177 
0178 static void RtemsTaskReqGetScheduler_Pre_Id_Prepare(
0179   RtemsTaskReqGetScheduler_Context *ctx,
0180   RtemsTaskReqGetScheduler_Pre_Id   state
0181 )
0182 {
0183   switch ( state ) {
0184     case RtemsTaskReqGetScheduler_Pre_Id_Invalid: {
0185       /*
0186        * While the ``task_id`` parameter is not associated with a task.
0187        */
0188       ctx->id = INVALID_ID;
0189       break;
0190     }
0191 
0192     case RtemsTaskReqGetScheduler_Pre_Id_Task: {
0193       /*
0194        * While the ``task_id`` parameter is associated with a task.
0195        */
0196       ctx->id = RTEMS_SELF;
0197       break;
0198     }
0199 
0200     case RtemsTaskReqGetScheduler_Pre_Id_NA:
0201       break;
0202   }
0203 }
0204 
0205 static void RtemsTaskReqGetScheduler_Pre_SchedulerID_Prepare(
0206   RtemsTaskReqGetScheduler_Context        *ctx,
0207   RtemsTaskReqGetScheduler_Pre_SchedulerID state
0208 )
0209 {
0210   switch ( state ) {
0211     case RtemsTaskReqGetScheduler_Pre_SchedulerID_Valid: {
0212       /*
0213        * While the ``scheduler_id`` parameter references an object of type
0214        * rtems_id.
0215        */
0216       ctx->scheduler_id = &ctx->scheduler_id_obj;
0217       break;
0218     }
0219 
0220     case RtemsTaskReqGetScheduler_Pre_SchedulerID_Null: {
0221       /*
0222        * While the ``scheduler_id`` parameter is equal to NULL.
0223        */
0224       ctx->scheduler_id = NULL;
0225       break;
0226     }
0227 
0228     case RtemsTaskReqGetScheduler_Pre_SchedulerID_NA:
0229       break;
0230   }
0231 }
0232 
0233 static void RtemsTaskReqGetScheduler_Post_Status_Check(
0234   RtemsTaskReqGetScheduler_Context    *ctx,
0235   RtemsTaskReqGetScheduler_Post_Status state
0236 )
0237 {
0238   switch ( state ) {
0239     case RtemsTaskReqGetScheduler_Post_Status_Ok: {
0240       /*
0241        * The return status of rtems_task_get_scheduler() shall be
0242        * RTEMS_SUCCESSFUL.
0243        */
0244       T_rsc_success( ctx->status );
0245       break;
0246     }
0247 
0248     case RtemsTaskReqGetScheduler_Post_Status_InvAddr: {
0249       /*
0250        * The return status of rtems_task_get_scheduler() shall be
0251        * RTEMS_INVALID_ADDRESS.
0252        */
0253       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0254       break;
0255     }
0256 
0257     case RtemsTaskReqGetScheduler_Post_Status_InvId: {
0258       /*
0259        * The return status of rtems_task_get_scheduler() shall be
0260        * RTEMS_INVALID_ID.
0261        */
0262       T_rsc( ctx->status, RTEMS_INVALID_ID );
0263       break;
0264     }
0265 
0266     case RtemsTaskReqGetScheduler_Post_Status_NA:
0267       break;
0268   }
0269 }
0270 
0271 static void RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Check(
0272   RtemsTaskReqGetScheduler_Context            *ctx,
0273   RtemsTaskReqGetScheduler_Post_SchedulerIDObj state
0274 )
0275 {
0276   switch ( state ) {
0277     case RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Set: {
0278       /*
0279        * The value of the object referenced by the ``scheduler_id`` parameter
0280        * shall be set to the object identifier of the home scheduler of the
0281        * task specified by the ``task_id`` parameter at some point during the
0282        * call after the return of the rtems_task_get_scheduler() call.
0283        */
0284       T_eq_u32( ctx->scheduler_id_obj, 0x0f010001 );
0285       break;
0286     }
0287 
0288     case RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Nop: {
0289       /*
0290        * Objects referenced by the ``scheduler_id`` parameter in past calls to
0291        * rtems_task_get_scheduler() shall not be accessed by the
0292        * rtems_task_get_scheduler() call.
0293        */
0294       T_eq_u32( ctx->scheduler_id_obj, INVALID_ID );
0295       break;
0296     }
0297 
0298     case RtemsTaskReqGetScheduler_Post_SchedulerIDObj_NA:
0299       break;
0300   }
0301 }
0302 
0303 static void RtemsTaskReqGetScheduler_Prepare(
0304   RtemsTaskReqGetScheduler_Context *ctx
0305 )
0306 {
0307   ctx->scheduler_id_obj = INVALID_ID;
0308 }
0309 
0310 static void RtemsTaskReqGetScheduler_Action(
0311   RtemsTaskReqGetScheduler_Context *ctx
0312 )
0313 {
0314   ctx->status = rtems_task_get_scheduler( ctx->id, ctx->scheduler_id );
0315 }
0316 
0317 static const RtemsTaskReqGetScheduler_Entry
0318 RtemsTaskReqGetScheduler_Entries[] = {
0319   { 0, 0, 0, RtemsTaskReqGetScheduler_Post_Status_InvAddr,
0320     RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Nop },
0321   { 0, 0, 0, RtemsTaskReqGetScheduler_Post_Status_InvId,
0322     RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Nop },
0323   { 0, 0, 0, RtemsTaskReqGetScheduler_Post_Status_Ok,
0324     RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Set }
0325 };
0326 
0327 static const uint8_t
0328 RtemsTaskReqGetScheduler_Map[] = {
0329   1, 0, 2, 0
0330 };
0331 
0332 static size_t RtemsTaskReqGetScheduler_Scope( void *arg, char *buf, size_t n )
0333 {
0334   RtemsTaskReqGetScheduler_Context *ctx;
0335 
0336   ctx = arg;
0337 
0338   if ( ctx->Map.in_action_loop ) {
0339     return T_get_scope(
0340       RtemsTaskReqGetScheduler_PreDesc,
0341       buf,
0342       n,
0343       ctx->Map.pcs
0344     );
0345   }
0346 
0347   return 0;
0348 }
0349 
0350 static T_fixture RtemsTaskReqGetScheduler_Fixture = {
0351   .setup = NULL,
0352   .stop = NULL,
0353   .teardown = NULL,
0354   .scope = RtemsTaskReqGetScheduler_Scope,
0355   .initial_context = &RtemsTaskReqGetScheduler_Instance
0356 };
0357 
0358 static inline RtemsTaskReqGetScheduler_Entry RtemsTaskReqGetScheduler_PopEntry(
0359   RtemsTaskReqGetScheduler_Context *ctx
0360 )
0361 {
0362   size_t index;
0363 
0364   index = ctx->Map.index;
0365   ctx->Map.index = index + 1;
0366   return RtemsTaskReqGetScheduler_Entries[
0367     RtemsTaskReqGetScheduler_Map[ index ]
0368   ];
0369 }
0370 
0371 static void RtemsTaskReqGetScheduler_TestVariant(
0372   RtemsTaskReqGetScheduler_Context *ctx
0373 )
0374 {
0375   RtemsTaskReqGetScheduler_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0376   RtemsTaskReqGetScheduler_Pre_SchedulerID_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0377   RtemsTaskReqGetScheduler_Action( ctx );
0378   RtemsTaskReqGetScheduler_Post_Status_Check(
0379     ctx,
0380     ctx->Map.entry.Post_Status
0381   );
0382   RtemsTaskReqGetScheduler_Post_SchedulerIDObj_Check(
0383     ctx,
0384     ctx->Map.entry.Post_SchedulerIDObj
0385   );
0386 }
0387 
0388 /**
0389  * @fn void T_case_body_RtemsTaskReqGetScheduler( void )
0390  */
0391 T_TEST_CASE_FIXTURE(
0392   RtemsTaskReqGetScheduler,
0393   &RtemsTaskReqGetScheduler_Fixture
0394 )
0395 {
0396   RtemsTaskReqGetScheduler_Context *ctx;
0397 
0398   ctx = T_fixture_context();
0399   ctx->Map.in_action_loop = true;
0400   ctx->Map.index = 0;
0401 
0402   for (
0403     ctx->Map.pcs[ 0 ] = RtemsTaskReqGetScheduler_Pre_Id_Invalid;
0404     ctx->Map.pcs[ 0 ] < RtemsTaskReqGetScheduler_Pre_Id_NA;
0405     ++ctx->Map.pcs[ 0 ]
0406   ) {
0407     for (
0408       ctx->Map.pcs[ 1 ] = RtemsTaskReqGetScheduler_Pre_SchedulerID_Valid;
0409       ctx->Map.pcs[ 1 ] < RtemsTaskReqGetScheduler_Pre_SchedulerID_NA;
0410       ++ctx->Map.pcs[ 1 ]
0411     ) {
0412       ctx->Map.entry = RtemsTaskReqGetScheduler_PopEntry( ctx );
0413       RtemsTaskReqGetScheduler_Prepare( ctx );
0414       RtemsTaskReqGetScheduler_TestVariant( ctx );
0415     }
0416   }
0417 }
0418 
0419 /** @} */