* what is the right way for an avocado test to do "wait for text that doesn't end in newline" ?
@ 2024-10-01 12:43 Peter Maydell
2024-10-01 16:21 ` Alex Bennée
2024-10-01 16:29 ` Daniel P. Berrangé
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2024-10-01 12:43 UTC (permalink / raw)
To: QEMU Developers
Cc: Thomas Huth, Cleber Rosa, Phil Mathieu-Daudé,
Wainer dos Santos Moschetta, John Snow
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.
What is the right way to do this common thing?
In tests/avocado at the moment we have:
tests/avocado/machine_aspeed.py:
self.wait_for_console_pattern("the last line before login:")
time.sleep(0.1)
exec_command(self, 'root')
time.sleep(0.1)
exec_command(self, "passw0rd")
This is flaky -- on my machine the test times out once in every
two or three iterations.
run_tuxtest_tests also tries the same sleep trick.
tests/functional/test_ppc64_hv.py:
wait_for_console_pattern(self, 'Welcome to Alpine Linux 3.18')
exec_command(self, 'root')
wait_for_console_pattern(self, 'localhost login:')
which sends the login username and *then* waits for the login prompt.
tests/avocado/boot_linux_console.py:
doesn't try to log in, just ends the test at login:
self.wait_for_console_pattern('gsj login:')
This test has been marked as "might timeout", which suggests this
isn't actually effective...
thanks
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: what is the right way for an avocado test to do "wait for text that doesn't end in newline" ?
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é
1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2024-10-01 16:21 UTC (permalink / raw)
To: Peter Maydell
Cc: QEMU Developers, Thomas Huth, Cleber Rosa,
Phil Mathieu-Daudé, Wainer dos Santos Moschetta, John Snow
Peter Maydell <peter.maydell@linaro.org> writes:
> 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.
>
> What is the right way to do this common thing?
Well the easiest way (which I do on some of my test images) is to enable
autologin so you get a shell prompt at the start.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: what is the right way for an avocado test to do "wait for text that doesn't end in newline" ?
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é
1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2024-10-01 16:29 UTC (permalink / raw)
To: Peter Maydell
Cc: QEMU Developers, Thomas Huth, Cleber Rosa,
Phil Mathieu-Daudé, Wainer dos Santos Moschetta, John Snow
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 :|
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-01 16:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).