From patchwork Fri Apr 13 14:27:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 152319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 21C97B6FF6 for ; Sat, 14 Apr 2012 00:29:03 +1000 (EST) Received: from localhost ([::1]:60841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIhUi-0006Ii-UE for incoming@patchwork.ozlabs.org; Fri, 13 Apr 2012 10:29:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIhUQ-0005ls-2s for qemu-devel@nongnu.org; Fri, 13 Apr 2012 10:28:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SIhUL-00073O-FO for qemu-devel@nongnu.org; Fri, 13 Apr 2012 10:28:41 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:37941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIhUL-00072q-6V for qemu-devel@nongnu.org; Fri, 13 Apr 2012 10:28:37 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Apr 2012 15:28:33 +0100 Received: from d06nrmr1407.portsmouth.uk.ibm.com (9.149.38.185) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 Apr 2012 15:28:01 +0100 Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3DES00Z2195658 for ; Fri, 13 Apr 2012 15:28:00 +0100 Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3DERxXi025121 for ; Fri, 13 Apr 2012 08:28:00 -0600 Received: from localhost (dyn-9-174-219-44.manchester-maybrook.uk.ibm.com [9.174.219.44]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3DERxUC025103; Fri, 13 Apr 2012 08:27:59 -0600 From: Stefan Hajnoczi To: Date: Fri, 13 Apr 2012 15:27:52 +0100 Message-Id: <1334327272-31278-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1334327272-31278-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1334327272-31278-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12041314-2966-0000-0000-000003C84CBD X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.109 Cc: Paolo Bonzini , Anthony Liguori , Stefan Hajnoczi , dmitry.fleytman@ravellosystems.com Subject: [Qemu-devel] [RFC PATCH 3/3] qtest: add virtio-test test-case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Stefan Hajnoczi --- tests/Makefile | 3 +- tests/virtio-test.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 tests/virtio-test.c diff --git a/tests/Makefile b/tests/Makefile index a98a848..fd0abf1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -18,7 +18,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. -check-qtest-i386-y = tests/rtc-test +check-qtest-i386-y = tests/rtc-test tests/virtio-test check-qtest-x86_64-y = $(check-qtest-i386-y) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h @@ -64,6 +64,7 @@ tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi- tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) +tests/virtio-test$(EXESUF): tests/virtio-test.o tests/libpci.o $(trace-obj-y) # QTest rules diff --git a/tests/virtio-test.c b/tests/virtio-test.c new file mode 100644 index 0000000..7ed564e --- /dev/null +++ b/tests/virtio-test.c @@ -0,0 +1,88 @@ +/* + * QTest testcase demo for virtio-pci devices + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include +#include +#include "bswap.h" +#include "libpci.h" +#include "hw/virtio-defs.h" +#include "hw/virtio-pci-defs.h" +#include "libqtest.h" + +enum { + /* Device address for this test */ + TEST_PCI_SLOT = 5, + TEST_PCI_FUNC = 0, + TEST_BAR0_IOADDR = 0x1000, +}; + +static void virtio_probe(void) +{ + PciDevice dev; + + if (!pci_probe(&dev, TEST_PCI_SLOT, TEST_PCI_FUNC)) { + g_test_message("Probe failed, no device present\n"); + return; + } + + /* "2.1 PCI Discovery" defines vendor/device IDs */ + g_assert_cmpint(pci_config_readw(&dev, PCI_VENDOR_ID), ==, 0x1af4); + g_assert_cmpint(pci_config_readw(&dev, PCI_DEVICE_ID), ==, 0x1002); + + /* "2.1 PCI Discovery" defines the revision ID */ + g_assert_cmpint(pci_config_readb(&dev, PCI_REVISION_ID), ==, 0); + + /* "2.1 PCI Discovery" defines the subsystem IDs */ + g_assert_cmpint(pci_config_readw(&dev, PCI_SUBSYSTEM_ID), ==, 5); + + pci_map_bar_io(&dev, PCI_BASE_ADDRESS_0, TEST_BAR0_IOADDR); + pci_enable(&dev); + + g_test_message("host features: %#x\n", + le32_to_cpu(inl(TEST_BAR0_IOADDR + VIRTIO_PCI_HOST_FEATURES))); + g_test_message("status: %#x\n", inb(TEST_BAR0_IOADDR + VIRTIO_PCI_STATUS)); + + outl(TEST_BAR0_IOADDR + VIRTIO_PCI_STATUS, + VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); +} + +int main(int argc, char **argv) +{ + const char *arch; + QTestState *s = NULL; + int ret; + + g_test_init(&argc, &argv, NULL); + + arch = qtest_get_arch(); + /* These tests only work on i386 and x86_64 */ + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + gchar *args = + g_strdup_printf("-vnc none -device virtio-balloon-pci,addr=%u.%u", + TEST_PCI_SLOT, TEST_PCI_FUNC); + s = qtest_start(args); + g_free(args); + + qtest_add_func("/virtio/probe", virtio_probe); + } else { + g_test_message("Skipping unsupported arch `%s'\n", arch); + } + + ret = g_test_run(); + + if (s) { + qtest_quit(s); + } + + return ret; +}