utilities: Add bash command-line completion script.
[cascardo/ovs.git] / utilities / ovs-command-compgen-test.bash
1 #!/bin/bash
2 #
3 # Tests for the ovs-command-compgen.bash
4 #
5 # Please run this with ovs-command-compgen.bash script inside
6 # ovs-sandbox, under the same directory.
7 #
8 # For information about running the ovs-sandbox, please refer to
9 # the tutorial directory.
10 #
11 #
12 #
13 COMP_OUTPUT=
14 TMP=
15 EXPECT=
16 TEST_RESULT=
17
18 TEST_COUNTER=0
19 TEST_COMMANDS=(ovs-appctl ovs-ofctl ovs-dpctl ovsdb-tool)
20 TEST_APPCTL_TARGETS=(ovs-vswitchd ovsdb-server ovs-ofctl)
21
22 #
23 # Helper functions.
24 #
25 get_command_format() {
26     local input="$@"
27
28     echo "$(grep -A 1 "Command format" <<< "$input" | tail -n+2)"
29 }
30
31 get_argument_expansion() {
32     local input="$@"
33
34     echo "$(grep -- "available completions for keyword" <<< "$input" | sed -e 's/^[ \t]*//')"
35 }
36
37 get_available_completions() {
38     local input="$@"
39
40     echo "$(sed -e '1,/Available/d' <<< "$input" | tail -n+2)"
41 }
42
43 generate_expect_completions() {
44     local keyword="$1"
45     local completions="$2"
46
47     echo "available completions for keyword \"$keyword\": $completions" \
48         | sed -e 's/[ \t]*$//'
49 }
50
51 reset_globals() {
52     COMP_OUTPUT=
53     TMP=
54     EXPECT=
55     TEST_RESULT=
56 }
57
58 #
59 # $1: Test name.
60 # $2: ok or fail.
61 #
62 print_result() {
63     (( TEST_COUNTER++ ))
64     printf "%2d: %-70s %s\n" "$TEST_COUNTER" "$1" "$2"
65 }
66
67 #
68 # $1: test stage
69 # $2: actual
70 # $3: expect
71 #
72 print_error() {
73     local stage="$1"
74     local actual="$2"
75     local expect="$3"
76
77     printf "failed at stage_%s:\n" "$stage"
78     printf "actual output: %s\n" "$actual"
79     printf "expect output: %s\n" "$expect"
80 }
81
82 #
83 # Sub-tests.
84 #
85 ovs_apptcl_TAB() {
86     local target="$1"
87     local target_line=
88     local comp_output tmp expect
89
90     if [ -n "$target" ]; then
91         target_line="--target $target"
92     fi
93     comp_output="$(bash ovs-command-compgen.bash debug ovs-appctl $target_line TAB 2>&1)"
94     tmp="$(get_available_completions "$comp_output")"
95     expect="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
96 $(ovs-appctl $target_line list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
97     if [ "$tmp" = "$expect" ]; then
98         echo "ok"
99     else
100         echo "fail"
101     fi
102 }
103
104 #
105 # Test preparation.
106 #
107 ovs-vsctl add-br br0
108 ovs-vsctl add-port br0 p1
109
110
111 #
112 # Begin the test.
113 #
114 cat <<EOF
115
116 ## ------------------------------- ##
117 ## ovs-command-compgen unit tests. ##
118 ## ------------------------------- ##
119
120 EOF
121
122
123 # complete ovs-appctl [TAB]
124 # complete ovs-dpctl  [TAB]
125 # complete ovs-ofctl  [TAB]
126 # complete ovsdb-tool [TAB]
127
128 for test_command in ${TEST_COMMANDS[@]}; do
129     reset_globals
130
131     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ${test_command} TAB 2>&1)"
132     TMP="$(get_available_completions "$COMP_OUTPUT")"
133     EXPECT="$(${test_command} --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
134 $(${test_command} list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
135     if [ "$TMP" = "$EXPECT" ]; then
136         TEST_RESULT=ok
137     else
138         TEST_RESULT=fail
139     fi
140
141     print_result "complete ${test_command} [TAB]" "$TEST_RESULT"
142 done
143
144
145 # complete ovs-appctl --tar[TAB]
146
147 reset_globals
148
149 COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --tar 2>&1)"
150 TMP="$(get_available_completions "$COMP_OUTPUT")"
151 EXPECT="--target"
152 if [ "$TMP" = "$EXPECT" ]; then
153     TEST_RESULT=ok
154 else
155     TEST_RESULT=fail
156 fi
157
158 print_result "complete ovs-appctl --targ[TAB]" "$TEST_RESULT"
159
160
161 # complete ovs-appctl --target [TAB]
162
163 reset_globals
164
165 COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target TAB 2>&1)"
166 TMP="$(get_available_completions "$COMP_OUTPUT")"
167 EXPECT="$(echo ${TEST_APPCTL_TARGETS[@]} | tr ' ' '\n' | sort)"
168 if [ "$TMP" = "$EXPECT" ]; then
169     TEST_RESULT=ok
170 else
171     TEST_RESULT=fail
172 fi
173
174 print_result "complete ovs-appctl --target [TAB]" "$TEST_RESULT"
175
176
177 # complete ovs-appctl --target ovs-vswitchd [TAB]
178 # complete ovs-appctl --target ovsdb-server [TAB]
179 # complete ovs-appctl --target ovs-ofctl    [TAB]
180
181 reset_globals
182
183 for target in ${TEST_APPCTL_TARGETS[@]}; do
184     target_field="--target $i "
185
186     if [ "$target" = "ovs-ofctl" ]; then
187         ovs-ofctl monitor br0 --detach --no-chdir --pidfile
188     fi
189
190     TEST_RESULT="$(ovs_apptcl_TAB $target)"
191
192     print_result "complete ovs-appctl ${target_field}[TAB]" "$TEST_RESULT"
193
194     if [ "$target" = "ovs-ofctl" ]; then
195         ovs-appctl --target ovs-ofctl exit
196     fi
197 done
198
199
200 # check all subcommand formats
201
202 reset_globals
203
204 TMP="$(ovs-appctl list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
205
206 # for each subcmd, check the print of subcmd format
207 for i in $TMP; do
208     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl $i TAB 2>&1)"
209     tmp="$(get_command_format "$COMP_OUTPUT")"
210     EXPECT="$(ovs-appctl list-commands | tail -n+2 | cut -c3- | grep -- "^$i " | tr -s ' ' | sort)"
211     if [ "$tmp" = "$EXPECT" ]; then
212         TEST_RESULT=ok
213     else
214         TEST_RESULT=fail
215         break
216     fi
217 done
218
219 print_result "check all subcommand format" "$TEST_RESULT"
220
221
222 # complex completion check - bfd/set-forwarding
223 # bfd/set-forwarding [interface] normal|false|true
224 # test expansion of 'interface'
225
226 reset_globals
227
228 for i in loop_once; do
229     # check the top level completion.
230     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
231     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
232     EXPECT="$(generate_expect_completions "normal" "")
233 $(generate_expect_completions "false" "")
234 $(generate_expect_completions "true" "")
235 $(generate_expect_completions "interface" "p1")"
236     if [ "$TMP" != "$EXPECT" ]; then
237         print_error "1" "$TMP" "$EXPECT"
238         TEST_RESULT=fail
239         break
240     fi
241
242     # check the available completions.
243     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
244     EXPECT="p1"
245     if [ "$TMP" != "$EXPECT" ]; then
246         print_error "2" "$TMP" "$EXPECT"
247         TEST_RESULT=fail
248         break
249     fi
250
251     # set argument to 'true', there should be no more completions.
252     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)"
253     TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
254     EXPECT="Command format:
255 bfd/set-forwarding [interface] normal|false|true"
256     if [ "$TMP" != "$EXPECT" ]; then
257         print_error "3" "$TMP" "$EXPECT"
258         TEST_RESULT=fail
259         break
260     fi
261
262     # set argument to 'p1', there should still be the completion for booleans.
263     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)"
264     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
265     EXPECT="$(generate_expect_completions "normal" "")
266 $(generate_expect_completions "false" "")
267 $(generate_expect_completions "true" "")"
268     if [ "$TMP" != "$EXPECT" ]; then
269         print_error "4" "$TMP" "$EXPECT"
270         TEST_RESULT=fail
271         break
272     fi
273
274     # check the available completions.
275     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
276     EXPECT=
277     if [ "$TMP" != "$EXPECT" ]; then
278         print_error "5" "$TMP" "$EXPECT"
279         TEST_RESULT=fail
280         break
281     fi
282
283     # set argument to 'p1 false', there should still no more completions.
284     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)"
285     TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
286     EXPECT="Command format:
287 bfd/set-forwarding [interface] normal|false|true"
288     if [ "$TMP" != "$EXPECT" ]; then
289         print_error "6" "$TMP" "$EXPECT"
290         TEST_RESULT=fail
291         break
292     fi
293
294     TEST_RESULT=ok
295 done
296
297 print_result "complex completion check - bfd/set-forwarding" "$TEST_RESULT"
298
299
300 # complex completion check - lacp/show
301 # lacp/show [port]
302 # test expansion on 'port'
303
304 reset_globals
305
306 for i in loop_once; do
307     # check the top level completion.
308     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
309     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
310     EXPECT="$(generate_expect_completions "port" "br0 p1")"
311     if [ "$TMP" != "$EXPECT" ]; then
312         print_error "1" "$TMP" "$EXPECT"
313         TEST_RESULT=fail
314         break
315     fi
316
317     # check the available completions.
318     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
319     EXPECT="br0 p1"
320     if [ "$TMP" != "$EXPECT" ]; then
321         print_error "2" "$TMP" "$EXPECT"
322         TEST_RESULT=fail
323         break
324     fi
325
326     # set argument to 'p1', there should be no more completions.
327     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show p1 TAB 2>&1)"
328     TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
329     EXPECT="Command format:
330 lacp/show [port]"
331     if [ "$TMP" != "$EXPECT" ]; then
332         print_error "3" "$TMP" "$EXPECT"
333         TEST_RESULT=fail
334         break
335     fi
336
337     TEST_RESULT=ok
338 done
339
340 print_result "complex completion check - lacp/show" "$TEST_RESULT"
341
342
343 # complex completion check - ofproto/trace
344 # ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]
345 # test expansion on 'dp|dp_name' and 'bridge'
346
347 reset_globals
348
349 for i in loop_once; do
350     # check the top level completion.
351     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace TAB 2>&1)"
352     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
353     EXPECT="$(generate_expect_completions "bridge" "br0")
354 $(generate_expect_completions "odp_flow" "")
355 $(generate_expect_completions "dp_name" "ovs-system")"
356     if [ "$TMP" != "$EXPECT" ]; then
357         print_error "1" "$TMP" "$EXPECT"
358         TEST_RESULT=fail
359         break
360     fi
361
362     # check the available completions.
363     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
364     EXPECT="br0 ovs-system"
365     if [ "$TMP" != "$EXPECT" ]; then
366         print_error "2" "$TMP" "$EXPECT"
367         TEST_RESULT=fail
368         break
369     fi
370
371     # set argument to 'ovs-system', should go to the dp-name path.
372     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system TAB 2>&1)"
373     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
374     EXPECT="$(generate_expect_completions "odp_flow" "")"
375     if [ "$TMP" != "$EXPECT" ]; then
376         print_error "3" "$TMP" "$EXPECT"
377         TEST_RESULT=fail
378         break
379     fi
380
381     # check the available completions.
382     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
383     EXPECT=
384     if [ "$TMP" != "$EXPECT" ]; then
385         print_error "4" "$TMP" "$EXPECT"
386         TEST_RESULT=fail
387         break
388     fi
389
390     # set odp_flow to some random string, should go to the next level.
391     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system "in_port(123),mac(),ip,tcp" TAB 2>&1)"
392     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
393     EXPECT="$(generate_expect_completions "-generate" "-generate")
394 $(generate_expect_completions "packet" "")"
395     if [ "$TMP" != "$EXPECT" ]; then
396         print_error "5" "$TMP" "$EXPECT"
397         TEST_RESULT=fail
398         break
399     fi
400
401     # check the available completions.
402     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
403     EXPECT="-generate"
404     if [ "$TMP" != "$EXPECT" ]; then
405         print_error "6" "$TMP" "$EXPECT"
406         TEST_RESULT=fail
407         break
408     fi
409
410     # set packet to some random string, there should be no more completions.
411     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)"
412     TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
413     EXPECT="Command format:
414 ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]"
415     if [ "$TMP" != "$EXPECT" ]; then
416         print_error "7" "$TMP" "$EXPECT"
417         TEST_RESULT=fail
418         break
419     fi
420
421     # set argument to 'br0', should go to the bridge path.
422     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)"
423     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
424     EXPECT="$(generate_expect_completions "br_flow" "")"
425     if [ "$TMP" != "$EXPECT" ]; then
426         print_error "8" "$TMP" "$EXPECT"
427         TEST_RESULT=fail
428         break
429     fi
430
431     # check the available completions.
432     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
433     EXPECT=
434     if [ "$TMP" != "$EXPECT" ]; then
435         print_error "9" "$TMP" "$EXPECT"
436         TEST_RESULT=fail
437         break
438     fi
439
440     # set argument to some random string, should go to the odp_flow path.
441     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)"
442     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
443     EXPECT="$(generate_expect_completions "-generate" "-generate")
444 $(generate_expect_completions "packet" "")"
445     if [ "$TMP" != "$EXPECT" ]; then
446         print_error "10" "$TMP" "$EXPEC"T
447         TEST_RESULT=fail
448         break
449     fi
450
451     # check the available completions.
452     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
453     EXPECT="-generate"
454     if [ "$TMP" != "$EXPECT" ]; then
455         print_error "11" "$TMP" "$EXPECT"
456         TEST_RESULT=fail
457         break
458     fi
459
460     TEST_RESULT=ok
461 done
462
463 print_result "complex completion check - ofproto/trace" "$TEST_RESULT"
464
465
466 # complex completion check - vlog/set
467 # vlog/set {spec | PATTERN:facility:pattern}
468 # test non expandable arguments
469
470 reset_globals
471
472 for i in loop_once; do
473     # check the top level completion.
474     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
475     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
476     EXPECT="$(generate_expect_completions "PATTERN:facility:pattern" "")
477 $(generate_expect_completions "spec" "")"
478     if [ "$TMP" != "$EXPECT" ]; then
479         print_error "1" "$TMP" "$EXPECT"
480         TEST_RESULT=fail
481         break
482     fi
483
484     # check the available completions.
485     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
486     EXPECT=
487     if [ "$TMP" != "$EXPECT" ]; then
488         print_error "2" "$TMP" "$EXPECT"
489         TEST_RESULT=fail
490         break
491     fi
492
493     # set argument to random 'abcd', there should be no more completions.
494     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
495     TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
496     EXPECT="Command format:
497 vlog/set {spec | PATTERN:facility:pattern}"
498     if [ "$TMP" != "$EXPECT" ]; then
499         print_error "3" "$TMP" "$EXPECT"
500         TEST_RESULT=fail
501         break
502     fi
503
504     TEST_RESULT=ok
505 done
506
507 print_result "complex completion check - vlog/set" "$TEST_RESULT"
508
509
510 # complete after delete port
511
512 reset_globals
513 ovs-vsctl del-port p1
514
515 for i in loop_once; do
516     # check match on interface, there should be no available interface expansion.
517     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
518     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
519     EXPECT="$(generate_expect_completions "normal" "")
520 $(generate_expect_completions "false" "")
521 $(generate_expect_completions "true" "")
522 $(generate_expect_completions "interface" "")"
523     if [ "$TMP" != "$EXPECT" ]; then
524         print_error "1" "$TMP" "$EXPECT"
525         TEST_RESULT=fail
526         break
527     fi
528
529     # check the available completions.
530     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
531     EXPECT=
532     if [ "$TMP" != "$EXPECT" ]; then
533         print_error "2" "$TMP" "$EXPECT"
534         TEST_RESULT=fail
535         break
536     fi
537
538     # check match on port, there should be no p1 as port.
539     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
540     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
541     EXPECT="$(generate_expect_completions "port" "br0")"
542     if [ "$TMP" != "$EXPECT" ]; then
543         print_error "3" "$TMP" "$EXPECT"
544         TEST_RESULT=fail
545         break
546     fi
547
548     # check the available completions.
549     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
550     EXPECT="br0"
551     if [ "$TMP" != "$EXPECT" ]; then
552         print_error "4" "$TMP" "$EXPECT"
553         TEST_RESULT=fail
554         break
555     fi
556
557     TEST_RESULT=ok
558 done
559
560 print_result "complete after delete port" "$TEST_RESULT"
561
562
563 # complete after delete bridge
564
565 reset_globals
566 ovs-vsctl del-br br0
567 for i in loop_once; do
568     # check match on port, there should be no p1 as port.
569     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bridge/dump-flows TAB 2>&1)"
570     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
571     EXPECT="$(generate_expect_completions "bridge" "")"
572     if [ "$TMP" != "$EXPECT" ]; then
573         print_error "1" "$TMP" "$EXPECT"
574         TEST_RESULT=fail
575         break
576     fi
577
578     # check the available completions.
579     TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
580     EXPECT=
581     if [ "$TMP" != "$EXPECT" ]; then
582         print_error "2" "$TMP" "$EXPECT"
583         TEST_RESULT=fail
584         break
585     fi
586
587     # check 'ovs-ofctl monitor [misslen] [invalid_ttl] [watch:[...]]', should
588     # not show any available completion.
589     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-ofctl monitor non_exist_br TAB 2>&1)"
590     TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
591     EXPECT=
592     if [ "$TMP" != "$EXPECT" ]; then
593         print_error "3" "$TMP" "$EXPECT"
594         TEST_RESULT=fail
595         break
596     fi
597
598     TEST_RESULT=ok
599 done
600
601 print_result "complete after delete bridge" "$TEST_RESULT"
602
603
604 # negative test - incorrect subcommand
605
606 reset_globals
607
608 for i in loop_once; do
609     # incorrect subcommand
610     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR 2>&1)"
611     TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d')"
612     EXPECT=
613     if [ "$TMP" != "$EXPECT" ]; then
614         print_error "1" "$TMP" "$EXPECT"
615         TEST_RESULT=fail
616         break
617     fi
618
619     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR TAB 2>&1)"
620     TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d')"
621     EXPECT="Command format:"
622     if [ "$TMP" != "$EXPECT" ]; then
623         print_error "2" "$TMP" "$EXPECT"
624         TEST_RESULT=fail
625         break
626     fi
627
628     TEST_RESULT=ok
629 done
630
631 print_result "negative test - incorrect subcommand" "$TEST_RESULT"
632
633
634 # negative test - no ovs-vswitchd
635 # negative test - no ovsdb-server
636 # negative test - no ovs-ofctl
637 # should not see any error.
638
639 reset_globals
640 killall ovs-vswitchd ovsdb-server
641
642 for i in ${TEST_APPCTL_TARGETS[@]}; do
643     for j in loop_once; do
644         reset_globals
645
646         daemon="$i"
647
648         # should show no avaiable subcommands.
649         COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target $daemon TAB 2>&1)"
650         TMP="$(get_available_completions "$COMP_OUTPUT")"
651         EXPECT="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)"
652         if [ "$TMP" != "$EXPECT" ]; then
653             TEST_RESULT=fail
654             break
655         fi
656
657         # should not match any input.
658         COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target $daemon ERROR SUBCMD TAB 2>&1)"
659         TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d')"
660         EXPECT="Command format:"
661         if [ "$TMP" != "$EXPECT" ]; then
662             TEST_RESULT=fail
663             break
664         fi
665
666         TEST_RESULT=ok
667     done
668     print_result "negative test - no $daemon" "$TEST_RESULT"
669 done
670
671
672 # negative test - do not match on nested option
673
674 reset_globals
675
676 for i in loop_once; do
677     COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovsdb-tool create TAB 2>&1)"
678     TMP="$(get_available_completions "$COMP_OUTPUT")"
679     EXPECT=
680     if [ "$TMP" != "$EXPECT" ]; then
681         TEST_RESULT=fail
682         break
683     fi
684
685     TEST_RESULT=ok
686 done
687
688 print_result "negative test - do not match on nested option" "$TEST_RESULT"