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 ScoreSemReqSeizeTry
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 "tr-sem-seize-try.h"
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup ScoreSemReqSeizeTry spec:/score/sem/req/seize-try
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef struct {
0068   uint8_t Skip : 1;
0069   uint8_t Pre_Count_NA : 1;
0070   uint8_t Post_Status : 2;
0071   uint8_t Post_Count : 2;
0072 } ScoreSemReqSeizeTry_Entry;
0073 
0074 /**
0075  * @brief Test context for spec:/score/sem/req/seize-try test case.
0076  */
0077 typedef struct {
0078   /**
0079    * @brief This member specifies the semaphore count before the directive
0080    *   call.
0081    */
0082   uint32_t count_before;
0083 
0084   /**
0085    * @brief This member contains the return status of the directive call.
0086    */
0087   Status_Control status;
0088 
0089   /**
0090    * @brief This member contains the semaphore count after the directive call.
0091    */
0092   uint32_t count_after;
0093 
0094   /**
0095    * @brief This member contains a copy of the corresponding
0096    *   ScoreSemReqSeizeTry_Run() parameter.
0097    */
0098   TQSemContext *tq_ctx;
0099 
0100   struct {
0101     /**
0102      * @brief This member defines the pre-condition states for the next action.
0103      */
0104     size_t pcs[ 1 ];
0105 
0106     /**
0107      * @brief If this member is true, then the test action loop is executed.
0108      */
0109     bool in_action_loop;
0110 
0111     /**
0112      * @brief This member contains the next transition map index.
0113      */
0114     size_t index;
0115 
0116     /**
0117      * @brief This member contains the current transition map entry.
0118      */
0119     ScoreSemReqSeizeTry_Entry entry;
0120 
0121     /**
0122      * @brief If this member is true, then the current transition variant
0123      *   should be skipped.
0124      */
0125     bool skip;
0126   } Map;
0127 } ScoreSemReqSeizeTry_Context;
0128 
0129 static ScoreSemReqSeizeTry_Context
0130   ScoreSemReqSeizeTry_Instance;
0131 
0132 static const char * const ScoreSemReqSeizeTry_PreDesc_Count[] = {
0133   "Zero",
0134   "Positive",
0135   "NA"
0136 };
0137 
0138 static const char * const * const ScoreSemReqSeizeTry_PreDesc[] = {
0139   ScoreSemReqSeizeTry_PreDesc_Count,
0140   NULL
0141 };
0142 
0143 typedef ScoreSemReqSeizeTry_Context Context;
0144 
0145 static Status_Control Status( const Context *ctx, Status_Control status )
0146 {
0147   return TQConvertStatus( &ctx->tq_ctx->base, status );
0148 }
0149 
0150 static void ScoreSemReqSeizeTry_Pre_Count_Prepare(
0151   ScoreSemReqSeizeTry_Context  *ctx,
0152   ScoreSemReqSeizeTry_Pre_Count state
0153 )
0154 {
0155   switch ( state ) {
0156     case ScoreSemReqSeizeTry_Pre_Count_Zero: {
0157       /*
0158        * While the count of the semaphore is zero.
0159        */
0160       ctx->count_before = 0;
0161       break;
0162     }
0163 
0164     case ScoreSemReqSeizeTry_Pre_Count_Positive: {
0165       /*
0166        * While the count of the semaphore is greater than zero.
0167        */
0168       ctx->count_before = 1;
0169       break;
0170     }
0171 
0172     case ScoreSemReqSeizeTry_Pre_Count_NA:
0173       break;
0174   }
0175 }
0176 
0177 static void ScoreSemReqSeizeTry_Post_Status_Check(
0178   ScoreSemReqSeizeTry_Context    *ctx,
0179   ScoreSemReqSeizeTry_Post_Status state
0180 )
0181 {
0182   switch ( state ) {
0183     case ScoreSemReqSeizeTry_Post_Status_Ok: {
0184       /*
0185        * The return status of the directive call shall be derived from
0186        * STATUS_SUCCESSFUL.
0187        */
0188       T_eq_int( ctx->status, Status( ctx, STATUS_SUCCESSFUL ) );
0189       break;
0190     }
0191 
0192     case ScoreSemReqSeizeTry_Post_Status_Unsat: {
0193       /*
0194        * The return status of the directive call shall be derived from
0195        * STATUS_UNSATISFIED.
0196        */
0197       T_eq_int( ctx->status, Status( ctx, STATUS_UNSATISFIED ) );
0198       break;
0199     }
0200 
0201     case ScoreSemReqSeizeTry_Post_Status_NA:
0202       break;
0203   }
0204 }
0205 
0206 static void ScoreSemReqSeizeTry_Post_Count_Check(
0207   ScoreSemReqSeizeTry_Context   *ctx,
0208   ScoreSemReqSeizeTry_Post_Count state
0209 )
0210 {
0211   switch ( state ) {
0212     case ScoreSemReqSeizeTry_Post_Count_Nop: {
0213       /*
0214        * The count of the semaphore shall not be modified.
0215        */
0216       T_eq_u32( ctx->count_after, ctx->count_before );
0217       break;
0218     }
0219 
0220     case ScoreSemReqSeizeTry_Post_Count_MinusOne: {
0221       /*
0222        * The count of the semaphore shall be decremented by one.
0223        */
0224       T_eq_u32( ctx->count_after, ctx->count_before - 1 );
0225       break;
0226     }
0227 
0228     case ScoreSemReqSeizeTry_Post_Count_NA:
0229       break;
0230   }
0231 }
0232 
0233 static void ScoreSemReqSeizeTry_Action( ScoreSemReqSeizeTry_Context *ctx )
0234 {
0235   TQSemSetCount( ctx->tq_ctx, ctx->count_before );
0236   ctx->status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
0237   ctx->count_after = TQSemGetCount( ctx->tq_ctx );
0238 }
0239 
0240 static const ScoreSemReqSeizeTry_Entry
0241 ScoreSemReqSeizeTry_Entries[] = {
0242   { 0, 0, ScoreSemReqSeizeTry_Post_Status_Unsat,
0243     ScoreSemReqSeizeTry_Post_Count_Nop },
0244   { 0, 0, ScoreSemReqSeizeTry_Post_Status_Ok,
0245     ScoreSemReqSeizeTry_Post_Count_MinusOne }
0246 };
0247 
0248 static const uint8_t
0249 ScoreSemReqSeizeTry_Map[] = {
0250   0, 1
0251 };
0252 
0253 static size_t ScoreSemReqSeizeTry_Scope( void *arg, char *buf, size_t n )
0254 {
0255   ScoreSemReqSeizeTry_Context *ctx;
0256 
0257   ctx = arg;
0258 
0259   if ( ctx->Map.in_action_loop ) {
0260     return T_get_scope( ScoreSemReqSeizeTry_PreDesc, buf, n, ctx->Map.pcs );
0261   }
0262 
0263   return 0;
0264 }
0265 
0266 static T_fixture ScoreSemReqSeizeTry_Fixture = {
0267   .setup = NULL,
0268   .stop = NULL,
0269   .teardown = NULL,
0270   .scope = ScoreSemReqSeizeTry_Scope,
0271   .initial_context = &ScoreSemReqSeizeTry_Instance
0272 };
0273 
0274 static inline ScoreSemReqSeizeTry_Entry ScoreSemReqSeizeTry_PopEntry(
0275   ScoreSemReqSeizeTry_Context *ctx
0276 )
0277 {
0278   size_t index;
0279 
0280   index = ctx->Map.index;
0281   ctx->Map.index = index + 1;
0282   return ScoreSemReqSeizeTry_Entries[
0283     ScoreSemReqSeizeTry_Map[ index ]
0284   ];
0285 }
0286 
0287 static void ScoreSemReqSeizeTry_TestVariant( ScoreSemReqSeizeTry_Context *ctx )
0288 {
0289   ScoreSemReqSeizeTry_Pre_Count_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0290   ScoreSemReqSeizeTry_Action( ctx );
0291   ScoreSemReqSeizeTry_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0292   ScoreSemReqSeizeTry_Post_Count_Check( ctx, ctx->Map.entry.Post_Count );
0293 }
0294 
0295 static T_fixture_node ScoreSemReqSeizeTry_Node;
0296 
0297 static T_remark ScoreSemReqSeizeTry_Remark = {
0298   .next = NULL,
0299   .remark = "ScoreSemReqSeizeTry"
0300 };
0301 
0302 void ScoreSemReqSeizeTry_Run( TQSemContext *tq_ctx )
0303 {
0304   ScoreSemReqSeizeTry_Context *ctx;
0305 
0306   ctx = &ScoreSemReqSeizeTry_Instance;
0307   ctx->tq_ctx = tq_ctx;
0308 
0309   ctx = T_push_fixture(
0310     &ScoreSemReqSeizeTry_Node,
0311     &ScoreSemReqSeizeTry_Fixture
0312   );
0313   ctx->Map.in_action_loop = true;
0314   ctx->Map.index = 0;
0315 
0316   for (
0317     ctx->Map.pcs[ 0 ] = ScoreSemReqSeizeTry_Pre_Count_Zero;
0318     ctx->Map.pcs[ 0 ] < ScoreSemReqSeizeTry_Pre_Count_NA;
0319     ++ctx->Map.pcs[ 0 ]
0320   ) {
0321     ctx->Map.entry = ScoreSemReqSeizeTry_PopEntry( ctx );
0322     ScoreSemReqSeizeTry_TestVariant( ctx );
0323   }
0324 
0325   T_add_remark( &ScoreSemReqSeizeTry_Remark );
0326   T_pop_fixture();
0327 }
0328 
0329 /** @} */