Received: from eggs.gnu.org ([2001:4830:134:3::10]:44395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfSI5-0001LZ-S1 for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfSI3-00030k-AP for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:39877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfSI3-00030D-0f for qemu-devel@nongnu.org; Fri, 25 Sep 2015 08:39:51 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 25 Sep 2015 14:39:46 +0200 Message-Id: <1443184788-18859-6-git-send-email-afaerber@suse.de> In-Reply-To: <1443184788-18859-1-git-send-email-afaerber@suse.de> References: <1443184788-18859-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 5/7] tests: Add scsi-disk test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , Bruce Rogers , Lin Ma , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Test scsi-{disk,hd,cd} wwn properties for correct 64-bit parsing. For now piggyback on virtio-scsi. Cc: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- MAINTAINERS | 1 + tests/Makefile | 3 ++ tests/scsi-disk-test.c | 83 ++++++++++++++++++++++++++++++++++++++++++++= ++++++ 3 files changed, 87 insertions(+) create mode 100644 tests/scsi-disk-test.c diff --git a/MAINTAINERS b/MAINTAINERS index a941cfd..2078f7f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -688,6 +688,7 @@ M: Paolo Bonzini S: Supported F: include/hw/scsi* F: hw/scsi/* +F: tests/scsi-disk-test.c T: git git://github.com/bonzini/qemu.git scsi-next =20 LSI53C895A diff --git a/tests/Makefile b/tests/Makefile index 93116a2..e9cf3cc 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -106,6 +106,8 @@ check-qtest-virtio-y +=3D tests/virtio-rng-test$(EXES= UF) gcov-files-virtio-y +=3D hw/virtio/virtio-rng.c check-qtest-virtio-y +=3D tests/virtio-scsi-test$(EXESUF) gcov-files-virtio-y +=3D i386-softmmu/hw/scsi/virtio-scsi.c +check-qtest-virtio-y +=3D tests/scsi-disk-test$(EXESUF) +gcov-files-virtio-y +=3D i386-softmmu/hw/scsi/scsi-disk.c ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) check-qtest-virtio-y +=3D tests/virtio-9p-test$(EXESUF) gcov-files-virtio-y +=3D hw/9pfs/virtio-9p.c @@ -435,6 +437,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-= test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb= -obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu= -timer.o $(qtest-obj-y) +tests/scsi-disk-test$(EXESUF): tests/scsi-disk-test.o tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket= _scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test= -block-obj-y) diff --git a/tests/scsi-disk-test.c b/tests/scsi-disk-test.c new file mode 100644 index 0000000..618fec9 --- /dev/null +++ b/tests/scsi-disk-test.c @@ -0,0 +1,83 @@ +/* + * QTest testcase for SCSI disks + * See virtio-scsi-test for more integrated tests. + * + * Copyright (c) 2015 SUSE Linux GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include "libqtest.h" +#include "qemu/osdep.h" +#include "qapi/qmp/qint.h" + +static void test_scsi_disk_common(const char *type, const char *id) +{ + char *cmdline, *path; + QDict *response; + QInt *value; + + cmdline =3D g_strdup_printf( + "-drive id=3Ddrv0,if=3Dnone,file=3D/dev/null,format=3Draw " + "-device virtio-scsi-pci,id=3Dscsi0 " + "-device %s,id=3D%s,bus=3Dscsi0.0,drive=3Ddrv0" + ",wwn=3D0x%" PRIx64 ",port_wwn=3D0x%" PRIx64, + type, id, UINT64_MAX, UINT64_C(1) << 63); + qtest_start(cmdline); + g_free(cmdline); + + path =3D g_strdup_printf("/machine/peripheral/%s", id); + + response =3D qmp("{ 'execute': 'qom-get'," + " 'arguments': { 'path': %s," + " 'property': 'wwn' } }", + path); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + value =3D qobject_to_qint(qdict_get(response, "return")); + g_assert_cmpint(qint_get_int(value), =3D=3D, UINT64_MAX); + + response =3D qmp("{ 'execute': 'qom-get'," + " 'arguments': { 'path': %s," + " 'property': 'port_wwn' } }", + path); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + value =3D qobject_to_qint(qdict_get(response, "return")); + g_assert_cmpint(qint_get_int(value), =3D=3D, UINT64_C(1) << 63); + + g_free(path); + qtest_end(); +} + +static void test_scsi_disk(void) +{ + test_scsi_disk_common("scsi-disk", "disk0"); +} + +static void test_scsi_hd(void) +{ + test_scsi_disk_common("scsi-hd", "hd0"); +} + +static void test_scsi_cd(void) +{ + test_scsi_disk_common("scsi-cd", "cd0"); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + qtest_add_func("/scsi-disk/props", test_scsi_disk); + qtest_add_func("/scsi-hd/props", test_scsi_hd); + qtest_add_func("/scsi-cd/props", test_scsi_cd); + + ret =3D g_test_run(); + + return ret; +} --=20 2.1.4