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 DevGrlibReqApbuartInbyteNonblocking
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 <string.h>
0056 #include <grlib/apbuart.h>
0057 
0058 #include <rtems/test.h>
0059 
0060 /**
0061  * @defgroup DevGrlibReqApbuartInbyteNonblocking \
0062  *   spec:/dev/grlib/req/apbuart-inbyte-nonblocking
0063  *
0064  * @ingroup TestsuitesBspsValidationBsp0
0065  *
0066  * @{
0067  */
0068 
0069 typedef enum {
0070   DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes,
0071   DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_No,
0072   DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA
0073 } DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady;
0074 
0075 typedef enum {
0076   DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data,
0077   DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne,
0078   DevGrlibReqApbuartInbyteNonblocking_Post_Result_NA
0079 } DevGrlibReqApbuartInbyteNonblocking_Post_Result;
0080 
0081 typedef enum {
0082   DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared,
0083   DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_NA
0084 } DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags;
0085 
0086 typedef struct {
0087   uint8_t Skip : 1;
0088   uint8_t Pre_DataReady_NA : 1;
0089   uint8_t Post_Result : 2;
0090   uint8_t Post_ErrorFlags : 1;
0091 } DevGrlibReqApbuartInbyteNonblocking_Entry;
0092 
0093 /**
0094  * @brief Test context for spec:/dev/grlib/req/apbuart-inbyte-nonblocking test
0095  *   case.
0096  */
0097 typedef struct {
0098   /**
0099    * @brief This member provides the APBUART register block.
0100    */
0101   apbuart regs;
0102 
0103   /**
0104    * @brief This member contains the return value of the
0105    *   apbuart_inbyte_nonblocking() call.
0106    */
0107   int result;
0108 
0109   struct {
0110     /**
0111      * @brief This member defines the pre-condition states for the next action.
0112      */
0113     size_t pcs[ 1 ];
0114 
0115     /**
0116      * @brief If this member is true, then the test action loop is executed.
0117      */
0118     bool in_action_loop;
0119 
0120     /**
0121      * @brief This member contains the next transition map index.
0122      */
0123     size_t index;
0124 
0125     /**
0126      * @brief This member contains the current transition map entry.
0127      */
0128     DevGrlibReqApbuartInbyteNonblocking_Entry entry;
0129 
0130     /**
0131      * @brief If this member is true, then the current transition variant
0132      *   should be skipped.
0133      */
0134     bool skip;
0135   } Map;
0136 } DevGrlibReqApbuartInbyteNonblocking_Context;
0137 
0138 static DevGrlibReqApbuartInbyteNonblocking_Context
0139   DevGrlibReqApbuartInbyteNonblocking_Instance;
0140 
0141 static const char * const DevGrlibReqApbuartInbyteNonblocking_PreDesc_DataReady[] = {
0142   "Yes",
0143   "No",
0144   "NA"
0145 };
0146 
0147 static const char * const * const DevGrlibReqApbuartInbyteNonblocking_PreDesc[] = {
0148   DevGrlibReqApbuartInbyteNonblocking_PreDesc_DataReady,
0149   NULL
0150 };
0151 
0152 static void DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Prepare(
0153   DevGrlibReqApbuartInbyteNonblocking_Context      *ctx,
0154   DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady state
0155 )
0156 {
0157   switch ( state ) {
0158     case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes: {
0159       /*
0160        * While the data ready flag is set in the status register of the
0161        * register block specified by ``regs`` parameter.
0162        */
0163       ctx->regs.status |= APBUART_STATUS_DR;
0164       break;
0165     }
0166 
0167     case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_No: {
0168       /*
0169        * While the data ready flag is cleared in the status register of the
0170        * register block specified by ``regs`` parameter.
0171        */
0172       ctx->regs.status &= ~APBUART_STATUS_DR;
0173       break;
0174     }
0175 
0176     case DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA:
0177       break;
0178   }
0179 }
0180 
0181 static void DevGrlibReqApbuartInbyteNonblocking_Post_Result_Check(
0182   DevGrlibReqApbuartInbyteNonblocking_Context    *ctx,
0183   DevGrlibReqApbuartInbyteNonblocking_Post_Result state
0184 )
0185 {
0186   switch ( state ) {
0187     case DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data: {
0188       /*
0189        * The return value of apbuart_inbyte_nonblocking() shall be the data
0190        * read from the data register of the register block specified by
0191        * ``regs``.
0192        */
0193       T_eq_int( ctx->result, 0xff );
0194       break;
0195     }
0196 
0197     case DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne: {
0198       /*
0199        * The return value of apbuart_inbyte_nonblocking() shall be minus one.
0200        */
0201       T_eq_int( ctx->result, -1 );
0202       break;
0203     }
0204 
0205     case DevGrlibReqApbuartInbyteNonblocking_Post_Result_NA:
0206       break;
0207   }
0208 }
0209 
0210 static void DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Check(
0211   DevGrlibReqApbuartInbyteNonblocking_Context        *ctx,
0212   DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags state
0213 )
0214 {
0215   switch ( state ) {
0216     case DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared: {
0217       /*
0218        * The framing error, parity error, overrun, and break received flags in
0219        * the status register of the register block specified by ``regs`` shall
0220        * be cleared.
0221        */
0222       T_eq_u32( ctx->regs.status & 0x78, 0 );
0223       break;
0224     }
0225 
0226     case DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_NA:
0227       break;
0228   }
0229 }
0230 
0231 static void DevGrlibReqApbuartInbyteNonblocking_Prepare(
0232   DevGrlibReqApbuartInbyteNonblocking_Context *ctx
0233 )
0234 {
0235   memset( &ctx->regs, 0, sizeof( ctx->regs ) );
0236   ctx->regs.status = 0x78;
0237   ctx->regs.data = 0xff;
0238 }
0239 
0240 static void DevGrlibReqApbuartInbyteNonblocking_Action(
0241   DevGrlibReqApbuartInbyteNonblocking_Context *ctx
0242 )
0243 {
0244   ctx->result = apbuart_inbyte_nonblocking( &ctx->regs );
0245 }
0246 
0247 static const DevGrlibReqApbuartInbyteNonblocking_Entry
0248 DevGrlibReqApbuartInbyteNonblocking_Entries[] = {
0249   { 0, 0, DevGrlibReqApbuartInbyteNonblocking_Post_Result_Data,
0250     DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared },
0251   { 0, 0, DevGrlibReqApbuartInbyteNonblocking_Post_Result_MinusOne,
0252     DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Cleared }
0253 };
0254 
0255 static const uint8_t
0256 DevGrlibReqApbuartInbyteNonblocking_Map[] = {
0257   0, 1
0258 };
0259 
0260 static size_t DevGrlibReqApbuartInbyteNonblocking_Scope(
0261   void  *arg,
0262   char  *buf,
0263   size_t n
0264 )
0265 {
0266   DevGrlibReqApbuartInbyteNonblocking_Context *ctx;
0267 
0268   ctx = arg;
0269 
0270   if ( ctx->Map.in_action_loop ) {
0271     return T_get_scope(
0272       DevGrlibReqApbuartInbyteNonblocking_PreDesc,
0273       buf,
0274       n,
0275       ctx->Map.pcs
0276     );
0277   }
0278 
0279   return 0;
0280 }
0281 
0282 static T_fixture DevGrlibReqApbuartInbyteNonblocking_Fixture = {
0283   .setup = NULL,
0284   .stop = NULL,
0285   .teardown = NULL,
0286   .scope = DevGrlibReqApbuartInbyteNonblocking_Scope,
0287   .initial_context = &DevGrlibReqApbuartInbyteNonblocking_Instance
0288 };
0289 
0290 static inline DevGrlibReqApbuartInbyteNonblocking_Entry
0291 DevGrlibReqApbuartInbyteNonblocking_PopEntry(
0292   DevGrlibReqApbuartInbyteNonblocking_Context *ctx
0293 )
0294 {
0295   size_t index;
0296 
0297   index = ctx->Map.index;
0298   ctx->Map.index = index + 1;
0299   return DevGrlibReqApbuartInbyteNonblocking_Entries[
0300     DevGrlibReqApbuartInbyteNonblocking_Map[ index ]
0301   ];
0302 }
0303 
0304 static void DevGrlibReqApbuartInbyteNonblocking_TestVariant(
0305   DevGrlibReqApbuartInbyteNonblocking_Context *ctx
0306 )
0307 {
0308   DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Prepare(
0309     ctx,
0310     ctx->Map.pcs[ 0 ]
0311   );
0312   DevGrlibReqApbuartInbyteNonblocking_Action( ctx );
0313   DevGrlibReqApbuartInbyteNonblocking_Post_Result_Check(
0314     ctx,
0315     ctx->Map.entry.Post_Result
0316   );
0317   DevGrlibReqApbuartInbyteNonblocking_Post_ErrorFlags_Check(
0318     ctx,
0319     ctx->Map.entry.Post_ErrorFlags
0320   );
0321 }
0322 
0323 /**
0324  * @fn void T_case_body_DevGrlibReqApbuartInbyteNonblocking( void )
0325  */
0326 T_TEST_CASE_FIXTURE(
0327   DevGrlibReqApbuartInbyteNonblocking,
0328   &DevGrlibReqApbuartInbyteNonblocking_Fixture
0329 )
0330 {
0331   DevGrlibReqApbuartInbyteNonblocking_Context *ctx;
0332 
0333   ctx = T_fixture_context();
0334   ctx->Map.in_action_loop = true;
0335   ctx->Map.index = 0;
0336 
0337   for (
0338     ctx->Map.pcs[ 0 ] = DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_Yes;
0339     ctx->Map.pcs[ 0 ] < DevGrlibReqApbuartInbyteNonblocking_Pre_DataReady_NA;
0340     ++ctx->Map.pcs[ 0 ]
0341   ) {
0342     ctx->Map.entry = DevGrlibReqApbuartInbyteNonblocking_PopEntry( ctx );
0343     DevGrlibReqApbuartInbyteNonblocking_Prepare( ctx );
0344     DevGrlibReqApbuartInbyteNonblocking_TestVariant( ctx );
0345   }
0346 }
0347 
0348 /** @} */