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 ScoreSemReqSeizeWait
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/score/statesimpl.h>
0056 
0057 #include "tr-sem-seize-wait.h"
0058 #include "tr-tq-enqueue-fifo.h"
0059 #include "tr-tq-enqueue-priority.h"
0060 
0061 #include <rtems/test.h>
0062 
0063 /**
0064  * @defgroup ScoreSemReqSeizeWait spec:/score/sem/req/seize-wait
0065  *
0066  * @ingroup TestsuitesValidationNoClock0
0067  *
0068  * @{
0069  */
0070 
0071 typedef struct {
0072   uint8_t Skip : 1;
0073   uint8_t Pre_Count_NA : 1;
0074   uint8_t Post_Status : 2;
0075   uint8_t Post_Count : 2;
0076   uint8_t Post_Timer : 2;
0077 } ScoreSemReqSeizeWait_Entry;
0078 
0079 /**
0080  * @brief Test context for spec:/score/sem/req/seize-wait test case.
0081  */
0082 typedef struct {
0083   /**
0084    * @brief This member contains a copy of the corresponding
0085    *   ScoreSemReqSeizeWait_Run() parameter.
0086    */
0087   TQSemContext *tq_ctx;
0088 
0089   struct {
0090     /**
0091      * @brief This member defines the pre-condition states for the next action.
0092      */
0093     size_t pcs[ 1 ];
0094 
0095     /**
0096      * @brief If this member is true, then the test action loop is executed.
0097      */
0098     bool in_action_loop;
0099 
0100     /**
0101      * @brief This member contains the next transition map index.
0102      */
0103     size_t index;
0104 
0105     /**
0106      * @brief This member contains the current transition map entry.
0107      */
0108     ScoreSemReqSeizeWait_Entry entry;
0109 
0110     /**
0111      * @brief If this member is true, then the current transition variant
0112      *   should be skipped.
0113      */
0114     bool skip;
0115   } Map;
0116 } ScoreSemReqSeizeWait_Context;
0117 
0118 static ScoreSemReqSeizeWait_Context
0119   ScoreSemReqSeizeWait_Instance;
0120 
0121 static const char * const ScoreSemReqSeizeWait_PreDesc_Count[] = {
0122   "Zero",
0123   "Positive",
0124   "NA"
0125 };
0126 
0127 static const char * const * const ScoreSemReqSeizeWait_PreDesc[] = {
0128   ScoreSemReqSeizeWait_PreDesc_Count,
0129   NULL
0130 };
0131 
0132 typedef ScoreSemReqSeizeWait_Context Context;
0133 
0134 static Status_Control Status( const Context *ctx, Status_Control status )
0135 {
0136   return TQConvertStatus( &ctx->tq_ctx->base, status );
0137 }
0138 
0139 static void GetProperties( TQContext *base, TQWorkerKind enqueued_worker )
0140 {
0141   TQSemContext        *ctx;
0142   T_thread_timer_state timer_state;
0143 
0144   ctx = (TQSemContext *) base;
0145   T_eq_u32(
0146     ctx->base.worker_tcb[ enqueued_worker ]->current_state,
0147     STATES_WAITING_FOR_SEMAPHORE
0148   );
0149 
0150   timer_state = T_get_thread_timer_state(
0151     ctx->base.worker_id[ enqueued_worker ]
0152   );
0153 
0154   if ( base->wait == TQ_WAIT_TIMED ) {
0155     T_eq_int( timer_state, T_THREAD_TIMER_SCHEDULED );
0156   } else {
0157     T_eq_int( timer_state, T_THREAD_TIMER_INACTIVE );
0158   }
0159 
0160   T_eq_u32( TQSemGetCount( ctx ), 0 );
0161 }
0162 
0163 static void ScoreSemReqSeizeWait_Pre_Count_Prepare(
0164   ScoreSemReqSeizeWait_Context  *ctx,
0165   ScoreSemReqSeizeWait_Pre_Count state
0166 )
0167 {
0168   switch ( state ) {
0169     case ScoreSemReqSeizeWait_Pre_Count_Zero: {
0170       /*
0171        * While the count of the semaphore is zero.
0172        */
0173       /* Done by TQEnqueuePrepareDefault() */
0174       break;
0175     }
0176 
0177     case ScoreSemReqSeizeWait_Pre_Count_Positive: {
0178       /*
0179        * While the count of the semaphore is greater than zero.
0180        */
0181       TQSemSetCount( ctx->tq_ctx, 1 );
0182       break;
0183     }
0184 
0185     case ScoreSemReqSeizeWait_Pre_Count_NA:
0186       break;
0187   }
0188 }
0189 
0190 static void ScoreSemReqSeizeWait_Post_Status_Check(
0191   ScoreSemReqSeizeWait_Context    *ctx,
0192   ScoreSemReqSeizeWait_Post_Status state
0193 )
0194 {
0195   Status_Control status;
0196 
0197   switch ( state ) {
0198     case ScoreSemReqSeizeWait_Post_Status_Ok: {
0199       /*
0200        * The return status of the directive call shall be derived from
0201        * STATUS_SUCCESSFUL.
0202        */
0203       status = TQEnqueue( &ctx->tq_ctx->base, ctx->tq_ctx->base.wait );
0204       T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
0205       break;
0206     }
0207 
0208     case ScoreSemReqSeizeWait_Post_Status_Enqueued: {
0209       /*
0210        * Where the thread queue uses the FIFO discipline, the calling thread
0211        * shall be enqueued in FIFO order.
0212        *
0213        * Where the thread queue uses the priority discipline, the calling
0214        * thread shall be enqueued in priority order.
0215        */
0216       switch ( ctx->tq_ctx->base.discipline ) {
0217         case TQ_FIFO:
0218           ScoreTqReqEnqueueFifo_Run( &ctx->tq_ctx->base );
0219           break;
0220         case TQ_PRIORITY:
0221           ScoreTqReqEnqueuePriority_Run( &ctx->tq_ctx->base );
0222           break;
0223         default:
0224           T_unreachable();
0225           break;
0226       }
0227       break;
0228     }
0229 
0230     case ScoreSemReqSeizeWait_Post_Status_NA:
0231       break;
0232   }
0233 }
0234 
0235 static void ScoreSemReqSeizeWait_Post_Count_Check(
0236   ScoreSemReqSeizeWait_Context   *ctx,
0237   ScoreSemReqSeizeWait_Post_Count state
0238 )
0239 {
0240   switch ( state ) {
0241     case ScoreSemReqSeizeWait_Post_Count_Nop: {
0242       /*
0243        * The count of the semaphore shall not be modified.
0244        */
0245       /* Checked by GetProperties() */
0246       break;
0247     }
0248 
0249     case ScoreSemReqSeizeWait_Post_Count_MinusOne: {
0250       /*
0251        * The count of the semaphore shall be decremented by one.
0252        */
0253       T_eq_u32( TQSemGetCount( ctx->tq_ctx ), 0 );
0254       break;
0255     }
0256 
0257     case ScoreSemReqSeizeWait_Post_Count_NA:
0258       break;
0259   }
0260 }
0261 
0262 static void ScoreSemReqSeizeWait_Post_Timer_Check(
0263   ScoreSemReqSeizeWait_Context   *ctx,
0264   ScoreSemReqSeizeWait_Post_Timer state
0265 )
0266 {
0267   switch ( state ) {
0268     case ScoreSemReqSeizeWait_Post_Timer_Optional: {
0269       /*
0270        * Where the directive was called with a timeout in clock ticks, the
0271        * thread timer of the calling task shall fire after the specified clock
0272        * ticks.
0273        *
0274        * Where the directive was called without a timeout, the thread timer of
0275        * the calling task shall be inactive.
0276        */
0277       /* Checked by GetProperties() */
0278       break;
0279     }
0280 
0281     case ScoreSemReqSeizeWait_Post_Timer_No: {
0282       /*
0283        * The thread timer of the calling task shall be inactive.
0284        */
0285       T_eq_int(
0286         T_get_thread_timer_state( RTEMS_SELF ),
0287         T_THREAD_TIMER_INACTIVE
0288       );
0289       break;
0290     }
0291 
0292     case ScoreSemReqSeizeWait_Post_Timer_NA:
0293       break;
0294   }
0295 }
0296 
0297 static void ScoreSemReqSeizeWait_Prepare( ScoreSemReqSeizeWait_Context *ctx )
0298 {
0299   ctx->tq_ctx->base.enqueue_prepare = TQEnqueuePrepareDefault;
0300   ctx->tq_ctx->base.enqueue_done = TQEnqueueDoneDefault;
0301   ctx->tq_ctx->base.get_properties = GetProperties;
0302 }
0303 
0304 static void ScoreSemReqSeizeWait_Action( ScoreSemReqSeizeWait_Context *ctx )
0305 {
0306   /* Action performed by Status post-condition */
0307 }
0308 
0309 static const ScoreSemReqSeizeWait_Entry
0310 ScoreSemReqSeizeWait_Entries[] = {
0311   { 0, 0, ScoreSemReqSeizeWait_Post_Status_Enqueued,
0312     ScoreSemReqSeizeWait_Post_Count_Nop,
0313     ScoreSemReqSeizeWait_Post_Timer_Optional },
0314   { 0, 0, ScoreSemReqSeizeWait_Post_Status_Ok,
0315     ScoreSemReqSeizeWait_Post_Count_MinusOne,
0316     ScoreSemReqSeizeWait_Post_Timer_No }
0317 };
0318 
0319 static const uint8_t
0320 ScoreSemReqSeizeWait_Map[] = {
0321   0, 1
0322 };
0323 
0324 static size_t ScoreSemReqSeizeWait_Scope( void *arg, char *buf, size_t n )
0325 {
0326   ScoreSemReqSeizeWait_Context *ctx;
0327 
0328   ctx = arg;
0329 
0330   if ( ctx->Map.in_action_loop ) {
0331     return T_get_scope( ScoreSemReqSeizeWait_PreDesc, buf, n, ctx->Map.pcs );
0332   }
0333 
0334   return 0;
0335 }
0336 
0337 static T_fixture ScoreSemReqSeizeWait_Fixture = {
0338   .setup = NULL,
0339   .stop = NULL,
0340   .teardown = NULL,
0341   .scope = ScoreSemReqSeizeWait_Scope,
0342   .initial_context = &ScoreSemReqSeizeWait_Instance
0343 };
0344 
0345 static inline ScoreSemReqSeizeWait_Entry ScoreSemReqSeizeWait_PopEntry(
0346   ScoreSemReqSeizeWait_Context *ctx
0347 )
0348 {
0349   size_t index;
0350 
0351   index = ctx->Map.index;
0352   ctx->Map.index = index + 1;
0353   return ScoreSemReqSeizeWait_Entries[
0354     ScoreSemReqSeizeWait_Map[ index ]
0355   ];
0356 }
0357 
0358 static void ScoreSemReqSeizeWait_TestVariant(
0359   ScoreSemReqSeizeWait_Context *ctx
0360 )
0361 {
0362   ScoreSemReqSeizeWait_Pre_Count_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0363   ScoreSemReqSeizeWait_Action( ctx );
0364   ScoreSemReqSeizeWait_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0365   ScoreSemReqSeizeWait_Post_Count_Check( ctx, ctx->Map.entry.Post_Count );
0366   ScoreSemReqSeizeWait_Post_Timer_Check( ctx, ctx->Map.entry.Post_Timer );
0367 }
0368 
0369 static T_fixture_node ScoreSemReqSeizeWait_Node;
0370 
0371 static T_remark ScoreSemReqSeizeWait_Remark = {
0372   .next = NULL,
0373   .remark = "ScoreSemReqSeizeWait"
0374 };
0375 
0376 void ScoreSemReqSeizeWait_Run( TQSemContext *tq_ctx )
0377 {
0378   ScoreSemReqSeizeWait_Context *ctx;
0379 
0380   ctx = &ScoreSemReqSeizeWait_Instance;
0381   ctx->tq_ctx = tq_ctx;
0382 
0383   ctx = T_push_fixture(
0384     &ScoreSemReqSeizeWait_Node,
0385     &ScoreSemReqSeizeWait_Fixture
0386   );
0387   ctx->Map.in_action_loop = true;
0388   ctx->Map.index = 0;
0389 
0390   for (
0391     ctx->Map.pcs[ 0 ] = ScoreSemReqSeizeWait_Pre_Count_Zero;
0392     ctx->Map.pcs[ 0 ] < ScoreSemReqSeizeWait_Pre_Count_NA;
0393     ++ctx->Map.pcs[ 0 ]
0394   ) {
0395     ctx->Map.entry = ScoreSemReqSeizeWait_PopEntry( ctx );
0396     ScoreSemReqSeizeWait_Prepare( ctx );
0397     ScoreSemReqSeizeWait_TestVariant( ctx );
0398   }
0399 
0400   T_add_remark( &ScoreSemReqSeizeWait_Remark );
0401   T_pop_fixture();
0402 }
0403 
0404 /** @} */