1 | /* |
---|
2 | * Fully exercise CPU_SET() methods |
---|
3 | */ |
---|
4 | |
---|
5 | #ifdef HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #define CONFIGURE_INIT |
---|
10 | #include <rtems.h> |
---|
11 | #include <stdlib.h> |
---|
12 | #include <stdio.h> |
---|
13 | #include <assert.h> |
---|
14 | #include "system.h" |
---|
15 | |
---|
16 | const char rtems_test_name[] = "SPCPUSET 1"; |
---|
17 | |
---|
18 | static void test_cpu_zero_case_1(void) |
---|
19 | { |
---|
20 | size_t i; |
---|
21 | |
---|
22 | /* |
---|
23 | * Set to all zeros and verify |
---|
24 | */ |
---|
25 | puts( "Exercise CPU_ZERO, CPU_ISSET, and CPU_COUNT" ); |
---|
26 | CPU_ZERO(&set3); |
---|
27 | |
---|
28 | /* test if all bits clear */ |
---|
29 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
30 | rtems_test_assert( CPU_ISSET(i, &set3) == 0 ); |
---|
31 | } |
---|
32 | rtems_test_assert( CPU_COUNT(&set3) == 0 ); |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | static void test_cpu_fill_case_1(void) |
---|
37 | { |
---|
38 | size_t i; |
---|
39 | |
---|
40 | /* |
---|
41 | * Set to all zeros and verify |
---|
42 | */ |
---|
43 | puts( "Exercise CPU_FILL, CPU_ISSET, and CPU_COUNT" ); |
---|
44 | CPU_FILL(&set1); |
---|
45 | |
---|
46 | /* test if all bits clear */ |
---|
47 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
48 | rtems_test_assert( CPU_ISSET(i, &set1) == 1 ); |
---|
49 | } |
---|
50 | rtems_test_assert( CPU_COUNT(&set1) == _NCPUBITS ); |
---|
51 | } |
---|
52 | |
---|
53 | static void test_cpu_equal_case_1(void) |
---|
54 | { |
---|
55 | /* |
---|
56 | * CPU_EQUAL |
---|
57 | */ |
---|
58 | puts( "Exercise CPU_ZERO, CPU_EQUAL, CPU_CMP, and CPU_EMPTY" ); |
---|
59 | CPU_ZERO(&set1); |
---|
60 | CPU_ZERO(&set2); |
---|
61 | |
---|
62 | /* test that all bits are equal */ |
---|
63 | rtems_test_assert( CPU_EQUAL(&set1, &set2) ); |
---|
64 | |
---|
65 | /* compare all bits */ |
---|
66 | rtems_test_assert( !CPU_CMP(&set1, &set2) ); |
---|
67 | |
---|
68 | /* compare all bits */ |
---|
69 | rtems_test_assert( CPU_EMPTY(&set1) ); |
---|
70 | } |
---|
71 | |
---|
72 | static void test_cpu_set_case_1(size_t cpu) |
---|
73 | { |
---|
74 | size_t i; |
---|
75 | |
---|
76 | /* |
---|
77 | * Set to all zeros and verify |
---|
78 | */ |
---|
79 | DPRINT( "Exercise CPU_ZERO, CPU_SET(%zu), and CPU_ISSET\n", cpu ); |
---|
80 | CPU_ZERO(&set1); |
---|
81 | CPU_SET(cpu, &set1); |
---|
82 | |
---|
83 | /* test if all bits except 1 clear */ |
---|
84 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
85 | if (i==cpu) |
---|
86 | rtems_test_assert( CPU_ISSET(i, &set1) == 1 ); |
---|
87 | else |
---|
88 | rtems_test_assert( CPU_ISSET(i, &set1) == 0 ); |
---|
89 | |
---|
90 | rtems_test_assert( ! CPU_EMPTY(&set1) ); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | static void test_cpu_clr_case_1(size_t cpu) |
---|
95 | { |
---|
96 | size_t i; |
---|
97 | |
---|
98 | /* |
---|
99 | * Set to all zeros and verify |
---|
100 | */ |
---|
101 | DPRINT( "Exercise CPU_FILL, CPU_CLR(%zu), and CPU_ISSET\n", cpu ); |
---|
102 | CPU_FILL(&set1); |
---|
103 | CPU_CLR(cpu, &set1); |
---|
104 | |
---|
105 | /* test if all bits except 5 are set */ |
---|
106 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
107 | if (i==cpu) |
---|
108 | rtems_test_assert( CPU_ISSET(i, &set1) == 0 ); |
---|
109 | else |
---|
110 | rtems_test_assert( CPU_ISSET(i, &set1) == 1 ); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | static void test_cpu_copy_case_1(void) |
---|
115 | { |
---|
116 | size_t i; |
---|
117 | |
---|
118 | /* |
---|
119 | * CPU_EQUAL |
---|
120 | */ |
---|
121 | puts( "Exercise CPU_ZERO, CPU_COPY, and CPU_ISSET" ); |
---|
122 | CPU_ZERO(&set1); |
---|
123 | CPU_FILL(&set2); |
---|
124 | |
---|
125 | CPU_COPY(&set1, &set2); |
---|
126 | |
---|
127 | /* test if all bits clear in set2 */ |
---|
128 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
129 | rtems_test_assert( CPU_ISSET(i, &set2) == 0 ); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | rtems_task Init( |
---|
134 | rtems_task_argument ignored |
---|
135 | ) |
---|
136 | { |
---|
137 | size_t i; |
---|
138 | |
---|
139 | TEST_BEGIN(); |
---|
140 | |
---|
141 | test_cpu_zero_case_1(); |
---|
142 | test_cpu_fill_case_1(); |
---|
143 | test_cpu_equal_case_1(); |
---|
144 | test_cpu_copy_case_1(); |
---|
145 | |
---|
146 | for (i=0 ; i<CPU_SETSIZE ; i++) { |
---|
147 | test_cpu_set_case_1(i); |
---|
148 | test_cpu_clr_case_1(i); |
---|
149 | } |
---|
150 | |
---|
151 | cpuset_logic_test(); |
---|
152 | |
---|
153 | TEST_END(); |
---|
154 | exit( 0 ); |
---|
155 | } |
---|