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 RtemsTaskReqIsSuspended
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 RtemsTaskReqIsSuspended spec:/rtems/task/req/is-suspended
0063  *
0064  * @ingroup TestsuitesValidationNoClock0
0065  *
0066  * @{
0067  */
0068 
0069 typedef enum {
0070   RtemsTaskReqIsSuspended_Pre_Id_Invalid,
0071   RtemsTaskReqIsSuspended_Pre_Id_Task,
0072   RtemsTaskReqIsSuspended_Pre_Id_NA
0073 } RtemsTaskReqIsSuspended_Pre_Id;
0074 
0075 typedef enum {
0076   RtemsTaskReqIsSuspended_Pre_Suspended_Yes,
0077   RtemsTaskReqIsSuspended_Pre_Suspended_No,
0078   RtemsTaskReqIsSuspended_Pre_Suspended_NA
0079 } RtemsTaskReqIsSuspended_Pre_Suspended;
0080 
0081 typedef enum {
0082   RtemsTaskReqIsSuspended_Post_Status_Ok,
0083   RtemsTaskReqIsSuspended_Post_Status_InvId,
0084   RtemsTaskReqIsSuspended_Post_Status_AlrdySus,
0085   RtemsTaskReqIsSuspended_Post_Status_NA
0086 } RtemsTaskReqIsSuspended_Post_Status;
0087 
0088 typedef struct {
0089   uint8_t Skip : 1;
0090   uint8_t Pre_Id_NA : 1;
0091   uint8_t Pre_Suspended_NA : 1;
0092   uint8_t Post_Status : 2;
0093 } RtemsTaskReqIsSuspended_Entry;
0094 
0095 /**
0096  * @brief Test context for spec:/rtems/task/req/is-suspended test case.
0097  */
0098 typedef struct {
0099   /**
0100    * @brief This member contains the identifier of a task.
0101    */
0102   rtems_id worker_id;
0103 
0104   /**
0105    * @brief If this member is true, then the worker is suspended before the
0106    *   rtems_task_is_suspended() call.
0107    */
0108   bool suspend;
0109 
0110   /**
0111    * @brief This member contains the return value of the
0112    *   rtems_task_is_suspended() call.
0113    */
0114   rtems_status_code status;
0115 
0116   /**
0117    * @brief This member specifies if the ``id`` parameter value.
0118    */
0119   rtems_id id;
0120 
0121   struct {
0122     /**
0123      * @brief This member defines the pre-condition indices for the next
0124      *   action.
0125      */
0126     size_t pci[ 2 ];
0127 
0128     /**
0129      * @brief This member defines the pre-condition states for the next action.
0130      */
0131     size_t pcs[ 2 ];
0132 
0133     /**
0134      * @brief If this member is true, then the test action loop is executed.
0135      */
0136     bool in_action_loop;
0137 
0138     /**
0139      * @brief This member contains the next transition map index.
0140      */
0141     size_t index;
0142 
0143     /**
0144      * @brief This member contains the current transition map entry.
0145      */
0146     RtemsTaskReqIsSuspended_Entry entry;
0147 
0148     /**
0149      * @brief If this member is true, then the current transition variant
0150      *   should be skipped.
0151      */
0152     bool skip;
0153   } Map;
0154 } RtemsTaskReqIsSuspended_Context;
0155 
0156 static RtemsTaskReqIsSuspended_Context
0157   RtemsTaskReqIsSuspended_Instance;
0158 
0159 static const char * const RtemsTaskReqIsSuspended_PreDesc_Id[] = {
0160   "Invalid",
0161   "Task",
0162   "NA"
0163 };
0164 
0165 static const char * const RtemsTaskReqIsSuspended_PreDesc_Suspended[] = {
0166   "Yes",
0167   "No",
0168   "NA"
0169 };
0170 
0171 static const char * const * const RtemsTaskReqIsSuspended_PreDesc[] = {
0172   RtemsTaskReqIsSuspended_PreDesc_Id,
0173   RtemsTaskReqIsSuspended_PreDesc_Suspended,
0174   NULL
0175 };
0176 
0177 static void Worker( rtems_task_argument arg )
0178 {
0179   while ( true ) {
0180     /* Do nothing */
0181   }
0182 }
0183 
0184 static void RtemsTaskReqIsSuspended_Pre_Id_Prepare(
0185   RtemsTaskReqIsSuspended_Context *ctx,
0186   RtemsTaskReqIsSuspended_Pre_Id   state
0187 )
0188 {
0189   switch ( state ) {
0190     case RtemsTaskReqIsSuspended_Pre_Id_Invalid: {
0191       /*
0192        * While the ``id`` parameter is not associated with a task.
0193        */
0194       ctx->id = INVALID_ID;
0195       break;
0196     }
0197 
0198     case RtemsTaskReqIsSuspended_Pre_Id_Task: {
0199       /*
0200        * While the ``id`` parameter is associated with a task.
0201        */
0202       ctx->id = ctx->worker_id;
0203       break;
0204     }
0205 
0206     case RtemsTaskReqIsSuspended_Pre_Id_NA:
0207       break;
0208   }
0209 }
0210 
0211 static void RtemsTaskReqIsSuspended_Pre_Suspended_Prepare(
0212   RtemsTaskReqIsSuspended_Context      *ctx,
0213   RtemsTaskReqIsSuspended_Pre_Suspended state
0214 )
0215 {
0216   switch ( state ) {
0217     case RtemsTaskReqIsSuspended_Pre_Suspended_Yes: {
0218       /*
0219        * While the task specified by the ``id`` parameter is suspended.
0220        */
0221       ctx->suspend = true;
0222       break;
0223     }
0224 
0225     case RtemsTaskReqIsSuspended_Pre_Suspended_No: {
0226       /*
0227        * While the task specified by the ``id`` parameter is not suspended.
0228        */
0229       ctx->suspend = false;
0230       break;
0231     }
0232 
0233     case RtemsTaskReqIsSuspended_Pre_Suspended_NA:
0234       break;
0235   }
0236 }
0237 
0238 static void RtemsTaskReqIsSuspended_Post_Status_Check(
0239   RtemsTaskReqIsSuspended_Context    *ctx,
0240   RtemsTaskReqIsSuspended_Post_Status state
0241 )
0242 {
0243   switch ( state ) {
0244     case RtemsTaskReqIsSuspended_Post_Status_Ok: {
0245       /*
0246        * The return status of rtems_task_is_suspended() shall be
0247        * RTEMS_SUCCESSFUL.
0248        */
0249       T_rsc_success( ctx->status );
0250       break;
0251     }
0252 
0253     case RtemsTaskReqIsSuspended_Post_Status_InvId: {
0254       /*
0255        * The return status of rtems_task_is_suspended() shall be
0256        * RTEMS_INVALID_ID.
0257        */
0258       T_rsc( ctx->status, RTEMS_INVALID_ID );
0259       break;
0260     }
0261 
0262     case RtemsTaskReqIsSuspended_Post_Status_AlrdySus: {
0263       /*
0264        * The return status of rtems_task_is_suspended() shall be
0265        * RTEMS_ALREADY_SUSPENDED.
0266        */
0267       T_rsc( ctx->status, RTEMS_ALREADY_SUSPENDED );
0268       break;
0269     }
0270 
0271     case RtemsTaskReqIsSuspended_Post_Status_NA:
0272       break;
0273   }
0274 }
0275 
0276 static void RtemsTaskReqIsSuspended_Setup(
0277   RtemsTaskReqIsSuspended_Context *ctx
0278 )
0279 {
0280   ctx->worker_id = CreateTask( "WORK", PRIO_LOW );
0281   StartTask( ctx->worker_id, Worker, ctx );
0282 }
0283 
0284 static void RtemsTaskReqIsSuspended_Setup_Wrap( void *arg )
0285 {
0286   RtemsTaskReqIsSuspended_Context *ctx;
0287 
0288   ctx = arg;
0289   ctx->Map.in_action_loop = false;
0290   RtemsTaskReqIsSuspended_Setup( ctx );
0291 }
0292 
0293 static void RtemsTaskReqIsSuspended_Teardown(
0294   RtemsTaskReqIsSuspended_Context *ctx
0295 )
0296 {
0297   DeleteTask( ctx->worker_id );
0298 }
0299 
0300 static void RtemsTaskReqIsSuspended_Teardown_Wrap( void *arg )
0301 {
0302   RtemsTaskReqIsSuspended_Context *ctx;
0303 
0304   ctx = arg;
0305   ctx->Map.in_action_loop = false;
0306   RtemsTaskReqIsSuspended_Teardown( ctx );
0307 }
0308 
0309 static void RtemsTaskReqIsSuspended_Action(
0310   RtemsTaskReqIsSuspended_Context *ctx
0311 )
0312 {
0313   if ( ctx->suspend ) {
0314     SuspendTask( ctx->worker_id );
0315   }
0316 
0317   ctx->status = rtems_task_is_suspended( ctx->id );
0318 
0319   if ( ctx->suspend ) {
0320     ResumeTask( ctx->worker_id );
0321   }
0322 }
0323 
0324 static const RtemsTaskReqIsSuspended_Entry
0325 RtemsTaskReqIsSuspended_Entries[] = {
0326   { 0, 0, 1, RtemsTaskReqIsSuspended_Post_Status_InvId },
0327   { 0, 0, 0, RtemsTaskReqIsSuspended_Post_Status_AlrdySus },
0328   { 0, 0, 0, RtemsTaskReqIsSuspended_Post_Status_Ok }
0329 };
0330 
0331 static const uint8_t
0332 RtemsTaskReqIsSuspended_Map[] = {
0333   0, 0, 1, 2
0334 };
0335 
0336 static size_t RtemsTaskReqIsSuspended_Scope( void *arg, char *buf, size_t n )
0337 {
0338   RtemsTaskReqIsSuspended_Context *ctx;
0339 
0340   ctx = arg;
0341 
0342   if ( ctx->Map.in_action_loop ) {
0343     return T_get_scope(
0344       RtemsTaskReqIsSuspended_PreDesc,
0345       buf,
0346       n,
0347       ctx->Map.pcs
0348     );
0349   }
0350 
0351   return 0;
0352 }
0353 
0354 static T_fixture RtemsTaskReqIsSuspended_Fixture = {
0355   .setup = RtemsTaskReqIsSuspended_Setup_Wrap,
0356   .stop = NULL,
0357   .teardown = RtemsTaskReqIsSuspended_Teardown_Wrap,
0358   .scope = RtemsTaskReqIsSuspended_Scope,
0359   .initial_context = &RtemsTaskReqIsSuspended_Instance
0360 };
0361 
0362 static inline RtemsTaskReqIsSuspended_Entry RtemsTaskReqIsSuspended_PopEntry(
0363   RtemsTaskReqIsSuspended_Context *ctx
0364 )
0365 {
0366   size_t index;
0367 
0368   index = ctx->Map.index;
0369   ctx->Map.index = index + 1;
0370   return RtemsTaskReqIsSuspended_Entries[
0371     RtemsTaskReqIsSuspended_Map[ index ]
0372   ];
0373 }
0374 
0375 static void RtemsTaskReqIsSuspended_SetPreConditionStates(
0376   RtemsTaskReqIsSuspended_Context *ctx
0377 )
0378 {
0379   ctx->Map.pcs[ 0 ] = ctx->Map.pci[ 0 ];
0380 
0381   if ( ctx->Map.entry.Pre_Suspended_NA ) {
0382     ctx->Map.pcs[ 1 ] = RtemsTaskReqIsSuspended_Pre_Suspended_NA;
0383   } else {
0384     ctx->Map.pcs[ 1 ] = ctx->Map.pci[ 1 ];
0385   }
0386 }
0387 
0388 static void RtemsTaskReqIsSuspended_TestVariant(
0389   RtemsTaskReqIsSuspended_Context *ctx
0390 )
0391 {
0392   RtemsTaskReqIsSuspended_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0393   RtemsTaskReqIsSuspended_Pre_Suspended_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0394   RtemsTaskReqIsSuspended_Action( ctx );
0395   RtemsTaskReqIsSuspended_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0396 }
0397 
0398 /**
0399  * @fn void T_case_body_RtemsTaskReqIsSuspended( void )
0400  */
0401 T_TEST_CASE_FIXTURE(
0402   RtemsTaskReqIsSuspended,
0403   &RtemsTaskReqIsSuspended_Fixture
0404 )
0405 {
0406   RtemsTaskReqIsSuspended_Context *ctx;
0407 
0408   ctx = T_fixture_context();
0409   ctx->Map.in_action_loop = true;
0410   ctx->Map.index = 0;
0411 
0412   for (
0413     ctx->Map.pci[ 0 ] = RtemsTaskReqIsSuspended_Pre_Id_Invalid;
0414     ctx->Map.pci[ 0 ] < RtemsTaskReqIsSuspended_Pre_Id_NA;
0415     ++ctx->Map.pci[ 0 ]
0416   ) {
0417     for (
0418       ctx->Map.pci[ 1 ] = RtemsTaskReqIsSuspended_Pre_Suspended_Yes;
0419       ctx->Map.pci[ 1 ] < RtemsTaskReqIsSuspended_Pre_Suspended_NA;
0420       ++ctx->Map.pci[ 1 ]
0421     ) {
0422       ctx->Map.entry = RtemsTaskReqIsSuspended_PopEntry( ctx );
0423       RtemsTaskReqIsSuspended_SetPreConditionStates( ctx );
0424       RtemsTaskReqIsSuspended_TestVariant( ctx );
0425     }
0426   }
0427 }
0428 
0429 /** @} */