]> git.proxmox.com Git - mirror_ovs.git/blame - tests/completion.at
test: Reverse the order of commands added by ON_EXIT macro
[mirror_ovs.git] / tests / completion.at
CommitLineData
08d42548
AW
1AT_BANNER([command completion unit tests - bash])
2
3m4_define([GET_FORMAT], [
4echo "$@" | grep -A 1 -- "Command format" | tail -n+2
5])
6
7m4_define([GET_EXPAN], [
8echo "$@" | grep -- "available completions for keyword" \
9 | sed -e 's/^[ ]*//g;s/[ ]*$//g'
10])
11
12m4_define([GET_AVAIL], [
13echo "$@" | sed -e '1,/Available/d' | tail -n+2
14])
15
16m4_define([GET_COMP_STR], [
17echo "available completions for keyword \"$1\": $2" \
18 | sed -e 's/[ ]*$//g'
19])
20
21AT_SETUP([bash completion - basic verification])
22AT_SKIP_IF([test -z ${BASH_VERSION+x}])
23OVS_VSWITCHD_START
24
25# complete ovs-appctl [TAB]
26# complete ovs-dpctl [TAB]
27# complete ovs-ofctl [TAB]
28# complete ovsdb-tool [TAB]
29m4_foreach(
30[test_command],
31[[ovs-appctl],
32[ovs-dpctl],
33[ovs-ofctl],
34[ovsdb-tool]],
35[
36INPUT="$(bash ovs-command-compgen.bash debug test_command TAB 2>&1)"
37MATCH="$(test_command --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
38$(test_command list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
39AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
40[0], [dnl
41${MATCH}
42])])
43
44
45# complete ovs-appctl --tar[TAB]
46INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --tar 2>&1)"
47AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
48[0], [dnl
49--target
50])
51
52
53# complete ovs-appctl --target [TAB]
54INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target TAB 2>&1)"
55AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
56[0], [dnl
57ovs-ofctl
58ovs-vswitchd
59ovsdb-server
60])
61
62
63# complete ovs-appctl --target ovs-vswitchd [TAB]
64# complete ovs-appctl --target ovsdb-server [TAB]
65# complete ovs-appctl --target ovs-ofctl [TAB]
66AT_CHECK([ovs-ofctl monitor br0 --detach --no-chdir --pidfile])
67m4_foreach(
68[target_daemon],
69[[ovs-vswitchd],
70[ovsdb-server],
71[ovs-ofctl]],
72[
73INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
74MATCH="$(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)"
76AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
77[0], [dnl
78${MATCH}
79])])
80AT_CHECK([ovs-appctl --target ovs-ofctl exit])
08d42548
AW
81OVS_VSWITCHD_STOP
82AT_CLEANUP
83
84
85# complex completion check - bfd/set-forwarding
86# bfd/set-forwarding [interface] normal|false|true
87# test expansion of 'interface'
88AT_SETUP([bash completion - complex completion check 1])
89AT_SKIP_IF([test -z ${BASH_VERSION+x}])
90OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)
91
92# check the top level completion.
93INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
94MATCH="$(GET_COMP_STR([normal], [])
95GET_COMP_STR([false], [])
96GET_COMP_STR([true], [])
97GET_COMP_STR([interface], [p0]))"
98AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
99[0], [dnl
100${MATCH}
101])
102# check the available completions.
103AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
104[0], [dnl
105p0
106])
107
108
109# set argument to 'true', there should be no more completions.
110INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)"
111AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
112[0], [dnl
08d42548
AW
113])
114
115
116# set argument to 'p1', there should still be the completion for booleans.
117INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)"
118MATCH="$(GET_COMP_STR([normal], [])
119GET_COMP_STR([false], [])
120GET_COMP_STR([true], []))"
121AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
122[0], [dnl
123${MATCH}
124])
125# check the available completions.
126AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
127
128
129# set argument to 'p1 false', there should still no more completions.
130INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)"
131AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
132[0], [dnl
08d42548
AW
133])
134
135OVS_VSWITCHD_STOP
136AT_CLEANUP
137
138
139# complex completion check - lacp/show
140# lacp/show [port]
141# test expansion on 'port'
142AT_SETUP([bash completion - complex completion check 2])
143AT_SKIP_IF([test -z ${BASH_VERSION+x}])
144OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
145 -- add-port br0 p1 -- set Interface p1 type=dummy)
146
147# check the top level completion.
148INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
149MATCH="$(GET_COMP_STR([port], [br0 p0 p1]))"
150AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
151[0], [dnl
152${MATCH}
153])
154# check the available completions.
155AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
156[0], [dnl
157br0
158p0
159p1
160])
161
162
163# set argument to 'p1', there should be no more completions.
164INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show p1 TAB 2>&1)"
165AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
166[0], [dnl
08d42548
AW
167])
168
169OVS_VSWITCHD_STOP
170AT_CLEANUP
171
172
173# complex completion check - ofproto/trace
174# ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]
175# test expansion on 'dp|dp_name' and 'bridge'
176AT_SETUP([bash completion - complex completion check 3])
177AT_SKIP_IF([test -z ${BASH_VERSION+x}])
178OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
179 -- add-port br0 p1 -- set Interface p1 type=dummy)
180
181# check the top level completion.
182INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace TAB 2>&1)"
183MATCH="$(GET_COMP_STR([bridge], [br0])
184GET_COMP_STR([odp_flow], [])
185GET_COMP_STR([dp_name], [ovs-dummy]))"
186AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
187[0], [dnl
188${MATCH}
189])
190# check the available completions.
191AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
192[0], [dnl
193br0
194ovs-dummy
195])
196
197
198# set argument to 'ovs-dummy', should go to the dp-name path.
199INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy TAB 2>&1)"
200MATCH="$(GET_COMP_STR([odp_flow], []))"
201AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
202[0], [dnl
203${MATCH}
204])
205# check the available completions.
206AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
207
208
209# set odp_flow to some random string, should go to the next level.
210INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" TAB 2>&1)"
211MATCH="$(GET_COMP_STR([-generate], [-generate])
212GET_COMP_STR([packet], []))"
213AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
214[0], [dnl
215${MATCH}
216])
217# check the available completions.
218AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
219[0], [dnl
220-generate
221])
222
223
224# set packet to some random string, there should be no more completions.
225INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)"
226AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
227[0], [dnl
08d42548
AW
228])
229
230
231# set argument to 'br0', should go to the bridge path.
232INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)"
233MATCH="$(GET_COMP_STR([br_flow], []))"
234AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
235[0], [dnl
236${MATCH}
237])
238# check the available completions.
239AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
240
241
242# set argument to some random string, should go to the odp_flow path.
243INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)"
244MATCH="$(GET_COMP_STR([-generate], [-generate])
245GET_COMP_STR([packet], []))"
246AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
247[0], [dnl
248${MATCH}
249])
250# check the available completions.
251AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
252[0], [dnl
253-generate
254])
255
256OVS_VSWITCHD_STOP
257AT_CLEANUP
258
259
260# complex completion check - vlog/set
261# vlog/set {spec | PATTERN:destination:pattern}
262# test non expandable arguments
263AT_SETUP([bash completion - complex completion check 4])
264AT_SKIP_IF([test -z ${BASH_VERSION+x}])
265OVS_VSWITCHD_START
266
267# check the top level completion.
268INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
269MATCH="$(GET_COMP_STR([PATTERN:destination:pattern], [])
270GET_COMP_STR([spec], []))"
271AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
272[0], [dnl
273${MATCH}
274])
275# check the available completions.
276AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
277
278
279# set argument to random 'abcd', there should be no more completions.
280INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
281AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
282[0], [dnl
08d42548
AW
283])
284
285OVS_VSWITCHD_STOP
286AT_CLEANUP
287
288
289AT_SETUP([bash completion - negative test])
290AT_SKIP_IF([test -z ${BASH_VERSION+x}])
291OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)
292
293# negative test - incorrect subcommand
294INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR 2>&1)"
295AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d'], [0])
296INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR TAB 2>&1)"
297AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
298[0], [dnl
08d42548
AW
299])
300
301
302# negative test - no ovs-vswitchd
303# negative test - no ovsdb-server
304# negative test - no ovs-ofctl
305# should not see any error.
306OVS_VSWITCHD_STOP
307m4_foreach(
308[target_daemon],
309[[ovs-vswitchd],
310[ovsdb-server],
311[ovs-ofctl]],
312[
313INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
314MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)"
315AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
316[0], [dnl
317${MATCH}
318])
319INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon ERROR SUBCMD TAB 2>&1)"
320AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
321[0], [dnl
08d42548
AW
322])])
323
324
325# negative test - do not match on nested option
326INPUT="$(bash ovs-command-compgen.bash debug ovsdb-tool create TAB 2>&1)"
327AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])
328
329AT_CLEANUP