From c2f248588b271f083c81f260c0818781e74e3c2d Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 12 Sep 2022 20:56:17 +1000 Subject: 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 --- test/lib/term | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/lib/term') 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 -- cgit v1.2.3