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 RtemsSchedulerReqGetMaximumPriority
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 <limits.h>
0056 #include <rtems.h>
0057 
0058 #include "ts-config.h"
0059 #include "tx-support.h"
0060 
0061 #include <rtems/test.h>
0062 
0063 /**
0064  * @defgroup RtemsSchedulerReqGetMaximumPriority \
0065  *   spec:/rtems/scheduler/req/get-maximum-priority
0066  *
0067  * @ingroup TestsuitesValidationNoClock0
0068  *
0069  * @{
0070  */
0071 
0072 typedef enum {
0073   RtemsSchedulerReqGetMaximumPriority_Pre_Id_Invalid,
0074   RtemsSchedulerReqGetMaximumPriority_Pre_Id_Scheduler,
0075   RtemsSchedulerReqGetMaximumPriority_Pre_Id_NA
0076 } RtemsSchedulerReqGetMaximumPriority_Pre_Id;
0077 
0078 typedef enum {
0079   RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Valid,
0080   RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Null,
0081   RtemsSchedulerReqGetMaximumPriority_Pre_Prio_NA
0082 } RtemsSchedulerReqGetMaximumPriority_Pre_Prio;
0083 
0084 typedef enum {
0085   RtemsSchedulerReqGetMaximumPriority_Post_Status_Ok,
0086   RtemsSchedulerReqGetMaximumPriority_Post_Status_InvAddr,
0087   RtemsSchedulerReqGetMaximumPriority_Post_Status_InvId,
0088   RtemsSchedulerReqGetMaximumPriority_Post_Status_NA
0089 } RtemsSchedulerReqGetMaximumPriority_Post_Status;
0090 
0091 typedef enum {
0092   RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Set,
0093   RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Nop,
0094   RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_NA
0095 } RtemsSchedulerReqGetMaximumPriority_Post_PrioObj;
0096 
0097 typedef struct {
0098   uint8_t Skip : 1;
0099   uint8_t Pre_Id_NA : 1;
0100   uint8_t Pre_Prio_NA : 1;
0101   uint8_t Post_Status : 2;
0102   uint8_t Post_PrioObj : 2;
0103 } RtemsSchedulerReqGetMaximumPriority_Entry;
0104 
0105 /**
0106  * @brief Test context for spec:/rtems/scheduler/req/get-maximum-priority test
0107  *   case.
0108  */
0109 typedef struct {
0110   /**
0111    * @brief This member contains the identifier of a scheduler.
0112    */
0113   rtems_id scheduler_id;
0114 
0115   /**
0116    * @brief This member provides the object referenced by the ``priority``
0117    *   parameter.
0118    */
0119   rtems_task_priority priority_obj;
0120 
0121   /**
0122    * @brief This member contains the return value of the
0123    *   rtems_scheduler_get_maximum_priority() call.
0124    */
0125   rtems_status_code status;
0126 
0127   /**
0128    * @brief This member specifies if the ``scheduler_id`` parameter value.
0129    */
0130   rtems_id id;
0131 
0132   /**
0133    * @brief This member specifies if the ``priority`` parameter value.
0134    */
0135   rtems_task_priority *priority;
0136 
0137   struct {
0138     /**
0139      * @brief This member defines the pre-condition states for the next action.
0140      */
0141     size_t pcs[ 2 ];
0142 
0143     /**
0144      * @brief If this member is true, then the test action loop is executed.
0145      */
0146     bool in_action_loop;
0147 
0148     /**
0149      * @brief This member contains the next transition map index.
0150      */
0151     size_t index;
0152 
0153     /**
0154      * @brief This member contains the current transition map entry.
0155      */
0156     RtemsSchedulerReqGetMaximumPriority_Entry entry;
0157 
0158     /**
0159      * @brief If this member is true, then the current transition variant
0160      *   should be skipped.
0161      */
0162     bool skip;
0163   } Map;
0164 } RtemsSchedulerReqGetMaximumPriority_Context;
0165 
0166 static RtemsSchedulerReqGetMaximumPriority_Context
0167   RtemsSchedulerReqGetMaximumPriority_Instance;
0168 
0169 static const char * const RtemsSchedulerReqGetMaximumPriority_PreDesc_Id[] = {
0170   "Invalid",
0171   "Scheduler",
0172   "NA"
0173 };
0174 
0175 static const char * const RtemsSchedulerReqGetMaximumPriority_PreDesc_Prio[] = {
0176   "Valid",
0177   "Null",
0178   "NA"
0179 };
0180 
0181 static const char * const * const RtemsSchedulerReqGetMaximumPriority_PreDesc[] = {
0182   RtemsSchedulerReqGetMaximumPriority_PreDesc_Id,
0183   RtemsSchedulerReqGetMaximumPriority_PreDesc_Prio,
0184   NULL
0185 };
0186 
0187 static void RtemsSchedulerReqGetMaximumPriority_Pre_Id_Prepare(
0188   RtemsSchedulerReqGetMaximumPriority_Context *ctx,
0189   RtemsSchedulerReqGetMaximumPriority_Pre_Id   state
0190 )
0191 {
0192   switch ( state ) {
0193     case RtemsSchedulerReqGetMaximumPriority_Pre_Id_Invalid: {
0194       /*
0195        * While the ``scheduler_id`` parameter is not associated with a
0196        * scheduler.
0197        */
0198       ctx->id = INVALID_ID;
0199       break;
0200     }
0201 
0202     case RtemsSchedulerReqGetMaximumPriority_Pre_Id_Scheduler: {
0203       /*
0204        * While the ``scheduler_id`` parameter is associated with a scheduler.
0205        */
0206       ctx->id = ctx->scheduler_id;
0207       break;
0208     }
0209 
0210     case RtemsSchedulerReqGetMaximumPriority_Pre_Id_NA:
0211       break;
0212   }
0213 }
0214 
0215 static void RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Prepare(
0216   RtemsSchedulerReqGetMaximumPriority_Context *ctx,
0217   RtemsSchedulerReqGetMaximumPriority_Pre_Prio state
0218 )
0219 {
0220   switch ( state ) {
0221     case RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Valid: {
0222       /*
0223        * While the ``priority`` parameter references an object of type
0224        * rtems_task_priority.
0225        */
0226       ctx->priority = &ctx->priority_obj;
0227       break;
0228     }
0229 
0230     case RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Null: {
0231       /*
0232        * While the ``priority`` parameter is equal to NULL.
0233        */
0234       ctx->priority = NULL;
0235       break;
0236     }
0237 
0238     case RtemsSchedulerReqGetMaximumPriority_Pre_Prio_NA:
0239       break;
0240   }
0241 }
0242 
0243 static void RtemsSchedulerReqGetMaximumPriority_Post_Status_Check(
0244   RtemsSchedulerReqGetMaximumPriority_Context    *ctx,
0245   RtemsSchedulerReqGetMaximumPriority_Post_Status state
0246 )
0247 {
0248   switch ( state ) {
0249     case RtemsSchedulerReqGetMaximumPriority_Post_Status_Ok: {
0250       /*
0251        * The return status of rtems_scheduler_get_maximum_priority() shall be
0252        * RTEMS_SUCCESSFUL.
0253        */
0254       T_rsc_success( ctx->status );
0255       break;
0256     }
0257 
0258     case RtemsSchedulerReqGetMaximumPriority_Post_Status_InvAddr: {
0259       /*
0260        * The return status of rtems_scheduler_get_maximum_priority() shall be
0261        * RTEMS_INVALID_ADDRESS.
0262        */
0263       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0264       break;
0265     }
0266 
0267     case RtemsSchedulerReqGetMaximumPriority_Post_Status_InvId: {
0268       /*
0269        * The return status of rtems_scheduler_get_maximum_priority() shall be
0270        * RTEMS_INVALID_ID.
0271        */
0272       T_rsc( ctx->status, RTEMS_INVALID_ID );
0273       break;
0274     }
0275 
0276     case RtemsSchedulerReqGetMaximumPriority_Post_Status_NA:
0277       break;
0278   }
0279 }
0280 
0281 static void RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Check(
0282   RtemsSchedulerReqGetMaximumPriority_Context     *ctx,
0283   RtemsSchedulerReqGetMaximumPriority_Post_PrioObj state
0284 )
0285 {
0286   switch ( state ) {
0287     case RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Set: {
0288       /*
0289        * The value of the object referenced by the ``priority`` parameter shall
0290        * be set to the maximum priority value of the scheduler specified by the
0291        * ``scheduler_id`` parameter after the return of the
0292        * rtems_scheduler_get_maximum_priority() call.
0293        */
0294       #if defined(RTEMS_SMP)
0295       T_eq_u32( ctx->priority_obj, INT_MAX );
0296       #else
0297       T_eq_u32( ctx->priority_obj, 127 );
0298       #endif
0299       break;
0300     }
0301 
0302     case RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Nop: {
0303       /*
0304        * Objects referenced by the ``priority`` parameter in past calls to
0305        * rtems_scheduler_get_maximum_priority() shall not be accessed by the
0306        * rtems_scheduler_get_maximum_priority() call.
0307        */
0308       T_eq_u32( ctx->priority_obj, PRIO_INVALID );
0309       break;
0310     }
0311 
0312     case RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_NA:
0313       break;
0314   }
0315 }
0316 
0317 static void RtemsSchedulerReqGetMaximumPriority_Setup(
0318   RtemsSchedulerReqGetMaximumPriority_Context *ctx
0319 )
0320 {
0321   rtems_status_code sc;
0322 
0323   sc = rtems_scheduler_ident(
0324     TEST_SCHEDULER_A_NAME,
0325     &ctx->scheduler_id
0326   );
0327   T_rsc_success( sc );
0328 }
0329 
0330 static void RtemsSchedulerReqGetMaximumPriority_Setup_Wrap( void *arg )
0331 {
0332   RtemsSchedulerReqGetMaximumPriority_Context *ctx;
0333 
0334   ctx = arg;
0335   ctx->Map.in_action_loop = false;
0336   RtemsSchedulerReqGetMaximumPriority_Setup( ctx );
0337 }
0338 
0339 static void RtemsSchedulerReqGetMaximumPriority_Prepare(
0340   RtemsSchedulerReqGetMaximumPriority_Context *ctx
0341 )
0342 {
0343   ctx->priority_obj = PRIO_INVALID;
0344 }
0345 
0346 static void RtemsSchedulerReqGetMaximumPriority_Action(
0347   RtemsSchedulerReqGetMaximumPriority_Context *ctx
0348 )
0349 {
0350   ctx->status = rtems_scheduler_get_maximum_priority( ctx->id, ctx->priority );
0351 }
0352 
0353 static const RtemsSchedulerReqGetMaximumPriority_Entry
0354 RtemsSchedulerReqGetMaximumPriority_Entries[] = {
0355   { 0, 0, 0, RtemsSchedulerReqGetMaximumPriority_Post_Status_InvAddr,
0356     RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Nop },
0357   { 0, 0, 0, RtemsSchedulerReqGetMaximumPriority_Post_Status_InvId,
0358     RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Nop },
0359   { 0, 0, 0, RtemsSchedulerReqGetMaximumPriority_Post_Status_Ok,
0360     RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Set }
0361 };
0362 
0363 static const uint8_t
0364 RtemsSchedulerReqGetMaximumPriority_Map[] = {
0365   1, 0, 2, 0
0366 };
0367 
0368 static size_t RtemsSchedulerReqGetMaximumPriority_Scope(
0369   void  *arg,
0370   char  *buf,
0371   size_t n
0372 )
0373 {
0374   RtemsSchedulerReqGetMaximumPriority_Context *ctx;
0375 
0376   ctx = arg;
0377 
0378   if ( ctx->Map.in_action_loop ) {
0379     return T_get_scope(
0380       RtemsSchedulerReqGetMaximumPriority_PreDesc,
0381       buf,
0382       n,
0383       ctx->Map.pcs
0384     );
0385   }
0386 
0387   return 0;
0388 }
0389 
0390 static T_fixture RtemsSchedulerReqGetMaximumPriority_Fixture = {
0391   .setup = RtemsSchedulerReqGetMaximumPriority_Setup_Wrap,
0392   .stop = NULL,
0393   .teardown = NULL,
0394   .scope = RtemsSchedulerReqGetMaximumPriority_Scope,
0395   .initial_context = &RtemsSchedulerReqGetMaximumPriority_Instance
0396 };
0397 
0398 static inline RtemsSchedulerReqGetMaximumPriority_Entry
0399 RtemsSchedulerReqGetMaximumPriority_PopEntry(
0400   RtemsSchedulerReqGetMaximumPriority_Context *ctx
0401 )
0402 {
0403   size_t index;
0404 
0405   index = ctx->Map.index;
0406   ctx->Map.index = index + 1;
0407   return RtemsSchedulerReqGetMaximumPriority_Entries[
0408     RtemsSchedulerReqGetMaximumPriority_Map[ index ]
0409   ];
0410 }
0411 
0412 static void RtemsSchedulerReqGetMaximumPriority_TestVariant(
0413   RtemsSchedulerReqGetMaximumPriority_Context *ctx
0414 )
0415 {
0416   RtemsSchedulerReqGetMaximumPriority_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0417   RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Prepare(
0418     ctx,
0419     ctx->Map.pcs[ 1 ]
0420   );
0421   RtemsSchedulerReqGetMaximumPriority_Action( ctx );
0422   RtemsSchedulerReqGetMaximumPriority_Post_Status_Check(
0423     ctx,
0424     ctx->Map.entry.Post_Status
0425   );
0426   RtemsSchedulerReqGetMaximumPriority_Post_PrioObj_Check(
0427     ctx,
0428     ctx->Map.entry.Post_PrioObj
0429   );
0430 }
0431 
0432 /**
0433  * @fn void T_case_body_RtemsSchedulerReqGetMaximumPriority( void )
0434  */
0435 T_TEST_CASE_FIXTURE(
0436   RtemsSchedulerReqGetMaximumPriority,
0437   &RtemsSchedulerReqGetMaximumPriority_Fixture
0438 )
0439 {
0440   RtemsSchedulerReqGetMaximumPriority_Context *ctx;
0441 
0442   ctx = T_fixture_context();
0443   ctx->Map.in_action_loop = true;
0444   ctx->Map.index = 0;
0445 
0446   for (
0447     ctx->Map.pcs[ 0 ] = RtemsSchedulerReqGetMaximumPriority_Pre_Id_Invalid;
0448     ctx->Map.pcs[ 0 ] < RtemsSchedulerReqGetMaximumPriority_Pre_Id_NA;
0449     ++ctx->Map.pcs[ 0 ]
0450   ) {
0451     for (
0452       ctx->Map.pcs[ 1 ] = RtemsSchedulerReqGetMaximumPriority_Pre_Prio_Valid;
0453       ctx->Map.pcs[ 1 ] < RtemsSchedulerReqGetMaximumPriority_Pre_Prio_NA;
0454       ++ctx->Map.pcs[ 1 ]
0455     ) {
0456       ctx->Map.entry = RtemsSchedulerReqGetMaximumPriority_PopEntry( ctx );
0457       RtemsSchedulerReqGetMaximumPriority_Prepare( ctx );
0458       RtemsSchedulerReqGetMaximumPriority_TestVariant( ctx );
0459     }
0460   }
0461 }
0462 
0463 /** @} */