1#!/bin/sh
2#-*-sh-*-
3
4#
5# Copyright © 2009 CNRS
6# Copyright © 2009-2020 Inria.  All rights reserved.
7# Copyright © 2009, 2011 Université Bordeaux
8# Copyright © 2014 Cisco Systems, Inc.  All rights reserved.
9# See COPYING in top-level directory.
10#
11
12HWLOC_top_srcdir="@HWLOC_top_srcdir@"
13HWLOC_top_builddir="@HWLOC_top_builddir@"
14srcdir="$HWLOC_top_srcdir/utils/hwloc"
15builddir="$HWLOC_top_builddir/utils/hwloc"
16calc="$builddir/hwloc-calc"
17xmldir="$HWLOC_top_srcdir/tests/hwloc/xml"
18linuxdir="$HWLOC_top_srcdir/tests/hwloc/linux"
19
20HWLOC_PLUGINS_PATH=${HWLOC_top_builddir}/hwloc/.libs
21export HWLOC_PLUGINS_PATH
22
23HWLOC_DEBUG_CHECK=1
24export HWLOC_DEBUG_CHECK
25
26: ${TMPDIR=/tmp}
27{
28  tmp=`
29    (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
30  ` &&
31  test -n "$tmp" && test -d "$tmp"
32} || {
33  tmp=$TMPDIR/foo$$-$RANDOM
34  (umask 077 && mkdir "$tmp")
35} || exit $?
36file="$tmp/test-hwloc-calc.output"
37
38set -e
39(
40  echo "# root"
41  $calc --if synthetic --input "node:4 core:4 pu:4" root
42  echo
43  echo "# all --taskset"
44  $calc --if synthetic --input "node:4 core:4 pu:4" all --taskset
45  echo
46
47  echo "# hex"
48  $calc --if synthetic --input "node:4 core:4 pu:4" 0xf
49  echo
50  echo "# hex combination"
51  $calc --if synthetic --input "node:4 core:4 pu:4" 0xf ~0x3 0xff0 '^0xf0'
52  echo
53  echo "# object combination"
54  $calc --if synthetic --input "node:4 core:4 pu:4" core:0 pu:15 ~pu:0 '^pu:2'
55  echo
56
57  echo "# --no-smt NUMA Node range"
58  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt node:2-3
59  echo
60  echo "# --no-smt hex"
61  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt 0x1fe
62  echo
63  echo "# --no-smt=1 hex"
64  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt=1 0x1fe
65  echo
66  echo "# --no-smt=2 hex"
67  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt=2 0x1fe
68  echo
69  echo "# --no-smt=3 hex"
70  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt=3 0x1fe
71  echo
72  echo "# --no-smt=4 hex"
73  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt=4 0x1fe
74  echo
75  echo "# --no-smt=-1 hex"
76  $calc --if synthetic --input "node:4 core:4 pu:4" --no-smt=-1 0x1fe
77  echo
78
79  echo "# even PUs"
80  $calc --if synthetic --input "node:4 core:4 pu:4" pu:even
81  echo
82  echo "# NUMA Nodes 2+"
83  $calc --if synthetic --input "node:4 core:4 pu:4" node:2-
84  echo
85  echo "# cores 12+"
86  $calc --if synthetic --input "node:4 core:4 pu:4" core:12-
87  echo
88  echo "# PU wrapping range"
89  $calc --if synthetic --input "node:4 core:4 pu:4" pu:62:10
90  echo
91  echo "# some PUs in all Cores"
92  $calc --if synthetic --input "node:4 core:4 pu:4" core:all.pu:1:2
93  echo
94  echo "# one PU in odd Cores"
95  $calc --if synthetic --input "node:4 core:4 pu:4" core:odd.pu:0
96  echo
97  echo "# combination of different ranges, hierarchical or not"
98  $calc --if synthetic --input "node:4 core:4 pu:4" pu:6:2 core:3-4.pu:1-3 node:2.pu:14:2 node:3.core:3.pu:3
99  echo
100
101  echo "# Number of NUMA Nodes"
102  $calc --if synthetic --input "node:4 core:4 pu:4" root --number-of node
103  echo
104  echo "# Number of Cores in a NUMA Node"
105  $calc --if synthetic --input "node:4 core:4 pu:4" node:2 -N core
106  echo
107  echo "# Number of objects at depth 3 in a NUMA Node"
108  $calc --if synthetic --input "node:4 core:4 pu:4" node:2 -N 3
109  echo
110
111  echo "# List of Machine objects"
112  $calc --if synthetic --input "node:4 core:4 pu:4" root --intersect Machine
113  echo
114  echo "# List of NUMA Nodes in a range of Cores"
115  $calc --if synthetic --input "node:4 core:4 pu:4" core:4-7 -I NUMANode
116  echo
117  echo "# List of NUMA Nodes in a range of Cores (again)"
118  $calc --if synthetic --input "node:4 core:4 pu:4" core:10-15 -I NUMANode
119  echo
120
121  echo "# Hierarchical spec for a range of PUs"
122  $calc --if synthetic --input "node:4 core:4 pu:4" pu:2-3 --hierarchical group.pu
123  echo
124  echo "# Hierarchical spec for a range of PUs, with different separator"
125  $calc --if synthetic --input "node:4 core:4 pu:4" pu:3-6 -H group.core --sep foo
126  echo
127  echo "# Hierarchical spec for a range of PUs (again)"
128  $calc --if synthetic --input "node:4 core:4 pu:4" pu:3-6 -H core.pu
129  echo
130  echo "# List of PUs from another invocation with hierarchical output"
131  $calc --if synthetic --input "node:4 core:4 pu:4" -I pu `$calc --if synthetic --input "node:4 core:4 pu:4" pu:3-6 -H core.pu`
132  echo
133  echo "# Hierarchical spec for a range of PUs (3 levels)"
134  $calc --if synthetic --input "node:4 core:4 pu:4" pu:11:4 -H group.core.pu
135  echo
136  echo "# List of PUs from another invocation with hierarchical output (again)"
137  $calc --if synthetic --input "node:4 core:4 pu:4" -I pu `$calc --if synthetic --input "node:4 core:4 pu:4" pu:11:4 -H group.core.pu`
138  echo
139
140  echo "# --largest"
141  $calc --if synthetic --input "node:4 core:4 pu:4" pu:12-37 --largest
142  echo
143  echo "# --largest, with different separator"
144  $calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --largest --sep "_"
145  echo
146
147  echo "# Singlified output"
148  $calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --single
149  echo
150  echo "# Singlified PU list"
151  $calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --single --pulist
152  echo
153
154  echo "# PU list with physical output"
155  $calc --if synthetic --input "node:4 core:4 pu:4" pu:33-37 --pulist --po
156  echo
157  echo "# NUMA Node list of physical output and different separator"
158  $calc --if synthetic --input "node:4 core:4 pu:4" pu:30-37 --nodelist --po --sep foo
159  echo
160
161  echo "# Manipulating NUMA Nodes with nodesets"
162  $calc --if synthetic --input "node:4 core:4 pu:4" -n node:1-2
163  echo
164  echo "# Nodeset output of PUs"
165  $calc --if synthetic --input "node:4 core:4 pu:4" --no pu:63
166  echo
167  echo "# Converting NUMA Nodes from logical to physical"
168  $calc --if synthetic --input "node:4 core:4 pu:4" --ni 0x5 --nodelist --po
169  echo
170
171  echo "# Physical output of NUMA Nodes when out-of-order in the topology"
172  $calc --if synthetic --input "node:4(indexes=3,2,1,0) pu:2" node:1-2 --po -I node
173  echo
174  echo "# Converting physical to logical PU indexes when complexly ordered in the topology"
175  $calc --if synthetic --input "node:4 core:4 pu:4(indexes=node:core)" --pi pu:2-5 -I pu
176  echo
177
178  echo "# 4 local nodes near a Package (node:3-4@Die + node:5@Package + node:6@Machine)"
179  $calc --if synthetic --input "[numa] pack:2 [numa] die:2 [numa] pu:2" --local-memory package:1
180  echo
181  echo "# 2 local nodes larger or equal to a Package (node:2@Package + node:6@Machine), with space separator"
182  $calc --if synthetic --input "[numa] pack:2 [numa] die:2 [numa] pu:2" --local-memory-flags 1 --sep " " pack:0
183  echo
184  echo "# Best-locality local node near a PU (node:1@Die)"
185  $calc --if synthetic --input "[numa] pack:2 [numa] die:2 [numa] pu:2" --best-memattr locality pu:3
186  echo
187  echo "# Best-capacity local node near a PU (node:6@Machine)"
188  $calc --if synthetic --input "[numa(memory=1000000)] pack:2 [numa(memory=100000)] die:2 [numa(memory=1000)] pu:2" --best-memattr capacity pu:4
189  echo
190
191  echo "# CPU kind by index"
192  $calc --if xml --input $linuxdir/fakeheterocpunuma.output --cpukind 1 all
193  echo
194  echo "# CPU kind by wrong index"
195  $calc --if xml --input $linuxdir/fakeheterocpunuma.output --cpukind 3 all
196  echo
197  echo "# CPU kind by info attr"
198  $calc --if xml --input $linuxdir/fakeheterocpunuma.output --cpukind FrequencyMaxMHz=3000 all
199  echo
200
201  echo "# Caches with attributes"
202  $calc --if synthetic --input "numa:2 l3:2 pu:1" numa:0 l3u:3
203  echo
204  echo "# Groups with attributes"
205  $calc --if synthetic --input "group:2 numa:2 l2:2 l1d:2 pu:1" Group0:1 NUMA:0
206  echo
207  echo "# Caches without attributes"
208  $calc --if synthetic --input "group:2 numa:2 l2:2 l1d:2 pu:1" l2:0-2 L1cache:13:3
209  echo
210
211  echo "# OS devices by name"
212  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml os=eth6 os=eth4
213  echo
214  echo "# OS devices by name (again)"
215  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml os=sdc os=sr0 ~os=sda
216  echo
217  echo "# OS devices by range"
218  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml os:7-8
219  echo
220  echo "# PCI devices by range"
221  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci:10-11
222  echo
223  echo "# PCI devices by vendors/device IDs and range wrapping around"
224  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci'[1000:0062]':3:2
225  echo
226  echo "# PCI devices by vendors/device IDs and index"
227  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci'[14e4:1639]':1
228  echo
229  echo "# PCI devices by vendors/device IDs and range"
230  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci'[14e4:1639]':2-5
231  echo
232  echo "# PCI devices added"
233  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci=0000:62:00.1 pci=0000:02:00.1
234  echo
235  echo "# PCI devices intersection"
236  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci=0000:62:00.1 xpci=0000:02:00.0
237  echo
238  echo "# PCI devices intersection (again)"
239  $calc --if xml --input $xmldir/96em64t-4n4d3ca2co-pci.xml pci=0000:02:00.0 xpci=0000:02:00.1
240  echo
241  echo "# Restrict"
242  $calc -i "node:4 pu:4" --restrict 0xf0 --restrict-flags cpuless all -N pu
243  $calc -i "node:4 pu:4" --restrict 0xf0 --restrict-flags cpuless all -N numa
244  $calc -i "node:4 pu:4" --restrict-flags bynode,memless --restrict 0x3 all -N pu
245  $calc -i "node:4 pu:4" --restrict 0xff0 --restrict-flags none all -N pu
246  $calc -i "node:4 pu:4" --restrict-flags cpuless --restrict 0xff0 all -I numa --po
247  echo
248
249  echo "# Reading from stdin"
250  cat << EOF | $calc --if synthetic --input "node:4 core:4 pu:4"
251pu:0
252core:0 core:15
253node:0 node:3
2540x0001 0x00002 0x000004 0x000000000008
2550x0000000000000000000000000000000000000000000000000000000000000000000000000000001
2560x1,0x0,0x0
257root
258EOF
259  echo
260) > "$file"
261@DIFF@ @HWLOC_DIFF_U@ @HWLOC_DIFF_W@ $srcdir/test-hwloc-calc.output "$file"
262rm -rf "$tmp"
263