1 AT_BANNER([command completion unit tests - bash])
3 m4_define([GET_FORMAT], [
4 echo "$@" | grep -A 1 -- "Command format" | tail -n+2
7 m4_define([GET_EXPAN], [
8 echo "$@" | grep -- "available completions for keyword" \
9 | sed -e 's/^[ ]*//g;s/[ ]*$//g'
12 m4_define([GET_AVAIL], [
13 echo "$@" | sed -e '1,/Available/d' | tail -n+2
16 m4_define([GET_COMP_STR], [
17 echo "available completions for keyword \"$1\": $2" \
21 AT_SETUP([bash completion - basic verification])
22 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
25 # complete ovs-appctl [TAB]
26 # complete ovs-dpctl [TAB]
27 # complete ovs-ofctl [TAB]
28 # complete ovsdb-tool [TAB]
36 INPUT="$(bash ovs-command-compgen.bash debug test_command TAB 2>&1)"
37 MATCH="$(test_command --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
38 $(test_command list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
39 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
45 # complete ovs-appctl --tar[TAB]
46 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --tar 2>&1)"
47 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
53 # complete ovs-appctl --target [TAB]
54 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target TAB 2>&1)"
55 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
63 # complete ovs-appctl --target ovs-vswitchd [TAB]
64 # complete ovs-appctl --target ovsdb-server [TAB]
65 # complete ovs-appctl --target ovs-ofctl [TAB]
66 AT_CHECK([ovs-ofctl monitor br0 --detach --no-chdir --pidfile])
73 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
74 MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
75 $(ovs-appctl --target target_daemon list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
76 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
80 AT_CHECK([ovs-appctl --target ovs-ofctl exit])
83 # check all ovs-appctl subcommand formats
84 LIST=$(ovs-appctl list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)
85 for subcommand in $LIST; do
86 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl $subcommand TAB 2>&1)"
87 MATCH=$(ovs-appctl list-commands | tail -n+2 | cut -c3- | grep -- "^$subcommand " | tr -s ' ')
88 AT_CHECK_UNQUOTED([GET_FORMAT(${INPUT})],
98 # complex completion check - bfd/set-forwarding
99 # bfd/set-forwarding [interface] normal|false|true
100 # test expansion of 'interface'
101 AT_SETUP([bash completion - complex completion check 1])
102 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
103 OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)
105 # check the top level completion.
106 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
107 MATCH="$(GET_COMP_STR([normal], [])
108 GET_COMP_STR([false], [])
109 GET_COMP_STR([true], [])
110 GET_COMP_STR([interface], [p0]))"
111 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
115 # check the available completions.
116 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
122 # set argument to 'true', there should be no more completions.
123 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)"
124 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
127 bfd/set-forwarding [[interface]] normal|false|true
131 # set argument to 'p1', there should still be the completion for booleans.
132 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)"
133 MATCH="$(GET_COMP_STR([normal], [])
134 GET_COMP_STR([false], [])
135 GET_COMP_STR([true], []))"
136 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
140 # check the available completions.
141 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
144 # set argument to 'p1 false', there should still no more completions.
145 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)"
146 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
149 bfd/set-forwarding [[interface]] normal|false|true
156 # complex completion check - lacp/show
158 # test expansion on 'port'
159 AT_SETUP([bash completion - complex completion check 2])
160 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
161 OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
162 -- add-port br0 p1 -- set Interface p1 type=dummy)
164 # check the top level completion.
165 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
166 MATCH="$(GET_COMP_STR([port], [br0 p0 p1]))"
167 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
171 # check the available completions.
172 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
180 # set argument to 'p1', there should be no more completions.
181 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show p1 TAB 2>&1)"
182 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
192 # complex completion check - ofproto/trace
193 # ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]
194 # test expansion on 'dp|dp_name' and 'bridge'
195 AT_SETUP([bash completion - complex completion check 3])
196 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
197 OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
198 -- add-port br0 p1 -- set Interface p1 type=dummy)
200 # check the top level completion.
201 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace TAB 2>&1)"
202 MATCH="$(GET_COMP_STR([bridge], [br0])
203 GET_COMP_STR([odp_flow], [])
204 GET_COMP_STR([dp_name], [ovs-dummy]))"
205 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
209 # check the available completions.
210 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
217 # set argument to 'ovs-dummy', should go to the dp-name path.
218 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy TAB 2>&1)"
219 MATCH="$(GET_COMP_STR([odp_flow], []))"
220 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
224 # check the available completions.
225 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
228 # set odp_flow to some random string, should go to the next level.
229 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" TAB 2>&1)"
230 MATCH="$(GET_COMP_STR([-generate], [-generate])
231 GET_COMP_STR([packet], []))"
232 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
236 # check the available completions.
237 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
243 # set packet to some random string, there should be no more completions.
244 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)"
245 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
248 ofproto/trace {[[dp_name]] odp_flow | bridge br_flow} [[-generate|packet]]
252 # set argument to 'br0', should go to the bridge path.
253 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)"
254 MATCH="$(GET_COMP_STR([br_flow], []))"
255 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
259 # check the available completions.
260 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
263 # set argument to some random string, should go to the odp_flow path.
264 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)"
265 MATCH="$(GET_COMP_STR([-generate], [-generate])
266 GET_COMP_STR([packet], []))"
267 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
271 # check the available completions.
272 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
281 # complex completion check - vlog/set
282 # vlog/set {spec | PATTERN:destination:pattern}
283 # test non expandable arguments
284 AT_SETUP([bash completion - complex completion check 4])
285 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
288 # check the top level completion.
289 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
290 MATCH="$(GET_COMP_STR([PATTERN:destination:pattern], [])
291 GET_COMP_STR([spec], []))"
292 AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
296 # check the available completions.
297 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
300 # set argument to random 'abcd', there should be no more completions.
301 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
302 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
305 vlog/set {spec | PATTERN:destination:pattern}
312 AT_SETUP([bash completion - negative test])
313 AT_SKIP_IF([test -z ${BASH_VERSION+x}])
314 OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)
316 # negative test - incorrect subcommand
317 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR 2>&1)"
318 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d'], [0])
319 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR TAB 2>&1)"
320 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
326 # negative test - no ovs-vswitchd
327 # negative test - no ovsdb-server
328 # negative test - no ovs-ofctl
329 # should not see any error.
337 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
338 MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)"
339 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
343 INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon ERROR SUBCMD TAB 2>&1)"
344 AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
350 # negative test - do not match on nested option
351 INPUT="$(bash ovs-command-compgen.bash debug ovsdb-tool create TAB 2>&1)"
352 AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])