testsuite: Improve VM output check for login prompt

Message ID 20240304150403.13016-1-ubely@ilbers.de
State Accepted, archived
Headers show
Series testsuite: Improve VM output check for login prompt | expand

Commit Message

Uladzimir Bely March 4, 2024, 3:04 p.m. UTC
VM output is read by chunks and " login:" string is looked up in
the every chunk. This may fail in case this string is splitted by
two consecutive chunks.

Improve this by looking up in a bigger data buffer instead of
current chunk.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 testsuite/cibuilder.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Uladzimir Bely March 7, 2024, 7:21 a.m. UTC | #1
On Mon, 2024-03-04 at 16:04 +0100, Uladzimir Bely wrote:
> VM output is read by chunks and " login:" string is looked up in
> the every chunk. This may fail in case this string is splitted by
> two consecutive chunks.
> 
> Improve this by looking up in a bigger data buffer instead of
> current chunk.
> 
> Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> ---
>  testsuite/cibuilder.py | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 

Applied to next.

Patch

diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index 002a368b..fa30c2f5 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -487,17 +487,20 @@  BBPATH .= ":${LAYERDIR}"\
         poller.register(p1.stdout, select.POLLIN)
         poller.register(p1.stderr, select.POLLIN)
 
+        # Databuf of size enough to keep two data chunks + checked string
+        databuf = bytearray(b'')
+        databuf_size = 1024 * 2 + len(login_prompt)
+
         while time.time() < timeout and p1.poll() is None:
             events = poller.poll(1000 * (timeout - time.time()))
             for fd, event in events:
                 if event != select.POLLIN:
                     continue
                 if fd == p1.stdout.fileno():
-                    # Wait for the complete string if it is read in chunks
-                    # like "i", "sar", " login:"
-                    time.sleep(0.01)
                     data = os.read(fd, 1024)
-                    if login_prompt in data:
+                    shift = max(0, len(data) + len(databuf) - databuf_size)
+                    databuf = databuf[shift:] + bytearray(data)
+                    if login_prompt in databuf:
                         self.log.info('Got login prompt')
                         return 0
                 if fd == p1.stderr.fileno():