-
Notifications
You must be signed in to change notification settings - Fork 168
/
hwloc_topology_abi.c
173 lines (141 loc) · 5.53 KB
/
hwloc_topology_abi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright © 2017-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
#include "hwloc.h"
#include "private/debug.h" /* HWLOC_BUILD_ASSERT */
#include "private/private.h" /* for struct topology fields */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stddef.h>
int main(void)
{
hwloc_topology_t topo, dup;
int err;
printf("loading and checking...\n");
err = hwloc_topology_init(&topo);
assert(!err);
err = hwloc_topology_load(topo);
assert(!err);
err = hwloc_topology_abi_check(topo);
assert(!err);
printf("dupping and checking\n");
err = hwloc_topology_dup(&dup, topo);
assert(!err);
err = hwloc_topology_abi_check(dup);
assert(!err);
hwloc_topology_destroy(dup);
#if (defined HWLOC_LINUX_SYS) && (defined HWLOC_X86_64_ARCH)
if (!getenv("HWLOC_IGNORE_TOPOLOGY_ABI")) {
size_t size, offset __hwloc_attribute_unused;
printf("checking offsets and sizes in struct hwloc_topology for topology ABI 0x%x...\n", (unsigned) HWLOC_TOPOLOGY_ABI);
/*******************************************************************
* WARNING: if anything breaks below, the topology ABI has changed.
* HWLOC_TOPOLOGY_ABI must be bumped when updating these checks.
*******************************************************************/
HWLOC_BUILD_ASSERT(HWLOC_OBJ_TYPE_MAX == 20);
HWLOC_BUILD_ASSERT(HWLOC_NR_SLEVELS == 6);
offset = offsetof(struct hwloc_topology, topology_abi);
assert(offset == 0);
offset = offsetof(struct hwloc_topology, adopted_shmem_addr);
assert(offset == 240);
offset = offsetof(struct hwloc_topology, binding_hooks);
assert(offset == 464);
size = sizeof(struct hwloc_binding_hooks);
assert(size == 192);
offset = offsetof(struct hwloc_topology, support);
assert(offset == 656);
offset = offsetof(struct hwloc_topology, first_dist);
assert(offset == 712);
size = sizeof(struct hwloc_internal_distances_s);
assert(size == 88);
offset = offsetof(struct hwloc_topology, memattrs);
assert(offset == 736);
size = sizeof(struct hwloc_internal_memattr_s);
assert(size == 32);
size = sizeof(struct hwloc_internal_memattr_target_s);
assert(size == 48);
size = sizeof(struct hwloc_internal_memattr_initiator_s);
assert(size == 40);
size = sizeof(struct hwloc_internal_location_s);
assert(size == 32);
offset = offsetof(struct hwloc_topology, cpukinds);
assert(offset == 752);
size = sizeof(struct hwloc_internal_cpukind_s);
assert(size == 40);
offset = offsetof(struct hwloc_topology, grouping_next_subkind);
assert(offset == 792);
/* fields after this one aren't needed after discovery */
/* check bitmap ABI too, but those fields are private to bitmap.c */
printf("checking bitmaps for topology ABI 0x%x...\n", (unsigned) HWLOC_TOPOLOGY_ABI);
{
hwloc_bitmap_t set = hwloc_bitmap_alloc();
unsigned *ulongs_count = (unsigned*) (((char*)set) );
unsigned *ulongs_allocated = (unsigned*) (((char*)set)+4 );
unsigned long **ulongs = (unsigned long**) (((char*)set)+8 );
int *infinite = (int*) (((char*)set)+16);
/* empty set */
assert(*ulongs_count >= 1);
assert(*ulongs_allocated >= *ulongs_count);
assert((*ulongs)[0] == 0UL);
assert(!*infinite);
/* 260th bit */
hwloc_bitmap_set(set, 260);
assert(*ulongs_count >= 5);
assert(*ulongs_allocated >= *ulongs_count);
assert((*ulongs)[0] == 0UL);
assert((*ulongs)[1] == 0UL);
assert((*ulongs)[2] == 0UL);
assert((*ulongs)[3] == 0UL);
assert((*ulongs)[4] == 0x10UL);
assert(!*infinite);
/* full set */
hwloc_bitmap_fill(set);
assert((*ulongs)[0] == ~0UL);
assert(*infinite);
hwloc_bitmap_free(set);
}
/*******************************************************************
* WARNING: if anything breaks above, the topology ABI has changed.
* HWLOC_TOPOLOGY_ABI must be bumped when updating these checks.
*******************************************************************/
printf("checking sizes of public objects...\n");
/* if these first lines break, you may be breaking the main library ABI.
* adding fields may be OK. changing/removing likely isn't.
*/
size = sizeof(struct hwloc_obj);
assert(size == 248);
size = sizeof(union hwloc_obj_attr_u);
assert(size == 48);
size = sizeof(struct hwloc_info_s);
assert(size == 16);
size = sizeof(struct hwloc_topology_support);
assert(size == 32);
size = sizeof(struct hwloc_topology_discovery_support);
assert(size == 6);
size = sizeof(struct hwloc_topology_cpubind_support);
assert(size == 11);
size = sizeof(struct hwloc_topology_membind_support);
assert(size == 15);
size = sizeof(struct hwloc_topology_misc_support);
assert(size == 1);
size = sizeof(struct hwloc_distances_s);
assert(size == 32);
size = sizeof(struct hwloc_location);
assert(size == 16);
size = sizeof(union hwloc_topology_diff_u);
assert(size == 56);
size = sizeof(union hwloc_topology_diff_obj_attr_u);
assert(size == 32);
} else {
/* if building with non-binary-compatible compiler flags */
printf("checking topology ABI disabled by environment variable HWLOC_IGNORE_TOPOLOGY_ABI\n");
}
#else /* !LINUX || !X86_64 */
printf("checking topology ABI disabled, not running on Linux/x86_64\n");
#endif /* !LINUX || !X86_64 */
hwloc_topology_destroy(topo);
return 0;
}