From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 79EE15A026F for ; Thu, 23 Nov 2023 02:53:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1700704377; bh=HeMtXjDT3I/C/+yhYBI86Jqd7QNKOlZNRovSApi1M9U=; h=From:To:Cc:Subject:Date:From; b=Ng3p/Z2OCq94pDfZCkSlfMVR16rpYqCKeHb4U/07td356dEyiTdpSc7rgdCmx4L9E qT8XJJjCW5PapasHm5nJnzhYLb2YQor1kG7yF6/P677x2kAMaTpIzt8o/tIlTMkn1i ewJcHEZSMJ7oyXMZIWmWI7K43gIwF8ODNrVerlPk= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SbLjP5CMCz4x5n; Thu, 23 Nov 2023 12:52:57 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH] test: Make handling of shell prompts with escapes a little more reliable Date: Thu, 23 Nov 2023 12:52:53 +1100 Message-ID: <20231123015253.1692422-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 2WGNS4P3QG365QWYOOI4CDTQ5A352SV5 X-Message-ID-Hash: 2WGNS4P3QG365QWYOOI4CDTQ5A352SV5 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When using the old-style "pane" methods of executing commands during the tests, we need to scan the shell output for prompts in order to tell when commands have finished. This is inherently unreliable because commands could output things that look like prompts, and prompts might not look like we expect them to. The only way to really fix this is to use a better way of dispatching commands, like the newer "context" system. However, it's awkward to convert everything to "context" right at the moment, so we're still relying on some tests that do work most of the time. It is, however, particularly sensitive to fancy coloured prompts using escape sequences. Currently we try to handle this by stripping actual ESC characters with tr, then looking for some common variants. We can do a bit better: instead strip all escape sequences using sed before looking for our prompt. Or, at least, any one using [a-zA-Z] as the terminating character. Strictly speaking ANSI escapes can be terminated by any character in 0x40..0x7e, which isn't easily expressed in a regexp. This should capture all common ones, though. With this transformation we can simplify the list of patterns we then look for as a prompt, removing some redundant variants. Signed-off-by: David Gibson --- test/lib/term | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/lib/term b/test/lib/term index aa05bf1..262937e 100755 --- a/test/lib/term +++ b/test/lib/term @@ -203,11 +203,9 @@ pane_wait() { __done=0 while - __l="$(tail -1 ${LOGDIR}/pane_${__lc}.log | tr -d [:cntrl:])" + __l="$(tail -1 ${LOGDIR}/pane_${__lc}.log | sed 's/[[][^a-zA-Z]*[a-zA-Z]//g')" case ${__l} in - '$ ' | '# ' | '# # ' | *"$ " | *"# ") return ;; - *" #[m " | *" #[m [K" | *"]# ["*) return ;; - *' $ [6n' | *' # [6n' ) return ;; + *"$ " | *"# ") return ;; esac do sleep 0.1 || sleep 1; done } -- 2.42.0