summaryrefslogtreecommitdiff
path: root/tests/completion.at
blob: dd50429b4d22114bf83af0eef6df7203f4e093ac (plain)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
AT_BANNER([command completion unit tests - bash])

m4_define([GET_FORMAT], [
echo "$@" | grep -A 1 -- "Command format" | tail -n+2
])

m4_define([GET_EXPAN], [
echo "$@" | grep -- "available completions for keyword" \
     | sed -e 's/^[ ]*//g;s/[ ]*$//g'
])

m4_define([GET_AVAIL], [
echo "$@" | sed -e '1,/Available/d' | tail -n+2
])

m4_define([GET_COMP_STR], [
echo "available completions for keyword \"$1\": $2" \
     | sed -e 's/[ ]*$//g'
])

AT_SETUP([bash completion - basic verification])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START

# complete ovs-appctl [TAB]
# complete ovs-dpctl  [TAB]
# complete ovs-ofctl  [TAB]
# complete ovsdb-tool [TAB]
m4_foreach(
[test_command],
[[ovs-appctl],
[ovs-dpctl],
[ovs-ofctl],
[ovsdb-tool]],
[
INPUT="$(bash ovs-command-compgen.bash debug test_command TAB 2>&1)"
MATCH="$(test_command --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
$(test_command list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
${MATCH}
])])


# complete ovs-appctl --tar[TAB]
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --tar 2>&1)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
--target
])


# complete ovs-appctl --target [TAB]
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target TAB 2>&1)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
ovs-ofctl
ovs-vswitchd
ovsdb-server
])


# complete ovs-appctl --target ovs-vswitchd [TAB]
# complete ovs-appctl --target ovsdb-server [TAB]
# complete ovs-appctl --target ovs-ofctl    [TAB]
AT_CHECK([ovs-ofctl monitor br0 --detach --no-chdir --pidfile])
m4_foreach(
[target_daemon],
[[ovs-vswitchd],
[ovsdb-server],
[ovs-ofctl]],
[
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
$(ovs-appctl --target target_daemon list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
${MATCH}
])])
AT_CHECK([ovs-appctl --target ovs-ofctl exit])
OVS_VSWITCHD_STOP
AT_CLEANUP


# complex completion check - bfd/set-forwarding
# bfd/set-forwarding [interface] normal|false|true
# test expansion of 'interface'
AT_SETUP([bash completion - complex completion check 1])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)

# check the top level completion.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
MATCH="$(GET_COMP_STR([normal], [])
GET_COMP_STR([false], [])
GET_COMP_STR([true], [])
GET_COMP_STR([interface], [p0]))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
p0
])


# set argument to 'true', there should be no more completions.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
[0], [dnl
])


# set argument to 'p1', there should still be the completion for booleans.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)"
MATCH="$(GET_COMP_STR([normal], [])
GET_COMP_STR([false], [])
GET_COMP_STR([true], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])


# set argument to 'p1 false', there should still no more completions.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
[0], [dnl
])

OVS_VSWITCHD_STOP
AT_CLEANUP


# complex completion check - lacp/show
# lacp/show [port]
# test expansion on 'port'
AT_SETUP([bash completion - complex completion check 2])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
                   -- add-port br0 p1 -- set Interface p1 type=dummy)

# check the top level completion.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
MATCH="$(GET_COMP_STR([port], [br0 p0 p1]))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
br0
p0
p1
])


# set argument to 'p1', there should be no more completions.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show p1 TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
[0], [dnl
])

OVS_VSWITCHD_STOP
AT_CLEANUP


# complex completion check - ofproto/trace
# ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]
# test expansion on 'dp|dp_name' and 'bridge'
AT_SETUP([bash completion - complex completion check 3])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \
                   -- add-port br0 p1 -- set Interface p1 type=dummy)

# check the top level completion.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace TAB 2>&1)"
MATCH="$(GET_COMP_STR([bridge], [br0])
GET_COMP_STR([odp_flow], [])
GET_COMP_STR([dp_name], [ovs-dummy]))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
br0
ovs-dummy
])


# set argument to 'ovs-dummy', should go to the dp-name path.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy TAB 2>&1)"
MATCH="$(GET_COMP_STR([odp_flow], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])


# set odp_flow to some random string, should go to the next level.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" TAB 2>&1)"
MATCH="$(GET_COMP_STR([-generate], [-generate])
GET_COMP_STR([packet], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
-generate
])


# set packet to some random string, there should be no more completions.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
[0], [dnl
])


# set argument to 'br0', should go to the bridge path.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)"
MATCH="$(GET_COMP_STR([br_flow], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])


# set argument to some random string, should go to the odp_flow path.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)"
MATCH="$(GET_COMP_STR([-generate], [-generate])
GET_COMP_STR([packet], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
-generate
])

OVS_VSWITCHD_STOP
AT_CLEANUP


# complex completion check - vlog/set
# vlog/set {spec | PATTERN:destination:pattern}
# test non expandable arguments
AT_SETUP([bash completion - complex completion check 4])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START

# check the top level completion.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
MATCH="$(GET_COMP_STR([PATTERN:destination:pattern], [])
GET_COMP_STR([spec], []))"
AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})],
[0], [dnl
${MATCH}
])
# check the available completions.
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])


# set argument to random 'abcd', there should be no more completions.
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'],
[0], [dnl
])

OVS_VSWITCHD_STOP
AT_CLEANUP


AT_SETUP([bash completion - negative test])
AT_SKIP_IF([test -z ${BASH_VERSION+x}])
OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy)

# negative test - incorrect subcommand
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d'], [0])
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
[0], [dnl
])


# negative test - no ovs-vswitchd
# negative test - no ovsdb-server
# negative test - no ovs-ofctl
# should not see any error.
OVS_VSWITCHD_STOP
m4_foreach(
[target_daemon],
[[ovs-vswitchd],
[ovsdb-server],
[ovs-ofctl]],
[
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon TAB 2>&1)"
MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})],
[0], [dnl
${MATCH}
])
INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target target_daemon ERROR SUBCMD TAB 2>&1)"
AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'],
[0], [dnl
])])


# negative test - do not match on nested option
INPUT="$(bash ovs-command-compgen.bash debug ovsdb-tool create TAB 2>&1)"
AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0])

AT_CLEANUP