Skip to content

Commit 2a6c598

Browse files
bgoglinndenoyelle
authored andcommitted
tests/fake: check a TWEAK phase in the fake component
It restricts the topology to a single PU and single NUMA. Signed-off-by: Brice Goglin <[email protected]>
1 parent d588628 commit 2a6c598

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

hwloc/topology-fake.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99

1010
#include <stdlib.h>
1111

12+
static int
13+
hwloc_look_fake(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
14+
{
15+
hwloc_topology_t topology = backend->topology;
16+
17+
assert(dstatus->phase == HWLOC_DISC_PHASE_TWEAK);
18+
19+
if (getenv("HWLOC_DEBUG_FAKE_COMPONENT_TWEAK")) {
20+
hwloc_obj_t obj;
21+
int err;
22+
/* restrict to single (last) PU */
23+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU)-1);
24+
assert(obj);
25+
err = hwloc_topology_restrict(topology, obj->cpuset, 0);
26+
assert(!err);
27+
/* restrict to single (first) NUMA node */
28+
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0);
29+
assert(obj);
30+
err = hwloc_topology_restrict(topology, obj->nodeset, HWLOC_RESTRICT_FLAG_BYNODESET);
31+
assert(!err);
32+
}
33+
34+
return 0;
35+
}
36+
1237
static struct hwloc_backend *
1338
hwloc_fake_component_instantiate(struct hwloc_topology *topology __hwloc_attribute_unused,
1439
struct hwloc_disc_component *component __hwloc_attribute_unused,
@@ -17,14 +42,25 @@ hwloc_fake_component_instantiate(struct hwloc_topology *topology __hwloc_attribu
1742
const void *_data2 __hwloc_attribute_unused,
1843
const void *_data3 __hwloc_attribute_unused)
1944
{
45+
struct hwloc_backend *backend;
46+
47+
backend = hwloc_backend_alloc(topology, component);
48+
if (!backend)
49+
goto out;
50+
backend->discover = hwloc_look_fake;
51+
2052
if (getenv("HWLOC_DEBUG_FAKE_COMPONENT"))
2153
printf("fake component instantiated\n");
54+
55+
return backend;
56+
57+
out:
2258
return NULL;
2359
}
2460

2561
static struct hwloc_disc_component hwloc_fake_disc_component = {
2662
"fake",
27-
HWLOC_DISC_PHASE_MISC, /* so that it's always enabled when using the OS discovery */
63+
HWLOC_DISC_PHASE_TWEAK,
2864
0, /* nothing to exclude */
2965
hwloc_fake_component_instantiate,
3066
100, /* make sure it's loaded before anything conflicting excludes it */

utils/hwloc/test-fake-plugin.sh.in

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
#-*-sh-*-
33

44
#
5-
# Copyright © 2009-2014 Inria. All rights reserved.
5+
# Copyright © 2009-2019 Inria. All rights reserved.
66
# Copyright © 2009, 2011 Université Bordeaux
77
# Copyright © 2014 Cisco Systems, Inc. All rights reserved.
88
# See COPYING in top-level directory.
99
#
1010

1111
HWLOC_top_builddir="@HWLOC_top_builddir@"
12-
builddir="$HWLOC_top_builddir/utils/lstopo"
13-
lstopo="$builddir/lstopo-no-graphics"
12+
builddir="$HWLOC_top_builddir"
13+
lstopo="$builddir/utils/lstopo/lstopo-no-graphics"
14+
hcalc="$builddir/utils/hwloc/hwloc-calc"
1415

1516
HWLOC_PLUGINS_PATH=${HWLOC_top_builddir}/hwloc
1617
export HWLOC_PLUGINS_PATH
1718

18-
HWLOC_DEBUG_FAKE_COMPONENT=1
19-
export HWLOC_DEBUG_FAKE_COMPONENT
20-
2119
HWLOC_DEBUG_CHECK=1
2220
export HWLOC_DEBUG_CHECK
2321

@@ -35,6 +33,17 @@ file="$tmp/test-fake-plugin.output"
3533

3634
set -e
3735

36+
echo "Checking that the tweak phase restricts to a single PU and single NUMA"
37+
HWLOC_DEBUG_FAKE_COMPONENT_TWEAK=1
38+
export HWLOC_DEBUG_FAKE_COMPONENT_TWEAK
39+
40+
test `$hcalc -N pu root` = 1
41+
test `$hcalc -N numa root` = 1
42+
43+
echo "Checking that the init/instantiate/finalize callbacks are invoked"
44+
HWLOC_DEBUG_FAKE_COMPONENT=1
45+
export HWLOC_DEBUG_FAKE_COMPONENT
46+
3847
$lstopo > $file
3948

4049
grep "fake component initialized" $file \

0 commit comments

Comments
 (0)