1
0
mirror of https://passt.top/passt synced 2024-07-04 00:42:41 +00:00

test: Integration of old-style pane execution and new context execution

We're creating a system for tests to more reliably execute commands in
various contexts (e.g. host, guest, namespace).  That transition is going
to happen over a number of steps though, so in the meantime we need to deal
with both the old-style issuing of commands via typing into and screen
scraping tmux panels, and the new-style system for executing commands in
context.

Introduce some transitional helpers which will issue a command via context
if the requested context is initialized, but will otherwise fall back to
the old style tmux panel based method.  Re-implement the various test DSL
commands in terms of these new helpers.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-09-12 20:56:17 +10:00 committed by Stefano Brivio
parent a32df9b6f4
commit c2f248588b
3 changed files with 121 additions and 81 deletions

View File

@ -259,6 +259,69 @@ pane_watch_contexts() {
cmd_write ${__pane_number} "${__cmd}" cmd_write ${__pane_number} "${__cmd}"
} }
# pane_or_context_run() - Issue a command in given context or pane
# $1: Context or lower-case pane name
# $@: Command to issue
pane_or_context_run() {
__name="${1}"
shift
if context_exists "${__name}"; then
context_run "${__name}" "$@" >/dev/null 2>&1
else
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
pane_run "${__uc}" "$@"
pane_status "${__uc}"
fi
}
# pane_or_context_run_bg() - Issue a background command in given context or pane
# $1: Context or lower-case pane name
# $@: Command to issue
pane_or_context_run_bg() {
__name="${1}"
shift
if context_exists "${__name}"; then
context_run_bg "${__name}" "$@" >/dev/null 2>&1
else
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
pane_run "${__uc}" "$@"
fi
}
# pane_or_context_output() - Get output from a command in a context or pane
# $1: Context or lower-case pane name
# $@: Command to issue
pane_or_context_output() {
__name="${1}"
shift
if context_exists "${__name}"; then
__output=$(context_run "${__name}" "$@" 2>/dev/null)
if [ -z "${__output}" ]; then
echo "@EMPTY@"
else
echo "${__output}"
fi
else
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
pane_run "${__uc}" "$@"
pane_wait "${__uc}"
pane_parse "${__uc}"
fi
}
# pane_or_context_wait() - Wait for a command to be done in a context or pane
# $1: Context or lower-case pane name
pane_or_context_wait() {
__name="${1}"
shift
if context_exists "${__name}"; then
context_wait "${__name}"
else
__uc="$(echo "${__name}" | tr [a-z] [A-Z])"
pane_wait "${__uc}"
fi
}
# status_file_end() - Display and log messages when tests from one file are done # status_file_end() - Display and log messages when tests from one file are done
status_file_end() { status_file_end() {
[ -z "${STATUS_FILE}" ] && return [ -z "${STATUS_FILE}" ] && return

View File

@ -15,8 +15,8 @@
# test_iperf3() - Ugly helper for iperf3 directive # test_iperf3() - Ugly helper for iperf3 directive
# $1: Variable name: to put the measure bandwidth into # $1: Variable name: to put the measure bandwidth into
# $2: Source/client pane name, can be lowercase # $2: Source/client context
# $3: Destination/server pane name, can be lowercase # $3: Destination/server context
# $4: Destination name or address for client # $4: Destination name or address for client
# $5: Port number, ${i} is translated to process index # $5: Port number, ${i} is translated to process index
# $6: Number of processes to run in parallel # $6: Number of processes to run in parallel
@ -24,14 +24,14 @@
# $@: Client options # $@: Client options
test_iperf3() { test_iperf3() {
__var="${1}"; shift __var="${1}"; shift
__cpane="$(echo "${1}" | tr [a-z] [A-Z])"; shift __cctx="${1}"; shift
__spane="$(echo "${1}" | tr [a-z] [A-Z])"; shift __sctx="${1}"; shift
__dest="${1}"; shift __dest="${1}"; shift
__port="${1}"; shift __port="${1}"; shift
__procs="$((${1} - 1))"; shift __procs="$((${1} - 1))"; shift
__time="${1}"; shift __time="${1}"; shift
pane_run "${__spane}" \ pane_or_context_run_bg "${__sctx}" \
'(' \ '(' \
' for i in $(seq 0 '${__procs}'); do' \ ' for i in $(seq 0 '${__procs}'); do' \
' iperf3 -s1J -p'${__port}' -i'${__time} \ ' iperf3 -s1J -p'${__port}' -i'${__time} \
@ -40,7 +40,9 @@ test_iperf3() {
' wait' \ ' wait' \
')' ')'
pane_run "${__cpane}" \ sleep 1 # Wait for server to be ready
pane_or_context_run "${__cctx}" \
'(' \ '(' \
' for i in $(seq 0 '${__procs}'); do' \ ' for i in $(seq 0 '${__procs}'); do' \
' iperf3 -c '${__dest}' -p '${__port} \ ' iperf3 -c '${__dest}' -p '${__port} \
@ -49,8 +51,7 @@ test_iperf3() {
' wait' \ ' wait' \
')' ')'
pane_status "${__cpane}" pane_or_context_wait "${__sctx}"
pane_status "${__spane}"
__jval=".end.sum_received.bits_per_second" __jval=".end.sum_received.bits_per_second"
for __opt in ${@}; do for __opt in ${@}; do
@ -58,14 +59,10 @@ test_iperf3() {
[ "${__opt}" = "-u" ] && __jval=".intervals[0].sum.bits_per_second" [ "${__opt}" = "-u" ] && __jval=".intervals[0].sum.bits_per_second"
done done
pane_run "${__spane}" \ __bw=$(pane_or_context_output "${__sctx}" \
'cat s*.json | jq -rMs "map('${__jval}') | add"' 'cat s*.json | jq -rMs "map('${__jval}') | add"')
pane_wait "${__spane}" pane_or_context_run "${__sctx}" \
__bw="$(pane_parse "${__spane}")"
pane_run "${__spane}" \
'for i in $(seq 0 '${__procs}'); do rm s${i}.json; done' 'for i in $(seq 0 '${__procs}'); do rm s${i}.json; done'
pane_status "${__spane}"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}" )" TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}" )"
} }
@ -122,155 +119,134 @@ test_one_line() {
TEST_ONE_perf_nok=0 TEST_ONE_perf_nok=0
;; ;;
"host") "host")
pane_run HOST "${__arg}" pane_or_context_run host "${__arg}" || TEST_ONE_nok=1
pane_status HOST || TEST_ONE_nok=1
;; ;;
"hostb") "hostb")
pane_run HOST "${__arg}" pane_or_context_run_bg host "${__arg}"
;; ;;
"hostw") "hostw")
pane_status HOST || TEST_ONE_nok=1 pane_or_context_wait host || TEST_ONE_nok=1
;; ;;
"hint") "hint")
tmux send-keys -t ${PANE_HOST} "C-c" tmux send-keys -t ${PANE_HOST} "C-c"
;; ;;
"htools") "htools")
pane_run HOST 'which '"${__arg}"' >/dev/null' pane_or_context_run host 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
pane_status HOST || TEST_ONE_skip=1
;; ;;
"passt") "passt")
pane_run PASST "${__arg}" pane_or_context_run passt "${__arg}" || TEST_ONE_nok=1
pane_status PASST || TEST_ONE_nok=1
;; ;;
"passtb") "passtb")
pane_run PASST "${__arg}" pane_or_context_run_bg passt "${__arg}"
;; ;;
"passtw") "passtw")
pane_status PASST || TEST_ONE_nok=1 pane_or_context_wait passt || TEST_ONE_nok=1
;; ;;
"pout") "pout")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run PASST "${__arg#* }" __output="$(pane_or_context_output passt "${__arg#* }")"
pane_wait PASST TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse PASST)")"
;; ;;
"guest") "guest")
pane_run GUEST "${__arg}" pane_or_context_run guest "${__arg}" || TEST_ONE_nok=1
pane_status GUEST || TEST_ONE_nok=1
;; ;;
"guestb") "guestb")
pane_run GUEST "${__arg}" pane_or_context_run_bg guest "${__arg}"
;; ;;
"guestw") "guestw")
pane_status GUEST || TEST_ONE_nok=1 pane_or_context_wait guest || TEST_ONE_nok=1
;; ;;
"guest1") "guest1")
pane_run GUEST_1 "${__arg}" pane_or_context_run guest_1 "${__arg}" || TEST_ONE_nok=1
pane_status GUEST_1 || TEST_ONE_nok=1
;; ;;
"guest1b") "guest1b")
pane_run GUEST_1 "${__arg}" pane_or_context_run_bg guest_1 "${__arg}"
;; ;;
"guest1w") "guest1w")
pane_status GUEST_1 || TEST_ONE_nok=1 pane_or_context_wait guest_1 || TEST_ONE_nok=1
;; ;;
"gtools") "gtools")
pane_run GUEST 'which '"${__arg}"' >/dev/null' pane_or_context_run guest 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
pane_status GUEST || TEST_ONE_skip=1
;; ;;
"g1tools") "g1tools")
pane_run GUEST_1 'which '"${__arg}"' >/dev/null' pane_or_context_run guest_1 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
pane_status GUEST_1 || TEST_ONE_skip=1
;; ;;
"g2tools") "g2tools")
pane_run GUEST_2 'which '"${__arg}"' >/dev/null' pane_or_context_run guest_2 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
pane_status GUEST_2 || TEST_ONE_skip=1
;; ;;
"guest2") "guest2")
pane_run GUEST_2 "${__arg}" pane_or_context_run guest_2 "${__arg}" || TEST_ONE_nok=1
pane_status GUEST_2 || TEST_ONE_nok=1
;; ;;
"guest2b") "guest2b")
pane_run GUEST_2 "${__arg}" pane_or_context_run_bg guest_2 "${__arg}"
;; ;;
"guest2w") "guest2w")
pane_status GUEST_2 || TEST_ONE_nok=1 pane_or_context_wait guest_2 || TEST_ONE_nok=1
;; ;;
"ns") "ns")
pane_run NS "${__arg}" pane_or_context_run ns "${__arg}" || TEST_ONE_nok=1
pane_status NS || TEST_ONE_nok=1
;; ;;
"ns1") "ns1")
pane_run NS1 "${__arg}" pane_or_context_run ns1 "${__arg}" || TEST_ONE_nok=1
pane_status NS1 || TEST_ONE_nok=1
;; ;;
"ns2") "ns2")
pane_run NS2 "${__arg}" pane_or_context_run ns2 "${__arg}" || TEST_ONE_nok=1
pane_status NS2 || TEST_ONE_nok=1
;; ;;
"nsb") "nsb")
pane_run NS "${__arg}" pane_or_context_run_bg ns "${__arg}"
;; ;;
"ns1b") "ns1b")
pane_run NS1 "${__arg}" pane_or_context_run_bg ns1 "${__arg}"
;; ;;
"ns2b") "ns2b")
pane_run NS2 "${__arg}" pane_or_context_run_bg ns2 "${__arg}"
;; ;;
"nsw") "nsw")
pane_status NS || TEST_ONE_nok=1 pane_or_context_wait ns || TEST_ONE_nok=1
;; ;;
"ns1w") "ns1w")
pane_status NS1 || TEST_ONE_nok=1 pane_or_context_wait ns1 || TEST_ONE_nok=1
;; ;;
"ns2w") "ns2w")
pane_status NS2 || TEST_ONE_nok=1 pane_or_context_wait ns2 || TEST_ONE_nok=1
;; ;;
"nstools") "nstools")
pane_run NS 'which '"${__arg}"' >/dev/null' pane_or_context_run ns 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
pane_status NS || TEST_ONE_skip=1
;; ;;
"gout") "gout")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run GUEST "${__arg#* }" __output="$(pane_or_context_output guest "${__arg#* }")"
pane_wait GUEST TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST)")"
;; ;;
"g1out") "g1out")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run GUEST_1 "${__arg#* }" __output="$(pane_or_context_output guest_1 "${__arg#* }")"
pane_wait GUEST_1 TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST_1)")"
;; ;;
"g2out") "g2out")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run GUEST_2 "${__arg#* }" __output="$(pane_or_context_output guest_2 "${__arg#* }")"
pane_wait GUEST_2 TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST_2)")"
;; ;;
"hout") "hout")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run HOST "${__arg#* }" __output="$(pane_or_context_output host "${__arg#* }")"
pane_wait HOST TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse HOST)")"
;; ;;
"nsout") "nsout")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run NS "${__arg#* }" __output="$(pane_or_context_output ns "${__arg#* }")"
pane_wait NS TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS)")"
;; ;;
"ns1out") "ns1out")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run NS1 "${__arg#* }" __output="$(pane_or_context_output ns1 "${__arg#* }")"
pane_wait NS1 TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS1)")"
;; ;;
"ns2out") "ns2out")
__varname="${__arg%% *}" __varname="${__arg%% *}"
pane_run NS2 "${__arg#* }" __output="$(pane_or_context_output ns2 "${__arg#* }")"
pane_wait NS2 TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS2)")"
;; ;;
"check") "check")
info_check "${__arg}" info_check "${__arg}"

View File

@ -39,6 +39,7 @@ COMMIT="$(git log --oneline --no-decorate -1)"
. lib/util . lib/util
. lib/setup . lib/setup
. lib/context
. lib/term . lib/term
. lib/perf_report . lib/perf_report
. lib/layout . lib/layout