Skip to content

Commit fb2a495

Browse files
authored
Merge pull request #674 from bgoglin/completion
Completion fixes and tests
2 parents 5f0269a + e4942bf commit fb2a495

File tree

4 files changed

+189
-6
lines changed

4 files changed

+189
-6
lines changed

config/hwloc_internal.m4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dnl -*- Autoconf -*-
22
dnl
3-
dnl Copyright © 2010-2023 Inria. All rights reserved.
3+
dnl Copyright © 2010-2024 Inria. All rights reserved.
44
dnl Copyright © 2009, 2011 Université Bordeaux
55
dnl Copyright © 2004-2005 The Trustees of Indiana University and Indiana
66
dnl University Research and Technology
@@ -514,6 +514,7 @@ int foo(void) {
514514
hwloc_config_prefix[contrib/hwloc-ps.www/Makefile]
515515
hwloc_config_prefix[contrib/systemd/Makefile]
516516
hwloc_config_prefix[contrib/completion/Makefile]
517+
hwloc_config_prefix[contrib/completion/test-bash-completion.sh]
517518
hwloc_config_prefix[contrib/misc/Makefile]
518519
hwloc_config_prefix[contrib/windows/Makefile]
519520
)
@@ -539,7 +540,8 @@ int foo(void) {
539540
hwloc_config_prefix[utils/hwloc/test-parsing-flags.sh] \
540541
hwloc_config_prefix[utils/hwloc/test-hwloc-dump-hwdata/test-hwloc-dump-hwdata.sh] \
541542
hwloc_config_prefix[utils/lstopo/test-lstopo.sh] \
542-
hwloc_config_prefix[utils/lstopo/test-lstopo-shmem.sh])
543+
hwloc_config_prefix[utils/lstopo/test-lstopo-shmem.sh] \
544+
hwloc_config_prefix[contrib/completion/test-bash-completion.sh])
543545
544546
# These links are only needed in standalone mode. It would
545547
# be nice to m4 foreach this somehow, but whenever I tried

contrib/completion/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Copyright © 2009-2020 Inria. All rights reserved.
1+
# Copyright © 2009-2024 Inria. All rights reserved.
22
#
33
# See COPYING in top-level directory.
44

55
# This makefile is only reached when building in standalone mode
66

77
bashcompletionsdir = $(datadir)/bash-completion/completions
88
dist_bashcompletions_DATA = bash/hwloc
9+
10+
if HWLOC_HAVE_LINUX
11+
TESTS = test-bash-completion.sh
12+
endif

contrib/completion/bash/hwloc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ _lstopo() {
8686
)
8787
local cur=${COMP_WORDS[COMP_CWORD]}
8888
local prev=${COMP_WORDS[COMP_CWORD-1]}
89+
COMPREPLY=()
8990

9091
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
9192
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -136,7 +137,7 @@ _lstopo() {
136137
COMPREPLY=( "<line of text>" "" )
137138
;;
138139
--palette)
139-
COMPREPLY=( `compgen -W "grey" "greyscale" "default" "colors" "white" "none" -- "$cur"` )
140+
COMPREPLY=( `compgen -W "grey greyscale default colors white none" -- "$cur"` )
140141
;;
141142
--binding-color | --disallowed-color | --top-color)
142143
COMPREPLY=( `compgen -W "none <#rrggbb>" -- "$cur"` )
@@ -159,6 +160,7 @@ complete -F _lstopo hwloc-ls
159160

160161

161162
_hwloc_info(){
163+
local INPUT_FORMAT=(xml synthetic fsroot cpuid)
162164
local TYPES=("Machine" "Misc" "Group" "NUMANode" "MemCache" "Package" "Die" "L1" "L2" "L3" "L4" "L5" "L1i" "L2i" "L3i" "Core" "Bridge" "PCIDev" "OSDev" "PU")
163165
local FILTERKINDS=("none" "all" "structure" "important")
164166
local OPTIONS=(--objects
@@ -195,6 +197,7 @@ _hwloc_info(){
195197
)
196198
local cur=${COMP_WORDS[COMP_CWORD]}
197199
local prev=${COMP_WORDS[COMP_CWORD-1]}
200+
COMPREPLY=()
198201

199202
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
200203
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -223,7 +226,8 @@ _hwloc_info(){
223226
COMPREPLY=( `compgen -W "${TYPES[*]/%/:} cache: icache: io:" -- "$cur"` ) && compopt -o nospace
224227
;;
225228
--ancestor | --descendants)
226-
COMPREPLY=( `compgen -W "${TYPES[*]}" -- "$cur"` kind=normal kind=cpu kind=cache kind=memory kind=io kind=all )
229+
COMPREPLY=( `compgen -W "${TYPES[*]} kind=normal kind=cpu kind=cache kind=memory kind=io kind=all" -- "$cur"` )
230+
# TODO "kind=<tab>" doesn't complete with kinds
227231
;;
228232
--local-memory-flags)
229233
COMPREPLY=( "<flags>" "" )
@@ -269,6 +273,7 @@ _hwloc_bind(){
269273
)
270274
local cur=${COMP_WORDS[COMP_CWORD]}
271275
local prev=${COMP_WORDS[COMP_CWORD-1]}
276+
COMPREPLY=()
272277

273278
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
274279
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -302,6 +307,7 @@ complete -F _hwloc_bind hwloc-bind
302307

303308

304309
_hwloc_calc(){
310+
local INPUT_FORMAT=(xml synthetic fsroot cpuid)
305311
local TYPES=("Machine" "Misc" "Group" "NUMANode" "MemCache" "Package" "Die" "L1" "L2" "L3" "L4" "L5" "L1i" "L2i" "L3i" "Core" "Bridge" "PCIDev" "OSDev" "PU")
306312
local OPTIONS=(-N --number-of
307313
-I --intersect
@@ -337,6 +343,7 @@ _hwloc_calc(){
337343
)
338344
local cur=${COMP_WORDS[COMP_CWORD]}
339345
local prev=${COMP_WORDS[COMP_CWORD-1]}
346+
COMPREPLY=()
340347

341348
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
342349
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -384,6 +391,7 @@ complete -F _hwloc_calc hwloc-calc
384391
_hwloc_annotate(){
385392
local OPTIONS=(--ci --ri --cu --cd --version -h --help)
386393
local cur=${COMP_WORDS[COMP_CWORD]}
394+
COMPREPLY=()
387395

388396
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
389397
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"`)
@@ -400,6 +408,7 @@ _hwloc_diff(){
400408
)
401409
local cur=${COMP_WORDS[COMP_CWORD]}
402410
local prev=${COMP_WORDS[COMP_CWORD-1]}
411+
COMPREPLY=()
403412

404413
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
405414
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -417,11 +426,12 @@ complete -F _hwloc_diff hwloc-diff
417426

418427

419428
_hwloc_patch(){
420-
local OPTIONS=(--R --reverse
429+
local OPTIONS=(-R --reverse
421430
--version
422431
-h --help
423432
)
424433
local cur=${COMP_WORDS[COMP_CWORD]}
434+
COMPREPLY=()
425435

426436
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
427437
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -438,6 +448,7 @@ _hwloc_compress_dir(){
438448
-h --help
439449
)
440450
local cur=${COMP_WORDS[COMP_CWORD]}
451+
COMPREPLY=()
441452

442453
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
443454
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -448,6 +459,7 @@ complete -F _hwloc_compress_dir hwloc-compress-dir
448459

449460

450461
_hwloc_distrib(){
462+
local INPUT_FORMAT=(xml synthetic fsroot cpuid)
451463
local TYPES=("Machine" "Misc" "Group" "NUMANode" "MemCache" "Package" "Die" "L1" "L2" "L3" "L4" "L5" "L1i" "L2i" "L3i" "Core" "Bridge" "PCIDev" "OSDev" "PU")
452464
local OPTIONS=(--ignore
453465
--from
@@ -467,6 +479,7 @@ _hwloc_distrib(){
467479
)
468480
local cur=${COMP_WORDS[COMP_CWORD]}
469481
local prev=${COMP_WORDS[COMP_CWORD-1]}
482+
COMPREPLY=()
470483

471484
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
472485
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -520,6 +533,7 @@ _hwloc_ps(){
520533
)
521534
local cur=${COMP_WORDS[COMP_CWORD]}
522535
local prev=${COMP_WORDS[COMP_CWORD-1]}
536+
COMPREPLY=()
523537

524538
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
525539
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -554,6 +568,7 @@ _hwloc_gather_cpuid(){
554568
)
555569
local cur=${COMP_WORDS[COMP_CWORD]}
556570
local prev=${COMP_WORDS[COMP_CWORD-1]}
571+
COMPREPLY=()
557572

558573
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
559574
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
@@ -578,6 +593,7 @@ _hwloc_gather_topology(){
578593
-h --help
579594
)
580595
local cur=${COMP_WORDS[COMP_CWORD]}
596+
COMPREPLY=()
581597

582598
if [[ $COMP_CWORD == 1 || $cur == -* ]] ; then
583599
COMPREPLY=( `compgen -W "${OPTIONS[*]}" -- "$cur"` )
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!@BASH@
2+
3+
#
4+
# Copyright © 2024 Inria. All rights reserved.
5+
# See COPYING in top-level directory.
6+
#
7+
8+
set -e
9+
10+
# the real _filedir() defined in /usr/share/bash-completion/bash_completion seems to fail here,
11+
# and we won't actually test it anyway, so just redefine it to empty
12+
_filedir() {
13+
return
14+
}
15+
16+
# the real compopt doesn't work outside of actual completion
17+
compopt() {
18+
return
19+
}
20+
21+
# load completions
22+
HWLOC_top_srcdir="@HWLOC_top_srcdir@"
23+
source $HWLOC_top_srcdir/contrib/completion/bash/hwloc
24+
25+
COMP_WORDS=( "lstopo" "--o" )
26+
COMP_CWORD=${#COMP_WORDS[*]}-1
27+
echo "Completing ${COMP_WORDS[*]}<tab>"
28+
_lstopo
29+
echo "Got ${COMPREPLY[*]}"
30+
test "${COMPREPLY[*]}" == "--os-index-prefix --output-format --of --osf --obj-snprintf-flags --only"
31+
echo "OK"
32+
33+
COMP_WORDS=( "lstopo" "--palette" "" )
34+
COMP_CWORD=${#COMP_WORDS[*]}-1
35+
echo "Completing ${COMP_WORDS[*]}<tab>"
36+
_lstopo
37+
echo "Got ${COMPREPLY[*]}"
38+
test "${COMPREPLY[*]}" == "grey greyscale default colors white none"
39+
echo "OK"
40+
41+
COMP_WORDS=( "lstopo" "--filter" "i" )
42+
COMP_CWORD=${#COMP_WORDS[*]}-1
43+
echo "Completing ${COMP_WORDS[*]}<tab>"
44+
_lstopo
45+
echo "Got ${COMPREPLY[*]}"
46+
test "${COMPREPLY[*]}" == "icache: io:"
47+
echo "OK"
48+
49+
# "--filter type:kind" must be split into "--filter" "type" ":" "kind" outside of actual completion
50+
COMP_WORDS=( "lstopo" "--filter" "io" ":" "" )
51+
COMP_CWORD=${#COMP_WORDS[*]}-1
52+
echo "Completing ${COMP_WORDS[*]}<tab>"
53+
_lstopo
54+
echo "Got ${COMPREPLY[*]}"
55+
test "${COMPREPLY[*]}" == "none all structure important"
56+
echo "OK"
57+
58+
# "--foo=bar" must be split into "--foo" "=" "bar" outside of actual completion
59+
COMP_WORDS=( "lstopo" "--horiz" "=" "M" )
60+
COMP_CWORD=${#COMP_WORDS[*]}-1
61+
echo "Completing ${COMP_WORDS[*]}<tab>"
62+
_lstopo
63+
echo "Got ${COMPREPLY[*]}"
64+
test "${COMPREPLY[*]}" == "Machine Misc MemCache"
65+
echo "OK"
66+
67+
COMP_WORDS=( "hwloc-info" "--ancestor" )
68+
COMP_CWORD=${#COMP_WORDS[*]}-1
69+
echo "Completing ${COMP_WORDS[*]}<tab>"
70+
_hwloc_info
71+
echo "Got ${COMPREPLY[*]}"
72+
test "${COMPREPLY[*]}" == "--ancestors --ancestor"
73+
echo "OK"
74+
75+
COMP_WORDS=( "hwloc-info" "--ancestor" "P" )
76+
COMP_CWORD=${#COMP_WORDS[*]}-1
77+
echo "Completing ${COMP_WORDS[*]}<tab>"
78+
_hwloc_info
79+
echo "Got ${COMPREPLY[*]}"
80+
test "${COMPREPLY[*]}" == "Package PCIDev PU"
81+
echo "OK"
82+
83+
COMP_WORDS=( "hwloc-bind" "--membind" "--get" "--cof" "" )
84+
COMP_CWORD=${#COMP_WORDS[*]}-1
85+
echo "Completing ${COMP_WORDS[*]}<tab>"
86+
_hwloc_bind
87+
echo "Got ${COMPREPLY[*]}"
88+
test "${COMPREPLY[*]}" == "hwloc list taskset"
89+
echo "OK"
90+
91+
COMP_WORDS=( "hwloc-calc" "--cpukind" "" )
92+
COMP_CWORD=${#COMP_WORDS[*]}-1
93+
echo "Completing ${COMP_WORDS[*]}<tab>"
94+
_hwloc_calc
95+
echo "Got ${COMPREPLY[*]}"
96+
test "${COMPREPLY[*]}" == "<name>=<value> <n> "
97+
echo "OK"
98+
99+
COMP_WORDS=( "hwloc-annotate" "-" )
100+
COMP_CWORD=${#COMP_WORDS[*]}-1
101+
echo "Completing ${COMP_WORDS[*]}<tab>"
102+
_hwloc_annotate
103+
echo "Got ${COMPREPLY[*]}"
104+
test "${COMPREPLY[*]}" = "--ci --ri --cu --cd --version -h --help"
105+
echo "OK"
106+
107+
COMP_WORDS=( "hwloc-diff" "--re" )
108+
COMP_CWORD=${#COMP_WORDS[*]}-1
109+
echo "Completing ${COMP_WORDS[*]}<tab>"
110+
_hwloc_diff
111+
echo "Got ${COMPREPLY[*]}"
112+
test "${COMPREPLY[*]}" = "--refname"
113+
echo "OK"
114+
115+
COMP_WORDS=( "hwloc-patch" "--" )
116+
COMP_CWORD=${#COMP_WORDS[*]}-1
117+
echo "Completing ${COMP_WORDS[*]}<tab>"
118+
_hwloc_patch
119+
echo "Got ${COMPREPLY[*]}"
120+
test "${COMPREPLY[*]}" = "--reverse --version --help"
121+
echo "OK"
122+
123+
COMP_WORDS=( "hwloc-compress-dir" "--v" )
124+
COMP_CWORD=${#COMP_WORDS[*]}-1
125+
echo "Completing ${COMP_WORDS[*]}<tab>"
126+
_hwloc_compress_dir
127+
echo "Got ${COMPREPLY[*]}"
128+
test "${COMPREPLY[*]}" = "--verbose --version"
129+
echo "OK"
130+
131+
COMP_WORDS=( "hwloc-distrib" "--if" "" )
132+
COMP_CWORD=${#COMP_WORDS[*]}-1
133+
echo "Completing ${COMP_WORDS[*]}<tab>"
134+
_hwloc_distrib
135+
echo "Got ${COMPREPLY[*]}"
136+
test "${COMPREPLY[*]}" = "xml synthetic fsroot cpuid"
137+
echo "OK"
138+
139+
COMP_WORDS=( "hwloc-ps" "--children-of-pid" "" )
140+
COMP_CWORD=${#COMP_WORDS[*]}-1
141+
echo "Completing ${COMP_WORDS[*]}<tab>"
142+
_hwloc_ps
143+
echo "Got ${COMPREPLY[*]}"
144+
test "${COMPREPLY[*]}" = "<pid> "
145+
echo "OK"
146+
147+
COMP_WORDS=( "hwloc-gather-cpuid" "-c" "" )
148+
COMP_CWORD=${#COMP_WORDS[*]}-1
149+
echo "Completing ${COMP_WORDS[*]}<tab>"
150+
_hwloc_gather_cpuid
151+
echo "Got ${COMPREPLY[*]}"
152+
test "${COMPREPLY[*]}" = "<index of cpu to operate on> "
153+
echo "OK"
154+
155+
COMP_WORDS=( "hwloc-gather-topology" "-" )
156+
COMP_CWORD=${#COMP_WORDS[*]}-1
157+
echo "Completing ${COMP_WORDS[*]}<tab>"
158+
_hwloc_gather_topology
159+
echo "Got ${COMPREPLY[*]}"
160+
test "${COMPREPLY[*]}" = "--io --dmi --dt --no-cpuid --keep --version -h --help"
161+
echo "OK"

0 commit comments

Comments
 (0)