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 DevGrlibReqIrqampGetTimestamp
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 <grlib/irqamp.h>
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup DevGrlibReqIrqampGetTimestamp \
0061  *   spec:/dev/grlib/req/irqamp-get-timestamp
0062  *
0063  * @ingroup TestsuitesBspsValidationBsp0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Zero,
0070   DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Positive,
0071   DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_NA
0072 } DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets;
0073 
0074 typedef enum {
0075   DevGrlibReqIrqampGetTimestamp_Post_Result_Registers,
0076   DevGrlibReqIrqampGetTimestamp_Post_Result_Null,
0077   DevGrlibReqIrqampGetTimestamp_Post_Result_NA
0078 } DevGrlibReqIrqampGetTimestamp_Post_Result;
0079 
0080 typedef struct {
0081   uint8_t Skip : 1;
0082   uint8_t Pre_NumberOfTimestampRegisterSets_NA : 1;
0083   uint8_t Post_Result : 2;
0084 } DevGrlibReqIrqampGetTimestamp_Entry;
0085 
0086 /**
0087  * @brief Test context for spec:/dev/grlib/req/irqamp-get-timestamp test case.
0088  */
0089 typedef struct {
0090   /**
0091    * @brief This member contains the return value of the
0092    *   irqamp_get_timestamp_registers() call.
0093    */
0094   irqamp_timestamp *result;
0095 
0096   /**
0097    * @brief This member contains the IRQ(A)MP register block.
0098    */
0099   irqamp irqamp_regs;
0100 
0101   struct {
0102     /**
0103      * @brief This member defines the pre-condition states for the next action.
0104      */
0105     size_t pcs[ 1 ];
0106 
0107     /**
0108      * @brief If this member is true, then the test action loop is executed.
0109      */
0110     bool in_action_loop;
0111 
0112     /**
0113      * @brief This member contains the next transition map index.
0114      */
0115     size_t index;
0116 
0117     /**
0118      * @brief This member contains the current transition map entry.
0119      */
0120     DevGrlibReqIrqampGetTimestamp_Entry entry;
0121 
0122     /**
0123      * @brief If this member is true, then the current transition variant
0124      *   should be skipped.
0125      */
0126     bool skip;
0127   } Map;
0128 } DevGrlibReqIrqampGetTimestamp_Context;
0129 
0130 static DevGrlibReqIrqampGetTimestamp_Context
0131   DevGrlibReqIrqampGetTimestamp_Instance;
0132 
0133 static const char * const DevGrlibReqIrqampGetTimestamp_PreDesc_NumberOfTimestampRegisterSets[] = {
0134   "Zero",
0135   "Positive",
0136   "NA"
0137 };
0138 
0139 static const char * const * const DevGrlibReqIrqampGetTimestamp_PreDesc[] = {
0140   DevGrlibReqIrqampGetTimestamp_PreDesc_NumberOfTimestampRegisterSets,
0141   NULL
0142 };
0143 
0144 static void
0145 DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Prepare(
0146   DevGrlibReqIrqampGetTimestamp_Context                          *ctx,
0147   DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets state
0148 )
0149 {
0150   switch ( state ) {
0151     case DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Zero: {
0152       /*
0153        * While the number of timestamp register sets indicated by the IRQ(A)MP
0154        * register block specified by the ``irqamp_regs`` parameter is zero.
0155        */
0156       ctx->irqamp_regs.itstmp[ 0 ].itstmpc = 0;
0157       break;
0158     }
0159 
0160     case DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Positive: {
0161       /*
0162        * While the number of timestamp register sets indicated by the IRQ(A)MP
0163        * register block specified by the ``irqamp_regs`` parameter is positive.
0164        */
0165       ctx->irqamp_regs.itstmp[ 0 ].itstmpc = IRQAMP_ITSTMPC_TSTAMP( 1 );
0166       break;
0167     }
0168 
0169     case DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_NA:
0170       break;
0171   }
0172 }
0173 
0174 static void DevGrlibReqIrqampGetTimestamp_Post_Result_Check(
0175   DevGrlibReqIrqampGetTimestamp_Context    *ctx,
0176   DevGrlibReqIrqampGetTimestamp_Post_Result state
0177 )
0178 {
0179   switch ( state ) {
0180     case DevGrlibReqIrqampGetTimestamp_Post_Result_Registers: {
0181       /*
0182        * The return value of irqamp_get_timestamp_registers() shall be address
0183        * of the timestamping register block contained in the IRQ(A)MP register
0184        * block specified by the ``irqamp_regs`` parameter.
0185        */
0186       T_not_null( ctx->result );
0187       break;
0188     }
0189 
0190     case DevGrlibReqIrqampGetTimestamp_Post_Result_Null: {
0191       /*
0192        * The return value of irqamp_get_timestamp_registers() shall be false.
0193        */
0194       T_null( ctx->result );
0195       break;
0196     }
0197 
0198     case DevGrlibReqIrqampGetTimestamp_Post_Result_NA:
0199       break;
0200   }
0201 }
0202 
0203 static void DevGrlibReqIrqampGetTimestamp_Action(
0204   DevGrlibReqIrqampGetTimestamp_Context *ctx
0205 )
0206 {
0207   ctx->result = irqamp_get_timestamp_registers( &ctx->irqamp_regs );
0208 }
0209 
0210 static const DevGrlibReqIrqampGetTimestamp_Entry
0211 DevGrlibReqIrqampGetTimestamp_Entries[] = {
0212   { 0, 0, DevGrlibReqIrqampGetTimestamp_Post_Result_Null },
0213   { 0, 0, DevGrlibReqIrqampGetTimestamp_Post_Result_Registers }
0214 };
0215 
0216 static const uint8_t
0217 DevGrlibReqIrqampGetTimestamp_Map[] = {
0218   0, 1
0219 };
0220 
0221 static size_t DevGrlibReqIrqampGetTimestamp_Scope(
0222   void  *arg,
0223   char  *buf,
0224   size_t n
0225 )
0226 {
0227   DevGrlibReqIrqampGetTimestamp_Context *ctx;
0228 
0229   ctx = arg;
0230 
0231   if ( ctx->Map.in_action_loop ) {
0232     return T_get_scope(
0233       DevGrlibReqIrqampGetTimestamp_PreDesc,
0234       buf,
0235       n,
0236       ctx->Map.pcs
0237     );
0238   }
0239 
0240   return 0;
0241 }
0242 
0243 static T_fixture DevGrlibReqIrqampGetTimestamp_Fixture = {
0244   .setup = NULL,
0245   .stop = NULL,
0246   .teardown = NULL,
0247   .scope = DevGrlibReqIrqampGetTimestamp_Scope,
0248   .initial_context = &DevGrlibReqIrqampGetTimestamp_Instance
0249 };
0250 
0251 static inline DevGrlibReqIrqampGetTimestamp_Entry
0252 DevGrlibReqIrqampGetTimestamp_PopEntry(
0253   DevGrlibReqIrqampGetTimestamp_Context *ctx
0254 )
0255 {
0256   size_t index;
0257 
0258   index = ctx->Map.index;
0259   ctx->Map.index = index + 1;
0260   return DevGrlibReqIrqampGetTimestamp_Entries[
0261     DevGrlibReqIrqampGetTimestamp_Map[ index ]
0262   ];
0263 }
0264 
0265 static void DevGrlibReqIrqampGetTimestamp_TestVariant(
0266   DevGrlibReqIrqampGetTimestamp_Context *ctx
0267 )
0268 {
0269   DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Prepare(
0270     ctx,
0271     ctx->Map.pcs[ 0 ]
0272   );
0273   DevGrlibReqIrqampGetTimestamp_Action( ctx );
0274   DevGrlibReqIrqampGetTimestamp_Post_Result_Check(
0275     ctx,
0276     ctx->Map.entry.Post_Result
0277   );
0278 }
0279 
0280 /**
0281  * @fn void T_case_body_DevGrlibReqIrqampGetTimestamp( void )
0282  */
0283 T_TEST_CASE_FIXTURE(
0284   DevGrlibReqIrqampGetTimestamp,
0285   &DevGrlibReqIrqampGetTimestamp_Fixture
0286 )
0287 {
0288   DevGrlibReqIrqampGetTimestamp_Context *ctx;
0289 
0290   ctx = T_fixture_context();
0291   ctx->Map.in_action_loop = true;
0292   ctx->Map.index = 0;
0293 
0294   for (
0295     ctx->Map.pcs[ 0 ] = DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_Zero;
0296     ctx->Map.pcs[ 0 ] < DevGrlibReqIrqampGetTimestamp_Pre_NumberOfTimestampRegisterSets_NA;
0297     ++ctx->Map.pcs[ 0 ]
0298   ) {
0299     ctx->Map.entry = DevGrlibReqIrqampGetTimestamp_PopEntry( ctx );
0300     DevGrlibReqIrqampGetTimestamp_TestVariant( ctx );
0301   }
0302 }
0303 
0304 /** @} */