Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsPartReqGetBuffer
0007  */
0008 
0009 /*
0010  * Copyright (C) 2020 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 <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsPartReqGetBuffer spec:/rtems/part/req/get-buffer
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef enum {
0068   RtemsPartReqGetBuffer_Pre_Id_NoObj,
0069   RtemsPartReqGetBuffer_Pre_Id_Part,
0070   RtemsPartReqGetBuffer_Pre_Id_NA
0071 } RtemsPartReqGetBuffer_Pre_Id;
0072 
0073 typedef enum {
0074   RtemsPartReqGetBuffer_Pre_Buf_Valid,
0075   RtemsPartReqGetBuffer_Pre_Buf_Null,
0076   RtemsPartReqGetBuffer_Pre_Buf_NA
0077 } RtemsPartReqGetBuffer_Pre_Buf;
0078 
0079 typedef enum {
0080   RtemsPartReqGetBuffer_Pre_Avail_Yes,
0081   RtemsPartReqGetBuffer_Pre_Avail_No,
0082   RtemsPartReqGetBuffer_Pre_Avail_NA
0083 } RtemsPartReqGetBuffer_Pre_Avail;
0084 
0085 typedef enum {
0086   RtemsPartReqGetBuffer_Post_Status_Ok,
0087   RtemsPartReqGetBuffer_Post_Status_InvId,
0088   RtemsPartReqGetBuffer_Post_Status_InvAddr,
0089   RtemsPartReqGetBuffer_Post_Status_Unsat,
0090   RtemsPartReqGetBuffer_Post_Status_NA
0091 } RtemsPartReqGetBuffer_Post_Status;
0092 
0093 typedef enum {
0094   RtemsPartReqGetBuffer_Post_BufVar_Set,
0095   RtemsPartReqGetBuffer_Post_BufVar_Nop,
0096   RtemsPartReqGetBuffer_Post_BufVar_NA
0097 } RtemsPartReqGetBuffer_Post_BufVar;
0098 
0099 typedef struct {
0100   uint16_t Skip : 1;
0101   uint16_t Pre_Id_NA : 1;
0102   uint16_t Pre_Buf_NA : 1;
0103   uint16_t Pre_Avail_NA : 1;
0104   uint16_t Post_Status : 3;
0105   uint16_t Post_BufVar : 2;
0106 } RtemsPartReqGetBuffer_Entry;
0107 
0108 /**
0109  * @brief Test context for spec:/rtems/part/req/get-buffer test case.
0110  */
0111 typedef struct {
0112   rtems_status_code status;
0113 
0114   rtems_id id;
0115 
0116   rtems_id id_value;
0117 
0118   void **buffer;
0119 
0120   void *buffer_pointer;
0121 
0122   void *stolen_buffer;
0123 
0124   struct {
0125     /**
0126      * @brief This member defines the pre-condition states for the next action.
0127      */
0128     size_t pcs[ 3 ];
0129 
0130     /**
0131      * @brief If this member is true, then the test action loop is executed.
0132      */
0133     bool in_action_loop;
0134 
0135     /**
0136      * @brief This member contains the next transition map index.
0137      */
0138     size_t index;
0139 
0140     /**
0141      * @brief This member contains the current transition map entry.
0142      */
0143     RtemsPartReqGetBuffer_Entry entry;
0144 
0145     /**
0146      * @brief If this member is true, then the current transition variant
0147      *   should be skipped.
0148      */
0149     bool skip;
0150   } Map;
0151 } RtemsPartReqGetBuffer_Context;
0152 
0153 static RtemsPartReqGetBuffer_Context
0154   RtemsPartReqGetBuffer_Instance;
0155 
0156 static const char * const RtemsPartReqGetBuffer_PreDesc_Id[] = {
0157   "NoObj",
0158   "Part",
0159   "NA"
0160 };
0161 
0162 static const char * const RtemsPartReqGetBuffer_PreDesc_Buf[] = {
0163   "Valid",
0164   "Null",
0165   "NA"
0166 };
0167 
0168 static const char * const RtemsPartReqGetBuffer_PreDesc_Avail[] = {
0169   "Yes",
0170   "No",
0171   "NA"
0172 };
0173 
0174 static const char * const * const RtemsPartReqGetBuffer_PreDesc[] = {
0175   RtemsPartReqGetBuffer_PreDesc_Id,
0176   RtemsPartReqGetBuffer_PreDesc_Buf,
0177   RtemsPartReqGetBuffer_PreDesc_Avail,
0178   NULL
0179 };
0180 
0181 #define BUFFER_COUNT 1
0182 
0183 #define BUFFER_SIZE ( 2 * sizeof( void * ) )
0184 
0185 static RTEMS_ALIGNED( RTEMS_PARTITION_ALIGNMENT ) uint8_t
0186   buffers[ BUFFER_COUNT ][ BUFFER_SIZE ];
0187 
0188 static void RtemsPartReqGetBuffer_Pre_Id_Prepare(
0189   RtemsPartReqGetBuffer_Context *ctx,
0190   RtemsPartReqGetBuffer_Pre_Id   state
0191 )
0192 {
0193   switch ( state ) {
0194     case RtemsPartReqGetBuffer_Pre_Id_NoObj: {
0195       /*
0196        * While the ``id`` parameter is not associated with a partition.
0197        */
0198       ctx->id = 0xffffffff;
0199       break;
0200     }
0201 
0202     case RtemsPartReqGetBuffer_Pre_Id_Part: {
0203       /*
0204        * While the ``id`` parameter is associated with a partition.
0205        */
0206       ctx->id = ctx->id_value;
0207       break;
0208     }
0209 
0210     case RtemsPartReqGetBuffer_Pre_Id_NA:
0211       break;
0212   }
0213 }
0214 
0215 static void RtemsPartReqGetBuffer_Pre_Buf_Prepare(
0216   RtemsPartReqGetBuffer_Context *ctx,
0217   RtemsPartReqGetBuffer_Pre_Buf  state
0218 )
0219 {
0220   switch ( state ) {
0221     case RtemsPartReqGetBuffer_Pre_Buf_Valid: {
0222       /*
0223        * While the ``buffer`` parameter references an object of type ``void
0224        * *``.
0225        */
0226       ctx->buffer = &ctx->buffer_pointer;
0227       break;
0228     }
0229 
0230     case RtemsPartReqGetBuffer_Pre_Buf_Null: {
0231       /*
0232        * While the ``buffer`` parameter is NULL.
0233        */
0234       ctx->buffer = NULL;
0235       break;
0236     }
0237 
0238     case RtemsPartReqGetBuffer_Pre_Buf_NA:
0239       break;
0240   }
0241 }
0242 
0243 static void RtemsPartReqGetBuffer_Pre_Avail_Prepare(
0244   RtemsPartReqGetBuffer_Context  *ctx,
0245   RtemsPartReqGetBuffer_Pre_Avail state
0246 )
0247 {
0248   rtems_status_code sc;
0249 
0250   switch ( state ) {
0251     case RtemsPartReqGetBuffer_Pre_Avail_Yes: {
0252       /*
0253        * While the partition has at least one free buffer available.
0254        */
0255       /* Nothing to do */
0256       break;
0257     }
0258 
0259     case RtemsPartReqGetBuffer_Pre_Avail_No: {
0260       /*
0261        * While the partition does not have a buffer available.
0262        */
0263       sc = rtems_partition_get_buffer( ctx->id_value, &ctx->stolen_buffer );
0264       T_rsc_success( sc );
0265       break;
0266     }
0267 
0268     case RtemsPartReqGetBuffer_Pre_Avail_NA:
0269       break;
0270   }
0271 }
0272 
0273 static void RtemsPartReqGetBuffer_Post_Status_Check(
0274   RtemsPartReqGetBuffer_Context    *ctx,
0275   RtemsPartReqGetBuffer_Post_Status state
0276 )
0277 {
0278   switch ( state ) {
0279     case RtemsPartReqGetBuffer_Post_Status_Ok: {
0280       /*
0281        * The return status of rtems_partition_get_buffer() shall be
0282        * RTEMS_SUCCESSFUL.
0283        */
0284       T_rsc_success( ctx->status );
0285       T_eq_ptr( ctx->buffer_pointer, buffers );
0286       break;
0287     }
0288 
0289     case RtemsPartReqGetBuffer_Post_Status_InvId: {
0290       /*
0291        * The return status of rtems_partition_get_buffer() shall be
0292        * RTEMS_INVALID_ID.
0293        */
0294       T_rsc( ctx->status, RTEMS_INVALID_ID );
0295       T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0296       break;
0297     }
0298 
0299     case RtemsPartReqGetBuffer_Post_Status_InvAddr: {
0300       /*
0301        * The return status of rtems_partition_get_buffer() shall be
0302        * RTEMS_INVALID_ADDRESS.
0303        */
0304       T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
0305       break;
0306     }
0307 
0308     case RtemsPartReqGetBuffer_Post_Status_Unsat: {
0309       /*
0310        * The return status of rtems_partition_get_buffer() shall be
0311        * RTEMS_UNSATISFIED.
0312        */
0313       T_rsc( ctx->status, RTEMS_UNSATISFIED );
0314       T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0315       break;
0316     }
0317 
0318     case RtemsPartReqGetBuffer_Post_Status_NA:
0319       break;
0320   }
0321 }
0322 
0323 static void RtemsPartReqGetBuffer_Post_BufVar_Check(
0324   RtemsPartReqGetBuffer_Context    *ctx,
0325   RtemsPartReqGetBuffer_Post_BufVar state
0326 )
0327 {
0328   switch ( state ) {
0329     case RtemsPartReqGetBuffer_Post_BufVar_Set: {
0330       /*
0331        * The value of the object referenced by the ``starting_address``
0332        * parameter shall be set to the object identifier of the begin address
0333        * of the returned buffer after the return of the
0334        * rtems_partition_create() call.
0335        */
0336       T_eq_ptr( ctx->buffer, &ctx->buffer_pointer );
0337       T_eq_ptr( ctx->buffer_pointer, buffers );
0338       break;
0339     }
0340 
0341     case RtemsPartReqGetBuffer_Post_BufVar_Nop: {
0342       /*
0343        * Objects referenced by the ``buffer`` parameter in past calls to
0344        * rtems_partition_get_buffer() shall not be accessed by the
0345        * rtems_partition_get_buffer() call.
0346        */
0347       T_eq_ptr( ctx->buffer_pointer, (void *) (uintptr_t) 1 );
0348       break;
0349     }
0350 
0351     case RtemsPartReqGetBuffer_Post_BufVar_NA:
0352       break;
0353   }
0354 }
0355 
0356 static void RtemsPartReqGetBuffer_Setup( RtemsPartReqGetBuffer_Context *ctx )
0357 {
0358   rtems_status_code sc;
0359 
0360   ctx->id_value = 0;
0361   sc = rtems_partition_create(
0362     rtems_build_name( 'N', 'A', 'M', 'E' ),
0363     buffers,
0364     sizeof( buffers ),
0365     sizeof( buffers[ 0 ] ),
0366     RTEMS_DEFAULT_ATTRIBUTES,
0367     &ctx->id_value
0368   );
0369   T_assert_rsc_success( sc );
0370 }
0371 
0372 static void RtemsPartReqGetBuffer_Setup_Wrap( void *arg )
0373 {
0374   RtemsPartReqGetBuffer_Context *ctx;
0375 
0376   ctx = arg;
0377   ctx->Map.in_action_loop = false;
0378   RtemsPartReqGetBuffer_Setup( ctx );
0379 }
0380 
0381 static void RtemsPartReqGetBuffer_Teardown(
0382   RtemsPartReqGetBuffer_Context *ctx
0383 )
0384 {
0385   if ( ctx->id_value != 0 ) {
0386     rtems_status_code sc;
0387 
0388     sc = rtems_partition_delete( ctx->id_value );
0389     T_rsc_success( sc );
0390   }
0391 }
0392 
0393 static void RtemsPartReqGetBuffer_Teardown_Wrap( void *arg )
0394 {
0395   RtemsPartReqGetBuffer_Context *ctx;
0396 
0397   ctx = arg;
0398   ctx->Map.in_action_loop = false;
0399   RtemsPartReqGetBuffer_Teardown( ctx );
0400 }
0401 
0402 static void RtemsPartReqGetBuffer_Prepare( RtemsPartReqGetBuffer_Context *ctx )
0403 {
0404   ctx->buffer_pointer = (void *) (uintptr_t) 1;
0405   ctx->stolen_buffer = NULL;
0406 }
0407 
0408 static void RtemsPartReqGetBuffer_Action( RtemsPartReqGetBuffer_Context *ctx )
0409 {
0410   ctx->status = rtems_partition_get_buffer( ctx->id, ctx->buffer );
0411 }
0412 
0413 static void RtemsPartReqGetBuffer_Cleanup( RtemsPartReqGetBuffer_Context *ctx )
0414 {
0415   rtems_status_code sc;
0416 
0417   if ( (uintptr_t) ctx->buffer_pointer != 1 ) {
0418     sc = rtems_partition_return_buffer( ctx->id_value, ctx->buffer_pointer );
0419     T_rsc_success( sc );
0420   }
0421 
0422   if ( ctx->stolen_buffer != NULL ) {
0423     sc = rtems_partition_return_buffer( ctx->id_value, ctx->stolen_buffer );
0424     T_rsc_success( sc );
0425   }
0426 }
0427 
0428 static const RtemsPartReqGetBuffer_Entry
0429 RtemsPartReqGetBuffer_Entries[] = {
0430   { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_InvAddr,
0431     RtemsPartReqGetBuffer_Post_BufVar_Nop },
0432   { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_InvId,
0433     RtemsPartReqGetBuffer_Post_BufVar_Nop },
0434   { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_Ok,
0435     RtemsPartReqGetBuffer_Post_BufVar_Set },
0436   { 0, 0, 0, 0, RtemsPartReqGetBuffer_Post_Status_Unsat,
0437     RtemsPartReqGetBuffer_Post_BufVar_Nop }
0438 };
0439 
0440 static const uint8_t
0441 RtemsPartReqGetBuffer_Map[] = {
0442   1, 1, 0, 0, 2, 3, 0, 0
0443 };
0444 
0445 static size_t RtemsPartReqGetBuffer_Scope( void *arg, char *buf, size_t n )
0446 {
0447   RtemsPartReqGetBuffer_Context *ctx;
0448 
0449   ctx = arg;
0450 
0451   if ( ctx->Map.in_action_loop ) {
0452     return T_get_scope( RtemsPartReqGetBuffer_PreDesc, buf, n, ctx->Map.pcs );
0453   }
0454 
0455   return 0;
0456 }
0457 
0458 static T_fixture RtemsPartReqGetBuffer_Fixture = {
0459   .setup = RtemsPartReqGetBuffer_Setup_Wrap,
0460   .stop = NULL,
0461   .teardown = RtemsPartReqGetBuffer_Teardown_Wrap,
0462   .scope = RtemsPartReqGetBuffer_Scope,
0463   .initial_context = &RtemsPartReqGetBuffer_Instance
0464 };
0465 
0466 static inline RtemsPartReqGetBuffer_Entry RtemsPartReqGetBuffer_PopEntry(
0467   RtemsPartReqGetBuffer_Context *ctx
0468 )
0469 {
0470   size_t index;
0471 
0472   index = ctx->Map.index;
0473   ctx->Map.index = index + 1;
0474   return RtemsPartReqGetBuffer_Entries[
0475     RtemsPartReqGetBuffer_Map[ index ]
0476   ];
0477 }
0478 
0479 static void RtemsPartReqGetBuffer_TestVariant(
0480   RtemsPartReqGetBuffer_Context *ctx
0481 )
0482 {
0483   RtemsPartReqGetBuffer_Pre_Id_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0484   RtemsPartReqGetBuffer_Pre_Buf_Prepare( ctx, ctx->Map.pcs[ 1 ] );
0485   RtemsPartReqGetBuffer_Pre_Avail_Prepare( ctx, ctx->Map.pcs[ 2 ] );
0486   RtemsPartReqGetBuffer_Action( ctx );
0487   RtemsPartReqGetBuffer_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0488   RtemsPartReqGetBuffer_Post_BufVar_Check( ctx, ctx->Map.entry.Post_BufVar );
0489 }
0490 
0491 /**
0492  * @fn void T_case_body_RtemsPartReqGetBuffer( void )
0493  */
0494 T_TEST_CASE_FIXTURE( RtemsPartReqGetBuffer, &RtemsPartReqGetBuffer_Fixture )
0495 {
0496   RtemsPartReqGetBuffer_Context *ctx;
0497 
0498   ctx = T_fixture_context();
0499   ctx->Map.in_action_loop = true;
0500   ctx->Map.index = 0;
0501 
0502   for (
0503     ctx->Map.pcs[ 0 ] = RtemsPartReqGetBuffer_Pre_Id_NoObj;
0504     ctx->Map.pcs[ 0 ] < RtemsPartReqGetBuffer_Pre_Id_NA;
0505     ++ctx->Map.pcs[ 0 ]
0506   ) {
0507     for (
0508       ctx->Map.pcs[ 1 ] = RtemsPartReqGetBuffer_Pre_Buf_Valid;
0509       ctx->Map.pcs[ 1 ] < RtemsPartReqGetBuffer_Pre_Buf_NA;
0510       ++ctx->Map.pcs[ 1 ]
0511     ) {
0512       for (
0513         ctx->Map.pcs[ 2 ] = RtemsPartReqGetBuffer_Pre_Avail_Yes;
0514         ctx->Map.pcs[ 2 ] < RtemsPartReqGetBuffer_Pre_Avail_NA;
0515         ++ctx->Map.pcs[ 2 ]
0516       ) {
0517         ctx->Map.entry = RtemsPartReqGetBuffer_PopEntry( ctx );
0518         RtemsPartReqGetBuffer_Prepare( ctx );
0519         RtemsPartReqGetBuffer_TestVariant( ctx );
0520         RtemsPartReqGetBuffer_Cleanup( ctx );
0521       }
0522     }
0523   }
0524 }
0525 
0526 /** @} */