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