summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Wang <alexw@nicira.com>2014-11-24 11:15:45 -0800
committerAlex Wang <alexw@nicira.com>2015-01-30 15:28:22 -0800
commit08d425488a53338a5786323686e5f3b43a0c24ff (patch)
tree6a0cfba959672e4fc0fa0691c2a7c1be2a783bd3
parent9530457f245a886c6594409ad378f827bbf69728 (diff)
downloadopenvswitch-08d425488a53338a5786323686e5f3b43a0c24ff.tar.gz
ovs-command-completion: Autotest integration.
This commit integrates the unit tests defined in utilities/ovs-command-compgen-test.bash into 'make check'. The tests will be skipped if the current shell is not bash. Signed-off-by: Alex Wang <alexw@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
-rw-r--r--Makefile.am1
-rw-r--r--tests/automake.mk1
-rw-r--r--tests/completion.at354
-rw-r--r--tests/testsuite.at1
-rw-r--r--utilities/automake.mk4
-rwxr-xr-xutilities/ovs-command-compgen-test.bash688
6 files changed, 360 insertions, 689 deletions
diff --git a/Makefile.am b/Makefile.am
index b3ff4e31d..3e5e0b2d1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -134,6 +134,7 @@ scripts_SCRIPTS =
scripts_DATA =
SUFFIXES =
check_DATA =
+check_SCRIPTS =
pkgconfig_DATA =
scriptsdir = $(pkgdatadir)/scripts
diff --git a/tests/automake.mk b/tests/automake.mk
index 2dfaff11a..2e8d213dc 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -15,6 +15,7 @@ COMMON_MACROS_AT = \
TESTSUITE_AT = \
tests/testsuite.at \
+ tests/completion.at \
tests/library.at \
tests/heap.at \
tests/bundle.at \
diff --git a/tests/completion.at b/tests/completion.at
new file mode 100644
index 000000000..4832f61f3
--- /dev/null
+++ b/tests/completion.at
@@ -0,0 +1,354 @@
+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 \ No newline at end of file
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 57e9205dc..cd7f45531 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -18,6 +18,7 @@ m4_include([tests/ovs-macros.at])
m4_include([tests/ovsdb-macros.at])
m4_include([tests/ofproto-macros.at])
+m4_include([tests/completion.at])
m4_include([tests/bfd.at])
m4_include([tests/cfm.at])
m4_include([tests/lacp.at])
diff --git a/utilities/automake.mk b/utilities/automake.mk
index 834be5873..6fd7176df 100644
--- a/utilities/automake.mk
+++ b/utilities/automake.mk
@@ -22,13 +22,15 @@ scripts_SCRIPTS += \
utilities/ovs-save
scripts_DATA += utilities/ovs-lib
+check_SCRIPTS += utilities/ovs-command-compgen.bash
+
utilities/ovs-lib: $(top_builddir)/config.status
docs += utilities/ovs-command-compgen.INSTALL.md
EXTRA_DIST += \
utilities/ovs-check-dead-ifs.in \
utilities/ovs-command-compgen.bash \
- utilities/ovs-command-compgen-test.bash \
+ utilities/ovs-command-compgen.INSTALL.md \
utilities/ovs-ctl.in \
utilities/ovs-dev.py \
utilities/ovs-docker \
diff --git a/utilities/ovs-command-compgen-test.bash b/utilities/ovs-command-compgen-test.bash
deleted file mode 100755
index 3de6482f7..000000000
--- a/utilities/ovs-command-compgen-test.bash
+++ /dev/null
@@ -1,688 +0,0 @@
-#!/bin/bash
-#
-# Tests for the ovs-command-compgen.bash
-#
-# Please run this with ovs-command-compgen.bash script inside
-# ovs-sandbox, under the same directory.
-#
-# For information about running the ovs-sandbox, please refer to
-# the tutorial directory.
-#
-#
-#
-COMP_OUTPUT=
-TMP=
-EXPECT=
-TEST_RESULT=
-
-TEST_COUNTER=0
-TEST_COMMANDS=(ovs-appctl ovs-ofctl ovs-dpctl ovsdb-tool)
-TEST_APPCTL_TARGETS=(ovs-vswitchd ovsdb-server ovs-ofctl)
-
-#
-# Helper functions.
-#
-get_command_format() {
- local input="$@"
-
- echo "$(grep -A 1 "Command format" <<< "$input" | tail -n+2)"
-}
-
-get_argument_expansion() {
- local input="$@"
-
- echo "$(grep -- "available completions for keyword" <<< "$input" | sed -e 's/^[ \t]*//')"
-}
-
-get_available_completions() {
- local input="$@"
-
- echo "$(sed -e '1,/Available/d' <<< "$input" | tail -n+2)"
-}
-
-generate_expect_completions() {
- local keyword="$1"
- local completions="$2"
-
- echo "available completions for keyword \"$keyword\": $completions" \
- | sed -e 's/[ \t]*$//'
-}
-
-reset_globals() {
- COMP_OUTPUT=
- TMP=
- EXPECT=
- TEST_RESULT=
-}
-
-#
-# $1: Test name.
-# $2: ok or fail.
-#
-print_result() {
- (( TEST_COUNTER++ ))
- printf "%2d: %-70s %s\n" "$TEST_COUNTER" "$1" "$2"
-}
-
-#
-# $1: test stage
-# $2: actual
-# $3: expect
-#
-print_error() {
- local stage="$1"
- local actual="$2"
- local expect="$3"
-
- printf "failed at stage_%s:\n" "$stage"
- printf "actual output: %s\n" "$actual"
- printf "expect output: %s\n" "$expect"
-}
-
-#
-# Sub-tests.
-#
-ovs_apptcl_TAB() {
- local target="$1"
- local target_line=
- local comp_output tmp expect
-
- if [ -n "$target" ]; then
- target_line="--target $target"
- fi
- comp_output="$(bash ovs-command-compgen.bash debug ovs-appctl $target_line TAB 2>&1)"
- tmp="$(get_available_completions "$comp_output")"
- expect="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
-$(ovs-appctl $target_line list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
- if [ "$tmp" = "$expect" ]; then
- echo "ok"
- else
- echo "fail"
- fi
-}
-
-#
-# Test preparation.
-#
-ovs-vsctl add-br br0
-ovs-vsctl add-port br0 p1
-
-
-#
-# Begin the test.
-#
-cat <<EOF
-
-## ------------------------------- ##
-## ovs-command-compgen unit tests. ##
-## ------------------------------- ##
-
-EOF
-
-
-# complete ovs-appctl [TAB]
-# complete ovs-dpctl [TAB]
-# complete ovs-ofctl [TAB]
-# complete ovsdb-tool [TAB]
-
-for test_command in ${TEST_COMMANDS[@]}; do
- reset_globals
-
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ${test_command} TAB 2>&1)"
- TMP="$(get_available_completions "$COMP_OUTPUT")"
- EXPECT="$(${test_command} --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)
-$(${test_command} list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
- if [ "$TMP" = "$EXPECT" ]; then
- TEST_RESULT=ok
- else
- TEST_RESULT=fail
- fi
-
- print_result "complete ${test_command} [TAB]" "$TEST_RESULT"
-done
-
-
-# complete ovs-appctl --tar[TAB]
-
-reset_globals
-
-COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --tar 2>&1)"
-TMP="$(get_available_completions "$COMP_OUTPUT")"
-EXPECT="--target"
-if [ "$TMP" = "$EXPECT" ]; then
- TEST_RESULT=ok
-else
- TEST_RESULT=fail
-fi
-
-print_result "complete ovs-appctl --targ[TAB]" "$TEST_RESULT"
-
-
-# complete ovs-appctl --target [TAB]
-
-reset_globals
-
-COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target TAB 2>&1)"
-TMP="$(get_available_completions "$COMP_OUTPUT")"
-EXPECT="$(echo ${TEST_APPCTL_TARGETS[@]} | tr ' ' '\n' | sort)"
-if [ "$TMP" = "$EXPECT" ]; then
- TEST_RESULT=ok
-else
- TEST_RESULT=fail
-fi
-
-print_result "complete ovs-appctl --target [TAB]" "$TEST_RESULT"
-
-
-# complete ovs-appctl --target ovs-vswitchd [TAB]
-# complete ovs-appctl --target ovsdb-server [TAB]
-# complete ovs-appctl --target ovs-ofctl [TAB]
-
-reset_globals
-
-for target in ${TEST_APPCTL_TARGETS[@]}; do
- target_field="--target $i "
-
- if [ "$target" = "ovs-ofctl" ]; then
- ovs-ofctl monitor br0 --detach --no-chdir --pidfile
- fi
-
- TEST_RESULT="$(ovs_apptcl_TAB $target)"
-
- print_result "complete ovs-appctl ${target_field}[TAB]" "$TEST_RESULT"
-
- if [ "$target" = "ovs-ofctl" ]; then
- ovs-appctl --target ovs-ofctl exit
- fi
-done
-
-
-# check all subcommand formats
-
-reset_globals
-
-TMP="$(ovs-appctl list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)"
-
-# for each subcmd, check the print of subcmd format
-for i in $TMP; do
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl $i TAB 2>&1)"
- tmp="$(get_command_format "$COMP_OUTPUT")"
- EXPECT="$(ovs-appctl list-commands | tail -n+2 | cut -c3- | grep -- "^$i " | tr -s ' ' | sort)"
- if [ "$tmp" = "$EXPECT" ]; then
- TEST_RESULT=ok
- else
- TEST_RESULT=fail
- break
- fi
-done
-
-print_result "check all subcommand format" "$TEST_RESULT"
-
-
-# complex completion check - bfd/set-forwarding
-# bfd/set-forwarding [interface] normal|false|true
-# test expansion of 'interface'
-
-reset_globals
-
-for i in loop_once; do
- # check the top level completion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "normal" "")
-$(generate_expect_completions "false" "")
-$(generate_expect_completions "true" "")
-$(generate_expect_completions "interface" "p1")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="p1"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'true', there should be no more completions.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)"
- TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
- EXPECT="Command format:
-bfd/set-forwarding [interface] normal|false|true"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'p1', there should still be the completion for booleans.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "normal" "")
-$(generate_expect_completions "false" "")
-$(generate_expect_completions "true" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "4" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "5" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'p1 false', there should still no more completions.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)"
- TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
- EXPECT="Command format:
-bfd/set-forwarding [interface] normal|false|true"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "6" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complex completion check - bfd/set-forwarding" "$TEST_RESULT"
-
-
-# complex completion check - lacp/show
-# lacp/show [port]
-# test expansion on 'port'
-
-reset_globals
-
-for i in loop_once; do
- # check the top level completion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "port" "br0 p1")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="br0 p1"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'p1', there should be no more completions.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show p1 TAB 2>&1)"
- TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
- EXPECT="Command format:
-lacp/show [port]"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complex completion check - lacp/show" "$TEST_RESULT"
-
-
-# complex completion check - ofproto/trace
-# ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]
-# test expansion on 'dp|dp_name' and 'bridge'
-
-reset_globals
-
-for i in loop_once; do
- # check the top level completion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "bridge" "br0")
-$(generate_expect_completions "odp_flow" "")
-$(generate_expect_completions "dp_name" "ovs-system")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="br0 ovs-system"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'ovs-system', should go to the dp-name path.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "odp_flow" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "4" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set odp_flow to some random string, should go to the next level.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system "in_port(123),mac(),ip,tcp" TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "-generate" "-generate")
-$(generate_expect_completions "packet" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "5" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="-generate"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "6" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set packet to some random string, there should be no more completions.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace ovs-system "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)"
- TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
- EXPECT="Command format:
-ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet]"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "7" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to 'br0', should go to the bridge path.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "br_flow" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "8" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "9" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to some random string, should go to the odp_flow path.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "-generate" "-generate")
-$(generate_expect_completions "packet" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "10" "$TMP" "$EXPEC"T
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="-generate"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "11" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complex completion check - ofproto/trace" "$TEST_RESULT"
-
-
-# complex completion check - vlog/set
-# vlog/set {spec | PATTERN:destination:pattern}
-# test non expandable arguments
-
-reset_globals
-
-for i in loop_once; do
- # check the top level completion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "PATTERN:destination:pattern" "")
-$(generate_expect_completions "spec" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # set argument to random 'abcd', there should be no more completions.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
- TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
- EXPECT="Command format:
-vlog/set {spec | PATTERN:destination:pattern}"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complex completion check - vlog/set" "$TEST_RESULT"
-
-
-# complete after delete port
-
-reset_globals
-ovs-vsctl del-port p1
-
-for i in loop_once; do
- # check match on interface, there should be no available interface expansion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "normal" "")
-$(generate_expect_completions "false" "")
-$(generate_expect_completions "true" "")
-$(generate_expect_completions "interface" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check match on port, there should be no p1 as port.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl lacp/show TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "port" "br0")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT="br0"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "4" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complete after delete port" "$TEST_RESULT"
-
-
-# complete after delete bridge
-
-reset_globals
-ovs-vsctl del-br br0
-for i in loop_once; do
- # check match on port, there should be no p1 as port.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl bridge/dump-flows TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT="$(generate_expect_completions "bridge" "")"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check the available completions.
- TMP="$(get_available_completions "$COMP_OUTPUT" | tr '\n' ' ' | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- # check 'ovs-ofctl monitor [misslen] [invalid_ttl] [watch:[...]]', should
- # not show any available completion.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-ofctl monitor non_exist_br TAB 2>&1)"
- TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "3" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "complete after delete bridge" "$TEST_RESULT"
-
-
-# negative test - incorrect subcommand
-
-reset_globals
-
-for i in loop_once; do
- # incorrect subcommand
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR 2>&1)"
- TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d')"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "1" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl ERROR TAB 2>&1)"
- TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d')"
- EXPECT="Command format:"
- if [ "$TMP" != "$EXPECT" ]; then
- print_error "2" "$TMP" "$EXPECT"
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "negative test - incorrect subcommand" "$TEST_RESULT"
-
-
-# negative test - no ovs-vswitchd
-# negative test - no ovsdb-server
-# negative test - no ovs-ofctl
-# should not see any error.
-
-reset_globals
-killall ovs-vswitchd ovsdb-server
-
-for i in ${TEST_APPCTL_TARGETS[@]}; do
- for j in loop_once; do
- reset_globals
-
- daemon="$i"
-
- # should show no avaiable subcommands.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target $daemon TAB 2>&1)"
- TMP="$(get_available_completions "$COMP_OUTPUT")"
- EXPECT="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)"
- if [ "$TMP" != "$EXPECT" ]; then
- TEST_RESULT=fail
- break
- fi
-
- # should not match any input.
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl --target $daemon ERROR SUBCMD TAB 2>&1)"
- TMP="$(echo "$COMP_OUTPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d')"
- EXPECT="Command format:"
- if [ "$TMP" != "$EXPECT" ]; then
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
- done
- print_result "negative test - no $daemon" "$TEST_RESULT"
-done
-
-
-# negative test - do not match on nested option
-
-reset_globals
-
-for i in loop_once; do
- COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovsdb-tool create TAB 2>&1)"
- TMP="$(get_available_completions "$COMP_OUTPUT")"
- EXPECT=
- if [ "$TMP" != "$EXPECT" ]; then
- TEST_RESULT=fail
- break
- fi
-
- TEST_RESULT=ok
-done
-
-print_result "negative test - do not match on nested option" "$TEST_RESULT"