[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 2/4] tests/vm: add console_consume helper
From: |
Gerd Hoffmann |
Subject: |
[PATCH v6 2/4] tests/vm: add console_consume helper |
Date: |
Thu, 31 Oct 2019 09:53:04 +0100 |
Helper function to read all console output.
Signed-off-by: Gerd Hoffmann <address@hidden>
---
tests/vm/basevm.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 2929de23aa..086bfb2c66 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:
--
2.18.1