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 RtemsIoReqGetchark
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/bspIo.h>
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsIoReqGetchark spec:/rtems/io/req/getchark
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @{
0065  */
0066 
0067 typedef enum {
0068   RtemsIoReqGetchark_Pre_PollChar_Valid,
0069   RtemsIoReqGetchark_Pre_PollChar_Null,
0070   RtemsIoReqGetchark_Pre_PollChar_NA
0071 } RtemsIoReqGetchark_Pre_PollChar;
0072 
0073 typedef enum {
0074   RtemsIoReqGetchark_Post_Result_PollChar,
0075   RtemsIoReqGetchark_Post_Result_MinusOne,
0076   RtemsIoReqGetchark_Post_Result_NA
0077 } RtemsIoReqGetchark_Post_Result;
0078 
0079 typedef enum {
0080   RtemsIoReqGetchark_Post_Calls_Once,
0081   RtemsIoReqGetchark_Post_Calls_NA
0082 } RtemsIoReqGetchark_Post_Calls;
0083 
0084 typedef struct {
0085   uint8_t Skip : 1;
0086   uint8_t Pre_PollChar_NA : 1;
0087   uint8_t Post_Result : 2;
0088   uint8_t Post_Calls : 1;
0089 } RtemsIoReqGetchark_Entry;
0090 
0091 /**
0092  * @brief Test context for spec:/rtems/io/req/getchark test case.
0093  */
0094 typedef struct {
0095   /**
0096    * @brief This member contains the character input count.
0097    */
0098   size_t input_count;
0099 
0100   /**
0101    * @brief This member specifies the value for BSP_poll_char.
0102    */
0103   BSP_polling_getchar_function_type poll_char;
0104 
0105   /**
0106    * @brief This member contains the return value of the getchark() call.
0107    */
0108   int result;
0109 
0110   struct {
0111     /**
0112      * @brief This member defines the pre-condition states for the next action.
0113      */
0114     size_t pcs[ 1 ];
0115 
0116     /**
0117      * @brief If this member is true, then the test action loop is executed.
0118      */
0119     bool in_action_loop;
0120 
0121     /**
0122      * @brief This member contains the next transition map index.
0123      */
0124     size_t index;
0125 
0126     /**
0127      * @brief This member contains the current transition map entry.
0128      */
0129     RtemsIoReqGetchark_Entry entry;
0130 
0131     /**
0132      * @brief If this member is true, then the current transition variant
0133      *   should be skipped.
0134      */
0135     bool skip;
0136   } Map;
0137 } RtemsIoReqGetchark_Context;
0138 
0139 static RtemsIoReqGetchark_Context
0140   RtemsIoReqGetchark_Instance;
0141 
0142 static const char * const RtemsIoReqGetchark_PreDesc_PollChar[] = {
0143   "Valid",
0144   "Null",
0145   "NA"
0146 };
0147 
0148 static const char * const * const RtemsIoReqGetchark_PreDesc[] = {
0149   RtemsIoReqGetchark_PreDesc_PollChar,
0150   NULL
0151 };
0152 
0153 typedef RtemsIoReqGetchark_Context Context;
0154 
0155 static int PollChar( void )
0156 {
0157   Context *ctx;
0158 
0159   ctx = T_fixture_context();
0160   ++ctx->input_count;
0161 
0162   return 123;
0163 }
0164 
0165 static void RtemsIoReqGetchark_Pre_PollChar_Prepare(
0166   RtemsIoReqGetchark_Context     *ctx,
0167   RtemsIoReqGetchark_Pre_PollChar state
0168 )
0169 {
0170   switch ( state ) {
0171     case RtemsIoReqGetchark_Pre_PollChar_Valid: {
0172       /*
0173        * While BSP_poll_char references a function.
0174        */
0175       ctx->poll_char = PollChar;
0176       break;
0177     }
0178 
0179     case RtemsIoReqGetchark_Pre_PollChar_Null: {
0180       /*
0181        * While BSP_poll_char is equal to NULL.
0182        */
0183       ctx->poll_char = NULL;
0184       break;
0185     }
0186 
0187     case RtemsIoReqGetchark_Pre_PollChar_NA:
0188       break;
0189   }
0190 }
0191 
0192 static void RtemsIoReqGetchark_Post_Result_Check(
0193   RtemsIoReqGetchark_Context    *ctx,
0194   RtemsIoReqGetchark_Post_Result state
0195 )
0196 {
0197   switch ( state ) {
0198     case RtemsIoReqGetchark_Post_Result_PollChar: {
0199       /*
0200        * The return value of getchark() shall be the return value of the
0201        * function referenced by BSP_poll_char.
0202        */
0203       T_eq_int( ctx->result, 123 );
0204       break;
0205     }
0206 
0207     case RtemsIoReqGetchark_Post_Result_MinusOne: {
0208       /*
0209        * The return value of getchark() shall be minus one.
0210        */
0211       T_eq_int( ctx->result, -1 );
0212       T_eq_u32( ctx->input_count, 0 );
0213       break;
0214     }
0215 
0216     case RtemsIoReqGetchark_Post_Result_NA:
0217       break;
0218   }
0219 }
0220 
0221 static void RtemsIoReqGetchark_Post_Calls_Check(
0222   RtemsIoReqGetchark_Context   *ctx,
0223   RtemsIoReqGetchark_Post_Calls state
0224 )
0225 {
0226   switch ( state ) {
0227     case RtemsIoReqGetchark_Post_Calls_Once: {
0228       /*
0229        * The function referenced by BSP_poll_char shall be called exactly once
0230        * to get the return value for getchark().
0231        */
0232       T_eq_u32( ctx->input_count, 1 );
0233       break;
0234     }
0235 
0236     case RtemsIoReqGetchark_Post_Calls_NA:
0237       break;
0238   }
0239 }
0240 
0241 static void RtemsIoReqGetchark_Action( RtemsIoReqGetchark_Context *ctx )
0242 {
0243   BSP_polling_getchar_function_type poll_char;
0244 
0245   ctx->input_count = 0;
0246   poll_char = BSP_poll_char;
0247   BSP_poll_char = ctx->poll_char;
0248   ctx->result = getchark();
0249   BSP_poll_char = poll_char;
0250 }
0251 
0252 static const RtemsIoReqGetchark_Entry
0253 RtemsIoReqGetchark_Entries[] = {
0254   { 0, 0, RtemsIoReqGetchark_Post_Result_PollChar,
0255     RtemsIoReqGetchark_Post_Calls_Once },
0256   { 0, 0, RtemsIoReqGetchark_Post_Result_MinusOne,
0257     RtemsIoReqGetchark_Post_Calls_NA }
0258 };
0259 
0260 static const uint8_t
0261 RtemsIoReqGetchark_Map[] = {
0262   0, 1
0263 };
0264 
0265 static size_t RtemsIoReqGetchark_Scope( void *arg, char *buf, size_t n )
0266 {
0267   RtemsIoReqGetchark_Context *ctx;
0268 
0269   ctx = arg;
0270 
0271   if ( ctx->Map.in_action_loop ) {
0272     return T_get_scope( RtemsIoReqGetchark_PreDesc, buf, n, ctx->Map.pcs );
0273   }
0274 
0275   return 0;
0276 }
0277 
0278 static T_fixture RtemsIoReqGetchark_Fixture = {
0279   .setup = NULL,
0280   .stop = NULL,
0281   .teardown = NULL,
0282   .scope = RtemsIoReqGetchark_Scope,
0283   .initial_context = &RtemsIoReqGetchark_Instance
0284 };
0285 
0286 static inline RtemsIoReqGetchark_Entry RtemsIoReqGetchark_PopEntry(
0287   RtemsIoReqGetchark_Context *ctx
0288 )
0289 {
0290   size_t index;
0291 
0292   index = ctx->Map.index;
0293   ctx->Map.index = index + 1;
0294   return RtemsIoReqGetchark_Entries[
0295     RtemsIoReqGetchark_Map[ index ]
0296   ];
0297 }
0298 
0299 static void RtemsIoReqGetchark_TestVariant( RtemsIoReqGetchark_Context *ctx )
0300 {
0301   RtemsIoReqGetchark_Pre_PollChar_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0302   RtemsIoReqGetchark_Action( ctx );
0303   RtemsIoReqGetchark_Post_Result_Check( ctx, ctx->Map.entry.Post_Result );
0304   RtemsIoReqGetchark_Post_Calls_Check( ctx, ctx->Map.entry.Post_Calls );
0305 }
0306 
0307 /**
0308  * @fn void T_case_body_RtemsIoReqGetchark( void )
0309  */
0310 T_TEST_CASE_FIXTURE( RtemsIoReqGetchark, &RtemsIoReqGetchark_Fixture )
0311 {
0312   RtemsIoReqGetchark_Context *ctx;
0313 
0314   ctx = T_fixture_context();
0315   ctx->Map.in_action_loop = true;
0316   ctx->Map.index = 0;
0317 
0318   for (
0319     ctx->Map.pcs[ 0 ] = RtemsIoReqGetchark_Pre_PollChar_Valid;
0320     ctx->Map.pcs[ 0 ] < RtemsIoReqGetchark_Pre_PollChar_NA;
0321     ++ctx->Map.pcs[ 0 ]
0322   ) {
0323     ctx->Map.entry = RtemsIoReqGetchark_PopEntry( ctx );
0324     RtemsIoReqGetchark_TestVariant( ctx );
0325   }
0326 }
0327 
0328 /** @} */