1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2010 inria.  All rights reserved.
4  * Copyright © 2009 Université Bordeaux
5  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
9 #include <hwloc.h>
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <assert.h>
15 
16 /* check hwloc_bitmap_singlify() */
17 
main(void)18 int main(void)
19 {
20   hwloc_bitmap_t orig, expected;
21 
22   orig = hwloc_bitmap_alloc();
23   expected = hwloc_bitmap_alloc();
24 
25   /* empty set gives empty set */
26   hwloc_bitmap_singlify(orig);
27   assert(hwloc_bitmap_iszero(orig));
28 
29   /* full set gives first bit only */
30   hwloc_bitmap_fill(orig);
31   hwloc_bitmap_singlify(orig);
32   hwloc_bitmap_zero(expected);
33   hwloc_bitmap_set(expected, 0);
34   assert(hwloc_bitmap_isequal(orig, expected));
35   assert(!hwloc_bitmap_compare(orig, expected));
36 
37   /* actual non-trivial set */
38   hwloc_bitmap_zero(orig);
39   hwloc_bitmap_set(orig, 45);
40   hwloc_bitmap_set(orig, 46);
41   hwloc_bitmap_set(orig, 517);
42   hwloc_bitmap_singlify(orig);
43   hwloc_bitmap_zero(expected);
44   hwloc_bitmap_set(expected, 45);
45   assert(hwloc_bitmap_isequal(orig, expected));
46   assert(!hwloc_bitmap_compare(orig, expected));
47 
48   hwloc_bitmap_free(orig);
49   hwloc_bitmap_free(expected);
50 
51   return 0;
52 }
53