Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsTaskReqIdent
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 "tr-object-ident.h"
0056 #include "tx-support.h"
0057 
0058 #include <rtems/test.h>
0059 
0060 /**
0061  * @defgroup RtemsTaskReqIdent spec:/rtems/task/req/ident
0062  *
0063  * @ingroup TestsuitesValidationNoClock0
0064  *
0065  * @{
0066  */
0067 
0068 typedef enum {
0069   RtemsTaskReqIdent_Pre_Name_WhoAmI,
0070   RtemsTaskReqIdent_Pre_Name_NotWhoAmI,
0071   RtemsTaskReqIdent_Pre_Name_NA
0072 } RtemsTaskReqIdent_Pre_Name;
0073 
0074 typedef enum {
0075   RtemsTaskReqIdent_Post_Status_OkAndWhoAmI,
0076   RtemsTaskReqIdent_Post_Status_Skip,
0077   RtemsTaskReqIdent_Post_Status_NA
0078 } RtemsTaskReqIdent_Post_Status;
0079 
0080 typedef struct {
0081   uint8_t Skip : 1;
0082   uint8_t Pre_Name_NA : 1;
0083   uint8_t Post_Status : 2;
0084 } RtemsTaskReqIdent_Entry;
0085 
0086 /**
0087  * @brief Test context for spec:/rtems/task/req/ident test case.
0088  */
0089 typedef struct {
0090   rtems_status_code status;
0091 
0092   rtems_id *id;
0093 
0094   rtems_id id_value;
0095 
0096   rtems_id id_local_object;
0097 
0098   struct {
0099     /**
0100      * @brief This member defines the pre-condition states for the next action.
0101      */
0102     size_t pcs[ 1 ];
0103 
0104     /**
0105      * @brief If this member is true, then the test action loop is executed.
0106      */
0107     bool in_action_loop;
0108 
0109     /**
0110      * @brief This member contains the next transition map index.
0111      */
0112     size_t index;
0113 
0114     /**
0115      * @brief This member contains the current transition map entry.
0116      */
0117     RtemsTaskReqIdent_Entry entry;
0118 
0119     /**
0120      * @brief If this member is true, then the current transition variant
0121      *   should be skipped.
0122      */
0123     bool skip;
0124   } Map;
0125 } RtemsTaskReqIdent_Context;
0126 
0127 static RtemsTaskReqIdent_Context
0128   RtemsTaskReqIdent_Instance;
0129 
0130 static const char * const RtemsTaskReqIdent_PreDesc_Name[] = {
0131   "WhoAmI",
0132   "NotWhoAmI",
0133   "NA"
0134 };
0135 
0136 static const char * const * const RtemsTaskReqIdent_PreDesc[] = {
0137   RtemsTaskReqIdent_PreDesc_Name,
0138   NULL
0139 };
0140 
0141 static rtems_status_code ClassicTaskIdentAction(
0142   rtems_name name,
0143   uint32_t   node,
0144   rtems_id  *id
0145 )
0146 {
0147   return rtems_task_ident( name, node, id );
0148 }
0149 
0150 static void RtemsTaskReqIdent_Pre_Name_Prepare(
0151   RtemsTaskReqIdent_Context *ctx,
0152   RtemsTaskReqIdent_Pre_Name state
0153 )
0154 {
0155   switch ( state ) {
0156     case RtemsTaskReqIdent_Pre_Name_WhoAmI: {
0157       /*
0158        * While the ``name`` parameter is equal to RTEMS_WHO_AM_I, while ``id``
0159        * parameter is not equal to NULL.
0160        */
0161       ctx->id_value = 0xffffffff;
0162       ctx->id = &ctx->id_value;
0163       break;
0164     }
0165 
0166     case RtemsTaskReqIdent_Pre_Name_NotWhoAmI: {
0167       /*
0168        * While the ``name`` is not equal to RTEMS_WHO_AM_I or ``id`` parameter
0169        * is equal to NULL, the behaviour of rtems_task_ident() shall be
0170        * specified by spec:/rtems/req/ident.
0171        */
0172       ctx->id = NULL;
0173       /* Preparation performed by RtemsReqIdent_Run() */
0174       break;
0175     }
0176 
0177     case RtemsTaskReqIdent_Pre_Name_NA:
0178       break;
0179   }
0180 }
0181 
0182 static void RtemsTaskReqIdent_Post_Status_Check(
0183   RtemsTaskReqIdent_Context    *ctx,
0184   RtemsTaskReqIdent_Post_Status state
0185 )
0186 {
0187   switch ( state ) {
0188     case RtemsTaskReqIdent_Post_Status_OkAndWhoAmI: {
0189       /*
0190        * The return status of rtems_task_ident() shall be RTEMS_SUCCESSFUL.
0191        * The value of the object identifier referenced by the ``name``
0192        * parameter shall be the identifier of the executing thread.
0193        */
0194       T_rsc( ctx->status, RTEMS_SUCCESSFUL );
0195       T_eq_ptr( ctx->id, &ctx->id_value );
0196       T_eq_u32( ctx->id_value, rtems_task_self() );
0197       break;
0198     }
0199 
0200     case RtemsTaskReqIdent_Post_Status_Skip: {
0201       /*
0202        * There is no status to validate.
0203        */
0204       /* Checks performed by RtemsReqIdent_Run() */
0205       break;
0206     }
0207 
0208     case RtemsTaskReqIdent_Post_Status_NA:
0209       break;
0210   }
0211 }
0212 
0213 static void RtemsTaskReqIdent_Setup( RtemsTaskReqIdent_Context *ctx )
0214 {
0215   rtems_status_code sc;
0216 
0217   sc = rtems_task_construct(
0218     &DefaultTaskConfig,
0219     &ctx->id_local_object
0220   );
0221   T_assert_rsc_success( sc );
0222 }
0223 
0224 static void RtemsTaskReqIdent_Setup_Wrap( void *arg )
0225 {
0226   RtemsTaskReqIdent_Context *ctx;
0227 
0228   ctx = arg;
0229   ctx->Map.in_action_loop = false;
0230   RtemsTaskReqIdent_Setup( ctx );
0231 }
0232 
0233 static void RtemsTaskReqIdent_Teardown( RtemsTaskReqIdent_Context *ctx )
0234 {
0235   if ( ctx->id_local_object != 0 ) {
0236     rtems_status_code sc;
0237 
0238     sc = rtems_task_delete( ctx->id_local_object );
0239     T_rsc_success( sc );
0240   }
0241 }
0242 
0243 static void RtemsTaskReqIdent_Teardown_Wrap( void *arg )
0244 {
0245   RtemsTaskReqIdent_Context *ctx;
0246 
0247   ctx = arg;
0248   ctx->Map.in_action_loop = false;
0249   RtemsTaskReqIdent_Teardown( ctx );
0250 }
0251 
0252 static void RtemsTaskReqIdent_Action( RtemsTaskReqIdent_Context *ctx )
0253 {
0254   if ( ctx->id != NULL ) {
0255     ctx->status = rtems_task_ident( RTEMS_SELF, 0xdeadbeef, ctx->id );
0256   } else {
0257     RtemsReqIdent_Run(
0258       ctx->id_local_object,
0259       DefaultTaskConfig.name,
0260       ClassicTaskIdentAction
0261     );
0262   }
0263 }
0264 
0265 static const RtemsTaskReqIdent_Entry
0266 RtemsTaskReqIdent_Entries[] = {
0267   { 0, 0, RtemsTaskReqIdent_Post_Status_OkAndWhoAmI },
0268   { 0, 0, RtemsTaskReqIdent_Post_Status_Skip }
0269 };
0270 
0271 static const uint8_t
0272 RtemsTaskReqIdent_Map[] = {
0273   0, 1
0274 };
0275 
0276 static size_t RtemsTaskReqIdent_Scope( void *arg, char *buf, size_t n )
0277 {
0278   RtemsTaskReqIdent_Context *ctx;
0279 
0280   ctx = arg;
0281 
0282   if ( ctx->Map.in_action_loop ) {
0283     return T_get_scope( RtemsTaskReqIdent_PreDesc, buf, n, ctx->Map.pcs );
0284   }
0285 
0286   return 0;
0287 }
0288 
0289 static T_fixture RtemsTaskReqIdent_Fixture = {
0290   .setup = RtemsTaskReqIdent_Setup_Wrap,
0291   .stop = NULL,
0292   .teardown = RtemsTaskReqIdent_Teardown_Wrap,
0293   .scope = RtemsTaskReqIdent_Scope,
0294   .initial_context = &RtemsTaskReqIdent_Instance
0295 };
0296 
0297 static inline RtemsTaskReqIdent_Entry RtemsTaskReqIdent_PopEntry(
0298   RtemsTaskReqIdent_Context *ctx
0299 )
0300 {
0301   size_t index;
0302 
0303   index = ctx->Map.index;
0304   ctx->Map.index = index + 1;
0305   return RtemsTaskReqIdent_Entries[
0306     RtemsTaskReqIdent_Map[ index ]
0307   ];
0308 }
0309 
0310 static void RtemsTaskReqIdent_TestVariant( RtemsTaskReqIdent_Context *ctx )
0311 {
0312   RtemsTaskReqIdent_Pre_Name_Prepare( ctx, ctx->Map.pcs[ 0 ] );
0313   RtemsTaskReqIdent_Action( ctx );
0314   RtemsTaskReqIdent_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
0315 }
0316 
0317 /**
0318  * @fn void T_case_body_RtemsTaskReqIdent( void )
0319  */
0320 T_TEST_CASE_FIXTURE( RtemsTaskReqIdent, &RtemsTaskReqIdent_Fixture )
0321 {
0322   RtemsTaskReqIdent_Context *ctx;
0323 
0324   ctx = T_fixture_context();
0325   ctx->Map.in_action_loop = true;
0326   ctx->Map.index = 0;
0327 
0328   for (
0329     ctx->Map.pcs[ 0 ] = RtemsTaskReqIdent_Pre_Name_WhoAmI;
0330     ctx->Map.pcs[ 0 ] < RtemsTaskReqIdent_Pre_Name_NA;
0331     ++ctx->Map.pcs[ 0 ]
0332   ) {
0333     ctx->Map.entry = RtemsTaskReqIdent_PopEntry( ctx );
0334     RtemsTaskReqIdent_TestVariant( ctx );
0335   }
0336 }
0337 
0338 /** @} */