summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2015-02-24 12:59:13 +0000
committerPeter Maydell <peter.maydell@linaro.org>2015-02-24 12:59:14 +0000
commit3dc10613c313a042a111e46a977733411495ea8c (patch)
treeea992fe32d4272c169d7d9f1fd43c621a80aa2d5 /scripts
parent3dd2d1a33976a7ec4aa3a6a29e5183af53949237 (diff)
parentb9c649470ba0d4056b2d486105a0f8fb982654ae (diff)
downloadhqemu-3dc10613c313a042a111e46a977733411495ea8c.zip
hqemu-3dc10613c313a042a111e46a977733411495ea8c.tar.gz
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
Pull request v2: * Fix C11 typedef redefinitions in ahci and libqos malloc [Peter] * Fix lx -> PRIx64 format specifiers in ahci [Peter] # gpg: Signature made Mon Feb 16 15:45:53 2015 GMT using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" * remotes/stefanha/tags/block-pull-request: (65 commits) block: Keep bdrv_check*_request()'s return value block: Remove "growable" from BDS block: Clamp BlockBackend requests qemu-io: Use BlockBackend qemu-io: Remove "growable" option qemu-io: Use blk_new_open() in openfile() qemu-nbd: Use blk_new_open() in main() qemu-img: Use BlockBackend as far as possible qemu-img: Use blk_new_open() in img_rebase() qemu-img: Use blk_new_open() in img_open() block/xen: Use blk_new_open() in blk_connect() blockdev: Use blk_new_open() in blockdev_init() iotests: Add test for driver=qcow2, format=qcow2 block: Add Error parameter to bdrv_find_protocol() block: Add blk_new_open() block: Lift some BDS functions to the BlockBackend iotests: Add test for qemu-img convert to NBD qemu-img: Fix qemu-img convert -n qemu-iotests: Add 093 for IO throttling qemu-iotests: Allow caller to disable underscore convertion for qmp ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qtest.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/qtest.py b/scripts/qtest.py
new file mode 100644
index 0000000..a971445
--- /dev/null
+++ b/scripts/qtest.py
@@ -0,0 +1,71 @@
+# QEMU qtest library
+#
+# Copyright (C) 2015 Red Hat Inc.
+#
+# Authors:
+# Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+# Based on qmp.py.
+#
+
+import errno
+import socket
+
+class QEMUQtestProtocol(object):
+ def __init__(self, address, server=False):
+ """
+ Create a QEMUQtestProtocol object.
+
+ @param address: QEMU address, can be either a unix socket path (string)
+ or a tuple in the form ( address, port ) for a TCP
+ connection
+ @param server: server mode, listens on the socket (bool)
+ @raise socket.error on socket connection errors
+ @note No connection is established, this is done by the connect() or
+ accept() methods
+ """
+ self._address = address
+ self._sock = self._get_sock()
+ if server:
+ self._sock.bind(self._address)
+ self._sock.listen(1)
+
+ def _get_sock(self):
+ if isinstance(self._address, tuple):
+ family = socket.AF_INET
+ else:
+ family = socket.AF_UNIX
+ return socket.socket(family, socket.SOCK_STREAM)
+
+ def connect(self):
+ """
+ Connect to the qtest socket.
+
+ @raise socket.error on socket connection errors
+ """
+ self._sock.connect(self._address)
+
+ def accept(self):
+ """
+ Await connection from QEMU.
+
+ @raise socket.error on socket connection errors
+ """
+ self._sock, _ = self._sock.accept()
+
+ def cmd(self, qtest_cmd):
+ """
+ Send a qtest command on the wire.
+
+ @param qtest_cmd: qtest command text to be sent
+ """
+ self._sock.sendall(qtest_cmd + "\n")
+
+ def close(self):
+ self._sock.close()
+
+ def settimeout(self, timeout):
+ self._sock.settimeout(timeout)
OpenPOWER on IntegriCloud