From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH 04/11] test: Integration of old-style pane execution and new context execution Date: Fri, 02 Sep 2022 12:14:53 +1000 Message-ID: <20220902021500.25358-5-david@gibson.dropbear.id.au> In-Reply-To: <20220902021500.25358-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6273276913953818359==" --===============6273276913953818359== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- test/lib/term | 63 +++++++++++++++++++++++ test/lib/test | 138 +++++++++++++++++++++----------------------------- test/run | 1 + 3 files changed, 121 insertions(+), 81 deletions(-) diff --git a/test/lib/term b/test/lib/term index fa34873..a06c80b 100755 --- a/test/lib/term +++ b/test/lib/term @@ -259,6 +259,69 @@ pane_watch_contexts() { cmd_write ${__pane_number} "${__cmd}" } =20 +# 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=3D"${1}" + shift + if context_exists "${__name}"; then + context_run "${__name}" "$@" >/dev/null 2>&1 + else + __uc=3D"$(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=3D"${1}" + shift + if context_exists "${__name}"; then + context_run_bg "${__name}" "$@" >/dev/null 2>&1 + else + __uc=3D"$(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=3D"${1}" + shift + if context_exists "${__name}"; then + __output=3D$(context_run "${__name}" "$@" 2>/dev/null) + if [ -z "${__output}" ]; then + echo "@EMPTY@" + else + echo "${__output}" + fi + else + __uc=3D"$(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=3D"${1}" + shift + if context_exists "${__name}"; then + context_wait "${__name}" + else + __uc=3D"$(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() { [ -z "${STATUS_FILE}" ] && return diff --git a/test/lib/test b/test/lib/test index d4357b7..15ad685 100755 --- a/test/lib/test +++ b/test/lib/test @@ -15,22 +15,22 @@ =20 # test_iperf3() - Ugly helper for iperf3 directive # $1: Variable name: to put the measure bandwidth into -# $2: Source/client pane name, can be lowercase -# $3: Destination/server pane name, can be lowercase +# $2: Source/client context +# $3: Destination/server context # $4: Destination name or address for client # $5: Port number, ${i} is translated to process index # $6: Number of processes to run in parallel # $@: Client options test_iperf3() { __var=3D"${1}"; shift - __cpane=3D"$(echo "${1}" | tr [a-z] [A-Z])"; shift - __spane=3D"$(echo "${1}" | tr [a-z] [A-Z])"; shift + __cctx=3D"${1}"; shift + __sctx=3D"${1}"; shift __dest=3D"${1}"; shift __port=3D"${1}"; shift __procs=3D"$((${1} - 1))"; shift __time=3D"${1}"; shift =20 - pane_run "${__spane}" \ + pane_or_context_run_bg "${__sctx}" \ '(' \ ' for i in $(seq 0 '${__procs}'); do' \ ' iperf3 -s1J -p'${__port}' -i'${__time} \ @@ -39,7 +39,9 @@ test_iperf3() { ' wait' \ ')' =20 - pane_run "${__cpane}" \ + sleep 1 # Wait for server to be ready + + pane_or_context_run "${__cctx}" \ '(' \ ' for i in $(seq 0 '${__procs}'); do' \ ' iperf3 -c '${__dest}' -p '${__port} \ @@ -48,8 +50,7 @@ test_iperf3() { ' wait' \ ')' =20 - pane_status "${__cpane}" - pane_status "${__spane}" + pane_or_context_wait "${__sctx}" =20 __jval=3D".end.sum_received.bits_per_second" for __opt in ${@}; do @@ -57,14 +58,10 @@ test_iperf3() { [ "${__opt}" =3D "-u" ] && __jval=3D".intervals[0].sum.bits_per_second" done =20 - pane_run "${__spane}" \ - 'cat s*.json | jq -rMs "map('${__jval}') | add"' - pane_wait "${__spane}" - __bw=3D"$(pane_parse "${__spane}")" - - pane_run "${__spane}" \ + __bw=3D$(pane_or_context_output "${__sctx}" \ + 'cat s*.json | jq -rMs "map('${__jval}') | add"') + pane_or_context_run "${__sctx}" \ 'for i in $(seq 0 '${__procs}'); do rm s${i}.json; done' - pane_status "${__spane}" =20 TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}= " )" } @@ -121,155 +118,134 @@ test_one_line() { TEST_ONE_perf_nok=3D0 ;; "host") - pane_run HOST "${__arg}" - pane_status HOST || TEST_ONE_nok=3D1 + pane_or_context_run host "${__arg}" || TEST_ONE_nok=3D1 ;; "hostb") - pane_run HOST "${__arg}" + pane_or_context_run_bg host "${__arg}" ;; "hostw") - pane_status HOST || TEST_ONE_nok=3D1 + pane_or_context_wait host || TEST_ONE_nok=3D1 ;; "hint") tmux send-keys -t ${PANE_HOST} "C-c" ;; "htools") - pane_run HOST 'which '"${__arg}"' >/dev/null' - pane_status HOST || TEST_ONE_skip=3D1 + pane_or_context_run host 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip= =3D1 ;; "passt") - pane_run PASST "${__arg}" - pane_status PASST || TEST_ONE_nok=3D1 + pane_or_context_run passt "${__arg}" || TEST_ONE_nok=3D1 ;; "passtb") - pane_run PASST "${__arg}" + pane_or_context_run_bg passt "${__arg}" ;; "passtw") - pane_status PASST || TEST_ONE_nok=3D1 + pane_or_context_wait passt || TEST_ONE_nok=3D1 ;; "pout") __varname=3D"${__arg%% *}" - pane_run PASST "${__arg#* }" - pane_wait PASST - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse PASST)")" + __output=3D"$(pane_or_context_output passt "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "guest") - pane_run GUEST "${__arg}" - pane_status GUEST || TEST_ONE_nok=3D1 + pane_or_context_run guest "${__arg}" || TEST_ONE_nok=3D1 ;; "guestb") - pane_run GUEST "${__arg}" + pane_or_context_run_bg guest "${__arg}" ;; "guestw") - pane_status GUEST || TEST_ONE_nok=3D1 + pane_or_context_wait guest || TEST_ONE_nok=3D1 ;; "guest1") - pane_run GUEST_1 "${__arg}" - pane_status GUEST_1 || TEST_ONE_nok=3D1 + pane_or_context_run guest_1 "${__arg}" || TEST_ONE_nok=3D1 ;; "guest1b") - pane_run GUEST_1 "${__arg}" + pane_or_context_run_bg guest_1 "${__arg}" ;; "guest1w") - pane_status GUEST_1 || TEST_ONE_nok=3D1 + pane_or_context_wait guest_1 || TEST_ONE_nok=3D1 ;; "gtools") - pane_run GUEST 'which '"${__arg}"' >/dev/null' - pane_status GUEST || TEST_ONE_skip=3D1 + pane_or_context_run guest 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip= =3D1 ;; "g1tools") - pane_run GUEST_1 'which '"${__arg}"' >/dev/null' - pane_status GUEST_1 || TEST_ONE_skip=3D1 + pane_or_context_run guest_1 'which '"${__arg}"' >/dev/null' || TEST_ONE_sk= ip=3D1 ;; "g2tools") - pane_run GUEST_2 'which '"${__arg}"' >/dev/null' - pane_status GUEST_2 || TEST_ONE_skip=3D1 + pane_or_context_run guest_2 'which '"${__arg}"' >/dev/null' || TEST_ONE_sk= ip=3D1 ;; "guest2") - pane_run GUEST_2 "${__arg}" - pane_status GUEST_2 || TEST_ONE_nok=3D1 + pane_or_context_run guest_2 "${__arg}" || TEST_ONE_nok=3D1 ;; "guest2b") - pane_run GUEST_2 "${__arg}" + pane_or_context_run_bg guest_2 "${__arg}" ;; "guest2w") - pane_status GUEST_2 || TEST_ONE_nok=3D1 + pane_or_context_wait guest_2 || TEST_ONE_nok=3D1 ;; "ns") - pane_run NS "${__arg}" - pane_status NS || TEST_ONE_nok=3D1 + pane_or_context_run ns "${__arg}" || TEST_ONE_nok=3D1 ;; "ns1") - pane_run NS1 "${__arg}" - pane_status NS1 || TEST_ONE_nok=3D1 + pane_or_context_run ns1 "${__arg}" || TEST_ONE_nok=3D1 ;; "ns2") - pane_run NS2 "${__arg}" - pane_status NS2 || TEST_ONE_nok=3D1 + pane_or_context_run ns2 "${__arg}" || TEST_ONE_nok=3D1 ;; "nsb") - pane_run NS "${__arg}" + pane_or_context_run_bg ns "${__arg}" ;; "ns1b") - pane_run NS1 "${__arg}" + pane_or_context_run_bg ns1 "${__arg}" ;; "ns2b") - pane_run NS2 "${__arg}" + pane_or_context_run_bg ns2 "${__arg}" ;; "nsw") - pane_status NS || TEST_ONE_nok=3D1 + pane_or_context_wait ns || TEST_ONE_nok=3D1 ;; "ns1w") - pane_status NS1 || TEST_ONE_nok=3D1 + pane_or_context_wait ns1 || TEST_ONE_nok=3D1 ;; "ns2w") - pane_status NS2 || TEST_ONE_nok=3D1 + pane_or_context_wait ns2 || TEST_ONE_nok=3D1 ;; "nstools") - pane_run NS 'which '"${__arg}"' >/dev/null' - pane_status NS || TEST_ONE_skip=3D1 + pane_or_context_run ns 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=3D1 ;; "gout") __varname=3D"${__arg%% *}" - pane_run GUEST "${__arg#* }" - pane_wait GUEST - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse GUEST)")" + __output=3D"$(pane_or_context_output guest "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "g1out") __varname=3D"${__arg%% *}" - pane_run GUEST_1 "${__arg#* }" - pane_wait GUEST_1 - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse GUEST_1)")" + __output=3D"$(pane_or_context_output guest_1 "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "g2out") __varname=3D"${__arg%% *}" - pane_run GUEST_2 "${__arg#* }" - pane_wait GUEST_2 - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse GUEST_2)")" + __output=3D"$(pane_or_context_output guest_2 "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "hout") __varname=3D"${__arg%% *}" - pane_run HOST "${__arg#* }" - pane_wait HOST - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse HOST)")" + __output=3D"$(pane_or_context_output host "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "nsout") __varname=3D"${__arg%% *}" - pane_run NS "${__arg#* }" - pane_wait NS - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse NS)")" + __output=3D"$(pane_or_context_output ns "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "ns1out") __varname=3D"${__arg%% *}" - pane_run NS1 "${__arg#* }" - pane_wait NS1 - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse NS1)")" + __output=3D"$(pane_or_context_output ns1 "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "ns2out") __varname=3D"${__arg%% *}" - pane_run NS2 "${__arg#* }" - pane_wait NS2 - TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(= pane_parse NS2)")" + __output=3D"$(pane_or_context_output ns2 "${__arg#* }")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${= __output}")" ;; "check") info_check "${__arg}" diff --git a/test/run b/test/run index aa9a380..0ec1334 100755 --- a/test/run +++ b/test/run @@ -39,6 +39,7 @@ COMMIT=3D"$(git log --oneline --no-decorate -1)" =20 . lib/util . lib/setup +. lib/context . lib/term . lib/perf_report . lib/layout --=20 2.37.2 --===============6273276913953818359==--