source: rtems/testsuites/sptests/spcpuset01/test.c @ 13ab94b

4.115
Last change on this file since 13ab94b was 13ab94b, checked in by Jennifer Averett <jennifer.averett@…>, on 02/06/14 at 18:51:01

spcpuset01: Add check for sys/cpuset.h.

If <sys/cpuset.h> is not provided by the toolset, the test
cannot be compiled.

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