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 RtemsTimerReqCreate
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 "tx-support.h"
0059 
0060 #include <rtems/test.h>
0061 
0062 /**
0063  * @defgroup RtemsTimerReqCreate spec:/rtems/timer/req/create
0064  *
0065  * @ingroup TestsuitesValidationNoClock0
0066  *
0067  * @{
0068  */
0069 
0070 typedef enum {
0071   RtemsTimerReqCreate_Pre_Name_Valid,
0072   RtemsTimerReqCreate_Pre_Name_Invalid,
0073   RtemsTimerReqCreate_Pre_Name_NA
0074 } RtemsTimerReqCreate_Pre_Name;
0075 
0076 typedef enum {
0077   RtemsTimerReqCreate_Pre_Id_Valid,
0078   RtemsTimerReqCreate_Pre_Id_Null,
0079   RtemsTimerReqCreate_Pre_Id_NA
0080 } RtemsTimerReqCreate_Pre_Id;
0081 
0082 typedef enum {
0083   RtemsTimerReqCreate_Pre_Free_Yes,
0084   RtemsTimerReqCreate_Pre_Free_No,
0085   RtemsTimerReqCreate_Pre_Free_NA
0086 } RtemsTimerReqCreate_Pre_Free;
0087 
0088 typedef enum {
0089   RtemsTimerReqCreate_Post_Status_Ok,
0090   RtemsTimerReqCreate_Post_Status_InvName,
0091   RtemsTimerReqCreate_Post_Status_InvAddr,
0092   RtemsTimerReqCreate_Post_Status_TooMany,
0093   RtemsTimerReqCreate_Post_Status_NA
0094 } RtemsTimerReqCreate_Post_Status;
0095 
0096 typedef enum {
0097   RtemsTimerReqCreate_Post_Name_Valid,
0098   RtemsTimerReqCreate_Post_Name_Invalid,
0099   RtemsTimerReqCreate_Post_Name_NA
0100 } RtemsTimerReqCreate_Post_Name;
0101 
0102 typedef enum {
0103   RtemsTimerReqCreate_Post_IdVar_Set,
0104   RtemsTimerReqCreate_Post_IdVar_Nop,
0105   RtemsTimerReqCreate_Post_IdVar_NA
0106 } RtemsTimerReqCreate_Post_IdVar;
0107 
0108 typedef struct {
0109   uint16_t Skip : 1;
0110   uint16_t Pre_Name_NA : 1;
0111   uint16_t Pre_Id_NA : 1;
0112   uint16_t Pre_Free_NA : 1;
0113   uint16_t Post_Status : 3;
0114   uint16_t Post_Name : 2;
0115   uint16_t Post_IdVar : 2;
0116 } RtemsTimerReqCreate_Entry;
0117 
0118 /**
0119  * @brief Test context for spec:/rtems/timer/req/create test case.
0120  */
0121 typedef struct {
0122   /**
0123    * @brief This member is used by the T_seize_objects() and
0124    *   T_surrender_objects() support functions.
0125    */
0126   void *seized_objects;
0127 
0128   /**
0129    * @brief This member may contain the object identifier returned by
0130    *   rtems_timer_create().
0131    */
0132   rtems_id id_value;
0133 
0134   /**
0135    * @brief This member specifies the ``name`` parameter for the action.
0136    */
0137   rtems_name name;
0138 
0139   /**
0140    * @brief This member specifies the ``id`` parameter for the action.
0141    */
0142   rtems_id *id;
0143 
0144   /**
0145    * @brief This member contains the return status of the action.
0146    */
0147   rtems_status_code status;
0148 
0149   struct {
0150     /**
0151      * @brief This member defines the pre-condition states for the next action.
0152      */
0153     size_t pcs[ 3 ];
0154 
0155     /**
0156      * @brief If this member is true, then the test action loop is executed.
0157      */
0158     bool in_action_loop;
0159 
0160     /**
0161      * @brief This member contains the next transition map index.
0162      */
0163     size_t index;
0164 
0165     /**
0166      * @brief This member contains the current transition map entry.
0167      */
0168     RtemsTimerReqCreate_Entry entry;
0169 
0170     /**
0171      * @brief If this member is true, then the current transition variant
0172      *   should be skipped.
0173      */
0174     bool skip;
0175   } Map;
0176 } RtemsTimerReqCreate_Context;
0177 
0178 static RtemsTimerReqCreate_Context
0179   RtemsTimerReqCreate_Instance;
0180 
0181 static const char * const RtemsTimerReqCreate_PreDesc_Name[] = {
0182   "Valid",
0183   "Invalid",
0184   "NA"
0185 };
0186 
0187 static const char * const RtemsTimerReqCreate_PreDesc_Id[] = {
0188   "Valid",
0189   "Null",
0190   "NA"
0191 };
0192 
0193 static const char * const RtemsTimerReqCreate_PreDesc_Free[] = {
0194   "Yes",
0195   "No",
0196   "NA"
0197 };
0198 
0199 static const char * const * const RtemsTimerReqCreate_PreDesc[] = {
0200   RtemsTimerReqCreate_PreDesc_Name,
0201   RtemsTimerReqCreate_PreDesc_Id,
0202   RtemsTimerReqCreate_PreDesc_Free,
0203   NULL
0204 };
0205 
0206 #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
0207 
0208 static rtems_status_code Create( void *arg, uint32_t *id )
0209 {
0210   return rtems_timer_create( rtems_build_name( 'S', 'I', 'Z', 'E' ), id );
0211 }
0212 
0213 static void RtemsTimerReqCreate_Pre_Name_Prepare(
0214   RtemsTimerReqCreate_Context *ctx,
0215   RtemsTimerReqCreate_Pre_Name state
0216 )
0217 {
0218   switch ( state ) {
0219     case RtemsTimerReqCreate_Pre_Name_Valid: {
0220       /*
0221        * While the ``name`` parameter is valid.
0222        */
0223       ctx->name = NAME;
0224       break;
0225     }
0226 
0227     case RtemsTimerReqCreate_Pre_Name_Invalid: {
0228       /*
0229        * While the ``name`` parameter is invalid.
0230        */
0231       ctx->name = 0;
0232       break;
0233     }
0234 
0235     case RtemsTimerReqCreate_Pre_Name_NA:
0236       break;
0237   }
0238 }
0239 
0240 static void RtemsTimerReqCreate_Pre_Id_Prepare(
0241   RtemsTimerReqCreate_Context *ctx,
0242   RtemsTimerReqCreate_Pre_Id   state
0243 )
0244 {
0245   switch ( state ) {
0246     case RtemsTimerReqCreate_Pre_Id_Valid: {
0247       /*
0248        * While the ``id`` parameter references an object of type rtems_id.
0249        */
0250       ctx->id = &ctx->id_value;
0251       break;
0252     }
0253 
0254     case RtemsTimerReqCreate_Pre_Id_Null: {
0255       /*
0256        * While the ``id`` parameter is NULL.
0257        */
0258       ctx->id = NULL;
0259       break;
0260     }
0261 
0262     case RtemsTimerReqCreate_Pre_Id_NA:
0263       break;
0264   }
0265 }
0266 
0267 static void RtemsTimerReqCreate_Pre_Free_Prepare(
0268   RtemsTimerReqCreate_Context *ctx,
0269   RtemsTimerReqCreate_Pre_Free state
0270 )
0271 {
0272   switch ( state ) {
0273     case RtemsTimerReqCreate_Pre_Free_Yes: {
0274       /*
0275        * While the system has at least one inactive timer object available.
0276        */
0277       /* Ensured by the test suite configuration */
0278       break;
0279     }
0280 
0281     case RtemsTimerReqCreate_Pre_Free_No: {
0282       /*
0283        * While the system has no inactive timer object available.
0284        */
0285       ctx->seized_objects = T_seize_objects( Create, NULL );
0286       break;
0287     }
0288 
0289     case RtemsTimerReqCreate_Pre_Free_NA:
0290       break;
0291   }
0292 }
0293 
0294 static void RtemsTimerReqCreate_Post_Status_Check(
0295   RtemsTimerReqCreate_Context    *ctx,
0296   RtemsTimerReqCreate_Post_Status state
0297 )
0298 {
0299   switch ( state ) {
0300     case RtemsTimerReqCreate_Post_Status_Ok: {
0301       /*
0302        * The return status of rtems_timer_create() shall be RTEMS_SUCCESSFUL.
0303        */
0304       T_rsc_success( ctx->status );
0305       break;
0306     }
0307 
0308     case RtemsTimerReqCreate_Post_Status_InvName: {
0309       /*
0310        * The return status of rtems_timer_create() shall be RTEMS_INVALID_NAME.
0311        */
0312       T_rsc( ctx->status, RTEMS_INVALID_NAME );
0313       break;
0314     }
0315 
0316     case RtemsTimerReqCreate_Post_Status_InvAddr: {
0317       /*
0318        * The return status of rtems_timer_create() shall be
0319        * RTEMS_INVALID_ADDRESS.
0320        */
0321       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0322       break;
0323     }
0324 
0325     case RtemsTimerReqCreate_Post_Status_TooMany: {
0326       /*
0327        * The return status of rtems_timer_create() shall be RTEMS_TOO_MANY.
0328        */
0329       T_rsc( ctx->status, RTEMS_TOO_MANY );
0330       break;
0331     }
0332 
0333     case RtemsTimerReqCreate_Post_Status_NA:
0334       break;
0335   }
0336 }
0337 
0338 static void RtemsTimerReqCreate_Post_Name_Check(
0339   RtemsTimerReqCreate_Context  *ctx,
0340   RtemsTimerReqCreate_Post_Name state
0341 )
0342 {
0343   rtems_status_code sc;
0344   rtems_id          id;
0345 
0346   switch ( state ) {
0347     case RtemsTimerReqCreate_Post_Name_Valid: {
0348       /*
0349        * The unique object name shall identify the timer created by the
0350        * rtems_timer_create() call.
0351        */
0352       id = 0;
0353       sc = rtems_timer_ident( NAME, &id );
0354       T_rsc_success( sc );
0355       T_eq_u32( id, ctx->id_value );
0356       break;
0357     }
0358 
0359     case RtemsTimerReqCreate_Post_Name_Invalid: {
0360       /*
0361        * The unique object name shall not identify a timer.
0362        */
0363       sc = rtems_timer_ident( NAME, &id );
0364       T_rsc( sc, RTEMS_INVALID_NAME );
0365       break;
0366     }
0367 
0368     case RtemsTimerReqCreate_Post_Name_NA:
0369       break;
0370   }
0371 }
0372 
0373 static void RtemsTimerReqCreate_Post_IdVar_Check(
0374   RtemsTimerReqCreate_Context   *ctx,
0375   RtemsTimerReqCreate_Post_IdVar state
0376 )
0377 {
0378   switch ( state ) {
0379     case RtemsTimerReqCreate_Post_IdVar_Set: {
0380       /*
0381        * The value of the object referenced by the ``id`` parameter shall be
0382        * set to the object identifier of the created timer after the return of
0383        * the rtems_timer_create() call.
0384        */
0385       T_eq_ptr( ctx->id, &ctx->id_value );
0386       T_ne_u32( ctx->id_value, INVALID_ID );
0387       break;
0388     }
0389 
0390     case RtemsTimerReqCreate_Post_IdVar_Nop: {
0391       /*
0392        * Objects referenced by the ``id`` parameter in past calls to
0393        * rtems_timer_create() shall not be accessed by the rtems_timer_create()
0394        * call.
0395        */
0396       T_eq_u32( ctx->id_value, INVALID_ID );
0397       break;
0398     }
0399 
0400     case RtemsTimerReqCreate_Post_IdVar_NA:
0401       break;
0402   }
0403 }
0404 
0405 static void RtemsTimerReqCreate_Setup( RtemsTimerReqCreate_Context *ctx )
0406 {
0407   memset( ctx, 0, sizeof( *ctx ) );
0408   ctx->id_value = INVALID_ID;
0409 }
0410 
0411 static void RtemsTimerReqCreate_Setup_Wrap( void *arg )
0412 {
0413   RtemsTimerReqCreate_Context *ctx;
0414 
0415   ctx = arg;
0416   ctx->Map.in_action_loop = false;
0417   RtemsTimerReqCreate_Setup( ctx );
0418 }
0419 
0420 static void RtemsTimerReqCreate_Action( RtemsTimerReqCreate_Context *ctx )
0421 {
0422   ctx->status = rtems_timer_create( ctx->name, ctx->id );
0423 }
0424 
0425 static void RtemsTimerReqCreate_Cleanup( RtemsTimerReqCreate_Context *ctx )
0426 {
0427   if ( ctx->id_value != INVALID_ID ) {
0428     rtems_status_code sc;
0429 
0430     sc = rtems_timer_delete( ctx->id_value );
0431     T_rsc_success( sc );
0432 
0433     ctx->id_value = INVALID_ID;
0434   }
0435 
0436   T_surrender_objects( &ctx->seized_objects, rtems_timer_delete );
0437 }
0438 
0439 static const RtemsTimerReqCreate_Entry
0440 RtemsTimerReqCreate_Entries[] = {
0441   { 0, 0, 0, 0, RtemsTimerReqCreate_Post_Status_InvName,
0442     RtemsTimerReqCreate_Post_Name_Invalid, RtemsTimerReqCreate_Post_IdVar_Nop },
0443   { 0, 0, 0, 0, RtemsTimerReqCreate_Post_Status_InvAddr,
0444     RtemsTimerReqCreate_Post_Name_Invalid, RtemsTimerReqCreate_Post_IdVar_Nop },
0445   { 0, 0, 0, 0, RtemsTimerReqCreate_Post_Status_Ok,
0446     RtemsTimerReqCreate_Post_Name_Valid, RtemsTimerReqCreate_Post_IdVar_Set },
0447   { 0, 0, 0, 0, RtemsTimerReqCreate_Post_Status_TooMany,
0448     RtemsTimerReqCreate_Post_Name_Invalid, RtemsTimerReqCreate_Post_IdVar_Nop }
0449 };
0450 
0451 static const uint8_t
0452 RtemsTimerReqCreate_Map[] = {
0453   2, 3, 1, 1, 0, 0, 0, 0
0454 };
0455 
0456 static size_t RtemsTimerReqCreate_Scope( void *arg, char *buf, size_t n )
0457 {
0458   RtemsTimerReqCreate_Context *ctx;
0459 
0460   ctx = arg;
0461 
0462   if ( ctx->Map.in_action_loop ) {
0463     return T_get_scope( RtemsTimerReqCreate_PreDesc, buf, n, ctx->Map.pcs );
0464   }
0465 
0466   return 0;
0467 }
0468 
0469 static T_fixture RtemsTimerReqCreate_Fixture = {
0470   .setup = RtemsTimerReqCreate_Setup_Wrap,
0471   .stop = NULL,
0472   .teardown = NULL,
0473   .scope = RtemsTimerReqCreate_Scope,
0474   .initial_context = &RtemsTimerReqCreate_Instance
0475 };
0476 
0477 static inline RtemsTimerReqCreate_Entry RtemsTimerReqCreate_PopEntry(
0478   RtemsTimerReqCreate_Context *ctx
0479 )
0480 {
0481   size_t index;
0482 
0483   index = ctx->Map.index;
0484   ctx->Map.index = index + 1;
0485   return RtemsTimerReqCreate_Entries[
0486     RtemsTimerReqCreate_Map[ index ]
0487   ];
0488 }
0489 
0490 static void RtemsTimerReqCreate_TestVariant( RtemsTimerReqCreate_Context *ctx )
0491 {
0492   RtemsTimerReqCreate_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0493   RtemsTimerReqCreate_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0494   RtemsTimerReqCreate_Pre_Free_Prepare( ctx, ctx->Map.pcs[ 2 ] );
0495   RtemsTimerReqCreate_Action( ctx );
0496   RtemsTimerReqCreate_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0497   RtemsTimerReqCreate_Post_Name_Check( ctx, ctx->Map.entry.Post_Name );
0498   RtemsTimerReqCreate_Post_IdVar_Check( ctx, ctx->Map.entry.Post_IdVar );
0499 }
0500 
0501 /**
0502  * @fn void T_case_body_RtemsTimerReqCreate( void )
0503  */
0504 T_TEST_CASE_FIXTURE( RtemsTimerReqCreate, &RtemsTimerReqCreate_Fixture )
0505 {
0506   RtemsTimerReqCreate_Context *ctx;
0507 
0508   ctx = T_fixture_context();
0509   ctx->Map.in_action_loop = true;
0510   ctx->Map.index = 0;
0511 
0512   for (
0513     ctx->Map.pcs[ 0 ] = RtemsTimerReqCreate_Pre_Name_Valid;
0514     ctx->Map.pcs[ 0 ] < RtemsTimerReqCreate_Pre_Name_NA;
0515     ++ctx->Map.pcs[ 0 ]
0516   ) {
0517     for (
0518       ctx->Map.pcs[ 1 ] = RtemsTimerReqCreate_Pre_Id_Valid;
0519       ctx->Map.pcs[ 1 ] < RtemsTimerReqCreate_Pre_Id_NA;
0520       ++ctx->Map.pcs[ 1 ]
0521     ) {
0522       for (
0523         ctx->Map.pcs[ 2 ] = RtemsTimerReqCreate_Pre_Free_Yes;
0524         ctx->Map.pcs[ 2 ] < RtemsTimerReqCreate_Pre_Free_NA;
0525         ++ctx->Map.pcs[ 2 ]
0526       ) {
0527         ctx->Map.entry = RtemsTimerReqCreate_PopEntry( ctx );
0528         RtemsTimerReqCreate_TestVariant( ctx );
0529         RtemsTimerReqCreate_Cleanup( ctx );
0530       }
0531     }
0532   }
0533 }
0534 
0535 /** @} */