/
test-topology.sh.in
153 lines (121 loc) · 3.37 KB
/
test-topology.sh.in
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
#!@BASH@
#-*-sh-*-
#
# Copyright © 2009 CNRS
# Copyright © 2009-2019 Inria. All rights reserved.
# Copyright © 2009-2011 Université Bordeaux
# Copyright © 2009-2014 Cisco Systems, Inc. All rights reserved.
# See COPYING in top-level directory.
#
# Check the conformance of `lstopo' for all the Linux sysfs
# hierarchies available here. Return true on success.
HWLOC_top_srcdir="@HWLOC_top_srcdir@"
HWLOC_top_builddir="@HWLOC_top_builddir@"
lstopo="$HWLOC_top_builddir/utils/lstopo/lstopo-no-graphics"
HWLOC_PLUGINS_PATH=${HWLOC_top_builddir}/hwloc
export HWLOC_PLUGINS_PATH
HWLOC_DONT_ADD_VERSION_INFO=1
export HWLOC_DONT_ADD_VERSION_INFO
HWLOC_DEBUG_SORT_CHILDREN=1
export HWLOC_DEBUG_SORT_CHILDREN
HWLOC_COMPONENTS=linux,stop
export HWLOC_COMPONENTS
actual_output="$1"
# make sure we use default numeric formats (only XML outputs are dis-localized when supported)
LANG=C
LC_ALL=C
export LANG LC_ALL
error()
{
echo $@ 2>&1
}
# test_topology NAME TOPOLOGY-DIR
#
# Test the topology under TOPOLOGY-DIR. Return true on success.
test_topology ()
{
local name="$1"
local dir="$2"
local expected_output="$3"
local options="$4"
local output="`mktemp`"
export HWLOC_DEBUG_CHECK=1
opts="-v -"
[ -r "$options" ] && opts=`cat $options`
if ! "$lstopo" -i "$dir" --if fsroot $opts \
| sed -e 's/ gp_index="[0-9]\+"//' \
> "$output"
# filtered gp_index because it depends on the insertiong order, which may depend on pciaccess version, etc
then
result=1
else
if [ "$HWLOC_UPDATE_TEST_TOPOLOGY_OUTPUT" != 1 ]
then
@DIFF@ @HWLOC_DIFF_U@ @HWLOC_DIFF_W@ "$expected_output" "$output"
result=$?
else
if ! @DIFF@ "$expected_output" "$output" >/dev/null
then
cp -f "$output" "$expected_output"
echo "Updated $expected_output"
fi
result=0
fi
fi
rm "$output"
return $result
}
# test_eligible TOPOLOGY-DIR
#
# Return true if the topology under TOPOLOGY-DIR is eligible for
# testing with the current flavor.
test_eligible()
{
local dir="$1"
local output="$2"
[ -d "$dir" -a -f "$output" ]
}
if [ ! -x "$lstopo" ]
then
error "Could not find executable file \`$lstopo'."
exit 1
fi
topology="${actual_output%.output}"
if [ "$topology" = "$actual_output" ] ;
then
error "Input file \`$1' should end with .output"
exit 1
fi
actual_options="$topology".options
# if there's a .source file, use the tarball name it contains instead of $topology
if [ -f "$topology".source ] ; then
actual_source="$HWLOC_top_srcdir"/tests/hwloc/linux/`cat "$topology".source`
else
actual_source="$topology".tar.bz2
fi
# if there's a .env file, source it
if [ -f "$topology".env ] ; then
. "$topology".env
fi
# use an absolute path for tar options because tar is invoked from the temp directory
actual_exclude="$HWLOC_top_srcdir/tests/hwloc/linux/`basename $topology`".exclude
[ -f "$actual_exclude" ] && tar_options="--exclude-from=$actual_exclude"
result=1
dir="`mktemp -d`"
if ! ( bunzip2 -c "$actual_source" | ( cd "$dir" && tar xf - $tar_options ) )
then
error "failed to extract topology \`$topology'"
else
actual_dir="`echo "$dir"/*`"
if test_eligible "$actual_dir" "$actual_output"
then
test_count="`expr $test_count + 1`"
test_topology "`basename $topology`" "$actual_dir" "$actual_output" "$actual_options"
result=$?
else
# Skip this test.
result=77
fi
fi
rm -rf "$dir"
exit $result