diff mbox series

[v1,2/6] tests/vm: add console_consume helper

Message ID 20191104173654.30125-3-alex.bennee@linaro.org (mailing list archive)
State New, archived
Headers show
Series testing/next (netbsd stuff) | expand

Commit Message

Alex Bennée Nov. 4, 2019, 5:36 p.m. UTC
From: Gerd Hoffmann <kraxel@redhat.com>

Helper function to read all console output.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <20191031085306.28888-3-kraxel@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/vm/basevm.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Philippe Mathieu-Daudé Nov. 4, 2019, 6:44 p.m. UTC | #1
On 11/4/19 6:36 PM, Alex Bennée wrote:
> From: Gerd Hoffmann <kraxel@redhat.com>
> 
> Helper function to read all console output.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Message-Id: <20191031085306.28888-3-kraxel@redhat.com>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   tests/vm/basevm.py | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
> 
> diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
> index 2929de23aa7..086bfb2c66d 100755
> --- a/tests/vm/basevm.py
> +++ b/tests/vm/basevm.py
> @@ -242,6 +242,25 @@ class BaseVM(object):
>               return False
>           return True
>   
> +    def console_consume(self):
> +        vm = self._guest
> +        output = ""
> +        vm.console_socket.setblocking(0)
> +        while True:
> +            try:
> +                chars = vm.console_socket.recv(1)
> +            except:
> +                break
> +            output += chars.decode("latin1")
> +            if "\r" in output or "\n" in output:
> +                lines = re.split("[\r\n]", output)
> +                output = lines.pop()
> +                if self.debug:
> +                    self.console_log("\n".join(lines))
> +        if self.debug:
> +            self.console_log(output)
> +        vm.console_socket.setblocking(1)
> +
>       def console_send(self, command):
>           vm = self._guest
>           if self.debug:
>
diff mbox series

Patch

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 2929de23aa7..086bfb2c66d 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -242,6 +242,25 @@  class BaseVM(object):
             return False
         return True
 
+    def console_consume(self):
+        vm = self._guest
+        output = ""
+        vm.console_socket.setblocking(0)
+        while True:
+            try:
+                chars = vm.console_socket.recv(1)
+            except:
+                break
+            output += chars.decode("latin1")
+            if "\r" in output or "\n" in output:
+                lines = re.split("[\r\n]", output)
+                output = lines.pop()
+                if self.debug:
+                    self.console_log("\n".join(lines))
+        if self.debug:
+            self.console_log(output)
+        vm.console_socket.setblocking(1)
+
     def console_send(self, command):
         vm = self._guest
         if self.debug: