aboutsummaryrefslogtreecommitdiff
path: root/python/qemu/machine.py
diff options
context:
space:
mode:
authorRobert Foley <robert.foley@linaro.org>2020-07-01 14:56:24 +0100
committerAlex Bennée <alex.bennee@linaro.org>2020-07-11 15:53:00 +0100
commit0fc8f660c5c0d7b4513805f4798e97e4c371e486 (patch)
tree6746a8c269a2fdae2d4a8a3dbcd46e0512c6a7cf /python/qemu/machine.py
parentdf00168039c8a58db3c33456db2c00da51043ee2 (diff)
downloadqemu-0fc8f660c5c0d7b4513805f4798e97e4c371e486.zip
qemu-0fc8f660c5c0d7b4513805f4798e97e4c371e486.tar.gz
qemu-0fc8f660c5c0d7b4513805f4798e97e4c371e486.tar.bz2
python/qemu: Add ConsoleSocket for optional use in QEMUMachine
We add the ConsoleSocket object, which has a socket interface and which will consume all arriving characters on the socket, placing them into an in memory buffer. This will also provide those chars via recv() as would a regular socket. ConsoleSocket also has the option of dumping the console bytes to a log file. We also give QEMUMachine the option of using ConsoleSocket to drain and to use for logging console to a file. By default QEMUMachine does not use ConsoleSocket. This is added in preparation for use by basevm.py in a later commit. This is a workaround we found was needed for basevm.py since there is a known issue where QEMU will hang waiting for console characters to be consumed. Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: Cleber Rosa <crosa@redhat.com> Signed-off-by: Robert Foley <robert.foley@linaro.org> Reviewed-by: Peter Puhov <peter.puhov@linaro.org> Acked-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200601211421.1277-9-robert.foley@linaro.org> Message-Id: <20200701135652.1366-13-alex.bennee@linaro.org>
Diffstat (limited to 'python/qemu/machine.py')
-rw-r--r--python/qemu/machine.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 041c615..c25f0b4 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -26,6 +26,7 @@ import socket
import tempfile
from typing import Optional, Type
from types import TracebackType
+from qemu.console_socket import ConsoleSocket
from . import qmp
@@ -75,7 +76,8 @@ class QEMUMachine:
def __init__(self, binary, args=None, wrapper=None, name=None,
test_dir="/var/tmp", monitor_address=None,
- socket_scm_helper=None, sock_dir=None):
+ socket_scm_helper=None, sock_dir=None,
+ drain_console=False, console_log=None):
'''
Initialize a QEMUMachine
@@ -86,6 +88,9 @@ class QEMUMachine:
@param test_dir: where to create socket and log file
@param monitor_address: address for QMP monitor
@param socket_scm_helper: helper program, required for send_fd_scm()
+ @param sock_dir: where to create socket (overrides test_dir for sock)
+ @param console_log: (optional) path to console log file
+ @param drain_console: (optional) True to drain console socket to buffer
@note: Qemu process is not started until launch() is used.
'''
if args is None:
@@ -122,6 +127,12 @@ class QEMUMachine:
self._console_address = None
self._console_socket = None
self._remove_files = []
+ self._console_log_path = console_log
+ if self._console_log_path:
+ # In order to log the console, buffering needs to be enabled.
+ self._drain_console = True
+ else:
+ self._drain_console = drain_console
def __enter__(self):
return self
@@ -580,7 +591,11 @@ class QEMUMachine:
Returns a socket connected to the console
"""
if self._console_socket is None:
- self._console_socket = socket.socket(socket.AF_UNIX,
- socket.SOCK_STREAM)
- self._console_socket.connect(self._console_address)
+ if self._drain_console:
+ self._console_socket = ConsoleSocket(self._console_address,
+ file=self._console_log_path)
+ else:
+ self._console_socket = socket.socket(socket.AF_UNIX,
+ socket.SOCK_STREAM)
+ self._console_socket.connect(self._console_address)
return self._console_socket