From nobody Mon Feb 9 20:30:29 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512662034798148.33252373092762; Thu, 7 Dec 2017 07:53:54 -0800 (PST) Received: from localhost ([::1]:32970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMyUX-000541-Er for importer@patchew.org; Thu, 07 Dec 2017 10:53:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMySW-0003bo-W3 for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMySU-0008BI-0z for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:36 -0500 Received: from [195.214.232.25] (port=27764 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMyST-00087I-JI for qemu-devel@nongnu.org; Thu, 07 Dec 2017 10:51:33 -0500 Received: from kvm.sw.ru ([195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vB7Fp3Zg005896; Thu, 7 Dec 2017 18:51:04 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 7 Dec 2017 18:51:01 +0300 Message-Id: <20171207155102.66622-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20171207155102.66622-1-vsementsov@virtuozzo.com> References: <20171207155102.66622-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v2 5/6] iotests: implement QemuIoInteractive class X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Eric Blake --- tests/qemu-iotests/iotests.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 6f057904a9..a9f312db83 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] =20 + +class QemuIoInteractive: + def __init__(self, *args): + self.args =3D qemu_io_args + list(args) + self._p =3D subprocess.Popen(self.args, stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT) + assert self._p.stdout.read(9) =3D=3D 'qemu-io> ' + + def close(self): + self._p.communicate('q\n') + + def _read_output(self): + pattern =3D 'qemu-io> ' + n =3D len(pattern) + pos =3D 0 + s =3D [] + while pos !=3D n: + c =3D self._p.stdout.read(1) + #check unexpected EOF + assert c !=3D '' + s.append(c) + if c =3D=3D pattern[pos]: + pos +=3D 1 + else: + pos =3D 0 + + return ''.join(s[:-n]) + + def cmd(self, cmd): + # quit command is in close(), '\n' is added automatically + assert '\n' not in cmd + cmd =3D cmd.strip() + assert cmd !=3D 'q' and cmd !=3D '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)) --=20 2.11.1