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]) # check all ovs-appctl subcommand formats LIST=$(ovs-appctl list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort) for subcommand in $LIST; do INPUT="$(bash ovs-command-compgen.bash debug ovs-appctl $subcommand TAB 2>&1)" MATCH=$(ovs-appctl list-commands | tail -n+2 | cut -c3- | grep -- "^$subcommand " | tr -s ' ') AT_CHECK_UNQUOTED([GET_FORMAT(${INPUT})], [0], [dnl ${MATCH} ]) done 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 Command format: bfd/set-forwarding [[interface]] normal|false|true ]) # 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 Command format: bfd/set-forwarding [[interface]] normal|false|true ]) 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 Command format: lacp/show [[port]] ]) 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 Command format: ofproto/trace {[[dp_name]] odp_flow | bridge br_flow} [[-generate|packet]] ]) # 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 Command format: vlog/set {spec | PATTERN:destination:pattern} ]) 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 Command format: ]) # 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 Command format: ])]) # 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