Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsTimerReqDelete
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 #include <string.h>
0057 
0058 #include <rtems/test.h>
0059 
0060 /**
0061  * @defgroup RtemsTimerReqDelete spec:/rtems/timer/req/delete
0062  *
0063  * @ingroup TestsuitesValidationNoClock0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   RtemsTimerReqDelete_Pre_Id_NoObj,
0070   RtemsTimerReqDelete_Pre_Id_Timer,
0071   RtemsTimerReqDelete_Pre_Id_NA
0072 } RtemsTimerReqDelete_Pre_Id;
0073 
0074 typedef enum {
0075   RtemsTimerReqDelete_Post_Status_Ok,
0076   RtemsTimerReqDelete_Post_Status_InvId,
0077   RtemsTimerReqDelete_Post_Status_NA
0078 } RtemsTimerReqDelete_Post_Status;
0079 
0080 typedef enum {
0081   RtemsTimerReqDelete_Post_Name_Valid,
0082   RtemsTimerReqDelete_Post_Name_Invalid,
0083   RtemsTimerReqDelete_Post_Name_NA
0084 } RtemsTimerReqDelete_Post_Name;
0085 
0086 typedef struct {
0087   uint8_t Skip : 1;
0088   uint8_t Pre_Id_NA : 1;
0089   uint8_t Post_Status : 2;
0090   uint8_t Post_Name : 2;
0091 } RtemsTimerReqDelete_Entry;
0092 
0093 /**
0094  * @brief Test context for spec:/rtems/timer/req/delete test case.
0095  */
0096 typedef struct {
0097   rtems_id timer_id;
0098 
0099   rtems_id id;
0100 
0101   rtems_status_code status;
0102 
0103   struct {
0104     /**
0105      * @brief This member defines the pre-condition states for the next action.
0106      */
0107     size_t pcs[ 1 ];
0108 
0109     /**
0110      * @brief If this member is true, then the test action loop is executed.
0111      */
0112     bool in_action_loop;
0113 
0114     /**
0115      * @brief This member contains the next transition map index.
0116      */
0117     size_t index;
0118 
0119     /**
0120      * @brief This member contains the current transition map entry.
0121      */
0122     RtemsTimerReqDelete_Entry entry;
0123 
0124     /**
0125      * @brief If this member is true, then the current transition variant
0126      *   should be skipped.
0127      */
0128     bool skip;
0129   } Map;
0130 } RtemsTimerReqDelete_Context;
0131 
0132 static RtemsTimerReqDelete_Context
0133   RtemsTimerReqDelete_Instance;
0134 
0135 static const char * const RtemsTimerReqDelete_PreDesc_Id[] = {
0136   "NoObj",
0137   "Timer",
0138   "NA"
0139 };
0140 
0141 static const char * const * const RtemsTimerReqDelete_PreDesc[] = {
0142   RtemsTimerReqDelete_PreDesc_Id,
0143   NULL
0144 };
0145 
0146 #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
0147 
0148 static void RtemsTimerReqDelete_Pre_Id_Prepare(
0149   RtemsTimerReqDelete_Context *ctx,
0150   RtemsTimerReqDelete_Pre_Id   state
0151 )
0152 {
0153   switch ( state ) {
0154     case RtemsTimerReqDelete_Pre_Id_NoObj: {
0155       /*
0156        * While the ``id`` parameter is not associated with a timer.
0157        */
0158       ctx->id = 0;
0159       break;
0160     }
0161 
0162     case RtemsTimerReqDelete_Pre_Id_Timer: {
0163       /*
0164        * While the ``id`` parameter is associated with a timer.
0165        */
0166       ctx->id = ctx->timer_id;
0167       break;
0168     }
0169 
0170     case RtemsTimerReqDelete_Pre_Id_NA:
0171       break;
0172   }
0173 }
0174 
0175 static void RtemsTimerReqDelete_Post_Status_Check(
0176   RtemsTimerReqDelete_Context    *ctx,
0177   RtemsTimerReqDelete_Post_Status state
0178 )
0179 {
0180   switch ( state ) {
0181     case RtemsTimerReqDelete_Post_Status_Ok: {
0182       /*
0183        * The return status of rtems_timer_delete() shall be RTEMS_SUCCESSFUL.
0184        */
0185       ctx->timer_id = 0;
0186       T_rsc_success( ctx->status );
0187       break;
0188     }
0189 
0190     case RtemsTimerReqDelete_Post_Status_InvId: {
0191       /*
0192        * The return status of rtems_timer_delete() shall be RTEMS_INVALID_ID.
0193        */
0194       T_rsc( ctx->status, RTEMS_INVALID_ID );
0195       break;
0196     }
0197 
0198     case RtemsTimerReqDelete_Post_Status_NA:
0199       break;
0200   }
0201 }
0202 
0203 static void RtemsTimerReqDelete_Post_Name_Check(
0204   RtemsTimerReqDelete_Context  *ctx,
0205   RtemsTimerReqDelete_Post_Name state
0206 )
0207 {
0208   rtems_status_code sc;
0209   rtems_id          id;
0210 
0211   switch ( state ) {
0212     case RtemsTimerReqDelete_Post_Name_Valid: {
0213       /*
0214        * The unique object name shall identify a timer.
0215        */
0216       id = 0;
0217       sc = rtems_timer_ident( NAME, &id );
0218       T_rsc_success( sc );
0219       T_eq_u32( id, ctx->timer_id );
0220       break;
0221     }
0222 
0223     case RtemsTimerReqDelete_Post_Name_Invalid: {
0224       /*
0225        * The unique object name shall not identify a timer.
0226        */
0227       sc = rtems_timer_ident( NAME, &id );
0228       T_rsc( sc, RTEMS_INVALID_NAME );
0229       break;
0230     }
0231 
0232     case RtemsTimerReqDelete_Post_Name_NA:
0233       break;
0234   }
0235 }
0236 
0237 static void RtemsTimerReqDelete_Setup( RtemsTimerReqDelete_Context *ctx )
0238 {
0239   memset( ctx, 0, sizeof( *ctx ) );
0240 }
0241 
0242 static void RtemsTimerReqDelete_Setup_Wrap( void *arg )
0243 {
0244   RtemsTimerReqDelete_Context *ctx;
0245 
0246   ctx = arg;
0247   ctx->Map.in_action_loop = false;
0248   RtemsTimerReqDelete_Setup( ctx );
0249 }
0250 
0251 static void RtemsTimerReqDelete_Teardown( RtemsTimerReqDelete_Context *ctx )
0252 {
0253   if ( ctx->timer_id != 0 ) {
0254     rtems_status_code sc;
0255 
0256     sc = rtems_timer_delete( ctx->timer_id );
0257     T_rsc_success( sc );
0258   }
0259 }
0260 
0261 static void RtemsTimerReqDelete_Teardown_Wrap( void *arg )
0262 {
0263   RtemsTimerReqDelete_Context *ctx;
0264 
0265   ctx = arg;
0266   ctx->Map.in_action_loop = false;
0267   RtemsTimerReqDelete_Teardown( ctx );
0268 }
0269 
0270 static void RtemsTimerReqDelete_Prepare( RtemsTimerReqDelete_Context *ctx )
0271 {
0272   if ( ctx->timer_id == 0 ) {
0273     rtems_status_code sc;
0274 
0275     sc = rtems_timer_create( NAME, &ctx->timer_id );
0276     T_rsc_success( sc );
0277   }
0278 }
0279 
0280 static void RtemsTimerReqDelete_Action( RtemsTimerReqDelete_Context *ctx )
0281 {
0282   ctx->status = rtems_timer_delete( ctx->id );
0283 }
0284 
0285 static const RtemsTimerReqDelete_Entry
0286 RtemsTimerReqDelete_Entries[] = {
0287   { 0, 0, RtemsTimerReqDelete_Post_Status_InvId,
0288     RtemsTimerReqDelete_Post_Name_Valid },
0289   { 0, 0, RtemsTimerReqDelete_Post_Status_Ok,
0290     RtemsTimerReqDelete_Post_Name_Invalid }
0291 };
0292 
0293 static const uint8_t
0294 RtemsTimerReqDelete_Map[] = {
0295   0, 1
0296 };
0297 
0298 static size_t RtemsTimerReqDelete_Scope( void *arg, char *buf, size_t n )
0299 {
0300   RtemsTimerReqDelete_Context *ctx;
0301 
0302   ctx = arg;
0303 
0304   if ( ctx->Map.in_action_loop ) {
0305     return T_get_scope( RtemsTimerReqDelete_PreDesc, buf, n, ctx->Map.pcs );
0306   }
0307 
0308   return 0;
0309 }
0310 
0311 static T_fixture RtemsTimerReqDelete_Fixture = {
0312   .setup = RtemsTimerReqDelete_Setup_Wrap,
0313   .stop = NULL,
0314   .teardown = RtemsTimerReqDelete_Teardown_Wrap,
0315   .scope = RtemsTimerReqDelete_Scope,
0316   .initial_context = &RtemsTimerReqDelete_Instance
0317 };
0318 
0319 static inline RtemsTimerReqDelete_Entry RtemsTimerReqDelete_PopEntry(
0320   RtemsTimerReqDelete_Context *ctx
0321 )
0322 {
0323   size_t index;
0324 
0325   index = ctx->Map.index;
0326   ctx->Map.index = index + 1;
0327   return RtemsTimerReqDelete_Entries[
0328     RtemsTimerReqDelete_Map[ index ]
0329   ];
0330 }
0331 
0332 static void RtemsTimerReqDelete_TestVariant( RtemsTimerReqDelete_Context *ctx )
0333 {
0334   RtemsTimerReqDelete_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0335   RtemsTimerReqDelete_Action( ctx );
0336   RtemsTimerReqDelete_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0337   RtemsTimerReqDelete_Post_Name_Check( ctx, ctx->Map.entry.Post_Name );
0338 }
0339 
0340 /**
0341  * @fn void T_case_body_RtemsTimerReqDelete( void )
0342  */
0343 T_TEST_CASE_FIXTURE( RtemsTimerReqDelete, &RtemsTimerReqDelete_Fixture )
0344 {
0345   RtemsTimerReqDelete_Context *ctx;
0346 
0347   ctx = T_fixture_context();
0348   ctx->Map.in_action_loop = true;
0349   ctx->Map.index = 0;
0350 
0351   for (
0352     ctx->Map.pcs[ 0 ] = RtemsTimerReqDelete_Pre_Id_NoObj;
0353     ctx->Map.pcs[ 0 ] < RtemsTimerReqDelete_Pre_Id_NA;
0354     ++ctx->Map.pcs[ 0 ]
0355   ) {
0356     ctx->Map.entry = RtemsTimerReqDelete_PopEntry( ctx );
0357     RtemsTimerReqDelete_Prepare( ctx );
0358     RtemsTimerReqDelete_TestVariant( ctx );
0359   }
0360 }
0361 
0362 /** @} */