Skip to content

Commit 690a672

Browse files
committed
tests: rework/cleanup some code to make changes easier
Don't hardwire types/depths, abstract-out some checks, use explicit types in synthetic string, use less NUMA nodes since their modeling will change soon, etc Signed-off-by: Brice Goglin <[email protected]>
1 parent 38afc20 commit 690a672

6 files changed

+114
-128
lines changed

tests/hwloc/hwloc_distances.c

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2010-2016 Inria. All rights reserved.
2+
* Copyright © 2010-2017 Inria. All rights reserved.
33
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
44
* See COPYING in top-level directory.
55
*/
@@ -36,13 +36,36 @@ static void print_distances(const struct hwloc_distances_s *distances)
3636
}
3737
}
3838

39+
static void check_distances(hwloc_topology_t topology, unsigned depth, unsigned expected)
40+
{
41+
struct hwloc_distances_s *distances[2];
42+
unsigned nr = 0;
43+
int err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
44+
assert(!err);
45+
assert(nr == expected);
46+
if (!nr) {
47+
printf("No distance at depth %u\n", depth);
48+
return;
49+
}
50+
nr = 2;
51+
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
52+
assert(!err);
53+
printf("distance matrix for depth %u:\n", depth);
54+
print_distances(distances[0]);
55+
hwloc_distances_release(topology, distances[0]);
56+
if (nr > 1) {
57+
print_distances(distances[1]);
58+
hwloc_distances_release(topology, distances[1]);
59+
}
60+
}
61+
3962
int main(void)
4063
{
4164
hwloc_topology_t topology;
4265
struct hwloc_distances_s *distances[2];
4366
hwloc_obj_t objs[16];
4467
uint64_t values[16*16];
45-
unsigned depth, topodepth;
68+
unsigned topodepth;
4669
unsigned i, j, k, nr;
4770
int err;
4871

@@ -75,25 +98,12 @@ int main(void)
7598
assert(!err);
7699

77100
topodepth = hwloc_topology_get_depth(topology);
78-
for(depth=0; depth<topodepth; depth++) {
79-
nr = 0;
80-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
81-
assert(!err);
82-
if (depth == 2)
83-
assert(nr == 1);
84-
else
85-
assert(!nr);
86-
if (!nr) {
87-
printf("No distance at depth %u\n", depth);
88-
continue;
89-
}
90-
nr = 1;
91-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
92-
assert(!err);
93-
printf("distance matrix for depth %u:\n", depth);
94-
print_distances(distances[0]);
95-
hwloc_distances_release(topology, distances[0]);
96-
}
101+
assert(topodepth == 5);
102+
check_distances(topology, 0, 0);
103+
check_distances(topology, 1, 0);
104+
check_distances(topology, 2, 1);
105+
check_distances(topology, 3, 0);
106+
check_distances(topology, 4, 0);
97107

98108
/* check numa distances */
99109
printf("Checking NUMA distances\n");
@@ -137,25 +147,13 @@ int main(void)
137147
assert(!err);
138148

139149
topodepth = hwloc_topology_get_depth(topology);
140-
for(depth=0; depth<topodepth; depth++) {
141-
nr = 0;
142-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
143-
assert(!err);
144-
if (depth == 2 || depth == 5)
145-
assert(nr == 1);
146-
else
147-
assert(!nr);
148-
if (!nr) {
149-
printf("No distance at depth %u\n", depth);
150-
continue;
151-
}
152-
nr = 1;
153-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
154-
assert(!err);
155-
printf("distance matrix for depth %u:\n", depth);
156-
print_distances(distances[0]);
157-
hwloc_distances_release(topology, distances[0]);
158-
}
150+
assert(topodepth == 6);
151+
check_distances(topology, 0, 0);
152+
check_distances(topology, 1, 0);
153+
check_distances(topology, 2, 1);
154+
check_distances(topology, 3, 0);
155+
check_distances(topology, 4, 0);
156+
check_distances(topology, 5, 1);
159157

160158
/* check PU distances */
161159
printf("Checking PU distances\n");
@@ -191,31 +189,13 @@ int main(void)
191189
assert(!err);
192190

193191
topodepth = hwloc_topology_get_depth(topology);
194-
for(depth=0; depth<topodepth; depth++) {
195-
nr = 0;
196-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
197-
assert(!err);
198-
if (depth == 2)
199-
assert(nr == 1);
200-
else if (depth == 5)
201-
assert(nr == 2);
202-
else
203-
assert(!nr);
204-
if (!nr) {
205-
printf("No distance at depth %u\n", depth);
206-
continue;
207-
}
208-
nr = 2;
209-
err = hwloc_distances_get_by_depth(topology, depth, &nr, distances, 0, 0);
210-
assert(!err);
211-
printf("distance matrix for depth %u:\n", depth);
212-
print_distances(distances[0]);
213-
hwloc_distances_release(topology, distances[0]);
214-
if (nr > 1) {
215-
print_distances(distances[1]);
216-
hwloc_distances_release(topology, distances[1]);
217-
}
218-
}
192+
assert(topodepth == 6);
193+
check_distances(topology, 0, 0);
194+
check_distances(topology, 1, 0);
195+
check_distances(topology, 2, 1);
196+
check_distances(topology, 3, 0);
197+
check_distances(topology, 4, 0);
198+
check_distances(topology, 5, 2);
219199

220200
/* check PU distances */
221201
printf("Checking 2nd PU distances\n");

tests/hwloc/hwloc_get_cache_covering_cpuset.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2015 Inria. All rights reserved.
3+
* Copyright © 2009-2017 Inria. All rights reserved.
44
* Copyright © 2009 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -15,7 +15,7 @@
1515

1616
/* check hwloc_get_cache_covering_cpuset() */
1717

18-
#define SYNTHETIC_TOPOLOGY_DESCRIPTION "6 5 4 3 2" /* 736bits wide topology */
18+
#define SYNTHETIC_TOPOLOGY_DESCRIPTION "numa:6 pack:5 l2:4 core:3 pu:2" /* 736bits wide topology */
1919

2020
int main(void)
2121
{
@@ -30,7 +30,7 @@ int main(void)
3030
/* check the cache above a given cpu */
3131
#define CPUINDEX 180
3232
set = hwloc_bitmap_alloc();
33-
obj = hwloc_get_obj_by_depth(topology, 5, CPUINDEX);
33+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, CPUINDEX);
3434
assert(obj);
3535
hwloc_bitmap_or(set, set, obj->cpuset);
3636
cache = hwloc_get_cache_covering_cpuset(topology, set);
@@ -44,10 +44,10 @@ int main(void)
4444
#define CPUINDEX1 180
4545
#define CPUINDEX2 183
4646
set = hwloc_bitmap_alloc();
47-
obj = hwloc_get_obj_by_depth(topology, 5, CPUINDEX1);
47+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, CPUINDEX1);
4848
assert(obj);
4949
hwloc_bitmap_or(set, set, obj->cpuset);
50-
obj = hwloc_get_obj_by_depth(topology, 5, CPUINDEX2);
50+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, CPUINDEX2);
5151
assert(obj);
5252
hwloc_bitmap_or(set, set, obj->cpuset);
5353
cache = hwloc_get_cache_covering_cpuset(topology, set);
@@ -62,10 +62,10 @@ int main(void)
6262
#undef CPUINDEX1
6363
#define CPUINDEX1 300
6464
set = hwloc_bitmap_alloc();
65-
obj = hwloc_get_obj_by_depth(topology, 5, CPUINDEX1);
65+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, CPUINDEX1);
6666
assert(obj);
6767
hwloc_bitmap_or(set, set, obj->cpuset);
68-
obj = hwloc_get_obj_by_depth(topology, 5, CPUINDEX2);
68+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, CPUINDEX2);
6969
assert(obj);
7070
hwloc_bitmap_or(set, set, obj->cpuset);
7171
cache = hwloc_get_cache_covering_cpuset(topology, set);
@@ -74,7 +74,7 @@ int main(void)
7474

7575
/* check no cache above higher level */
7676
set = hwloc_bitmap_alloc();
77-
obj = hwloc_get_obj_by_depth(topology, 2, 0);
77+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 0);
7878
assert(obj);
7979
hwloc_bitmap_or(set, set, obj->cpuset);
8080
cache = hwloc_get_cache_covering_cpuset(topology, set);

tests/hwloc/hwloc_get_largest_objs_inside_cpuset.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2010 inria. All rights reserved.
3+
* Copyright © 2009-2017 Inria. All rights reserved.
44
* Copyright © 2009 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -17,7 +17,7 @@
1717
* and hwloc_get_first_largest_obj_inside_cpuset()
1818
*/
1919

20-
#define SYNTHETIC_TOPOLOGY_DESCRIPTION "6 5 4 3 2" /* 736bits wide topology */
20+
#define SYNTHETIC_TOPOLOGY_DESCRIPTION "numa:6 pack:5 l2:4 core:3 pu:2" /* 736bits wide topology */
2121

2222
#define GIVEN_LARGESPLIT_CPUSET_STRING "8000,,,,,,,,,,,,,,,,,,,,,,1" /* first and last(735th) bit set */
2323
#define GIVEN_TOOLARGE_CPUSET_STRING "10000,,,,,,,,,,,,,,,,,,,,,,0" /* 736th bit is too large for the 720-wide topology */
@@ -28,16 +28,17 @@
2828
int main(void)
2929
{
3030
hwloc_topology_t topology;
31-
unsigned depth;
3231
hwloc_obj_t objs[OBJ_MAX];
3332
hwloc_obj_t obj;
3433
hwloc_bitmap_t set;
34+
unsigned pus;
3535
int ret;
3636

3737
hwloc_topology_init(&topology);
3838
hwloc_topology_set_synthetic(topology, SYNTHETIC_TOPOLOGY_DESCRIPTION);
3939
hwloc_topology_load(topology);
40-
depth = hwloc_topology_get_depth(topology);
40+
41+
pus = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU);
4142

4243
/* just get the system object */
4344
obj = hwloc_get_root_obj(topology);
@@ -48,7 +49,7 @@ int main(void)
4849
assert(objs[0] == obj);
4950

5051
/* just get the very last object */
51-
obj = hwloc_get_obj_by_depth(topology, depth-1, hwloc_get_nbobjs_by_depth(topology, depth-1)-1);
52+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, pus-1);
5253
ret = hwloc_get_largest_objs_inside_cpuset(topology, obj->cpuset, objs, 1);
5354
assert(ret == 1);
5455
assert(objs[0] == obj);
@@ -75,21 +76,21 @@ int main(void)
7576
hwloc_bitmap_sscanf(set, GIVEN_LARGESPLIT_CPUSET_STRING);
7677
ret = hwloc_get_largest_objs_inside_cpuset(topology, set, objs, 1);
7778
assert(ret == 1);
78-
assert(objs[0] == hwloc_get_obj_by_depth(topology, depth-1, 0));
79+
assert(objs[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0));
7980
objs[0] = hwloc_get_first_largest_obj_inside_cpuset(topology, set);
80-
assert(objs[0] == hwloc_get_obj_by_depth(topology, depth-1, 0));
81+
assert(objs[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0));
8182
/* try a harder one with lots of objs instead of 2 needed */
8283
ret = hwloc_get_largest_objs_inside_cpuset(topology, set, objs, 2);
8384
assert(ret == 2);
84-
assert(objs[0] == hwloc_get_obj_by_depth(topology, depth-1, 0));
85-
assert(objs[1] == hwloc_get_obj_by_depth(topology, depth-1, hwloc_get_nbobjs_by_depth(topology, depth-1)-1));
85+
assert(objs[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0));
86+
assert(objs[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, pus-1));
8687
objs[0] = hwloc_get_first_largest_obj_inside_cpuset(topology, set);
8788
hwloc_bitmap_andnot(set, set, objs[0]->cpuset);
8889
objs[1] = hwloc_get_first_largest_obj_inside_cpuset(topology, set);
8990
hwloc_bitmap_andnot(set, set, objs[1]->cpuset);
9091
objs[2] = hwloc_get_first_largest_obj_inside_cpuset(topology, set);
91-
assert(objs[0] == hwloc_get_obj_by_depth(topology, depth-1, 0));
92-
assert(objs[1] == hwloc_get_obj_by_depth(topology, depth-1, hwloc_get_nbobjs_by_depth(topology, depth-1)-1));
92+
assert(objs[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0));
93+
assert(objs[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, pus-1));
9394
assert(objs[2] == NULL);
9495
assert(hwloc_bitmap_iszero(set));
9596
hwloc_bitmap_free(set);
@@ -98,13 +99,13 @@ int main(void)
9899
set = hwloc_bitmap_alloc();
99100
hwloc_bitmap_sscanf(set, GIVEN_HARD_CPUSET_STRING);
100101
ret = hwloc_get_largest_objs_inside_cpuset(topology, set, objs, OBJ_MAX);
101-
assert(objs[0] == hwloc_get_obj_by_depth(topology, 5, 29));
102-
assert(objs[1] == hwloc_get_obj_by_depth(topology, 3, 5));
103-
assert(objs[2] == hwloc_get_obj_by_depth(topology, 3, 6));
104-
assert(objs[3] == hwloc_get_obj_by_depth(topology, 3, 7));
105-
assert(objs[4] == hwloc_get_obj_by_depth(topology, 2, 2));
106-
assert(objs[5] == hwloc_get_obj_by_depth(topology, 4, 36));
107-
assert(objs[6] == hwloc_get_obj_by_depth(topology, 5, 74));
102+
assert(objs[0] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 29));
103+
assert(objs[1] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_L2CACHE, 5));
104+
assert(objs[2] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_L2CACHE, 6));
105+
assert(objs[3] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_L2CACHE, 7));
106+
assert(objs[4] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 2));
107+
assert(objs[5] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 36));
108+
assert(objs[6] == hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 74));
108109
hwloc_bitmap_free(set);
109110

110111
hwloc_topology_destroy(topology);

tests/hwloc/hwloc_get_obj_below_array_by_type.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2014 Inria. All rights reserved.
3+
* Copyright © 2009-2017 Inria. All rights reserved.
44
* Copyright © 2009 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -30,49 +30,49 @@ main (void)
3030
if (err)
3131
return EXIT_FAILURE;
3232

33-
hwloc_topology_set_synthetic (topology, "node:3 pack:3 core:3 pu:3");
33+
hwloc_topology_set_synthetic (topology, "numa:1 pack:3 l2:3 core:3 pu:3");
3434

3535
err = hwloc_topology_load (topology);
3636
if (err)
3737
return EXIT_FAILURE;
3838

3939

4040
/* find the first thread */
41-
typev[0] = HWLOC_OBJ_NUMANODE; idxv[0] = 0;
42-
typev[1] = HWLOC_OBJ_PACKAGE; idxv[1] = 0;
41+
typev[0] = HWLOC_OBJ_PACKAGE; idxv[0] = 0;
42+
typev[1] = HWLOC_OBJ_L2CACHE; idxv[1] = 0;
4343
typev[2] = HWLOC_OBJ_CORE; idxv[2] = 0;
4444
typev[3] = HWLOC_OBJ_PU; idxv[3] = 0;
4545
obj = hwloc_get_obj_below_array_by_type(topology, 4, typev, idxv);
46-
assert(obj == hwloc_get_obj_by_depth(topology, 4, 0));
46+
assert(obj == hwloc_get_obj_by_depth(topology, 5, 0));
4747

4848
/* find the last core */
49-
typev[0] = HWLOC_OBJ_NUMANODE; idxv[0] = 2;
50-
typev[1] = HWLOC_OBJ_PACKAGE; idxv[1] = 2;
49+
typev[0] = HWLOC_OBJ_PACKAGE; idxv[0] = 2;
50+
typev[1] = HWLOC_OBJ_L2CACHE; idxv[1] = 2;
5151
typev[2] = HWLOC_OBJ_CORE; idxv[2] = 2;
5252
obj = hwloc_get_obj_below_array_by_type(topology, 3, typev, idxv);
53-
assert(obj == hwloc_get_obj_by_depth(topology, 3, 26));
53+
assert(obj == hwloc_get_obj_by_depth(topology, 4, 26));
5454

5555
/* misc tests */
5656

57-
typev[0] = HWLOC_OBJ_PACKAGE; idxv[0] = 2;
57+
typev[0] = HWLOC_OBJ_L2CACHE; idxv[0] = 2;
5858
obj = hwloc_get_obj_below_array_by_type(topology, 1, typev, idxv);
59-
assert(obj == hwloc_get_obj_by_depth(topology, 2, 2));
59+
assert(obj == hwloc_get_obj_by_depth(topology, 3, 2));
6060

61-
typev[0] = HWLOC_OBJ_NUMANODE; idxv[0] = 2;
61+
typev[0] = HWLOC_OBJ_PACKAGE; idxv[0] = 2;
6262
typev[1] = HWLOC_OBJ_CORE; idxv[1] = 2;
6363
obj = hwloc_get_obj_below_array_by_type(topology, 2, typev, idxv);
64-
assert(obj == hwloc_get_obj_by_depth(topology, 3, 20));
64+
assert(obj == hwloc_get_obj_by_depth(topology, 4, 20));
6565
/* check that hwloc_get_obj_below_by_type works as well */
6666
obj = hwloc_get_obj_below_by_type(topology, typev[0], idxv[0], typev[1], idxv[1]);
67-
assert(obj == hwloc_get_obj_by_depth(topology, 3, 20));
67+
assert(obj == hwloc_get_obj_by_depth(topology, 4, 20));
6868

69-
typev[0] = HWLOC_OBJ_PACKAGE; idxv[0] = 1;
69+
typev[0] = HWLOC_OBJ_L2CACHE; idxv[0] = 1;
7070
typev[1] = HWLOC_OBJ_PU; idxv[1] = 1;
7171
obj = hwloc_get_obj_below_array_by_type(topology, 2, typev, idxv);
72-
assert(obj == hwloc_get_obj_by_depth(topology, 4, 10));
72+
assert(obj == hwloc_get_obj_by_depth(topology, 5, 10));
7373
/* check that hwloc_get_obj_below_by_type works as well */
7474
obj = hwloc_get_obj_below_by_type(topology, typev[0], idxv[0], typev[1], idxv[1]);
75-
assert(obj == hwloc_get_obj_by_depth(topology, 4, 10));
75+
assert(obj == hwloc_get_obj_by_depth(topology, 5, 10));
7676

7777

7878
hwloc_topology_destroy (topology);

0 commit comments

Comments
 (0)