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 RtemsOptionValOptions
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 RtemsOptionValOptions spec:/rtems/option/val/options
0061  *
0062  * @ingroup TestsuitesValidationNoClock0
0063  *
0064  * @brief Tests the option constants of the Classic API.
0065  *
0066  * This test case performs the following actions:
0067  *
0068  * - Validate the non-default option constants.
0069  *
0070  *   - Check that RTEMS_EVENT_ANY is a power of two.
0071  *
0072  *   - Check that RTEMS_NO_WAIT is a power of two.
0073  *
0074  * - Validate the default option constants.
0075  *
0076  *   - Check that RTEMS_DEFAULT_OPTIONS is equal to zero.
0077  *
0078  *   - Check that RTEMS_EVENT_ALL is equal to zero.
0079  *
0080  *   - Check that RTEMS_WAIT is equal to zero.
0081  *
0082  * - Calculate the bitwise or of all non-default option constants.
0083  *
0084  *   - Check that the count of set bits in the calculated value is equal to the
0085  *     count of non-default option constants.  Since each non-default option
0086  *     constant is a power of two, this proves that each constant has a unique
0087  *     value.
0088  *
0089  * - Check the value of RTEMS_DEFAULT_OPTIONS.
0090  *
0091  *   - Check RTEMS_DEFAULT_OPTIONS equals RTEMS_WAIT.
0092  *
0093  * @{
0094  */
0095 
0096 static bool IsPowerOfTwo( rtems_option option )
0097 {
0098   return option != 0 && ( option & ( option - 1 ) ) == 0;
0099 }
0100 
0101 static int PopCount( rtems_option options )
0102 {
0103   int count;
0104 
0105   count = 0;
0106 
0107   while ( options != 0 ) {
0108     ++count;
0109     options &= options - 1;
0110   }
0111 
0112   return count;
0113 }
0114 
0115 /**
0116  * @brief Validate the non-default option constants.
0117  */
0118 static void RtemsOptionValOptions_Action_0( void )
0119 {
0120   /* No action */
0121 
0122   /*
0123    * Check that RTEMS_EVENT_ANY is a power of two.
0124    */
0125   T_step_true( 0, IsPowerOfTwo( RTEMS_EVENT_ANY ) );
0126 
0127   /*
0128    * Check that RTEMS_NO_WAIT is a power of two.
0129    */
0130   T_step_true( 1, IsPowerOfTwo( RTEMS_NO_WAIT ) );
0131 }
0132 
0133 /**
0134  * @brief Validate the default option constants.
0135  */
0136 static void RtemsOptionValOptions_Action_1( void )
0137 {
0138   /* No action */
0139 
0140   /*
0141    * Check that RTEMS_DEFAULT_OPTIONS is equal to zero.
0142    */
0143   T_step_eq_u32( 2, RTEMS_DEFAULT_OPTIONS, 0 );
0144 
0145   /*
0146    * Check that RTEMS_EVENT_ALL is equal to zero.
0147    */
0148   T_step_eq_u32( 3, RTEMS_EVENT_ALL, 0 );
0149 
0150   /*
0151    * Check that RTEMS_WAIT is equal to zero.
0152    */
0153   T_step_eq_u32( 4, RTEMS_WAIT, 0 );
0154 }
0155 
0156 /**
0157  * @brief Calculate the bitwise or of all non-default option constants.
0158  */
0159 static void RtemsOptionValOptions_Action_2( void )
0160 {
0161   rtems_option options;
0162 
0163   options = 0;
0164   options |= RTEMS_EVENT_ANY;
0165   options |= RTEMS_NO_WAIT;
0166 
0167   /*
0168    * Check that the count of set bits in the calculated value is equal to the
0169    * count of non-default option constants.  Since each non-default option
0170    * constant is a power of two, this proves that each constant has a unique
0171    * value.
0172    */
0173   T_step_eq_int( 5, PopCount( options ), 2 );
0174 }
0175 
0176 /**
0177  * @brief Check the value of RTEMS_DEFAULT_OPTIONS.
0178  */
0179 static void RtemsOptionValOptions_Action_3( void )
0180 {
0181   /* No action */
0182 
0183   /*
0184    * Check RTEMS_DEFAULT_OPTIONS equals RTEMS_WAIT.
0185    */
0186   T_step_eq_int( 6, RTEMS_DEFAULT_OPTIONS, RTEMS_WAIT );
0187 }
0188 
0189 /**
0190  * @fn void T_case_body_RtemsOptionValOptions( void )
0191  */
0192 T_TEST_CASE( RtemsOptionValOptions )
0193 {
0194   T_plan( 7 );
0195 
0196   RtemsOptionValOptions_Action_0();
0197   RtemsOptionValOptions_Action_1();
0198   RtemsOptionValOptions_Action_2();
0199   RtemsOptionValOptions_Action_3();
0200 }
0201 
0202 /** @} */