[Buildroot] [git commit branch/2020.11.x] support/scripts/boot-qemu-image.py: properly catch timeout

Peter Korsgaard peter at korsgaard.com
Sat Feb 27 18:05:03 UTC 2021


commit: https://git.buildroot.net/buildroot/commit/?id=6bf41019fbce3d42d6857a81754ac7f7f43980e7
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/2020.11.x

As reported on IRC by sephthir, the gitlab test of the defconfig
qemu_sparc_ss10_defconfig doesn't error out while the system
is not working properly.

This is because we explicitly wait for the timeout as an expected
condition, but do not check for it. Indeed, pexpect.expect() returns
the index of the matching condition in the list of expected conditions,
but we just ignore the return code, so we are not able to differentiate
between a successful login (or prompt) from a timeout.

By default, pexepect.expect() raises the pexpect.TIMEOUT exception on a
timeout, and we are already prepared to catch and handle that exception.
But because pexpect.TIMEOUT is passed as an expected condition, the
exception is not raised.

Remove pexpect.TIMEOUT from the list of expected conditions, so that the
exception is properly raised again, and so that we can catch it.

The qemu_sparc_ss10_defconfig is already fixed by
4d16e6f5324f0285f51bfbb5a3503584f3b3ad12.

Signed-off-by: Romain Naour <romain.naour at gmail.com>
Cc: Jugurtha BELKALEM <jugurtha.belkalem at smile.fr>
[yann.morin.1998 at free.fr: reword commit log]
Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
(cherry picked from commit 03c3fbd81c51c7b0cc236362b3afc73e01219170)
Signed-off-by: Peter Korsgaard <peter at korsgaard.com>
---
 support/scripts/boot-qemu-image.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/support/scripts/boot-qemu-image.py b/support/scripts/boot-qemu-image.py
index dbbba552ad..9b7bfec990 100755
--- a/support/scripts/boot-qemu-image.py
+++ b/support/scripts/boot-qemu-image.py
@@ -32,7 +32,7 @@ def main():
     time.sleep(1)
 
     try:
-        child.expect(["buildroot login:", pexpect.TIMEOUT], timeout=60)
+        child.expect(["buildroot login:"], timeout=60)
     except pexpect.EOF as e:
         # Some emulations require a fork of qemu-system, which may be
         # missing on the system, and is not provided by Buildroot.
@@ -54,7 +54,7 @@ def main():
     child.sendline("root\r")
 
     try:
-        child.expect(["# ", pexpect.TIMEOUT], timeout=60)
+        child.expect(["# "], timeout=60)
     except pexpect.EOF:
         print("Cannot connect to shell")
         sys.exit(1)
@@ -65,7 +65,7 @@ def main():
     child.sendline("poweroff\r")
 
     try:
-        child.expect(["System halted", pexpect.TIMEOUT], timeout=60)
+        child.expect(["System halted"], timeout=60)
         child.expect(pexpect.EOF)
     except pexpect.EOF:
         pass


More information about the buildroot mailing list