public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH v2 04/11] test: Integration of old-style pane execution and new context execution
Date: Thu, 08 Sep 2022 11:49:13 +1000	[thread overview]
Message-ID: <20220908014920.1474597-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220908014920.1474597-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 12123 bytes --]

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(a)gibson.dropbear.id.au>
---
 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}"
 }
 
+# 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() {
 	[ -z "${STATUS_FILE}" ] && return
diff --git a/test/lib/test b/test/lib/test
index 5a6c01c..0d06afd 100755
--- a/test/lib/test
+++ b/test/lib/test
@@ -15,8 +15,8 @@
 
 # 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
@@ -24,14 +24,14 @@
 # $@:	Client options
 test_iperf3() {
 	__var="${1}"; shift
-	__cpane="$(echo "${1}" | tr [a-z] [A-Z])"; shift
-	__spane="$(echo "${1}" | tr [a-z] [A-Z])"; shift
+	__cctx="${1}"; shift
+	__sctx="${1}"; shift
 	__dest="${1}"; shift
 	__port="${1}"; shift
 	__procs="$((${1} - 1))"; shift
 	__time="${1}"; shift
 
-	pane_run "${__spane}" 						\
+	pane_or_context_run_bg "${__sctx}" 				\
 		 '('							\
 		 '	for i in $(seq 0 '${__procs}'); do'		\
 		 '		iperf3 -s1J -p'${__port}' -i'${__time}	\
@@ -40,7 +40,9 @@ test_iperf3() {
 		 '	wait'						\
 		 ')'
 
-	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}	\
@@ -49,8 +51,7 @@ test_iperf3() {
 		 '	wait'						\
 		 ')'
 
-	pane_status "${__cpane}"
-	pane_status "${__spane}"
+	pane_or_context_wait "${__sctx}"
 
 	__jval=".end.sum_received.bits_per_second"
 	for __opt in ${@}; do
@@ -58,14 +59,10 @@ test_iperf3() {
 		[ "${__opt}" = "-u" ] && __jval=".intervals[0].sum.bits_per_second"
 	done
 
-	pane_run "${__spane}"						\
-		 'cat s*.json | jq -rMs "map('${__jval}') | add"'
-	pane_wait "${__spane}"
-	__bw="$(pane_parse "${__spane}")"
-
-	pane_run "${__spane}"						\
+	__bw=$(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}"
 
 	TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}" )"
 }
@@ -122,155 +119,134 @@ test_one_line() {
 		TEST_ONE_perf_nok=0
 		;;
 	"host")
-		pane_run HOST "${__arg}"
-		pane_status HOST || TEST_ONE_nok=1
+		pane_or_context_run host "${__arg}" || TEST_ONE_nok=1
 		;;
 	"hostb")
-		pane_run HOST "${__arg}"
+		pane_or_context_run_bg host "${__arg}"
 		;;
 	"hostw")
-		pane_status HOST || TEST_ONE_nok=1
+		pane_or_context_wait host || TEST_ONE_nok=1
 		;;
 	"hint")
 		tmux send-keys -t ${PANE_HOST} "C-c"
 		;;
 	"htools")
-		pane_run HOST 'which '"${__arg}"' >/dev/null'
-		pane_status HOST || TEST_ONE_skip=1
+		pane_or_context_run host 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
 		;;
 	"passt")
-		pane_run PASST "${__arg}"
-		pane_status PASST || TEST_ONE_nok=1
+		pane_or_context_run passt "${__arg}" || TEST_ONE_nok=1
 		;;
 	"passtb")
-		pane_run PASST "${__arg}"
+		pane_or_context_run_bg passt "${__arg}"
 		;;
 	"passtw")
-		pane_status PASST || TEST_ONE_nok=1
+		pane_or_context_wait passt || TEST_ONE_nok=1
 		;;
 	"pout")
 		__varname="${__arg%% *}"
-		pane_run PASST "${__arg#* }"
-		pane_wait PASST
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse PASST)")"
+		__output="$(pane_or_context_output passt "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"guest")
-		pane_run GUEST "${__arg}"
-		pane_status GUEST || TEST_ONE_nok=1
+		pane_or_context_run guest "${__arg}" || TEST_ONE_nok=1
 		;;
 	"guestb")
-		pane_run GUEST "${__arg}"
+		pane_or_context_run_bg guest "${__arg}"
 		;;
 	"guestw")
-		pane_status GUEST || TEST_ONE_nok=1
+		pane_or_context_wait guest || TEST_ONE_nok=1
 		;;
 	"guest1")
-		pane_run GUEST_1 "${__arg}"
-		pane_status GUEST_1 || TEST_ONE_nok=1
+		pane_or_context_run guest_1 "${__arg}" || TEST_ONE_nok=1
 		;;
 	"guest1b")
-		pane_run GUEST_1 "${__arg}"
+		pane_or_context_run_bg guest_1 "${__arg}"
 		;;
 	"guest1w")
-		pane_status GUEST_1 || TEST_ONE_nok=1
+		pane_or_context_wait guest_1 || TEST_ONE_nok=1
 		;;
 	"gtools")
-		pane_run GUEST 'which '"${__arg}"' >/dev/null'
-		pane_status GUEST || TEST_ONE_skip=1
+		pane_or_context_run guest 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
 		;;
 	"g1tools")
-		pane_run GUEST_1 'which '"${__arg}"' >/dev/null'
-		pane_status GUEST_1 || TEST_ONE_skip=1
+		pane_or_context_run guest_1 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
 		;;
 	"g2tools")
-		pane_run GUEST_2 'which '"${__arg}"' >/dev/null'
-		pane_status GUEST_2 || TEST_ONE_skip=1
+		pane_or_context_run guest_2 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
 		;;
 	"guest2")
-		pane_run GUEST_2 "${__arg}"
-		pane_status GUEST_2 || TEST_ONE_nok=1
+		pane_or_context_run guest_2 "${__arg}" || TEST_ONE_nok=1
 		;;
 	"guest2b")
-		pane_run GUEST_2 "${__arg}"
+		pane_or_context_run_bg guest_2 "${__arg}"
 		;;
 	"guest2w")
-		pane_status GUEST_2 || TEST_ONE_nok=1
+		pane_or_context_wait guest_2 || TEST_ONE_nok=1
 		;;
 	"ns")
-		pane_run NS "${__arg}"
-		pane_status NS || TEST_ONE_nok=1
+		pane_or_context_run ns "${__arg}" || TEST_ONE_nok=1
 		;;
 	"ns1")
-		pane_run NS1 "${__arg}"
-		pane_status NS1 || TEST_ONE_nok=1
+		pane_or_context_run ns1 "${__arg}" || TEST_ONE_nok=1
 		;;
 	"ns2")
-		pane_run NS2 "${__arg}"
-		pane_status NS2 || TEST_ONE_nok=1
+		pane_or_context_run ns2 "${__arg}" || TEST_ONE_nok=1
 		;;
 	"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=1
+		pane_or_context_wait ns || TEST_ONE_nok=1
 		;;
 	"ns1w")
-		pane_status NS1 || TEST_ONE_nok=1
+		pane_or_context_wait ns1 || TEST_ONE_nok=1
 		;;
 	"ns2w")
-		pane_status NS2 || TEST_ONE_nok=1
+		pane_or_context_wait ns2 || TEST_ONE_nok=1
 		;;
 	"nstools")
-		pane_run NS 'which '"${__arg}"' >/dev/null'
-		pane_status NS || TEST_ONE_skip=1
+		pane_or_context_run ns 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
 		;;
 	"gout")
 		__varname="${__arg%% *}"
-		pane_run GUEST "${__arg#* }"
-		pane_wait GUEST
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST)")"
+		__output="$(pane_or_context_output guest "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"g1out")
 		__varname="${__arg%% *}"
-		pane_run GUEST_1 "${__arg#* }"
-		pane_wait GUEST_1
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST_1)")"
+		__output="$(pane_or_context_output guest_1 "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"g2out")
 		__varname="${__arg%% *}"
-		pane_run GUEST_2 "${__arg#* }"
-		pane_wait GUEST_2
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse GUEST_2)")"
+		__output="$(pane_or_context_output guest_2 "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"hout")
 		__varname="${__arg%% *}"
-		pane_run HOST "${__arg#* }"
-		pane_wait HOST
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse HOST)")"
+		__output="$(pane_or_context_output host "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"nsout")
 		__varname="${__arg%% *}"
-		pane_run NS "${__arg#* }"
-		pane_wait NS
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS)")"
+		__output="$(pane_or_context_output ns "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"ns1out")
 		__varname="${__arg%% *}"
-		pane_run NS1 "${__arg#* }"
-		pane_wait NS1
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS1)")"
+		__output="$(pane_or_context_output ns1 "${__arg#* }")"
+		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
 		;;
 	"ns2out")
 		__varname="${__arg%% *}"
-		pane_run NS2 "${__arg#* }"
-		pane_wait NS2
-		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "$(pane_parse NS2)")"
+		__output="$(pane_or_context_output ns2 "${__arg#* }")"
+		TEST_ONE_subs="$(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="$(git log --oneline --no-decorate -1)"
 
 . lib/util
 . lib/setup
+. lib/context
 . lib/term
 . lib/perf_report
 . lib/layout
-- 
@@ -39,6 +39,7 @@ COMMIT="$(git log --oneline --no-decorate -1)"
 
 . lib/util
 . lib/setup
+. lib/context
 . lib/term
 . lib/perf_report
 . lib/layout
-- 
2.37.3


  parent reply	other threads:[~2022-09-08  1:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08  1:49 [PATCH v2 00/11] Improve command dispatch in test scripts David Gibson
2022-09-08  1:49 ` [PATCH v2 01/11] test: Correctly match "background" with "wait" commands David Gibson
2022-09-08  1:49 ` [PATCH v2 02/11] test: Context execution helpers David Gibson
2022-09-08  1:49 ` [PATCH v2 03/11] test: Allow a tmux pane to watch commands executed in contexts David Gibson
2022-09-09 15:18   ` Stefano Brivio
2022-09-10  6:36     ` David Gibson
2022-09-08  1:49 ` David Gibson [this message]
2022-09-08  1:49 ` [PATCH v2 05/11] test: Issue host commands via context for most tests David Gibson
2022-09-09 15:18   ` Stefano Brivio
2022-09-10  6:38     ` David Gibson
2022-09-08  1:49 ` [PATCH v2 06/11] test: Use new-style contexts for passt pane in the pasta and passt tests David Gibson
2022-09-08  1:49 ` [PATCH v2 07/11] test: Add nsholder utility David Gibson
2022-09-09 15:18   ` Stefano Brivio
2022-09-10  6:45     ` David Gibson
2022-09-08  1:49 ` [PATCH v2 08/11] test: Extend context system to run commands in namespace for pasta tests David Gibson
2022-09-08  1:49 ` [PATCH v2 09/11] test: Use context system for guest commands David Gibson
2022-09-08  1:49 ` [PATCH v2 10/11] test: Use context system for two_guests tests David Gibson
2022-09-08  1:49 ` [PATCH v2 11/11] test: Use new-style command issue for passt_in_ns tests David Gibson
2022-09-09 15:19   ` Stefano Brivio
2022-09-10  6:47     ` David Gibson
2022-09-10 20:40       ` Stefano Brivio
2022-09-09 15:21 ` [PATCH v2 00/11] Improve command dispatch in test scripts Stefano Brivio
2022-09-10  6:59   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220908014920.1474597-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).