summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/iotests.py
diff options
context:
space:
mode:
authorPeter Maydell2018-11-01 14:24:51 +0100
committerPeter Maydell2018-11-01 14:24:51 +0100
commit8ebf8ea90ecbbb2ef743dccfbfb73e2904cad1f5 (patch)
tree56a5de883941fd7bacf6c485225bedcbad5450f9 /tests/qemu-iotests/iotests.py
parentMerge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2018-10-29-2... (diff)
parentscripts/qemu.py: use a more consistent docstring style (diff)
downloadqemu-8ebf8ea90ecbbb2ef743dccfbfb73e2904cad1f5.tar.gz
qemu-8ebf8ea90ecbbb2ef743dccfbfb73e2904cad1f5.tar.xz
qemu-8ebf8ea90ecbbb2ef743dccfbfb73e2904cad1f5.zip
Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging
Python queue, 2018-10-30 * Makefile rule for running acceptance tests (make check-acceptance) (Cleber Rosa) * Make iotests compatible with Python 3 (Max Reitz) * device-crash-test whitelist update (Thomas Huth) * Misc cleanups (Cleber Rosa) # gpg: Signature made Wed 31 Oct 2018 00:28:39 GMT # gpg: using RSA key 2807936F984DC5A6 # gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" # Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6 * remotes/ehabkost/tags/python-next-pull-request: scripts/qemu.py: use a more consistent docstring style scripts/decodetree.py: fix reference to attributes Travis support for the acceptance tests Acceptance tests: add make rule for running them Bootstrap Python venv for tests iotests: Unify log outputs between Python 2 and 3 iotests: Modify imports for Python 3 iotests: 'new' module replacement in 169 iotests: Explicitly bequeath FDs in Python iotests: Different iterator behavior in Python 3 iotests: Use // for Python integer division iotests: Use Python byte strings where appropriate iotests: Flush in iotests.py's QemuIoInteractive iotests: Make nbd-fault-injector flush scripts/device-crash-test: Remove devices that are not user_creatable anymore Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/qemu-iotests/iotests.py')
-rw-r--r--tests/qemu-iotests/iotests.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 4e67fbbe96..27bb2b600c 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -29,6 +29,7 @@ import json
import signal
import logging
import atexit
+import io
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts'))
import qtest
@@ -104,7 +105,8 @@ def qemu_img_pipe(*args):
'''Run qemu-img and return its output'''
subp = subprocess.Popen(qemu_img_args + list(args),
stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ stderr=subprocess.STDOUT,
+ universal_newlines=True)
exitcode = subp.wait()
if exitcode < 0:
sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
@@ -128,7 +130,8 @@ def qemu_io(*args):
'''Run qemu-io and return the stdout data'''
args = qemu_io_args + list(args)
subp = subprocess.Popen(args, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ stderr=subprocess.STDOUT,
+ universal_newlines=True)
exitcode = subp.wait()
if exitcode < 0:
sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, ' '.join(args)))
@@ -149,7 +152,8 @@ class QemuIoInteractive:
self.args = qemu_io_args + list(args)
self._p = subprocess.Popen(self.args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ stderr=subprocess.STDOUT,
+ universal_newlines=True)
assert self._p.stdout.read(9) == 'qemu-io> '
def close(self):
@@ -178,6 +182,7 @@ class QemuIoInteractive:
cmd = cmd.strip()
assert cmd != 'q' and cmd != 'quit'
self._p.stdin.write(cmd + '\n')
+ self._p.stdin.flush()
return self._read_output()
@@ -192,10 +197,10 @@ def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):
def create_image(name, size):
'''Create a fully-allocated raw image with sector markers'''
- file = open(name, 'w')
+ file = open(name, 'wb')
i = 0
while i < size:
- sector = struct.pack('>l504xl', i / 512, i / 512)
+ sector = struct.pack('>l504xl', i // 512, i // 512)
file.write(sector)
i = i + 512
file.close()
@@ -249,7 +254,10 @@ def filter_img_info(output, filename):
def log(msg, filters=[]):
for flt in filters:
msg = flt(msg)
- print(msg)
+ if type(msg) is dict or type(msg) is list:
+ print(json.dumps(msg, sort_keys=True))
+ else:
+ print(msg)
class Timeout:
def __init__(self, seconds, errmsg = "Timeout"):
@@ -437,10 +445,11 @@ class VM(qtest.QEMUQtestMachine):
return result
def qmp_log(self, cmd, filters=[filter_testfiles], **kwargs):
- logmsg = "{'execute': '%s', 'arguments': %s}" % (cmd, kwargs)
+ logmsg = '{"execute": "%s", "arguments": %s}' % \
+ (cmd, json.dumps(kwargs, sort_keys=True))
log(logmsg, filters)
result = self.qmp(cmd, **kwargs)
- log(str(result), filters)
+ log(json.dumps(result, sort_keys=True), filters)
return result
def run_job(self, job, auto_finalize=True, auto_dismiss=False):
@@ -677,15 +686,19 @@ def main(supported_fmts=[], supported_oses=['linux'], supported_cache_modes=[],
verify_platform(supported_oses)
verify_cache_mode(supported_cache_modes)
- # We need to filter out the time taken from the output so that qemu-iotest
- # can reliably diff the results against master output.
- import StringIO
if debug:
output = sys.stdout
verbosity = 2
sys.argv.remove('-d')
else:
- output = StringIO.StringIO()
+ # We need to filter out the time taken from the output so that
+ # qemu-iotest can reliably diff the results against master output.
+ if sys.version_info.major >= 3:
+ output = io.StringIO()
+ else:
+ # io.StringIO is for unicode strings, which is not what
+ # 2.x's test runner emits.
+ output = io.BytesIO()
logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))