1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2020 Inria. All rights reserved.
4 * Copyright © 2009, 2012 Université Bordeaux
5 * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
6 * See COPYING in top-level directory.
7 */
8
9 #include "hwloc.h"
10
11 #include "private/misc.h" /* for HWLOC_BITS_PER_LONG */
12
13 #include <assert.h>
14
15 /* check misc bitmap stuff */
16
main(void)17 int main(void)
18 {
19 hwloc_bitmap_t set;
20 unsigned long masks[10];
21
22 /* check an empty bitmap */
23 set = hwloc_bitmap_alloc();
24 assert(hwloc_bitmap_weight(set) == 0);
25 assert(hwloc_bitmap_first(set) == -1);
26 assert(hwloc_bitmap_last(set) == -1);
27 assert(hwloc_bitmap_to_ulong(set) == 0UL);
28 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
29 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
30 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
31 assert(hwloc_bitmap_nr_ulongs(set) == 0);
32 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
33 assert(masks[0] == 0UL);
34 assert(masks[1] == 0UL);
35 assert(masks[2] == 0UL);
36 assert(masks[3] == 0UL);
37 assert(masks[4] == 0UL);
38 assert(masks[5] == 0UL);
39 assert(masks[6] == 0UL);
40 assert(masks[7] == 0UL);
41 assert(masks[8] == 0UL);
42 assert(masks[9] == 0UL);
43 /* check a bitmap with only the first bit */
44 hwloc_bitmap_only(set, 0);
45 assert(hwloc_bitmap_weight(set) == 1);
46 assert(hwloc_bitmap_first(set) == 0);
47 assert(hwloc_bitmap_last(set) == 0);
48 assert(hwloc_bitmap_to_ulong(set) == 0x1);
49 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0x1);
50 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
51 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
52 assert(hwloc_bitmap_nr_ulongs(set) == 1);
53 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
54 assert(masks[0] == 0x1);
55 assert(masks[1] == 0UL);
56 assert(masks[2] == 0UL);
57 assert(masks[3] == 0UL);
58 assert(masks[4] == 0UL);
59 assert(masks[5] == 0UL);
60 assert(masks[6] == 0UL);
61 assert(masks[7] == 0UL);
62 assert(masks[8] == 0UL);
63 assert(masks[9] == 0UL);
64 /* check a bitmap with the entire first ulong */
65 hwloc_bitmap_from_ulong(set, ~0UL);
66 assert(hwloc_bitmap_weight(set) == HWLOC_BITS_PER_LONG);
67 assert(hwloc_bitmap_first(set) == 0);
68 assert(hwloc_bitmap_last(set) == HWLOC_BITS_PER_LONG-1);
69 assert(hwloc_bitmap_to_ulong(set) == ~0UL);
70 assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
71 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
72 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
73 assert(hwloc_bitmap_nr_ulongs(set) == 1);
74 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
75 assert(masks[0] == ~0UL);
76 assert(masks[1] == 0UL);
77 assert(masks[2] == 0UL);
78 assert(masks[3] == 0UL);
79 assert(masks[4] == 0UL);
80 assert(masks[5] == 0UL);
81 assert(masks[6] == 0UL);
82 assert(masks[7] == 0UL);
83 assert(masks[8] == 0UL);
84 assert(masks[9] == 0UL);
85 /* check a non-empty bitmap */
86 hwloc_bitmap_from_ith_ulong(set, 4, 0xff);
87 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
88 assert(hwloc_bitmap_to_ulong(set) == 0UL);
89 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
90 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
91 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
92 assert(hwloc_bitmap_nr_ulongs(set) == 5);
93 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
94 assert(masks[0] == 0UL);
95 assert(masks[1] == 0UL);
96 assert(masks[2] == 0UL);
97 assert(masks[3] == 0UL);
98 assert(masks[4] == 0xff);
99 assert(masks[5] == 0UL);
100 assert(masks[6] == 0UL);
101 assert(masks[7] == 0UL);
102 assert(masks[8] == 0UL);
103 assert(masks[9] == 0UL);
104 /* check a two-long bitmap */
105 hwloc_bitmap_from_ith_ulong(set, 4, 0xfe);
106 hwloc_bitmap_set_ith_ulong(set, 6, 0xef);
107 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xfe);
108 assert(hwloc_bitmap_to_ith_ulong(set, 6) == 0xef);
109 assert(hwloc_bitmap_to_ulong(set) == 0UL);
110 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
111 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
112 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
113 assert(hwloc_bitmap_nr_ulongs(set) == 7);
114 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
115 assert(masks[0] == 0UL);
116 assert(masks[1] == 0UL);
117 assert(masks[2] == 0UL);
118 assert(masks[3] == 0UL);
119 assert(masks[4] == 0xfe);
120 assert(masks[5] == 0UL);
121 assert(masks[6] == 0xef);
122 assert(masks[7] == 0UL);
123 assert(masks[8] == 0UL);
124 assert(masks[9] == 0UL);
125 /* check setting multiple ulongs at once */
126 masks[0] = 0UL;
127 masks[1] = 1UL;
128 masks[2] = 2UL;
129 masks[3] = 3UL;
130 masks[4] = 4UL;
131 masks[5] = 5UL;
132 masks[6] = 6UL;
133 masks[7] = 7UL;
134 masks[8] = 0UL;
135 assert(!hwloc_bitmap_from_ulongs(set, 9, masks));
136 assert(hwloc_bitmap_to_ulong(set) == 0UL);
137 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
138 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 1UL);
139 assert(hwloc_bitmap_to_ith_ulong(set, 2) == 2UL);
140 assert(hwloc_bitmap_to_ith_ulong(set, 3) == 3UL);
141 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 4UL);
142 assert(hwloc_bitmap_to_ith_ulong(set, 5) == 5UL);
143 assert(hwloc_bitmap_to_ith_ulong(set, 6) == 6UL);
144 assert(hwloc_bitmap_to_ith_ulong(set, 7) == 7UL);
145 assert(hwloc_bitmap_to_ith_ulong(set, 8) == 0UL);
146 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
147 assert(hwloc_bitmap_nr_ulongs(set) == 8);
148 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
149 assert(masks[0] == 0UL);
150 assert(masks[1] == 1UL);
151 assert(masks[2] == 2UL);
152 assert(masks[3] == 3UL);
153 assert(masks[4] == 4UL);
154 assert(masks[5] == 5UL);
155 assert(masks[6] == 6UL);
156 assert(masks[7] == 7UL);
157 assert(masks[8] == 0UL);
158 assert(masks[9] == 0UL);
159 /* check a zeroed bitmap */
160 hwloc_bitmap_zero(set);
161 assert(hwloc_bitmap_weight(set) == 0);
162 assert(hwloc_bitmap_first(set) == -1);
163 assert(hwloc_bitmap_last(set) == -1);
164 assert(hwloc_bitmap_to_ulong(set) == 0UL);
165 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
166 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
167 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0UL);
168 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
169 assert(hwloc_bitmap_nr_ulongs(set) == 0);
170 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
171 assert(masks[0] == 0UL);
172 assert(masks[1] == 0UL);
173 assert(masks[2] == 0UL);
174 assert(masks[3] == 0UL);
175 assert(masks[4] == 0UL);
176 assert(masks[5] == 0UL);
177 assert(masks[6] == 0UL);
178 assert(masks[7] == 0UL);
179 assert(masks[8] == 0UL);
180 assert(masks[9] == 0UL);
181 hwloc_bitmap_free(set);
182
183 /* check a full bitmap */
184 set = hwloc_bitmap_alloc_full();
185 assert(hwloc_bitmap_weight(set) == -1);
186 assert(hwloc_bitmap_first(set) == 0);
187 assert(hwloc_bitmap_last(set) == -1);
188 assert(hwloc_bitmap_to_ulong(set) == ~0UL);
189 assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
190 assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL);
191 assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL);
192 assert(hwloc_bitmap_nr_ulongs(set) == -1);
193 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
194 assert(masks[0] == ~0UL);
195 assert(masks[1] == ~0UL);
196 assert(masks[2] == ~0UL);
197 assert(masks[3] == ~0UL);
198 assert(masks[4] == ~0UL);
199 assert(masks[5] == ~0UL);
200 assert(masks[6] == ~0UL);
201 assert(masks[7] == ~0UL);
202 assert(masks[8] == ~0UL);
203 assert(masks[9] == ~0UL);
204 /* check a almost full bitmap */
205 hwloc_bitmap_set_ith_ulong(set, 4, 0xff);
206 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
207 assert(hwloc_bitmap_to_ulong(set) == ~0UL);
208 assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
209 assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL);
210 assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL);
211 assert(hwloc_bitmap_nr_ulongs(set) == -1);
212 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
213 assert(masks[0] == ~0UL);
214 assert(masks[1] == ~0UL);
215 assert(masks[2] == ~0UL);
216 assert(masks[3] == ~0UL);
217 assert(masks[4] == 0xff);
218 assert(masks[5] == ~0UL);
219 assert(masks[6] == ~0UL);
220 assert(masks[7] == ~0UL);
221 assert(masks[8] == ~0UL);
222 assert(masks[9] == ~0UL);
223 /* check a almost empty bitmap */
224 hwloc_bitmap_from_ith_ulong(set, 4, 0xff);
225 assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
226 assert(hwloc_bitmap_to_ulong(set) == 0UL);
227 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
228 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
229 assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
230 assert(hwloc_bitmap_nr_ulongs(set) == 5);
231 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
232 assert(masks[0] == 0UL);
233 assert(masks[1] == 0UL);
234 assert(masks[2] == 0UL);
235 assert(masks[3] == 0UL);
236 assert(masks[4] == 0xff);
237 assert(masks[5] == 0UL);
238 assert(masks[6] == 0UL);
239 assert(masks[7] == 0UL);
240 assert(masks[8] == 0UL);
241 assert(masks[9] == 0UL);
242 /* check a filled bitmap */
243 hwloc_bitmap_fill(set);
244 assert(hwloc_bitmap_weight(set) == -1);
245 assert(hwloc_bitmap_first(set) == 0);
246 assert(hwloc_bitmap_last(set) == -1);
247 assert(hwloc_bitmap_to_ith_ulong(set, 4) == ~0UL);
248 assert(hwloc_bitmap_to_ulong(set) == ~0UL);
249 assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
250 assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL);
251 assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL);
252 assert(hwloc_bitmap_nr_ulongs(set) == -1);
253 assert(!hwloc_bitmap_to_ulongs(set, 10, masks));
254 assert(masks[0] == ~0UL);
255 assert(masks[1] == ~0UL);
256 assert(masks[2] == ~0UL);
257 assert(masks[3] == ~0UL);
258 assert(masks[4] == ~0UL);
259 assert(masks[5] == ~0UL);
260 assert(masks[6] == ~0UL);
261 assert(masks[7] == ~0UL);
262 assert(masks[8] == ~0UL);
263 assert(masks[9] == ~0UL);
264 hwloc_bitmap_free(set);
265
266 /* check ranges */
267 set = hwloc_bitmap_alloc();
268 assert(hwloc_bitmap_iszero(set));
269 assert(!hwloc_bitmap_isfull(set));
270 assert(hwloc_bitmap_weight(set) == 0);
271 assert(hwloc_bitmap_first(set) == -1);
272 assert(hwloc_bitmap_last(set) == -1);
273 assert(hwloc_bitmap_first_unset(set) == 0);
274 assert(hwloc_bitmap_last_unset(set) == -1);
275 assert(hwloc_bitmap_next_unset(set, -1) == 0);
276 /* 20-39 */
277 hwloc_bitmap_set_range(set, 20, 39);
278 assert(!hwloc_bitmap_iszero(set));
279 assert(!hwloc_bitmap_isfull(set));
280 assert(hwloc_bitmap_weight(set) == 20);
281 assert(hwloc_bitmap_first(set) == 20);
282 assert(hwloc_bitmap_last(set) == 39);
283 assert(hwloc_bitmap_first_unset(set) == 0);
284 assert(hwloc_bitmap_last_unset(set) == -1);
285 assert(hwloc_bitmap_next_unset(set, 19) == 40);
286 /* 20-39,80- */
287 hwloc_bitmap_set_range(set, 80, -1);
288 assert(!hwloc_bitmap_iszero(set));
289 assert(!hwloc_bitmap_isfull(set));
290 assert(hwloc_bitmap_weight(set) == -1);
291 assert(hwloc_bitmap_first(set) == 20);
292 assert(hwloc_bitmap_next(set, 39) == 80);
293 assert(hwloc_bitmap_last(set) == -1);
294 assert(hwloc_bitmap_first_unset(set) == 0);
295 assert(hwloc_bitmap_last_unset(set) == 79);
296 assert(hwloc_bitmap_next_unset(set, 79) == -1);
297 /* 20-39,80-359 */
298 hwloc_bitmap_clr_range(set, 360, -1);
299 assert(!hwloc_bitmap_iszero(set));
300 assert(!hwloc_bitmap_isfull(set));
301 assert(hwloc_bitmap_weight(set) == 300);
302 assert(hwloc_bitmap_first(set) == 20);
303 assert(hwloc_bitmap_next(set, 39) == 80);
304 assert(hwloc_bitmap_last(set) == 359);
305 assert(hwloc_bitmap_first_unset(set) == 0);
306 assert(hwloc_bitmap_last_unset(set) == -1);
307 assert(hwloc_bitmap_next_unset(set, 100) == 360);
308 /* 20-39,80-179,280-359 */
309 hwloc_bitmap_clr_range(set, 180, 279);
310 assert(!hwloc_bitmap_iszero(set));
311 assert(!hwloc_bitmap_isfull(set));
312 assert(hwloc_bitmap_weight(set) == 200);
313 assert(hwloc_bitmap_first(set) == 20);
314 assert(hwloc_bitmap_next(set, 39) == 80);
315 assert(hwloc_bitmap_next(set, 179) == 280);
316 assert(hwloc_bitmap_last(set) == 359);
317 assert(hwloc_bitmap_first_unset(set) == 0);
318 assert(hwloc_bitmap_last_unset(set) == -1);
319 assert(hwloc_bitmap_next_unset(set, 100) == 180);
320 /* 20- */
321 hwloc_bitmap_set_range(set, 35, -1);
322 assert(!hwloc_bitmap_iszero(set));
323 assert(!hwloc_bitmap_isfull(set));
324 assert(hwloc_bitmap_weight(set) == -1);
325 assert(hwloc_bitmap_first(set) == 20);
326 assert(hwloc_bitmap_last(set) == -1);
327 assert(hwloc_bitmap_first_unset(set) == 0);
328 assert(hwloc_bitmap_last_unset(set) == 19);
329 assert(hwloc_bitmap_next_unset(set, 100) == -1);
330 /* 20-419 */
331 hwloc_bitmap_clr_range(set, 420, -1);
332 assert(!hwloc_bitmap_iszero(set));
333 assert(!hwloc_bitmap_isfull(set));
334 assert(hwloc_bitmap_weight(set) == 400);
335 assert(hwloc_bitmap_first(set) == 20);
336 assert(hwloc_bitmap_last(set) == 419);
337 assert(hwloc_bitmap_first_unset(set) == 0);
338 assert(hwloc_bitmap_last_unset(set) == -1);
339 assert(hwloc_bitmap_next_unset(set, 100) == 420);
340 /* 20-419,1000- */
341 hwloc_bitmap_set_range(set, 1000, -1);
342 assert(!hwloc_bitmap_iszero(set));
343 assert(!hwloc_bitmap_isfull(set));
344 assert(hwloc_bitmap_weight(set) == -1);
345 assert(hwloc_bitmap_first(set) == 20);
346 assert(hwloc_bitmap_next(set, 419) == 1000);
347 assert(hwloc_bitmap_last(set) == -1);
348 assert(hwloc_bitmap_first_unset(set) == 0);
349 assert(hwloc_bitmap_last_unset(set) == 999);
350 assert(hwloc_bitmap_next_unset(set, 1000) == -1);
351 /* 20- */
352 hwloc_bitmap_set_range(set, 420, 999);
353 assert(!hwloc_bitmap_iszero(set));
354 assert(!hwloc_bitmap_isfull(set));
355 assert(hwloc_bitmap_weight(set) == -1);
356 assert(hwloc_bitmap_first(set) == 20);
357 assert(hwloc_bitmap_last(set) == -1);
358 assert(hwloc_bitmap_first_unset(set) == 0);
359 assert(hwloc_bitmap_last_unset(set) == 19);
360 assert(hwloc_bitmap_next_unset(set, 1000) == -1);
361 /* 0- */
362 hwloc_bitmap_set_range(set, 0, 25);
363 assert(!hwloc_bitmap_iszero(set));
364 assert(hwloc_bitmap_isfull(set));
365 assert(hwloc_bitmap_weight(set) == -1);
366 assert(hwloc_bitmap_first(set) == 0);
367 assert(hwloc_bitmap_last(set) == -1);
368 assert(hwloc_bitmap_first_unset(set) == -1);
369 assert(hwloc_bitmap_last_unset(set) == -1);
370 assert(hwloc_bitmap_next_unset(set, 1000) == -1);
371 /* 0-99,1500- */
372 hwloc_bitmap_clr_range(set, 100, 1499);
373 assert(!hwloc_bitmap_iszero(set));
374 assert(!hwloc_bitmap_isfull(set));
375 assert(hwloc_bitmap_weight(set) == -1);
376 assert(hwloc_bitmap_first(set) == 0);
377 assert(hwloc_bitmap_next(set, 99) == 1500);
378 assert(hwloc_bitmap_last(set) == -1);
379 assert(hwloc_bitmap_first_unset(set) == 100);
380 assert(hwloc_bitmap_last_unset(set) == 1499);
381 assert(hwloc_bitmap_next_unset(set, 99) == 100);
382 /* 0-99,1500-1999 */
383 hwloc_bitmap_clr_range(set, 2000, -1);
384 assert(!hwloc_bitmap_iszero(set));
385 assert(!hwloc_bitmap_isfull(set));
386 assert(hwloc_bitmap_weight(set) == 600);
387 assert(hwloc_bitmap_first(set) == 0);
388 assert(hwloc_bitmap_next(set, 99) == 1500);
389 assert(hwloc_bitmap_last(set) == 1999);
390 assert(hwloc_bitmap_first_unset(set) == 100);
391 assert(hwloc_bitmap_last_unset(set) == -1);
392 assert(hwloc_bitmap_next_unset(set, 1800) == 2000);
393 /* 0-99,1500- */
394 hwloc_bitmap_set_range(set, 1500, -1);
395 assert(!hwloc_bitmap_iszero(set));
396 assert(!hwloc_bitmap_isfull(set));
397 assert(hwloc_bitmap_weight(set) == -1);
398 assert(hwloc_bitmap_first(set) == 0);
399 assert(hwloc_bitmap_next(set, 99) == 1500);
400 assert(hwloc_bitmap_last(set) == -1);
401 assert(hwloc_bitmap_first_unset(set) == 100);
402 assert(hwloc_bitmap_last_unset(set) == 1499);
403 assert(hwloc_bitmap_next_unset(set, 1000) == 1001);
404 /* 0-99,1500-2199 */
405 hwloc_bitmap_clr_range(set, 2200, -1);
406 assert(!hwloc_bitmap_iszero(set));
407 assert(!hwloc_bitmap_isfull(set));
408 assert(hwloc_bitmap_weight(set) == 800);
409 assert(hwloc_bitmap_first(set) == 0);
410 assert(hwloc_bitmap_next(set, 99) == 1500);
411 assert(hwloc_bitmap_last(set) == 2199);
412 assert(hwloc_bitmap_first_unset(set) == 100);
413 assert(hwloc_bitmap_last_unset(set) == -1);
414 assert(hwloc_bitmap_next_unset(set, 1800) == 2200);
415 /* 0-99,1500-1999 */
416 hwloc_bitmap_clr_range(set, 2000, -1);
417 assert(!hwloc_bitmap_iszero(set));
418 assert(!hwloc_bitmap_isfull(set));
419 assert(hwloc_bitmap_weight(set) == 600);
420 assert(hwloc_bitmap_first(set) == 0);
421 assert(hwloc_bitmap_next(set, 99) == 1500);
422 assert(hwloc_bitmap_last(set) == 1999);
423 assert(hwloc_bitmap_first_unset(set) == 100);
424 assert(hwloc_bitmap_last_unset(set) == -1);
425 assert(hwloc_bitmap_next_unset(set, 1800) == 2000);
426 /* 0-99,1500- */
427 hwloc_bitmap_set_range(set, 2000, -1);
428 assert(!hwloc_bitmap_iszero(set));
429 assert(!hwloc_bitmap_isfull(set));
430 assert(hwloc_bitmap_weight(set) == -1);
431 assert(hwloc_bitmap_first(set) == 0);
432 assert(hwloc_bitmap_next(set, 99) == 1500);
433 assert(hwloc_bitmap_last(set) == -1);
434 assert(hwloc_bitmap_first_unset(set) == 100);
435 assert(hwloc_bitmap_last_unset(set) == 1499);
436 assert(hwloc_bitmap_next_unset(set, 1800) == -1);
437 /* 0-99,1500-1999 */
438 hwloc_bitmap_clr_range(set, 2000, -1);
439 assert(!hwloc_bitmap_iszero(set));
440 assert(!hwloc_bitmap_isfull(set));
441 assert(hwloc_bitmap_weight(set) == 600);
442 assert(hwloc_bitmap_first(set) == 0);
443 assert(hwloc_bitmap_next(set, 99) == 1500);
444 assert(hwloc_bitmap_last(set) == 1999);
445 assert(hwloc_bitmap_first_unset(set) == 100);
446 assert(hwloc_bitmap_last_unset(set) == -1);
447 assert(hwloc_bitmap_next_unset(set, 1800) == 2000);
448 /* 0-99,200-1999 */
449 hwloc_bitmap_set_range(set, 200, 1499);
450 assert(!hwloc_bitmap_iszero(set));
451 assert(!hwloc_bitmap_isfull(set));
452 assert(hwloc_bitmap_weight(set) == 1900);
453 assert(hwloc_bitmap_first(set) == 0);
454 assert(hwloc_bitmap_next(set, 99) == 200);
455 assert(hwloc_bitmap_last(set) == 1999);
456 assert(hwloc_bitmap_first_unset(set) == 100);
457 assert(hwloc_bitmap_last_unset(set) == -1);
458 assert(hwloc_bitmap_next_unset(set, 200) == 2000);
459 /* 0-99,1999 */
460 hwloc_bitmap_clr_range(set, 200, 1998);
461 assert(!hwloc_bitmap_iszero(set));
462 assert(!hwloc_bitmap_isfull(set));
463 assert(hwloc_bitmap_weight(set) == 101);
464 assert(hwloc_bitmap_first(set) == 0);
465 assert(hwloc_bitmap_next(set, 99) == 1999);
466 assert(hwloc_bitmap_last(set) == 1999);
467 assert(hwloc_bitmap_first_unset(set) == 100);
468 assert(hwloc_bitmap_last_unset(set) == -1);
469 assert(hwloc_bitmap_next_unset(set, 1999) == 2000);
470 /* 1999 */
471 hwloc_bitmap_clr_range(set, 0, 100);
472 assert(!hwloc_bitmap_iszero(set));
473 assert(!hwloc_bitmap_isfull(set));
474 assert(hwloc_bitmap_weight(set) == 1);
475 assert(hwloc_bitmap_first(set) == 1999);
476 assert(hwloc_bitmap_last(set) == 1999);
477 assert(hwloc_bitmap_first_unset(set) == 0);
478 assert(hwloc_bitmap_last_unset(set) == -1);
479 assert(hwloc_bitmap_next_unset(set, -1) == 0);
480 assert(hwloc_bitmap_next_unset(set, 1999) == 2000);
481 /* empty */
482 hwloc_bitmap_clr(set, 1999);
483 assert(hwloc_bitmap_iszero(set));
484 assert(!hwloc_bitmap_isfull(set));
485 assert(hwloc_bitmap_weight(set) == 0);
486 assert(hwloc_bitmap_first(set) == -1);
487 assert(hwloc_bitmap_last(set) == -1);
488 assert(hwloc_bitmap_first_unset(set) == 0);
489 assert(hwloc_bitmap_last_unset(set) == -1);
490 assert(hwloc_bitmap_next_unset(set, -1) == 0);
491 assert(hwloc_bitmap_next_unset(set, 1999) == 2000);
492 hwloc_bitmap_free(set);
493
494 /* check miscellaneous other functions */
495 set = hwloc_bitmap_alloc();
496 /* from_ulong */
497 hwloc_bitmap_from_ulong(set, 0x0ff0);
498 assert(hwloc_bitmap_first(set) == 4);
499 assert(hwloc_bitmap_last(set) == 11);
500 assert(hwloc_bitmap_weight(set) == 8);
501 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0xff0);
502 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0);
503 /* from_ith_ulong */
504 hwloc_bitmap_zero(set);
505 assert(hwloc_bitmap_weight(set) == 0);
506 hwloc_bitmap_from_ith_ulong(set, 2, 0xff00);
507 assert(hwloc_bitmap_weight(set) == 8);
508 assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0);
509 assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0);
510 assert(hwloc_bitmap_to_ith_ulong(set, 2) == 0xff00);
511 assert(hwloc_bitmap_to_ith_ulong(set, 3) == 0);
512 /* allbut and not */
513 hwloc_bitmap_allbut(set, 153);
514 assert(hwloc_bitmap_weight(set) == -1);
515 hwloc_bitmap_not(set, set);
516 assert(hwloc_bitmap_weight(set) == 1);
517 assert(hwloc_bitmap_first(set) == 153);
518 assert(hwloc_bitmap_last(set) == 153);
519 /* clr_range */
520 hwloc_bitmap_fill(set);
521 hwloc_bitmap_clr_range(set, 178, 3589);
522 hwloc_bitmap_not(set, set);
523 assert(hwloc_bitmap_weight(set) == 3589-178+1);
524 assert(hwloc_bitmap_first(set) == 178);
525 assert(hwloc_bitmap_last(set) == 3589);
526 /* singlify */
527 hwloc_bitmap_zero(set);
528 hwloc_bitmap_set_range(set, 0, 127);
529 assert(hwloc_bitmap_weight(set) == 128);
530 hwloc_bitmap_not(set, set);
531 assert(hwloc_bitmap_weight(set) == -1);
532 hwloc_bitmap_singlify(set);
533 assert(hwloc_bitmap_weight(set) == 1);
534 assert(hwloc_bitmap_first(set) == 128);
535 assert(hwloc_bitmap_last(set) == 128);
536
537 hwloc_bitmap_free(set);
538
539 return 0;
540 }
541