Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  @ingroup sptests
0007  *
0008  *  @brief This is the init for spcpuset01.
0009  */
0010 
0011 /*
0012  * Copyright (C) 1989-2013 On-Line Applications Research Corporation (OAR).
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 /*
0037  *  Fully exercise CPU_SET() methods
0038  */
0039 
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043 
0044 #define CONFIGURE_INIT
0045 #include <rtems.h>
0046 #include <stdlib.h>
0047 #include <stdio.h>
0048 #include <assert.h>
0049 #include "system.h"
0050 
0051 const char rtems_test_name[] = "SPCPUSET 1";
0052 
0053 static void test_cpu_zero_case_1(void)
0054 {
0055   size_t i;
0056 
0057   /*
0058    * Set to all zeros and verify
0059    */
0060   puts( "Exercise CPU_ZERO, CPU_ISSET, and CPU_COUNT" );
0061   CPU_ZERO(&set3);
0062 
0063   /* test if all bits clear */
0064   for (i=0 ; i<CPU_SETSIZE ; i++) {
0065     rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
0066   }
0067   rtems_test_assert( CPU_COUNT(&set3) == 0 );
0068 
0069 }
0070 
0071 static void test_cpu_fill_case_1(void)
0072 {
0073   size_t i;
0074 
0075   /*
0076    * Set to all zeros and verify
0077    */
0078   puts( "Exercise CPU_FILL, CPU_ISSET, and CPU_COUNT" );
0079   CPU_FILL(&set1);
0080 
0081   /* test if all bits clear */
0082   for (i=0 ; i<CPU_SETSIZE ; i++) {
0083     rtems_test_assert( CPU_ISSET(i, &set1) == 1 );
0084   }
0085   rtems_test_assert( CPU_COUNT(&set1) == _NCPUBITS );
0086 }
0087 
0088 static void test_cpu_equal_case_1(void)
0089 {
0090   /*
0091    * CPU_EQUAL
0092    */
0093   puts( "Exercise CPU_ZERO, CPU_EQUAL, CPU_CMP, and CPU_EMPTY" );
0094   CPU_ZERO(&set1);
0095   CPU_ZERO(&set2);
0096 
0097   /* test that all bits are equal */
0098   rtems_test_assert( CPU_EQUAL(&set1, &set2) );
0099 
0100   /* compare all bits */
0101   rtems_test_assert( !CPU_CMP(&set1, &set2) );
0102 
0103   /* compare all bits */
0104   rtems_test_assert( CPU_EMPTY(&set1) );
0105 }
0106 
0107 static void test_cpu_set_case_1(size_t cpu)
0108 {
0109   size_t i;
0110 
0111   /*
0112    * Set to all zeros and verify
0113    */
0114   DPRINT( "Exercise CPU_ZERO, CPU_SET(%zu), and CPU_ISSET\n", cpu );
0115   CPU_ZERO(&set1);
0116   CPU_SET(cpu, &set1);
0117 
0118   /* test if all bits except 1 clear */
0119   for (i=0 ; i<CPU_SETSIZE ; i++) {
0120     if (i==cpu)
0121       rtems_test_assert( CPU_ISSET(i, &set1) == 1 );
0122     else
0123       rtems_test_assert( CPU_ISSET(i, &set1) == 0 );
0124 
0125      rtems_test_assert( ! CPU_EMPTY(&set1) );
0126   }
0127 }
0128 
0129 static void test_cpu_clr_case_1(size_t cpu)
0130 {
0131   size_t i;
0132 
0133   /*
0134    * Set to all zeros and verify
0135    */
0136   DPRINT( "Exercise CPU_FILL, CPU_CLR(%zu), and CPU_ISSET\n", cpu );
0137   CPU_FILL(&set1);
0138   CPU_CLR(cpu, &set1);
0139 
0140   /* test if all bits except 5 are set */
0141   for (i=0 ; i<CPU_SETSIZE ; i++) {
0142     if (i==cpu)
0143       rtems_test_assert( CPU_ISSET(i, &set1) == 0 );
0144     else
0145       rtems_test_assert( CPU_ISSET(i, &set1) == 1 );
0146   }
0147 }
0148 
0149 static void test_cpu_copy_case_1(void)
0150 {
0151   size_t i;
0152 
0153   /*
0154    * CPU_EQUAL
0155    */
0156   puts( "Exercise CPU_ZERO, CPU_COPY, and CPU_ISSET" );
0157   CPU_ZERO(&set1);
0158   CPU_FILL(&set2);
0159 
0160   CPU_COPY(&set1, &set2);
0161 
0162   /* test if all bits clear in set2 */
0163   for (i=0 ; i<CPU_SETSIZE ; i++) {
0164     rtems_test_assert( CPU_ISSET(i, &set2) == 0 );
0165   }
0166 }
0167 
0168 rtems_task Init(
0169   rtems_task_argument ignored
0170 )
0171 {
0172   size_t    i;
0173 
0174   TEST_BEGIN();
0175 
0176   test_cpu_zero_case_1();
0177   test_cpu_fill_case_1();
0178   test_cpu_equal_case_1();
0179   test_cpu_copy_case_1();
0180 
0181   for (i=0 ; i<CPU_SETSIZE ; i++) {
0182     test_cpu_set_case_1(i);
0183     test_cpu_clr_case_1(i);
0184   }
0185 
0186   cpuset_logic_test();
0187 
0188   TEST_END();
0189   exit( 0 );
0190 }