diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2018-01-26 17:29:14 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2018-01-26 17:29:14 +0000 |
| commit | 6233b4a8c2a32ef6955a921246fa08705bbb3676 (patch) | |
| tree | d8985aba7aa14f1c066f8e75b1d479cf833edacd /tests/qemu-iotests/iotests.py | |
| parent | e607bbee553cfe73072870cef458cfa4e78133e2 (diff) | |
| parent | 9776f0db6a19a0510e89b7aae38190b4811c95ba (diff) | |
| download | focaccia-qemu-6233b4a8c2a32ef6955a921246fa08705bbb3676.tar.gz focaccia-qemu-6233b4a8c2a32ef6955a921246fa08705bbb3676.zip | |
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-01-26' into staging
nbd patches for 2018-01-26 - Vladimir Sementsov-Ogievskiy - nbd export qmp interface - Eric Blake - hmp: Add nbd_server_remove to mirror QMP command - Edgar Kaziakhmedov - nbd: implement bdrv_get_info callback # gpg: Signature made Fri 26 Jan 2018 16:02:34 GMT # gpg: using RSA key 0xA7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" # gpg: aka "[jpeg image of size 6874]" # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * remotes/ericb/tags/pull-nbd-2018-01-26: nbd: implement bdrv_get_info callback hmp: Add nbd_server_remove to mirror QMP command iotest 205: new test for qmp nbd-server-remove iotests: implement QemuIoInteractive class iotest 147: add cases to test new @name parameter of nbd-server-add qapi: add nbd-server-remove hmp: Add name parameter to nbd_server_add qapi: add name parameter to nbd-server-add Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/qemu-iotests/iotests.py')
| -rw-r--r-- | tests/qemu-iotests/iotests.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 44477e9295..5a10b2d534 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -93,6 +93,44 @@ def qemu_io(*args): sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, ' '.join(args))) return subp.communicate()[0] + +class QemuIoInteractive: + def __init__(self, *args): + self.args = qemu_io_args + list(args) + self._p = subprocess.Popen(self.args, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + assert self._p.stdout.read(9) == 'qemu-io> ' + + def close(self): + self._p.communicate('q\n') + + def _read_output(self): + pattern = 'qemu-io> ' + n = len(pattern) + pos = 0 + s = [] + while pos != n: + c = self._p.stdout.read(1) + # check unexpected EOF + assert c != '' + s.append(c) + if c == pattern[pos]: + pos += 1 + else: + pos = 0 + + return ''.join(s[:-n]) + + def cmd(self, cmd): + # quit command is in close(), '\n' is added automatically + assert '\n' not in cmd + cmd = cmd.strip() + assert cmd != 'q' and cmd != 'quit' + self._p.stdin.write(cmd + '\n') + return self._read_output() + + def qemu_nbd(*args): '''Run qemu-nbd in daemon mode and return the parent's exit code''' return subprocess.call(qemu_nbd_args + ['--fork'] + list(args)) |