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 RtemsAttrValAttr
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 RtemsAttrValAttr spec:/rtems/attr/val/attr
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @brief Tests the attribute constants of the Classic API.
0065  *
0066  * This test case performs the following actions:
0067  *
0068  * - Validate the non-default attribute constants.
0069  *
0070  *   - Check that RTEMS_BARRIER_AUTOMATIC_RELEASE is a power of two.
0071  *
0072  *   - Check that RTEMS_BINARY_SEMAPHORE is a power of two.
0073  *
0074  *   - Check that RTEMS_FLOATING_POINT is a power of two.
0075  *
0076  *   - Check that RTEMS_GLOBAL is a power of two.
0077  *
0078  *   - Check that RTEMS_INHERIT_PRIORITY is a power of two.
0079  *
0080  *   - Check that RTEMS_MULTIPROCESSOR_RESOURCE_SHARING is a power of two.
0081  *
0082  *   - Check that RTEMS_PRIORITY is a power of two.
0083  *
0084  *   - Check that RTEMS_PRIORITY_CEILING is a power of two.
0085  *
0086  *   - Check that RTEMS_SIMPLE_BINARY_SEMAPHORE is a power of two.
0087  *
0088  *   - Check that RTEMS_SYSTEM_TASK is a power of two.
0089  *
0090  * - Validate the default attribute constants.
0091  *
0092  *   - Check that RTEMS_APPLICATION_TASK is equal to zero.
0093  *
0094  *   - Check that RTEMS_BARRIER_MANUAL_RELEASE is equal to zero.
0095  *
0096  *   - Check that RTEMS_COUNTING_SEMAPHORE is equal to zero.
0097  *
0098  *   - Check that RTEMS_DEFAULT_ATTRIBUTES is equal to zero.
0099  *
0100  *   - Check that RTEMS_FIFO is equal to zero.
0101  *
0102  *   - Check that RTEMS_LOCAL is equal to zero.
0103  *
0104  *   - Check that RTEMS_NO_FLOATING_POINT is equal to zero.
0105  *
0106  *   - Check that RTEMS_NO_INHERIT_PRIORITY is equal to zero.
0107  *
0108  *   - Check that RTEMS_NO_MULTIPROCESSOR_RESOURCE_SHARING is equal to zero.
0109  *
0110  *   - Check that RTEMS_NO_PRIORITY_CEILING is equal to zero.
0111  *
0112  * - Calculate the bitwise or of all non-default attribute constants.
0113  *
0114  *   - Check that the count of set bits in the calculated value is equal to the
0115  *     count of non-default attribute constants.  Since each non-default
0116  *     attribute constant is a power of two, this proves that each constant has
0117  *     a unique value.
0118  *
0119  * - Calculate the bitwise or of the RTEMS_BINARY_SEMAPHORE,
0120  *   RTEMS_COUNTING_SEMAPHORE, and RTEMS_SIMPLE_BINARY_SEMAPHORE attribute
0121  *   constants.
0122  *
0123  *   - Check that the calculated value is equal to RTEMS_SEMAPHORE_CLASS.
0124  *
0125  * - Check the value of RTEMS_DEFAULT_ATTRIBUTES.
0126  *
0127  *   - Check RTEMS_DEFAULT_ATTRIBUTES equals RTEMS_FIFO | RTEMS_LOCAL.
0128  *
0129  * @{
0130  */
0131 
0132 static bool IsPowerOfTwo( rtems_attribute attribute )
0133 {
0134   return attribute != 0 && ( attribute & ( attribute - 1 ) ) == 0;
0135 }
0136 
0137 static int PopCount( rtems_attribute attributes )
0138 {
0139   int count;
0140 
0141   count = 0;
0142 
0143   while ( attributes != 0 ) {
0144     ++count;
0145     attributes &= attributes - 1;
0146   }
0147 
0148   return count;
0149 }
0150 
0151 /**
0152  * @brief Validate the non-default attribute constants.
0153  */
0154 static void RtemsAttrValAttr_Action_0( void )
0155 {
0156   /* No action */
0157 
0158   /*
0159    * Check that RTEMS_BARRIER_AUTOMATIC_RELEASE is a power of two.
0160    */
0161   T_step_true( 0, IsPowerOfTwo( RTEMS_BARRIER_AUTOMATIC_RELEASE ) );
0162 
0163   /*
0164    * Check that RTEMS_BINARY_SEMAPHORE is a power of two.
0165    */
0166   T_step_true( 1, IsPowerOfTwo( RTEMS_BINARY_SEMAPHORE ) );
0167 
0168   /*
0169    * Check that RTEMS_FLOATING_POINT is a power of two.
0170    */
0171   T_step_true( 2, IsPowerOfTwo( RTEMS_FLOATING_POINT ) );
0172 
0173   /*
0174    * Check that RTEMS_GLOBAL is a power of two.
0175    */
0176   T_step_true( 3, IsPowerOfTwo( RTEMS_GLOBAL ) );
0177 
0178   /*
0179    * Check that RTEMS_INHERIT_PRIORITY is a power of two.
0180    */
0181   T_step_true( 4, IsPowerOfTwo( RTEMS_INHERIT_PRIORITY ) );
0182 
0183   /*
0184    * Check that RTEMS_MULTIPROCESSOR_RESOURCE_SHARING is a power of two.
0185    */
0186   T_step_true(
0187     5,
0188     IsPowerOfTwo( RTEMS_MULTIPROCESSOR_RESOURCE_SHARING )
0189   );
0190 
0191   /*
0192    * Check that RTEMS_PRIORITY is a power of two.
0193    */
0194   T_step_true( 6, IsPowerOfTwo( RTEMS_PRIORITY ) );
0195 
0196   /*
0197    * Check that RTEMS_PRIORITY_CEILING is a power of two.
0198    */
0199   T_step_true( 7, IsPowerOfTwo( RTEMS_PRIORITY_CEILING ) );
0200 
0201   /*
0202    * Check that RTEMS_SIMPLE_BINARY_SEMAPHORE is a power of two.
0203    */
0204   T_step_true( 8, IsPowerOfTwo( RTEMS_SIMPLE_BINARY_SEMAPHORE ) );
0205 
0206   /*
0207    * Check that RTEMS_SYSTEM_TASK is a power of two.
0208    */
0209   T_step_true( 9, IsPowerOfTwo( RTEMS_SYSTEM_TASK ) );
0210 }
0211 
0212 /**
0213  * @brief Validate the default attribute constants.
0214  */
0215 static void RtemsAttrValAttr_Action_1( void )
0216 {
0217   /* No action */
0218 
0219   /*
0220    * Check that RTEMS_APPLICATION_TASK is equal to zero.
0221    */
0222   T_step_eq_u32( 10, RTEMS_APPLICATION_TASK, 0 );
0223 
0224   /*
0225    * Check that RTEMS_BARRIER_MANUAL_RELEASE is equal to zero.
0226    */
0227   T_step_eq_u32( 11, RTEMS_BARRIER_MANUAL_RELEASE, 0 );
0228 
0229   /*
0230    * Check that RTEMS_COUNTING_SEMAPHORE is equal to zero.
0231    */
0232   T_step_eq_u32( 12, RTEMS_COUNTING_SEMAPHORE, 0 );
0233 
0234   /*
0235    * Check that RTEMS_DEFAULT_ATTRIBUTES is equal to zero.
0236    */
0237   T_step_eq_u32( 13, RTEMS_DEFAULT_ATTRIBUTES, 0 );
0238 
0239   /*
0240    * Check that RTEMS_FIFO is equal to zero.
0241    */
0242   T_step_eq_u32( 14, RTEMS_FIFO, 0 );
0243 
0244   /*
0245    * Check that RTEMS_LOCAL is equal to zero.
0246    */
0247   T_step_eq_u32( 15, RTEMS_LOCAL, 0 );
0248 
0249   /*
0250    * Check that RTEMS_NO_FLOATING_POINT is equal to zero.
0251    */
0252   T_step_eq_u32( 16, RTEMS_NO_FLOATING_POINT, 0 );
0253 
0254   /*
0255    * Check that RTEMS_NO_INHERIT_PRIORITY is equal to zero.
0256    */
0257   T_step_eq_u32( 17, RTEMS_NO_INHERIT_PRIORITY, 0 );
0258 
0259   /*
0260    * Check that RTEMS_NO_MULTIPROCESSOR_RESOURCE_SHARING is equal to zero.
0261    */
0262   T_step_eq_u32( 18, RTEMS_NO_MULTIPROCESSOR_RESOURCE_SHARING, 0 );
0263 
0264   /*
0265    * Check that RTEMS_NO_PRIORITY_CEILING is equal to zero.
0266    */
0267   T_step_eq_u32( 19, RTEMS_NO_PRIORITY_CEILING, 0 );
0268 }
0269 
0270 /**
0271  * @brief Calculate the bitwise or of all non-default attribute constants.
0272  */
0273 static void RtemsAttrValAttr_Action_2( void )
0274 {
0275   rtems_attribute attributes;
0276 
0277   attributes = 0;
0278   attributes |= RTEMS_BARRIER_AUTOMATIC_RELEASE;
0279   attributes |= RTEMS_BINARY_SEMAPHORE;
0280   attributes |= RTEMS_FLOATING_POINT;
0281   attributes |= RTEMS_GLOBAL;
0282   attributes |= RTEMS_INHERIT_PRIORITY;
0283   attributes |= RTEMS_MULTIPROCESSOR_RESOURCE_SHARING;
0284   attributes |= RTEMS_PRIORITY;
0285   attributes |= RTEMS_PRIORITY_CEILING;
0286   attributes |= RTEMS_SEMAPHORE_CLASS;
0287   attributes |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
0288   attributes |= RTEMS_SYSTEM_TASK;
0289 
0290   /*
0291    * Check that the count of set bits in the calculated value is equal to the
0292    * count of non-default attribute constants.  Since each non-default
0293    * attribute constant is a power of two, this proves that each constant has a
0294    * unique value.
0295    */
0296   T_step_eq_int( 20, PopCount( attributes ), 10 );
0297 }
0298 
0299 /**
0300  * @brief Calculate the bitwise or of the RTEMS_BINARY_SEMAPHORE,
0301  *   RTEMS_COUNTING_SEMAPHORE, and RTEMS_SIMPLE_BINARY_SEMAPHORE attribute
0302  *   constants.
0303  */
0304 static void RtemsAttrValAttr_Action_3( void )
0305 {
0306   rtems_attribute attributes;
0307 
0308   attributes = 0;
0309   attributes |= RTEMS_BINARY_SEMAPHORE;
0310   attributes |= RTEMS_COUNTING_SEMAPHORE;
0311   attributes |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
0312 
0313   /*
0314    * Check that the calculated value is equal to RTEMS_SEMAPHORE_CLASS.
0315    */
0316   T_step_eq_u32( 21, RTEMS_SEMAPHORE_CLASS, attributes );
0317 }
0318 
0319 /**
0320  * @brief Check the value of RTEMS_DEFAULT_ATTRIBUTES.
0321  */
0322 static void RtemsAttrValAttr_Action_4( void )
0323 {
0324   /* No action */
0325 
0326   /*
0327    * Check RTEMS_DEFAULT_ATTRIBUTES equals RTEMS_FIFO | RTEMS_LOCAL.
0328    */
0329   T_step_eq_int(
0330     22,
0331     RTEMS_DEFAULT_ATTRIBUTES,
0332     RTEMS_FIFO | RTEMS_LOCAL
0333   );
0334 }
0335 
0336 /**
0337  * @fn void T_case_body_RtemsAttrValAttr( void )
0338  */
0339 T_TEST_CASE( RtemsAttrValAttr )
0340 {
0341   T_plan( 23 );
0342 
0343   RtemsAttrValAttr_Action_0();
0344   RtemsAttrValAttr_Action_1();
0345   RtemsAttrValAttr_Action_2();
0346   RtemsAttrValAttr_Action_3();
0347   RtemsAttrValAttr_Action_4();
0348 }
0349 
0350 /** @} */