public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] test: Make handling of shell prompts with escapes a little more reliable
@ 2023-11-23  1:52 David Gibson
  2023-12-04  9:54 ` Stefano Brivio
  0 siblings, 1 reply; 4+ messages in thread
From: David Gibson @ 2023-11-23  1:52 UTC (permalink / raw)
  To: Stefano Brivio, passt-dev; +Cc: David Gibson

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 <david@gibson.dropbear.id.au>
---
 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
 }
-- 
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] test: Make handling of shell prompts with escapes a little more reliable
  2023-11-23  1:52 [PATCH] test: Make handling of shell prompts with escapes a little more reliable David Gibson
@ 2023-12-04  9:54 ` Stefano Brivio
  2023-12-07  1:09   ` David Gibson
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Brivio @ 2023-12-04  9:54 UTC (permalink / raw)
  To: David Gibson; +Cc: passt-dev

On Thu, 23 Nov 2023 12:52:53 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> 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 <david@gibson.dropbear.id.au>

I didn't forget about this one, but I had unrelated test failures which
I wasn't sure about. This is actually fine though. Applying soon.

-- 
Stefano


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] test: Make handling of shell prompts with escapes a little more reliable
  2023-12-04  9:54 ` Stefano Brivio
@ 2023-12-07  1:09   ` David Gibson
  2023-12-07  6:26     ` Stefano Brivio
  0 siblings, 1 reply; 4+ messages in thread
From: David Gibson @ 2023-12-07  1:09 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev

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

On Mon, Dec 04, 2023 at 10:54:33AM +0100, Stefano Brivio wrote:
> On Thu, 23 Nov 2023 12:52:53 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > 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 <david@gibson.dropbear.id.au>
> 
> I didn't forget about this one, but I had unrelated test failures which
> I wasn't sure about. This is actually fine though. Applying soon.

I don't think there's any particular need to make a release for it,
but it would be nice to get this in the main git tree, so I don't have
to keep awkwardly carrying it about to test my other branches.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] test: Make handling of shell prompts with escapes a little more reliable
  2023-12-07  1:09   ` David Gibson
@ 2023-12-07  6:26     ` Stefano Brivio
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2023-12-07  6:26 UTC (permalink / raw)
  To: David Gibson; +Cc: passt-dev

On Thu, 7 Dec 2023 12:09:26 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Dec 04, 2023 at 10:54:33AM +0100, Stefano Brivio wrote:
> > On Thu, 23 Nov 2023 12:52:53 +1100
> > David Gibson <david@gibson.dropbear.id.au> wrote:
> >   
> > > 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 <david@gibson.dropbear.id.au>  
> > 
> > I didn't forget about this one, but I had unrelated test failures which
> > I wasn't sure about. This is actually fine though. Applying soon.  
> 
> I don't think there's any particular need to make a release for it,
> but it would be nice to get this in the main git tree, so I don't have
> to keep awkwardly carrying it about to test my other branches.

Okay, merged just this one without re-testing.

-- 
Stefano


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-07  6:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23  1:52 [PATCH] test: Make handling of shell prompts with escapes a little more reliable David Gibson
2023-12-04  9:54 ` Stefano Brivio
2023-12-07  1:09   ` David Gibson
2023-12-07  6:26     ` Stefano Brivio

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).