From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
"Thomas Huth" <thuth@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Phil Mathieu-Daudé" <philmd@linaro.org>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"John Snow" <jsnow@redhat.com>
Subject: Re: what is the right way for an avocado test to do "wait for text that doesn't end in newline" ?
Date: Tue, 1 Oct 2024 17:29:36 +0100 [thread overview]
Message-ID: <ZvwjcOJaX7ax3SEk@redhat.com> (raw)
In-Reply-To: <CAFEAcA8N8NoaPMKQN=_Ph1mmgE1DEn=7kDOuOVMUX4zBEaBmug@mail.gmail.com>
On Tue, Oct 01, 2024 at 01:43:47PM +0100, Peter Maydell wrote:
> One common thing to want to do in an avocado test is log into
> the guest. The obvious way to do that would seem to be:
>
> self.wait_for_console_pattern('login:')
> exec_command(self, 'root')
> self.wait_for_console_pattern('Password:')
> exec_command(self, "passw0rd")
>
> This doesn't work; Thomas tells me that's because the
> wait_for_console_pattern function requires that the guest outputs
> a newline, but the 'login:' and 'Password:' prompt lines don't
> have a newline after them.
I presume the problem is ultimately this lne of code
which calls 'readline()'
try:
msg = console.readline().decode().strip()
except UnicodeDecodeError:
msg = None
if not msg:
continue
I would think we should change this to read a byte at
a time, trying the pattern match after each line until
it succeeeds.
It would have to gracefully handle unicode decode errors,
trying to get more bytes, instead of discarding the data,
because reading byte a time we might only have a partial
utf8 sequence. Or we could ensure that "console" is opened
with utf8 decoding by default instead of raw bytes.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
prev parent reply other threads:[~2024-10-01 16:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 12:43 what is the right way for an avocado test to do "wait for text that doesn't end in newline" ? Peter Maydell
2024-10-01 16:21 ` Alex Bennée
2024-10-01 16:29 ` Daniel P. Berrangé [this message]
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=ZvwjcOJaX7ax3SEk@redhat.com \
--to=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=jsnow@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
/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.
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 NNTP newsgroup(s).