aboutgitcodebugslistschat
path: root/test/lib/term
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-12 20:56:17 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-13 05:32:00 +0200
commitc2f248588b271f083c81f260c0818781e74e3c2d (patch)
treeedfc25b7b5c5194878b5914e0a3101525e1a42aa /test/lib/term
parenta32df9b6f4e997cb1565f90eaa721266790590ff (diff)
downloadpasst-c2f248588b271f083c81f260c0818781e74e3c2d.tar
passt-c2f248588b271f083c81f260c0818781e74e3c2d.tar.gz
passt-c2f248588b271f083c81f260c0818781e74e3c2d.tar.bz2
passt-c2f248588b271f083c81f260c0818781e74e3c2d.tar.lz
passt-c2f248588b271f083c81f260c0818781e74e3c2d.tar.xz
passt-c2f248588b271f083c81f260c0818781e74e3c2d.tar.zst
passt-c2f248588b271f083c81f260c0818781e74e3c2d.zip
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>
Diffstat (limited to 'test/lib/term')
-rwxr-xr-xtest/lib/term63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/lib/term b/test/lib/term
index 78700f5..fc229f1 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