source: rtems/testsuites/sptests/spcpuset01/test.c @ fe011a5

4.115
Last change on this file since fe011a5 was fe011a5, checked in by Jennifer Averett <jennifer.averett@…>, on 12/16/13 at 19:13:14

sptests/spcpuset*: Add tests for fixed size cpu_set_t operations.

This adds five tests for <sys/cpuset.h>. It does not include
tests for CPU_XXX_S methods. The autotools should be able to
avoid enabling the tests unless the toolset has <sys/cpuset.h>.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  Fully exercise CPU_SET() methods
3 */
4
5#include <rtems.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <assert.h>
9#include <sys/cpuset.h>
10#include "system.h"
11
12
13void test_cpu_and_case_1(size_t cpu1, size_t cpu2);
14void test_cpu_nand_case_1(size_t cpu1, size_t cpu2);
15void test_cpu_or_case_1(size_t cpu1, size_t cpu2);
16void test_cpu_xor_case_1(size_t cpu1, size_t cpu2);
17static void test_logic01_setup(size_t cpu1, size_t cpu2);
18
19/*
20 *  Make these global so they can always be referenced. Optimization tends
21 *  to make them hard to see when on the stack.
22 */
23cpu_set_t set1;
24cpu_set_t set2;
25cpu_set_t set3;
26
27
28void test_cpu_and_case_1(size_t cpu1, size_t cpu2)
29{
30  size_t i;
31
32  /*  AND set1 and set2 */
33  printf( "Exercise CPU_AND with bits %d,%d\n",cpu1,cpu2 );
34  CPU_AND(&set3, &set1, &set2);
35   
36  /* test if all bits clear except cpu1 */
37  for (i=0 ; i<CPU_SETSIZE ; i++) {
38    if (i== cpu1)
39      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
40    else
41      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
42  }
43
44}
45
46void test_cpu_nand_case_1(size_t cpu1, size_t cpu2)
47{
48  size_t i;
49
50   /*  NAND set1 and set2 */
51  printf( "Exercise CPU_NAND with bits %d,%d\n",cpu1,cpu2 );
52  CPU_NAND(&set3, &set1, &set2);
53   
54  /* test if all bits clear except cpu1 */
55  for (i=0 ; i<CPU_SETSIZE ; i++) {
56    if (i== cpu1)
57      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
58    else
59      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
60  }
61}
62
63void test_cpu_or_case_1(size_t cpu1, size_t cpu2)
64{
65  size_t i;
66
67  /*  OR set1 and set2 */
68  printf( "Exercise CPU_OR with bits %d,%d\n",cpu1,cpu2 );
69  CPU_OR(&set3, &set1, &set2);
70   
71  /* test if all bits clear except cpu1 */
72  for (i=0 ; i<CPU_SETSIZE ; i++) {
73    if ((i== cpu1) || (i==cpu2))
74      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
75    else
76      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
77  }
78}
79
80void test_cpu_xor_case_1(size_t cpu1, size_t cpu2)
81{
82  size_t i;
83
84  /*  XOR set1 and set2 */
85  printf( "Exercise CPU_XOR with bits %d,%d\n",cpu1,cpu2 );
86  CPU_XOR(&set3, &set1, &set2);
87   
88  /* test if all bits clear except cpu1 */
89  for (i=0 ; i<CPU_SETSIZE ; i++) {
90    if (i==cpu2)
91      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
92    else
93      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
94  }
95}
96
97static void test_logic01_setup(size_t cpu1, size_t cpu2)
98{
99  /*
100   * Clear all bits except cpu1 in both sets and cpu2 in set1 only
101   */
102  CPU_ZERO(&set1);
103  CPU_SET(cpu1, &set1);
104  CPU_SET(cpu2, &set1);
105  CPU_COPY(&set2, &set1);
106  CPU_CLR(cpu2, &set2);
107}   
108
109void cpuset_logic_test()
110{
111  size_t    i,j;
112
113  for (i=0 ; i<CPU_SETSIZE ; i++) {
114    for (j=0 ; j<CPU_SETSIZE ; j++) {
115      if (i != j){
116        test_logic01_setup(i,j);
117        test_cpu_and_case_1(i, j);
118        test_cpu_nand_case_1(i, j);
119        test_cpu_or_case_1(i, j);
120        test_cpu_xor_case_1(i, j);
121      }
122    }
123  }
124}
125
Note: See TracBrowser for help on using the repository browser.