From patchwork Thu Mar 7 17:29:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QwgOJiZV"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdHX4M7sz9sNB for ; Fri, 8 Mar 2019 04:42:16 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x26-0003Vu-EE for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:42:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqQ-0002hy-82 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqP-0007kj-6s for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:10 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:39166) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqO-0007jf-OM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:09 -0500 Received: by mail-wr1-x435.google.com with SMTP id l12so1947945wrp.6 for ; Thu, 07 Mar 2019 09:30:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9qsHMfj3SXqze2xdBVc6hsNmSf+AshL1Xh6WpZaMRNY=; b=QwgOJiZVGcHl3ns+8ojE6CurX/GYvF0N/Rmi9uQpzHiZeT4Je5iHkGT7oA2o20HKmL erk9Y+efQA1i1DbKwwpfHFUjpVIZh0T+cxkwz4/kxqjpw5dd2J1Z2CcFfamgiXWoWt9g vSRBfzm092T8iYSG0cSqoS4G/d5XWuRX84Ip8sYdDsTveFIJ2tmtgYZtWKfUpJiC03c/ XufvyP4Hi6ovnzPASMN+aG1UcGgV7XoAis8sidOHJdXlIrFWxx4vvJ2TdWaRLsNggPxe YmGO6TjwJsQNBSaFb9/wQ8JZ+/dNtT2K/OAuIzKqgUabNbsMWS1je/AEfMBpq/1HuD3a bquQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9qsHMfj3SXqze2xdBVc6hsNmSf+AshL1Xh6WpZaMRNY=; b=lqHD0TInmKcmpQxk1tkFzY/aJqnjLqprTrGVIlJcFPa4D0XGVDOUJl2U96QE5/Kwvc CfMSZ60QXcWvShlfE2zcvfUr0XPjjX8b20sSlEpcHt2z1ZvmNQUj5gSJ63jOEq1Fb8OV puOkTZ7Z9hgNkdfITzWVyuKICH4jOVxUUTUVshxX4WCD8kJWP8M9TuI/3CCr418mWBLs 68z/onSEXrc1ZnDQn8qZLlIpixy3lkzoHm70OXhSIgqhFSRYyL7N0hj5ra3guk/mbrYv buxCFuxFT57hplBIgWBxD6PSq8A6gSpzxOG21rv1ZbQwbOK5pNbZPtmOEVCIeh+VPbH/ ucwA== X-Gm-Message-State: APjAAAUIc0aByfbCXhx2G6DLtTr66JQS2zlpJTiCYO1vRSOjvXEPmskD rZJLOcyzMJXAoSNjgKKU2KPqzvoF X-Google-Smtp-Source: APXvYqxfOcUq03vGi+ibRSEeRT82N8L6OEi83pM94g8yQHCk688HB67PSlF5m30EIuTUaJPGT5lvkA== X-Received: by 2002:a5d:4145:: with SMTP id c5mr7586326wrq.256.1551979806693; Thu, 07 Mar 2019 09:30:06 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:08 +0100 Message-Id: <1551979804-6060-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::435 Subject: [Qemu-devel] [PULL 01/57] chardev-socket: do not blindly reset handlers when switching GMainContext 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If the socket is connecting or connected, tcp_chr_update_read_handler will be called but it should not set the NetListener's callbacks again. Otherwise, tcp_chr_accept is invoked while the socket is in connected state and you get an assertion failure. Reviewed-by: Daniel P. Berrangé Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- chardev/char-socket.c | 2 +- tests/test-char.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 4fcdd8a..6d287ba 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -632,7 +632,7 @@ static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); - if (s->listener) { + if (s->listener && s->state == TCP_CHARDEV_STATE_DISCONNECTED) { /* * It's possible that chardev context is changed in * qemu_chr_be_update_read_handlers(). Reset it for QIO net diff --git a/tests/test-char.c b/tests/test-char.c index 63b4d32..de32838 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -1003,6 +1003,103 @@ static void char_socket_client_test(gconstpointer opaque) g_free(optstr); } +static void +count_closed_event(void *opaque, int event) +{ + int *count = opaque; + if (event == CHR_EVENT_CLOSED) { + (*count)++; + } +} + +static void +char_socket_discard_read(void *opaque, const uint8_t *buf, int size) +{ +} + +static void char_socket_server_two_clients_test(gconstpointer opaque) +{ + SocketAddress *incoming_addr = (gpointer) opaque; + Chardev *chr; + CharBackend be = {0}; + QObject *qaddr; + SocketAddress *addr; + Visitor *v; + char *optstr; + QemuOpts *opts; + QIOChannelSocket *ioc1, *ioc2; + int closed = 0; + + g_setenv("QTEST_SILENT_ERRORS", "1", 1); + /* + * We rely on addr containing "nowait", otherwise + * qemu_chr_new() will block until a client connects. We + * can't spawn our client thread though, because until + * qemu_chr_new() returns we don't know what TCP port was + * allocated by the OS + */ + optstr = char_socket_addr_to_opt_str(incoming_addr, + false, + NULL, + true); + opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), + optstr, true); + g_assert_nonnull(opts); + chr = qemu_chr_new_from_opts(opts, NULL, &error_abort); + qemu_opts_del(opts); + g_assert_nonnull(chr); + g_assert(!object_property_get_bool(OBJECT(chr), "connected", &error_abort)); + + qaddr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort); + g_assert_nonnull(qaddr); + + v = qobject_input_visitor_new(qaddr); + visit_type_SocketAddress(v, "addr", &addr, &error_abort); + visit_free(v); + qobject_unref(qaddr); + + qemu_chr_fe_init(&be, chr, &error_abort); + + qemu_chr_fe_set_handlers(&be, char_socket_can_read, char_socket_discard_read, + count_closed_event, NULL, + &closed, NULL, true); + + ioc1 = qio_channel_socket_new(); + qio_channel_socket_connect_sync(ioc1, addr, &error_abort); + qemu_chr_wait_connected(chr, &error_abort); + + /* switch the chardev to another context */ + GMainContext *ctx = g_main_context_new(); + qemu_chr_fe_set_handlers(&be, char_socket_can_read, char_socket_discard_read, + count_closed_event, NULL, + &closed, ctx, true); + + /* Start a second connection while the first is still connected. + * It will be placed in the listen() backlog, and connect() will + * succeed immediately. + */ + ioc2 = qio_channel_socket_new(); + qio_channel_socket_connect_sync(ioc2, addr, &error_abort); + + object_unref(OBJECT(ioc1)); + /* The two connections should now be processed serially. */ + while (g_main_context_iteration(ctx, TRUE)) { + if (closed == 1 && ioc2) { + object_unref(OBJECT(ioc2)); + ioc2 = NULL; + } + if (closed == 2) { + break; + } + } + + qapi_free_SocketAddress(addr); + object_unparent(OBJECT(chr)); + g_main_context_unref(ctx); + g_free(optstr); + g_unsetenv("QTEST_SILENT_ERRORS"); +} + #ifdef HAVE_CHARDEV_SERIAL static void char_serial_test(void) @@ -1342,12 +1439,15 @@ int main(int argc, char **argv) SOCKET_SERVER_TEST(tcp, &tcpaddr); SOCKET_CLIENT_TEST(tcp, &tcpaddr); + g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr, + char_socket_server_two_clients_test); #ifndef WIN32 SOCKET_SERVER_TEST(unix, &unixaddr); SOCKET_CLIENT_TEST(unix, &unixaddr); + g_test_add_data_func("/char/socket/server/two-clients/unix", &unixaddr, + char_socket_server_two_clients_test); #endif - g_test_add_func("/char/udp", char_udp_test); #ifdef HAVE_CHARDEV_SERIAL g_test_add_func("/char/serial", char_serial_test); From patchwork Thu Mar 7 17:29:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RJlzG3xz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdRp6b4wz9s00 for ; Fri, 8 Mar 2019 04:49:26 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x92-0000tm-Mk for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:49:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqQ-0002jH-IQ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqP-0007lE-KH for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:10 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:53141) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqP-0007kI-Bb for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:09 -0500 Received: by mail-wm1-x329.google.com with SMTP id f65so10066460wma.2 for ; Thu, 07 Mar 2019 09:30:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+fpYfSN8S5YMvoOC7a+nbq24Fgg+Bb1zyXdRL9Ro974=; b=RJlzG3xzLml2yhGYKch6+qYPq8U1XFCu9Kh66HjE4CMMIX9CoGZCxFNaBA9nfmM/Fd UnnB73VRFBN4FeOCa56jXxALz5zuiVgV9rnkqfSSXR97vtHsYZ2aDAKL0H981XPaRgxt D0M2/Cv1Lh3Uc1VzkMo3f89ey2VOuKcFqHFeNmld5Yp8GxtJMP8AgdFuypACcJ2q/Ovv DCsTAL6utJ1vMMAGytakH1ltEaD6/rlf0ycEoq5Ewm9vi4JctSdrswcsccybs40m+m+P aDA92mZTeZlRoJjk4nQJQ5RJ5n67Mm2ZRfez6PnHQcxAWa3yegwdWRUyO7Dw+8y2CDDM D2Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+fpYfSN8S5YMvoOC7a+nbq24Fgg+Bb1zyXdRL9Ro974=; b=EtVw2klvtYUUWOz5+mXJrXVPPBq6T288cItiBQLJ7P5gmwxaDrTHf/OkTVzJOPUdmi 6xGAN5kXBJvZeaqPtW5MfX99sQyF3F9nkDDuiV3REG76Dv3G3Yrf27utNNJIEVPOcgWW BRRNtY+hFQZ1EMzr5fwI/u5iy/5v7+BgPNBQvN2r85rRPTGOPOPA+gzTM6vsoZMRsrKf zeYhbF4lDrpiUO/xpYa99/rG1AIRCeL+zMhLEj/txky3JNYRrD/IytlCmzIeIddXIZ/l jr1qS4XkrUqJ294lZrYlIUVO3IocbUctI3ZHToUau+bIQPOYdJP6I29drGfhgWdgLPNc Hs2g== X-Gm-Message-State: APjAAAWXSKxtLIyTTFlseQ+OPrcmxk0XWIAuTAgW1bXyhqLmwxTehBoT +QK6U0K06ov08lM8rF0gZGGBN5fB X-Google-Smtp-Source: APXvYqxWpjcjvwCPhQIqYQ+p3KBQA1xg+QGetJi55cmMke/KMYJPOyq3FnoejeBtosVq4OUtfaCoMQ== X-Received: by 2002:a1c:e2c2:: with SMTP id z185mr6245381wmg.84.1551979807727; Thu, 07 Mar 2019 09:30:07 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:09 +0100 Message-Id: <1551979804-6060-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 Subject: [Qemu-devel] [PULL 02/57] tests/libqos: introduce virtio_start_device 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito This function is intended to group all the qvirtio_* functions that start the qvirtio devices. Applied in all tests using this combination of functions. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Laurent Vivier Reviewed-by: Thomas Huth Signed-off-by: Paolo Bonzini --- tests/libqos/virtio.c | 7 +++++++ tests/libqos/virtio.h | 1 + tests/vhost-user-test.c | 4 +--- tests/virtio-9p-test.c | 4 +--- tests/virtio-blk-test.c | 9 ++------- tests/virtio-net-test.c | 4 +--- tests/virtio-scsi-test.c | 4 +--- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 0dad5c1..c1ff020 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -365,3 +365,10 @@ const char *qvirtio_get_dev_type(void) return "pci"; } } + +void qvirtio_start_device(QVirtioDevice *vdev) +{ + qvirtio_reset(vdev); + qvirtio_set_acknowledge(vdev); + qvirtio_set_driver(vdev); +} diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 69b5b13..2c68668 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -146,5 +146,6 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len); void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx); const char *qvirtio_get_dev_type(void); +void qvirtio_start_device(QVirtioDevice *vdev); #endif diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 4cd0a97..770e1e6 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -204,9 +204,7 @@ static void init_virtio_dev(QTestState *qts, TestServer *s, uint32_t features_ma g_assert_nonnull(s->dev); qvirtio_pci_device_enable(s->dev); - qvirtio_reset(&s->dev->vdev); - qvirtio_set_acknowledge(&s->dev->vdev); - qvirtio_set_driver(&s->dev->vdev); + qvirtio_start_device(&s->dev->vdev); s->alloc = pc_alloc_init(qts); diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index a2b3108..d275c74 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -65,9 +65,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void) v9p->dev = (QVirtioDevice *) dev; qvirtio_pci_device_enable(dev); - qvirtio_reset(v9p->dev); - qvirtio_set_acknowledge(v9p->dev); - qvirtio_set_driver(v9p->dev); + qvirtio_start_device(v9p->dev); v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 8d2fc9c..0680bd0 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -122,10 +122,7 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot) g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN)); qvirtio_pci_device_enable(dev); - qvirtio_reset(&dev->vdev); - qvirtio_set_acknowledge(&dev->vdev); - qvirtio_set_driver(&dev->vdev); - + qvirtio_start_device(&dev->vdev); return dev; } @@ -833,9 +830,7 @@ static void mmio_basic(void) g_assert(dev != NULL); g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); - qvirtio_reset(&dev->vdev); - qvirtio_set_acknowledge(&dev->vdev); - qvirtio_set_driver(&dev->vdev); + qvirtio_start_device(&dev->vdev); alloc = generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE); vq = qvirtqueue_setup(&dev->vdev, alloc, 0); diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index e9783e6..d4a32a4 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -44,9 +44,7 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET); qvirtio_pci_device_enable(dev); - qvirtio_reset(&dev->vdev); - qvirtio_set_acknowledge(&dev->vdev); - qvirtio_set_driver(&dev->vdev); + qvirtio_start_device(&dev->vdev); return dev; } diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 0d4f25d..961925c 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -159,9 +159,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI); qvirtio_pci_device_enable(dev); - qvirtio_reset(vs->dev); - qvirtio_set_acknowledge(vs->dev); - qvirtio_set_driver(vs->dev); + qvirtio_start_device(vs->dev); vs->num_queues = qvirtio_config_readl(vs->dev, 0); From patchwork Thu Mar 7 17:29:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L/VQaF3B"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdWb5W10z9s1B for ; Fri, 8 Mar 2019 04:52:43 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xCD-0003kf-Jt for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:52:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqS-0002ln-3k for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqQ-0007oP-KR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:12 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:40176) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqQ-0007lC-8z for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:10 -0500 Received: by mail-wm1-x344.google.com with SMTP id g20so9982133wmh.5 for ; Thu, 07 Mar 2019 09:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=/aneWvt80TmInYECf1xnPkchx/0HmGBT7HZv/bi5g2M=; b=L/VQaF3Bc5yTfwiKi8FubhUkfwQn9f1O1gX0amu7k0HP9TbRcc71/uyTxVMlDQkFMA 6jz703tzIYQEBnEcf/2nLqvUA+Fxwxa0is8szKiSTlauxAsWG31vfdjyzCUAWxAQhQUH 86l+VFpm8KB5psNMXpqhTpnTPyI+JuwrB1b0m8AMikD2ZXdZchS3fqLXvmEmU0RZ2LV5 DO5x1Sv3EiAUjfQ5r/ATdgOz0ZqqkUkHL1WbJAS4w+7DcSSZ14Bup3h9Q3GXl7/ULyb9 uj301C9EqdXsCSyMqT1c5SeGh6lQ6f15EmGxX7EGZz5SUan0Fw2rvbGCcpZ1TScKZ6US GrqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=/aneWvt80TmInYECf1xnPkchx/0HmGBT7HZv/bi5g2M=; b=ULBICYO/gEbNYZZuEbVTu069aSxRmtNPLBk0ZDtvLU6i2HMX47FCQTLliWTL6zZppg ZdUjIIlOwhwmeuVH+qi4Ls3GTHztAJNXD6vVcnlcpd/uk0JUIXQrG/s7FjwB+1nPBoHG 2o2x96W6Jy3vNnflr/kF8YwDi3zhShJp/HqhvbazTCB3zRY7I5/3cnP4vrjNo9PIbEka ERSf/W4Jx3T06JEui9golpOZEswo87L3tJ+mQBEF6LqCT/5is3G8twjn15gNQVgAxUuj +wQwsrtEYcuijR/Kkofux43RInQUGA7I7BZuSlc7+VReqjVUx4j/7zQbPiGY3XKBK2tj LqbQ== X-Gm-Message-State: APjAAAVgTxGf12LX9U3ymDqi1/meBBXYC61WYbdZCJ4oCHsYX5RmQwjr zr7GDZRLb1pg8T1tVgFElgXq5u78 X-Google-Smtp-Source: APXvYqy5EYZi+XJ4mSpqNS9HKJnqQIsml6T7R5zPtEOQBCb6aJ7WukLO0ss1jfEvYSDzpdtW7zlI3w== X-Received: by 2002:a05:600c:224c:: with SMTP id a12mr6317706wmm.103.1551979808795; Thu, 07 Mar 2019 09:30:08 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:10 +0100 Message-Id: <1551979804-6060-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 03/57] tests/libqos: rename qpci_init_pc and qpci_init_spapr functions 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Rename qpci_init_pc in qpci_pc_new and qpci_init_spapr in qpci_spapr_new, since these function actually allocate a new pci struct and initialize it (compare to object_new and object_initialize). Changed QOSOps field name from qpci_init to qpci_new. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Laurent Vivier Reviewed-by: Thomas Huth Signed-off-by: Paolo Bonzini --- tests/e1000e-test.c | 2 +- tests/i440fx-test.c | 2 +- tests/ide-test.c | 2 +- tests/libqos/ahci.c | 2 +- tests/libqos/libqos-pc.c | 2 +- tests/libqos/libqos-spapr.c | 2 +- tests/libqos/libqos.c | 2 +- tests/libqos/libqos.h | 2 +- tests/libqos/pci-pc.c | 2 +- tests/libqos/pci-pc.h | 12 +++++++++++- tests/libqos/pci-spapr.c | 2 +- tests/libqos/pci-spapr.h | 2 +- tests/q35-test.c | 4 ++-- tests/rtl8139-test.c | 2 +- tests/sdhci-test.c | 2 +- tests/tco-test.c | 2 +- tests/usb-hcd-ehci-test.c | 2 +- tests/vhost-user-test.c | 2 +- 18 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index c9408a5..5525589 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -395,7 +395,7 @@ static void data_test_init(e1000e_device *d) test_alloc = pc_alloc_init(global_qtest); g_assert_nonnull(test_alloc); - test_bus = qpci_init_pc(global_qtest, test_alloc); + test_bus = qpci_new_pc(global_qtest, test_alloc); g_assert_nonnull(test_bus); e1000e_device_init(test_bus, d); diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c index 4390e55..69205b5 100644 --- a/tests/i440fx-test.c +++ b/tests/i440fx-test.c @@ -38,7 +38,7 @@ static QPCIBus *test_start_get_bus(const TestData *s) cmdline = g_strdup_printf("-smp %d", s->num_cpus); qtest_start(cmdline); g_free(cmdline); - return qpci_init_pc(global_qtest, NULL); + return qpci_new_pc(global_qtest, NULL); } static void test_i440fx_defaults(gconstpointer opaque) diff --git a/tests/ide-test.c b/tests/ide-test.c index 300d64e..46898d9 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -157,7 +157,7 @@ static QPCIDevice *get_pci_device(QPCIBar *bmdma_bar, QPCIBar *ide_bar) uint16_t vendor_id, device_id; if (!pcibus) { - pcibus = qpci_init_pc(global_qtest, NULL); + pcibus = qpci_new_pc(global_qtest, NULL); } /* Find PCI device and verify it's the right one */ diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c index 63fbc9e..cc1b08e 100644 --- a/tests/libqos/ahci.c +++ b/tests/libqos/ahci.c @@ -130,7 +130,7 @@ QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint) uint32_t ahci_fingerprint; QPCIBus *pcibus; - pcibus = qpci_init_pc(qts, NULL); + pcibus = qpci_new_pc(qts, NULL); /* Find the AHCI PCI device and verify it's the right one. */ ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02)); diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c index a9c1ace..293f9b6 100644 --- a/tests/libqos/libqos-pc.c +++ b/tests/libqos/libqos-pc.c @@ -6,7 +6,7 @@ static QOSOps qos_ops = { .init_allocator = pc_alloc_init_flags, .uninit_allocator = pc_alloc_uninit, - .qpci_init = qpci_init_pc, + .qpci_new = qpci_new_pc, .qpci_free = qpci_free_pc, .shutdown = qtest_pc_shutdown, }; diff --git a/tests/libqos/libqos-spapr.c b/tests/libqos/libqos-spapr.c index a37791e..64addfe 100644 --- a/tests/libqos/libqos-spapr.c +++ b/tests/libqos/libqos-spapr.c @@ -6,7 +6,7 @@ static QOSOps qos_ops = { .init_allocator = spapr_alloc_init_flags, .uninit_allocator = spapr_alloc_uninit, - .qpci_init = qpci_init_spapr, + .qpci_new = qpci_new_spapr, .qpci_free = qpci_free_spapr, .shutdown = qtest_spapr_shutdown, }; diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index c514187..6c91371 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -25,7 +25,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) qs->ops = ops; if (ops) { qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); - qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); + qs->pcibus = ops->qpci_new(qs->qts, qs->alloc); } g_free(cmdline); diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 07d4b93..1af6035 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -10,7 +10,7 @@ typedef struct QOSState QOSState; typedef struct QOSOps { QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts); void (*uninit_allocator)(QGuestAllocator *); - QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc); + QPCIBus *(*qpci_new)(QTestState *qts, QGuestAllocator *alloc); void (*qpci_free)(QPCIBus *bus); void (*shutdown)(QOSState *); } QOSOps; diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index a4fc02b..43d7082 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -116,7 +116,7 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 qtest_outl(bus->qts, 0xcfc, value); } -QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) +QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc) { QPCIBusPC *ret = g_new0(QPCIBusPC, 1); diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h index 491eeac..5be68ba 100644 --- a/tests/libqos/pci-pc.h +++ b/tests/libqos/pci-pc.h @@ -16,7 +16,17 @@ #include "libqos/pci.h" #include "libqos/malloc.h" -QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc); +/* qpci_pc_new(): + * @qts: The %QTestState for this PC machine + * @alloc: A previously initialized @alloc providing memory for @qts + * + * This function creates a new QPCIBusPC object, + * and properly initialize its fields. + * + * Returns a newly allocated QPCIBus. + */ +QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc); + void qpci_free_pc(QPCIBus *bus); #endif diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c index 4c29889..59679f6 100644 --- a/tests/libqos/pci-spapr.c +++ b/tests/libqos/pci-spapr.c @@ -160,7 +160,7 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, #define SPAPR_PCI_MMIO32_WIN_SIZE 0x80000000 /* 2 GiB */ #define SPAPR_PCI_IO_WIN_SIZE 0x10000 -QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc) +QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc) { QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1); diff --git a/tests/libqos/pci-spapr.h b/tests/libqos/pci-spapr.h index 387686d..177e8c0 100644 --- a/tests/libqos/pci-spapr.h +++ b/tests/libqos/pci-spapr.h @@ -11,7 +11,7 @@ #include "libqos/malloc.h" #include "libqos/pci.h" -QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc); +QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc); void qpci_free_spapr(QPCIBus *bus); #endif diff --git a/tests/q35-test.c b/tests/q35-test.c index 7ea7acc..34b34bc 100644 --- a/tests/q35-test.c +++ b/tests/q35-test.c @@ -87,7 +87,7 @@ static void test_smram_lock(void) qtest_start("-M q35"); - pcibus = qpci_init_pc(global_qtest, NULL); + pcibus = qpci_new_pc(global_qtest, NULL); g_assert(pcibus != NULL); pcidev = qpci_device_find(pcibus, 0); @@ -146,7 +146,7 @@ static void test_tseg_size(const void *data) g_free(cmdline); /* locate the DRAM controller */ - pcibus = qpci_init_pc(global_qtest, NULL); + pcibus = qpci_new_pc(global_qtest, NULL); g_assert(pcibus != NULL); pcidev = qpci_device_find(pcibus, 0); g_assert(pcidev != NULL); diff --git a/tests/rtl8139-test.c b/tests/rtl8139-test.c index 68bfc42..a85c91f 100644 --- a/tests/rtl8139-test.c +++ b/tests/rtl8139-test.c @@ -35,7 +35,7 @@ static QPCIDevice *get_device(void) { QPCIDevice *dev; - pcibus = qpci_init_pc(global_qtest, NULL); + pcibus = qpci_new_pc(global_qtest, NULL); qpci_device_foreach(pcibus, 0x10ec, 0x8139, save_fn, &dev); g_assert(dev != NULL); diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c index 982f5eb..28d481b 100644 --- a/tests/sdhci-test.c +++ b/tests/sdhci-test.c @@ -187,7 +187,7 @@ static QSDHCI *machine_start(const struct sdhci_t *test) global_qtest = qtest_initf("-machine %s -device sdhci-pci", test->machine); - s->pci.bus = qpci_init_pc(global_qtest, NULL); + s->pci.bus = qpci_new_pc(global_qtest, NULL); /* Find PCI device and verify it's the right one */ s->pci.dev = qpci_device_find(s->pci.bus, QPCI_DEVFN(4, 0)); diff --git a/tests/tco-test.c b/tests/tco-test.c index 6bee9a3..f89a42c 100644 --- a/tests/tco-test.c +++ b/tests/tco-test.c @@ -64,7 +64,7 @@ static void test_init(TestData *d) global_qtest = qs; qtest_irq_intercept_in(qs, "ioapic"); - d->bus = qpci_init_pc(qs, NULL); + d->bus = qpci_new_pc(qs, NULL); d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00)); g_assert(d->dev != NULL); diff --git a/tests/usb-hcd-ehci-test.c b/tests/usb-hcd-ehci-test.c index f28ea27..8bc3e44 100644 --- a/tests/usb-hcd-ehci-test.c +++ b/tests/usb-hcd-ehci-test.c @@ -52,7 +52,7 @@ static void ehci_port_test(struct qhc *hc, int port, uint32_t expect) static void test_init(void) { - pcibus = qpci_init_pc(global_qtest, NULL); + pcibus = qpci_new_pc(global_qtest, NULL); g_assert(pcibus != NULL); qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4); diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 770e1e6..611d3a7 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -197,7 +197,7 @@ static void init_virtio_dev(QTestState *qts, TestServer *s, uint32_t features_ma uint32_t features; int i; - s->bus = qpci_init_pc(qts, NULL); + s->bus = qpci_new_pc(qts, NULL); g_assert_nonnull(s->bus); s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET); From patchwork Thu Mar 7 17:29:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PbxfdQSE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdLP0xhQz9sNF for ; Fri, 8 Mar 2019 04:44:45 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x4V-0005Xq-2v for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:44:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqV-0002r6-DR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqS-0007pz-3U for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:33356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqR-0007oy-Nl for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:12 -0500 Received: by mail-wm1-x329.google.com with SMTP id c13so7231159wmb.0 for ; Thu, 07 Mar 2019 09:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=p7WyB4FGFEbHxG6zKaVRMhCl6DOMfwNsjOYCApmR5Ao=; b=PbxfdQSEk+VWFkHGQe7SPYnszAQwalFQu/dQaZcAaMO3M6ux41Dxs+7eRD8a4AaOV6 3PtjTswRoTxOM5E6OIy6s42aEEZXZzioGTs4+RnBkYQoUWaGM4r0tn/HjenzVxUVtQg2 eZX6irGfgAlNhiwxMG3DTP1OQd1dHVh7fl1uC7zbMoo0QSSY9OO3nrkwV78s4GjkG0wV JVgi0i8ISN2WQfb8+GydsjvyPRaQTwXVivR7VtKMh5dEY9MXen7lB0RiApnjn0AAPC7V RfiLjckLj18Sj0MeyHZBpUETYoxs/H5ouk/AmkXcE///hTXuPwC76lWA+nt+8L5t90ax u8XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=p7WyB4FGFEbHxG6zKaVRMhCl6DOMfwNsjOYCApmR5Ao=; b=JUGPKjUQ3EJeeYxDD4m6eiKVNO3ccjTmvqLPZGY7WKlpjsqV222J5RJPrbGd8a/GGz qenZu6tzm74fI2+9XvMOnVuS/GBjlJ9SFVZruWjnSYwnuPCofXhc3GSoWN+Yy5VqS0Cl Lno3AGYm2lzJIHUfV2G6fFbzoh7Uqe9zTm4+IlMz22U5Nf/TUhBeJV54B5sN6LRK18uS yRhi7dU+8Wal2xI5A99UlOnYLP6X7YJhgnwnJfwE3/K9VG7MGIRAOgFZHwTuqq7lp10m 1aleyxYQG/sAR3+luDcioikuufhPu3DSDoSQBvKCFvGEx0Pu9deSGyfuDlVRefVk0T25 oTmw== X-Gm-Message-State: APjAAAUUu3l2NhwjSkDJ+7kOWanC5n4Bw7qC1BvktGI1rkt0CzY+YZRB bgNq5PtsOX6JH0EVGXWJ36ec52LZ X-Google-Smtp-Source: APXvYqwNDbzfwFM1iI/oenJlH/AqBvsIW11rplr+FB2KwTb4BWdJmGbBPrUuTaSbHGXT5NkEp7tmKg== X-Received: by 2002:a7b:c932:: with SMTP id h18mr6070037wml.12.1551979809873; Thu, 07 Mar 2019 09:30:09 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:11 +0100 Message-Id: <1551979804-6060-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 Subject: [Qemu-devel] [PULL 04/57] tests/libqos: embed allocators instead of malloc-ing them separately 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qgraph will embed these objects instead of allocating them in a separate object. Expose a new API "generic_alloc_init" and "generic_alloc_destroy" for that, and rename the existing API with s/init/new/ and s/uninit/free/. Signed-off-by: Paolo Bonzini --- tests/ahci-test.c | 6 ++-- tests/e1000e-test.c | 22 +++++++------- tests/ide-test.c | 17 +++++------ tests/libqos/libqos-pc.c | 3 +- tests/libqos/libqos-spapr.c | 3 +- tests/libqos/libqos.c | 13 ++++---- tests/libqos/libqos.h | 11 ++++--- tests/libqos/malloc-generic.c | 21 ++----------- tests/libqos/malloc-generic.h | 7 ++--- tests/libqos/malloc-pc.c | 18 ++--------- tests/libqos/malloc-pc.h | 4 +-- tests/libqos/malloc-spapr.c | 19 ++---------- tests/libqos/malloc-spapr.h | 4 +-- tests/libqos/malloc.c | 42 ++++---------------------- tests/libqos/malloc.h | 21 +++++++++---- tests/rtas-test.c | 2 +- tests/vhost-user-test.c | 10 +++---- tests/virtio-9p-test.c | 12 ++++---- tests/virtio-blk-test.c | 69 ++++++++++++++++++++++--------------------- tests/virtio-net-test.c | 10 +++---- tests/virtio-scsi-test.c | 14 ++++----- 21 files changed, 124 insertions(+), 204 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 5dd380e..9f07e6f 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -162,7 +162,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap) s = g_new0(AHCIQState, 1); s->parent = qtest_pc_vboot(cli, ap); global_qtest = s->parent->qts; - alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT); + alloc_set_flags(&s->parent->alloc, ALLOC_LEAK_ASSERT); /* Verify that we have an AHCI device present. */ s->dev = get_ahci_device(s->parent->qts, &s->fingerprint); @@ -1039,7 +1039,7 @@ static void test_dma_fragmented(void) generate_pattern(tx, bufsize, AHCI_SECTOR_SIZE); /* Create a DMA buffer in guest memory, and write our pattern to it. */ - ptr = guest_alloc(ahci->parent->alloc, bufsize); + ptr = guest_alloc(&ahci->parent->alloc, bufsize); g_assert(ptr); bufwrite(ptr, tx, bufsize); @@ -1059,7 +1059,7 @@ static void test_dma_fragmented(void) /* Read back the guest's receive buffer into local memory */ bufread(ptr, rx, bufsize); - guest_free(ahci->parent->alloc, ptr); + guest_free(&ahci->parent->alloc, ptr); g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0); diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index 5525589..17a12b8 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -94,7 +94,7 @@ typedef struct e1000e_device { } e1000e_device; static int test_sockets[2]; -static QGuestAllocator *test_alloc; +static QGuestAllocator test_alloc; static QPCIBus *test_bus; static void e1000e_pci_foreach_callback(QPCIDevice *dev, int devfn, void *data) @@ -165,7 +165,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_device *d) val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW); /* Allocate and setup TX ring */ - d->tx_ring = guest_alloc(test_alloc, E1000E_RING_LEN); + d->tx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN); g_assert(d->tx_ring != 0); e1000e_macreg_write(d, E1000E_TDBAL, (uint32_t) d->tx_ring); @@ -178,7 +178,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_device *d) e1000e_macreg_write(d, E1000E_TCTL, E1000E_TCTL_EN); /* Allocate and setup RX ring */ - d->rx_ring = guest_alloc(test_alloc, E1000E_RING_LEN); + d->rx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN); g_assert(d->rx_ring != 0); e1000e_macreg_write(d, E1000E_RDBAL, (uint32_t)d->rx_ring); @@ -268,7 +268,7 @@ static void e1000e_send_verify(e1000e_device *d) uint32_t recv_len; /* Prepare test data buffer */ - uint64_t data = guest_alloc(test_alloc, data_len); + uint64_t data = guest_alloc(&test_alloc, data_len); memwrite(data, "TEST", 5); /* Prepare TX descriptor */ @@ -296,7 +296,7 @@ static void e1000e_send_verify(e1000e_device *d) g_assert_cmpstr(buffer, == , "TEST"); /* Free test data buffer */ - guest_free(test_alloc, data); + guest_free(&test_alloc, data); } static void e1000e_receive_verify(e1000e_device *d) @@ -348,7 +348,7 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpint(ret, == , sizeof(test) + sizeof(len)); /* Prepare test data buffer */ - uint64_t data = guest_alloc(test_alloc, data_len); + uint64_t data = guest_alloc(&test_alloc, data_len); /* Prepare RX descriptor */ memset(&descr, 0, sizeof(descr)); @@ -369,7 +369,7 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpstr(buffer, == , "TEST"); /* Free test data buffer */ - guest_free(test_alloc, data); + guest_free(&test_alloc, data); } static void e1000e_device_clear(QPCIBus *bus, e1000e_device *d) @@ -392,10 +392,8 @@ static void data_test_init(e1000e_device *d) qtest_start(cmdline); g_free(cmdline); - test_alloc = pc_alloc_init(global_qtest); - g_assert_nonnull(test_alloc); - - test_bus = qpci_new_pc(global_qtest, test_alloc); + pc_alloc_init(&test_alloc, global_qtest, 0); + test_bus = qpci_new_pc(global_qtest, &test_alloc); g_assert_nonnull(test_bus); e1000e_device_init(test_bus, d); @@ -405,7 +403,7 @@ static void data_test_clear(e1000e_device *d) { e1000e_device_clear(test_bus, d); close(test_sockets[0]); - pc_alloc_uninit(test_alloc); + alloc_destroy(&test_alloc); g_free(d->pci_dev); qpci_free_pc(test_bus); qtest_end(); diff --git a/tests/ide-test.c b/tests/ide-test.c index 46898d9..d863a99 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -120,7 +120,7 @@ enum { #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0) static QPCIBus *pcibus = NULL; -static QGuestAllocator *guest_malloc; +static QGuestAllocator guest_malloc; static char tmp_path[] = "/tmp/qtest.XXXXXX"; static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX"; @@ -135,7 +135,7 @@ static void ide_test_start(const char *cmdline_fmt, ...) va_end(ap); qtest_start(cmdline); - guest_malloc = pc_alloc_init(global_qtest); + pc_alloc_init(&guest_malloc, global_qtest, 0); g_free(cmdline); } @@ -146,8 +146,7 @@ static void ide_test_quit(void) qpci_free_pc(pcibus); pcibus = NULL; } - pc_alloc_uninit(guest_malloc); - guest_malloc = NULL; + alloc_destroy(&guest_malloc); qtest_end(); } @@ -246,7 +245,7 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, /* Setup PRDT */ len = sizeof(*prdt) * prdt_entries; - guest_prdt = guest_alloc(guest_malloc, len); + guest_prdt = guest_alloc(&guest_malloc, len); memwrite(guest_prdt, prdt, len); qpci_io_writel(dev, bmdma_bar, bmreg_prdt, guest_prdt); @@ -311,7 +310,7 @@ static void test_bmdma_simple_rw(void) uint8_t *buf; uint8_t *cmpbuf; size_t len = 512; - uintptr_t guest_buf = guest_alloc(guest_malloc, len); + uintptr_t guest_buf = guest_alloc(&guest_malloc, len); PrdtEntry prdt[] = { { @@ -381,7 +380,7 @@ static void test_bmdma_trim(void) const uint64_t bad_range = trim_range_le(TEST_IMAGE_SIZE / 512 - 1, 2); size_t len = 512; uint8_t *buf; - uintptr_t guest_buf = guest_alloc(guest_malloc, len); + uintptr_t guest_buf = guest_alloc(&guest_malloc, len); PrdtEntry prdt[] = { { @@ -625,7 +624,7 @@ static void make_dirty(uint8_t device) dev = get_pci_device(&bmdma_bar, &ide_bar); - guest_buf = guest_alloc(guest_malloc, len); + guest_buf = guest_alloc(&guest_malloc, len); buf = g_malloc(len); memset(buf, rand() % 255 + 1, len); g_assert(guest_buf); @@ -986,7 +985,7 @@ static void test_cdrom_dma(void) "-device ide-cd,drive=sr0,bus=ide.0", tmp_path); qtest_irq_intercept_in(global_qtest, "ioapic"); - guest_buf = guest_alloc(guest_malloc, len); + guest_buf = guest_alloc(&guest_malloc, len); prdt[0].addr = cpu_to_le32(guest_buf); prdt[0].size = cpu_to_le32(len | PRDT_EOT); diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c index 293f9b6..d04abc5 100644 --- a/tests/libqos/libqos-pc.c +++ b/tests/libqos/libqos-pc.c @@ -4,8 +4,7 @@ #include "libqos/pci-pc.h" static QOSOps qos_ops = { - .init_allocator = pc_alloc_init_flags, - .uninit_allocator = pc_alloc_uninit, + .alloc_init = pc_alloc_init, .qpci_new = qpci_new_pc, .qpci_free = qpci_free_pc, .shutdown = qtest_pc_shutdown, diff --git a/tests/libqos/libqos-spapr.c b/tests/libqos/libqos-spapr.c index 64addfe..8766d54 100644 --- a/tests/libqos/libqos-spapr.c +++ b/tests/libqos/libqos-spapr.c @@ -4,8 +4,7 @@ #include "libqos/pci-spapr.h" static QOSOps qos_ops = { - .init_allocator = spapr_alloc_init_flags, - .uninit_allocator = spapr_alloc_uninit, + .alloc_init = spapr_alloc_init, .qpci_new = qpci_new_spapr, .qpci_free = qpci_free_spapr, .shutdown = qtest_spapr_shutdown, diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 6c91371..636a111 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -24,8 +24,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) qs->qts = qtest_init(cmdline); qs->ops = ops; if (ops) { - qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); - qs->pcibus = ops->qpci_new(qs->qts, qs->alloc); + ops->alloc_init(&qs->alloc, qs->qts, ALLOC_NO_FLAGS); + qs->pcibus = ops->qpci_new(qs->qts, &qs->alloc); } g_free(cmdline); @@ -58,11 +58,8 @@ void qtest_common_shutdown(QOSState *qs) qs->ops->qpci_free(qs->pcibus); qs->pcibus = NULL; } - if (qs->alloc && qs->ops->uninit_allocator) { - qs->ops->uninit_allocator(qs->alloc); - qs->alloc = NULL; - } } + alloc_destroy(&qs->alloc); qtest_quit(qs->qts); g_free(qs); } @@ -116,7 +113,7 @@ void migrate(QOSState *from, QOSState *to, const char *uri) /* If we were running, we can wait for an event. */ if (running) { - migrate_allocator(from->alloc, to->alloc); + migrate_allocator(&from->alloc, &to->alloc); set_context(to); qtest_qmp_eventwait(to->qts, "RESUME"); return; @@ -146,7 +143,7 @@ void migrate(QOSState *from, QOSState *to, const char *uri) g_assert_not_reached(); } - migrate_allocator(from->alloc, to->alloc); + migrate_allocator(&from->alloc, &to->alloc); set_context(to); } diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 1af6035..149b0be 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -3,13 +3,12 @@ #include "libqtest.h" #include "libqos/pci.h" -#include "libqos/malloc-pc.h" +#include "libqos/malloc.h" typedef struct QOSState QOSState; typedef struct QOSOps { - QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts); - void (*uninit_allocator)(QGuestAllocator *); + void (*alloc_init)(QGuestAllocator *, QTestState *, QAllocOpts); QPCIBus *(*qpci_new)(QTestState *qts, QGuestAllocator *alloc); void (*qpci_free)(QPCIBus *bus); void (*shutdown)(QOSState *); @@ -17,7 +16,7 @@ typedef struct QOSOps { struct QOSState { QTestState *qts; - QGuestAllocator *alloc; + QGuestAllocator alloc; QPCIBus *pcibus; QOSOps *ops; }; @@ -36,12 +35,12 @@ void generate_pattern(void *buffer, size_t len, size_t cycle_len); static inline uint64_t qmalloc(QOSState *q, size_t bytes) { - return guest_alloc(q->alloc, bytes); + return guest_alloc(&q->alloc, bytes); } static inline void qfree(QOSState *q, uint64_t addr) { - guest_free(q->alloc, addr); + guest_free(&q->alloc, addr); } #endif diff --git a/tests/libqos/malloc-generic.c b/tests/libqos/malloc-generic.c index 33ce90b..766a308 100644 --- a/tests/libqos/malloc-generic.c +++ b/tests/libqos/malloc-generic.c @@ -15,25 +15,10 @@ * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void generic_alloc_uninit(QGuestAllocator *allocator) +void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, + uint64_t size, uint32_t page_size) { - alloc_uninit(allocator); -} - -QGuestAllocator *generic_alloc_init_flags(uint64_t base_addr, uint64_t size, - uint32_t page_size, QAllocOpts flags) -{ - QGuestAllocator *s; uint64_t start = base_addr + (1 << 20); /* Start at 1MB */ - s = alloc_init_flags(flags, start, start + size); - alloc_set_page_size(s, page_size); - - return s; -} - -inline QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t size, - uint32_t page_size) -{ - return generic_alloc_init_flags(base_addr, size, page_size, ALLOC_NO_FLAGS); + alloc_init(s, 0, start, start + size, page_size); } diff --git a/tests/libqos/malloc-generic.h b/tests/libqos/malloc-generic.h index 90104ec..40ea058 100644 --- a/tests/libqos/malloc-generic.h +++ b/tests/libqos/malloc-generic.h @@ -12,10 +12,7 @@ #include "libqos/malloc.h" -QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t size, - uint32_t page_size); -QGuestAllocator *generic_alloc_init_flags(uint64_t base_addr, uint64_t size, - uint32_t page_size, QAllocOpts flags); -void generic_alloc_uninit(QGuestAllocator *allocator); +void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, uint64_t size, + uint32_t page_size); #endif diff --git a/tests/libqos/malloc-pc.c b/tests/libqos/malloc-pc.c index b83cb8f..9aff807 100644 --- a/tests/libqos/malloc-pc.c +++ b/tests/libqos/malloc-pc.c @@ -24,28 +24,14 @@ * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void pc_alloc_uninit(QGuestAllocator *allocator) +void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags) { - alloc_uninit(allocator); -} - -QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags) -{ - QGuestAllocator *s; uint64_t ram_size; QFWCFG *fw_cfg = pc_fw_cfg_init(qts); ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE); - s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000)); - alloc_set_page_size(s, PAGE_SIZE); + alloc_init(s, flags, 1 << 20, MIN(ram_size, 0xE0000000), PAGE_SIZE); /* clean-up */ g_free(fw_cfg); - - return s; -} - -inline QGuestAllocator *pc_alloc_init(QTestState *qts) -{ - return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS); } diff --git a/tests/libqos/malloc-pc.h b/tests/libqos/malloc-pc.h index 10f3da6..21e75ae 100644 --- a/tests/libqos/malloc-pc.h +++ b/tests/libqos/malloc-pc.h @@ -15,8 +15,6 @@ #include "libqos/malloc.h" -QGuestAllocator *pc_alloc_init(QTestState *qts); -QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags); -void pc_alloc_uninit(QGuestAllocator *allocator); +void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags); #endif diff --git a/tests/libqos/malloc-spapr.c b/tests/libqos/malloc-spapr.c index 1c359ce..2a6b7e3 100644 --- a/tests/libqos/malloc-spapr.c +++ b/tests/libqos/malloc-spapr.c @@ -17,22 +17,7 @@ */ #define SPAPR_MIN_SIZE 0x10000000 -void spapr_alloc_uninit(QGuestAllocator *allocator) +void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags) { - alloc_uninit(allocator); -} - -QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags) -{ - QGuestAllocator *s; - - s = alloc_init_flags(flags, 1 << 20, SPAPR_MIN_SIZE); - alloc_set_page_size(s, PAGE_SIZE); - - return s; -} - -QGuestAllocator *spapr_alloc_init(void) -{ - return spapr_alloc_init_flags(NULL, ALLOC_NO_FLAGS); + alloc_init(s, flags, 1 << 20, SPAPR_MIN_SIZE, PAGE_SIZE); } diff --git a/tests/libqos/malloc-spapr.h b/tests/libqos/malloc-spapr.h index 52a9346..e5fe9bf 100644 --- a/tests/libqos/malloc-spapr.h +++ b/tests/libqos/malloc-spapr.h @@ -10,8 +10,6 @@ #include "libqos/malloc.h" -QGuestAllocator *spapr_alloc_init(void); -QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags); -void spapr_alloc_uninit(QGuestAllocator *allocator); +void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags); #endif diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c index f7bae47..615422a 100644 --- a/tests/libqos/malloc.c +++ b/tests/libqos/malloc.c @@ -15,24 +15,12 @@ #include "qemu-common.h" #include "qemu/host-utils.h" -typedef QTAILQ_HEAD(MemList, MemBlock) MemList; - typedef struct MemBlock { QTAILQ_ENTRY(MemBlock) MLIST_ENTNAME; uint64_t size; uint64_t addr; } MemBlock; -struct QGuestAllocator { - QAllocOpts opts; - uint64_t start; - uint64_t end; - uint32_t page_size; - - MemList *used; - MemList *free; -}; - #define DEFAULT_PAGE_SIZE 4096 static void mlist_delete(MemList *list, MemBlock *node) @@ -225,7 +213,7 @@ static void mlist_free(QGuestAllocator *s, uint64_t addr) * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void alloc_uninit(QGuestAllocator *allocator) +void alloc_destroy(QGuestAllocator *allocator) { MemBlock *node; MemBlock *tmp; @@ -261,7 +249,6 @@ void alloc_uninit(QGuestAllocator *allocator) g_free(allocator->used); g_free(allocator->free); - g_free(allocator); } uint64_t guest_alloc(QGuestAllocator *allocator, size_t size) @@ -297,11 +284,13 @@ void guest_free(QGuestAllocator *allocator, uint64_t addr) } } -QGuestAllocator *alloc_init(uint64_t start, uint64_t end) +void alloc_init(QGuestAllocator *s, QAllocOpts opts, + uint64_t start, uint64_t end, + size_t page_size) { - QGuestAllocator *s = g_malloc0(sizeof(*s)); MemBlock *node; + s->opts = opts; s->start = start; s->end = end; @@ -313,26 +302,7 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end) node = mlist_new(s->start, s->end - s->start); QTAILQ_INSERT_HEAD(s->free, node, MLIST_ENTNAME); - s->page_size = DEFAULT_PAGE_SIZE; - - return s; -} - -QGuestAllocator *alloc_init_flags(QAllocOpts opts, - uint64_t start, uint64_t end) -{ - QGuestAllocator *s = alloc_init(start, end); - s->opts = opts; - return s; -} - -void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size) -{ - /* Can't alter the page_size for an allocator in-use */ - g_assert(QTAILQ_EMPTY(allocator->used)); - - g_assert(is_power_of_2(page_size)); - allocator->page_size = page_size; + s->page_size = page_size; } void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts) diff --git a/tests/libqos/malloc.h b/tests/libqos/malloc.h index 828fdda..4d1a2e2 100644 --- a/tests/libqos/malloc.h +++ b/tests/libqos/malloc.h @@ -23,19 +23,28 @@ typedef enum { ALLOC_PARANOID = 0x04 } QAllocOpts; -typedef struct QGuestAllocator QGuestAllocator; +typedef QTAILQ_HEAD(MemList, MemBlock) MemList; -void alloc_uninit(QGuestAllocator *allocator); +typedef struct QGuestAllocator { + QAllocOpts opts; + uint64_t start; + uint64_t end; + uint32_t page_size; + + MemList *used; + MemList *free; +} QGuestAllocator; /* Always returns page aligned values */ uint64_t guest_alloc(QGuestAllocator *allocator, size_t size); void guest_free(QGuestAllocator *allocator, uint64_t addr); void migrate_allocator(QGuestAllocator *src, QGuestAllocator *dst); -QGuestAllocator *alloc_init(uint64_t start, uint64_t end); -QGuestAllocator *alloc_init_flags(QAllocOpts flags, - uint64_t start, uint64_t end); -void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size); void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts); +void alloc_init(QGuestAllocator *alloc, QAllocOpts flags, + uint64_t start, uint64_t end, + size_t page_size); +void alloc_destroy(QGuestAllocator *allocator); + #endif diff --git a/tests/rtas-test.c b/tests/rtas-test.c index 009bda6..ee88867 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -17,7 +17,7 @@ static void test_rtas_get_time_of_day(void) global_qtest = qs->qts; t1 = time(NULL); - ret = qrtas_get_time_of_day(qs->qts, qs->alloc, &tm, &ns); + ret = qrtas_get_time_of_day(qs->qts, &qs->alloc, &tm, &ns); g_assert_cmpint(ret, ==, 0); t2 = mktimegm(&tm); g_assert(t2 - t1 < 5); /* 5 sec max to run the test */ diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 611d3a7..b1414e2 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -158,7 +158,7 @@ typedef struct TestServer { bool test_fail; int test_flags; int queues; - QGuestAllocator *alloc; + QGuestAllocator alloc; } TestServer; static TestServer *test_server_new(const gchar *name); @@ -206,10 +206,10 @@ static void init_virtio_dev(QTestState *qts, TestServer *s, uint32_t features_ma qvirtio_pci_device_enable(s->dev); qvirtio_start_device(&s->dev->vdev); - s->alloc = pc_alloc_init(qts); + pc_alloc_init(&s->alloc, qts, 0); for (i = 0; i < s->queues * 2; i++) { - s->vq[i] = qvirtqueue_setup(&s->dev->vdev, s->alloc, i); + s->vq[i] = qvirtqueue_setup(&s->dev->vdev, &s->alloc, i); } features = qvirtio_get_features(&s->dev->vdev); @@ -224,9 +224,9 @@ static void uninit_virtio_dev(TestServer *s) int i; for (i = 0; i < s->queues * 2; i++) { - qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], s->alloc); + qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], &s->alloc); } - pc_alloc_uninit(s->alloc); + alloc_destroy(&s->alloc); qvirtio_pci_device_free(s->dev); } diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index d275c74..8fd74f6 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -67,7 +67,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void) qvirtio_pci_device_enable(dev); qvirtio_start_device(v9p->dev); - v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0); + v9p->vq = qvirtqueue_setup(v9p->dev, &v9p->qs->alloc, 0); qvirtio_set_driver_ok(v9p->dev); @@ -76,7 +76,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void) static void qvirtio_9p_pci_stop(QVirtIO9P *v9p) { - qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->qs->alloc); + qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, &v9p->qs->alloc); qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev)); qvirtio_pci_device_free((QVirtioPCIDevice *)v9p->dev); qvirtio_9p_stop(v9p); @@ -222,7 +222,7 @@ static P9Req *v9fs_req_init(QVirtIO9P *v9p, uint32_t size, uint8_t id, req->v9p = v9p; req->t_size = total_size; - req->t_msg = guest_alloc(v9p->qs->alloc, req->t_size); + req->t_msg = guest_alloc(&v9p->qs->alloc, req->t_size); v9fs_memwrite(req, &hdr, 7); req->tag = tag; return req; @@ -232,7 +232,7 @@ static void v9fs_req_send(P9Req *req) { QVirtIO9P *v9p = req->v9p; - req->r_msg = guest_alloc(v9p->qs->alloc, P9_MAX_SIZE); + req->r_msg = guest_alloc(&v9p->qs->alloc, P9_MAX_SIZE); req->free_head = qvirtqueue_add(v9p->vq, req->t_msg, req->t_size, false, true); qvirtqueue_add(v9p->vq, req->r_msg, P9_MAX_SIZE, true, false); @@ -290,8 +290,8 @@ static void v9fs_req_free(P9Req *req) { QVirtIO9P *v9p = req->v9p; - guest_free(v9p->qs->alloc, req->t_msg); - guest_free(v9p->qs->alloc, req->r_msg); + guest_free(&v9p->qs->alloc, req->t_msg); + guest_free(&v9p->qs->alloc, req->r_msg); g_free(req); } diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0680bd0..b449970 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -15,6 +15,7 @@ #include "libqos/virtio.h" #include "libqos/virtio-pci.h" #include "libqos/virtio-mmio.h" +#include "libqos/malloc.h" #include "libqos/malloc-generic.h" #include "qapi/qmp/qdict.h" #include "qemu/bswap.h" @@ -403,12 +404,12 @@ static void pci_basic(void) qs = pci_test_start(); dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); + vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - test_basic(&dev->vdev, qs->alloc, &vqpci->vq); + test_basic(&dev->vdev, &qs->alloc, &vqpci->vq); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); qtest_shutdown(qs); @@ -442,7 +443,7 @@ static void pci_indirect(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); + vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); qvirtio_set_driver_ok(&dev->vdev); /* Write request */ @@ -452,11 +453,11 @@ static void pci_indirect(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); - indirect = qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2); + indirect = qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); @@ -468,7 +469,7 @@ static void pci_indirect(void) g_assert_cmpint(status, ==, 0); g_free(indirect); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -477,11 +478,11 @@ static void pci_indirect(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); - indirect = qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2); + indirect = qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); @@ -498,10 +499,10 @@ static void pci_indirect(void) g_free(data); g_free(indirect); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); qtest_shutdown(qs); @@ -556,7 +557,7 @@ static void pci_msix(void) dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); qpci_msix_enable(dev->pdev); - qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0); + qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); capacity = qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); @@ -568,8 +569,8 @@ static void pci_msix(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1); + vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); qvirtio_set_driver_ok(&dev->vdev); @@ -589,7 +590,7 @@ static void pci_msix(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); @@ -604,7 +605,7 @@ static void pci_msix(void) status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -612,7 +613,7 @@ static void pci_msix(void) req.sector = 0; req.data = g_malloc0(512); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); @@ -634,10 +635,10 @@ static void pci_msix(void) g_assert_cmpstr(data, ==, "TEST"); g_free(data); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); @@ -664,7 +665,7 @@ static void pci_idx(void) dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); qpci_msix_enable(dev->pdev); - qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0); + qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); capacity = qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); @@ -676,8 +677,8 @@ static void pci_idx(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1); + vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); qvirtio_set_driver_ok(&dev->vdev); @@ -688,7 +689,7 @@ static void pci_idx(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); @@ -707,7 +708,7 @@ static void pci_idx(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); @@ -725,7 +726,7 @@ static void pci_idx(void) QVIRTIO_BLK_TIMEOUT_US); g_assert_cmpint(status, ==, 0); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -733,7 +734,7 @@ static void pci_idx(void) req.sector = 1; req.data = g_malloc0(512); - req_addr = virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); g_free(req.data); @@ -757,10 +758,10 @@ static void pci_idx(void) g_assert_cmpstr(data, ==, "TEST"); g_free(data); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); @@ -820,7 +821,7 @@ static void mmio_basic(void) { QVirtioMMIODevice *dev; QVirtQueue *vq; - QGuestAllocator *alloc; + QGuestAllocator alloc; int n_size = TEST_IMAGE_SIZE / 2; uint64_t capacity; @@ -832,10 +833,10 @@ static void mmio_basic(void) qvirtio_start_device(&dev->vdev); - alloc = generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE); - vq = qvirtqueue_setup(&dev->vdev, alloc, 0); + generic_alloc_init(&alloc, MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE); + vq = qvirtqueue_setup(&dev->vdev, &alloc, 0); - test_basic(&dev->vdev, alloc, vq); + test_basic(&dev->vdev, &alloc, vq); qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " @@ -847,9 +848,9 @@ static void mmio_basic(void) g_assert_cmpint(capacity, ==, n_size / 512); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, vq, alloc); + qvirtqueue_cleanup(dev->vdev.bus, vq, &alloc); g_free(dev); - generic_alloc_uninit(alloc); + alloc_destroy(&alloc); test_end(); } diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index d4a32a4..653148e 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -228,16 +228,16 @@ static void pci_basic(gconstpointer data) "virtio-net-pci,netdev=hs0", sv[1]); dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT); - rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1); + rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 1); driver_init(&dev->vdev); - func(&dev->vdev, qs->alloc, &rx->vq, &tx->vq, sv[0]); + func(&dev->vdev, &qs->alloc, &rx->vq, &tx->vq, sv[0]); /* End test */ close(sv[0]); - qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc); - qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, &qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, &qs->alloc); qvirtio_pci_device_disable(dev); g_free(dev->pdev); g_free(dev); diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 961925c..9298aa8 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -62,7 +62,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) int i; for (i = 0; i < vs->num_queues + 2; i++) { - qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], vs->qs->alloc); + qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], &vs->qs->alloc); } qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev)); qvirtio_pci_device_free((QVirtioPCIDevice *)vs->dev); @@ -75,7 +75,7 @@ static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size, { uint64_t addr; - addr = guest_alloc(vs->qs->alloc, alloc_size); + addr = guest_alloc(&vs->qs->alloc, alloc_size); if (data) { memwrite(addr, data, alloc_size); } @@ -133,10 +133,10 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, memread(resp_addr, resp_out, sizeof(*resp_out)); } - guest_free(vs->qs->alloc, req_addr); - guest_free(vs->qs->alloc, resp_addr); - guest_free(vs->qs->alloc, data_in_addr); - guest_free(vs->qs->alloc, data_out_addr); + guest_free(&vs->qs->alloc, req_addr); + guest_free(&vs->qs->alloc, resp_addr); + guest_free(&vs->qs->alloc, data_in_addr); + guest_free(&vs->qs->alloc, data_out_addr); return response; } @@ -166,7 +166,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES); for (i = 0; i < vs->num_queues + 2; i++) { - vs->vq[i] = qvirtqueue_setup(vs->dev, vs->qs->alloc, i); + vs->vq[i] = qvirtqueue_setup(vs->dev, &vs->qs->alloc, i); } /* Clear the POWER ON OCCURRED unit attention */ From patchwork Thu Mar 7 17:29:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ssfM0nEu"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdkJ3Ykwz9s70 for ; Fri, 8 Mar 2019 05:02:00 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xLC-0003Vs-Ao for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:01:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqc-0002ya-8v for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqU-0007ry-EG for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:22 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:40971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqT-0007qw-QO for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:14 -0500 Received: by mail-wr1-x436.google.com with SMTP id n2so18405512wrw.8 for ; Thu, 07 Mar 2019 09:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7N+GbaPLbNEi2iD31sIi1+gkEdTBy+A2elsv51/MLHw=; b=ssfM0nEu66mOlT2e+27nub/FJyGvjtOv3vy4tyB9qoMo1Dr1ZiFS8kDAC1kvvmQC0n htmlvjHU1RbQ7apEX9bDM36Oj77GO1RCQmhkuf9VaGoo1Vqi+9cQYbuB0XEXfaiD9C2i QIdVLGsBujuKV3ezXpvskbthKxBKEcR6YLG5l5hYhKTYaZTM4T1eWBzw41rUpwjzgV+S lRqTZ2TN85Wp6O7izke8hVjNICJ4LOVFYsZ4lIMjCVnepeDT+Ybn0V4FG7tdHKVw3ftP JQMvkcuRwJ5ycXm3jJK/lw6DrMQSP1MHLFVpdC9mJG0g3IHLivlZSq8AFPDfe5wIAMwS zx4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7N+GbaPLbNEi2iD31sIi1+gkEdTBy+A2elsv51/MLHw=; b=HnqchpA49TrsHsJ7lS5MuuTJ0VvpJz2x673IRBHyD+o/+eXK7wYpMR4ul0tDMGqS2l c7OG6xDyYK7a1dqzzmEsm5x8+0g3FYi47sHDsKCLtj7vX/oRoQyMduZq7ibQ5Vug4lPn hMxvK5TUJfOZ6VLNC/+ssnIooHnYZ7pekjETmbLPFjhFB9BuZNTavkgBXCiic4oD2aLM RcvcAMghsjhgf0nhdOUVEZiJlVhuHz/avTQuR73IJBQb+npgJLFaXui0Rtipa0iFzWgE 1njTZ56xnPg+4XDxdxpe27sJRiQQbOcLtt/MbBbmmGID0wRZapCUWGUXZlEywhiG+8cb 2Kxw== X-Gm-Message-State: APjAAAUKNTU2zSVO0U8H9xClUY0QmIgIcK07Uf7937V0O55ONBJjrJhS H3PV45Dt/L0WzI4XqZ250Rk5aEB9 X-Google-Smtp-Source: APXvYqxrxrF+DY7ikVCvppE+Vm7mo2RRKHtg4lrFQcD0xayI+L87MXg8tCxj4FpkZk2jEOgxWgBWzw== X-Received: by 2002:adf:dd12:: with SMTP id a18mr7222260wrm.4.1551979810931; Thu, 07 Mar 2019 09:30:10 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:12 +0100 Message-Id: <1551979804-6060-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PULL 05/57] tests: qgraph API for the qtest driver framework 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph API that allows to add/remove nodes and edges from the graph, implementation of Depth First Search to discover the paths and basic unit test to check correctness of the API. Included also a main executable that takes care of starting the framework, create the nodes, set the available drivers/machines, discover the path and run tests. graph.h provides the public API to manage the graph nodes/edges graph_extra.h provides a more private API used successively by the gtest integration part qos-test.c provides the main executable Signed-off-by: Emanuele Giuseppe Esposito [Paolo's changes compared to the Google Summer of Code submission: * added subprocess to test options * refactored object creation to support live migration tests * removed driver .before callback (unused) * removed test .after callbacks (replaced by GTest destruction queue)] Signed-off-by: Paolo Bonzini --- configure | 2 +- include/qemu/module.h | 2 + tests/Makefile.include | 13 +- tests/libqos/qgraph.c | 753 +++++++++++++++++++++++++++++++++++++++++ tests/libqos/qgraph.h | 575 +++++++++++++++++++++++++++++++ tests/libqos/qgraph_internal.h | 257 ++++++++++++++ tests/libqtest.h | 3 + tests/qos-test.c | 445 ++++++++++++++++++++++++ tests/test-qgraph.c | 434 ++++++++++++++++++++++++ 9 files changed, 2481 insertions(+), 3 deletions(-) create mode 100644 tests/libqos/qgraph.c create mode 100644 tests/libqos/qgraph.h create mode 100644 tests/libqos/qgraph_internal.h create mode 100644 tests/qos-test.c create mode 100644 tests/test-qgraph.c diff --git a/configure b/configure index cefeb8f..f7b8c2e 100755 --- a/configure +++ b/configure @@ -7647,7 +7647,7 @@ fi # tests might fail. Prefer to keep the relevant files in their own # directory and symlink the directory instead. DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm" -DIRS="$DIRS tests/fp" +DIRS="$DIRS tests/fp tests/qgraph" DIRS="$DIRS docs docs/interop fsdev scsi" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" diff --git a/include/qemu/module.h b/include/qemu/module.h index 55dd2be..db30653 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -45,6 +45,7 @@ typedef enum { MODULE_INIT_QOM, MODULE_INIT_TRACE, MODULE_INIT_XEN_BACKEND, + MODULE_INIT_LIBQOS, MODULE_INIT_MAX } module_init_type; @@ -54,6 +55,7 @@ typedef enum { #define trace_init(function) module_init(function, MODULE_INIT_TRACE) #define xen_backend_init(function) module_init(function, \ MODULE_INIT_XEN_BACKEND) +#define libqos_init(function) module_init(function, MODULE_INIT_LIBQOS) #define block_module_load_one(lib) module_load_one("block-", lib) #define ui_module_load_one(lib) module_load_one("ui-", lib) diff --git a/tests/Makefile.include b/tests/Makefile.include index 97e1cb9..94ace7b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -732,7 +732,10 @@ tests/test-crypto-ivgen$(EXESUF): tests/test-crypto-ivgen.o $(test-crypto-obj-y) tests/test-crypto-afsplit$(EXESUF): tests/test-crypto-afsplit.o $(test-crypto-obj-y) tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o $(test-crypto-obj-y) -libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o +libqgraph-obj-y = tests/libqos/qgraph.o + +libqos-obj-y = $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg.o +libqos-obj-y += tests/libqos/malloc.o tests/libqos/malloc-generic.o libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o libqos-spapr-obj-y = $(libqos-obj-y) tests/libqos/malloc-spapr.o libqos-spapr-obj-y += tests/libqos/libqos-spapr.o @@ -744,7 +747,13 @@ libqos-pc-obj-y += tests/libqos/ahci.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o -libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o +libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o + +check-unit-y += tests/test-qgraph$(EXESUF) +tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) + +check-qtest-generic-y += tests/qos-test$(EXESUF) +tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y) tests/qmp-test$(EXESUF): tests/qmp-test.o tests/qmp-cmd-test$(EXESUF): tests/qmp-cmd-test.o diff --git a/tests/libqos/qgraph.c b/tests/libqos/qgraph.c new file mode 100644 index 0000000..122efc1 --- /dev/null +++ b/tests/libqos/qgraph.c @@ -0,0 +1,753 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu/queue.h" +#include "libqos/qgraph_internal.h" +#include "libqos/qgraph.h" + +#define QGRAPH_PRINT_DEBUG 0 +#define QOS_ROOT "" +typedef struct QOSStackElement QOSStackElement; + +/* Graph Edge.*/ +struct QOSGraphEdge { + QOSEdgeType type; + char *dest; + void *arg; /* just for QEDGE_CONTAINS + * and QEDGE_CONSUMED_BY */ + char *extra_device_opts; /* added to -device option, "," is + * automatically added + */ + char *before_cmd_line; /* added before node cmd_line */ + char *after_cmd_line; /* added after -device options */ + char *edge_name; /* used by QEDGE_CONTAINS */ + QSLIST_ENTRY(QOSGraphEdge) edge_list; +}; + +typedef QSLIST_HEAD(, QOSGraphEdge) QOSGraphEdgeList; + +/** + * Stack used to keep track of the discovered path when using + * the DFS algorithm + */ +struct QOSStackElement { + QOSGraphNode *node; + QOSStackElement *parent; + QOSGraphEdge *parent_edge; + int length; +}; + +/* Each enty in these hash table will consist of pair. */ +static GHashTable *edge_table; +static GHashTable *node_table; + +/* stack used by the DFS algorithm to store the path from machine to test */ +static QOSStackElement qos_node_stack[QOS_PATH_MAX_ELEMENT_SIZE]; +static int qos_node_tos; + +/** + * add_edge(): creates an edge of type @type + * from @source to @dest node, and inserts it in the + * edges hash table + * + * Nodes @source and @dest do not necessarily need to exist. + * Possibility to add also options (see #QOSGraphEdgeOptions) + * edge->edge_name is used as identifier for get_device relationships, + * so by default is equal to @dest. + */ +static void add_edge(const char *source, const char *dest, + QOSEdgeType type, QOSGraphEdgeOptions *opts) +{ + char *key; + QOSGraphEdgeList *list = g_hash_table_lookup(edge_table, source); + + if (!list) { + list = g_new0(QOSGraphEdgeList, 1); + key = g_strdup(source); + g_hash_table_insert(edge_table, key, list); + } + + if (!opts) { + opts = &(QOSGraphEdgeOptions) { }; + } + + QOSGraphEdge *edge = g_new0(QOSGraphEdge, 1); + edge->type = type; + edge->dest = g_strdup(dest); + edge->edge_name = g_strdup(opts->edge_name ?: dest); + edge->arg = g_memdup(opts->arg, opts->size_arg); + + edge->before_cmd_line = + opts->before_cmd_line ? g_strconcat(" ", opts->before_cmd_line, NULL) : NULL; + edge->extra_device_opts = + opts->extra_device_opts ? g_strconcat(",", opts->extra_device_opts, NULL) : NULL; + edge->after_cmd_line = + opts->after_cmd_line ? g_strconcat(" ", opts->after_cmd_line, NULL) : NULL; + + QSLIST_INSERT_HEAD(list, edge, edge_list); +} + +/* destroy_edges(): frees all edges inside a given @list */ +static void destroy_edges(void *list) +{ + QOSGraphEdge *temp; + QOSGraphEdgeList *elist = list; + + while (!QSLIST_EMPTY(elist)) { + temp = QSLIST_FIRST(elist); + QSLIST_REMOVE_HEAD(elist, edge_list); + g_free(temp->dest); + g_free(temp->before_cmd_line); + g_free(temp->after_cmd_line); + g_free(temp->extra_device_opts); + g_free(temp->edge_name); + g_free(temp->arg); + g_free(temp); + } + g_free(elist); +} + +/** + * create_node(): creates a node @name of type @type + * and inserts it to the nodes hash table. + * By default, node is not available. + */ +static QOSGraphNode *create_node(const char *name, QOSNodeType type) +{ + if (g_hash_table_lookup(node_table, name)) { + g_printerr("Node %s already created\n", name); + abort(); + } + + QOSGraphNode *node = g_new0(QOSGraphNode, 1); + node->type = type; + node->available = false; + node->name = g_strdup(name); + g_hash_table_insert(node_table, node->name, node); + return node; +} + +/** + * destroy_node(): frees a node @val from the nodes hash table. + * Note that node->name is not free'd since it will represent the + * hash table key + */ +static void destroy_node(void *val) +{ + QOSGraphNode *node = val; + g_free(node->command_line); + g_free(node); +} + +/** + * destroy_string(): frees @key from the nodes hash table. + * Actually frees the node->name + */ +static void destroy_string(void *key) +{ + g_free(key); +} + +/** + * search_node(): search for a node @key in the nodes hash table + * Returns the QOSGraphNode if found, #NULL otherwise + */ +static QOSGraphNode *search_node(const char *key) +{ + return g_hash_table_lookup(node_table, key); +} + +/** + * get_edgelist(): returns the edge list (value) assigned to + * the @key in the edge hash table. + * This list will contain all edges with source equal to @key + * + * Returns: on success: the %QOSGraphEdgeList + * otherwise: abort() + */ +static QOSGraphEdgeList *get_edgelist(const char *key) +{ + return g_hash_table_lookup(edge_table, key); +} + +/** + * search_list_edges(): search for an edge with destination @dest + * in the given @edgelist. + * + * Returns: on success: the %QOSGraphEdge + * otherwise: #NULL + */ +static QOSGraphEdge *search_list_edges(QOSGraphEdgeList *edgelist, + const char *dest) +{ + QOSGraphEdge *tmp, *next; + if (!edgelist) { + return NULL; + } + QSLIST_FOREACH_SAFE(tmp, edgelist, edge_list, next) { + if (g_strcmp0(tmp->dest, dest) == 0) { + break; + } + } + return tmp; +} + +/** + * search_machine(): search for a machine @name in the node hash + * table. A machine is the child of the root node. + * This function forces the research in the childs of the root, + * to check the node is a proper machine + * + * Returns: on success: the %QOSGraphNode + * otherwise: #NULL + */ +static QOSGraphNode *search_machine(const char *name) +{ + QOSGraphNode *n; + QOSGraphEdgeList *root_list = get_edgelist(QOS_ROOT); + QOSGraphEdge *e = search_list_edges(root_list, name); + if (!e) { + return NULL; + } + n = search_node(e->dest); + if (n->type == QNODE_MACHINE) { + return n; + } + return NULL; +} + +/** + * create_interface(): checks if there is already + * a node @node in the node hash table, if not + * creates a node @node of type #QNODE_INTERFACE + * and inserts it. If there is one, check it's + * a #QNODE_INTERFACE and abort() if it's not. + */ +static void create_interface(const char *node) +{ + QOSGraphNode *interface; + interface = search_node(node); + if (!interface) { + create_node(node, QNODE_INTERFACE); + } else if (interface->type != QNODE_INTERFACE) { + fprintf(stderr, "Error: Node %s is not an interface\n", node); + abort(); + } +} + +/** + * build_machine_cmd_line(): builds the command line for the machine + * @node. The node name must be a valid qemu identifier, since it + * will be used to build the command line. + * + * It is also possible to pass an optional @args that will be + * concatenated to the command line. + * + * For machines, prepend -M to the machine name. ", @rgs" is added + * after the -M command. + */ +static void build_machine_cmd_line(QOSGraphNode *node, const char *args) +{ + char *machine = qos_get_machine_type(node->name); + if (args) { + node->command_line = g_strconcat("-M ", machine, ",", args, NULL); + } else { + node->command_line = g_strconcat("-M ", machine, " ", NULL); + } +} + +/** + * build_driver_cmd_line(): builds the command line for the driver + * @node. The node name must be a valid qemu identifier, since it + * will be used to build the command line. + * + * Driver do not need additional command line, since it will be + * provided by the edge options. + * + * For drivers, prepend -device to the node name. + */ +static void build_driver_cmd_line(QOSGraphNode *node) +{ + node->command_line = g_strconcat(" -device ", node->name, NULL); +} + +/* qos_print_cb(): callback prints all path found by the DFS algorithm. */ +static void qos_print_cb(QOSGraphNode *path, int length) +{ + #if QGRAPH_PRINT_DEBUG + printf("%d elements\n", length); + + if (!path) { + return; + } + + while (path->path_edge) { + printf("%s ", path->name); + switch (path->path_edge->type) { + case QEDGE_PRODUCES: + printf("--PRODUCES--> "); + break; + case QEDGE_CONSUMED_BY: + printf("--CONSUMED_BY--> "); + break; + case QEDGE_CONTAINS: + printf("--CONTAINS--> "); + break; + } + path = search_node(path->path_edge->dest); + } + + printf("%s\n\n", path->name); + #endif +} + +/* qos_push(): push a node @el and edge @e in the qos_node_stack */ +static void qos_push(QOSGraphNode *el, QOSStackElement *parent, + QOSGraphEdge *e) +{ + int len = 0; /* root is not counted */ + if (qos_node_tos == QOS_PATH_MAX_ELEMENT_SIZE) { + g_printerr("QOSStack: full stack, cannot push"); + abort(); + } + + if (parent) { + len = parent->length + 1; + } + qos_node_stack[qos_node_tos++] = (QOSStackElement) { + .node = el, + .parent = parent, + .parent_edge = e, + .length = len, + }; +} + +/* qos_tos(): returns the top of stack, without popping */ +static QOSStackElement *qos_tos(void) +{ + return &qos_node_stack[qos_node_tos - 1]; +} + +/* qos_pop(): pops an element from the tos, setting it unvisited*/ +static QOSStackElement *qos_pop(void) +{ + if (qos_node_tos == 0) { + g_printerr("QOSStack: empty stack, cannot pop"); + abort(); + } + QOSStackElement *e = qos_tos(); + e->node->visited = false; + qos_node_tos--; + return e; +} + +/** + * qos_reverse_path(): reverses the found path, going from + * test-to-machine to machine-to-test + */ +static QOSGraphNode *qos_reverse_path(QOSStackElement *el) +{ + if (!el) { + return NULL; + } + + el->node->path_edge = NULL; + + while (el->parent) { + el->parent->node->path_edge = el->parent_edge; + el = el->parent; + } + + return el->node; +} + +/** + * qos_traverse_graph(): graph-walking algorithm, using Depth First Search it + * starts from the root @machine and walks all possible path until it + * reaches a test node. + * At that point, it reverses the path found and invokes the @callback. + * + * Being Depth First Search, time complexity is O(|V| + |E|), while + * space is O(|V|). In this case, the maximum stack size is set by + * QOS_PATH_MAX_ELEMENT_SIZE. + */ +static void qos_traverse_graph(QOSGraphNode *root, QOSTestCallback callback) +{ + QOSGraphNode *v, *dest_node, *path; + QOSStackElement *s_el; + QOSGraphEdge *e, *next; + QOSGraphEdgeList *list; + + qos_push(root, NULL, NULL); + + while (qos_node_tos > 0) { + s_el = qos_tos(); + v = s_el->node; + if (v->visited) { + qos_pop(); + continue; + } + v->visited = true; + list = get_edgelist(v->name); + if (!list) { + qos_pop(); + if (v->type == QNODE_TEST) { + v->visited = false; + path = qos_reverse_path(s_el); + callback(path, s_el->length); + } + } else { + QSLIST_FOREACH_SAFE(e, list, edge_list, next) { + dest_node = search_node(e->dest); + + if (!dest_node) { + fprintf(stderr, "node %s in %s -> %s does not exist\n", + e->dest, v->name, e->dest); + abort(); + } + + if (!dest_node->visited && dest_node->available) { + qos_push(dest_node, s_el, e); + } + } + } + } +} + +/* QGRAPH API*/ + +QOSGraphNode *qos_graph_get_node(const char *key) +{ + return search_node(key); +} + +bool qos_graph_has_node(const char *node) +{ + QOSGraphNode *n = search_node(node); + return n != NULL; +} + +QOSNodeType qos_graph_get_node_type(const char *node) +{ + QOSGraphNode *n = search_node(node); + if (n) { + return n->type; + } + return -1; +} + +bool qos_graph_get_node_availability(const char *node) +{ + QOSGraphNode *n = search_node(node); + if (n) { + return n->available; + } + return false; +} + +QOSGraphEdge *qos_graph_get_edge(const char *node, const char *dest) +{ + QOSGraphEdgeList *list = get_edgelist(node); + return search_list_edges(list, dest); +} + +QOSEdgeType qos_graph_edge_get_type(QOSGraphEdge *edge) +{ + if (!edge) { + return -1; + } + return edge->type;; +} + +char *qos_graph_edge_get_dest(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->dest; +} + +void *qos_graph_edge_get_arg(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->arg; +} + +char *qos_graph_edge_get_after_cmd_line(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->after_cmd_line; +} + +char *qos_graph_edge_get_before_cmd_line(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->before_cmd_line; +} + +char *qos_graph_edge_get_extra_device_opts(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->extra_device_opts; +} + +char *qos_graph_edge_get_name(QOSGraphEdge *edge) +{ + if (!edge) { + return NULL; + } + return edge->edge_name; +} + +bool qos_graph_has_edge(const char *start, const char *dest) +{ + QOSGraphEdgeList *list = get_edgelist(start); + QOSGraphEdge *e = search_list_edges(list, dest); + return e != NULL; +} + +QOSGraphNode *qos_graph_get_machine(const char *node) +{ + return search_machine(node); +} + +bool qos_graph_has_machine(const char *node) +{ + QOSGraphNode *m = search_machine(node); + return m != NULL; +} + +void qos_print_graph(void) +{ + qos_graph_foreach_test_path(qos_print_cb); +} + +void qos_graph_init(void) +{ + if (!node_table) { + node_table = g_hash_table_new_full(g_str_hash, g_str_equal, + destroy_string, destroy_node); + create_node(QOS_ROOT, QNODE_DRIVER); + } + + if (!edge_table) { + edge_table = g_hash_table_new_full(g_str_hash, g_str_equal, + destroy_string, destroy_edges); + } +} + +void qos_graph_destroy(void) +{ + if (node_table) { + g_hash_table_destroy(node_table); + } + + if (edge_table) { + g_hash_table_destroy(edge_table); + } + + node_table = NULL; + edge_table = NULL; +} + +void qos_node_destroy(void *key) +{ + g_hash_table_remove(node_table, key); +} + +void qos_edge_destroy(void *key) +{ + g_hash_table_remove(edge_table, key); +} + +void qos_add_test(const char *name, const char *interface, + QOSTestFunc test_func, QOSGraphTestOptions *opts) +{ + QOSGraphNode *node; + char *test_name = g_strdup_printf("%s-tests/%s", interface, name);; + + if (!opts) { + opts = &(QOSGraphTestOptions) { }; + } + node = create_node(test_name, QNODE_TEST); + node->u.test.function = test_func; + node->u.test.arg = opts->arg; + assert(!opts->edge.arg); + assert(!opts->edge.size_arg); + + node->u.test.before = opts->before; + node->u.test.subprocess = opts->subprocess; + node->available = true; + add_edge(interface, test_name, QEDGE_CONSUMED_BY, &opts->edge); + g_free(test_name); +} + +void qos_node_create_machine(const char *name, QOSCreateMachineFunc function) +{ + qos_node_create_machine_args(name, function, NULL); +} + +void qos_node_create_machine_args(const char *name, + QOSCreateMachineFunc function, + const char *opts) +{ + QOSGraphNode *node = create_node(name, QNODE_MACHINE); + build_machine_cmd_line(node, opts); + node->u.machine.constructor = function; + add_edge(QOS_ROOT, name, QEDGE_CONTAINS, NULL); +} + +void qos_node_create_driver(const char *name, QOSCreateDriverFunc function) +{ + QOSGraphNode *node = create_node(name, QNODE_DRIVER); + build_driver_cmd_line(node); + node->u.driver.constructor = function; +} + +void qos_node_contains(const char *container, const char *contained, + ...) +{ + va_list va; + va_start(va, contained); + QOSGraphEdgeOptions *opts; + + do { + opts = va_arg(va, QOSGraphEdgeOptions *); + add_edge(container, contained, QEDGE_CONTAINS, opts); + } while (opts != NULL); + + va_end(va); +} + +void qos_node_produces(const char *producer, const char *interface) +{ + create_interface(interface); + add_edge(producer, interface, QEDGE_PRODUCES, NULL); +} + +void qos_node_consumes(const char *consumer, const char *interface, + QOSGraphEdgeOptions *opts) +{ + create_interface(interface); + add_edge(interface, consumer, QEDGE_CONSUMED_BY, opts); +} + +void qos_graph_node_set_availability(const char *node, bool av) +{ + QOSGraphEdgeList *elist; + QOSGraphNode *n = search_node(node); + QOSGraphEdge *e, *next; + if (!n) { + return; + } + n->available = av; + elist = get_edgelist(node); + if (!elist) { + return; + } + QSLIST_FOREACH_SAFE(e, elist, edge_list, next) { + if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES) { + qos_graph_node_set_availability(e->dest, av); + } + } +} + +void qos_graph_foreach_test_path(QOSTestCallback fn) +{ + QOSGraphNode *root = qos_graph_get_node(QOS_ROOT); + qos_traverse_graph(root, fn); +} + +QOSGraphObject *qos_machine_new(QOSGraphNode *node, QTestState *qts) +{ + QOSGraphObject *obj; + + g_assert(node->type == QNODE_MACHINE); + obj = node->u.machine.constructor(qts); + obj->free = g_free; + return obj; +} + +QOSGraphObject *qos_driver_new(QOSGraphNode *node, QOSGraphObject *parent, + QGuestAllocator *alloc, void *arg) +{ + QOSGraphObject *obj; + + g_assert(node->type == QNODE_DRIVER); + obj = node->u.driver.constructor(parent, alloc, arg); + obj->free = g_free; + return obj; +} + +void qos_object_destroy(QOSGraphObject *obj) +{ + if (!obj) { + return; + } + if (obj->destructor) { + obj->destructor(obj); + } + if (obj->free) { + obj->free(obj); + } +} + +void qos_object_queue_destroy(QOSGraphObject *obj) +{ + g_test_queue_destroy((GDestroyNotify) qos_object_destroy, obj); +} + +void qos_object_start_hw(QOSGraphObject *obj) +{ + if (obj->start_hw) { + obj->start_hw(obj); + } +} + +char *qos_get_machine_type(char *name) +{ + while (*name != '\0' && *name != '/') { + name++; + } + + if (!*name || !name[1]) { + fprintf(stderr, "Machine name has to be of the form /\n"); + abort(); + } + + return name + 1; +} + +void qos_delete_cmd_line(const char *name) +{ + QOSGraphNode *node = search_node(name); + if (node) { + g_free(node->command_line); + node->command_line = NULL; + } +} diff --git a/tests/libqos/qgraph.h b/tests/libqos/qgraph.h new file mode 100644 index 0000000..ef0c738 --- /dev/null +++ b/tests/libqos/qgraph.h @@ -0,0 +1,575 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef QGRAPH_H +#define QGRAPH_H + +#include +#include +#include +#include +#include +#include "qemu/module.h" +#include "malloc.h" + +/* maximum path length */ +#define QOS_PATH_MAX_ELEMENT_SIZE 50 + +typedef struct QOSGraphObject QOSGraphObject; +typedef struct QOSGraphNode QOSGraphNode; +typedef struct QOSGraphEdge QOSGraphEdge; +typedef struct QOSGraphNodeOptions QOSGraphNodeOptions; +typedef struct QOSGraphEdgeOptions QOSGraphEdgeOptions; +typedef struct QOSGraphTestOptions QOSGraphTestOptions; + +/* Constructor for drivers, machines and test */ +typedef void *(*QOSCreateDriverFunc) (void *parent, QGuestAllocator *alloc, + void *addr); +typedef void *(*QOSCreateMachineFunc) (QTestState *qts); +typedef void (*QOSTestFunc) (void *parent, void *arg, QGuestAllocator *alloc); + +/* QOSGraphObject functions */ +typedef void *(*QOSGetDriver) (void *object, const char *interface); +typedef QOSGraphObject *(*QOSGetDevice) (void *object, const char *name); +typedef void (*QOSDestructorFunc) (QOSGraphObject *object); +typedef void (*QOSStartFunct) (QOSGraphObject *object); + +/* Test options functions */ +typedef void *(*QOSBeforeTest) (GString *cmd_line, void *arg); + +/** + * SECTION: qgraph.h + * @title: Qtest Driver Framework + * @short_description: interfaces to organize drivers and tests + * as nodes in a graph + * + * This Qgraph API provides all basic functions to create a graph + * and instantiate nodes representing machines, drivers and tests + * representing their relations with CONSUMES, PRODUCES, and CONTAINS + * edges. + * + * The idea is to have a framework where each test asks for a specific + * driver, and the framework takes care of allocating the proper devices + * required and passing the correct command line arguments to QEMU. + * + * A node can be of four types: + * - QNODE_MACHINE: for example "arm/raspi2" + * - QNODE_DRIVER: for example "generic-sdhci" + * - QNODE_INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers) + * an interface is not explicitly created, it will be auto- + * matically instantiated when a node consumes or produces + * it. + * - QNODE_TEST: for example "sdhci-test", consumes an interface and tests + * the functions provided + * + * Notes for the nodes: + * - QNODE_MACHINE: each machine struct must have a QGuestAllocator and + * implement get_driver to return the allocator passing + * "memory". The function can also return NULL if the + * allocator is not set. + * - QNODE_DRIVER: driver names must be unique, and machines and nodes + * planned to be "consumed" by other nodes must match QEMU + * drivers name, otherwise they won't be discovered + * + * An edge relation between two nodes (drivers or machines) X and Y can be: + * - X CONSUMES Y: Y can be plugged into X + * - X PRODUCES Y: X provides the interface Y + * - X CONTAINS Y: Y is part of X component + * + * Basic framework steps are the following: + * - All nodes and edges are created in their respective + * machine/driver/test files + * - The framework starts QEMU and asks for a list of available devices + * and machines (note that only machines and "consumed" nodes are mapped + * 1:1 with QEMU devices) + * - The framework walks the graph starting from the available machines and + * performs a Depth First Search for tests + * - Once a test is found, the path is walked again and all drivers are + * allocated accordingly and the final interface is passed to the test + * - The test is executed + * - Unused objects are cleaned and the path discovery is continued + * + * Depending on the QEMU binary used, only some drivers/machines will be + * available and only test that are reached by them will be executed. + * + * + * Creating new driver an its interface + * + #include "libqos/qgraph.h" + + struct My_driver { + QOSGraphObject obj; + Node_produced prod; + Node_contained cont; + } + + static void my_destructor(QOSGraphObject *obj) + { + g_free(obj); + } + + static void my_get_driver(void *object, const char *interface) { + My_driver *dev = object; + if (!g_strcmp0(interface, "my_interface")) { + return &dev->prod; + } + abort(); + } + + static void my_get_device(void *object, const char *device) { + My_driver *dev = object; + if (!g_strcmp0(device, "my_driver_contained")) { + return &dev->cont; + } + abort(); + } + + static void *my_driver_constructor(void *node_consumed, + QOSGraphObject *alloc) + { + My_driver dev = g_new(My_driver, 1); + // get the node pointed by the produce edge + dev->obj.get_driver = my_get_driver; + // get the node pointed by the contains + dev->obj.get_device = my_get_device; + // free the object + dev->obj.destructor = my_destructor; + do_something_with_node_consumed(node_consumed); + // set all fields of contained device + init_contained_device(&dev->cont); + return &dev->obj; + } + + static void register_my_driver(void) + { + qos_node_create_driver("my_driver", my_driver_constructor); + // contained drivers don't need a constructor, + // they will be init by the parent. + qos_node_create_driver("my_driver_contained", NULL); + + // For the sake of this example, assume machine x86_64/pc contains + // "other_node". + // This relation, along with the machine and "other_node" creation, + // should be defined in the x86_64_pc-machine.c file. + // "my_driver" will then consume "other_node" + qos_node_contains("my_driver", "my_driver_contained"); + qos_node_produces("my_driver", "my_interface"); + qos_node_consumes("my_driver", "other_node"); + } + * + * + * + * In the above example, all possible types of relations are created: + * node "my_driver" consumes, contains and produces other nodes. + * more specifically: + * x86_64/pc -->contains--> other_node <--consumes-- my_driver + * | + * my_driver_contained <--contains--+ + * | + * my_interface <--produces--+ + * + * or inverting the consumes edge in consumed_by: + * + * x86_64/pc -->contains--> other_node --consumed_by--> my_driver + * | + * my_driver_contained <--contains--+ + * | + * my_interface <--produces--+ + * + * + * Creating new test + * + * #include "libqos/qgraph.h" + * + * static void my_test_function(void *obj, void *data) + * { + * Node_produced *interface_to_test = obj; + * // test interface_to_test + * } + * + * static void register_my_test(void) + * { + * qos_add_test("my_interface", "my_test", my_test_function); + * } + * + * libqos_init(register_my_test); + * + * + * + * + * Here a new test is created, consuming "my_interface" node + * and creating a valid path from a machine to a test. + * Final graph will be like this: + * x86_64/pc -->contains--> other_node <--consumes-- my_driver + * | + * my_driver_contained <--contains--+ + * | + * my_test --consumes--> my_interface <--produces--+ + * + * or inverting the consumes edge in consumed_by: + * + * x86_64/pc -->contains--> other_node --consumed_by--> my_driver + * | + * my_driver_contained <--contains--+ + * | + * my_test <--consumed_by-- my_interface <--produces--+ + * + * Assuming there the binary is + * QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 + * a valid test path will be: + * "/x86_64/pc/other_node/my_driver/my_interface/my_test". + * + * Additional examples are also in libqos/test-qgraph.c + * + * Command line: + * Command line is built by using node names and optional arguments + * passed by the user when building the edges. + * + * There are three types of command line arguments: + * - in node : created from the node name. For example, machines will + * have "-M " to its command line, while devices + * "-device ". It is automatically done by the + * framework. + * - after node : added as additional argument to the node name. + * This argument is added optionally when creating edges, + * by setting the parameter @after_cmd_line and + * @extra_edge_opts in #QOSGraphEdgeOptions. + * The framework automatically adds + * a comma before @extra_edge_opts, + * because it is going to add attributes + * after the destination node pointed by + * the edge containing these options, and automatically + * adds a space before @after_cmd_line, because it + * adds an additional device, not an attribute. + * - before node : added as additional argument to the node name. + * This argument is added optionally when creating edges, + * by setting the parameter @before_cmd_line in + * #QOSGraphEdgeOptions. This attribute + * is going to add attributes before the destination node + * pointed by the edge containing these options. It is + * helpful to commands that are not node-representable, + * such as "-fdsev" or "-netdev". + * + * While adding command line in edges is always used, not all nodes names are + * used in every path walk: this is because the contained or produced ones + * are already added by QEMU, so only nodes that "consumes" will be used to + * build the command line. Also, nodes that will have { "abstract" : true } + * as QMP attribute will loose their command line, since they are not proper + * devices to be added in QEMU. + * + * Example: + * + QOSGraphEdgeOptions opts = { + .arg = NULL, + .size_arg = 0, + .after_cmd_line = "-device other", + .before_cmd_line = "-netdev something", + .extra_edge_opts = "addr=04.0", + }; + QOSGraphNode * node = qos_node_create_driver("my_node", constructor); + qos_node_consumes_args("my_node", "interface", &opts); + * + * Will produce the following command line: + * "-netdev something -device my_node,addr=04.0 -device other" + */ + +/** + * Edge options to be passed to the contains/consumes *_args function. + */ +struct QOSGraphEdgeOptions { + void *arg; /* + * optional arg that will be used by + * dest edge + */ + uint32_t size_arg; /* + * optional arg size that will be used by + * dest edge + */ + const char *extra_device_opts;/* + *optional additional command line for dest + * edge, used to add additional attributes + * *after* the node command line, the + * framework automatically prepends "," + * to this argument. + */ + const char *before_cmd_line; /* + * optional additional command line for dest + * edge, used to add additional attributes + * *before* the node command line, usually + * other non-node represented commands, + * like "-fdsev synt" + */ + const char *after_cmd_line; /* + * optional extra command line to be added + * after the device command. This option + * is used to add other devices + * command line that depend on current node. + * Automatically prepends " " to this + * argument + */ + const char *edge_name; /* + * optional edge to differentiate multiple + * devices with same node name + */ +}; + +/** + * Test options to be passed to the test functions. + */ +struct QOSGraphTestOptions { + QOSGraphEdgeOptions edge; /* edge arguments that will be used by test. + * Note that test *does not* use edge_name, + * and uses instead arg and size_arg as + * data arg for its test function. + */ + void *arg; /* passed to the .before function, or to the + * test function if there is no .before + * function + */ + QOSBeforeTest before; /* executed before the test. Can add + * additional parameters to the command line + * and modify the argument to the test function. + */ + bool subprocess; /* run the test in a subprocess */ +}; + +/** + * Each driver, test or machine of this framework will have a + * QOSGraphObject as first field. + * + * This set of functions offered by QOSGraphObject are executed + * in different stages of the framework: + * - get_driver / get_device : Once a machine-to-test path has been + * found, the framework traverses it again and allocates all the + * nodes, using the provided constructor. To satisfy their relations, + * i.e. for produces or contains, where a struct constructor needs + * an external parameter represented by the previous node, + * the framework will call get_device (for contains) or + * get_driver (for produces), depending on the edge type, passing + * them the name of the next node to be taken and getting from them + * the corresponding pointer to the actual structure of the next node to + * be used in the path. + * + * - start_hw: This function is executed after all the path objects + * have been allocated, but before the test is run. It starts the hw, setting + * the initial configurations (*_device_enable) and making it ready for the + * test. + * + * - destructor: Opposite to the node constructor, destroys the object. + * This function is called after the test has been executed, and performs + * a complete cleanup of each node allocated field. In case no constructor + * is provided, no destructor will be called. + * + */ +struct QOSGraphObject { + /* for produces edges, returns void * */ + QOSGetDriver get_driver; + /* for contains edges, returns a QOSGraphObject * */ + QOSGetDevice get_device; + /* start the hw, get ready for the test */ + QOSStartFunct start_hw; + /* destroy this QOSGraphObject */ + QOSDestructorFunc destructor; + /* free the memory associated to the QOSGraphObject and its contained + * children */ + GDestroyNotify free; +}; + +/** + * qos_graph_init(): initialize the framework, creates two hash + * tables: one for the nodes and another for the edges. + */ +void qos_graph_init(void); + +/** + * qos_graph_destroy(): deallocates all the hash tables, + * freeing all nodes and edges. + */ +void qos_graph_destroy(void); + +/** + * qos_node_destroy(): removes and frees a node from the, + * nodes hash table. + */ +void qos_node_destroy(void *key); + +/** + * qos_edge_destroy(): removes and frees an edge from the, + * edges hash table. + */ +void qos_edge_destroy(void *key); + +/** + * qos_add_test(): adds a test node @name to the nodes hash table. + * + * The test will consume a @interface node, and once the + * graph walking algorithm has found it, the @test_func will be + * executed. It also has the possibility to + * add an optional @opts (see %QOSGraphNodeOptions). + * + * For tests, opts->edge.arg and size_arg represent the arg to pass + * to @test_func + */ +void qos_add_test(const char *name, const char *interface, + QOSTestFunc test_func, + QOSGraphTestOptions *opts); + +/** + * qos_node_create_machine(): creates the machine @name and + * adds it to the node hash table. + * + * This node will be of type QNODE_MACHINE and have @function + * as constructor + */ +void qos_node_create_machine(const char *name, QOSCreateMachineFunc function); + +/** + * qos_node_create_machine_args(): same as qos_node_create_machine, + * but with the possibility to add an optional ", @opts" after -M machine + * command line. + */ +void qos_node_create_machine_args(const char *name, + QOSCreateMachineFunc function, + const char *opts); + +/** + * qos_node_create_driver(): creates the driver @name and + * adds it to the node hash table. + * + * This node will be of type QNODE_DRIVER and have @function + * as constructor + */ +void qos_node_create_driver(const char *name, QOSCreateDriverFunc function); + +/** + * qos_node_contains(): creates an edge of type QEDGE_CONTAINS and + * adds it to the edge list mapped to @container in the + * edge hash table. + * + * This edge will have @container as source and @contained as destination. + * + * It also has the possibility to add optional NULL-terminated + * @opts parameters (see %QOSGraphEdgeOptions) + * + * This function can be useful when there are multiple devices + * with the same node name contained in a machine/other node + * + * For example, if "arm/raspi2" contains 2 "generic-sdhci" + * devices, the right commands will be: + * qos_node_create_machine("arm/raspi2"); + * qos_node_create_driver("generic-sdhci", constructor); + * //assume rest of the fields are set NULL + * QOSGraphEdgeOptions op1 = { .edge_name = "emmc" }; + * QOSGraphEdgeOptions op2 = { .edge_name = "sdcard" }; + * qos_node_contains("arm/raspi2", "generic-sdhci", &op1, &op2, NULL); + * + * Of course this also requires that the @container's get_device function + * should implement a case for "emmc" and "sdcard". + * + * For contains, op1.arg and op1.size_arg represent the arg to pass + * to @contained constructor to properly initialize it. + */ +void qos_node_contains(const char *container, const char *contained, ...); + +/** + * qos_node_produces(): creates an edge of type QEDGE_PRODUCES and + * adds it to the edge list mapped to @producer in the + * edge hash table. + * + * This edge will have @producer as source and @interface as destination. + */ +void qos_node_produces(const char *producer, const char *interface); + +/** + * qos_node_consumes(): creates an edge of type QEDGE_CONSUMED_BY and + * adds it to the edge list mapped to @interface in the + * edge hash table. + * + * This edge will have @interface as source and @consumer as destination. + * It also has the possibility to add an optional @opts + * (see %QOSGraphEdgeOptions) + */ +void qos_node_consumes(const char *consumer, const char *interface, + QOSGraphEdgeOptions *opts); + +/** + * qos_invalidate_command_line(): invalidates current command line, so that + * qgraph framework cannot try to cache the current command line and + * forces QEMU to restart. + */ +void qos_invalidate_command_line(void); + +/** + * qos_get_current_command_line(): return the command line required by the + * machine and driver objects. This is the same string that was passed to + * the test's "before" callback, if any. + */ +const char *qos_get_current_command_line(void); + +/** + * qos_allocate_objects(): + * @qts: The #QTestState that will be referred to by the machine object. + * @alloc: Where to store the allocator for the machine object, or %NULL. + * + * Allocate driver objects for the current test + * path, but relative to the QTestState @qts. + * + * Returns a test object just like the one that was passed to + * the test function, but relative to @qts. + */ +void *qos_allocate_objects(QTestState *qts, QGuestAllocator **p_alloc); + +/** + * qos_object_destroy(): calls the destructor for @obj + */ +void qos_object_destroy(QOSGraphObject *obj); + +/** + * qos_object_queue_destroy(): queue the destructor for @obj so that it is + * called at the end of the test + */ +void qos_object_queue_destroy(QOSGraphObject *obj); + +/** + * qos_object_start_hw(): calls the start_hw function for @obj + */ +void qos_object_start_hw(QOSGraphObject *obj); + +/** + * qos_machine_new(): instantiate a new machine node + * @node: A machine node to be instantiated + * @qts: The #QTestState that will be referred to by the machine object. + * + * Returns a machine object. + */ +QOSGraphObject *qos_machine_new(QOSGraphNode *node, QTestState *qts); + +/** + * qos_machine_new(): instantiate a new driver node + * @node: A driver node to be instantiated + * @parent: A #QOSGraphObject to be consumed by the new driver node + * @alloc: An allocator to be used by the new driver node. + * @arg: The argument for the consumed-by edge to @node. + * + * Calls the constructor for the driver object. + */ +QOSGraphObject *qos_driver_new(QOSGraphNode *node, QOSGraphObject *parent, + QGuestAllocator *alloc, void *arg); + + +#endif diff --git a/tests/libqos/qgraph_internal.h b/tests/libqos/qgraph_internal.h new file mode 100644 index 0000000..2ef748b --- /dev/null +++ b/tests/libqos/qgraph_internal.h @@ -0,0 +1,257 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef QGRAPH_EXTRA_H +#define QGRAPH_EXTRA_H + +/* This header is declaring additional helper functions defined in + * libqos/qgraph.c + * It should not be included in tests + */ + +#include "libqos/qgraph.h" + +typedef struct QOSGraphMachine QOSGraphMachine; +typedef enum QOSEdgeType QOSEdgeType; +typedef enum QOSNodeType QOSNodeType; + +/* callback called when the walk path algorithm found a + * valid path + */ +typedef void (*QOSTestCallback) (QOSGraphNode *path, int len); + +/* edge types*/ +enum QOSEdgeType { + QEDGE_CONTAINS, + QEDGE_PRODUCES, + QEDGE_CONSUMED_BY +}; + +/* node types*/ +enum QOSNodeType { + QNODE_MACHINE, + QNODE_DRIVER, + QNODE_INTERFACE, + QNODE_TEST +}; + +/* Graph Node */ +struct QOSGraphNode { + QOSNodeType type; + bool available; /* set by QEMU via QMP, used during graph walk */ + bool visited; /* used during graph walk */ + char *name; /* used to identify the node */ + char *command_line; /* used to start QEMU at test execution */ + union { + struct { + QOSCreateDriverFunc constructor; + } driver; + struct { + QOSCreateMachineFunc constructor; + } machine; + struct { + QOSTestFunc function; + void *arg; + QOSBeforeTest before; + bool subprocess; + } test; + } u; + + /** + * only used when traversing the path, never rely on that except in the + * qos_traverse_graph callback function + */ + QOSGraphEdge *path_edge; +}; + +/** + * qos_graph_get_node(): returns the node mapped to that @key. + * It performs an hash map search O(1) + * + * Returns: on success: the %QOSGraphNode + * otherwise: #NULL + */ +QOSGraphNode *qos_graph_get_node(const char *key); + +/** + * qos_graph_has_node(): returns #TRUE if the node + * has map has a node mapped to that @key. + */ +bool qos_graph_has_node(const char *node); + +/** + * qos_graph_get_node_type(): returns the %QOSNodeType + * of the node @node. + * It performs an hash map search O(1) + * Returns: on success: the %QOSNodeType + * otherwise: #-1 + */ +QOSNodeType qos_graph_get_node_type(const char *node); + +/** + * qos_graph_get_node_availability(): returns the availability (boolean) + * of the node @node. + */ +bool qos_graph_get_node_availability(const char *node); + +/** + * qos_graph_get_edge(): returns the edge + * linking of the node @node with @dest. + * + * Returns: on success: the %QOSGraphEdge + * otherwise: #NULL + */ +QOSGraphEdge *qos_graph_get_edge(const char *node, const char *dest); + +/** + * qos_graph_edge_get_type(): returns the edge type + * of the edge @edge. + * + * Returns: on success: the %QOSEdgeType + * otherwise: #-1 + */ +QOSEdgeType qos_graph_edge_get_type(QOSGraphEdge *edge); + +/** + * qos_graph_edge_get_dest(): returns the name of the node + * pointed as destination of edge @edge. + * + * Returns: on success: the destination + * otherwise: #NULL + */ +char *qos_graph_edge_get_dest(QOSGraphEdge *edge); + +/** + * qos_graph_has_edge(): returns #TRUE if there + * exists an edge from @start to @dest. + */ +bool qos_graph_has_edge(const char *start, const char *dest); + +/** + * qos_graph_edge_get_arg(): returns the args assigned + * to that @edge. + * + * Returns: on success: the arg + * otherwise: #NULL + */ +void *qos_graph_edge_get_arg(QOSGraphEdge *edge); + +/** + * qos_graph_edge_get_after_cmd_line(): returns the edge + * command line that will be added after all the node arguments + * and all the before_cmd_line arguments. + * + * Returns: on success: the char* arg + * otherwise: #NULL + */ +char *qos_graph_edge_get_after_cmd_line(QOSGraphEdge *edge); + +/** + * qos_graph_edge_get_before_cmd_line(): returns the edge + * command line that will be added before the node command + * line argument. + * + * Returns: on success: the char* arg + * otherwise: #NULL + */ +char *qos_graph_edge_get_before_cmd_line(QOSGraphEdge *edge); + +/** + * qos_graph_edge_get_extra_device_opts(): returns the arg + * command line that will be added to the node command + * line argument. + * + * Returns: on success: the char* arg + * otherwise: #NULL + */ +char *qos_graph_edge_get_extra_device_opts(QOSGraphEdge *edge); + +/** + * qos_graph_edge_get_name(): returns the name + * assigned to the destination node (different only) + * if there are multiple devices with the same node name + * e.g. a node has two "generic-sdhci", "emmc" and "sdcard" + * there will be two edges with edge_name ="emmc" and "sdcard" + * + * Returns always the char* edge_name + */ +char *qos_graph_edge_get_name(QOSGraphEdge *edge); + +/** + * qos_graph_get_machine(): returns the machine assigned + * to that @node name. + * + * It performs a search only trough the list of machines + * (i.e. the QOS_ROOT child). + * + * Returns: on success: the %QOSGraphNode + * otherwise: #NULL + */ +QOSGraphNode *qos_graph_get_machine(const char *node); + +/** + * qos_graph_has_machine(): returns #TRUE if the node + * has map has a node mapped to that @node. + */ +bool qos_graph_has_machine(const char *node); + + +/** + * qos_print_graph(): walks the graph and prints + * all machine-to-test paths. + */ +void qos_print_graph(void); + +/** + * qos_graph_foreach_test_path(): executes the Depth First search + * algorithm and applies @fn to all discovered paths. + * + * See qos_traverse_graph() in qgraph.c for more info on + * how it works. + */ +void qos_graph_foreach_test_path(QOSTestCallback fn); + +/** + * qos_get_machine_type(): return QEMU machine type for a machine node. + * This function requires every machine @name to be in the form + * /, like "arm/raspi2" or "x86_64/pc". + * + * The function will validate the format and return a pointer to + * @machine to . For example, when passed "x86_64/pc" + * it will return "pc". + * + * Note that this function *does not* allocate any new string. + */ +char *qos_get_machine_type(char *name); + +/** + * qos_delete_cmd_line(): delete the + * command line present in node mapped with key @name. + * + * This function is called when the QMP query returns a node with + * { "abstract" : true } attribute. + */ +void qos_delete_cmd_line(const char *name); + +/** + * qos_graph_node_set_availability(): sets the node identified + * by @node with availability @av. + */ +void qos_graph_node_set_availability(const char *node, bool av); + +#endif diff --git a/tests/libqtest.h b/tests/libqtest.h index 5937f91..1a2f87e 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -598,6 +598,9 @@ static inline QTestState *qtest_start(const char *args) */ static inline void qtest_end(void) { + if (!global_qtest) { + return; + } qtest_quit(global_qtest); global_qtest = NULL; } diff --git a/tests/qos-test.c b/tests/qos-test.c new file mode 100644 index 0000000..6b1145e --- /dev/null +++ b/tests/qos-test.c @@ -0,0 +1,445 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qbool.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qlist.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "libqos/qgraph_internal.h" + +static char *old_path; + +static void apply_to_node(const char *name, bool is_machine, bool is_abstract) +{ + char *machine_name = NULL; + if (is_machine) { + const char *arch = qtest_get_arch(); + machine_name = g_strconcat(arch, "/", name, NULL); + name = machine_name; + } + qos_graph_node_set_availability(name, true); + if (is_abstract) { + qos_delete_cmd_line(name); + } + g_free(machine_name); +} + +/** + * apply_to_qlist(): using QMP queries QEMU for a list of + * machines and devices available, and sets the respective node + * as true. If a node is found, also all its produced and contained + * child are marked available. + * + * See qos_graph_node_set_availability() for more info + */ +static void apply_to_qlist(QList *list, bool is_machine) +{ + const QListEntry *p; + const char *name; + bool abstract; + QDict *minfo; + QObject *qobj; + QString *qstr; + QBool *qbool; + + for (p = qlist_first(list); p; p = qlist_next(p)) { + minfo = qobject_to(QDict, qlist_entry_obj(p)); + qobj = qdict_get(minfo, "name"); + qstr = qobject_to(QString, qobj); + name = qstring_get_str(qstr); + + qobj = qdict_get(minfo, "abstract"); + if (qobj) { + qbool = qobject_to(QBool, qobj); + abstract = qbool_get_bool(qbool); + } else { + abstract = false; + } + + apply_to_node(name, is_machine, abstract); + qobj = qdict_get(minfo, "alias"); + if (qobj) { + qstr = qobject_to(QString, qobj); + name = qstring_get_str(qstr); + apply_to_node(name, is_machine, abstract); + } + } +} + +/** + * qos_set_machines_devices_available(): sets availability of qgraph + * machines and devices. + * + * This function firstly starts QEMU with "-machine none" option, + * and then executes the QMP protocol asking for the list of devices + * and machines available. + * + * for each of these items, it looks up the corresponding qgraph node, + * setting it as available. The list currently returns all devices that + * are either machines or QEDGE_CONSUMED_BY other nodes. + * Therefore, in order to mark all other nodes, it recursively sets + * all its QEDGE_CONTAINS and QEDGE_PRODUCES child as available too. + */ +static void qos_set_machines_devices_available(void) +{ + QDict *response; + QDict *args = qdict_new(); + QList *list; + + qtest_start("-machine none"); + response = qmp("{ 'execute': 'query-machines' }"); + list = qdict_get_qlist(response, "return"); + + apply_to_qlist(list, true); + + qobject_unref(response); + + qdict_put_bool(args, "abstract", true); + qdict_put_str(args, "implements", "device"); + + response = qmp("{'execute': 'qom-list-types'," + " 'arguments': %p }", args); + g_assert(qdict_haskey(response, "return")); + list = qdict_get_qlist(response, "return"); + + apply_to_qlist(list, false); + + qtest_end(); + qobject_unref(response); +} + +static QGuestAllocator *get_machine_allocator(QOSGraphObject *obj) +{ + return obj->get_driver(obj, "memory"); +} + +static void restart_qemu_or_continue(char *path) +{ + /* compares the current command line with the + * one previously executed: if they are the same, + * don't restart QEMU, if they differ, stop previous + * QEMU subprocess (if active) and start over with + * the new command line + */ + if (g_strcmp0(old_path, path)) { + qtest_end(); + qos_invalidate_command_line(); + old_path = g_strdup(path); + qtest_start(path); + } else { /* if cmd line is the same, reset the guest */ + qobject_unref(qmp("{ 'execute': 'system_reset' }")); + qmp_eventwait("RESET"); + } +} + +void qos_invalidate_command_line(void) +{ + g_free(old_path); + old_path = NULL; +} + +/** + * allocate_objects(): given an array of nodes @arg, + * walks the path invoking all constructors and + * passing the corresponding parameter in order to + * continue the objects allocation. + * Once the test is reached, return the object it consumes. + * + * Since the machine and QEDGE_CONSUMED_BY nodes allocate + * memory in the constructor, g_test_queue_destroy is used so + * that after execution they can be safely free'd. (The test's + * ->before callback is also welcome to use g_test_queue_destroy). + * + * Note: as specified in walk_path() too, @arg is an array of + * char *, where arg[0] is a pointer to the command line + * string that will be used to properly start QEMU when executing + * the test, and the remaining elements represent the actual objects + * that will be allocated. + */ +static void *allocate_objects(QTestState *qts, char **path, QGuestAllocator **p_alloc) +{ + int current = 0; + QGuestAllocator *alloc; + QOSGraphObject *parent = NULL; + QOSGraphEdge *edge; + QOSGraphNode *node; + void *edge_arg; + void *obj; + + node = qos_graph_get_node(path[current]); + g_assert(node->type == QNODE_MACHINE); + + obj = qos_machine_new(node, qts); + qos_object_queue_destroy(obj); + + alloc = get_machine_allocator(obj); + if (p_alloc) { + *p_alloc = alloc; + } + + for (;;) { + if (node->type != QNODE_INTERFACE) { + qos_object_start_hw(obj); + parent = obj; + } + + /* follow edge and get object for next node constructor */ + current++; + edge = qos_graph_get_edge(path[current - 1], path[current]); + node = qos_graph_get_node(path[current]); + + if (node->type == QNODE_TEST) { + g_assert(qos_graph_edge_get_type(edge) == QEDGE_CONSUMED_BY); + return obj; + } + + switch (qos_graph_edge_get_type(edge)) { + case QEDGE_PRODUCES: + obj = parent->get_driver(parent, path[current]); + break; + + case QEDGE_CONSUMED_BY: + edge_arg = qos_graph_edge_get_arg(edge); + obj = qos_driver_new(node, obj, alloc, edge_arg); + qos_object_queue_destroy(obj); + break; + + case QEDGE_CONTAINS: + obj = parent->get_device(parent, path[current]); + break; + } + } +} + +/* The argument to run_one_test, which is the test function that is registered + * with GTest, is a vector of strings. The first item is the initial command + * line (before it is modified by the test's "before" function), the remaining + * items are node names forming the path to the test node. + */ +static char **current_path; + +const char *qos_get_current_command_line(void) +{ + return current_path[0]; +} + +void *qos_allocate_objects(QTestState *qts, QGuestAllocator **p_alloc) +{ + return allocate_objects(qts, current_path + 1, p_alloc); +} + +/** + * run_one_test(): given an array of nodes @arg, + * walks the path invoking all constructors and + * passing the corresponding parameter in order to + * continue the objects allocation. + * Once the test is reached, its function is executed. + * + * Since the machine and QEDGE_CONSUMED_BY nodes allocate + * memory in the constructor, g_test_queue_destroy is used so + * that after execution they can be safely free'd. The test's + * ->before callback is also welcome to use g_test_queue_destroy. + * + * Note: as specified in walk_path() too, @arg is an array of + * char *, where arg[0] is a pointer to the command line + * string that will be used to properly start QEMU when executing + * the test, and the remaining elements represent the actual objects + * that will be allocated. + * + * The order of execution is the following: + * 1) @before test function as defined in the given QOSGraphTestOptions + * 2) start QEMU + * 3) call all nodes constructor and get_driver/get_device depending on edge, + * start the hardware (*_device_enable functions) + * 4) start test + */ +static void run_one_test(const void *arg) +{ + QOSGraphNode *test_node; + QGuestAllocator *alloc = NULL; + void *obj; + char **path = (char **) arg; + GString *cmd_line = g_string_new(path[0]); + void *test_arg; + + /* Before test */ + current_path = path; + test_node = qos_graph_get_node(path[(g_strv_length(path) - 1)]); + test_arg = test_node->u.test.arg; + if (test_node->u.test.before) { + test_arg = test_node->u.test.before(cmd_line, test_arg); + } + + restart_qemu_or_continue(cmd_line->str); + g_string_free(cmd_line, true); + + obj = qos_allocate_objects(global_qtest, &alloc); + test_node->u.test.function(obj, test_arg, alloc); +} + +static void subprocess_run_one_test(const void *arg) +{ + const gchar *path = arg; + g_test_trap_subprocess(path, 0, 0); + g_test_trap_assert_passed(); +} + +/* + * in this function, 2 path will be built: + * path_str, a one-string path (ex "pc/i440FX-pcihost/...") + * path_vec, a string-array path (ex [0] = "pc", [1] = "i440FX-pcihost"). + * + * path_str will be only used to build the test name, and won't need the + * architecture name at beginning, since it will be added by qtest_add_func(). + * + * path_vec is used to allocate all constructors of the path nodes. + * Each name in this array except position 0 must correspond to a valid + * QOSGraphNode name. + * Position 0 is special, initially contains just the name of + * the node, (ex for "x86_64/pc" it will be "pc"), used to build the test + * path (see below). After it will contain the command line used to start + * qemu with all required devices. + * + * Note that the machine node name must be with format / + * (ex "x86_64/pc"), because it will identify the node "x86_64/pc" + * and start QEMU with "-M pc". For this reason, + * when building path_str, path_vec + * initially contains the at position 0 ("pc"), + * and the node name at position 1 (/) + * ("x86_64/pc"), followed by the rest of the nodes. + */ +static void walk_path(QOSGraphNode *orig_path, int len) +{ + QOSGraphNode *path; + QOSGraphEdge *edge; + + /* etype set to QEDGE_CONSUMED_BY so that machine can add to the command line */ + QOSEdgeType etype = QEDGE_CONSUMED_BY; + + /* twice QOS_PATH_MAX_ELEMENT_SIZE since each edge can have its arg */ + char **path_vec = g_new0(char *, (QOS_PATH_MAX_ELEMENT_SIZE * 2)); + int path_vec_size = 0; + + char *after_cmd = NULL, *before_cmd = NULL, *after_device = NULL; + char *node_name = orig_path->name, *path_str; + + GString *cmd_line = g_string_new(""); + GString *cmd_line2 = g_string_new(""); + + path = qos_graph_get_node(node_name); /* root */ + node_name = qos_graph_edge_get_dest(path->path_edge); /* machine name */ + + path_vec[path_vec_size++] = node_name; + path_vec[path_vec_size++] = qos_get_machine_type(node_name); + + for (;;) { + path = qos_graph_get_node(node_name); + if (!path->path_edge) { + break; + } + + node_name = qos_graph_edge_get_dest(path->path_edge); + + /* append node command line + previous edge command line */ + if (path->command_line && etype == QEDGE_CONSUMED_BY) { + g_string_append(cmd_line, path->command_line); + if (after_device) { + g_string_append(cmd_line, after_device); + } + } + + path_vec[path_vec_size++] = qos_graph_edge_get_name(path->path_edge); + /* detect if edge has command line args */ + after_cmd = qos_graph_edge_get_after_cmd_line(path->path_edge); + after_device = qos_graph_edge_get_extra_device_opts(path->path_edge); + before_cmd = qos_graph_edge_get_before_cmd_line(path->path_edge); + edge = qos_graph_get_edge(path->name, node_name); + etype = qos_graph_edge_get_type(edge); + + if (before_cmd) { + g_string_append(cmd_line, before_cmd); + } + if (after_cmd) { + g_string_append(cmd_line2, after_cmd); + } + } + + path_vec[path_vec_size++] = NULL; + if (after_device) { + g_string_append(cmd_line, after_device); + } + g_string_append(cmd_line, cmd_line2->str); + g_string_free(cmd_line2, true); + + /* here position 0 has /, position 1 has . + * The path must not have the , qtest_add_data_func adds it. + */ + path_str = g_strjoinv("/", path_vec + 1); + + /* put arch/machine in position 1 so run_one_test can do its work + * and add the command line at position 0. + */ + path_vec[1] = path_vec[0]; + path_vec[0] = g_string_free(cmd_line, false); + + if (path->u.test.subprocess) { + gchar *subprocess_path = g_strdup_printf("/%s/%s/subprocess", + qtest_get_arch(), path_str); + qtest_add_data_func(path_str, subprocess_path, subprocess_run_one_test); + g_test_add_data_func(subprocess_path, path_vec, run_one_test); + } else { + qtest_add_data_func(path_str, path_vec, run_one_test); + } + + g_free(path_str); +} + + + +/** + * main(): heart of the qgraph framework. + * + * - Initializes the glib test framework + * - Creates the graph by invoking the various _init constructors + * - Starts QEMU to mark the available devices + * - Walks the graph, and each path is added to + * the glib test framework (walk_path) + * - Runs the tests, calling allocate_object() and allocating the + * machine/drivers/test objects + * - Cleans up everything + */ +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qos_graph_init(); + module_call_init(MODULE_INIT_QOM); + module_call_init(MODULE_INIT_LIBQOS); + qos_set_machines_devices_available(); + + qos_graph_foreach_test_path(walk_path); + g_test_run(); + qtest_end(); + qos_graph_destroy(); + g_free(old_path); + return 0; +} diff --git a/tests/test-qgraph.c b/tests/test-qgraph.c new file mode 100644 index 0000000..f6a6565 --- /dev/null +++ b/tests/test-qgraph.c @@ -0,0 +1,434 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/qgraph_internal.h" + +#define MACHINE_PC "x86_64/pc" +#define MACHINE_RASPI2 "arm/raspi2" +#define I440FX "i440FX-pcihost" +#define PCIBUS_PC "pcibus-pc" +#define SDHCI "sdhci" +#define PCIBUS "pci-bus" +#define SDHCI_PCI "sdhci-pci" +#define SDHCI_MM "generic-sdhci" +#define REGISTER_TEST "register-test" + +int npath; + +static void *machinefunct(QTestState *qts) +{ + return NULL; +} + +static void *driverfunct(void *obj, QGuestAllocator *machine, void *arg) +{ + return NULL; +} + +static void testfunct(void *obj, void *arg, QGuestAllocator *alloc) +{ + return; +} + +static void check_interface(const char *interface) +{ + g_assert_cmpint(qos_graph_has_machine(interface), ==, FALSE); + g_assert_nonnull(qos_graph_get_node(interface)); + g_assert_cmpint(qos_graph_has_node(interface), ==, TRUE); + g_assert_cmpint(qos_graph_get_node_type(interface), ==, QNODE_INTERFACE); + qos_graph_node_set_availability(interface, TRUE); + g_assert_cmpint(qos_graph_get_node_availability(interface), ==, TRUE); +} + +static void check_machine(const char *machine) +{ + qos_node_create_machine(machine, machinefunct); + g_assert_nonnull(qos_graph_get_machine(machine)); + g_assert_cmpint(qos_graph_has_machine(machine), ==, TRUE); + g_assert_nonnull(qos_graph_get_node(machine)); + g_assert_cmpint(qos_graph_get_node_availability(machine), ==, FALSE); + qos_graph_node_set_availability(machine, TRUE); + g_assert_cmpint(qos_graph_get_node_availability(machine), ==, TRUE); + g_assert_cmpint(qos_graph_has_node(machine), ==, TRUE); + g_assert_cmpint(qos_graph_get_node_type(machine), ==, QNODE_MACHINE); +} + +static void check_contains(const char *machine, const char *driver) +{ + QOSGraphEdge *edge; + qos_node_contains(machine, driver, NULL); + + edge = qos_graph_get_edge(machine, driver); + g_assert_nonnull(edge); + g_assert_cmpint(qos_graph_edge_get_type(edge), ==, QEDGE_CONTAINS); + g_assert_cmpint(qos_graph_has_edge(machine, driver), ==, TRUE); +} + +static void check_produces(const char *machine, const char *interface) +{ + QOSGraphEdge *edge; + + qos_node_produces(machine, interface); + check_interface(interface); + edge = qos_graph_get_edge(machine, interface); + g_assert_nonnull(edge); + g_assert_cmpint(qos_graph_edge_get_type(edge), ==, + QEDGE_PRODUCES); + g_assert_cmpint(qos_graph_has_edge(machine, interface), ==, TRUE); +} + +static void check_consumes(const char *driver, const char *interface) +{ + QOSGraphEdge *edge; + + qos_node_consumes(driver, interface, NULL); + check_interface(interface); + edge = qos_graph_get_edge(interface, driver); + g_assert_nonnull(edge); + g_assert_cmpint(qos_graph_edge_get_type(edge), ==, QEDGE_CONSUMED_BY); + g_assert_cmpint(qos_graph_has_edge(interface, driver), ==, TRUE); +} + +static void check_driver(const char *driver) +{ + qos_node_create_driver(driver, driverfunct); + g_assert_cmpint(qos_graph_has_machine(driver), ==, FALSE); + g_assert_nonnull(qos_graph_get_node(driver)); + g_assert_cmpint(qos_graph_has_node(driver), ==, TRUE); + g_assert_cmpint(qos_graph_get_node_type(driver), ==, QNODE_DRIVER); + g_assert_cmpint(qos_graph_get_node_availability(driver), ==, FALSE); + qos_graph_node_set_availability(driver, TRUE); + g_assert_cmpint(qos_graph_get_node_availability(driver), ==, TRUE); +} + +static void check_test(const char *test, const char *interface) +{ + QOSGraphEdge *edge; + const char *full_name = g_strdup_printf("%s-tests/%s", interface, test); + + qos_add_test(test, interface, testfunct, NULL); + g_assert_cmpint(qos_graph_has_machine(test), ==, FALSE); + g_assert_cmpint(qos_graph_has_machine(full_name), ==, FALSE); + g_assert_nonnull(qos_graph_get_node(full_name)); + g_assert_cmpint(qos_graph_has_node(full_name), ==, TRUE); + g_assert_cmpint(qos_graph_get_node_type(full_name), ==, QNODE_TEST); + edge = qos_graph_get_edge(interface, full_name); + g_assert_nonnull(edge); + g_assert_cmpint(qos_graph_edge_get_type(edge), ==, + QEDGE_CONSUMED_BY); + g_assert_cmpint(qos_graph_has_edge(interface, full_name), ==, TRUE); + g_assert_cmpint(qos_graph_get_node_availability(full_name), ==, TRUE); + qos_graph_node_set_availability(full_name, FALSE); + g_assert_cmpint(qos_graph_get_node_availability(full_name), ==, FALSE); +} + +static void count_each_test(QOSGraphNode *path, int len) +{ + npath++; +} + +static void check_leaf_discovered(int n) +{ + npath = 0; + qos_graph_foreach_test_path(count_each_test); + g_assert_cmpint(n, ==, npath); +} + +/* G_Test functions */ + +static void init_nop(void) +{ + qos_graph_init(); + qos_graph_destroy(); +} + +static void test_machine(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + qos_graph_destroy(); +} + +static void test_contains(void) +{ + qos_graph_init(); + check_contains(MACHINE_PC, I440FX); + g_assert_null(qos_graph_get_machine(MACHINE_PC)); + g_assert_null(qos_graph_get_machine(I440FX)); + g_assert_null(qos_graph_get_node(MACHINE_PC)); + g_assert_null(qos_graph_get_node(I440FX)); + qos_graph_destroy(); +} + +static void test_multiple_contains(void) +{ + qos_graph_init(); + check_contains(MACHINE_PC, I440FX); + check_contains(MACHINE_PC, PCIBUS_PC); + qos_graph_destroy(); +} + +static void test_produces(void) +{ + qos_graph_init(); + check_produces(MACHINE_PC, I440FX); + g_assert_null(qos_graph_get_machine(MACHINE_PC)); + g_assert_null(qos_graph_get_machine(I440FX)); + g_assert_null(qos_graph_get_node(MACHINE_PC)); + g_assert_nonnull(qos_graph_get_node(I440FX)); + qos_graph_destroy(); +} + +static void test_multiple_produces(void) +{ + qos_graph_init(); + check_produces(MACHINE_PC, I440FX); + check_produces(MACHINE_PC, PCIBUS_PC); + qos_graph_destroy(); +} + +static void test_consumes(void) +{ + qos_graph_init(); + check_consumes(I440FX, SDHCI); + g_assert_null(qos_graph_get_machine(I440FX)); + g_assert_null(qos_graph_get_machine(SDHCI)); + g_assert_null(qos_graph_get_node(I440FX)); + g_assert_nonnull(qos_graph_get_node(SDHCI)); + qos_graph_destroy(); +} + +static void test_multiple_consumes(void) +{ + qos_graph_init(); + check_consumes(I440FX, SDHCI); + check_consumes(PCIBUS_PC, SDHCI); + qos_graph_destroy(); +} + +static void test_driver(void) +{ + qos_graph_init(); + check_driver(I440FX); + qos_graph_destroy(); +} + +static void test_test(void) +{ + qos_graph_init(); + check_test(REGISTER_TEST, SDHCI); + qos_graph_destroy(); +} + +static void test_machine_contains_driver(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + check_driver(I440FX); + check_contains(MACHINE_PC, I440FX); + qos_graph_destroy(); +} + +static void test_driver_contains_driver(void) +{ + qos_graph_init(); + check_driver(PCIBUS_PC); + check_driver(I440FX); + check_contains(PCIBUS_PC, I440FX); + qos_graph_destroy(); +} + +static void test_machine_produces_interface(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + check_produces(MACHINE_PC, SDHCI); + qos_graph_destroy(); +} + +static void test_driver_produces_interface(void) +{ + qos_graph_init(); + check_driver(I440FX); + check_produces(I440FX, SDHCI); + qos_graph_destroy(); +} + +static void test_machine_consumes_interface(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + check_consumes(MACHINE_PC, SDHCI); + qos_graph_destroy(); +} + +static void test_driver_consumes_interface(void) +{ + qos_graph_init(); + check_driver(I440FX); + check_consumes(I440FX, SDHCI); + qos_graph_destroy(); +} + +static void test_test_consumes_interface(void) +{ + qos_graph_init(); + check_test(REGISTER_TEST, SDHCI); + qos_graph_destroy(); +} + +static void test_full_sample(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + check_contains(MACHINE_PC, I440FX); + check_driver(I440FX); + check_driver(PCIBUS_PC); + check_contains(I440FX, PCIBUS_PC); + check_produces(PCIBUS_PC, PCIBUS); + check_driver(SDHCI_PCI); + qos_node_consumes(SDHCI_PCI, PCIBUS, NULL); + check_produces(SDHCI_PCI, SDHCI); + check_driver(SDHCI_MM); + check_produces(SDHCI_MM, SDHCI); + qos_add_test(REGISTER_TEST, SDHCI, testfunct, NULL); + check_leaf_discovered(1); + qos_print_graph(); + qos_graph_destroy(); +} + +static void test_full_sample_raspi(void) +{ + qos_graph_init(); + check_machine(MACHINE_PC); + check_contains(MACHINE_PC, I440FX); + check_driver(I440FX); + check_driver(PCIBUS_PC); + check_contains(I440FX, PCIBUS_PC); + check_produces(PCIBUS_PC, PCIBUS); + check_driver(SDHCI_PCI); + qos_node_consumes(SDHCI_PCI, PCIBUS, NULL); + check_produces(SDHCI_PCI, SDHCI); + check_machine(MACHINE_RASPI2); + check_contains(MACHINE_RASPI2, SDHCI_MM); + check_driver(SDHCI_MM); + check_produces(SDHCI_MM, SDHCI); + qos_add_test(REGISTER_TEST, SDHCI, testfunct, NULL); + qos_print_graph(); + check_leaf_discovered(2); + qos_graph_destroy(); +} + +static void test_cycle(void) +{ + qos_graph_init(); + check_machine(MACHINE_RASPI2); + check_driver("B"); + check_driver("C"); + check_driver("D"); + check_contains(MACHINE_RASPI2, "B"); + check_contains("B", "C"); + check_contains("C", "D"); + check_contains("D", MACHINE_RASPI2); + check_leaf_discovered(0); + qos_print_graph(); + qos_graph_destroy(); +} + +static void test_two_test_same_interface(void) +{ + qos_graph_init(); + check_machine(MACHINE_RASPI2); + check_produces(MACHINE_RASPI2, "B"); + qos_add_test("C", "B", testfunct, NULL); + qos_add_test("D", "B", testfunct, NULL); + check_contains(MACHINE_RASPI2, "B"); + check_leaf_discovered(4); + qos_print_graph(); + qos_graph_destroy(); +} + +static void test_test_in_path(void) +{ + qos_graph_init(); + check_machine(MACHINE_RASPI2); + check_produces(MACHINE_RASPI2, "B"); + qos_add_test("C", "B", testfunct, NULL); + check_driver("D"); + check_consumes("D", "B"); + check_produces("D", "E"); + qos_add_test("F", "E", testfunct, NULL); + check_leaf_discovered(2); + qos_print_graph(); + qos_graph_destroy(); +} + +static void test_double_edge(void) +{ + qos_graph_init(); + check_machine(MACHINE_RASPI2); + check_produces("B", "C"); + qos_node_consumes("C", "B", NULL); + qos_add_test("D", "C", testfunct, NULL); + check_contains(MACHINE_RASPI2, "B"); + qos_print_graph(); + qos_graph_destroy(); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/qgraph/init_nop", init_nop); + g_test_add_func("/qgraph/test_machine", test_machine); + g_test_add_func("/qgraph/test_contains", test_contains); + g_test_add_func("/qgraph/test_multiple_contains", test_multiple_contains); + g_test_add_func("/qgraph/test_produces", test_produces); + g_test_add_func("/qgraph/test_multiple_produces", test_multiple_produces); + g_test_add_func("/qgraph/test_consumes", test_consumes); + g_test_add_func("/qgraph/test_multiple_consumes", + test_multiple_consumes); + g_test_add_func("/qgraph/test_driver", test_driver); + g_test_add_func("/qgraph/test_test", test_test); + g_test_add_func("/qgraph/test_machine_contains_driver", + test_machine_contains_driver); + g_test_add_func("/qgraph/test_driver_contains_driver", + test_driver_contains_driver); + g_test_add_func("/qgraph/test_machine_produces_interface", + test_machine_produces_interface); + g_test_add_func("/qgraph/test_driver_produces_interface", + test_driver_produces_interface); + g_test_add_func("/qgraph/test_machine_consumes_interface", + test_machine_consumes_interface); + g_test_add_func("/qgraph/test_driver_consumes_interface", + test_driver_consumes_interface); + g_test_add_func("/qgraph/test_test_consumes_interface", + test_test_consumes_interface); + g_test_add_func("/qgraph/test_full_sample", test_full_sample); + g_test_add_func("/qgraph/test_full_sample_raspi", test_full_sample_raspi); + g_test_add_func("/qgraph/test_cycle", test_cycle); + g_test_add_func("/qgraph/test_two_test_same_interface", + test_two_test_same_interface); + g_test_add_func("/qgraph/test_test_in_path", test_test_in_path); + g_test_add_func("/qgraph/test_double_edge", test_double_edge); + + g_test_run(); + return 0; +} From patchwork Thu Mar 7 17:29:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Y2N+2u8i"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdNs33Qcz9sNs for ; Fri, 8 Mar 2019 04:46:52 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x6U-0007HL-QL for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:46:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqV-0002r5-Ct for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqU-0007ra-0D for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqT-0007qr-MH for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:13 -0500 Received: by mail-wr1-x442.google.com with SMTP id o17so18418702wrw.3 for ; Thu, 07 Mar 2019 09:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Rj0bBMCz/i1OFKd6w5W+aefBQc2LAB4CG3hoi2l8ef0=; b=Y2N+2u8iB1d+nEMVCzsZ37utX7BAyGPETI3Hzu4z/Mi8Gz3o080dKgfKh9etyJDVqp U6w6HmwmDtExXZy+NS0mK3Jjerz5cqF0dcytJzjzALje0v7uKE4MJLPEftAGJHgfTV5j +e40ns/BvOCMLJZOFaj4jNWVwdhLBRSeDNNq+pnvD3mVHMoO7ReG+TKTiOBWtCt8pnf3 7uWb7opYfXHaQwDdEdQteZScvmQlnKj/yX39lwbuIjdSvzP/yMtPX6nRLbvu/WNee7xJ 7vVJHkyxuBsc3D/v7Ceg24pJpntjxOlK2dbp1K61hCQ7BkHRZfOmecXR8uWCBdP3ecYu x/fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Rj0bBMCz/i1OFKd6w5W+aefBQc2LAB4CG3hoi2l8ef0=; b=LgBAKHa15aTZrk0IFNhkqyiqhKUyzR/7/eCLmLPu3lAY0+/xmHQWrZ2uGvotbZYJQ9 WyVjV0vNkYF2yLWvRum568O9y12AkXkBqJU4bJldutYeCoKtBzS358gymRNXmS5hPVfA uVtitoPOhHGlZXvdnoLfeMzygHEVZ0cHYCTVQIwljuKujl8ru8bXJzoOow2y/knPLcc6 VIaSBrBK8a+ImQEs5ICZpdm/XsK/HJIIVWR2S1zHqm0glIFw5WPV2uZtj4pft3wMRz0A G3tMUqKL0TBMXss3jwEwNan1+GZSqqXCzhidwI5KNwYeUh2+U5YnrmLoVigmSFCVdR/9 Xr2w== X-Gm-Message-State: APjAAAXS/mfBobQaIy1oRqf6vI1EJseHBa64q8fBnY2F4D1OryrtbD8z IjY1hhy1XGZxdPN8V4uqJam41EKQ X-Google-Smtp-Source: APXvYqzSSE1MqOkggd/H8P3Yc4owFE4+DNkeocNg8jOqQVEluuV7ikdF7ZNPC29/QF9QS/Ac9uHsLA== X-Received: by 2002:a5d:574b:: with SMTP id q11mr7449916wrw.41.1551979812182; Thu, 07 Mar 2019 09:30:12 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:13 +0100 Message-Id: <1551979804-6060-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PULL 06/57] tests/libqos: pci-pc driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add pci-bus-pc node, move QPCIBusPC struct declaration in its header (since it will be needed by other drivers) and introduce a setter method for drivers that do not need to allocate but have to initialize QPCIBusPC. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 6 +++- tests/libqos/pci-pc.c | 83 ++++++++++++++++++++++++++++++++------------------ tests/libqos/pci-pc.h | 19 +++++++++++- tests/libqos/pci.c | 32 +++++++++++++++++-- tests/libqos/pci.h | 12 ++++++++ 5 files changed, 118 insertions(+), 34 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 94ace7b..5a7ea15 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -749,11 +749,15 @@ libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o +# Devices +qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) +qos-test-obj-y += $(libqos-pc-obj-y) + check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) check-qtest-generic-y += tests/qos-test$(EXESUF) -tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y) +tests/qos-test$(EXESUF): $(qos-test-obj-y) tests/qmp-test$(EXESUF): tests/qmp-test.o tests/qmp-cmd-test$(EXESUF): tests/qmp-cmd-test.o diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index 43d7082..d729ad4 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -18,15 +18,9 @@ #include "qemu-common.h" - #define ACPI_PCIHP_ADDR 0xae00 #define PCI_EJ_BASE 0x0008 -typedef struct QPCIBusPC -{ - QPCIBus bus; -} QPCIBusPC; - static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr) { return qtest_inb(bus->qts, addr); @@ -116,44 +110,65 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 qtest_outl(bus->qts, 0xcfc, value); } -QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc) +static void *qpci_pc_get_driver(void *obj, const char *interface) { - QPCIBusPC *ret = g_new0(QPCIBusPC, 1); + QPCIBusPC *qpci = obj; + if (!g_strcmp0(interface, "pci-bus")) { + return &qpci->bus; + } + fprintf(stderr, "%s not present in pci-bus-pc\n", interface); + g_assert_not_reached(); +} +void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc) +{ assert(qts); - ret->bus.pio_readb = qpci_pc_pio_readb; - ret->bus.pio_readw = qpci_pc_pio_readw; - ret->bus.pio_readl = qpci_pc_pio_readl; - ret->bus.pio_readq = qpci_pc_pio_readq; + qpci->bus.pio_readb = qpci_pc_pio_readb; + qpci->bus.pio_readw = qpci_pc_pio_readw; + qpci->bus.pio_readl = qpci_pc_pio_readl; + qpci->bus.pio_readq = qpci_pc_pio_readq; + + qpci->bus.pio_writeb = qpci_pc_pio_writeb; + qpci->bus.pio_writew = qpci_pc_pio_writew; + qpci->bus.pio_writel = qpci_pc_pio_writel; + qpci->bus.pio_writeq = qpci_pc_pio_writeq; + + qpci->bus.memread = qpci_pc_memread; + qpci->bus.memwrite = qpci_pc_memwrite; - ret->bus.pio_writeb = qpci_pc_pio_writeb; - ret->bus.pio_writew = qpci_pc_pio_writew; - ret->bus.pio_writel = qpci_pc_pio_writel; - ret->bus.pio_writeq = qpci_pc_pio_writeq; + qpci->bus.config_readb = qpci_pc_config_readb; + qpci->bus.config_readw = qpci_pc_config_readw; + qpci->bus.config_readl = qpci_pc_config_readl; - ret->bus.memread = qpci_pc_memread; - ret->bus.memwrite = qpci_pc_memwrite; + qpci->bus.config_writeb = qpci_pc_config_writeb; + qpci->bus.config_writew = qpci_pc_config_writew; + qpci->bus.config_writel = qpci_pc_config_writel; - ret->bus.config_readb = qpci_pc_config_readb; - ret->bus.config_readw = qpci_pc_config_readw; - ret->bus.config_readl = qpci_pc_config_readl; + qpci->bus.qts = qts; + qpci->bus.pio_alloc_ptr = 0xc000; + qpci->bus.mmio_alloc_ptr = 0xE0000000; + qpci->bus.mmio_limit = 0x100000000ULL; - ret->bus.config_writeb = qpci_pc_config_writeb; - ret->bus.config_writew = qpci_pc_config_writew; - ret->bus.config_writel = qpci_pc_config_writel; + qpci->obj.get_driver = qpci_pc_get_driver; +} - ret->bus.qts = qts; - ret->bus.pio_alloc_ptr = 0xc000; - ret->bus.mmio_alloc_ptr = 0xE0000000; - ret->bus.mmio_limit = 0x100000000ULL; +QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc) +{ + QPCIBusPC *qpci = g_new0(QPCIBusPC, 1); + qpci_init_pc(qpci, qts, alloc); - return &ret->bus; + return &qpci->bus; } void qpci_free_pc(QPCIBus *bus) { - QPCIBusPC *s = container_of(bus, QPCIBusPC, bus); + QPCIBusPC *s; + + if (!bus) { + return; + } + s = container_of(bus, QPCIBusPC, bus); g_free(s); } @@ -172,3 +187,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) qmp_eventwait("DEVICE_DELETED"); } + +static void qpci_pc_register_nodes(void) +{ + qos_node_create_driver("pci-bus-pc", NULL); + qos_node_produces("pci-bus-pc", "pci-bus"); +} + +libqos_init(qpci_pc_register_nodes); diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h index 5be68ba..4690005 100644 --- a/tests/libqos/pci-pc.h +++ b/tests/libqos/pci-pc.h @@ -15,6 +15,22 @@ #include "libqos/pci.h" #include "libqos/malloc.h" +#include "libqos/qgraph.h" + +typedef struct QPCIBusPC { + QOSGraphObject obj; + QPCIBus bus; +} QPCIBusPC; + +/* qpci_init_pc(): + * @ret: A valid QPCIBusPC * pointer + * @qts: The %QTestState for this PC machine + * @alloc: A previously initialized @alloc providing memory for @qts + * + * This function initializes an already allocated + * QPCIBusPC object. + */ +void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc); /* qpci_pc_new(): * @qts: The %QTestState for this PC machine @@ -23,7 +39,8 @@ * This function creates a new QPCIBusPC object, * and properly initialize its fields. * - * Returns a newly allocated QPCIBus. + * Returns the QPCIBus *bus field of a newly + * allocated QPCIBusPC. */ QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc); diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index e8c342c..8257904 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -15,6 +15,7 @@ #include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "libqos/qgraph.h" void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *data), @@ -50,13 +51,20 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, } } +static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn) +{ + g_assert(dev); + + dev->bus = bus; + dev->devfn = devfn; +} + QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) { QPCIDevice *dev; dev = g_malloc0(sizeof(*dev)); - dev->bus = bus; - dev->devfn = devfn; + qpci_device_set(dev, bus, devfn); if (qpci_config_readw(dev, PCI_VENDOR_ID) == 0xFFFF) { g_free(dev); @@ -66,6 +74,17 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) return dev; } +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr) +{ + uint16_t vendor_id, device_id; + + qpci_device_set(dev, bus, addr->devfn); + vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID); + device_id = qpci_config_readw(dev, PCI_DEVICE_ID); + g_assert(!addr->vendor_id || vendor_id == addr->vendor_id); + g_assert(!addr->device_id || device_id == addr->device_id); +} + void qpci_device_enable(QPCIDevice *dev) { uint16_t cmd; @@ -395,3 +414,12 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr) QPCIBar bar = { .addr = addr }; return bar; } + +void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr) +{ + g_assert(addr); + g_assert(opts); + + opts->arg = addr; + opts->size_arg = sizeof(QPCIAddress); +} diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index 0b7e936..9fd521a 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -14,6 +14,7 @@ #define LIBQOS_PCI_H #include "libqtest.h" +#include "libqos/qgraph.h" #define QPCI_PIO_LIMIT 0x10000 @@ -22,6 +23,7 @@ typedef struct QPCIDevice QPCIDevice; typedef struct QPCIBus QPCIBus; typedef struct QPCIBar QPCIBar; +typedef struct QPCIAddress QPCIAddress; struct QPCIBus { uint8_t (*pio_readb)(QPCIBus *bus, uint32_t addr); @@ -51,6 +53,7 @@ struct QPCIBus { QTestState *qts; uint16_t pio_alloc_ptr; uint64_t mmio_alloc_ptr, mmio_limit; + }; struct QPCIBar { @@ -66,10 +69,17 @@ struct QPCIDevice uint64_t msix_table_off, msix_pba_off; }; +struct QPCIAddress { + uint32_t devfn; + uint16_t vendor_id; + uint16_t device_id; +}; + void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *data), void *data); QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn); +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr); void qpci_device_enable(QPCIDevice *dev); uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id); @@ -110,4 +120,6 @@ void qpci_iounmap(QPCIDevice *dev, QPCIBar addr); QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr); void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); + +void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr); #endif From patchwork Thu Mar 7 17:29:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JPjP5JxB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdSc2Z0rz9sNB for ; Fri, 8 Mar 2019 04:50:08 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x9i-0001OF-C6 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:50:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqW-0002sN-Ip for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqV-0007sT-4K for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:16 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:53656) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqU-0007rY-My for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: by mail-wm1-x32c.google.com with SMTP id e74so10066371wmg.3 for ; Thu, 07 Mar 2019 09:30:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4f96miqlDQnqH5jBEIDnorZ6/qIF6M4o3BxJP/ggJwU=; b=JPjP5JxB/FzmYvtcViJt58/VkmA3pivWF3q9YfGuzaQfqYJBuHOlwarVQYuV6EMKYV qDMJa1MQIdnPf/epFHyWKW1Dx2VsSTR1mTc/a4fWEypveo5P/leMqpP5hy/B+uHKLqzm fgrbgaFvvoKa3ZI+6I1MIegiX4ihKEqcRmPBcLpsOwymvvyuz1a6OiPONDQ6EF4iSXx+ ojsa9AvQB9c3Ji8hxdmAOo4wCdJZ7+DWsVGgnrkFBVUsfnGQpmvn7Ye8V2bPP2O9rrDI wMl6dXhu1IetGh9dxyLcEzf02mWJgL1FcXmTTCurJP9voqE2vIW9s381HqyDsCgso7MW Wz9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4f96miqlDQnqH5jBEIDnorZ6/qIF6M4o3BxJP/ggJwU=; b=CBaQdqdloAu6f/rdiPL5KmNxmB28Q9VvsWlyCl4VuVz5r9QrEJlI1RXt6Q7LwNIA7h /XflAXATVkUEG2uAqHK6Q1yajV/b7ONr73BfSQSeSUdfDJZM//VBpbARP04s9en0CcyT O5E2JZEM7G+4jhza8iF25VecMl62JpgCi0Kxz1Adrp95B3+v0KrD5Af5vuEWUmhOS7TA GOXAI01i25Cjd4dbNWKBVLj27hokuudspkmMAr2S8npRex60W7mrdHtmL8OyAyGFt2Fb NunxIJR4lLm6/7G8zyiGrOAGb4b2cV/zclj3880zyDDRwvAwm2JRgIcuu84UbIMeox33 Lf3A== X-Gm-Message-State: APjAAAVzTgi4XP4SKPitWfpFwTQW8ohDz8sChoQSQs72r3YHfOr/Hmc1 BubScKrrcY9uHykE7YjW4rhxBeWh X-Google-Smtp-Source: APXvYqw15Rgjg2om337EBVavm2cZKrAHoJ/NhQdcM6sdDmevO1PpmULS4pfr/ynPl64fYV9gzLU0jw== X-Received: by 2002:a7b:c94c:: with SMTP id i12mr6324736wml.2.1551979813228; Thu, 07 Mar 2019 09:30:13 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:14 +0100 Message-Id: <1551979804-6060-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32c Subject: [Qemu-devel] [PULL 07/57] tests/libqos: x86_64/pc machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add pc machine for the x86_64 QEMU binary. This machine contains an i440FX-pcihost driver, that contains itself a pci-bus-pc that produces the pci-bus interface. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 ++ tests/libqos/x86_64_pc-machine.c | 114 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/libqos/x86_64_pc-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 5a7ea15..8a760bd 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -753,6 +753,9 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) +# Machines +qos-test-obj-y += tests/libqos/x86_64_pc-machine.o + check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) diff --git a/tests/libqos/x86_64_pc-machine.c b/tests/libqos/x86_64_pc-machine.c new file mode 100644 index 0000000..8bd0360 --- /dev/null +++ b/tests/libqos/x86_64_pc-machine.c @@ -0,0 +1,114 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "pci-pc.h" +#include "malloc-pc.h" + +typedef struct QX86PCMachine QX86PCMachine; +typedef struct i440FX_pcihost i440FX_pcihost; +typedef struct QSDHCI_PCI QSDHCI_PCI; + +struct i440FX_pcihost { + QOSGraphObject obj; + QPCIBusPC pci; +}; + +struct QX86PCMachine { + QOSGraphObject obj; + QGuestAllocator alloc; + i440FX_pcihost bridge; +}; + +/* i440FX_pcihost */ + +static QOSGraphObject *i440FX_host_get_device(void *obj, const char *device) +{ + i440FX_pcihost *host = obj; + if (!g_strcmp0(device, "pci-bus-pc")) { + return &host->pci.obj; + } + fprintf(stderr, "%s not present in i440FX-pcihost\n", device); + g_assert_not_reached(); +} + +static void qos_create_i440FX_host(i440FX_pcihost *host, + QTestState *qts, + QGuestAllocator *alloc) +{ + host->obj.get_device = i440FX_host_get_device; + qpci_init_pc(&host->pci, qts, alloc); +} + +/* x86_64/pc machine */ + +static void pc_destructor(QOSGraphObject *obj) +{ + QX86PCMachine *machine = (QX86PCMachine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *pc_get_driver(void *object, const char *interface) +{ + QX86PCMachine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in x86_64/pc\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *pc_get_device(void *obj, const char *device) +{ + QX86PCMachine *machine = obj; + if (!g_strcmp0(device, "i440FX-pcihost")) { + return &machine->bridge.obj; + } + + fprintf(stderr, "%s not present in x86_64/pc\n", device); + g_assert_not_reached(); +} + +static void *qos_create_machine_pc(QTestState *qts) +{ + QX86PCMachine *machine = g_new0(QX86PCMachine, 1); + machine->obj.get_device = pc_get_device; + machine->obj.get_driver = pc_get_driver; + machine->obj.destructor = pc_destructor; + pc_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS); + qos_create_i440FX_host(&machine->bridge, qts, &machine->alloc); + + return &machine->obj; +} + +static void pc_machine_register_nodes(void) +{ + qos_node_create_machine("i386/pc", qos_create_machine_pc); + qos_node_contains("i386/pc", "i440FX-pcihost", NULL); + + qos_node_create_machine("x86_64/pc", qos_create_machine_pc); + qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL); + + qos_node_create_driver("i440FX-pcihost", NULL); + qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL); +} + +libqos_init(pc_machine_register_nodes); From patchwork Thu Mar 7 17:29:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="e8k88tvX"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdZy16bVz9s1B for ; Fri, 8 Mar 2019 04:55:37 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xF0-0006Os-R6 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:55:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqX-0002tD-GC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqV-0007tD-W0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:17 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35869) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqV-0007sN-Ky for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: by mail-wr1-x42c.google.com with SMTP id o17so18418897wrw.3 for ; Thu, 07 Mar 2019 09:30:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=MqLceWYo/1aDeyMKe7IYbzY2aLftA8ogYskRfKhqnGI=; b=e8k88tvXsG+FSgqZzM4ySSmxHyC00L6Yv/zPkd1Do6/dWBFdSArQ77x4D9kmXI6dIx G9TjjhRQaDMyUlR5YSV448JplVMEe/VZxA+FjmHKWxR38+D1kOWGXxak9hBICuHA+6J7 b0IFsyUC7LVQ5N9MDr900E/7phI00muQ/qNHkzP0zTDHsy1CchHz1lgI6FTutTA+Nph5 SL25/p0Mck6v07N9etdsEB75z/q/N3/y8L4BICl8Wo2M3UwrOjyEp1aafKQRMehsRlx4 mLAosxrrqNNzot7rWmsNrLy2NINpAnRA3BP0feJSn3Mvt44lXe2ejurV54LUeFkJSl0b cz2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=MqLceWYo/1aDeyMKe7IYbzY2aLftA8ogYskRfKhqnGI=; b=burZA7kcZNKMxuJZq1KU/ONdYm9S3Hucckt4Wj8LXy99oTtCwcrVlWQp6rrDNebeqC qFJltWIayN+SFQYZGLig+5JAQqZPvAK5AD65iu67kKlzA5hK3vYsDgD2i9xTALM6lze9 Hu5vOFWSmvYWU8tIJnQySpjWTHHWNDnzB2W5er+d3mQHm9Xdsm1eeB7SkIvSf2ZmToIn AhCCXUVf9PBB4Oe6AmIpN2DJmQsPc+5sAJYV/wrqooV21vqCdec4F2lxoMXxLQQ4Z+p8 D8qJGoZEdCCI4FnnWMXhuAtVnU8uRq53nlPD6U99FeAj2orj0U4UHUo10H620satOiQ2 55IQ== X-Gm-Message-State: APjAAAXAgpNjiyIOeJbTQSlsiHdbiae25s51J4m72CmAFbx8t5i9Dyzy 2Ai1WLYtv4YbDz9Et21nAqGjSBEs X-Google-Smtp-Source: APXvYqzXJxvAs3RX/58ObVDKhnHzkJlrCRwGep7UmJJQB+YgZvWevdtknhHwotkJLWbuMIvvd+FerQ== X-Received: by 2002:a5d:4145:: with SMTP id c5mr7586776wrq.256.1551979814233; Thu, 07 Mar 2019 09:30:14 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:15 +0100 Message-Id: <1551979804-6060-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 08/57] tests/libqos: sdhci driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for sdhci-pci and generic-sdhci (memory mapped) drivers. Both drivers implement (produce) the same interface sdhci, that provides the readw - readq - writeq functions. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/sdhci.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/sdhci.h | 70 +++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 tests/libqos/sdhci.c create mode 100644 tests/libqos/sdhci.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 8a760bd..b1b03e6 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -752,6 +752,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt # Devices qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) +qos-test-obj-y += tests/libqos/sdhci.o # Machines qos-test-obj-y += tests/libqos/x86_64_pc-machine.o diff --git a/tests/libqos/sdhci.c b/tests/libqos/sdhci.c new file mode 100644 index 0000000..22c33de --- /dev/null +++ b/tests/libqos/sdhci.c @@ -0,0 +1,163 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "pci.h" +#include "sdhci.h" +#include "hw/pci/pci.h" + +static void set_qsdhci_fields(QSDHCI *s, uint8_t version, uint8_t baseclock, + bool sdma, uint64_t reg) +{ + s->props.version = version; + s->props.baseclock = baseclock; + s->props.capab.sdma = sdma; + s->props.capab.reg = reg; +} + +/* Memory mapped implementation of QSDHCI */ + +static uint16_t sdhci_mm_readw(QSDHCI *s, uint32_t reg) +{ + QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci); + return qtest_readw(smm->qts, smm->addr + reg); +} + +static uint64_t sdhci_mm_readq(QSDHCI *s, uint32_t reg) +{ + QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci); + return qtest_readq(smm->qts, smm->addr + reg); +} + +static void sdhci_mm_writeq(QSDHCI *s, uint32_t reg, uint64_t val) +{ + QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci); + qtest_writeq(smm->qts, smm->addr + reg, val); +} + +static void *sdhci_mm_get_driver(void *obj, const char *interface) +{ + QSDHCI_MemoryMapped *smm = obj; + if (!g_strcmp0(interface, "sdhci")) { + return &smm->sdhci; + } + fprintf(stderr, "%s not present in generic-sdhci\n", interface); + g_assert_not_reached(); +} + +void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, QTestState *qts, + uint32_t addr, QSDHCIProperties *common) +{ + sdhci->obj.get_driver = sdhci_mm_get_driver; + sdhci->sdhci.readw = sdhci_mm_readw; + sdhci->sdhci.readq = sdhci_mm_readq; + sdhci->sdhci.writeq = sdhci_mm_writeq; + memcpy(&sdhci->sdhci.props, common, sizeof(QSDHCIProperties)); + sdhci->addr = addr; + sdhci->qts = qts; +} + +/* PCI implementation of QSDHCI */ + +static uint16_t sdhci_pci_readw(QSDHCI *s, uint32_t reg) +{ + QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci); + return qpci_io_readw(&spci->dev, spci->mem_bar, reg); +} + +static uint64_t sdhci_pci_readq(QSDHCI *s, uint32_t reg) +{ + QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci); + return qpci_io_readq(&spci->dev, spci->mem_bar, reg); +} + +static void sdhci_pci_writeq(QSDHCI *s, uint32_t reg, uint64_t val) +{ + QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci); + return qpci_io_writeq(&spci->dev, spci->mem_bar, reg, val); +} + +static void *sdhci_pci_get_driver(void *object, const char *interface) +{ + QSDHCI_PCI *spci = object; + if (!g_strcmp0(interface, "sdhci")) { + return &spci->sdhci; + } + + fprintf(stderr, "%s not present in sdhci-pci\n", interface); + g_assert_not_reached(); +} + +static void sdhci_pci_start_hw(QOSGraphObject *obj) +{ + QSDHCI_PCI *spci = (QSDHCI_PCI *)obj; + qpci_device_enable(&spci->dev); +} + +static void sdhci_destructor(QOSGraphObject *obj) +{ + QSDHCI_PCI *spci = (QSDHCI_PCI *)obj; + qpci_iounmap(&spci->dev, spci->mem_bar); +} + +static void *sdhci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr) +{ + QSDHCI_PCI *spci = g_new0(QSDHCI_PCI, 1); + QPCIBus *bus = pci_bus; + uint64_t barsize; + + qpci_device_init(&spci->dev, bus, addr); + spci->mem_bar = qpci_iomap(&spci->dev, 0, &barsize); + spci->sdhci.readw = sdhci_pci_readw; + spci->sdhci.readq = sdhci_pci_readq; + spci->sdhci.writeq = sdhci_pci_writeq; + set_qsdhci_fields(&spci->sdhci, 2, 0, 1, 0x057834b4); + + spci->obj.get_driver = sdhci_pci_get_driver; + spci->obj.start_hw = sdhci_pci_start_hw; + spci->obj.destructor = sdhci_destructor; + return &spci->obj; +} + +static void qsdhci_register_nodes(void) +{ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + .vendor_id = PCI_VENDOR_ID_REDHAT, + .device_id = PCI_DEVICE_ID_REDHAT_SDHCI, + }; + + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + + /* generic-sdhci */ + qos_node_create_driver("generic-sdhci", NULL); + qos_node_produces("generic-sdhci", "sdhci"); + + /* sdhci-pci */ + add_qpci_address(&opts, &addr); + qos_node_create_driver("sdhci-pci", sdhci_pci_create); + qos_node_produces("sdhci-pci", "sdhci"); + qos_node_consumes("sdhci-pci", "pci-bus", &opts); + +} + +libqos_init(qsdhci_register_nodes); diff --git a/tests/libqos/sdhci.h b/tests/libqos/sdhci.h new file mode 100644 index 0000000..032d815 --- /dev/null +++ b/tests/libqos/sdhci.h @@ -0,0 +1,70 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef QGRAPH_QSDHCI +#define QGRAPH_QSDHCI + +#include "libqos/qgraph.h" +#include "pci.h" + +typedef struct QSDHCI QSDHCI; +typedef struct QSDHCI_MemoryMapped QSDHCI_MemoryMapped; +typedef struct QSDHCI_PCI QSDHCI_PCI; +typedef struct QSDHCIProperties QSDHCIProperties; + +/* Properties common to all QSDHCI devices */ +struct QSDHCIProperties { + uint8_t version; + uint8_t baseclock; + struct { + bool sdma; + uint64_t reg; + } capab; +}; + +struct QSDHCI { + uint16_t (*readw)(QSDHCI *s, uint32_t reg); + uint64_t (*readq)(QSDHCI *s, uint32_t reg); + void (*writeq)(QSDHCI *s, uint32_t reg, uint64_t val); + QSDHCIProperties props; +}; + +/* Memory Mapped implementation of QSDHCI */ +struct QSDHCI_MemoryMapped { + QOSGraphObject obj; + QTestState *qts; + QSDHCI sdhci; + uint64_t addr; +}; + +/* PCI implementation of QSDHCI */ +struct QSDHCI_PCI { + QOSGraphObject obj; + QPCIDevice dev; + QSDHCI sdhci; + QPCIBar mem_bar; +}; + +/** + * qos_init_sdhci_mm(): external constructor used by all drivers/machines + * that "contain" a #QSDHCI_MemoryMapped driver + */ +void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, QTestState *qts, + uint32_t addr, QSDHCIProperties *common); + +#endif From patchwork Thu Mar 7 17:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nA2x8IGH"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdf80GLNz9sD4 for ; Fri, 8 Mar 2019 04:58:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xHh-0000TV-Cu for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:58:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqY-0002tv-7p for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqX-0007tx-7X for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:18 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:42108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqW-0007tQ-Ve for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:17 -0500 Received: by mail-wr1-x429.google.com with SMTP id r5so18398151wrg.9 for ; Thu, 07 Mar 2019 09:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gRQtJP4aVVEtFFsiyWmcf17aJjmb84pPeK7GLf6s4aQ=; b=nA2x8IGHhYXC4el9HoPGyeG/L61RnjMBuU0KffTshnHE0sBUqRZsHPDYiucnQ2pGJ6 VjeN/2IPJnIoaQCpD4bm7DB+fnVmnN0PerW+aQYDxrrZ0xYNhKD0NMQTu+alhGMaBtZe RxytWRtC5KA8t1DHINLQx0h/idhEUgTOncrdQM41EalXw10X8ldy1GS1vslGaRvXQv16 6kplRAT2r8h/MjMsRUtcK2CG65js8SPE2gxn4vM3wmLoHiVPK7UluySK1XGflGCra/iy jY11Nvpszp+s4SWx759O64JjX5oGQSBSMZOD8hKecNp624UGIp1hAG/tRXEzMAuh6DuB Pt2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=gRQtJP4aVVEtFFsiyWmcf17aJjmb84pPeK7GLf6s4aQ=; b=UyUJEH993d37hJYfHkpmgnEnTMGTxhxCoq7eTyxXx7qAE2tYykAgVEcydktvC00viw ZloCbvBghRBzbY8WUlKIjV4K0CDWILVEPbOqhM9dq2WvVxzqjzDrsvIXyxRUFRZW1xGX CDEqbH/0Vb+YlzjHSkZBQs+H9xBk08/51p3Z+2bYdx6QKadWyZjhg8jc5EqhA/m68AcG c47uvWPHGAtLTSlz3FmIIUSXD7fwh1/oDic2Wfdt8NCJkQjiYgmltYa+rr9sNrhKff3P c84wjoK8TeVOSSklnLjMvcSwLfNEXsEnHiGxURI2/BNR5W2UdGhsR4gzbwhx1BBTwhCR yyAg== X-Gm-Message-State: APjAAAXYetQcXOlnAQLOspx4MqCIbgAxbtvgLNhZOXAS22JPm4uN6fKp 928e6L87+1VHY6sJOkrv8+OIqpQa X-Google-Smtp-Source: APXvYqwxF9RRDVViPKi3vbJ7d6T8unXNJ/wR7CvTX4xYNKx0kCV9TPqQ0BykpO0Y8bR2Z3Fz/m6UQw== X-Received: by 2002:a5d:558c:: with SMTP id i12mr7575251wrv.19.1551979815610; Thu, 07 Mar 2019 09:30:15 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:16 +0100 Message-Id: <1551979804-6060-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::429 Subject: [Qemu-devel] [PULL 09/57] tests/libqos: arm/raspi2 machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add arm/raspi2 machine to the graph. This machine contains a generic-sdhci, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-raspi2-machine.c | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/libqos/arm-raspi2-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index b1b03e6..41d248d 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -755,6 +755,7 @@ qos-test-obj-y += $(libqos-pc-obj-y) qos-test-obj-y += tests/libqos/sdhci.o # Machines +qos-test-obj-y += tests/libqos/arm-raspi2-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o check-unit-y += tests/test-qgraph$(EXESUF) diff --git a/tests/libqos/arm-raspi2-machine.c b/tests/libqos/arm-raspi2-machine.c new file mode 100644 index 0000000..3aff670 --- /dev/null +++ b/tests/libqos/arm-raspi2-machine.c @@ -0,0 +1,91 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "sdhci.h" + +#define ARM_PAGE_SIZE 4096 +#define RASPI2_RAM_ADDR 0 +#define RASPI2_RAM_SIZE 0x20000000 + +typedef struct QRaspi2Machine QRaspi2Machine; + +struct QRaspi2Machine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSDHCI_MemoryMapped sdhci; +}; + +static void *raspi2_get_driver(void *object, const char *interface) +{ + QRaspi2Machine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/raspi2\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *raspi2_get_device(void *obj, const char *device) +{ + QRaspi2Machine *machine = obj; + if (!g_strcmp0(device, "generic-sdhci")) { + return &machine->sdhci.obj; + } + + fprintf(stderr, "%s not present in arm/raspi2\n", device); + g_assert_not_reached(); +} + +static void raspi2_destructor(QOSGraphObject *obj) +{ + QRaspi2Machine *machine = (QRaspi2Machine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_raspi2(QTestState *qts) +{ + QRaspi2Machine *machine = g_new0(QRaspi2Machine, 1); + + alloc_init(&machine->alloc, 0, + RASPI2_RAM_ADDR + (1 << 20), + RASPI2_RAM_ADDR + RASPI2_RAM_SIZE, + ARM_PAGE_SIZE); + machine->obj.get_device = raspi2_get_device; + machine->obj.get_driver = raspi2_get_driver; + machine->obj.destructor = raspi2_destructor; + qos_init_sdhci_mm(&machine->sdhci, qts, 0x3f300000, &(QSDHCIProperties) { + .version = 3, + .baseclock = 52, + .capab.sdma = false, + .capab.reg = 0x052134b4 + }); + return &machine->obj; +} + +static void raspi2_register_nodes(void) +{ + qos_node_create_machine("arm/raspi2", qos_create_machine_arm_raspi2); + qos_node_contains("arm/raspi2", "generic-sdhci", NULL); +} + +libqos_init(raspi2_register_nodes); From patchwork Thu Mar 7 17:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="igyKSBLT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdQ908tBz9sNF for ; Fri, 8 Mar 2019 04:48:01 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x7e-0008Cr-Ud for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:47:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqZ-0002vj-Se for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqY-0007v1-By for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:19 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:35868) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqY-0007uE-3F for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:18 -0500 Received: by mail-wr1-x42a.google.com with SMTP id o17so18419085wrw.3 for ; Thu, 07 Mar 2019 09:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=w8UtGXHxxOD7uSjdCIM7I57GrVcLCDRxU8RwJ5uXpKg=; b=igyKSBLTyTHrrcFtC5g+Wa32PGVeYYnwC/wRoHyEa1Qa8mYbAtfskOXkU8PKFiwzzw Zl64CxpjXq+iXsdqB/yjWHwXl+jBCosxt3BweDBwyAtpuk3Nsv//nJVaDV/2EudEDs4T ++4b/oGK3eIOZWFkD335eCuW78i8OZWl2ebDyqGSFnnuHTgTRYkTA4kIlN8gwXXUwA1j dFty3EMxnTlv0ppiPTGk5t3WWg8Ks1x5cRGUSu7WKSnyLJXvFNDn2ovkf4/wrMQDkAZc FnQ7aB4SPaE248ssEiByewyugu9G+WgauWt7L32bq8033W+Lfw5s467G18YJE/mLn/VZ tb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=w8UtGXHxxOD7uSjdCIM7I57GrVcLCDRxU8RwJ5uXpKg=; b=F3X2agzUVvBsU9bga8zdgXyAXK6Wd0ehiimKojlaMtrzG++uKV9odjEXB7wOY++V4L PGhBSUnUec0Qv8MHbS3RQCG5J1oYAuOthG87yC5SIXfcnN9+H611eJzPUv7JQLQhSf0N Ft8Sg2t0zwR4cfQ5NfDGIhTM4XWRnvUfys5jpqUEJXoY/NZazK6I3g9TfbkcRAUN47Gw gsk/QPMSQretT6JbuQQXtBH3VXqki4kNg5YoDKo/+j7AcWbsTzKdvxfCrbGsET4bEhK6 CPuJZgcRBiJmwT2EtTNLnoIM+DxpXbrCjMO426kPMpC+KPvpM3hodC0xvWSZR9WLj36G FqxA== X-Gm-Message-State: APjAAAWiCazgSLPDtQRelGFpIJPs03dbg1OgzN5mWxegEjXv+9J3vqD6 386rp1AuzEScxypNbsU7KG47Svhz X-Google-Smtp-Source: APXvYqxS1WMkMUuKIMhyCZkbESuDo9MG1kMRMrR/TddUTBXGnM9HzGBEkDOtBIp4QSoyEdvgPPou4Q== X-Received: by 2002:a5d:4804:: with SMTP id l4mr7970098wrq.177.1551979816656; Thu, 07 Mar 2019 09:30:16 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:15 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:17 +0100 Message-Id: <1551979804-6060-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42a Subject: [Qemu-devel] [PULL 10/57] tests/libqos: arm/smdkc210 machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add arm/smdkc210 machine machine to the graph. This machine contains generic-sdhci, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-smdkc210-machine.c | 91 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/libqos/arm-smdkc210-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 41d248d..959d026 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -756,6 +756,7 @@ qos-test-obj-y += tests/libqos/sdhci.o # Machines qos-test-obj-y += tests/libqos/arm-raspi2-machine.o +qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o check-unit-y += tests/test-qgraph$(EXESUF) diff --git a/tests/libqos/arm-smdkc210-machine.c b/tests/libqos/arm-smdkc210-machine.c new file mode 100644 index 0000000..1fb9dfc --- /dev/null +++ b/tests/libqos/arm-smdkc210-machine.c @@ -0,0 +1,91 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "sdhci.h" + +#define ARM_PAGE_SIZE 4096 +#define SMDKC210_RAM_ADDR 0x40000000ull +#define SMDKC210_RAM_SIZE 0x40000000ull + +typedef struct QSmdkc210Machine QSmdkc210Machine; + +struct QSmdkc210Machine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSDHCI_MemoryMapped sdhci; +}; + +static void *smdkc210_get_driver(void *object, const char *interface) +{ + QSmdkc210Machine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/smdkc210\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *smdkc210_get_device(void *obj, const char *device) +{ + QSmdkc210Machine *machine = obj; + if (!g_strcmp0(device, "generic-sdhci")) { + return &machine->sdhci.obj; + } + + fprintf(stderr, "%s not present in arm/smdkc210\n", device); + g_assert_not_reached(); +} + +static void smdkc210_destructor(QOSGraphObject *obj) +{ + QSmdkc210Machine *machine = (QSmdkc210Machine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_smdkc210(QTestState *qts) +{ + QSmdkc210Machine *machine = g_new0(QSmdkc210Machine, 1); + + alloc_init(&machine->alloc, 0, + SMDKC210_RAM_ADDR, + SMDKC210_RAM_ADDR + SMDKC210_RAM_SIZE, + ARM_PAGE_SIZE); + machine->obj.get_device = smdkc210_get_device; + machine->obj.get_driver = smdkc210_get_driver; + machine->obj.destructor = smdkc210_destructor; + qos_init_sdhci_mm(&machine->sdhci, qts, 0x12510000, &(QSDHCIProperties) { + .version = 2, + .baseclock = 0, + .capab.sdma = true, + .capab.reg = 0x5e80080, + }); + return &machine->obj; +} + +static void smdkc210_register_nodes(void) +{ + qos_node_create_machine("arm/smdkc210", qos_create_machine_arm_smdkc210); + qos_node_contains("arm/smdkc210", "generic-sdhci", NULL); +} + +libqos_init(smdkc210_register_nodes); From patchwork Thu Mar 7 17:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ogyrj+FB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdLv2r93z9sD4 for ; Fri, 8 Mar 2019 04:45:11 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x4v-0005zJ-Cm for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:45:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqb-0002x2-0a for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqZ-0007wd-Se for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:20 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:50667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqZ-0007vb-Ew for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:19 -0500 Received: by mail-wm1-x329.google.com with SMTP id x7so10090906wmj.0 for ; Thu, 07 Mar 2019 09:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3f55o9UjAoS/ed/61y7wMoloYdAQSCRtYGIZYtfr5nU=; b=ogyrj+FB1NhUGZDySZrWvZxwqHxjLtMUFqG3W1KtvEQ8Y7n2I/ZK4HAsViu/08PvkH ojIjso+EpAJ2pVbgYURVhIgiFB03IvXRX4g0M4scKiy0BH8XumES7Vh5TPUu6KAa9Jkq 35AK9OcIgN1KikAvVFxCZfv3Kjw2Yg6LcIAPicj59xGwxGF+4iyKMub5iRefc2Fgunew +d40rLgibA0kI/D70RkA0lkjzKrhc2GQ3IVig9s/xuhhfc75bgK4BicvaqJcxXN+vZ7G BmqWc3IaVjWUTddCmUGljk+pIxqXb+VSQ/9AcGOc5X0w2p52/pgMX3KLUh4aZqhF4h+5 CCUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3f55o9UjAoS/ed/61y7wMoloYdAQSCRtYGIZYtfr5nU=; b=ha7uvfoSwz+EQ0oM2RLj53hi7f/duvP8JZ3vrOq5giLIGXT+FzEj2RKSXmhS+UHoBF he6parBVqxaPLUfW5LOI1JmwoDvugK8YqwEE00B8WyGeQg2uoo3OW9jZSfN2fgcjIoJk M5x/vC8sXytCwU381CP+f1kV7JdVBUfX4mNBPbY9uE1SZDu8OxV78jquinm4ekfbX0I9 icHS5Sgx/E3rd/LcQHAfQ1nhuNFwF1LtJA+NiNlsBB0WuHIwYeWmeur3nsHnjFh/5LH7 M3Sx4MIyEa5z2qIKD6bu5IeeCdSTo7/KM3X0gnowcfvROQ0TVsQ/8F5xXmfHoU1R6cFs 3q0A== X-Gm-Message-State: APjAAAVWTkzqee3R0PtDZVpmViaV4Wh4DTteBfcZkmgINyfYQ6rq7pO1 nT8lwRZ3+y45W9VEhJwS0HMX6H8d X-Google-Smtp-Source: APXvYqw2gMEnxjH3L8v3n7r1DX0Qc4HO9Ob2uFvl74C9t6gH3j0mWpuqM6xFJEA6BWeg2Z0CYjd4hA== X-Received: by 2002:a7b:c74b:: with SMTP id w11mr6284503wmk.79.1551979817888; Thu, 07 Mar 2019 09:30:17 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:17 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:18 +0100 Message-Id: <1551979804-6060-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 Subject: [Qemu-devel] [PULL 11/57] tests/libqos: arm/sabrelite machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add arm/sabrelite machine to the graph. This machine contains generic-sdhci, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-sabrelite-machine.c | 91 ++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/libqos/arm-sabrelite-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 959d026..4758352 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -756,6 +756,7 @@ qos-test-obj-y += tests/libqos/sdhci.o # Machines qos-test-obj-y += tests/libqos/arm-raspi2-machine.o +qos-test-obj-y += tests/libqos/arm-sabrelite-machine.o qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o diff --git a/tests/libqos/arm-sabrelite-machine.c b/tests/libqos/arm-sabrelite-machine.c new file mode 100644 index 0000000..c4128d8 --- /dev/null +++ b/tests/libqos/arm-sabrelite-machine.c @@ -0,0 +1,91 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "sdhci.h" + +#define ARM_PAGE_SIZE 4096 +#define SABRELITE_RAM_START 0x10000000 +#define SABRELITE_RAM_END 0x30000000 + +typedef struct QSabreliteMachine QSabreliteMachine; + +struct QSabreliteMachine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSDHCI_MemoryMapped sdhci; +}; + +static void *sabrelite_get_driver(void *object, const char *interface) +{ + QSabreliteMachine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/sabrelite\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *sabrelite_get_device(void *obj, const char *device) +{ + QSabreliteMachine *machine = obj; + if (!g_strcmp0(device, "generic-sdhci")) { + return &machine->sdhci.obj; + } + + fprintf(stderr, "%s not present in arm/sabrelite\n", device); + g_assert_not_reached(); +} + +static void sabrelite_destructor(QOSGraphObject *obj) +{ + QSabreliteMachine *machine = (QSabreliteMachine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_sabrelite(QTestState *qts) +{ + QSabreliteMachine *machine = g_new0(QSabreliteMachine, 1); + + alloc_init(&machine->alloc, 0, + SABRELITE_RAM_START, + SABRELITE_RAM_END, + ARM_PAGE_SIZE); + machine->obj.get_device = sabrelite_get_device; + machine->obj.get_driver = sabrelite_get_driver; + machine->obj.destructor = sabrelite_destructor; + qos_init_sdhci_mm(&machine->sdhci, qts, 0x02190000, &(QSDHCIProperties) { + .version = 3, + .baseclock = 0, + .capab.sdma = true, + .capab.reg = 0x057834b4, + }); + return &machine->obj; +} + +static void sabrelite_register_nodes(void) +{ + qos_node_create_machine("arm/sabrelite", qos_create_machine_arm_sabrelite); + qos_node_contains("arm/sabrelite", "generic-sdhci", NULL); +} + +libqos_init(sabrelite_register_nodes); From patchwork Thu Mar 7 17:29:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oSb4uBxz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdX94kwjz9sNN for ; Fri, 8 Mar 2019 04:53:13 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xCh-0004Gs-Kd for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:53:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqc-0002yD-1L for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqa-0007xJ-P0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:22 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:39009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqa-0007wi-Gk for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:20 -0500 Received: by mail-wm1-x335.google.com with SMTP id z84so10074253wmg.4 for ; Thu, 07 Mar 2019 09:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qsg9qPMrbGORnhwvhcDNuGbu0oB8D6wNji1DeUCKqWY=; b=oSb4uBxzInHV6qMGLI9w+SUdzXBL4PPFo668OtMs4Zm4VzJRcSi4YhYac5NmewIIHa JhUD19DkfTVkC78H477YKHEi68jiJ66T7CII/vimueRIdAJFQxg8MpTZJKCc40nvAQoq 6q0fFniXfupajnL487wJhTkkDTwkhXom4WrgdShJl7kmB7/DK9PYM8ywbMwmmWTpaMTC ZsTykyJrDeDl+uSTb0bWQsSBKfjHTsao/fiuvceVKaKRj8MWaos5DWqfM4AfJaeZfQhg K0KmpjklARmKiHKoMAFZG/3PrkID1s0HUINQGoz1Zhy2sAjZXGTivHQTDxWstIA6zMOc 5jNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Qsg9qPMrbGORnhwvhcDNuGbu0oB8D6wNji1DeUCKqWY=; b=BAvKpKb/3H/qbY/d1aW9K7LmItQoeVSzxJ4pXLPfE0Y502we9b9rc7ge79uazWthhc n3tPJL6aiJuJxFuA4fdFq0TnKfa1xmoug1WjHvqvnOiCYOcnLCstAZ9ERDGgC9vEFrmo LrGuwyMnaVFb/FsUHyq5uMBC+W50MbfFNxeQR0UdgjH0/CrY0ndywuXC0Ih1AV5ql24o B2Ibu9BI7LtTOyOFrzezAGxjXtxSSPbH5LL+zcr+EHmnK6hZ01Nz8viTOoJraJjGJqgI YoubmJ3PmrUYc6FFvWLuEZGqCyE431klrn2Onl/uB3992SSrRtkW0e5nSK+/9QaMdpIU B1Zw== X-Gm-Message-State: APjAAAU7DALZy21nqH/WLg+cisoD6bhr4ecwSapdqNHF4s32SJyGWvVf ZJvCbW3SchlU8c1MXQiWryPeq3+w X-Google-Smtp-Source: APXvYqx9PDyq2on7zISqH0o1FdsGyY4qegTL5GqnKvSwsybPRSDGPY+c3QH5dEZ5uLw4q608e9g6Yw== X-Received: by 2002:a1c:2543:: with SMTP id l64mr6676864wml.116.1551979819184; Thu, 07 Mar 2019 09:30:19 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:19 +0100 Message-Id: <1551979804-6060-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 Subject: [Qemu-devel] [PULL 12/57] tests/libqos: arm/xilinx-zynq-a9 machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add xilinx-zynq-a9 machine to the graph. This machine contains generic-sdhci, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-xilinx-zynq-a9-machine.c | 94 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/libqos/arm-xilinx-zynq-a9-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 4758352..c7800d5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -758,6 +758,7 @@ qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += tests/libqos/arm-raspi2-machine.o qos-test-obj-y += tests/libqos/arm-sabrelite-machine.o qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o +qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o check-unit-y += tests/test-qgraph$(EXESUF) diff --git a/tests/libqos/arm-xilinx-zynq-a9-machine.c b/tests/libqos/arm-xilinx-zynq-a9-machine.c new file mode 100644 index 0000000..4e199fc --- /dev/null +++ b/tests/libqos/arm-xilinx-zynq-a9-machine.c @@ -0,0 +1,94 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "sdhci.h" + +typedef struct QXilinxZynqA9Machine QXilinxZynqA9Machine; + +struct QXilinxZynqA9Machine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSDHCI_MemoryMapped sdhci; +}; + +#define ARM_PAGE_SIZE 4096 +#define XILINX_ZYNQ_A9_RAM_ADDR 0 +#define XILINX_ZYNQ_A9_RAM_SIZE 0x20000000 + +static void *xilinx_zynq_a9_get_driver(void *object, const char *interface) +{ + QXilinxZynqA9Machine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *xilinx_zynq_a9_get_device(void *obj, const char *device) +{ + QXilinxZynqA9Machine *machine = obj; + if (!g_strcmp0(device, "generic-sdhci")) { + return &machine->sdhci.obj; + } + + fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", device); + g_assert_not_reached(); +} + +static void xilinx_zynq_a9_destructor(QOSGraphObject *obj) +{ + QXilinxZynqA9Machine *machine = (QXilinxZynqA9Machine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_xilinx_zynq_a9(QTestState *qts) +{ + QXilinxZynqA9Machine *machine = g_new0(QXilinxZynqA9Machine, 1); + + alloc_init(&machine->alloc, 0, + XILINX_ZYNQ_A9_RAM_ADDR + (1 << 20), + XILINX_ZYNQ_A9_RAM_ADDR + XILINX_ZYNQ_A9_RAM_SIZE, + ARM_PAGE_SIZE); + + machine->obj.get_device = xilinx_zynq_a9_get_device; + machine->obj.get_driver = xilinx_zynq_a9_get_driver; + machine->obj.destructor = xilinx_zynq_a9_destructor; + /* Datasheet: UG585 (v1.12.1) */ + qos_init_sdhci_mm(&machine->sdhci, qts, 0xe0100000, &(QSDHCIProperties) { + .version = 2, + .baseclock = 0, + .capab.sdma = true, + .capab.reg = 0x69ec0080, + }); + return &machine->obj; +} + +static void xilinx_zynq_a9_register_nodes(void) +{ + qos_node_create_machine("arm/xilinx-zynq-a9", + qos_create_machine_arm_xilinx_zynq_a9); + qos_node_contains("arm/xilinx-zynq-a9", "generic-sdhci", NULL); +} + +libqos_init(xilinx_zynq_a9_register_nodes); From patchwork Thu Mar 7 17:29:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lI44g0ur"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdjY39Rvz9s70 for ; Fri, 8 Mar 2019 05:01:19 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xKU-00032M-UD for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:01:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqc-0002z8-Qj for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqb-0007y0-LG for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:22 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqb-0007xN-Cy for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:21 -0500 Received: by mail-wr1-x442.google.com with SMTP id l12so1948926wrp.6 for ; Thu, 07 Mar 2019 09:30:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tDRByElg/tsuAN/LWk0Us4U3aK0MJsxONTOniwy9FmU=; b=lI44g0urcVOUyGAA+g/cAgYIKWqSdbQ7AjeS4sN+7Bh5BBYsiEx8QfVLDXBafzZlvQ 2UlwDB/KwKBc+NyUhjlg78RSpoLdn+iNwDojmKk/JPPH1ajJM19pmyaEtNMQ/eAOoiJi f9vZtee70jHHi0iOpIcs3u+SJ8agMM4qobGGYXBMLhUlJOotf2RoOJhmPtxN0QlTb+Pu n1ysvpKImkK/9aCNeawEXiwFsSOtMcEXjKELSwPhHYOEkAQdQSmJ1gxd8PtvZd+R+dDp lM77p+/tPpZp0GGsfYKuZN7M5a+BJ7FZEWJnqv+N244ax4arRyx/B4cGbly87Nw5qOYF ll+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tDRByElg/tsuAN/LWk0Us4U3aK0MJsxONTOniwy9FmU=; b=K7a/fi0a0tpwhhMAy5eDqHkW7coTJTUrUY1EyESmFAIeFiQa9zb+Iwh4E431K+al9r JRJo/W+sOh88/hwWZZYhY/bY/fxyFxkqlDuotMt4ENmyGbUbuGudnyV3sldPolq/oYye xAv2f9KcnmFCIU5xUy06jKhcpcokYSH3hhcMyXVd7rdmWFamqsmpQ9YDPGB+3lcta5RH BGQcdframaJEN8d9mvxL+P/pan2Onh21S8w2/2jeZba62bZGd6m3/imsiBJUO7GSXsiR w967jc6+OIRBDAqcp6mjBxjWivbGfK5L7SROOxRc1zIgD12m1LQIxQrTpY99xnJauHyL 8iaQ== X-Gm-Message-State: APjAAAWRuSrctj+nIJUcOoIpha1cJrdqjB41/zlRPgBugSU9FEEuZeCF 9x7VItXxIG6IQuL8qFRFR7K8DeW9 X-Google-Smtp-Source: APXvYqxt6xKDdgGyy6Qu9yQRlQ17jdSsaKJRYq1wmLZ4QwhzWZSQk2ApjfU+1RIdmwqWVaV0BTMhLQ== X-Received: by 2002:a5d:4145:: with SMTP id c5mr7587134wrq.256.1551979820129; Thu, 07 Mar 2019 09:30:20 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:20 +0100 Message-Id: <1551979804-6060-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PULL 13/57] tests/libqos: aarch64/xlnx-zcu102 machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add xlnx-zcu102 machine to the graph. This machine contains generic-sdhci, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/aarch64-xlnx-zcu102-machine.c | 94 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/libqos/aarch64-xlnx-zcu102-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index c7800d5..d675ad8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -755,6 +755,7 @@ qos-test-obj-y += $(libqos-pc-obj-y) qos-test-obj-y += tests/libqos/sdhci.o # Machines +qos-test-obj-y += tests/libqos/aarch64-xlnx-zcu102-machine.o qos-test-obj-y += tests/libqos/arm-raspi2-machine.o qos-test-obj-y += tests/libqos/arm-sabrelite-machine.o qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o diff --git a/tests/libqos/aarch64-xlnx-zcu102-machine.c b/tests/libqos/aarch64-xlnx-zcu102-machine.c new file mode 100644 index 0000000..6fff040 --- /dev/null +++ b/tests/libqos/aarch64-xlnx-zcu102-machine.c @@ -0,0 +1,94 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "sdhci.h" + +typedef struct QXlnxZCU102Machine QXlnxZCU102Machine; + +struct QXlnxZCU102Machine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSDHCI_MemoryMapped sdhci; +}; + +#define ARM_PAGE_SIZE 4096 +#define XLNX_ZCU102_RAM_ADDR 0 +#define XLNX_ZCU102_RAM_SIZE 0x20000000 + +static void *xlnx_zcu102_get_driver(void *object, const char *interface) +{ + QXlnxZCU102Machine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *xlnx_zcu102_get_device(void *obj, const char *device) +{ + QXlnxZCU102Machine *machine = obj; + if (!g_strcmp0(device, "generic-sdhci")) { + return &machine->sdhci.obj; + } + + fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", device); + g_assert_not_reached(); +} + +static void xlnx_zcu102_destructor(QOSGraphObject *obj) +{ + QXlnxZCU102Machine *machine = (QXlnxZCU102Machine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_aarch64_xlnx_zcu102(QTestState *qts) +{ + QXlnxZCU102Machine *machine = g_new0(QXlnxZCU102Machine, 1); + + alloc_init(&machine->alloc, 0, + XLNX_ZCU102_RAM_ADDR + (1 << 20), + XLNX_ZCU102_RAM_ADDR + XLNX_ZCU102_RAM_SIZE, + ARM_PAGE_SIZE); + + machine->obj.get_device = xlnx_zcu102_get_device; + machine->obj.get_driver = xlnx_zcu102_get_driver; + machine->obj.destructor = xlnx_zcu102_destructor; + /* Datasheet: UG1085 (v1.7) */ + qos_init_sdhci_mm(&machine->sdhci, qts, 0xff160000, &(QSDHCIProperties) { + .version = 3, + .baseclock = 0, + .capab.sdma = true, + .capab.reg = 0x280737ec6481 + }); + return &machine->obj; +} + +static void xlnx_zcu102_register_nodes(void) +{ + qos_node_create_machine("aarch64/xlnx-zcu102", + qos_create_machine_aarch64_xlnx_zcu102); + qos_node_contains("aarch64/xlnx-zcu102", "generic-sdhci", NULL); +} + +libqos_init(xlnx_zcu102_register_nodes); From patchwork Thu Mar 7 17:29:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EI2/Mp3i"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdfc60XPz9sNB for ; Fri, 8 Mar 2019 04:58:48 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xI6-0000or-L3 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:58:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqe-00031C-Ju for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqd-0007zB-5M for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:24 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:35271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqc-0007yJ-Qi for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:23 -0500 Received: by mail-wr1-x433.google.com with SMTP id t18so18422978wrx.2 for ; Thu, 07 Mar 2019 09:30:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fUa7oUuume8kt5FpgGRPAfQtZ3UsaWJIK9T0pnagtd8=; b=EI2/Mp3iG7JnvM0ZEXgkV48vnvVJB5MxI46URXLS7CEkNHXTmCS0LpyJwxswspAyHA JO2heDMcHcAoxnOEoRxc5/6Rt1k7ZBZj+Ew2/gp4ssRohPtreB80zJgFKo+BFJgRMYmr dcp2mpQ68WRpdK8cJKfCnq+mGpzeJku55MgtsQfT3lPEsnktg5yCZ0IWYhJL2v89H0l5 ytYyXEtseX3NT4tjvJoOB+XftgS6vqmvbUVsYOz9xiKxmatq4LVWo6/J/CrZp6RzZYUv goBzNEoHp6l1BBUVLiOqmHUaEdJiX+MZJ6iqcwx8Du24Dnaf62N3XcXkC3/14p/fXpuB LR6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=fUa7oUuume8kt5FpgGRPAfQtZ3UsaWJIK9T0pnagtd8=; b=XQJ+e+cGj9H2DR3u0QznQBTRzur9701V7E+mUAo6lai3sw+BnFb1iRJkzw/aO+NEbm iI0wcwAmv609ztFCn03KSIveX+v6gQod7ER4SCVLcueSd/ZSjboevFsj8W2HfVl/S5RV KpCOJicL7pPaDx2oFMC6WhySrmt+zSxfgjFQj6UILDe/cQGHObGH/dqMqqOSxT4TbS2w p149jYBSeNrIj2swMBGX5tArUSoy2d1RJSBZDv1sqZaQuc4UYhhxLqar1totSLSN0AR8 ToXltubRzzIM1LZwUBpl8Yl1AsI5YzlWLx28g8wdagQx0UljQp6zM34aTQZjWEHjdC61 4/AA== X-Gm-Message-State: APjAAAUdxFN+crXHRpHgniPV/a1RmiTcOPnYjMSLBaVrUWQMj+bL/SD4 6L8v3pVXQlVq4VopiLTs2Zp2i7n0 X-Google-Smtp-Source: APXvYqwi946r5whTwUe3RyKiGVVG/1FuHGjTgfZn0ZnHZcHFMDQXU3JLwJll57wQ9RjTy/vcEBKVvA== X-Received: by 2002:adf:dd4d:: with SMTP id u13mr8392547wrm.284.1551979821279; Thu, 07 Mar 2019 09:30:21 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:21 +0100 Message-Id: <1551979804-6060-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::433 Subject: [Qemu-devel] [PULL 14/57] qos-test: sdhci test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/sdhci-test in first qgraph test node, sdhci-test. This test consumes an sdhci interface and checks that its function return the expected values. Note that this test does not allocate any sdhci structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 7 +- tests/sdhci-test.c | 185 ++++++------------------------------------------- 2 files changed, 24 insertions(+), 168 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index d675ad8..4b545ac 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -229,7 +229,6 @@ check-qtest-i386-y += tests/test-announce-self$(EXESUF) check-qtest-i386-y += tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y += tests/numa-test$(EXESUF) check-qtest-x86_64-y += $(check-qtest-i386-y) -check-qtest-x86_64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF) check-qtest-alpha-y += tests/boot-serial-test$(EXESUF) check-qtest-alpha-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) @@ -299,11 +298,9 @@ check-qtest-arm-y += tests/m25p80-test$(EXESUF) check-qtest-arm-$(CONFIG_VIRTIO_BLK) += tests/virtio-blk-test$(EXESUF) check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF) check-qtest-arm-y += tests/boot-serial-test$(EXESUF) -check-qtest-arm-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF) check-qtest-arm-y += tests/hexloader-test$(EXESUF) check-qtest-aarch64-y = tests/numa-test$(EXESUF) -check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF) check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF) check-qtest-aarch64-y += tests/migration-test$(EXESUF) @@ -762,6 +759,9 @@ qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o +# Tests +qos-test-obj-y += tests/sdhci-test.o + check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) @@ -857,7 +857,6 @@ tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) tests/numa-test$(EXESUF): tests/numa-test.o tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o -tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y) tests/cdrom-test$(EXESUF): tests/cdrom-test.o tests/boot-sector.o $(libqos-obj-y) tests/migration/stress$(EXESUF): tests/migration/stress.o diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c index 28d481b..2f177e5 100644 --- a/tests/sdhci-test.c +++ b/tests/sdhci-test.c @@ -12,6 +12,8 @@ #include "libqtest.h" #include "libqos/pci-pc.h" #include "hw/pci/pci.h" +#include "libqos/qgraph.h" +#include "libqos/sdhci.h" #define SDHC_CAPAB 0x40 FIELD(SDHC_CAPAB, BASECLKFREQ, 8, 8); /* since v2 */ @@ -20,99 +22,11 @@ FIELD(SDHC_CAPAB, SDR, 32, 3); /* since v3 */ FIELD(SDHC_CAPAB, DRIVER, 36, 3); /* since v3 */ #define SDHC_HCVER 0xFE -static const struct sdhci_t { - const char *arch, *machine; - struct { - uintptr_t addr; - uint8_t version; - uint8_t baseclock; - struct { - bool sdma; - uint64_t reg; - } capab; - } sdhci; - struct { - uint16_t vendor_id, device_id; - } pci; -} models[] = { - /* PC via PCI */ - { "x86_64", "pc", - {-1, 2, 0, {1, 0x057834b4} }, - .pci = { PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_SDHCI } }, - - /* Exynos4210 */ - { "arm", "smdkc210", - {0x12510000, 2, 0, {1, 0x5e80080} } }, - - /* i.MX 6 */ - { "arm", "sabrelite", - {0x02190000, 3, 0, {1, 0x057834b4} } }, - - /* BCM2835 */ - { "arm", "raspi2", - {0x3f300000, 3, 52, {0, 0x052134b4} } }, - - /* Zynq-7000 */ - { "arm", "xilinx-zynq-a9", /* Datasheet: UG585 (v1.12.1) */ - {0xe0100000, 2, 0, {1, 0x69ec0080} } }, - - /* ZynqMP */ - { "aarch64", "xlnx-zcu102", /* Datasheet: UG1085 (v1.7) */ - {0xff160000, 3, 0, {1, 0x280737ec6481} } }, - -}; - -typedef struct QSDHCI { - struct { - QPCIBus *bus; - QPCIDevice *dev; - } pci; - union { - QPCIBar mem_bar; - uint64_t addr; - }; -} QSDHCI; - -static uint16_t sdhci_readw(QSDHCI *s, uint32_t reg) -{ - uint16_t val; - - if (s->pci.dev) { - val = qpci_io_readw(s->pci.dev, s->mem_bar, reg); - } else { - val = qtest_readw(global_qtest, s->addr + reg); - } - - return val; -} - -static uint64_t sdhci_readq(QSDHCI *s, uint32_t reg) -{ - uint64_t val; - - if (s->pci.dev) { - val = qpci_io_readq(s->pci.dev, s->mem_bar, reg); - } else { - val = qtest_readq(global_qtest, s->addr + reg); - } - - return val; -} - -static void sdhci_writeq(QSDHCI *s, uint32_t reg, uint64_t val) -{ - if (s->pci.dev) { - qpci_io_writeq(s->pci.dev, s->mem_bar, reg, val); - } else { - qtest_writeq(global_qtest, s->addr + reg, val); - } -} - static void check_specs_version(QSDHCI *s, uint8_t version) { uint32_t v; - v = sdhci_readw(s, SDHC_HCVER); + v = s->readw(s, SDHC_HCVER); v &= 0xff; v += 1; g_assert_cmpuint(v, ==, version); @@ -122,7 +36,7 @@ static void check_capab_capareg(QSDHCI *s, uint64_t expec_capab) { uint64_t capab; - capab = sdhci_readq(s, SDHC_CAPAB); + capab = s->readq(s, SDHC_CAPAB); g_assert_cmphex(capab, ==, expec_capab); } @@ -131,11 +45,11 @@ static void check_capab_readonly(QSDHCI *s) const uint64_t vrand = 0x123456789abcdef; uint64_t capab0, capab1; - capab0 = sdhci_readq(s, SDHC_CAPAB); + capab0 = s->readq(s, SDHC_CAPAB); g_assert_cmpuint(capab0, !=, vrand); - sdhci_writeq(s, SDHC_CAPAB, vrand); - capab1 = sdhci_readq(s, SDHC_CAPAB); + s->writeq(s, SDHC_CAPAB, vrand); + capab1 = s->readq(s, SDHC_CAPAB); g_assert_cmpuint(capab1, !=, vrand); g_assert_cmpuint(capab1, ==, capab0); } @@ -147,7 +61,7 @@ static void check_capab_baseclock(QSDHCI *s, uint8_t expec_freq) if (!expec_freq) { return; } - capab = sdhci_readq(s, SDHC_CAPAB); + capab = s->readq(s, SDHC_CAPAB); capab_freq = FIELD_EX64(capab, SDHC_CAPAB, BASECLKFREQ); g_assert_cmpuint(capab_freq, ==, expec_freq); } @@ -156,7 +70,7 @@ static void check_capab_sdma(QSDHCI *s, bool supported) { uint64_t capab, capab_sdma; - capab = sdhci_readq(s, SDHC_CAPAB); + capab = s->readq(s, SDHC_CAPAB); capab_sdma = FIELD_EX64(capab, SDHC_CAPAB, SDMA); g_assert_cmpuint(capab_sdma, ==, supported); } @@ -167,7 +81,7 @@ static void check_capab_v3(QSDHCI *s, uint8_t version) if (version < 3) { /* before v3 those fields are RESERVED */ - capab = sdhci_readq(s, SDHC_CAPAB); + capab = s->readq(s, SDHC_CAPAB); capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, SDR); g_assert_cmpuint(capab_v3, ==, 0); capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, DRIVER); @@ -175,78 +89,21 @@ static void check_capab_v3(QSDHCI *s, uint8_t version) } } -static QSDHCI *machine_start(const struct sdhci_t *test) -{ - QSDHCI *s = g_new0(QSDHCI, 1); - - if (test->pci.vendor_id) { - /* PCI */ - uint16_t vendor_id, device_id; - uint64_t barsize; - - global_qtest = qtest_initf("-machine %s -device sdhci-pci", - test->machine); - - s->pci.bus = qpci_new_pc(global_qtest, NULL); - - /* Find PCI device and verify it's the right one */ - s->pci.dev = qpci_device_find(s->pci.bus, QPCI_DEVFN(4, 0)); - g_assert_nonnull(s->pci.dev); - vendor_id = qpci_config_readw(s->pci.dev, PCI_VENDOR_ID); - device_id = qpci_config_readw(s->pci.dev, PCI_DEVICE_ID); - g_assert(vendor_id == test->pci.vendor_id); - g_assert(device_id == test->pci.device_id); - s->mem_bar = qpci_iomap(s->pci.dev, 0, &barsize); - qpci_device_enable(s->pci.dev); - } else { - /* SysBus */ - global_qtest = qtest_initf("-machine %s", test->machine); - s->addr = test->sdhci.addr; - } - - return s; -} - -static void machine_stop(QSDHCI *s) -{ - qpci_free_pc(s->pci.bus); - g_free(s->pci.dev); - qtest_quit(global_qtest); - g_free(s); -} - -static void test_machine(const void *data) +static void test_registers(void *obj, void *data, QGuestAllocator *alloc) { - const struct sdhci_t *test = data; - QSDHCI *s; + QSDHCI *s = obj; - s = machine_start(test); - - check_specs_version(s, test->sdhci.version); - check_capab_capareg(s, test->sdhci.capab.reg); + check_specs_version(s, s->props.version); + check_capab_capareg(s, s->props.capab.reg); check_capab_readonly(s); - check_capab_v3(s, test->sdhci.version); - check_capab_sdma(s, test->sdhci.capab.sdma); - check_capab_baseclock(s, test->sdhci.baseclock); - - machine_stop(s); + check_capab_v3(s, s->props.version); + check_capab_sdma(s, s->props.capab.sdma); + check_capab_baseclock(s, s->props.baseclock); } -int main(int argc, char *argv[]) +static void register_sdhci_test(void) { - const char *arch = qtest_get_arch(); - char *name; - int i; - - g_test_init(&argc, &argv, NULL); - for (i = 0; i < ARRAY_SIZE(models); i++) { - if (strcmp(arch, models[i].arch)) { - continue; - } - name = g_strdup_printf("sdhci/%s", models[i].machine); - qtest_add_data_func(name, &models[i], test_machine); - g_free(name); - } - - return g_test_run(); + qos_add_test("registers", "sdhci", test_registers, NULL); } + +libqos_init(register_sdhci_test); From patchwork Thu Mar 7 17:29:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I9iv0h0n"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdbV6j6nz9sD4 for ; Fri, 8 Mar 2019 04:56:06 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xFU-0006u1-SC for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:56:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqe-00031W-Ss for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqe-0007zs-3i for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:24 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:56277) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqd-0007zI-Ro for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:24 -0500 Received: by mail-wm1-x336.google.com with SMTP id q187so10149493wme.5 for ; Thu, 07 Mar 2019 09:30:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v3lESk55hw8XuGlGShzjOIOowBPK8525xla4V8empQY=; b=I9iv0h0n0vD4+Vzj32e94oNGXpinfcUsd2Xq7ZF5CDDfGbJziALj17BfboQbmJqENx 5ol+0c1R3QtQBFx/7W8Dwyj4Du7ZXq1Nl1n7sq73mZZXZ/W7eOKDCmSXXAb+JXOBm6x5 lo+gHRxXqVWOoagker3p+yWMxyegMmC8siJ9tmUiT7HoeWMrhZSN4z43copcYMx8Sc1f Pk/W1wCavRWb3fmjMitA0JVgeZQLbvwklEFqWkbobsGey0E5kysfGx1TtKQFqoFxzDmW 1OlnoENVI9b12UPZStxvpct+/w6P56SCtqLpkS3SOC+u/86Kyk9Yw7q4i5oD/Szt2DXO ITOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v3lESk55hw8XuGlGShzjOIOowBPK8525xla4V8empQY=; b=gYlhj/HeZgJfQSc30swAvAbZYPpMH3mMV6DYjbhueLq/VT/1Soq+DIjyAwTp+MZXZu KV+ygtQ0L616070pDfAQ58TT9eKSwwDnbvGn51D8ZEdc2ScAnvem4IypbcZU1+HdxlVt z0m+Fjc5lfa1ZJcMMhWmSreu8ifmT+eB+IMHnV69GJV+VTE0+qp4WKYpVjX6zAoDBULL kGij3HuE8ElacRhda24PZoBfVb860QEEXE3/k6bcIxyb2BJ4DFh+Yuz8DTKFpr3UIHZX ajsMxc37ujT2H9XEcjJG/jXcZ6yRuoyUr8I9CUuiyue12vJc+QiqYTfpaPqezjIXgWRm wHZg== X-Gm-Message-State: APjAAAW3SMQsmFjBtdhl+5bwJaGlUw9nfW9RUdCOjcQke8HXc+TtubRk Zf89YQ6ymrkHoqNFc9ikafcFqP1G X-Google-Smtp-Source: APXvYqz673fgcT6HAmeP8TnjqeTz4BsngS6LH1BKFXDdyua8x0qeptQsxmX41zyWoBKl0qGl5zfUjA== X-Received: by 2002:a1c:2947:: with SMTP id p68mr6473377wmp.104.1551979822517; Thu, 07 Mar 2019 09:30:22 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:22 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:22 +0100 Message-Id: <1551979804-6060-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 Subject: [Qemu-devel] [PULL 15/57] tests/qgraph: add generic PCI testcases 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/pci-test.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/pci-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 4b545ac..4391b7f 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -760,6 +760,7 @@ qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests +qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o check-unit-y += tests/test-qgraph$(EXESUF) diff --git a/tests/pci-test.c b/tests/pci-test.c new file mode 100644 index 0000000..ff80985 --- /dev/null +++ b/tests/pci-test.c @@ -0,0 +1,25 @@ +/* + * QTest testcase for PCI + * + * Copyright (c) 2018 Red Hat, Inc. + * + * 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 "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" + +/* Tests only initialization so far. TODO: Replace with functional tests */ +static void nop(void *obj, void *data, QGuestAllocator *alloc) +{ +} + +static void register_pci_test(void) +{ + qos_add_test("nop", "pci-device", nop, NULL); +} + +libqos_init(register_pci_test); From patchwork Thu Mar 7 17:29:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gPBs5aGR"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdnL4YVkz9s70 for ; Fri, 8 Mar 2019 05:04:38 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xNk-0005Wh-Fu for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:04:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqg-00033C-F4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqf-00080t-9y for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:26 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:38635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqf-000800-05 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:25 -0500 Received: by mail-wr1-x443.google.com with SMTP id g12so18405556wrm.5 for ; Thu, 07 Mar 2019 09:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3a8rzlsoySZRtDZAwm052QNWwR1TWW7HR2xTrEHHtfk=; b=gPBs5aGRCbBDkGK9fxWnPCC6l8L72aN6P8vkqygnrPgtwrB63GL4s3OgtZWv6K937/ rfi9TbqZul38TWb32Eydgk2kVcuUUh/IjuvL8GDD5b3mPaxh8+nC3MEomiKOA1ZpQ65j SV4IlHt9HLwd6FRmwcxLM6bSP4NWe6WDh6iKdC6wumidvaWR9qcZdUcJgtUjLUPN9ACX +Q1ZPCUM/5UTg54L4D5j6psitl1+74LoBIM9Jvj24X3VYdmBggGpMrg6d2Md75JiqeYK 2a7EzGiZpC27mHJGmcMt1AQlGJmD+lsbeN62hofQ2efPJHWh+z6slnhTUUYCpnzZ6/ax Ob+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3a8rzlsoySZRtDZAwm052QNWwR1TWW7HR2xTrEHHtfk=; b=UPF2fXyY9jIfkX57X0lJMqWcqQ4U/0JK1b4P8Ks0XsmblYr0uwAHdvdkyR3Ja81/qw OcYyJRDLmVQncqMrs1n63gkyUDs2CgRhR2UdDJYTl2UD6nVfo3BMxNc7R5ezElU9USC/ 3m6Tz2InkAfsYfzxu9/xaHM46hZ5MyG89j/gm/XVVShVTpbDQZkcF9pxd9HsF7cy5JlA ZMXaOXIFq7IBLeOnVP26FDEWe3EGwZ5tA7VjLQ36qZ2MVGQU53TmbzgL1sfibrfPBfJ+ UxrliAF/c4uGEjrJko2GSx9ppl2/AABxL77V5Dniuh6A7lfQt/S/Fy1PWONHVMtLkiyx gtMQ== X-Gm-Message-State: APjAAAXjmKFUmg+mQ0OBFYU9gAju/e6mh4vAYuQMdiqG4fUl5cTH5cEn sgXUPtN2axNDnJYvpG/KzH7z2Coz X-Google-Smtp-Source: APXvYqzPVXYPhL3RXF+UBzXF6akzBZdkVRVj2Gle0oORimHOVq5+QTGxHx4mKPa6xdYDVO1VJcRnMg== X-Received: by 2002:a5d:4804:: with SMTP id l4mr7970511wrq.177.1551979823566; Thu, 07 Mar 2019 09:30:23 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:23 +0100 Message-Id: <1551979804-6060-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PULL 16/57] tests/libqos: pci-spapr driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add pci-bus-spapr node, that produces pci-bus. Move QPCIBusSPAPR struct declaration in its header (since it will be needed by other drivers) and introduce a setter method for drivers that do not need to allocate but have to initialize QPCIBusSPAPR. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 2 +- tests/libqos/pci-spapr.c | 116 +++++++++++++++++++++++++---------------------- tests/libqos/pci-spapr.h | 24 ++++++++++ 3 files changed, 88 insertions(+), 54 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 4391b7f..37ca530 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -748,7 +748,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt # Devices qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) -qos-test-obj-y += $(libqos-pc-obj-y) +qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/sdhci.o # Machines diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c index 59679f6..d9b87a7 100644 --- a/tests/libqos/pci-spapr.c +++ b/tests/libqos/pci-spapr.c @@ -9,33 +9,13 @@ #include "libqtest.h" #include "libqos/pci-spapr.h" #include "libqos/rtas.h" +#include "libqos/qgraph.h" #include "hw/pci/pci_regs.h" #include "qemu-common.h" #include "qemu/host-utils.h" - -/* From include/hw/pci-host/spapr.h */ - -typedef struct QPCIWindow { - uint64_t pci_base; /* window address in PCI space */ - uint64_t size; /* window size */ -} QPCIWindow; - -typedef struct QPCIBusSPAPR { - QPCIBus bus; - QGuestAllocator *alloc; - - uint64_t buid; - - uint64_t pio_cpu_base; - QPCIWindow pio; - - uint64_t mmio32_cpu_base; - QPCIWindow mmio32; -} QPCIBusSPAPR; - /* * PCI devices are always little-endian * SPAPR by default is big-endian @@ -160,60 +140,90 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, #define SPAPR_PCI_MMIO32_WIN_SIZE 0x80000000 /* 2 GiB */ #define SPAPR_PCI_IO_WIN_SIZE 0x10000 -QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc) +static void *qpci_spapr_get_driver(void *obj, const char *interface) { - QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1); + QPCIBusSPAPR *qpci = obj; + if (!g_strcmp0(interface, "pci-bus")) { + return &qpci->bus; + } + fprintf(stderr, "%s not present in pci-bus-spapr", interface); + g_assert_not_reached(); +} +void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts, + QGuestAllocator *alloc) +{ assert(qts); - ret->alloc = alloc; + qpci->alloc = alloc; - ret->bus.pio_readb = qpci_spapr_pio_readb; - ret->bus.pio_readw = qpci_spapr_pio_readw; - ret->bus.pio_readl = qpci_spapr_pio_readl; - ret->bus.pio_readq = qpci_spapr_pio_readq; + qpci->bus.pio_readb = qpci_spapr_pio_readb; + qpci->bus.pio_readw = qpci_spapr_pio_readw; + qpci->bus.pio_readl = qpci_spapr_pio_readl; + qpci->bus.pio_readq = qpci_spapr_pio_readq; - ret->bus.pio_writeb = qpci_spapr_pio_writeb; - ret->bus.pio_writew = qpci_spapr_pio_writew; - ret->bus.pio_writel = qpci_spapr_pio_writel; - ret->bus.pio_writeq = qpci_spapr_pio_writeq; + qpci->bus.pio_writeb = qpci_spapr_pio_writeb; + qpci->bus.pio_writew = qpci_spapr_pio_writew; + qpci->bus.pio_writel = qpci_spapr_pio_writel; + qpci->bus.pio_writeq = qpci_spapr_pio_writeq; - ret->bus.memread = qpci_spapr_memread; - ret->bus.memwrite = qpci_spapr_memwrite; + qpci->bus.memread = qpci_spapr_memread; + qpci->bus.memwrite = qpci_spapr_memwrite; - ret->bus.config_readb = qpci_spapr_config_readb; - ret->bus.config_readw = qpci_spapr_config_readw; - ret->bus.config_readl = qpci_spapr_config_readl; + qpci->bus.config_readb = qpci_spapr_config_readb; + qpci->bus.config_readw = qpci_spapr_config_readw; + qpci->bus.config_readl = qpci_spapr_config_readl; - ret->bus.config_writeb = qpci_spapr_config_writeb; - ret->bus.config_writew = qpci_spapr_config_writew; - ret->bus.config_writel = qpci_spapr_config_writel; + qpci->bus.config_writeb = qpci_spapr_config_writeb; + qpci->bus.config_writew = qpci_spapr_config_writew; + qpci->bus.config_writel = qpci_spapr_config_writel; /* FIXME: We assume the default location of the PHB for now. * Ideally we'd parse the device tree deposited in the guest to * get the window locations */ - ret->buid = 0x800000020000000ULL; + qpci->buid = 0x800000020000000ULL; - ret->pio_cpu_base = SPAPR_PCI_BASE; - ret->pio.pci_base = 0; - ret->pio.size = SPAPR_PCI_IO_WIN_SIZE; + qpci->pio_cpu_base = SPAPR_PCI_BASE; + qpci->pio.pci_base = 0; + qpci->pio.size = SPAPR_PCI_IO_WIN_SIZE; /* 32-bit portion of the MMIO window is at PCI address 2..4 GiB */ - ret->mmio32_cpu_base = SPAPR_PCI_BASE; - ret->mmio32.pci_base = SPAPR_PCI_MMIO32_WIN_SIZE; - ret->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE; + qpci->mmio32_cpu_base = SPAPR_PCI_BASE; + qpci->mmio32.pci_base = SPAPR_PCI_MMIO32_WIN_SIZE; + qpci->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE; - ret->bus.qts = qts; - ret->bus.pio_alloc_ptr = 0xc000; - ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base; - ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size; + qpci->bus.qts = qts; + qpci->bus.pio_alloc_ptr = 0xc000; + qpci->bus.mmio_alloc_ptr = qpci->mmio32.pci_base; + qpci->bus.mmio_limit = qpci->mmio32.pci_base + qpci->mmio32.size; - return &ret->bus; + qpci->obj.get_driver = qpci_spapr_get_driver; +} + +QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc) +{ + QPCIBusSPAPR *qpci = g_new0(QPCIBusSPAPR, 1); + qpci_init_spapr(qpci, qts, alloc); + + return &qpci->bus; } void qpci_free_spapr(QPCIBus *bus) { - QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus); + QPCIBusSPAPR *s; + + if (!bus) { + return; + } + s = container_of(bus, QPCIBusSPAPR, bus); g_free(s); } + +static void qpci_spapr_register_nodes(void) +{ + qos_node_create_driver("pci-bus-spapr", NULL); + qos_node_produces("pci-bus-spapr", "pci-bus"); +} + +libqos_init(qpci_spapr_register_nodes); diff --git a/tests/libqos/pci-spapr.h b/tests/libqos/pci-spapr.h index 177e8c0..d9e2563 100644 --- a/tests/libqos/pci-spapr.h +++ b/tests/libqos/pci-spapr.h @@ -10,7 +10,31 @@ #include "libqos/malloc.h" #include "libqos/pci.h" +#include "libqos/qgraph.h" +/* From include/hw/pci-host/spapr.h */ + +typedef struct QPCIWindow { + uint64_t pci_base; /* window address in PCI space */ + uint64_t size; /* window size */ +} QPCIWindow; + +typedef struct QPCIBusSPAPR { + QOSGraphObject obj; + QPCIBus bus; + QGuestAllocator *alloc; + + uint64_t buid; + + uint64_t pio_cpu_base; + QPCIWindow pio; + + uint64_t mmio32_cpu_base; + QPCIWindow mmio32; +} QPCIBusSPAPR; + +void qpci_init_spapr(QPCIBusSPAPR *ret, QTestState *qts, + QGuestAllocator *alloc); QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc); void qpci_free_spapr(QPCIBus *bus); From patchwork Thu Mar 7 17:29:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YwGbHniN"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdQT6kP9z9sNG for ; Fri, 8 Mar 2019 04:48:17 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x7v-0008Tj-Lr for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:48:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqh-000345-CR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqg-00081a-7Z for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:27 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:35315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqf-00080x-Vr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:26 -0500 Received: by mail-wr1-x441.google.com with SMTP id t18so18423174wrx.2 for ; Thu, 07 Mar 2019 09:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=j7EctTVSWu166VMRkNMv2Z+QB3+xjzdATMk5tC685zw=; b=YwGbHniN+qtnbnB7cCpNOsZVojyq/GtHi18pwhsp09sG5ME7UjwnlXE7Z4fegE3iWo YWdwFDd9L5s1QWqnrB4sZcWjYraXN3vlLqBsdqz47VgcAZy195dhl70xGmL9Tqd44+FM nVxC8OY3sd5TftuG1RoMOb+WtK9RCgSjQYBQdZDdjiD8M/mcul15/EThrGYkmH/Wtsn5 9lu0s0LeMQwGsp5gvFP/WzyMJCQZinKhL+t6TJI80yG86dh3fJsJ0iBt89PSvsCz4w91 dGYtSiS8vzLxEA566slnarzAkcKUBsGQNEtKkQy8KNp6z1iWgn/3aCaiCa1CmTlFlmZl u9hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=j7EctTVSWu166VMRkNMv2Z+QB3+xjzdATMk5tC685zw=; b=aK3ZsZm5sPj9+7diAT8OBYrYF/HNGdOh0lZ+lCIEOFgwL053E7PqGYJFSpaXlUeyFn m/jkjzJVcql2M9W44+5mldxnkCdOEE2MxuBwUPeE3NaymDu2cqRlvK/FmIKUcG0+zFTT r+MXd+Z9gXH/UbK/7prKd8bvt8+j5ueSVK3MMRzUSBvkdYrmZb7qI92+4E/gk/tUGacK 9S1RwLeXaPbiA+nNgH69kqiYtJB9fFYi0Of96yEl+mWEtGvig8uCkPdxjP8oWo7pK18I vcnDmNlVhFwk+UUGS3WQGxblmzr67x/59mOAdnJ0zfv/R/s5+gvfV2bnYdfxqqHeUP/+ y68w== X-Gm-Message-State: APjAAAXYdRNkA8l5QevNJ15zCDqBf/YnKL/RRzUD6SZqIkMXESUTHYJE A00qr5owBsWkbXWV0uoJSakiBjQQ X-Google-Smtp-Source: APXvYqwrcBjRujxeveLHvdr6e4IwrUuA19asBA8likS2GzoDuZ3JXmGKQwk73rjDHr40AOswYrVe5w== X-Received: by 2002:a5d:574b:: with SMTP id q11mr7450636wrw.41.1551979824468; Thu, 07 Mar 2019 09:30:24 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:24 +0100 Message-Id: <1551979804-6060-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PULL 17/57] tests/qgraph: ppc64/pseries machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add pseries machine for the ppc64 QEMU binary. This machine contains a spapr-pci-host-bridge driver, that contains itself a pci-bus-spapr that produces the pci-bus interface. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/ppc64_pseries-machine.c | 111 +++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/libqos/ppc64_pseries-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 37ca530..a890327 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -757,6 +757,7 @@ qos-test-obj-y += tests/libqos/arm-raspi2-machine.o qos-test-obj-y += tests/libqos/arm-sabrelite-machine.o qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o +qos-test-obj-y += tests/libqos/ppc64_pseries-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests diff --git a/tests/libqos/ppc64_pseries-machine.c b/tests/libqos/ppc64_pseries-machine.c new file mode 100644 index 0000000..2f36400 --- /dev/null +++ b/tests/libqos/ppc64_pseries-machine.c @@ -0,0 +1,111 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + + #include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "pci-spapr.h" +#include "libqos/malloc-spapr.h" + +typedef struct QSPAPR_pci_host QSPAPR_pci_host; +typedef struct Qppc64_pseriesMachine Qppc64_pseriesMachine; + +struct QSPAPR_pci_host { + QOSGraphObject obj; + QPCIBusSPAPR pci; +}; + +struct Qppc64_pseriesMachine { + QOSGraphObject obj; + QGuestAllocator alloc; + QSPAPR_pci_host bridge; +}; + +/* QSPAPR_pci_host */ + +static QOSGraphObject *QSPAPR_host_get_device(void *obj, const char *device) +{ + QSPAPR_pci_host *host = obj; + if (!g_strcmp0(device, "pci-bus-spapr")) { + return &host->pci.obj; + } + fprintf(stderr, "%s not present in QSPAPR_pci_host\n", device); + g_assert_not_reached(); +} + +static void qos_create_QSPAPR_host(QSPAPR_pci_host *host, + QTestState *qts, + QGuestAllocator *alloc) +{ + host->obj.get_device = QSPAPR_host_get_device; + qpci_init_spapr(&host->pci, qts, alloc); +} + +/* ppc64/pseries machine */ + +static void spapr_destructor(QOSGraphObject *obj) +{ + Qppc64_pseriesMachine *machine = (Qppc64_pseriesMachine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *spapr_get_driver(void *object, const char *interface) +{ + Qppc64_pseriesMachine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in ppc64/pseries\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *spapr_get_device(void *obj, const char *device) +{ + Qppc64_pseriesMachine *machine = obj; + if (!g_strcmp0(device, "spapr-pci-host-bridge")) { + return &machine->bridge.obj; + } + + fprintf(stderr, "%s not present in ppc64/pseries\n", device); + g_assert_not_reached(); +} + +static void *qos_create_machine_spapr(QTestState *qts) +{ + Qppc64_pseriesMachine *machine = g_new0(Qppc64_pseriesMachine, 1); + machine->obj.get_device = spapr_get_device; + machine->obj.get_driver = spapr_get_driver; + machine->obj.destructor = spapr_destructor; + spapr_alloc_init(&machine->alloc, qts, ALLOC_NO_FLAGS); + + qos_create_QSPAPR_host(&machine->bridge, qts, &machine->alloc); + + return &machine->obj; +} + +static void spapr_machine_register_nodes(void) +{ + qos_node_create_machine("ppc64/pseries", qos_create_machine_spapr); + qos_node_create_driver("spapr-pci-host-bridge", NULL); + qos_node_contains("ppc64/pseries", "spapr-pci-host-bridge", NULL); + qos_node_contains("spapr-pci-host-bridge", "pci-bus-spapr", NULL); +} + +libqos_init(spapr_machine_register_nodes); + From patchwork Thu Mar 7 17:29:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lrKRJWtB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdry0P9hz9s70 for ; Fri, 8 Mar 2019 05:07:46 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xQl-0008DO-KD for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:07:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqi-00035X-Hi for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqh-00082Z-Ib for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:28 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:35437) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqh-00081s-A9 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:27 -0500 Received: by mail-wm1-x32d.google.com with SMTP id y15so10118955wma.0 for ; Thu, 07 Mar 2019 09:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=j7nLYa5t0iwQMQlb2p9lucvgT7D/mA9jbc3SpY3WtAU=; b=lrKRJWtB/BTQvrWFGW11FSPybNP+qvhwlJkw3oscVSYu922KLh8AZZt8B2X3z2IlYB FLecY3glz8t+Az2CCjARgRhifuPk3R5kyhtBqAvGRq3C/II8SoGTWTSFd2uu+Hasrh3f l4chGfkOp0yIaFOAn5cV8NFv7ZVN7L867Bzk7/hU8egZyMMCFdZEN2uj4jvN9CWxUIOt 726RmJFZvddXCnuSIe76WiBljocA4B7bI8mbXvHlRFPLMLm0PjeuS9AL69L6PYtCFK3B ngxue+gdvR3fidmmd7u81TSVYsjvPVx1i99TpD6Jb9dsuuO9RiKWDWZxNgnPa77I/D8k T2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=j7nLYa5t0iwQMQlb2p9lucvgT7D/mA9jbc3SpY3WtAU=; b=mj+hWhEonDBKIl6Fhe6xCj9ExFYJItmBI+jG4OluYMGJ15zrZDzUbDJfbiT0orX3Sk BW/hxElIy6PejVAm3c04uLyHV796BXf4PSpAkSgOugffWU/GDvhCfb8hdMMKYV6t4x17 H0yDEotP50uZYLJYtH5MRfy1GahNmg1YXvkDA3epnyh31F5cNEKx+vqTQlUmd4o3xbct YMQcdAX8dGqw74IALXMnHvgS28dNxr2Jf74hsC1IDXm60H3yTY3DN/SfXHtsN9MlBhzP yE9ymGTN8gNQ8AbFbchqQNVqcToRzUg6wTT3FIiMzBbyphr6yXxA35v5L2hKV+TpNCHD bl7g== X-Gm-Message-State: APjAAAVZH214BB0av5nfm8SMlgC7VWzEtmXLLBBB8si9JmtrxrcQ9ro1 /Dsde+jqm/U0hbHFjO7dFmmGKKc4 X-Google-Smtp-Source: APXvYqzRgVRscQKIDQCgWm5iZY0/yYUVy60mbmW2VXbR3ZtsoN98rkU0bkXc4dTe2aMDSB+8rocW+g== X-Received: by 2002:a1c:ce46:: with SMTP id e67mr6699867wmg.40.1551979825881; Thu, 07 Mar 2019 09:30:25 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:25 +0100 Message-Id: <1551979804-6060-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d Subject: [Qemu-devel] [PULL 18/57] tests/libqos: has_buggy_msi flag 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito The Qgraph framework makes any test using pci bus run the same function using pci-pci and pci-spapr bus. However, some tests are not ready to use the spapr bus, due to a MSI bug. Until it does not get fixed, this flag allows them to skip the test Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/libqos/pci-pc.c | 3 +++ tests/libqos/pci-spapr.c | 3 +++ tests/libqos/pci.c | 14 ++++++++++++++ tests/libqos/pci.h | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index d729ad4..4ab16fa 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -124,6 +124,9 @@ void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc) { assert(qts); + /* tests can use pci-bus */ + qpci->bus.has_buggy_msi = FALSE; + qpci->bus.pio_readb = qpci_pc_pio_readb; qpci->bus.pio_readw = qpci_pc_pio_readw; qpci->bus.pio_readl = qpci_pc_pio_readl; diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c index d9b87a7..6925925 100644 --- a/tests/libqos/pci-spapr.c +++ b/tests/libqos/pci-spapr.c @@ -155,6 +155,9 @@ void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts, { assert(qts); + /* tests cannot use spapr, needs to be fixed first */ + qpci->bus.has_buggy_msi = TRUE; + qpci->alloc = alloc; qpci->bus.pio_readb = qpci_spapr_pio_readb; diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index 8257904..662ee7a 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -51,6 +51,20 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, } } +bool qpci_has_buggy_msi(QPCIDevice *dev) +{ + return dev->bus->has_buggy_msi; +} + +bool qpci_check_buggy_msi(QPCIDevice *dev) +{ + if (qpci_has_buggy_msi(dev)) { + g_test_skip("Skipping due to incomplete support for MSI"); + return true; + } + return false; +} + static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn) { g_assert(dev); diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index 9fd521a..8e1d292 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -53,6 +53,7 @@ struct QPCIBus { QTestState *qts; uint16_t pio_alloc_ptr; uint64_t mmio_alloc_ptr, mmio_limit; + bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */ }; @@ -81,6 +82,9 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn); void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr); +bool qpci_has_buggy_msi(QPCIDevice *dev); +bool qpci_check_buggy_msi(QPCIDevice *dev); + void qpci_device_enable(QPCIDevice *dev); uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id); void qpci_msix_enable(QPCIDevice *dev); From patchwork Thu Mar 7 17:29:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lbynUiDc"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdwC5h39z9s7T for ; Fri, 8 Mar 2019 05:10:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xTV-0002Bv-Nt for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:10:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqk-00038L-Tl for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqi-00083N-L7 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:30 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37342) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqi-00082i-9J for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:28 -0500 Received: by mail-wr1-x42c.google.com with SMTP id w6so18399405wrs.4 for ; Thu, 07 Mar 2019 09:30:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=lY5Hdj1Bewp9swhusikSQ4EeMP0GCpeqtL5VawAK+T0=; b=lbynUiDcsakII+mrLSxjr419OccXUmTCwvo3fAQfPXch4miMnUUkzWEjorNPvyk3MT 8WPokD0d6GUaEbz+L+oWHguqBVF5/IuVDFDSJOm7JE8jozdUzWYu+WyR6b4NL3C8FOFB EPd9c7q5oRvFc51LwXLTYaQGgT7e0rctsoXkqhzSX3fwvPs4nJgJ4AvsKjBBcD0Qwod7 OoxfH9k9TTWL6mPAgopD+wmK76TP4KxtHyRcMJjmHq6lw8Hhaes4oworLjnyucJV/xLv BxJUBaioobMDHsSec68dXctZRP1CnyRPEgKwGpmH49OZttTa1nojlH7SzqvNaAJvzWvj Rw5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=lY5Hdj1Bewp9swhusikSQ4EeMP0GCpeqtL5VawAK+T0=; b=dEZWyZbw4Rt15CmDqPwWwxJ0HN5E8cSRC+U/EHm7RDuxr0AY+L8CwHghetcqX0YoYN B+rNEwcs6f/dUWVn1J9uaUCYpRFshNCThjBgNFDGRHg8RSNI+udX+2ePtUCrWgukZrgd sogWygSMtwVmyGExWmJkOSwl92JBpeCmimlLe4ehcB/GJAusTTyWEYreCO/BbfjWDrMY v9OgpKmmNZAySDpONRDG5TjVNmsFxF/6SEp75mqdUBzGOScWg4B1l2r1wCPhqmK+tck3 RzK6ZEQNtE2hS9ulFPE0oMBfOVe0ugOh3bOPY6YKKGQx7vuPlWvg6vf+atKLVvWwKJKx zohw== X-Gm-Message-State: APjAAAUQxWqK5WvOxmPM3RohDbfVYcvIYUQiDNgPLLxyKtOlAVvfSDjl OSv2+iOyGBJgTsROZRm4/6T2+6n9 X-Google-Smtp-Source: APXvYqz/b/F7tmcztKjMOeh/U429t3dkk/S3oMu4zL9PtWBWYouqaLBVAxj1iO3ImWJhkFjZw7cXwA== X-Received: by 2002:adf:ce91:: with SMTP id r17mr7365434wrn.80.1551979826831; Thu, 07 Mar 2019 09:30:26 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:26 +0100 Message-Id: <1551979804-6060-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 19/57] tests/libqos: e1000e driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-e1000e. It consumes a pci-bus, and it's directly used by tests (e1000e is pci based). Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/e1000e.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/e1000e.h | 53 ++++++++++ 3 files changed, 314 insertions(+) create mode 100644 tests/libqos/e1000e.c create mode 100644 tests/libqos/e1000e.h diff --git a/tests/Makefile.include b/tests/Makefile.include index a890327..5bd60a5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -749,6 +749,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt # Devices qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) +qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o # Machines diff --git a/tests/libqos/e1000e.c b/tests/libqos/e1000e.c new file mode 100644 index 0000000..54d3898 --- /dev/null +++ b/tests/libqos/e1000e.c @@ -0,0 +1,260 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qemu-common.h" +#include "libqos/pci-pc.h" +#include "qemu/sockets.h" +#include "qemu/iov.h" +#include "qemu/bitops.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "e1000e.h" + +#define E1000E_IMS (0x00d0) + +#define E1000E_STATUS (0x0008) +#define E1000E_STATUS_LU BIT(1) +#define E1000E_STATUS_ASDV1000 BIT(9) + +#define E1000E_CTRL (0x0000) +#define E1000E_CTRL_RESET BIT(26) + +#define E1000E_RCTL (0x0100) +#define E1000E_RCTL_EN BIT(1) +#define E1000E_RCTL_UPE BIT(3) +#define E1000E_RCTL_MPE BIT(4) + +#define E1000E_RFCTL (0x5008) +#define E1000E_RFCTL_EXTEN BIT(15) + +#define E1000E_TCTL (0x0400) +#define E1000E_TCTL_EN BIT(1) + +#define E1000E_CTRL_EXT (0x0018) +#define E1000E_CTRL_EXT_DRV_LOAD BIT(28) +#define E1000E_CTRL_EXT_TXLSFLOW BIT(22) + +#define E1000E_IVAR (0x00E4) +#define E1000E_IVAR_TEST_CFG ((E1000E_RX0_MSG_ID << 0) | BIT(3) | \ + (E1000E_TX0_MSG_ID << 8) | BIT(11) | \ + (E1000E_OTHER_MSG_ID << 16) | BIT(19) | \ + BIT(31)) + +#define E1000E_RING_LEN (0x1000) + +#define E1000E_TDBAL (0x3800) + +#define E1000E_TDBAH (0x3804) +#define E1000E_TDH (0x3810) + +#define E1000E_RDBAL (0x2800) +#define E1000E_RDBAH (0x2804) +#define E1000E_RDH (0x2810) + +#define E1000E_TXD_LEN (16) +#define E1000E_RXD_LEN (16) + +static void e1000e_macreg_write(QE1000E *d, uint32_t reg, uint32_t val) +{ + QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); + qpci_io_writel(&d_pci->pci_dev, d_pci->mac_regs, reg, val); +} + +static uint32_t e1000e_macreg_read(QE1000E *d, uint32_t reg) +{ + QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); + return qpci_io_readl(&d_pci->pci_dev, d_pci->mac_regs, reg); +} + +void e1000e_tx_ring_push(QE1000E *d, void *descr) +{ + uint32_t tail = e1000e_macreg_read(d, E1000E_TDT); + uint32_t len = e1000e_macreg_read(d, E1000E_TDLEN) / E1000E_TXD_LEN; + + memwrite(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); + e1000e_macreg_write(d, E1000E_TDT, (tail + 1) % len); + + /* Read WB data for the packet transmitted */ + memread(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); +} + +void e1000e_rx_ring_push(QE1000E *d, void *descr) +{ + uint32_t tail = e1000e_macreg_read(d, E1000E_RDT); + uint32_t len = e1000e_macreg_read(d, E1000E_RDLEN) / E1000E_RXD_LEN; + + memwrite(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); + e1000e_macreg_write(d, E1000E_RDT, (tail + 1) % len); + + /* Read WB data for the packet received */ + memread(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); +} + +static void e1000e_foreach_callback(QPCIDevice *dev, int devfn, void *data) +{ + QPCIDevice *res = data; + memcpy(res, dev, sizeof(QPCIDevice)); + g_free(dev); +} + +void e1000e_wait_isr(QE1000E *d, uint16_t msg_id) +{ + QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e); + guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; + + do { + if (qpci_msix_pending(&d_pci->pci_dev, msg_id)) { + return; + } + clock_step(10000); + } while (g_get_monotonic_time() < end_time); + + g_error("Timeout expired"); +} + +static void e1000e_pci_destructor(QOSGraphObject *obj) +{ + QE1000E_PCI *epci = (QE1000E_PCI *) obj; + qpci_iounmap(&epci->pci_dev, epci->mac_regs); + qpci_msix_disable(&epci->pci_dev); +} + +static void e1000e_pci_start_hw(QOSGraphObject *obj) +{ + QE1000E_PCI *d = (QE1000E_PCI *) obj; + uint32_t val; + + /* Enable the device */ + qpci_device_enable(&d->pci_dev); + + /* Reset the device */ + val = e1000e_macreg_read(&d->e1000e, E1000E_CTRL); + e1000e_macreg_write(&d->e1000e, E1000E_CTRL, val | E1000E_CTRL_RESET); + + /* Enable and configure MSI-X */ + qpci_msix_enable(&d->pci_dev); + e1000e_macreg_write(&d->e1000e, E1000E_IVAR, E1000E_IVAR_TEST_CFG); + + /* Check the device status - link and speed */ + val = e1000e_macreg_read(&d->e1000e, E1000E_STATUS); + g_assert_cmphex(val & (E1000E_STATUS_LU | E1000E_STATUS_ASDV1000), + ==, E1000E_STATUS_LU | E1000E_STATUS_ASDV1000); + + /* Initialize TX/RX logic */ + e1000e_macreg_write(&d->e1000e, E1000E_RCTL, 0); + e1000e_macreg_write(&d->e1000e, E1000E_TCTL, 0); + + /* Notify the device that the driver is ready */ + val = e1000e_macreg_read(&d->e1000e, E1000E_CTRL_EXT); + e1000e_macreg_write(&d->e1000e, E1000E_CTRL_EXT, + val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW); + + e1000e_macreg_write(&d->e1000e, E1000E_TDBAL, + (uint32_t) d->e1000e.tx_ring); + e1000e_macreg_write(&d->e1000e, E1000E_TDBAH, + (uint32_t) (d->e1000e.tx_ring >> 32)); + e1000e_macreg_write(&d->e1000e, E1000E_TDLEN, E1000E_RING_LEN); + e1000e_macreg_write(&d->e1000e, E1000E_TDT, 0); + e1000e_macreg_write(&d->e1000e, E1000E_TDH, 0); + + /* Enable transmit */ + e1000e_macreg_write(&d->e1000e, E1000E_TCTL, E1000E_TCTL_EN); + e1000e_macreg_write(&d->e1000e, E1000E_RDBAL, + (uint32_t)d->e1000e.rx_ring); + e1000e_macreg_write(&d->e1000e, E1000E_RDBAH, + (uint32_t)(d->e1000e.rx_ring >> 32)); + e1000e_macreg_write(&d->e1000e, E1000E_RDLEN, E1000E_RING_LEN); + e1000e_macreg_write(&d->e1000e, E1000E_RDT, 0); + e1000e_macreg_write(&d->e1000e, E1000E_RDH, 0); + + /* Enable receive */ + e1000e_macreg_write(&d->e1000e, E1000E_RFCTL, E1000E_RFCTL_EXTEN); + e1000e_macreg_write(&d->e1000e, E1000E_RCTL, E1000E_RCTL_EN | + E1000E_RCTL_UPE | + E1000E_RCTL_MPE); + + /* Enable all interrupts */ + e1000e_macreg_write(&d->e1000e, E1000E_IMS, 0xFFFFFFFF); + +} + +static void *e1000e_pci_get_driver(void *obj, const char *interface) +{ + QE1000E_PCI *epci = obj; + if (!g_strcmp0(interface, "e1000e-if")) { + return &epci->e1000e; + } + + /* implicit contains */ + if (!g_strcmp0(interface, "pci-device")) { + return &epci->pci_dev; + } + + fprintf(stderr, "%s not present in e1000e\n", interface); + g_assert_not_reached(); +} + +static void *e1000e_pci_create(void *pci_bus, QGuestAllocator *alloc, + void *addr) +{ + QE1000E_PCI *d = g_new0(QE1000E_PCI, 1); + QPCIBus *bus = pci_bus; + QPCIAddress *address = addr; + + qpci_device_foreach(bus, address->vendor_id, address->device_id, + e1000e_foreach_callback, &d->pci_dev); + + /* Map BAR0 (mac registers) */ + d->mac_regs = qpci_iomap(&d->pci_dev, 0, NULL); + + /* Allocate and setup TX ring */ + d->e1000e.tx_ring = guest_alloc(alloc, E1000E_RING_LEN); + g_assert(d->e1000e.tx_ring != 0); + + /* Allocate and setup RX ring */ + d->e1000e.rx_ring = guest_alloc(alloc, E1000E_RING_LEN); + g_assert(d->e1000e.rx_ring != 0); + + d->obj.get_driver = e1000e_pci_get_driver; + d->obj.start_hw = e1000e_pci_start_hw; + d->obj.destructor = e1000e_pci_destructor; + + return &d->obj; +} + +static void e1000e_register_nodes(void) +{ + QPCIAddress addr = { + .vendor_id = 0x8086, + .device_id = 0x10D3, + }; + + /* FIXME: every test using this node needs to setup a -netdev socket,id=hs0 + * otherwise QEMU is not going to start */ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "netdev=hs0", + }; + add_qpci_address(&opts, &addr); + + qos_node_create_driver("e1000e", e1000e_pci_create); + qos_node_consumes("e1000e", "pci-bus", &opts); +} + +libqos_init(e1000e_register_nodes); diff --git a/tests/libqos/e1000e.h b/tests/libqos/e1000e.h new file mode 100644 index 0000000..9d37094 --- /dev/null +++ b/tests/libqos/e1000e.h @@ -0,0 +1,53 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef QGRAPH_E1000E +#define QGRAPH_E1000E + +#include "libqos/qgraph.h" +#include "pci.h" + +#define E1000E_RX0_MSG_ID (0) +#define E1000E_TX0_MSG_ID (1) +#define E1000E_OTHER_MSG_ID (2) + +#define E1000E_TDLEN (0x3808) +#define E1000E_TDT (0x3818) +#define E1000E_RDLEN (0x2808) +#define E1000E_RDT (0x2818) + +typedef struct QE1000E QE1000E; +typedef struct QE1000E_PCI QE1000E_PCI; + +struct QE1000E { + uint64_t tx_ring; + uint64_t rx_ring; +}; + +struct QE1000E_PCI { + QOSGraphObject obj; + QPCIDevice pci_dev; + QPCIBar mac_regs; + QE1000E e1000e; +}; + +void e1000e_wait_isr(QE1000E *d, uint16_t msg_id); +void e1000e_tx_ring_push(QE1000E *d, void *descr); +void e1000e_rx_ring_push(QE1000E *d, void *descr); + +#endif From patchwork Thu Mar 7 17:29:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Oja2oQ/a"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdqy0lHvz9s70 for ; Fri, 8 Mar 2019 05:06:54 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xPv-0007Vl-UP for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:06:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqn-0003Bd-PM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqk-00084a-GF for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:33 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42352) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqj-00083X-Fh for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:29 -0500 Received: by mail-wr1-x441.google.com with SMTP id r5so18398960wrg.9 for ; Thu, 07 Mar 2019 09:30:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zgjWJIy9pJ+bIH2ANJiL0w6L4kse8E1FrdCULo/QcZY=; b=Oja2oQ/aEBPPRI8mG7N1pqyjDTVSNV09rlfvNgfc9s6msgl0abkGSWl1OM6FeRcdIH icLFlZCui+N19LnlFGz5GsXru/zw29xB3Y18+Dscng92fohFz8b+bMH2OKqJZVjv9Wyk JTzcz0BtC1ravz2uQtLyMwCS8Mh+dMBb0BKR95X9ALaTWc5mBaPzAk1aDW7IJgZ0fqHm qbnYZca/wFJVxYV763t3CDsZIfysedFGjj6AZxclTrOpH+SsNvZvkPazFxlBe+TSNFfZ JJz4TsEx3Ojv0+hF2nG3+Dssje2cHYmk4YbYkC/560MOJm2RoSwOKIBGnQEtgSiHbdUR JhEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zgjWJIy9pJ+bIH2ANJiL0w6L4kse8E1FrdCULo/QcZY=; b=t2jiA+YwgGBtPjdeIqSz7JwWsTLwHg+9nI18YKa59jh0YTzdcK7DPTNqLPa5ypcRIe mtsB1tzJSSBw1q1tzsG4CtGPuoYd++g4zkGgxymxNK/C4tDdcTO23yaLmLKH4BTMsNa/ u9c93qB915gy0BnOklAd+0U0+8kSqunBlHPEbe/hOjx5vRq1mcyRODU3E5YvGtLlGc+t 0FnzLxESRURhLN3FQ4IQ/wDBWnOHHJ7iIqliGd8jpXxjBSsX2yT2f3yhgRhhKEamahL4 VTtxHtAnV0xZoYuzIARdm8KaCfxsP2EEZTUahnru1vJT3Rt7jHSP3kb9hD+NpmVo1UsG 1YEA== X-Gm-Message-State: APjAAAU1mWZqnxRhu5sbvlmD/nyz/SarAr/W3zwtoLH/3Q3jGdXtMDEt wODT+ECQ8b8OeuDAnamFrVvkPZit X-Google-Smtp-Source: APXvYqyYEBIku5pjSaqYo55UK+WBNQmUgqWEMUKk7L9iKagQDe5Z3CMy6HnveIYrkltbrVjkXLN4Hw== X-Received: by 2002:a5d:4412:: with SMTP id z18mr7614809wrq.111.1551979828014; Thu, 07 Mar 2019 09:30:28 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:27 +0100 Message-Id: <1551979804-6060-21-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PULL 20/57] qos-test: e1000e test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/e1000e-test in qgraph test node, e1000e-test. This test consumes an e1000e interface and checks that its function return the expected values. Note that this test does not allocate any e1000e structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/e1000e-test.c | 356 +++++++++++-------------------------------------- 2 files changed, 78 insertions(+), 281 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 5bd60a5..dbd0e68 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -167,7 +167,6 @@ check-qtest-virtio-$(CONFIG_VIRTIO_SERIAL) += tests/virtio-serial-test$(EXESUF) check-qtest-virtio-y += $(check-qtest-virtioserial-y) check-qtest-pci-y += tests/e1000-test$(EXESUF) -check-qtest-pci-y += tests/e1000e-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) @@ -762,6 +761,7 @@ qos-test-obj-y += tests/libqos/ppc64_pseries-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests +qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o @@ -801,7 +801,6 @@ tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) tests/e1000-test$(EXESUF): tests/e1000-test.o -tests/e1000e-test$(EXESUF): tests/e1000e-test.o $(libqos-pc-obj-y) tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y) tests/pcnet-test$(EXESUF): tests/pcnet-test.o tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index 17a12b8..77ba809 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -32,210 +32,9 @@ #include "qemu/iov.h" #include "qemu/bitops.h" #include "libqos/malloc.h" -#include "libqos/malloc-pc.h" -#include "libqos/malloc-generic.h" +#include "libqos/e1000e.h" -#define E1000E_IMS (0x00d0) - -#define E1000E_STATUS (0x0008) -#define E1000E_STATUS_LU BIT(1) -#define E1000E_STATUS_ASDV1000 BIT(9) - -#define E1000E_CTRL (0x0000) -#define E1000E_CTRL_RESET BIT(26) - -#define E1000E_RCTL (0x0100) -#define E1000E_RCTL_EN BIT(1) -#define E1000E_RCTL_UPE BIT(3) -#define E1000E_RCTL_MPE BIT(4) - -#define E1000E_RFCTL (0x5008) -#define E1000E_RFCTL_EXTEN BIT(15) - -#define E1000E_TCTL (0x0400) -#define E1000E_TCTL_EN BIT(1) - -#define E1000E_CTRL_EXT (0x0018) -#define E1000E_CTRL_EXT_DRV_LOAD BIT(28) -#define E1000E_CTRL_EXT_TXLSFLOW BIT(22) - -#define E1000E_RX0_MSG_ID (0) -#define E1000E_TX0_MSG_ID (1) -#define E1000E_OTHER_MSG_ID (2) - -#define E1000E_IVAR (0x00E4) -#define E1000E_IVAR_TEST_CFG ((E1000E_RX0_MSG_ID << 0) | BIT(3) | \ - (E1000E_TX0_MSG_ID << 8) | BIT(11) | \ - (E1000E_OTHER_MSG_ID << 16) | BIT(19) | \ - BIT(31)) - -#define E1000E_RING_LEN (0x1000) -#define E1000E_TXD_LEN (16) -#define E1000E_RXD_LEN (16) - -#define E1000E_TDBAL (0x3800) -#define E1000E_TDBAH (0x3804) -#define E1000E_TDLEN (0x3808) -#define E1000E_TDH (0x3810) -#define E1000E_TDT (0x3818) - -#define E1000E_RDBAL (0x2800) -#define E1000E_RDBAH (0x2804) -#define E1000E_RDLEN (0x2808) -#define E1000E_RDH (0x2810) -#define E1000E_RDT (0x2818) - -typedef struct e1000e_device { - QPCIDevice *pci_dev; - QPCIBar mac_regs; - - uint64_t tx_ring; - uint64_t rx_ring; -} e1000e_device; - -static int test_sockets[2]; -static QGuestAllocator test_alloc; -static QPCIBus *test_bus; - -static void e1000e_pci_foreach_callback(QPCIDevice *dev, int devfn, void *data) -{ - QPCIDevice **res = data; - - g_assert_null(*res); - *res = dev; -} - -static QPCIDevice *e1000e_device_find(QPCIBus *bus) -{ - static const int e1000e_vendor_id = 0x8086; - static const int e1000e_dev_id = 0x10D3; - - QPCIDevice *e1000e_dev = NULL; - - qpci_device_foreach(bus, e1000e_vendor_id, e1000e_dev_id, - e1000e_pci_foreach_callback, &e1000e_dev); - - g_assert_nonnull(e1000e_dev); - - return e1000e_dev; -} - -static void e1000e_macreg_write(e1000e_device *d, uint32_t reg, uint32_t val) -{ - qpci_io_writel(d->pci_dev, d->mac_regs, reg, val); -} - -static uint32_t e1000e_macreg_read(e1000e_device *d, uint32_t reg) -{ - return qpci_io_readl(d->pci_dev, d->mac_regs, reg); -} - -static void e1000e_device_init(QPCIBus *bus, e1000e_device *d) -{ - uint32_t val; - - d->pci_dev = e1000e_device_find(bus); - - /* Enable the device */ - qpci_device_enable(d->pci_dev); - - /* Map BAR0 (mac registers) */ - d->mac_regs = qpci_iomap(d->pci_dev, 0, NULL); - - /* Reset the device */ - val = e1000e_macreg_read(d, E1000E_CTRL); - e1000e_macreg_write(d, E1000E_CTRL, val | E1000E_CTRL_RESET); - - /* Enable and configure MSI-X */ - qpci_msix_enable(d->pci_dev); - e1000e_macreg_write(d, E1000E_IVAR, E1000E_IVAR_TEST_CFG); - - /* Check the device status - link and speed */ - val = e1000e_macreg_read(d, E1000E_STATUS); - g_assert_cmphex(val & (E1000E_STATUS_LU | E1000E_STATUS_ASDV1000), - ==, E1000E_STATUS_LU | E1000E_STATUS_ASDV1000); - - /* Initialize TX/RX logic */ - e1000e_macreg_write(d, E1000E_RCTL, 0); - e1000e_macreg_write(d, E1000E_TCTL, 0); - - /* Notify the device that the driver is ready */ - val = e1000e_macreg_read(d, E1000E_CTRL_EXT); - e1000e_macreg_write(d, E1000E_CTRL_EXT, - val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW); - - /* Allocate and setup TX ring */ - d->tx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN); - g_assert(d->tx_ring != 0); - - e1000e_macreg_write(d, E1000E_TDBAL, (uint32_t) d->tx_ring); - e1000e_macreg_write(d, E1000E_TDBAH, (uint32_t) (d->tx_ring >> 32)); - e1000e_macreg_write(d, E1000E_TDLEN, E1000E_RING_LEN); - e1000e_macreg_write(d, E1000E_TDT, 0); - e1000e_macreg_write(d, E1000E_TDH, 0); - - /* Enable transmit */ - e1000e_macreg_write(d, E1000E_TCTL, E1000E_TCTL_EN); - - /* Allocate and setup RX ring */ - d->rx_ring = guest_alloc(&test_alloc, E1000E_RING_LEN); - g_assert(d->rx_ring != 0); - - e1000e_macreg_write(d, E1000E_RDBAL, (uint32_t)d->rx_ring); - e1000e_macreg_write(d, E1000E_RDBAH, (uint32_t)(d->rx_ring >> 32)); - e1000e_macreg_write(d, E1000E_RDLEN, E1000E_RING_LEN); - e1000e_macreg_write(d, E1000E_RDT, 0); - e1000e_macreg_write(d, E1000E_RDH, 0); - - /* Enable receive */ - e1000e_macreg_write(d, E1000E_RFCTL, E1000E_RFCTL_EXTEN); - e1000e_macreg_write(d, E1000E_RCTL, E1000E_RCTL_EN | - E1000E_RCTL_UPE | - E1000E_RCTL_MPE); - - /* Enable all interrupts */ - e1000e_macreg_write(d, E1000E_IMS, 0xFFFFFFFF); -} - -static void e1000e_tx_ring_push(e1000e_device *d, void *descr) -{ - uint32_t tail = e1000e_macreg_read(d, E1000E_TDT); - uint32_t len = e1000e_macreg_read(d, E1000E_TDLEN) / E1000E_TXD_LEN; - - memwrite(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); - e1000e_macreg_write(d, E1000E_TDT, (tail + 1) % len); - - /* Read WB data for the packet transmitted */ - memread(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN); -} - -static void e1000e_rx_ring_push(e1000e_device *d, void *descr) -{ - uint32_t tail = e1000e_macreg_read(d, E1000E_RDT); - uint32_t len = e1000e_macreg_read(d, E1000E_RDLEN) / E1000E_RXD_LEN; - - memwrite(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); - e1000e_macreg_write(d, E1000E_RDT, (tail + 1) % len); - - /* Read WB data for the packet received */ - memread(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN); -} - -static void e1000e_wait_isr(e1000e_device *d, uint16_t msg_id) -{ - guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; - - do { - if (qpci_msix_pending(d->pci_dev, msg_id)) { - return; - } - clock_step(10000); - } while (g_get_monotonic_time() < end_time); - - g_error("Timeout expired"); -} - -static void e1000e_send_verify(e1000e_device *d) +static void e1000e_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc) { struct { uint64_t buffer_addr; @@ -268,7 +67,7 @@ static void e1000e_send_verify(e1000e_device *d) uint32_t recv_len; /* Prepare test data buffer */ - uint64_t data = guest_alloc(&test_alloc, data_len); + uint64_t data = guest_alloc(alloc, data_len); memwrite(data, "TEST", 5); /* Prepare TX descriptor */ @@ -296,10 +95,10 @@ static void e1000e_send_verify(e1000e_device *d) g_assert_cmpstr(buffer, == , "TEST"); /* Free test data buffer */ - guest_free(&test_alloc, data); + guest_free(alloc, data); } -static void e1000e_receive_verify(e1000e_device *d) +static void e1000e_receive_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc) { union { struct { @@ -348,7 +147,7 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpint(ret, == , sizeof(test) + sizeof(len)); /* Prepare test data buffer */ - uint64_t data = guest_alloc(&test_alloc, data_len); + uint64_t data = guest_alloc(alloc, data_len); /* Prepare RX descriptor */ memset(&descr, 0, sizeof(descr)); @@ -369,109 +168,108 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpstr(buffer, == , "TEST"); /* Free test data buffer */ - guest_free(&test_alloc, data); -} - -static void e1000e_device_clear(QPCIBus *bus, e1000e_device *d) -{ - qpci_iounmap(d->pci_dev, d->mac_regs); - qpci_msix_disable(d->pci_dev); + guest_free(alloc, data); } -static void data_test_init(e1000e_device *d) +static void test_e1000e_init(void *obj, void *data, QGuestAllocator * alloc) { - char *cmdline; - - int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets); - g_assert_cmpint(ret, != , -1); - - cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 " - "-device e1000e,netdev=hs0", test_sockets[1]); - g_assert_nonnull(cmdline); - - qtest_start(cmdline); - g_free(cmdline); - - pc_alloc_init(&test_alloc, global_qtest, 0); - test_bus = qpci_new_pc(global_qtest, &test_alloc); - g_assert_nonnull(test_bus); - - e1000e_device_init(test_bus, d); + /* init does nothing */ } -static void data_test_clear(e1000e_device *d) +static void test_e1000e_tx(void *obj, void *data, QGuestAllocator * alloc) { - e1000e_device_clear(test_bus, d); - close(test_sockets[0]); - alloc_destroy(&test_alloc); - g_free(d->pci_dev); - qpci_free_pc(test_bus); - qtest_end(); -} - -static void test_e1000e_init(gconstpointer data) -{ - e1000e_device d; - - data_test_init(&d); - data_test_clear(&d); -} - -static void test_e1000e_tx(gconstpointer data) -{ - e1000e_device d; + QE1000E_PCI *e1000e = obj; + QE1000E *d = &e1000e->e1000e; + QOSGraphObject *e_object = obj; + QPCIDevice *dev = e_object->get_driver(e_object, "pci-device"); + + /* FIXME: add spapr support */ + if (qpci_check_buggy_msi(dev)) { + return; + } - data_test_init(&d); - e1000e_send_verify(&d); - data_test_clear(&d); + e1000e_send_verify(d, data, alloc); } -static void test_e1000e_rx(gconstpointer data) +static void test_e1000e_rx(void *obj, void *data, QGuestAllocator * alloc) { - e1000e_device d; + QE1000E_PCI *e1000e = obj; + QE1000E *d = &e1000e->e1000e; + QOSGraphObject *e_object = obj; + QPCIDevice *dev = e_object->get_driver(e_object, "pci-device"); + + /* FIXME: add spapr support */ + if (qpci_check_buggy_msi(dev)) { + return; + } - data_test_init(&d); - e1000e_receive_verify(&d); - data_test_clear(&d); + e1000e_receive_verify(d, data, alloc); } -static void test_e1000e_multiple_transfers(gconstpointer data) +static void test_e1000e_multiple_transfers(void *obj, void *data, + QGuestAllocator *alloc) { static const long iterations = 4 * 1024; long i; - e1000e_device d; + QE1000E_PCI *e1000e = obj; + QE1000E *d = &e1000e->e1000e; + QOSGraphObject *e_object = obj; + QPCIDevice *dev = e_object->get_driver(e_object, "pci-device"); - data_test_init(&d); + /* FIXME: add spapr support */ + if (qpci_check_buggy_msi(dev)) { + return; + } for (i = 0; i < iterations; i++) { - e1000e_send_verify(&d); - e1000e_receive_verify(&d); + e1000e_send_verify(d, data, alloc); + e1000e_receive_verify(d, data, alloc); } - data_test_clear(&d); } -static void test_e1000e_hotplug(gconstpointer data) +static void test_e1000e_hotplug(void *obj, void *data, QGuestAllocator * alloc) { - qtest_start("-device e1000e"); - qtest_qmp_device_add("e1000e", "e1000e_net", "{'addr': '0x06'}"); qpci_unplug_acpi_device_test("e1000e_net", 0x06); +} + +static void data_test_clear(void *sockets) +{ + int *test_sockets = sockets; - qtest_end(); + close(test_sockets[0]); + qos_invalidate_command_line(); + close(test_sockets[1]); + g_free(test_sockets); } -int main(int argc, char **argv) +static void *data_test_init(GString *cmd_line, void *arg) { - g_test_init(&argc, &argv, NULL); + int *test_sockets = g_new(int, 2); + int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets); + g_assert_cmpint(ret, != , -1); - qtest_add_data_func("e1000e/init", NULL, test_e1000e_init); - qtest_add_data_func("e1000e/tx", NULL, test_e1000e_tx); - qtest_add_data_func("e1000e/rx", NULL, test_e1000e_rx); - qtest_add_data_func("e1000e/multiple_transfers", NULL, - test_e1000e_multiple_transfers); - qtest_add_data_func("e1000e/hotplug", NULL, test_e1000e_hotplug); + g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ", + test_sockets[1]); - return g_test_run(); + g_test_queue_destroy(data_test_clear, test_sockets); + return test_sockets; } + +static void register_e1000e_test(void) +{ + QOSGraphTestOptions opts = { + .before = data_test_init, + }; + + qos_add_test("init", "e1000e", test_e1000e_init, &opts); + qos_add_test("tx", "e1000e", test_e1000e_tx, &opts); + qos_add_test("rx", "e1000e", test_e1000e_rx, &opts); + qos_add_test("multiple_transfers", "e1000e", + test_e1000e_multiple_transfers, &opts); + qos_add_test("hotplug", "e1000e", test_e1000e_hotplug, &opts); +} + +libqos_init(register_e1000e_test); From patchwork Thu Mar 7 17:29:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I1Y7Cjkr"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdWP2D68z9s1B for ; Fri, 8 Mar 2019 04:52:33 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xC3-0003cn-8H for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:52:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqn-0003Ba-P1 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wql-00085i-QZ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:33 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:40958) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wql-00084O-6f for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:31 -0500 Received: by mail-wr1-x42e.google.com with SMTP id y6so3258348wrn.7 for ; Thu, 07 Mar 2019 09:30:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=b37Z1HAa42CzxE/GqGEezVy8CPdfzJcbJmdYCDMbnew=; b=I1Y7Cjkrbhom544D3yIdluRGXl/TWfv55GMZVhiuLr6AyiwmI++YTLUVtKyXVAJYKw iDzc2G9IBr3jeKH3iEyV0+dOjUH2G/1fAei+3ItniFBq5lfxWZJvEdjr2hEGVtOckL3S bNbWcJSSSPBs+nIC+0VAfDiigLj2eCmjumZ1LIXeLL9Z0rfuG2E1T1rhxOB63ma9e3QA Ux4sRHZaZZn00cWZ8ZLx+Eaf4wkuggor980Zgqlt88THObS+ZGY8csZ+o9zCBI0tyaJY O+bd2n7D/z7J2fZTRucIX+2XOh4E3BsrcJ3Fz4ydpyokC5LjzjknXVn/fG1Gi1qDpW7F j5mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=b37Z1HAa42CzxE/GqGEezVy8CPdfzJcbJmdYCDMbnew=; b=CgKcqrXdYEma9e9i8OgqEy6DZHI8105BC1eEWuaU/seOVPSanDJHZ5IqrpvRlfYwGX e/LmxGWxbF4IqYIdR51lYQOVf3uMPFHzVYlg8MHQzNyC3HvDXIBUNwJy5gWcdqqhKG4Z E6u73uRZDjL0zGGgnjv4KVZOe7n5GtXdDKzwUt+byc271ECDMPbr1d6nO6kMzo8RQyIU TX79/GRqDvTlltKBCbglC+gQYRHRNh1Ni3vJwpYwTdLex+k5cXbfsL1HU1yIfCoqpYXY NIdrMZ9rpd70H/P6yv5e3wxAFNnQdFm8IGORf5jYZxEl8klXoVCQAIMV2a2JM/m5hGc0 9XmQ== X-Gm-Message-State: APjAAAVc7GlYPr3dESOoVnytHgNA3gdfAjoDsoNEAh01kEjaUutKvFrx m1qiffQqKL+fvfuE++wd/Ajtg0s6 X-Google-Smtp-Source: APXvYqy2oMkQ9HWO8BwvZEVIBMaKiSOrGplKTa0WhQ/CpVcbBldZ/ixvMOVQ9in2KfxQaFvc+H3wAA== X-Received: by 2002:adf:f5d0:: with SMTP id k16mr7389070wrp.325.1551979829084; Thu, 07 Mar 2019 09:30:29 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:28 +0100 Message-Id: <1551979804-6060-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [PULL 21/57] tests/libqos: virtio-pci driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add QOSGraphObject to QVirtioPCIDevice structure, with a basic constructor. virtio-pci is not present in qgraph, since it will be used as starting point by its subclasses (virtio-*-pci) Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-pci.c | 106 ++++++++++++++++++++++++++++++++++------------ tests/libqos/virtio-pci.h | 14 ++++++ tests/virtio-blk-test.c | 6 +++ 4 files changed, 99 insertions(+), 28 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index dbd0e68..c9c6019 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -750,6 +750,7 @@ qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o +qos-test-obj-y += $(libqos-virtio-obj-y) # Machines qos-test-obj-y += tests/libqos/aarch64-xlnx-zcu102-machine.o diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 550dede..6bcdbbb 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -15,12 +15,26 @@ #include "libqos/pci-pc.h" #include "libqos/malloc.h" #include "libqos/malloc-pc.h" +#include "libqos/qgraph.h" #include "standard-headers/linux/virtio_ring.h" #include "standard-headers/linux/virtio_pci.h" #include "hw/pci/pci.h" #include "hw/pci/pci_regs.h" +/* virtio-pci is a superclass of all virtio-xxx-pci devices; + * the relation between virtio-pci and virtio-xxx-pci is implicit, + * and therefore virtio-pci does not produce virtio and is not + * reached by any edge, not even as a "contains" edge. + * In facts, every device is a QVirtioPCIDevice with + * additional fields, since every one has its own + * number of queues and various attributes. + * Virtio-pci provides default functions to start the + * hw and destroy the object, and nodes that want to + * override them should always remember to call the + * original qvirtio_pci_destructor and qvirtio_pci_start_hw. + */ + typedef struct QVirtioPCIForeachData { void (*func)(QVirtioDevice *d, void *data); uint16_t device_type; @@ -32,36 +46,36 @@ typedef struct QVirtioPCIForeachData { void qvirtio_pci_device_free(QVirtioPCIDevice *dev) { g_free(dev->pdev); - g_free(dev); } -static QVirtioPCIDevice *qpcidevice_to_qvirtiodevice(QPCIDevice *pdev) +static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevice *dev, QPCIDevice *pci_dev) { - QVirtioPCIDevice *vpcidev; - vpcidev = g_malloc0(sizeof(*vpcidev)); + dev->pdev = pci_dev; + dev->vdev.device_type = qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); - if (pdev) { - vpcidev->pdev = pdev; - vpcidev->vdev.device_type = - qpci_config_readw(vpcidev->pdev, PCI_SUBSYSTEM_ID); - } + dev->config_msix_entry = -1; - vpcidev->config_msix_entry = -1; + dev->vdev.bus = &qvirtio_pci; - return vpcidev; + /* each virtio-xxx-pci device should override at least this function */ + dev->obj.get_driver = NULL; + dev->obj.start_hw = qvirtio_pci_start_hw; + dev->obj.destructor = qvirtio_pci_destructor; } static void qvirtio_pci_foreach_callback( QPCIDevice *dev, int devfn, void *data) { QVirtioPCIForeachData *d = data; - QVirtioPCIDevice *vpcidev = qpcidevice_to_qvirtiodevice(dev); + QVirtioPCIDevice *vpcidev = g_new0(QVirtioPCIDevice, 1); + qvirtio_pci_init_from_pcidev(vpcidev, dev); if (vpcidev->vdev.device_type == d->device_type && (!d->has_slot || vpcidev->pdev->devfn == d->slot << 3)) { d->func(&vpcidev->vdev, d->user_data); } else { qvirtio_pci_device_free(vpcidev); + g_free(vpcidev); } } @@ -69,14 +83,14 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) { QVirtioPCIDevice **vpcidev = data; assert(!*vpcidev); - *vpcidev = (QVirtioPCIDevice *)d; + *vpcidev = container_of(d, QVirtioPCIDevice, vdev); } #define CONFIG_BASE(dev) (VIRTIO_PCI_CONFIG_OFF((dev)->pdev->msix_enabled)) static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readb(dev->pdev, dev->bar, CONFIG_BASE(dev) + off); } @@ -90,7 +104,7 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off) static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); uint16_t value; value = qpci_io_readw(dev->pdev, dev->bar, CONFIG_BASE(dev) + off); @@ -102,7 +116,7 @@ static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off) static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t off) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); uint32_t value; value = qpci_io_readl(dev->pdev, dev->bar, CONFIG_BASE(dev) + off); @@ -114,7 +128,7 @@ static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t off) static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t off) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); uint64_t val; val = qpci_io_readq(dev->pdev, dev->bar, CONFIG_BASE(dev) + off); @@ -127,37 +141,37 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t off) static uint32_t qvirtio_pci_get_features(QVirtioDevice *d) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_HOST_FEATURES); } static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES, features); } static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES); } static uint8_t qvirtio_pci_get_status(QVirtioDevice *d) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readb(dev->pdev, dev->bar, VIRTIO_PCI_STATUS); } static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); qpci_io_writeb(dev->pdev, dev->bar, VIRTIO_PCI_STATUS, status); } static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); QVirtQueuePCI *vqpci = (QVirtQueuePCI *)vq; uint32_t data; @@ -182,7 +196,7 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); uint32_t data; if (dev->pdev->msix_enabled) { @@ -206,19 +220,19 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) static void qvirtio_pci_queue_select(QVirtioDevice *d, uint16_t index) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); qpci_io_writeb(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_SEL, index); } static uint16_t qvirtio_pci_get_queue_size(QVirtioDevice *d) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); return qpci_io_readw(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_NUM); } static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_PFN, pfn); } @@ -270,7 +284,7 @@ static void qvirtio_pci_virtqueue_cleanup(QVirtQueue *vq, static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { - QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; + QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev); qpci_io_writew(dev->pdev, dev->bar, VIRTIO_PCI_QUEUE_NOTIFY, vq->index); } @@ -294,6 +308,7 @@ const QVirtioBus qvirtio_pci = { .virtqueue_kick = qvirtio_pci_virtqueue_kick, }; +/* TODO: delete this once qgraph is completed */ static void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type, bool has_slot, int slot, void (*func)(QVirtioDevice *d, void *data), void *data) @@ -416,3 +431,38 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, vector = qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR); g_assert_cmphex(vector, !=, VIRTIO_MSI_NO_VECTOR); } + +void qvirtio_pci_destructor(QOSGraphObject *obj) +{ + QVirtioPCIDevice *dev = (QVirtioPCIDevice *)obj; + qvirtio_pci_device_disable(dev); + qvirtio_pci_device_free(dev); +} + +void qvirtio_pci_start_hw(QOSGraphObject *obj) +{ + QVirtioPCIDevice *dev = (QVirtioPCIDevice *)obj; + qvirtio_pci_device_enable(dev); + qvirtio_start_device(&dev->vdev); +} + +void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr) +{ + QPCIDevice *pci_dev = qpci_device_find(bus, addr->devfn); + g_assert_nonnull(pci_dev); + qvirtio_pci_init_from_pcidev(dev, pci_dev); +} + +QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr) +{ + QVirtioPCIDevice *dev; + QPCIDevice *pci_dev = qpci_device_find(bus, addr->devfn); + if (!pci_dev) { + return NULL; + } + + dev = g_new0(QVirtioPCIDevice, 1); + qvirtio_pci_init_from_pcidev(dev, pci_dev); + dev->obj.free = g_free; + return dev; +} diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 6ef1909..5631352 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -12,8 +12,10 @@ #include "libqos/virtio.h" #include "libqos/pci.h" +#include "libqos/qgraph.h" typedef struct QVirtioPCIDevice { + QOSGraphObject obj; QVirtioDevice vdev; QPCIDevice *pdev; QPCIBar bar; @@ -31,11 +33,23 @@ typedef struct QVirtQueuePCI { extern const QVirtioBus qvirtio_pci; +void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr); +QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr); QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type); QVirtioPCIDevice *qvirtio_pci_device_find_slot(QPCIBus *bus, uint16_t device_type, int slot); void qvirtio_pci_device_free(QVirtioPCIDevice *dev); +/* virtio-pci object functions available for subclasses that + * override the original start_hw and destroy + * function. All virtio-xxx-pci subclass that override must + * take care of calling these two functions in the respective + * places + */ +void qvirtio_pci_destructor(QOSGraphObject *obj); +void qvirtio_pci_start_hw(QOSGraphObject *obj); + + void qvirtio_pci_device_enable(QVirtioPCIDevice *d); void qvirtio_pci_device_disable(QVirtioPCIDevice *d); diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index b449970..8f8ef19 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -412,6 +412,7 @@ static void pci_basic(void) qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); qtest_shutdown(qs); } @@ -505,6 +506,7 @@ static void pci_indirect(void) qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); qtest_shutdown(qs); } @@ -534,6 +536,7 @@ static void pci_config(void) qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); qtest_shutdown(qs); } @@ -642,6 +645,7 @@ static void pci_msix(void) qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); qtest_shutdown(qs); } @@ -765,6 +769,7 @@ static void pci_idx(void) qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); qtest_shutdown(qs); } @@ -785,6 +790,7 @@ static void pci_hotplug(void) g_assert(dev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); + g_free(dev); /* unplug secondary disk */ if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { From patchwork Thu Mar 7 17:29:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053129 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C0cY0YGD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdZl5yTfz9s1B for ; Fri, 8 Mar 2019 04:55:27 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xEr-0006Hq-LB for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:55:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqp-0003Fn-Mu for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqn-000873-Pu for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:35 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:53657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wql-00085D-VE for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:33 -0500 Received: by mail-wm1-x32b.google.com with SMTP id e74so10067355wmg.3 for ; Thu, 07 Mar 2019 09:30:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=KvV9AwCyKpmUMPxFMYV4iWpmCw7F9sjtnGD1mBUuCFA=; b=C0cY0YGDF1/4koBfrVubpGGTwMvd3nCJ1Ej7DbxaMpccJwrT3hBRJJI+rrDkOH0dVd tpWuWj2290SjkyxLpaRSSROcqvH7LlpR8pQPBIv71Qxw5vWWmB4DIhocS6v7tMRCLryP oGvPtg1+R8CpDzqU9JUa55LYjk0Px8st48PA/LYyhQJVw0C2FGkKgJspD/EvrFVSLbkc YNHCWRUui/N7j3HHNucqLpTjNb8fFJG2YK1M+yOq8hDYXS/8C2xWZVOnHItreGKadj34 kpvRn81+yCFwS3N9qXDd59FlGZTKIs/CvczCLdqkSEXpNvpmVLs53vKKcHIuJYf4mpaq Uf5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=KvV9AwCyKpmUMPxFMYV4iWpmCw7F9sjtnGD1mBUuCFA=; b=ukCqsD7EVAHChuHlNr7pgS3PvQz4bbAZs5vyJws2pBFgIxxRbFoNitOLPENxrxqOYx gQ/CWL3AdRVHC9JxS2dRaarVlY6w7CQ9DMejPxRV/xri8KSBNJ1NJzRjn1NS4nG9GBNs kC+BP2M5wCNiNd5lTD9hl5Ib9e2qm2Ndy/lwm6Kt9rG5W2VX1ymWHOC7zu3AT/OjXCrP eYXqtG/EYJ900QHxVACAgdJMWxw2DHrcB7SHb5yOcNhg3Q/sftg3NKW4r1O4WsLvTUKk lLMhNqn05+55op+X2ssEzH1sMPE2nPPdGJdBzt0oz6Or4JyC63ts8xVjKGDYR06kjvDT uMlQ== X-Gm-Message-State: APjAAAVoDHxD/GG/td6nA/hinvsheOxWVVCY5WywYWAcVBfUXnOHpLaG eBVxYxInzKnzvHUOWxt+4dRFRPZC X-Google-Smtp-Source: APXvYqz7SACAKa5WN0fyBR9nUVNM3p0MXUFpe2IvhmZArE/XY6WDgQbliMJ7EdMwPhXZ8DPb29jRgQ== X-Received: by 2002:a1c:48f:: with SMTP id 137mr6189640wme.21.1551979830514; Thu, 07 Mar 2019 09:30:30 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:29 +0100 Message-Id: <1551979804-6060-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32b Subject: [Qemu-devel] [PULL 22/57] tests/libqos: remove global_qtest from virtio endianness checks 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is needed to support migration tests with qgraph. Signed-off-by: Paolo Bonzini --- tests/libqos/virtio-pci.c | 11 ++++++++++- tests/libqos/virtio.c | 5 +++++ tests/libqos/virtio.h | 8 ++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 6bcdbbb..0b58b74 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -43,6 +43,14 @@ typedef struct QVirtioPCIForeachData { void *user_data; } QVirtioPCIForeachData; +static inline bool qvirtio_pci_is_big_endian(QVirtioPCIDevice *dev) +{ + QPCIBus *bus = dev->pdev->bus; + + /* FIXME: virtio 1.0 is always little-endian */ + return qtest_big_endian(bus->qts); +} + void qvirtio_pci_device_free(QVirtioPCIDevice *dev) { g_free(dev->pdev); @@ -56,6 +64,7 @@ static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevice *dev, QPCIDevice *pci_ dev->config_msix_entry = -1; dev->vdev.bus = &qvirtio_pci; + dev->vdev.big_endian = qvirtio_pci_is_big_endian(dev); /* each virtio-xxx-pci device should override at least this function */ dev->obj.get_driver = NULL; @@ -99,7 +108,7 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off) * so with a big-endian guest the order has been reversed, * reverse it again * virtio-1.0 is always little-endian, like PCI, but this - * case will be managed inside qvirtio_is_big_endian() + * case will be managed inside qvirtio_pci_is_big_endian() */ static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off) diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index c1ff020..5a62950 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -372,3 +372,8 @@ void qvirtio_start_device(QVirtioDevice *vdev) qvirtio_set_acknowledge(vdev); qvirtio_set_driver(vdev); } + +bool qvirtio_is_big_endian(QVirtioDevice *d) +{ + return d->big_endian; +} diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 2c68668..7f0f9dd 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -21,6 +21,7 @@ typedef struct QVirtioDevice { const QVirtioBus *bus; /* Device type */ uint16_t device_type; + bool big_endian; } QVirtioDevice; typedef struct QVirtQueue { @@ -90,12 +91,6 @@ struct QVirtioBus { void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq); }; -static inline bool qvirtio_is_big_endian(QVirtioDevice *d) -{ - /* FIXME: virtio 1.0 is always little-endian */ - return qtest_big_endian(global_qtest); -} - static inline uint32_t qvring_size(uint32_t num, uint32_t align) { return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num) @@ -109,6 +104,7 @@ uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr); uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr); uint32_t qvirtio_get_features(QVirtioDevice *d); void qvirtio_set_features(QVirtioDevice *d, uint32_t features); +bool qvirtio_is_big_endian(QVirtioDevice *d); void qvirtio_reset(QVirtioDevice *d); void qvirtio_set_acknowledge(QVirtioDevice *d); From patchwork Thu Mar 7 17:29:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="habG9bO0"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdzR1zm3z9s70 for ; Fri, 8 Mar 2019 05:13:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xWD-0004nR-4s for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:13:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqr-0003I0-Qi for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqp-0008AP-Qr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:37 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqn-000869-OL for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:35 -0500 Received: by mail-wr1-x442.google.com with SMTP id g12so18406097wrm.5 for ; Thu, 07 Mar 2019 09:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=feTLCIoYdy5tnPeOnsQNprqM2qsQNbtqLifSbJa7rq8=; b=habG9bO0ZvypgGtP6BM0MGKwddQmyP7HmyPL/8jPr81HGVOhGJwx+gvesP3yg1tqfG CaUernS70EPSZMLpaAP92eY5RYBjLdlYA4Goqnws1mH3ZV2bgkvF0B9VIc4tM7kulSlb tNBczvReTU/xZEka4Wom5Uxd4ngwmDE+gQuoRipGAJusoo5OsaPML9bs3KYo+Ulw6/RO v4jHOdn8h46dVP8LaCh1mci8WGHivxI6NId4qSyNzXo3Dj7sYeIn/FUeBySdzx7y2ASJ 72PkzPALxhfd1jlrdcJM05YFriEsHXdU3Z5rasyIPIauTxUUFOEy2JaBA6Sgny2o5faQ sSKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=feTLCIoYdy5tnPeOnsQNprqM2qsQNbtqLifSbJa7rq8=; b=o51N4pATZp87ONDqBPI2Epd23wqeJi/eBz0gDokhOPoeHifPqzlrKGCRWD+B+uDgOv u35E+Gevh8BIZcKG4/Y9rwKDGEkysP/5XFg3PM387/xKJJKIc4X841wIzcoiwe4ExW0m SMmY54ypxieXtPtmIFuQbg03JkUYVa170urqcbc3/XF6UdO+26463IXRu611JOdyixbe RqpZbbSex/sGe4mRfjJ3yHNSY1qpe/R7qljC9xkpowXV4y5mqsQH2li1j2gn9Ztw0Cli w/F4cfxzjFoWRr+2S+TwurMsXIHjHXZTRoLiYo/4hjnGN5wWmjvNjKpupQx6a4J80FUs uWdw== X-Gm-Message-State: APjAAAXnvxkveXJcrS65uwhRt58p0moI8LxsCvy7Vl97hxHSTpy5yeGe k0/2tq+eWodkKMEWtpm91Ke1uw7A X-Google-Smtp-Source: APXvYqwANpd/Gkbu5xEvCTyzoQhdOPUthISo6OVd/9Ks4WJyUWYfIPYfJPlI4xOvME1GheahW2cSvg== X-Received: by 2002:adf:ed11:: with SMTP id a17mr7732838wro.283.1551979831466; Thu, 07 Mar 2019 09:30:31 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:30 +0100 Message-Id: <1551979804-6060-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PULL 23/57] tests/libqos: virtio-mmio driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add virtio-mmio node in qgraph framework. virtio-mmio produces virtio-bus, the interface consumed by all virtio-*-device nodes. Being a memory-mapped device, it doesn't have to provide a constructor to qgraph, since it's always "contained" inside some other nodes. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Laurent Vivier Signed-off-by: Paolo Bonzini --- tests/libqos/virtio-mmio.c | 116 +++++++++++++++++++++++++++------------------ tests/libqos/virtio-mmio.h | 6 ++- tests/virtio-blk-test.c | 3 +- 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index 7aa8383..3678c07 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -12,74 +12,74 @@ #include "libqos/virtio.h" #include "libqos/virtio-mmio.h" #include "libqos/malloc.h" -#include "libqos/malloc-generic.h" +#include "libqos/qgraph.h" #include "standard-headers/linux/virtio_ring.h" static uint8_t qvirtio_mmio_config_readb(QVirtioDevice *d, uint64_t off) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return readb(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return qtest_readb(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); } static uint16_t qvirtio_mmio_config_readw(QVirtioDevice *d, uint64_t off) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return readw(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return qtest_readw(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); } static uint32_t qvirtio_mmio_config_readl(QVirtioDevice *d, uint64_t off) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return readl(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); } static uint64_t qvirtio_mmio_config_readq(QVirtioDevice *d, uint64_t off) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return readq(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return qtest_readq(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off); } static uint32_t qvirtio_mmio_get_features(QVirtioDevice *d) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - writel(dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0); - return readl(dev->addr + QVIRTIO_MMIO_HOST_FEATURES); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0); + return qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_HOST_FEATURES); } static void qvirtio_mmio_set_features(QVirtioDevice *d, uint32_t features) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); dev->features = features; - writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL, 0); - writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, features); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL, 0); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, features); } static uint32_t qvirtio_mmio_get_guest_features(QVirtioDevice *d) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); return dev->features; } static uint8_t qvirtio_mmio_get_status(QVirtioDevice *d) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return (uint8_t)readl(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return (uint8_t)qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_STATUS); } static void qvirtio_mmio_set_status(QVirtioDevice *d, uint8_t status) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - writel(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS, (uint32_t)status); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_DEVICE_STATUS, (uint32_t)status); } static bool qvirtio_mmio_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); uint32_t isr; - isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 1; + isr = qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 1; if (isr != 0) { - writel(dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 1); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 1); return true; } @@ -88,12 +88,12 @@ static bool qvirtio_mmio_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) static bool qvirtio_mmio_get_config_isr_status(QVirtioDevice *d) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); uint32_t isr; - isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 2; + isr = qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 2; if (isr != 0) { - writel(dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 2); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_INTERRUPT_ACK, 2); return true; } @@ -102,34 +102,34 @@ static bool qvirtio_mmio_get_config_isr_status(QVirtioDevice *d) static void qvirtio_mmio_queue_select(QVirtioDevice *d, uint16_t index) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - writel(dev->addr + QVIRTIO_MMIO_QUEUE_SEL, (uint32_t)index); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_SEL, (uint32_t)index); - g_assert_cmphex(readl(dev->addr + QVIRTIO_MMIO_QUEUE_PFN), ==, 0); + g_assert_cmphex(qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_PFN), ==, 0); } static uint16_t qvirtio_mmio_get_queue_size(QVirtioDevice *d) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - return (uint16_t)readl(dev->addr + QVIRTIO_MMIO_QUEUE_NUM_MAX); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + return (uint16_t)qtest_readl(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_NUM_MAX); } static void qvirtio_mmio_set_queue_address(QVirtioDevice *d, uint32_t pfn) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - writel(dev->addr + QVIRTIO_MMIO_QUEUE_PFN, pfn); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_PFN, pfn); } static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); QVirtQueue *vq; uint64_t addr; vq = g_malloc0(sizeof(*vq)); qvirtio_mmio_queue_select(d, index); - writel(dev->addr + QVIRTIO_MMIO_QUEUE_ALIGN, dev->page_size); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_ALIGN, dev->page_size); vq->index = index; vq->size = qvirtio_mmio_get_queue_size(d); @@ -139,7 +139,7 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, vq->indirect = (dev->features & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0; vq->event = (dev->features & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0; - writel(dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size); /* Check different than 0 */ g_assert_cmpint(vq->size, !=, 0); @@ -163,8 +163,8 @@ static void qvirtio_mmio_virtqueue_cleanup(QVirtQueue *vq, static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { - QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; - writel(dev->addr + QVIRTIO_MMIO_QUEUE_NOTIFY, vq->index); + QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev); + qtest_writel(dev->qts, dev->addr + QVIRTIO_MMIO_QUEUE_NOTIFY, vq->index); } const QVirtioBus qvirtio_mmio = { @@ -187,21 +187,45 @@ const QVirtioBus qvirtio_mmio = { .virtqueue_kick = qvirtio_mmio_virtqueue_kick, }; -QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size) +static void *qvirtio_mmio_get_driver(void *obj, const char *interface) { - QVirtioMMIODevice *dev; - uint32_t magic; - dev = g_malloc0(sizeof(*dev)); + QVirtioMMIODevice *virtio_mmio = obj; + if (!g_strcmp0(interface, "virtio-bus")) { + return &virtio_mmio->vdev; + } + fprintf(stderr, "%s not present in virtio-mmio\n", interface); + g_assert_not_reached(); +} + +static void qvirtio_mmio_start_hw(QOSGraphObject *obj) +{ + QVirtioMMIODevice *dev = (QVirtioMMIODevice *) obj; + qvirtio_start_device(&dev->vdev); +} - magic = readl(addr + QVIRTIO_MMIO_MAGIC_VALUE); +void qvirtio_mmio_init_device(QVirtioMMIODevice *dev, QTestState *qts, + uint64_t addr, uint32_t page_size) +{ + uint32_t magic; + magic = qtest_readl(qts, addr + QVIRTIO_MMIO_MAGIC_VALUE); g_assert(magic == ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)); + dev->qts = qts; dev->addr = addr; dev->page_size = page_size; - dev->vdev.device_type = readl(addr + QVIRTIO_MMIO_DEVICE_ID); + dev->vdev.device_type = qtest_readl(qts, addr + QVIRTIO_MMIO_DEVICE_ID); dev->vdev.bus = &qvirtio_mmio; - writel(addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size); + qtest_writel(qts, addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size); + + dev->obj.get_driver = qvirtio_mmio_get_driver; + dev->obj.start_hw = qvirtio_mmio_start_hw; +} - return dev; +static void virtio_mmio_register_nodes(void) +{ + qos_node_create_driver("virtio-mmio", NULL); + qos_node_produces("virtio-mmio", "virtio-bus"); } + +libqos_init(virtio_mmio_register_nodes); diff --git a/tests/libqos/virtio-mmio.h b/tests/libqos/virtio-mmio.h index e3e52b9..17a1714 100644 --- a/tests/libqos/virtio-mmio.h +++ b/tests/libqos/virtio-mmio.h @@ -11,6 +11,7 @@ #define LIBQOS_VIRTIO_MMIO_H #include "libqos/virtio.h" +#include "libqos/qgraph.h" #define QVIRTIO_MMIO_MAGIC_VALUE 0x000 #define QVIRTIO_MMIO_VERSION 0x004 @@ -33,7 +34,9 @@ #define QVIRTIO_MMIO_DEVICE_SPECIFIC 0x100 typedef struct QVirtioMMIODevice { + QOSGraphObject obj; QVirtioDevice vdev; + QTestState *qts; uint64_t addr; uint32_t page_size; uint32_t features; /* As it cannot be read later, save it */ @@ -41,6 +44,7 @@ typedef struct QVirtioMMIODevice { extern const QVirtioBus qvirtio_mmio; -QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size); +void qvirtio_mmio_init_device(QVirtioMMIODevice *dev, QTestState *qts, + uint64_t addr, uint32_t page_size); #endif diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 8f8ef19..3a8126f 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -833,7 +833,8 @@ static void mmio_basic(void) arm_test_start(); - dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE); + dev = g_malloc0(sizeof(QVirtioMMIODevice)); + qvirtio_mmio_init_device(dev, global_qtest, MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE); g_assert(dev != NULL); g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); From patchwork Thu Mar 7 17:29:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g0Gioad9"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdvM24Jgz9s9N for ; Fri, 8 Mar 2019 05:09:51 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xSn-0001Ws-5t for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:09:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqt-0003K9-Rt for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqr-0008BO-PA for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:35446) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqp-00086i-KI for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:35 -0500 Received: by mail-wm1-x336.google.com with SMTP id y15so10119343wma.0 for ; Thu, 07 Mar 2019 09:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AhLswjmBjTbfNLDca7Rmx9gVUVlaW7z4DApF2fOvSXY=; b=g0Gioad9pNOxJYid0fw//a4Q9K+fZdFpg95thIc5Ro7dZDupRKu0bPbTaTzcVwkAOE sni6uEOVvgSgxEwIdnTEqxlziqdpcZNNo+RqcOK5h33s+p0gu0cSdJYPg+WOTShAHrdR DEnBFJwtASmt5CUgG337Sf1BxceBUEpke+1kYN5nsTBgz72cRC9Ogwey5I5PQy46Z/ns adxdLyQfhhhpA7nHRKv9QU1+KZKCsp5YNikUrWKI6wEeVS5akEWfh1IMzNaQ0+ZqJpsf nSJOQcSrCNCYhTQWQbd/KZZAdGp8z+CSrmkz7WDFex4EpUEbNdO6L0LRa9r59XbWXTI0 HtHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AhLswjmBjTbfNLDca7Rmx9gVUVlaW7z4DApF2fOvSXY=; b=lPtgk45E0ZLYlXqNDmCOu8t62L+ZUaQ+Rjo1KbEY+MzKieXkoZqimicL7ptoA3DEpV U0JtId9EOMTOj+ZCi75vY/xqC4ye4TFEeRPsGOof7SACYod3dahjPRYrPkRJJumOj3Q9 w3XEuBsfS/OZ97wZQAdCsu+yTEdJQcByFa7kwdLa20YK4TPGOYTj6ktIJ7Eb4TbVgP92 AWMvwEIVWpDHxa8pqhkZBCEC6o8RgvAdX4m7PYvyc7RWa5NF9VnFXevjR4TF3KAKwInk m5lGVru3PhKML93uAKFLp2CwJCXiYTwSB16eLpWonX8AX5+IwhFY9wx9z2ofFp5SNXkz xf6A== X-Gm-Message-State: APjAAAVjAW4sGvVZB2E8OHgKO1tUGFL1yX8sa683URJwfP9yOwNRjeB7 /JdrogOlMs8Ezyob8JprmV4Z59Tu X-Google-Smtp-Source: APXvYqwgchf4TIZ1zDYIfQ5uumexd6FsJJHJE2B1uohjsafy2zaTlSK4JiR0Bmcq7VGhOS2aeV9h3w== X-Received: by 2002:a1c:80d6:: with SMTP id b205mr6708819wmd.109.1551979832510; Thu, 07 Mar 2019 09:30:32 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:31 +0100 Message-Id: <1551979804-6060-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::336 Subject: [Qemu-devel] [PULL 24/57] tests/libqos: arm/virt machine node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add arm/virt machine to the graph. This machine contains virtio-mmio, so its constructor must take care of setting it properly when called. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-virt-machine.c | 90 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/libqos/arm-virt-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index c9c6019..4a9e2e4 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -757,6 +757,7 @@ qos-test-obj-y += tests/libqos/aarch64-xlnx-zcu102-machine.o qos-test-obj-y += tests/libqos/arm-raspi2-machine.o qos-test-obj-y += tests/libqos/arm-sabrelite-machine.o qos-test-obj-y += tests/libqos/arm-smdkc210-machine.o +qos-test-obj-y += tests/libqos/arm-virt-machine.o qos-test-obj-y += tests/libqos/arm-xilinx-zynq-a9-machine.o qos-test-obj-y += tests/libqos/ppc64_pseries-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o diff --git a/tests/libqos/arm-virt-machine.c b/tests/libqos/arm-virt-machine.c new file mode 100644 index 0000000..2abc431 --- /dev/null +++ b/tests/libqos/arm-virt-machine.c @@ -0,0 +1,90 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-mmio.h" + +#define ARM_PAGE_SIZE 4096 +#define VIRTIO_MMIO_BASE_ADDR 0x0A003E00 +#define ARM_VIRT_RAM_ADDR 0x40000000 +#define ARM_VIRT_RAM_SIZE 0x20000000 +#define VIRTIO_MMIO_SIZE 0x00000200 + +typedef struct QVirtMachine QVirtMachine; + +struct QVirtMachine { + QOSGraphObject obj; + QGuestAllocator alloc; + QVirtioMMIODevice virtio_mmio; +}; + +static void virt_destructor(QOSGraphObject *obj) +{ + QVirtMachine *machine = (QVirtMachine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *virt_get_driver(void *object, const char *interface) +{ + QVirtMachine *machine = object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/virtio\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *virt_get_device(void *obj, const char *device) +{ + QVirtMachine *machine = obj; + if (!g_strcmp0(device, "virtio-mmio")) { + return &machine->virtio_mmio.obj; + } + + fprintf(stderr, "%s not present in arm/virtio\n", device); + g_assert_not_reached(); +} + +static void *qos_create_machine_arm_virt(QTestState *qts) +{ + QVirtMachine *machine = g_new0(QVirtMachine, 1); + + alloc_init(&machine->alloc, 0, + ARM_VIRT_RAM_ADDR, + ARM_VIRT_RAM_ADDR + ARM_VIRT_RAM_SIZE, + ARM_PAGE_SIZE); + qvirtio_mmio_init_device(&machine->virtio_mmio, qts, VIRTIO_MMIO_BASE_ADDR, + VIRTIO_MMIO_SIZE); + + machine->obj.get_device = virt_get_device; + machine->obj.get_driver = virt_get_driver; + machine->obj.destructor = virt_destructor; + return machine; +} + +static void virtio_mmio_register_nodes(void) +{ + qos_node_create_machine("arm/virt", qos_create_machine_arm_virt); + qos_node_contains("arm/virt", "virtio-mmio", NULL); +} + +libqos_init(virtio_mmio_register_nodes); From patchwork Thu Mar 7 17:29:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053124 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j8zZPZHw"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdVN0YFlz9s1B for ; Fri, 8 Mar 2019 04:51:40 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xBC-0002x1-2p for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:51:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqt-0003KA-SK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqr-0008BZ-Pt for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:39003) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqp-000883-Nj for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:35 -0500 Received: by mail-wm1-x32c.google.com with SMTP id z84so10075074wmg.4 for ; Thu, 07 Mar 2019 09:30:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=HLAJODswjyjKfIz+7coNEAk6hp68u70/AMOlZAUhVNY=; b=j8zZPZHwELFPm8HY6vjPWNDaQNKVJhOBrLNCDmH5XUcQbXdcc73VrjJeJoj81xaGTf TgycBsof48+a6k3/5rmZJt+K3qBLGCk8qP6Hfq9p5UQDObRxhs1lhhUYwkQCVd7KCEBR vDBBz6f3HscfTgoPNKWpSTCksbMbojkUaSHHGIcxZFRxw8M4SeVzJzMdJGTG2qaq74G7 9Zp/dMoToaI8iSU0HEjxLK+L+KpAjLV0TIdh6eJUQj1sShEaoVaD4G9oWs3di0tLav14 WC3+faUwJbbDzKtPemTYe4Wtlt5e7OwgEJZjPSJ+WpTrBUEpdX05u/myfZpXXQXdzIbL ilnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=HLAJODswjyjKfIz+7coNEAk6hp68u70/AMOlZAUhVNY=; b=sOLz5mBnexTA7kwPJvXsYsegF4Ykzaf94AMCzp5xgR5M/cvZ9walHlc/QNH9zRVNVy BO/BJ6nxiYoBKeeRkAt9xsSMBUoTxDkkTeMYKDu9jFd0UK8Obb0a1GOgR//dfdOq/SNR X1kcZVzvDl1DqYkitSurd7i557CF4iAhsZYGJjwgpDPUk5oLPuhh+A+6bPo6xFUgsbSa 2W6MVOVRzYXXDpcJceSuV3DauHXyLJQe1+vo7QR0N5/e3TUSsffxI4yVr9ORR2XIpA0n bk4GPCqmo9iDRaMxe8CYXJjRzVc5X/XtOhbWMq6IStawlh8W7WqA0ynb250a9ydUQRbp AvrA== X-Gm-Message-State: APjAAAUejPH5KXAMMy7WQjkkvmDM00wm9LBRcUzUfltDKtsQW+I3/cj6 8aW6MG5Pf5gj5UbrRhwaMOyiTDTC X-Google-Smtp-Source: APXvYqzR5WSlMKOIJNleFM+ts4TG+GzOd9Rpu25AXlA3AnFcFflizoZO499WKb7m7wkts+bvDZ6VZA== X-Received: by 2002:a1c:2543:: with SMTP id l64mr6677530wml.116.1551979833577; Thu, 07 Mar 2019 09:30:33 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:32 +0100 Message-Id: <1551979804-6060-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32c Subject: [Qemu-devel] [PULL 25/57] tests/qgraph: add generic virtio testcases 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/virtio-test.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/virtio-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 4a9e2e4..ec929cc 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -766,6 +766,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o +qos-test-obj-y += tests/virtio-test.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) diff --git a/tests/virtio-test.c b/tests/virtio-test.c new file mode 100644 index 0000000..804e537 --- /dev/null +++ b/tests/virtio-test.c @@ -0,0 +1,25 @@ +/* + * QTest testcase for virtio + * + * Copyright (c) 2018 Red Hat, Inc. + * + * 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 "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" + +/* Tests only initialization so far. TODO: Replace with functional tests */ +static void nop(void *obj, void *data, QGuestAllocator *alloc) +{ +} + +static void register_virtio_test(void) +{ + qos_add_test("nop", "virtio", nop, NULL); +} + +libqos_init(register_virtio_test); From patchwork Thu Mar 7 17:29:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BZrDNBT/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fddw0sKtz9sD4 for ; Fri, 8 Mar 2019 04:58:12 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xHW-0000Hz-2V for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:58:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqx-0003OR-DC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqt-0008DR-VH for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37438) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqr-0008A3-RM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: by mail-wr1-x441.google.com with SMTP id w6so18399944wrs.4 for ; Thu, 07 Mar 2019 09:30:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PTfP8JpLl7uOvyXr3cNqGAztQtY9kCLVNrC57WeiAB0=; b=BZrDNBT/IUTVzshCp6mPZQwHx+l0tyVuuqjf4wOUbN0vt8PzqU3dhdUwlyWr7D6dvn BpTa+O2mAXfYX32y+5jp+bOzcb3siCSNII/oR1MnPyFKxmdXekLAut8Hh9xDmwdY649+ bcqg3krqQmywCNinYJVFg27ORl3TJ4GzwpaHJTrsGg7E+HdBFeW93fy7NcLvV8AciGrB joGJD8NPrrb804VsgFofemZbNOPHmroqMWvgdGnRS6NZn9auUqYiSZPIJ8dW+h40An8n Uui6xMIEspVb01la5BLv867BKyytqtIPew+8ljdTQYDUaZd/0HyqBO2ERW8ja8beN7xs tKmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PTfP8JpLl7uOvyXr3cNqGAztQtY9kCLVNrC57WeiAB0=; b=NvRPYTzJ1N+Rp/yniC2474dZLcV5veM7y0hDVRW2pDdVs5r+lYosoz4lweCiSvygY/ fufe0H427ui0RoLxF/PHrwUV41GXQ6nlU9QrG4g2H2Bof4mlk17Bi+nEH6nnkpOeSJdW Y+5ecgz1sTbXCYOKgyNPxUCPR52+hwvp7hKsV8RpvRN2DcXsOyg5uCVGQ+dqiVJvvSIw FDZVkf0bfZNPYP+yVjb6tfeqKuwNVD/Qs2N0/+CfXYjZdGK6bXeoelxLjOtsCa3Tgs0f flzskmM1ogQeDuU0zGRMeGBmsMrSZkZVwivoI13rTQWZQk/PHhnbuAq0p1uhV1TwmY4C /ZRQ== X-Gm-Message-State: APjAAAVEUvNwss61Y+fRNQZmsg260xWIWSMRwB3wnjsSun3gZbvEnIfX 34+DEBi8K75dc5Adee2HyJBrBFbg X-Google-Smtp-Source: APXvYqyxGuwddQ4GX0hezg9HjSXH1kf4rg1Pq+Iv1g6w19g2etFRo+O2wwQ350q9YXDuf9ZnvqnIIg== X-Received: by 2002:adf:8251:: with SMTP id 75mr8226386wrb.112.1551979834909; Thu, 07 Mar 2019 09:30:34 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:33 +0100 Message-Id: <1551979804-6060-27-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PULL 26/57] tests/libqos: virtio-serial driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-serial-pci and virtio-serial-device. Both nodes produce virtio-serial, but virtio-serial-pci receives a pci-bus and uses virtio-pci QOSGraphObject and functions, while virtio-serial-device receives a virtio-bus and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-serial.c | 110 +++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-serial.h | 39 +++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 tests/libqos/virtio-serial.c create mode 100644 tests/libqos/virtio-serial.h diff --git a/tests/Makefile.include b/tests/Makefile.include index ec929cc..2a51cab 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -751,6 +751,7 @@ qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += $(libqos-virtio-obj-y) +qos-test-obj-y += tests/libqos/virtio-serial.o # Machines qos-test-obj-y += tests/libqos/aarch64-xlnx-zcu102-machine.o diff --git a/tests/libqos/virtio-serial.c b/tests/libqos/virtio-serial.c new file mode 100644 index 0000000..91cedef --- /dev/null +++ b/tests/libqos/virtio-serial.c @@ -0,0 +1,110 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-serial.h" + +static void *qvirtio_serial_get_driver(QVirtioSerial *v_serial, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-serial")) { + return v_serial; + } + if (!g_strcmp0(interface, "virtio")) { + return v_serial->vdev; + } + + fprintf(stderr, "%s not present in virtio-serial-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_serial_device_get_driver(void *object, + const char *interface) +{ + QVirtioSerialDevice *v_serial = object; + return qvirtio_serial_get_driver(&v_serial->serial, interface); +} + +static void *virtio_serial_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSerialDevice *virtio_device = g_new0(QVirtioSerialDevice, 1); + QVirtioSerial *interface = &virtio_device->serial; + + interface->vdev = virtio_dev; + + virtio_device->obj.get_driver = qvirtio_serial_device_get_driver; + + return &virtio_device->obj; +} + +/* virtio-serial-pci */ +static void *qvirtio_serial_pci_get_driver(void *object, const char *interface) +{ + QVirtioSerialPCI *v_serial = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_serial->pci_vdev.pdev; + } + return qvirtio_serial_get_driver(&v_serial->serial, interface); +} + +static void *virtio_serial_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSerialPCI *virtio_spci = g_new0(QVirtioSerialPCI, 1); + QVirtioSerial *interface = &virtio_spci->serial; + QOSGraphObject *obj = &virtio_spci->pci_vdev.obj; + + virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_spci->pci_vdev.vdev; + + obj->get_driver = qvirtio_serial_pci_get_driver; + + return obj; +} + +static void virtio_serial_register_nodes(void) +{ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions edge_opts = { }; + + /* virtio-serial-device */ + edge_opts.extra_device_opts = "id=vser0"; + qos_node_create_driver("virtio-serial-device", + virtio_serial_device_create); + qos_node_consumes("virtio-serial-device", "virtio-bus", &edge_opts); + qos_node_produces("virtio-serial-device", "virtio"); + qos_node_produces("virtio-serial-device", "virtio-serial"); + + /* virtio-serial-pci */ + edge_opts.extra_device_opts = "id=vser0,addr=04.0"; + add_qpci_address(&edge_opts, &addr); + qos_node_create_driver("virtio-serial-pci", virtio_serial_pci_create); + qos_node_consumes("virtio-serial-pci", "pci-bus", &edge_opts); + qos_node_produces("virtio-serial-pci", "pci-device"); + qos_node_produces("virtio-serial-pci", "virtio"); + qos_node_produces("virtio-serial-pci", "virtio-serial"); +} + +libqos_init(virtio_serial_register_nodes); diff --git a/tests/libqos/virtio-serial.h b/tests/libqos/virtio-serial.h new file mode 100644 index 0000000..b7e2a5d --- /dev/null +++ b/tests/libqos/virtio-serial.h @@ -0,0 +1,39 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioSerial QVirtioSerial; +typedef struct QVirtioSerialPCI QVirtioSerialPCI; +typedef struct QVirtioSerialDevice QVirtioSerialDevice; + +struct QVirtioSerial { + QVirtioDevice *vdev; +}; + +struct QVirtioSerialPCI { + QVirtioPCIDevice pci_vdev; + QVirtioSerial serial; +}; + +struct QVirtioSerialDevice { + QOSGraphObject obj; + QVirtioSerial serial; +}; From patchwork Thu Mar 7 17:29:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jyPvtRnT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff2j54VLz9s7T for ; Fri, 8 Mar 2019 05:16:13 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xYx-0007S5-Ka for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:16:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqv-0003MT-QP for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqt-0008DM-Un for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:36302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqr-0008Ao-Ri for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:39 -0500 Received: by mail-wm1-x333.google.com with SMTP id j125so10118377wmj.1 for ; Thu, 07 Mar 2019 09:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tm/ryd33j6WKUW5QJW8/39A1xu+xmxtmcNmdEPrlvog=; b=jyPvtRnTf+BIrQcdjcmEizrDMp78VyOXs1mxq7U1OZ+wIGzeKcLRao0a5RtyqZ8S/u GivCnhriDt1VMvTcsF1rlB2HCq4WnU0Bafj/DP/MAZ98Uz/A2tlCmlDbVT2yNZp1iwmJ s6EanqzNjA1Sv5/kGByyvUfKSsJPgHqV/Qx44rjXKHT7CLbDLUO3+IZ5ebm5UMYo4pJT pXyKQ2X8T0zDbudgTz2PhpPQcMRexK+F4qkGij9ZD4i8WVLfoFbAgoecAayk0iDNDZvy IqxWMuHblUNBRI6wnKlaTZATZrZPQxgXGDy6ozggkhF2WACmWmLBtwIy1e25L4/bHQdI gYPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Tm/ryd33j6WKUW5QJW8/39A1xu+xmxtmcNmdEPrlvog=; b=emGpHD88uY7k0ZezrJ7p/dNiPtW/OMLL7ELyJtdu0D7oFMAnlSkN0p6GTgAR6UviaV AUAnN1yTYdnJbz0jfXLI4m83PxVgzcVUYQJ/OwJc9McxlBb1BGyaSWTPGn8zVDwgoeiO 2N9ZWGmDtVFX+zQSB37WCJdSE0aut47HjlKiskLo55nfW2KeUzk4+dsM3Mdf4NAFWGUu gHX7+te8Zw9FY1S/QFN+uZtNX7FbLnaggYRzqB8TgihWds0QGH5avYd2O+eChdvxpYew zDFeY4yYODXb3wZqwcRh9GLwK6+2iMFf4rj8KAzOWwMZeuMSXPxfdDLNFsz95cq6RoMo hJKw== X-Gm-Message-State: APjAAAWwCOyywO96J5RchkFVkaZILfeVYYI1gZ3fWZf26qrnJZQCDF+d LM1VIfLJSuxNWnG/WQX3B45kh5Fy X-Google-Smtp-Source: APXvYqy/XjH0n38jsolYlidMGmxBKyjZcNMO2MaNAQdeZJmcZZzEWZ0hPhNFtkJ48WWCI0VW3qFZbA== X-Received: by 2002:a1c:4c08:: with SMTP id z8mr5839059wmf.99.1551979835885; Thu, 07 Mar 2019 09:30:35 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:34 +0100 Message-Id: <1551979804-6060-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::333 Subject: [Qemu-devel] [PULL 27/57] qos-test: virtio-console and virtio-serial test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/virtio-console-test and tests/virtio-serial-test in qgraph test node. This test consumes a virtio-serial interface and checks that its function return the expected values. Note that this test does not allocate any virtio-console or virtio-serial structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 18 +++++++----------- tests/libqos/virtio.c | 1 + tests/virtio-console-test.c | 38 -------------------------------------- tests/virtio-serial-test.c | 27 ++++++++++++--------------- 4 files changed, 20 insertions(+), 64 deletions(-) delete mode 100644 tests/virtio-console-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 2a51cab..d0cd6d2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -153,18 +153,14 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) -check-qtest-virtioserial-$(CONFIG_VIRTIO_SERIAL) += tests/virtio-console-test$(EXESUF) - -check-qtest-virtio-$(CONFIG_VIRTIO_NET) += tests/virtio-net-test$(EXESUF) -check-qtest-virtio-$(CONFIG_VIRTIO_BALLOON) += tests/virtio-balloon-test$(EXESUF) -check-qtest-virtio-$(CONFIG_VIRTIO_BLK) += tests/virtio-blk-test$(EXESUF) -check-qtest-virtio-$(CONFIG_VIRTIO_RNG) += tests/virtio-rng-test$(EXESUF) -check-qtest-virtio-$(CONFIG_VIRTIO_SCSI) += tests/virtio-scsi-test$(EXESUF) +check-qtest-virtio-y += tests/virtio-net-test$(EXESUF) +check-qtest-virtio-y += tests/virtio-balloon-test$(EXESUF) +check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF) +check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF) +check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) check-qtest-virtio-$(CONFIG_VIRTIO_9P) += tests/virtio-9p-test$(EXESUF) endif -check-qtest-virtio-$(CONFIG_VIRTIO_SERIAL) += tests/virtio-serial-test$(EXESUF) -check-qtest-virtio-y += $(check-qtest-virtioserial-y) check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) @@ -315,6 +311,7 @@ check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF) check-qtest-s390x-y += tests/drive_del-test$(EXESUF) check-qtest-s390x-y += tests/device-plug-test$(EXESUF) check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF) +check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF) check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF) check-qtest-s390x-y += tests/migration-test$(EXESUF) @@ -768,6 +765,7 @@ qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/virtio-test.o +qos-test-obj-y += tests/virtio-serial-test.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) @@ -820,8 +818,6 @@ tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(lib tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y) tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o $(libqos-virtio-obj-y) -tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o $(libqos-virtio-obj-y) -tests/virtio-console-test$(EXESUF): tests/virtio-console-test.o $(libqos-virtio-obj-y) tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 5a62950..9fc8c7e 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -352,6 +352,7 @@ void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx) /* * qvirtio_get_dev_type: * Returns: the preferred virtio bus/device type for the current architecture. + * TODO: delete this */ const char *qvirtio_get_dev_type(void) { diff --git a/tests/virtio-console-test.c b/tests/virtio-console-test.c deleted file mode 100644 index a7c6f16..0000000 --- a/tests/virtio-console-test.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * QTest testcase for VirtIO Console - * - * Copyright (c) 2014 SUSE LINUX Products GmbH - * - * 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 "qemu/osdep.h" -#include "libqtest.h" -#include "libqos/virtio.h" - -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void console_nop(void) -{ - global_qtest = qtest_initf("-device virtio-serial-%s,id=vser0 " - "-device virtconsole,bus=vser0.0", - qvirtio_get_dev_type()); - qtest_end(); -} - -static void serialport_nop(void) -{ - global_qtest = qtest_initf("-device virtio-serial-%s,id=vser0 " - "-device virtserialport,bus=vser0.0", - qvirtio_get_dev_type()); - qtest_end(); -} - -int main(int argc, char **argv) -{ - g_test_init(&argc, &argv, NULL); - qtest_add_func("/virtio/console/nop", console_nop); - qtest_add_func("/virtio/serialport/nop", serialport_nop); - - return g_test_run(); -} diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c index 8da9980..85f35e0 100644 --- a/tests/virtio-serial-test.c +++ b/tests/virtio-serial-test.c @@ -9,33 +9,30 @@ #include "qemu/osdep.h" #include "libqtest.h" -#include "libqos/virtio.h" +#include "libqos/virtio-serial.h" /* Tests only initialization so far. TODO: Replace with functional tests */ -static void virtio_serial_nop(void) +static void virtio_serial_nop(void *obj, void *data, QGuestAllocator *alloc) { + /* no operation */ } -static void hotplug(void) +static void serial_hotplug(void *obj, void *data, QGuestAllocator *alloc) { qtest_qmp_device_add("virtserialport", "hp-port", "{}"); - qtest_qmp_device_del("hp-port"); } -int main(int argc, char **argv) +static void register_virtio_serial_test(void) { - int ret; - - g_test_init(&argc, &argv, NULL); - qtest_add_func("/virtio/serial/nop", virtio_serial_nop); - qtest_add_func("/virtio/serial/hotplug", hotplug); + QOSGraphTestOptions opts = { }; - global_qtest = qtest_initf("-device virtio-serial-%s", - qvirtio_get_dev_type()); - ret = g_test_run(); + opts.edge.before_cmd_line = "-device virtconsole,bus=vser0.0"; + qos_add_test("console-nop", "virtio-serial", virtio_serial_nop, &opts); - qtest_end(); + opts.edge.before_cmd_line = "-device virtserialport,bus=vser0.0"; + qos_add_test("serialport-nop", "virtio-serial", virtio_serial_nop, &opts); - return ret; + qos_add_test("hotplug", "virtio-serial", serial_hotplug, NULL); } +libqos_init(register_virtio_serial_test); From patchwork Thu Mar 7 17:29:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HevWtwEc"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdjB3qGmz9s70 for ; Fri, 8 Mar 2019 05:01:02 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xKG-0002sO-Dy for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:01:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqz-0003Qx-M0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqx-0008G0-N8 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:45 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:37440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqt-0008BD-Pq for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: by mail-wr1-x443.google.com with SMTP id w6so18400069wrs.4 for ; Thu, 07 Mar 2019 09:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ult0mEF+2e0zw3ErazF5kyITFBELMbqUeWoO+zunlEg=; b=HevWtwEc0kBf+D7vBkeHWZDoiv4dp62qeeBGUUGDnct8SkVqXtYRdzZYc7wEuqF3Gp G3/X15BTx1EHYmJ0tGZHgGN+pROXtCuTUndRxOSPEnkObuqgS+GZeAHG/d4K1eJHjqdE /QMew4CR0ci0JMQtiuoV3AokYAa0MnBI18ZH+N/N22t4oENOxRmKAuN6HtKZ7BZa3q9q 0K629xX2SYynxCBY5V4sr8dp6300uiNKEqpCzU0yAwBJDnaVy2rC1IshKjvAY1GXFR2L lRe0c7s+4CuDDvxmJxQDjntaa4lCBNwyjOQlUJZFUhOeW48a6bWhOw+tZ0RFZ/kUE97a 5z7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ult0mEF+2e0zw3ErazF5kyITFBELMbqUeWoO+zunlEg=; b=DaQvY0zjkbnPtZwaMaM7/jfKdPRjcDfack0s96dxNsl0AkUqNp3hqDPM+y7TDr8v// BY9D7HXJ2/NSZcNxY/FPYOe8F+2SO6BddCTtpSPB33j68g15OAzZ/rYJwBVz4MeymRHq ahIZnj+W7wjYiX6SyCm0hRrctF6zOckWGOPxQ6WsuSemE3dQgIMhOx+HMnfsi858Mveu wzBvMMY6corag+tJTMx5yFuSwL8eQt8Tbmg+HGGzvg/hDMu3fXlTlLPum2IK3tgQDD68 ilfidzSmaJ6pOnt96m1dKUmtEFEb5N6jCdpWBqwM2IEOTV33yLwTSEjigqJ8NjgypR8t qmbQ== X-Gm-Message-State: APjAAAXJefjQzIAGv5Sq+1/+aO2mqdG5NGUP6bCSQv/zRiFhx3C+b7nr RMsMwzTEnIs1WFXN8XqMMu/9IqZA X-Google-Smtp-Source: APXvYqxzmfmbegrkD2oQMfQkte9wLh9W6LqVz4SFe+KJIhHRIpDLNo9wJgvJGR9nd2T6NjVnKCwZuA== X-Received: by 2002:a5d:5042:: with SMTP id h2mr7727504wrt.12.1551979836843; Thu, 07 Mar 2019 09:30:36 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:35 +0100 Message-Id: <1551979804-6060-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PULL 28/57] tests/libqos: virtio-9p driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-9p-pci and virtio-9p-device. Both nodes produce virtio-9p, but virtio-9p-pci receives a pci-bus and overrides virtio-pci QOSGraphObject and its functions, while virtio-9p-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-9p.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-9p.h | 42 ++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 tests/libqos/virtio-9p.c create mode 100644 tests/libqos/virtio-9p.h diff --git a/tests/Makefile.include b/tests/Makefile.include index d0cd6d2..cb8f0c5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -748,6 +748,7 @@ qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += $(libqos-virtio-obj-y) +qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-serial.o # Machines diff --git a/tests/libqos/virtio-9p.c b/tests/libqos/virtio-9p.c new file mode 100644 index 0000000..a378b56 --- /dev/null +++ b/tests/libqos/virtio-9p.c @@ -0,0 +1,173 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "standard-headers/linux/virtio_ids.h" +#include "libqos/virtio-9p.h" +#include "libqos/qgraph.h" + +static QGuestAllocator *alloc; + +static void virtio_9p_cleanup(QVirtio9P *interface) +{ + qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); +} + +static void virtio_9p_setup(QVirtio9P *interface) +{ + interface->vq = qvirtqueue_setup(interface->vdev, alloc, 0); + qvirtio_set_driver_ok(interface->vdev); +} + +/* virtio-9p-device */ +static void virtio_9p_device_destructor(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p = (QVirtio9PDevice *) obj; + QVirtio9P *v9p = &v_9p->v9p; + + virtio_9p_cleanup(v9p); +} + +static void virtio_9p_device_start_hw(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p = (QVirtio9PDevice *) obj; + QVirtio9P *v9p = &v_9p->v9p; + + virtio_9p_setup(v9p); +} + +static void *virtio_9p_get_driver(QVirtio9P *v_9p, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-9p")) { + return v_9p; + } + if (!g_strcmp0(interface, "virtio")) { + return v_9p->vdev; + } + + fprintf(stderr, "%s not present in virtio-9p-device\n", interface); + g_assert_not_reached(); +} + +static void *virtio_9p_device_get_driver(void *object, const char *interface) +{ + QVirtio9PDevice *v_9p = object; + return virtio_9p_get_driver(&v_9p->v9p, interface); +} + +static void *virtio_9p_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtio9PDevice *virtio_device = g_new0(QVirtio9PDevice, 1); + QVirtio9P *interface = &virtio_device->v9p; + + interface->vdev = virtio_dev; + alloc = t_alloc; + + virtio_device->obj.destructor = virtio_9p_device_destructor; + virtio_device->obj.get_driver = virtio_9p_device_get_driver; + virtio_device->obj.start_hw = virtio_9p_device_start_hw; + + return &virtio_device->obj; +} + +/* virtio-9p-pci */ +static void virtio_9p_pci_destructor(QOSGraphObject *obj) +{ + QVirtio9PPCI *v9_pci = (QVirtio9PPCI *) obj; + QVirtio9P *interface = &v9_pci->v9p; + QOSGraphObject *pci_vobj = &v9_pci->pci_vdev.obj; + + virtio_9p_cleanup(interface); + qvirtio_pci_destructor(pci_vobj); +} + +static void virtio_9p_pci_start_hw(QOSGraphObject *obj) +{ + QVirtio9PPCI *v9_pci = (QVirtio9PPCI *) obj; + QVirtio9P *interface = &v9_pci->v9p; + QOSGraphObject *pci_vobj = &v9_pci->pci_vdev.obj; + + qvirtio_pci_start_hw(pci_vobj); + virtio_9p_setup(interface); +} + +static void *virtio_9p_pci_get_driver(void *object, const char *interface) +{ + QVirtio9PPCI *v_9p = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_9p->pci_vdev.pdev; + } + return virtio_9p_get_driver(&v_9p->v9p, interface); +} + +static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtio9PPCI *v9_pci = g_new0(QVirtio9PPCI, 1); + QVirtio9P *interface = &v9_pci->v9p; + QOSGraphObject *obj = &v9_pci->pci_vdev.obj; + + virtio_pci_init(&v9_pci->pci_vdev, pci_bus, addr); + interface->vdev = &v9_pci->pci_vdev.vdev; + alloc = t_alloc; + + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_9P); + + obj->destructor = virtio_9p_pci_destructor; + obj->start_hw = virtio_9p_pci_start_hw; + obj->get_driver = virtio_9p_pci_get_driver; + + return obj; +} + +static void virtio_9p_register_nodes(void) +{ + const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG; + const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG; + + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts = { + .before_cmd_line = "-fsdev synth,id=fsdev0", + }; + + /* virtio-9p-device */ + opts.extra_device_opts = str_simple, + qos_node_create_driver("virtio-9p-device", virtio_9p_device_create); + qos_node_consumes("virtio-9p-device", "virtio-bus", &opts); + qos_node_produces("virtio-9p-device", "virtio"); + qos_node_produces("virtio-9p-device", "virtio-9p"); + + /* virtio-9p-pci */ + opts.extra_device_opts = str_addr; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create); + qos_node_consumes("virtio-9p-pci", "pci-bus", &opts); + qos_node_produces("virtio-9p-pci", "pci-device"); + qos_node_produces("virtio-9p-pci", "virtio"); + qos_node_produces("virtio-9p-pci", "virtio-9p"); + +} + +libqos_init(virtio_9p_register_nodes); diff --git a/tests/libqos/virtio-9p.h b/tests/libqos/virtio-9p.h new file mode 100644 index 0000000..dba2277 --- /dev/null +++ b/tests/libqos/virtio-9p.h @@ -0,0 +1,42 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtio9P QVirtio9P; +typedef struct QVirtio9PPCI QVirtio9PPCI; +typedef struct QVirtio9PDevice QVirtio9PDevice; + +#define MOUNT_TAG "qtest" + +struct QVirtio9P { + QVirtioDevice *vdev; + QVirtQueue *vq; +}; + +struct QVirtio9PPCI { + QVirtioPCIDevice pci_vdev; + QVirtio9P v9p; +}; + +struct QVirtio9PDevice { + QOSGraphObject obj; + QVirtio9P v9p; +}; From patchwork Thu Mar 7 17:29:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Dg2JUm+4"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff6b5cXkz9s70 for ; Fri, 8 Mar 2019 05:19:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xcD-0001Q0-Kw for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:19:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr3-0003VE-IC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqx-0008GA-O1 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:49 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38200) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqv-0008Ca-Op for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wm1-x343.google.com with SMTP id a188so10001843wmf.3 for ; Thu, 07 Mar 2019 09:30:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7TR6DlnweAxCx8K5J44dvhYJYQSKpqKMrNRDI1lDL2w=; b=Dg2JUm+46DPRMqkQ0//tR1z/seDFNxXTDKdRaDftJfzpHphXPahh7AX7OGHN8idZeG Gdu1o/6ealuQjb5fCY5K5cnWL69anGS7jqgnADKKb4vtulHRxA5frcSeZTHG4xMEy8wn DYwfg1NYSzXRu9CCJeXCLKOq6ar0tC6OJ6UZBEsllrCkQRprcjvxiJ5owApnU21SPRrd yPit0sXA6to+2HBMzKDjnPl4t2sdzLkISSwA23Y8LZFxgyeBWRuVYvYifK/+Htn1q9C+ 55dRxHQO1+rf7fsIPF8K8pzqz8rVpG/oKVfk78cZAysGvlAOi0R/wXqOCYjoFzJbFyIF PI5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7TR6DlnweAxCx8K5J44dvhYJYQSKpqKMrNRDI1lDL2w=; b=Mf3Ow7XLJ+cDHcR9fedA5CZueIZ5pHsNzG1n9S8pIfu1QmZglVV6sjaouu8zCTMXDB skeGA0wz/zNWQ2NfU9GiEJUblcfYa1Lf3hTU0WGWXAFT/EmnzLk3AH6jl/EOoaz31QWG xgNSeOsM4Ep4aMDdDRQ7pTUleLjusF65m2jMAfWfVJk6tlw17WktZSPO6IR0Xn/LKOKS g8S5UZZsZaLWk9SgCKZ71Ujxyj2vPRwJawwOQ2yKH+Y4yRWS33cynPVoV8VXnr2XajG0 kG0oP/DfHZyoTcKsyWPSiD2z69u0kA6uWTPNczVsz6Lt6JGyWOy3JBU/01NblD64zlom rOyQ== X-Gm-Message-State: APjAAAX9Js9mwlrSMiRkxgp44e0bEfRDFLe6Z70wWRyRG1OYwK7Xh6k1 GjYQrVSLhV3o6vAsudscS0VnYmFd X-Google-Smtp-Source: APXvYqx7W97NKa++a/Ixd41Mq3CCZBEvyjWexz1ix1atAtm0Op+dd/+HZRtXF2hSf2PGI9Loc6OfnA== X-Received: by 2002:a1c:ce46:: with SMTP id e67mr6700437wmg.40.1551979838399; Thu, 07 Mar 2019 09:30:38 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:36 +0100 Message-Id: <1551979804-6060-30-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 29/57] qos-test: virtio-9p test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/virtio-9p-test into a qgraph test node. This test consumes a virtio-9p interface and checks that its functions return the expected values. Note that this test does not allocate any virtio-9p structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 5 +- tests/virtio-9p-test.c | 218 +++++++++++++++++-------------------------------- 2 files changed, 78 insertions(+), 145 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index cb8f0c5..8feca79 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -158,9 +158,6 @@ check-qtest-virtio-y += tests/virtio-balloon-test$(EXESUF) check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF) check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF) check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) -ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy) -check-qtest-virtio-$(CONFIG_VIRTIO_9P) += tests/virtio-9p-test$(EXESUF) -endif check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) @@ -766,6 +763,7 @@ qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/virtio-test.o +qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o qos-test-obj-y += tests/virtio-serial-test.o check-unit-y += tests/test-qgraph$(EXESUF) @@ -818,7 +816,6 @@ tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y) tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y) tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) -tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o $(libqos-virtio-obj-y) tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index 8fd74f6..16107ad 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -9,99 +9,36 @@ #include "qemu/osdep.h" #include "libqtest.h" -#include "qemu-common.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" -#include "libqos/virtio.h" -#include "libqos/virtio-pci.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_pci.h" #include "hw/9pfs/9p.h" #include "hw/9pfs/9p-synth.h" +#include "libqos/virtio-9p.h" +#include "libqos/qgraph.h" #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000) +static QGuestAllocator *alloc; -static const char mount_tag[] = "qtest"; - -typedef struct { - QVirtioDevice *dev; - QOSState *qs; - QVirtQueue *vq; -} QVirtIO9P; - -static QVirtIO9P *qvirtio_9p_start(const char *driver) -{ - const char *arch = qtest_get_arch(); - const char *cmd = "-fsdev synth,id=fsdev0 " - "-device %s,fsdev=fsdev0,mount_tag=%s"; - QVirtIO9P *v9p = g_new0(QVirtIO9P, 1); - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - v9p->qs = qtest_pc_boot(cmd, driver, mount_tag); - } else if (strcmp(arch, "ppc64") == 0) { - v9p->qs = qtest_spapr_boot(cmd, driver, mount_tag); - } else { - g_printerr("virtio-9p tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); - } - global_qtest = v9p->qs->qts; - - return v9p; -} - -static void qvirtio_9p_stop(QVirtIO9P *v9p) -{ - qtest_shutdown(v9p->qs); - g_free(v9p); -} - -static QVirtIO9P *qvirtio_9p_pci_start(void) -{ - QVirtIO9P *v9p = qvirtio_9p_start("virtio-9p-pci"); - QVirtioPCIDevice *dev = qvirtio_pci_device_find(v9p->qs->pcibus, - VIRTIO_ID_9P); - g_assert_nonnull(dev); - g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_9P); - v9p->dev = (QVirtioDevice *) dev; - - qvirtio_pci_device_enable(dev); - qvirtio_start_device(v9p->dev); - - v9p->vq = qvirtqueue_setup(v9p->dev, &v9p->qs->alloc, 0); - - qvirtio_set_driver_ok(v9p->dev); - - return v9p; -} - -static void qvirtio_9p_pci_stop(QVirtIO9P *v9p) -{ - qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, &v9p->qs->alloc); - qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev)); - qvirtio_pci_device_free((QVirtioPCIDevice *)v9p->dev); - qvirtio_9p_stop(v9p); -} - -static void pci_config(QVirtIO9P *v9p) +static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) { - size_t tag_len = qvirtio_config_readw(v9p->dev, 0); + QVirtio9P *v9p = obj; + alloc = t_alloc; + size_t tag_len = qvirtio_config_readw(v9p->vdev, 0); char *tag; int i; - g_assert_cmpint(tag_len, ==, strlen(mount_tag)); + g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG)); tag = g_malloc(tag_len); for (i = 0; i < tag_len; i++) { - tag[i] = qvirtio_config_readb(v9p->dev, i + 2); + tag[i] = qvirtio_config_readb(v9p->vdev, i + 2); } - g_assert_cmpmem(tag, tag_len, mount_tag, tag_len); + g_assert_cmpmem(tag, tag_len, MOUNT_TAG, tag_len); g_free(tag); } #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */ typedef struct { - QVirtIO9P *v9p; + QVirtio9P *v9p; uint16_t tag; uint64_t t_msg; uint32_t t_size; @@ -204,7 +141,7 @@ static void v9fs_string_read(P9Req *req, uint16_t *len, char **string) uint16_t tag; } QEMU_PACKED P9Hdr; -static P9Req *v9fs_req_init(QVirtIO9P *v9p, uint32_t size, uint8_t id, +static P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id, uint16_t tag) { P9Req *req = g_new0(P9Req, 1); @@ -222,7 +159,7 @@ static P9Req *v9fs_req_init(QVirtIO9P *v9p, uint32_t size, uint8_t id, req->v9p = v9p; req->t_size = total_size; - req->t_msg = guest_alloc(&v9p->qs->alloc, req->t_size); + req->t_msg = guest_alloc(alloc, req->t_size); v9fs_memwrite(req, &hdr, 7); req->tag = tag; return req; @@ -230,13 +167,13 @@ static P9Req *v9fs_req_init(QVirtIO9P *v9p, uint32_t size, uint8_t id, static void v9fs_req_send(P9Req *req) { - QVirtIO9P *v9p = req->v9p; + QVirtio9P *v9p = req->v9p; - req->r_msg = guest_alloc(&v9p->qs->alloc, P9_MAX_SIZE); + req->r_msg = guest_alloc(alloc, P9_MAX_SIZE); req->free_head = qvirtqueue_add(v9p->vq, req->t_msg, req->t_size, false, true); qvirtqueue_add(v9p->vq, req->r_msg, P9_MAX_SIZE, true, false); - qvirtqueue_kick(v9p->dev, v9p->vq, req->free_head); + qvirtqueue_kick(v9p->vdev, v9p->vq, req->free_head); req->t_off = 0; } @@ -255,9 +192,9 @@ static const char *rmessage_name(uint8_t id) static void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len) { - QVirtIO9P *v9p = req->v9p; + QVirtio9P *v9p = req->v9p; - qvirtio_wait_used_elem(v9p->dev, v9p->vq, req->free_head, len, + qvirtio_wait_used_elem(v9p->vdev, v9p->vq, req->free_head, len, QVIRTIO_9P_TIMEOUT_US); } @@ -288,10 +225,8 @@ static void v9fs_req_recv(P9Req *req, uint8_t id) static void v9fs_req_free(P9Req *req) { - QVirtIO9P *v9p = req->v9p; - - guest_free(&v9p->qs->alloc, req->t_msg); - guest_free(&v9p->qs->alloc, req->r_msg); + guest_free(alloc, req->t_msg); + guest_free(alloc, req->r_msg); g_free(req); } @@ -304,7 +239,7 @@ static void v9fs_rlerror(P9Req *req, uint32_t *err) } /* size[4] Tversion tag[2] msize[4] version[s] */ -static P9Req *v9fs_tversion(QVirtIO9P *v9p, uint32_t msize, const char *version, +static P9Req *v9fs_tversion(QVirtio9P *v9p, uint32_t msize, const char *version, uint16_t tag) { P9Req *req; @@ -339,7 +274,7 @@ static void v9fs_rversion(P9Req *req, uint16_t *len, char **version) } /* size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s] n_uname[4] */ -static P9Req *v9fs_tattach(QVirtIO9P *v9p, uint32_t fid, uint32_t n_uname, +static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname, uint16_t tag) { const char *uname = ""; /* ignored by QEMU */ @@ -368,7 +303,7 @@ static void v9fs_rattach(P9Req *req, v9fs_qid *qid) } /* size[4] Twalk tag[2] fid[4] newfid[4] nwname[2] nwname*(wname[s]) */ -static P9Req *v9fs_twalk(QVirtIO9P *v9p, uint32_t fid, uint32_t newfid, +static P9Req *v9fs_twalk(QVirtio9P *v9p, uint32_t fid, uint32_t newfid, uint16_t nwname, char *const wnames[], uint16_t tag) { P9Req *req; @@ -410,7 +345,7 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid) } /* size[4] Tlopen tag[2] fid[4] flags[4] */ -static P9Req *v9fs_tlopen(QVirtIO9P *v9p, uint32_t fid, uint32_t flags, +static P9Req *v9fs_tlopen(QVirtio9P *v9p, uint32_t fid, uint32_t flags, uint16_t tag) { P9Req *req; @@ -438,7 +373,7 @@ static void v9fs_rlopen(P9Req *req, v9fs_qid *qid, uint32_t *iounit) } /* size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count] */ -static P9Req *v9fs_twrite(QVirtIO9P *v9p, uint32_t fid, uint64_t offset, +static P9Req *v9fs_twrite(QVirtio9P *v9p, uint32_t fid, uint64_t offset, uint32_t count, const void *data, uint16_t tag) { P9Req *req; @@ -466,7 +401,7 @@ static void v9fs_rwrite(P9Req *req, uint32_t *count) } /* size[4] Tflush tag[2] oldtag[2] */ -static P9Req *v9fs_tflush(QVirtIO9P *v9p, uint16_t oldtag, uint16_t tag) +static P9Req *v9fs_tflush(QVirtio9P *v9p, uint16_t oldtag, uint16_t tag) { P9Req *req; @@ -483,8 +418,10 @@ static void v9fs_rflush(P9Req *req) v9fs_req_free(req); } -static void fs_version(QVirtIO9P *v9p) +static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; const char *version = "9P2000.L"; uint16_t server_len; char *server_version; @@ -499,18 +436,22 @@ static void fs_version(QVirtIO9P *v9p) g_free(server_version); } -static void fs_attach(QVirtIO9P *v9p) +static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; P9Req *req; - fs_version(v9p); + fs_version(v9p, NULL, t_alloc); req = v9fs_tattach(v9p, 0, getuid(), 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, NULL); } -static void fs_walk(QVirtIO9P *v9p) +static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *wnames[P9_MAXWELEM]; uint16_t nwqid; v9fs_qid *wqid; @@ -521,7 +462,7 @@ static void fs_walk(QVirtIO9P *v9p) wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i); } - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, &nwqid, &wqid); @@ -535,13 +476,15 @@ static void fs_walk(QVirtIO9P *v9p) g_free(wqid); } -static void fs_walk_no_slash(QVirtIO9P *v9p) +static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *const wnames[] = { g_strdup(" /") }; P9Req *req; uint32_t err; - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rlerror(req, &err); @@ -551,13 +494,15 @@ static void fs_walk_no_slash(QVirtIO9P *v9p) g_free(wnames[0]); } -static void fs_walk_dotdot(QVirtIO9P *v9p) +static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *const wnames[] = { g_strdup("..") }; v9fs_qid root_qid, *wqid; P9Req *req; - fs_version(v9p); + fs_version(v9p, NULL, t_alloc); req = v9fs_tattach(v9p, 0, getuid(), 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, &root_qid); @@ -572,12 +517,14 @@ static void fs_walk_dotdot(QVirtIO9P *v9p) g_free(wnames[0]); } -static void fs_lopen(QVirtIO9P *v9p) +static void fs_lopen(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) }; P9Req *req; - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -589,15 +536,17 @@ static void fs_lopen(QVirtIO9P *v9p) g_free(wnames[0]); } -static void fs_write(QVirtIO9P *v9p) +static void fs_write(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; static const uint32_t write_count = P9_MAX_SIZE / 2; char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_WRITE_FILE) }; char *buf = g_malloc0(write_count); uint32_t count; P9Req *req; - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -615,14 +564,16 @@ static void fs_write(QVirtIO9P *v9p) g_free(wnames[0]); } -static void fs_flush_success(QVirtIO9P *v9p) +static void fs_flush_success(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) }; P9Req *req, *flush_req; uint32_t reply_len; uint8_t should_block; - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -650,14 +601,16 @@ static void fs_flush_success(QVirtIO9P *v9p) g_free(wnames[0]); } -static void fs_flush_ignored(QVirtIO9P *v9p) +static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtio9P *v9p = obj; + alloc = t_alloc; char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) }; P9Req *req, *flush_req; uint32_t count; uint8_t should_block; - fs_attach(v9p); + fs_attach(v9p, NULL, t_alloc); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -685,39 +638,22 @@ static void fs_flush_ignored(QVirtIO9P *v9p) g_free(wnames[0]); } -typedef void (*v9fs_test_fn)(QVirtIO9P *v9p); - -static void v9fs_run_pci_test(gconstpointer data) +static void register_virtio_9p_test(void) { - v9fs_test_fn fn = data; - QVirtIO9P *v9p = qvirtio_9p_pci_start(); - - if (fn) { - fn(v9p); - } - qvirtio_9p_pci_stop(v9p); -} - -static void v9fs_qtest_pci_add(const char *path, v9fs_test_fn fn) -{ - qtest_add_data_func(path, fn, v9fs_run_pci_test); + qos_add_test("config", "virtio-9p", pci_config, NULL); + qos_add_test("fs/version/basic", "virtio-9p", fs_version, NULL); + qos_add_test("fs/attach/basic", "virtio-9p", fs_attach, NULL); + qos_add_test("fs/walk/basic", "virtio-9p", fs_walk, NULL); + qos_add_test("fs/walk/no_slash", "virtio-9p", fs_walk_no_slash, + NULL); + qos_add_test("fs/walk/dotdot_from_root", "virtio-9p", + fs_walk_dotdot, NULL); + qos_add_test("fs/lopen/basic", "virtio-9p", fs_lopen, NULL); + qos_add_test("fs/write/basic", "virtio-9p", fs_write, NULL); + qos_add_test("fs/flush/success", "virtio-9p", fs_flush_success, + NULL); + qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored, + NULL); } -int main(int argc, char **argv) -{ - g_test_init(&argc, &argv, NULL); - v9fs_qtest_pci_add("/virtio/9p/pci/nop", NULL); - v9fs_qtest_pci_add("/virtio/9p/pci/config", pci_config); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/version/basic", fs_version); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/attach/basic", fs_attach); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/walk/basic", fs_walk); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/walk/no_slash", fs_walk_no_slash); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/walk/dotdot_from_root", - fs_walk_dotdot); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/lopen/basic", fs_lopen); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/write/basic", fs_write); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/flush/success", fs_flush_success); - v9fs_qtest_pci_add("/virtio/9p/pci/fs/flush/ignored", fs_flush_ignored); - - return g_test_run(); -} +libqos_init(register_virtio_9p_test); From patchwork Thu Mar 7 17:29:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="geZyCqmh"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdyc2jz0z9s70 for ; Fri, 8 Mar 2019 05:12:40 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xVW-00049a-8x for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:12:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqz-0003Qz-MV for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqx-0008GF-PG for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:45 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36297) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqv-0008D2-Qs for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wm1-x32d.google.com with SMTP id j125so10118580wmj.1 for ; Thu, 07 Mar 2019 09:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AfDkS6wPBetCgGtPr5eF9mZqt6uxAqMyfxC05FkM4zw=; b=geZyCqmhe91jvpVOy+1LHq1sBjTA73Kl4IFQSNtXJ/efw/nUoMCvShx1QOnzdRui2R 0crZARwyQ0gKEdkJ/ZsRDR+hl6r4Y22Xl+4CIiWtqf5Ox1gXd9oz6J+Aw0QB6LRclTTc 3LWMdKOec3Sbgq10v03/rvk22Ixp6ymWLcf8F5MQoYH5xKhYU51Hh9+fSETF/0m3wiDM BR4YgU8qrCwPYFRXbHgaanFnwfz25rqf2Psso/uc9m5VDTTDgKXhuSPUyFbn/OiPSXii 0Nrsr/l2u6Q9c3MkNBwTNLV9lvY2erEDXUMs77P9TxmVILuqLqJbWgKyR20ixgCxSEEl 9/yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AfDkS6wPBetCgGtPr5eF9mZqt6uxAqMyfxC05FkM4zw=; b=BDx6L2O04iKbrQcr5PKo/q8QA8zDlsIqZo5sy/ojdrKP3HrUehftsbPzCvK5lgFaGt uLTRs+agmtKj5i9xRZaJ5G58aJjlvJjje6f+/vDzgE/38zpoxSP5/DyB8GiwRpZBqMes ZD0B+Ajh3rxAsPFAIB7Dxp7n53mwn9QvplQy3IhYIVgNk4aL9nqmFcEPiDCgp+D1soOh N3+FMYe/OLV6TPqOMjV2vgZYjHRazXN+IlDybHFySMNZ8qwCD8E9405f4wyiTMMaVp/n VvsTvUZ2oc3D5TTqr1rD27eymFva5z4Ve/C+mSlQUuifJ+37G2jcqmeAG2yxWGeugrLG Wy3g== X-Gm-Message-State: APjAAAUlnzERCzSCZ44H21jrArGNYl1RsEO8uPczOxA43NGbgPF1CBVZ WEZs8U4KB1UUXdlm3TECCM5yY3B8 X-Google-Smtp-Source: APXvYqxswDdzwNi7dDq5cdnHF9RCZgpU+hBIEndgzHjuufiHCshtay7BfiIGa8RO3MyPaM9tBk2tDg== X-Received: by 2002:a7b:c94c:: with SMTP id i12mr6325939wml.2.1551979839159; Thu, 07 Mar 2019 09:30:39 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:37 +0100 Message-Id: <1551979804-6060-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d Subject: [Qemu-devel] [PULL 30/57] tests/libqos: virtio-balloon driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-balloon-pci and virtio-balloon-device. Both nodes produce virtio-balloon, but virtio-balloon-pci receives a pci-bus and uses virtio-pci QOSGraphObject and functions, while virtio-balloon-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-balloon.c | 113 ++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-balloon.h | 39 +++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 tests/libqos/virtio-balloon.c create mode 100644 tests/libqos/virtio-balloon.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 8feca79..53794cd 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -746,6 +746,7 @@ qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o +qos-test-obj-y += tests/libqos/virtio-balloon.o qos-test-obj-y += tests/libqos/virtio-serial.o # Machines diff --git a/tests/libqos/virtio-balloon.c b/tests/libqos/virtio-balloon.c new file mode 100644 index 0000000..7e6e9e9 --- /dev/null +++ b/tests/libqos/virtio-balloon.c @@ -0,0 +1,113 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-balloon.h" + +/* virtio-balloon-device */ +static void *qvirtio_balloon_get_driver(QVirtioBalloon *v_balloon, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-balloon")) { + return v_balloon; + } + if (!g_strcmp0(interface, "virtio")) { + return v_balloon->vdev; + } + + fprintf(stderr, "%s not present in virtio-balloon-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_balloon_device_get_driver(void *object, + const char *interface) +{ + QVirtioBalloonDevice *v_balloon = object; + return qvirtio_balloon_get_driver(&v_balloon->balloon, interface); +} + +static void *virtio_balloon_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioBalloonDevice *virtio_bdevice = g_new0(QVirtioBalloonDevice, 1); + QVirtioBalloon *interface = &virtio_bdevice->balloon; + + interface->vdev = virtio_dev; + + virtio_bdevice->obj.get_driver = qvirtio_balloon_device_get_driver; + + return &virtio_bdevice->obj; +} + +/* virtio-balloon-pci */ +static void *qvirtio_balloon_pci_get_driver(void *object, + const char *interface) +{ + QVirtioBalloonPCI *v_balloon = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_balloon->pci_vdev.pdev; + } + return qvirtio_balloon_get_driver(&v_balloon->balloon, interface); +} + +static void *virtio_balloon_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioBalloonPCI *virtio_bpci = g_new0(QVirtioBalloonPCI, 1); + QVirtioBalloon *interface = &virtio_bpci->balloon; + QOSGraphObject *obj = &virtio_bpci->pci_vdev.obj; + + + virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_bpci->pci_vdev.vdev; + + obj->get_driver = qvirtio_balloon_pci_get_driver; + + return obj; +} + +static void virtio_balloon_register_nodes(void) +{ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + + /* virtio-balloon-device */ + qos_node_create_driver("virtio-balloon-device", + virtio_balloon_device_create); + qos_node_consumes("virtio-balloon-device", "virtio-bus", NULL); + qos_node_produces("virtio-balloon-device", "virtio"); + qos_node_produces("virtio-balloon-device", "virtio-balloon"); + + /* virtio-balloon-pci */ + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-balloon-pci", virtio_balloon_pci_create); + qos_node_consumes("virtio-balloon-pci", "pci-bus", &opts); + qos_node_produces("virtio-balloon-pci", "pci-device"); + qos_node_produces("virtio-balloon-pci", "virtio"); + qos_node_produces("virtio-balloon-pci", "virtio-balloon"); +} + +libqos_init(virtio_balloon_register_nodes); diff --git a/tests/libqos/virtio-balloon.h b/tests/libqos/virtio-balloon.h new file mode 100644 index 0000000..e8066c4 --- /dev/null +++ b/tests/libqos/virtio-balloon.h @@ -0,0 +1,39 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioBalloon QVirtioBalloon; +typedef struct QVirtioBalloonPCI QVirtioBalloonPCI; +typedef struct QVirtioBalloonDevice QVirtioBalloonDevice; + +struct QVirtioBalloon { + QVirtioDevice *vdev; +}; + +struct QVirtioBalloonPCI { + QVirtioPCIDevice pci_vdev; + QVirtioBalloon balloon; +}; + +struct QVirtioBalloonDevice { + QOSGraphObject obj; + QVirtioBalloon balloon; +}; From patchwork Thu Mar 7 17:29:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A9m5Q15A"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdn73l6Xz9s70 for ; Fri, 8 Mar 2019 05:04:27 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xNZ-0005OL-C4 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:04:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr4-0003Wk-Mf for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqz-0008HU-MB for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:50 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:37345) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqx-0008EE-M1 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wr1-x42e.google.com with SMTP id w6so18400328wrs.4 for ; Thu, 07 Mar 2019 09:30:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ASBoqVkdgMGHuvMQnRuTHGCFBVvTYt9hCrbHt87lWNk=; b=A9m5Q15AB+k+ioBt9ITf1BwjmDGH+C1LhySbfNwlL0qf9RQI+h1F5Nmk5MTL9Pjf/4 fcj2q3BPCd62O5hNLfhrxENHB3QN4EtNmpDIQYaM39FOQznMjt2uu+wactcKbh6zdWG5 0rakLlN3h3zg4I0upNcnFA4SfASyDUuCDRD9aVxl4yKL9wLo/HEf7aXotLR6nZusno1C xdx6AaCs4tCUeeYLjfx5LyXq8LxywVLBwdrTtJCrlPy/HCsZlWtSHrWtai1htXUXXzSN rvqz84DOf/JHXRo6AcOSz1MgTbDFM8EojQQrWR4tUd2Zr1bUMqJ20aNKQKj75D5IMFb4 5Iqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ASBoqVkdgMGHuvMQnRuTHGCFBVvTYt9hCrbHt87lWNk=; b=UrFNT2SVocXG2h/r+wzsfKyi9g59LA+0SkK2B3mn3sPg1xSBbi/ADXsyt+6Gk7prUp GalC60rEOSVp/ZXqAZj5W7BvBFSiViXxI0puRlVmH8JiYyRbpM3UE2SgSNZ2Ul8Rmcla KFfeRcwb9xzQsLA5uP1ybvZm4krPFwgFIcmJq/w/pBr3CbIXveGbYT0OPRT7QABd+Nqf /AOxgcbyMLTm5DzGKu2I0pxuEiUjFM5HdjCrWm6nZroC7LvlEkJO5ry7YhJizc7LYvJL 6RsfM7k4hVEFmB48lERu7b7WykW+Tkm9JLixB8LfjEDA9ItUaQk217YCzUJQrTrh9r+5 PItQ== X-Gm-Message-State: APjAAAWkhLdEt1syS6R06pgIMcWtzo4QJb4uoKcGNns4WG71KpsIoTcI uZLG/JVQuXSpGhXv+Vr2hxLZcEQ1 X-Google-Smtp-Source: APXvYqyUMV6kOwCChoTBn7B7Df41Qnvgpx8pvAPyMS9leOegGuQnhye738c6GWmlh64JoxQpzDXWyA== X-Received: by 2002:adf:f3d0:: with SMTP id g16mr7676263wrp.29.1551979840379; Thu, 07 Mar 2019 09:30:40 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:38 +0100 Message-Id: <1551979804-6060-32-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [PULL 31/57] tests/qgraph: remove virtio-balloon-test 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito The tests/virtio-balloon-test is covered by generic virtio tests, so remove it. Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- tests/Makefile.include | 3 --- tests/virtio-balloon-test.c | 33 --------------------------------- 2 files changed, 36 deletions(-) delete mode 100644 tests/virtio-balloon-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 53794cd..f53b718 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -154,7 +154,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) check-qtest-virtio-y += tests/virtio-net-test$(EXESUF) -check-qtest-virtio-y += tests/virtio-balloon-test$(EXESUF) check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF) check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF) check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) @@ -308,7 +307,6 @@ check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF) check-qtest-s390x-y += tests/drive_del-test$(EXESUF) check-qtest-s390x-y += tests/device-plug-test$(EXESUF) check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF) -check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF) check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF) check-qtest-s390x-y += tests/migration-test$(EXESUF) @@ -811,7 +809,6 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) -tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o $(libqos-virtio-obj-y) tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y) diff --git a/tests/virtio-balloon-test.c b/tests/virtio-balloon-test.c deleted file mode 100644 index 5a1d0cc..0000000 --- a/tests/virtio-balloon-test.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * QTest testcase for VirtIO Balloon - * - * Copyright (c) 2014 SUSE LINUX Products GmbH - * - * 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 "qemu/osdep.h" -#include "libqtest.h" -#include "libqos/virtio.h" - -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void balloon_nop(void) -{ -} - -int main(int argc, char **argv) -{ - int ret; - - g_test_init(&argc, &argv, NULL); - qtest_add_func("/virtio/balloon/nop", balloon_nop); - - global_qtest = qtest_initf("-device virtio-balloon-%s", - qvirtio_get_dev_type()); - ret = g_test_run(); - - qtest_end(); - - return ret; -} From patchwork Thu Mar 7 17:29:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t7NQ5gaC"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdYh1Qn1z9s1B for ; Fri, 8 Mar 2019 04:54:32 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xDy-0005Lu-4O for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:54:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr1-0003SU-6Q for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqz-0008Hc-My for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:52927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqx-0008Ew-N4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wm1-x342.google.com with SMTP id f65so10068410wma.2 for ; Thu, 07 Mar 2019 09:30:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oeeY8vrpczkGa7OMsxR7sXk8kYRvtqWAb9qZrxVB958=; b=t7NQ5gaC40MRJ+bDjYVj5OeCcMvv6koAqOtIqD/usR/jLEZAz0f976XVVEq7nyQhMK 4NlRuK0LQcdgQLZOB40CeavnvZp4/MwIKbuQ77LesNnk10GtwK6WvflZVmMvjsIZa+UE u22hEnIQn3Z4EEVAFVQjLCUV15HTVg6rI/AVIgR7g6huB2KtN7ACkBRzbDOLkezf+3Co hqXW4RbqpRwfBl+bb4j7bvy1RZ3QMIaFA3NmW5HUyrxZlv9XoNOnZEIde46UGwwEwquf Kl/RFfmbrJx2P4G1ckwuKerZJvwT5buBEvPIdqRih8oTjM91BdFFwgZDnXkW59XN3moI PfBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oeeY8vrpczkGa7OMsxR7sXk8kYRvtqWAb9qZrxVB958=; b=J+NcBji2ioF9c30iVSLvAtb+eBG6SGyJltnWSt1WNeXVENM3OF4pti3qGNne7SpmrA UclPpHwQovgBukufTy0A5uzwXWMboGfi8nNHOtnmAsLLxS0qF/ay1UazkqEXjqC8jofQ VCwFWrZpEnIMM5xaL/5TotfleRnlhiYe4DDx72q2WCvoZ873RTPZWTN6/jhMKaiVCC1S p2pH1yvX3T8aFjRuBCSDAVYUIEjmGSkhucbOrR9TNkZSDPT7o6Dhk5kETD8KwmSrSAB9 L/IIT+NdBigrQM80hLoamQ/dp1C3SAC6QKna8szPSUclaggfsR7Y/Jp+woCyu9kVZLkb aBkg== X-Gm-Message-State: APjAAAVu74qCbta1Eurc6bFxrjWok5kf5vEakRs42P+1HzqT1L4UqhSn KC0D4uLJXxlhr26G/1sFlNS2jED2 X-Google-Smtp-Source: APXvYqwGPNvVxHb7e5I0r0J4yfnS44CuG64rrpps873Ll5aWEP0vwDMJ4OigpP+ByH+Kbz6rVnj3pA== X-Received: by 2002:a7b:c74b:: with SMTP id w11mr6285554wmk.79.1551979841869; Thu, 07 Mar 2019 09:30:41 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:39 +0100 Message-Id: <1551979804-6060-33-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PULL 32/57] tests/libqos: virtio-rng driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-rng-pci and virtio-rng-device. Both nodes produce virtio-rng, but virtio-rng-pci receives a pci-bus and uses virtio-pci QOSGraphObject and functions, while virtio-rng-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-rng.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-rng.h | 39 ++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 tests/libqos/virtio-rng.c create mode 100644 tests/libqos/virtio-rng.h diff --git a/tests/Makefile.include b/tests/Makefile.include index f53b718..2d2817e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -745,6 +745,7 @@ qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-balloon.o +qos-test-obj-y += tests/libqos/virtio-rng.o qos-test-obj-y += tests/libqos/virtio-serial.o # Machines diff --git a/tests/libqos/virtio-rng.c b/tests/libqos/virtio-rng.c new file mode 100644 index 0000000..a1d2c76 --- /dev/null +++ b/tests/libqos/virtio-rng.c @@ -0,0 +1,110 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-rng.h" + +/* virtio-rng-device */ +static void *qvirtio_rng_get_driver(QVirtioRng *v_rng, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-rng")) { + return v_rng; + } + if (!g_strcmp0(interface, "virtio")) { + return v_rng->vdev; + } + + fprintf(stderr, "%s not present in virtio-rng-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_rng_device_get_driver(void *object, + const char *interface) +{ + QVirtioRngDevice *v_rng = object; + return qvirtio_rng_get_driver(&v_rng->rng, interface); +} + +static void *virtio_rng_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioRngDevice *virtio_rdevice = g_new0(QVirtioRngDevice, 1); + QVirtioRng *interface = &virtio_rdevice->rng; + + interface->vdev = virtio_dev; + + virtio_rdevice->obj.get_driver = qvirtio_rng_device_get_driver; + + return &virtio_rdevice->obj; +} + +/* virtio-rng-pci */ +static void *qvirtio_rng_pci_get_driver(void *object, const char *interface) +{ + QVirtioRngPCI *v_rng = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_rng->pci_vdev.pdev; + } + return qvirtio_rng_get_driver(&v_rng->rng, interface); +} + +static void *virtio_rng_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioRngPCI *virtio_rpci = g_new0(QVirtioRngPCI, 1); + QVirtioRng *interface = &virtio_rpci->rng; + QOSGraphObject *obj = &virtio_rpci->pci_vdev.obj; + + virtio_pci_init(&virtio_rpci->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_rpci->pci_vdev.vdev; + + obj->get_driver = qvirtio_rng_pci_get_driver; + + return obj; +} + +static void virtio_rng_register_nodes(void) +{ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + + /* virtio-rng-device */ + qos_node_create_driver("virtio-rng-device", virtio_rng_device_create); + qos_node_consumes("virtio-rng-device", "virtio-bus", NULL); + qos_node_produces("virtio-rng-device", "virtio"); + qos_node_produces("virtio-rng-device", "virtio-rng"); + + /* virtio-rng-pci */ + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-rng-pci", virtio_rng_pci_create); + qos_node_consumes("virtio-rng-pci", "pci-bus", &opts); + qos_node_produces("virtio-rng-pci", "pci-device"); + qos_node_produces("virtio-rng-pci", "virtio"); + qos_node_produces("virtio-rng-pci", "virtio-rng"); +} + +libqos_init(virtio_rng_register_nodes); diff --git a/tests/libqos/virtio-rng.h b/tests/libqos/virtio-rng.h new file mode 100644 index 0000000..fbba988 --- /dev/null +++ b/tests/libqos/virtio-rng.h @@ -0,0 +1,39 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioRng QVirtioRng; +typedef struct QVirtioRngPCI QVirtioRngPCI; +typedef struct QVirtioRngDevice QVirtioRngDevice; + +struct QVirtioRng { + QVirtioDevice *vdev; +}; + +struct QVirtioRngPCI { + QVirtioPCIDevice pci_vdev; + QVirtioRng rng; +}; + +struct QVirtioRngDevice { + QOSGraphObject obj; + QVirtioRng rng; +}; From patchwork Thu Mar 7 17:29:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="usTU36kq"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff1l0XqSz9s7T for ; Fri, 8 Mar 2019 05:15:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xY9-0006gn-10 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:15:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr1-0003SS-4n for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqz-0008Hv-W0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:52107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqz-0008GN-NA for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:45 -0500 Received: by mail-wm1-x343.google.com with SMTP id n19so10054307wmi.1 for ; Thu, 07 Mar 2019 09:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DG71ZyHm3BluoQ6xpJ/g+TjbO4Y/s/NXK5J7hNRv/ZQ=; b=usTU36kqwLIV2LJA4ZVwGtxEHo+wxvm83/8MVIyR80GxeVr2R7yxwDruN75wkn2zzU v/tm5mOvdaf6KVq3MOTXghvltYMpXpUw8eWUgmNO70THFt2ZwJa5gDdTznVyM9hLyT2d vf7AvzYgGue17QLwRFjEYfnHgCoGiZsReYYT5Low5FwcdA5nULetT82jy6RSIiWnyq/u yinJ/Ki9GV/X7Ihsz7C2vTG0bhtGQqgH4Lvr6+vRCfaVKPKGITx6Kq6TZyp55fHyRXZW PVXsdGBJMHjSx5BhnhrqapmYQ8RzVrlDQ6Kf4sauGUGhdN2Q/T7pgwxEGPld/SLs0v4i vatw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DG71ZyHm3BluoQ6xpJ/g+TjbO4Y/s/NXK5J7hNRv/ZQ=; b=GKrCjrSYfJZFeymdPANYp0aeaFVJqime1gUxa7R+OfACaLTz3O0yoJ2nPg8iw0K9UH sl2Xghzsw3tzSh6eXNixc8IksgWO/ambJeY97t6fxVH+juzZgAHHJBljpMvexTsjI3yC eIDNKBqqfFBLiiYSMN8IAzwCzFU0NJuF+cuxqjyCBt++ebZvkQwoDMFMRMw2fpBceKqX n5FitcXqcv4zWtbyXETh8tPgxXblU0NXa+1EFy6aWGMeoBxpZXs13T78gvP1u1pLc+aj 5shrb4WaruGvYU2BlIrLFjoG9Jf8fRmDJ+1aaFArt1nv6vk9JgjhuChyqs6eZSlEAv79 0hVg== X-Gm-Message-State: APjAAAVvf7MnClgsJxc/K/+0q6aBF2W7osJvpMZVWmj5ZD5MwsynLFYN gWDdmem8j5xMdNkHx0HPg2OkJmGA X-Google-Smtp-Source: APXvYqzfzYUyk91SogNDtZWP6ujrFcPBgDAg49V59fH4vVhsRIK+StnSpFwZsJjTW97FLqjvUBqTig== X-Received: by 2002:a1c:2947:: with SMTP id p68mr6474279wmp.104.1551979842994; Thu, 07 Mar 2019 09:30:42 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:40 +0100 Message-Id: <1551979804-6060-34-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 33/57] qos-test: virtio-rng test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/virtio-rng-test in qgraph test node, virtio-rng-test. This test consumes a virtio-rng interface and checks that its function return the expected values. Some functions are implemented only for virtio-rng-pci, so they don't consume virtio-rng, but virtio-rng-pci Note that this test does not allocate any virtio-rng structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/virtio-rng-test.c | 27 +++++++-------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 2d2817e..ebf2212 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,7 +155,6 @@ check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) check-qtest-virtio-y += tests/virtio-net-test$(EXESUF) check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF) -check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF) check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) @@ -764,6 +763,7 @@ qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o +qos-test-obj-y += tests/virtio-rng-test.o qos-test-obj-y += tests/virtio-serial-test.o check-unit-y += tests/test-qgraph$(EXESUF) @@ -813,7 +813,6 @@ tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y) -tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y) tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o diff --git a/tests/virtio-rng-test.c b/tests/virtio-rng-test.c index 657d9a4..5309c7c 100644 --- a/tests/virtio-rng-test.c +++ b/tests/virtio-rng-test.c @@ -9,16 +9,12 @@ #include "qemu/osdep.h" #include "libqtest.h" -#include "libqos/pci.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-rng.h" #define PCI_SLOT_HP 0x06 -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) -{ -} - -static void hotplug(void) +static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc) { const char *arch = qtest_get_arch(); @@ -30,18 +26,9 @@ static void hotplug(void) } } -int main(int argc, char **argv) +static void register_virtio_rng_test(void) { - int ret; - - g_test_init(&argc, &argv, NULL); - qtest_add_func("/virtio/rng/pci/nop", pci_nop); - qtest_add_func("/virtio/rng/pci/hotplug", hotplug); - - qtest_start("-device virtio-rng-pci"); - ret = g_test_run(); - - qtest_end(); - - return ret; + qos_add_test("hotplug", "virtio-rng-pci", rng_hotplug, NULL); } + +libqos_init(register_virtio_rng_test); From patchwork Thu Mar 7 17:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="a0gW95Tz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff5Q61gkz9s70 for ; Fri, 8 Mar 2019 05:18:34 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xbE-0000lX-KN for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:18:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr1-0003Ts-Tu for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr0-0008IL-6K for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:52108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqz-0008HG-Q3 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:46 -0500 Received: by mail-wm1-x344.google.com with SMTP id n19so10054376wmi.1 for ; Thu, 07 Mar 2019 09:30:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=V8PXDfNxsmlOrL10JWxkQgNVcXzqfY1jMHiu3eGH/rM=; b=a0gW95Tz4sMjgwof4gP6ogBhtWhG/HhrR1BwVZLLYuLTIOUeZ2VXA8s6WuP6a2Kv2+ iVjim7VymUdrWxjLSiXMR+ODPSS2sCeq+LO1R604ySHbDxXa/FHN75LCUYk4wD5gtGaG F/LykGhKyOyy4UnVXk20bOIoiuZseY81/svf9h/Lj4Zl+HAMYXGumagAjMIAW70z0C0P yJecUnTwNBFWsAnWjUNE+915SLjNYHeInhArI8WlJ6GMwhiU4KJL3dPjA+QQrmBnkYBf qV5vaq6y/tZ/M1UHFWNoeqeucB+QWonCCCxwZukH2xCg41qX+44aKdzC2S/AP7nFtYV3 LdbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=V8PXDfNxsmlOrL10JWxkQgNVcXzqfY1jMHiu3eGH/rM=; b=DHMICwTwvt3d7phhmgGg8wEEQD4AeNPMkG9bEQ90aIwtzbTJxm/3XamsvUQkMQNU6I 0qVmJOlXEyz1slpbyjFOIvowRFu0eHLWLJW+X3SSL3hl4kRXmHvy0oa2bKUGNaxPI0JW zzK8uOkSfoAZhHZaEj1V97sANdgjw9C3571XXivkGWX6FIi1LlTTZ1pTZmhce31na3QF np0BgFpe6a972s8kCQTPfWOELffCugzx9OyEMT2Skr3H8oSmdXPgDDBMTQ5DhExT10Zn +wwX3jD98hNB9hQaS/EuggigljN3oQzSF+dCyuV4o15MZJNpUjZy3VI1TK65FU6lK9Vw thVQ== X-Gm-Message-State: APjAAAUsucBSSIgBGy6KBNUPgGicy/lCye/xTfn2NJKwXWIRE/6DJ/0u GD4OtqCnc//vXhitzpYDmO0bxhMG X-Google-Smtp-Source: APXvYqz4EXkqJS6wS2OsicwgQ5gByxPx5gRL70oAaiWnSNA/J9SuGbdvGHBYXTmy7zFIKSIAUIYcuA== X-Received: by 2002:a1c:dc0a:: with SMTP id t10mr6477168wmg.101.1551979844279; Thu, 07 Mar 2019 09:30:44 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:41 +0100 Message-Id: <1551979804-6060-35-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 34/57] tests/libqos: virtio-blk driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-blk-pci and virtio-blk-device. Both nodes produce virtio-blk, but virtio-blk-pci receives a pci-bus and uses virtio-pci QOSGraphObject and functions, while virtio-blk-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-blk.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-blk.h | 40 +++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 tests/libqos/virtio-blk.c create mode 100644 tests/libqos/virtio-blk.h diff --git a/tests/Makefile.include b/tests/Makefile.include index ebf2212..5ef1b9b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -744,6 +744,7 @@ qos-test-obj-y += tests/libqos/sdhci.o qos-test-obj-y += $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-balloon.o +qos-test-obj-y += tests/libqos/virtio-blk.o qos-test-obj-y += tests/libqos/virtio-rng.o qos-test-obj-y += tests/libqos/virtio-serial.o diff --git a/tests/libqos/virtio-blk.c b/tests/libqos/virtio-blk.c new file mode 100644 index 0000000..c17bdf4 --- /dev/null +++ b/tests/libqos/virtio-blk.c @@ -0,0 +1,124 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "standard-headers/linux/virtio_blk.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-blk.h" + +#define PCI_SLOT 0x04 +#define PCI_FN 0x00 + +/* virtio-blk-device */ +static void *qvirtio_blk_get_driver(QVirtioBlk *v_blk, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-blk")) { + return v_blk; + } + if (!g_strcmp0(interface, "virtio")) { + return v_blk->vdev; + } + + fprintf(stderr, "%s not present in virtio-blk-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_blk_device_get_driver(void *object, + const char *interface) +{ + QVirtioBlkDevice *v_blk = object; + return qvirtio_blk_get_driver(&v_blk->blk, interface); +} + +static void *virtio_blk_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioBlkDevice *virtio_blk = g_new0(QVirtioBlkDevice, 1); + QVirtioBlk *interface = &virtio_blk->blk; + + interface->vdev = virtio_dev; + + virtio_blk->obj.get_driver = qvirtio_blk_device_get_driver; + + return &virtio_blk->obj; +} + +/* virtio-blk-pci */ +static void *qvirtio_blk_pci_get_driver(void *object, const char *interface) +{ + QVirtioBlkPCI *v_blk = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_blk->pci_vdev.pdev; + } + return qvirtio_blk_get_driver(&v_blk->blk, interface); +} + +static void *virtio_blk_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioBlkPCI *virtio_blk = g_new0(QVirtioBlkPCI, 1); + QVirtioBlk *interface = &virtio_blk->blk; + QOSGraphObject *obj = &virtio_blk->pci_vdev.obj; + + virtio_pci_init(&virtio_blk->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_blk->pci_vdev.vdev; + + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_BLOCK); + + obj->get_driver = qvirtio_blk_pci_get_driver; + + return obj; +} + +static void virtio_blk_register_nodes(void) +{ + /* FIXME: every test using these two nodes needs to setup a + * -drive,id=drive0 otherwise QEMU is not going to start. + * Therefore, we do not include "produces" edge for virtio + * and pci-device yet. + */ + + char *arg = g_strdup_printf("id=drv0,drive=drive0,addr=%x.%x", + PCI_SLOT, PCI_FN); + + QPCIAddress addr = { + .devfn = QPCI_DEVFN(PCI_SLOT, PCI_FN), + }; + + QOSGraphEdgeOptions opts = { }; + + /* virtio-blk-device */ + opts.extra_device_opts = "drive=drive0"; + qos_node_create_driver("virtio-blk-device", virtio_blk_device_create); + qos_node_consumes("virtio-blk-device", "virtio-bus", &opts); + qos_node_produces("virtio-blk-device", "virtio-blk"); + + /* virtio-blk-pci */ + opts.extra_device_opts = arg; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-blk-pci", virtio_blk_pci_create); + qos_node_consumes("virtio-blk-pci", "pci-bus", &opts); + qos_node_produces("virtio-blk-pci", "virtio-blk"); + + g_free(arg); +} + +libqos_init(virtio_blk_register_nodes); diff --git a/tests/libqos/virtio-blk.h b/tests/libqos/virtio-blk.h new file mode 100644 index 0000000..dc25849 --- /dev/null +++ b/tests/libqos/virtio-blk.h @@ -0,0 +1,40 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioBlk QVirtioBlk; +typedef struct QVirtioBlkPCI QVirtioBlkPCI; +typedef struct QVirtioBlkDevice QVirtioBlkDevice; + +/* virtqueue is created in each test */ +struct QVirtioBlk { + QVirtioDevice *vdev; +}; + +struct QVirtioBlkPCI { + QVirtioPCIDevice pci_vdev; + QVirtioBlk blk; +}; + +struct QVirtioBlkDevice { + QOSGraphObject obj; + QVirtioBlk blk; +}; From patchwork Thu Mar 7 17:29:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vQ85beYZ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfH41yS2z9s70 for ; Fri, 8 Mar 2019 05:26:56 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xjK-0007ne-3q for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:26:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr5-0003XC-52 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr1-0008Jo-Hr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:35447) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr1-0008Ib-4d for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: by mail-wm1-x335.google.com with SMTP id y15so10119991wma.0 for ; Thu, 07 Mar 2019 09:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i1Dt+JMG8477F9zKEkyymRnRh46/e7kRALE+q1f3QdM=; b=vQ85beYZWdl2f75SHwJvadYCiYI+0BJK4ow/MebhA/oIXNzB+yaPr1B/ZV6tXi40SO mLyiXep8BxIa8WaiCYSNNPpl/sOytPFSE2KjtnhcMu13vLed1oqIjhGNzAQIRZQUMxek yPNhU3acRawLVUszJO3aoICdwhZ/I35yEQ5Cj9Z+oI5Jxckx5W3hAj1MWeoHYCCGFRt2 OSpr/ttA6FB7J/bJlpfLy3HIdqjjjT7QgiYjX1YOHxqrglgHv6XfL1/1tSlZeeVcZPUn i4xQx3umf+ZQnqvPny5rjuF162n2+kRCRNZGbYaKJf6dGvLC+9RN1jfHogRJmzGwIzso 3jsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=i1Dt+JMG8477F9zKEkyymRnRh46/e7kRALE+q1f3QdM=; b=QehATIkVjCv9Se9C3WUdA9tN2FO0phT4+iAjboOif0gy20xzlMlNyvsyj8+njyRLqn wes4sbtHhZnqhaTfwYkEBAitmy3BGnzdKh1oXSJIqmD+GyQiIq7tQLBTMXNMj96TGYup x99SJl9dsv4JvKI1692rInk6z+g9Lae+6RJoQ3wLUJpDpw8RPM6AP6ruvAgUWMRZBM1i NrsuU/1a0seNZ+HADoMQo7OjocP+/vcPsmxW36vVbTECwjJ6ouIpCsTloFNlJSanxOeW +ADSOXSyxnJ6F2y8LphVbSO+rXiSEBKNsCekY5M8ULmjJid+aSyz+CxR+QD3h6TzUQK4 8Ibg== X-Gm-Message-State: APjAAAVzHvnYihbVc9gfxxnMrEFdI/LcI0OpTNnAs6F8gIsL8BRzByXH 4d7M0+YrtLndCutcdeaRPmYQIyVD X-Google-Smtp-Source: APXvYqzJeIYCHVbeB57y52b7xUfxOeymsV9WSgdNOV1a2fO8LmHqjaB15/1DNirvOtDbObjrfEx0qQ== X-Received: by 2002:a1c:80d6:: with SMTP id b205mr6709402wmd.109.1551979845344; Thu, 07 Mar 2019 09:30:45 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:42 +0100 Message-Id: <1551979804-6060-36-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 Subject: [Qemu-devel] [PULL 35/57] qos-test: virtio-blk test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Convert tests/virtio-blk-test in qgraph test node, virtio-blk-test. This test consumes a virtio-blk interface and checks that its function return the expected values. Some functions are implemented only for virtio-blk-pci, so they don't consume virtio-blk, but virtio-blk-pci Note that this test does not allocate any virtio-blk structure, it's all done by the qtest walking graph mechanism. The allocator is also provided by qgraph; remove malloc-generic.c and malloc-generic.h which are not used anymore. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 6 +- tests/libqos/malloc-generic.c | 24 --- tests/libqos/malloc-generic.h | 18 -- tests/libqtest.h | 3 + tests/virtio-blk-test.c | 474 ++++++++++++++++-------------------------- 5 files changed, 189 insertions(+), 336 deletions(-) delete mode 100644 tests/libqos/malloc-generic.c delete mode 100644 tests/libqos/malloc-generic.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 5ef1b9b..1d3133e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -154,7 +154,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) check-qtest-virtio-y += tests/virtio-net-test$(EXESUF) -check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF) check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) @@ -285,7 +284,6 @@ check-qtest-arm-y += tests/pca9552-test$(EXESUF) check-qtest-arm-y += tests/ds1338-test$(EXESUF) check-qtest-arm-y += tests/microbit-test$(EXESUF) check-qtest-arm-y += tests/m25p80-test$(EXESUF) -check-qtest-arm-$(CONFIG_VIRTIO_BLK) += tests/virtio-blk-test$(EXESUF) check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF) check-qtest-arm-y += tests/boot-serial-test$(EXESUF) check-qtest-arm-y += tests/hexloader-test$(EXESUF) @@ -722,7 +720,7 @@ tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o $(test-crypto-obj-y) libqgraph-obj-y = tests/libqos/qgraph.o libqos-obj-y = $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg.o -libqos-obj-y += tests/libqos/malloc.o tests/libqos/malloc-generic.o +libqos-obj-y += tests/libqos/malloc.o libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o libqos-spapr-obj-y = $(libqos-obj-y) tests/libqos/malloc-spapr.o libqos-spapr-obj-y += tests/libqos/libqos-spapr.o @@ -764,6 +762,7 @@ qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o +qos-test-obj-y += tests/virtio-blk-test.o qos-test-obj-y += tests/virtio-rng-test.o qos-test-obj-y += tests/virtio-serial-test.o @@ -811,7 +810,6 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) -tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y) tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) diff --git a/tests/libqos/malloc-generic.c b/tests/libqos/malloc-generic.c deleted file mode 100644 index 766a308..0000000 --- a/tests/libqos/malloc-generic.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Basic libqos generic malloc support - * - * Copyright (c) 2014 Marc Marí - * - * 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 "qemu/osdep.h" -#include "libqos/malloc-generic.h" -#include "libqos/malloc.h" - -/* - * Mostly for valgrind happiness, but it does offer - * a chokepoint for debugging guest memory leaks, too. - */ -void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, - uint64_t size, uint32_t page_size) -{ - uint64_t start = base_addr + (1 << 20); /* Start at 1MB */ - - alloc_init(s, 0, start, start + size, page_size); -} diff --git a/tests/libqos/malloc-generic.h b/tests/libqos/malloc-generic.h deleted file mode 100644 index 40ea058..0000000 --- a/tests/libqos/malloc-generic.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Basic libqos generic malloc support - * - * Copyright (c) 2014 Marc Marí - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ - -#ifndef LIBQOS_MALLOC_GENERIC_H -#define LIBQOS_MALLOC_GENERIC_H - -#include "libqos/malloc.h" - -void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, uint64_t size, - uint32_t page_size); - -#endif diff --git a/tests/libqtest.h b/tests/libqtest.h index 1a2f87e..a16acd5 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -17,6 +17,9 @@ #ifndef LIBQTEST_H #define LIBQTEST_H +#include "qapi/qmp/qobject.h" +#include "qapi/qmp/qdict.h" + typedef struct QTestState QTestState; extern QTestState *global_qtest; diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 3a8126f..b02be02 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -10,20 +10,11 @@ #include "qemu/osdep.h" #include "libqtest.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" -#include "libqos/virtio.h" -#include "libqos/virtio-pci.h" -#include "libqos/virtio-mmio.h" -#include "libqos/malloc.h" -#include "libqos/malloc-generic.h" -#include "qapi/qmp/qdict.h" #include "qemu/bswap.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_config.h" -#include "standard-headers/linux/virtio_ring.h" #include "standard-headers/linux/virtio_blk.h" #include "standard-headers/linux/virtio_pci.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-blk.h" /* TODO actually test the results and get rid of this */ #define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__)) @@ -31,13 +22,6 @@ #define TEST_IMAGE_SIZE (64 * 1024 * 1024) #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) #define PCI_SLOT_HP 0x06 -#define PCI_SLOT 0x04 -#define PCI_FN 0x00 - -#define MMIO_PAGE_SIZE 4096 -#define MMIO_DEV_BASE_ADDR 0x0A003E00 -#define MMIO_RAM_ADDR 0x40000000 -#define MMIO_RAM_SIZE 0x20000000 typedef struct QVirtioBlkReq { uint32_t type; @@ -47,84 +31,34 @@ typedef struct QVirtioBlkReq { uint8_t status; } QVirtioBlkReq; + #ifdef HOST_WORDS_BIGENDIAN const bool host_is_big_endian = true; #else const bool host_is_big_endian; /* false */ #endif +static void drive_destroy(void *path) +{ + unlink(path); + g_free(path); + qos_invalidate_command_line(); +} + static char *drive_create(void) { int fd, ret; - char *tmp_path = g_strdup("/tmp/qtest.XXXXXX"); + char *t_path = g_strdup("/tmp/qtest.XXXXXX"); /* Create a temporary raw image */ - fd = mkstemp(tmp_path); + fd = mkstemp(t_path); g_assert_cmpint(fd, >=, 0); ret = ftruncate(fd, TEST_IMAGE_SIZE); g_assert_cmpint(ret, ==, 0); close(fd); - return tmp_path; -} - -static QOSState *pci_test_start(void) -{ - QOSState *qs; - const char *arch = qtest_get_arch(); - char *tmp_path; - const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw " - "-drive if=none,id=drive1,file=null-co://,format=raw " - "-device virtio-blk-pci,id=drv0,drive=drive0," - "addr=%x.%x"; - - tmp_path = drive_create(); - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qs = qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN); - } else if (strcmp(arch, "ppc64") == 0) { - qs = qtest_spapr_boot(cmd, tmp_path, PCI_SLOT, PCI_FN); - } else { - g_printerr("virtio-blk tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); - } - global_qtest = qs->qts; - unlink(tmp_path); - g_free(tmp_path); - return qs; -} - -static void arm_test_start(void) -{ - char *tmp_path; - - tmp_path = drive_create(); - - global_qtest = qtest_initf("-machine virt " - "-drive if=none,id=drive0,file=%s,format=raw " - "-device virtio-blk-device,drive=drive0", - tmp_path); - unlink(tmp_path); - g_free(tmp_path); -} - -static void test_end(void) -{ - qtest_end(); -} - -static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot) -{ - QVirtioPCIDevice *dev; - - dev = qvirtio_pci_device_find_slot(bus, VIRTIO_ID_BLOCK, slot); - g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); - g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN)); - - qvirtio_pci_device_enable(dev); - qvirtio_start_device(&dev->vdev); - return dev; + g_test_queue_destroy(drive_destroy, t_path); + return t_path; } static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req) @@ -395,32 +329,21 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc, } } -static void pci_basic(void) +static void basic(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; - - qs = pci_test_start(); - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - - test_basic(&dev->vdev, &qs->alloc, &vqpci->vq); + QVirtioBlk *blk_if = obj; + QVirtQueue *vq; + vq = qvirtqueue_setup(blk_if->vdev, t_alloc, 0); + test_basic(blk_if->vdev, t_alloc, vq); + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); } -static void pci_indirect(void) +static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QVirtQueuePCI *vqpci; - QOSState *qs; + QVirtQueue *vq; + QVirtioBlk *blk_if = obj; + QVirtioDevice *dev = blk_if->vdev; QVirtioBlkReq req; QVRingIndirectDesc *indirect; uint64_t req_addr; @@ -430,22 +353,18 @@ static void pci_indirect(void) uint8_t status; char *data; - qs = pci_test_start(); - - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); - features = qvirtio_get_features(&dev->vdev); + features = qvirtio_get_features(dev); g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_EVENT_IDX) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtio_set_driver_ok(&dev->vdev); + vq = qvirtqueue_setup(dev, t_alloc, 0); + qvirtio_set_driver_ok(dev); /* Write request */ req.type = VIRTIO_BLK_T_OUT; @@ -454,23 +373,23 @@ static void pci_indirect(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - indirect = qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); + indirect = qvring_indirect_desc_setup(dev, t_alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); - free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head = qvirtqueue_add_indirect(vq, indirect); + qvirtqueue_kick(dev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); g_free(indirect); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -479,17 +398,17 @@ static void pci_indirect(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - indirect = qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); + indirect = qvring_indirect_desc_setup(dev, t_alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); - free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head = qvirtqueue_add_indirect(vq, indirect); + qvirtqueue_kick(dev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); @@ -500,52 +419,37 @@ static void pci_indirect(void) g_free(data); g_free(indirect); - guest_free(&qs->alloc, req_addr); - - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + guest_free(t_alloc, req_addr); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } -static void pci_config(void) +static void config(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; + QVirtioBlk *blk_if = obj; + QVirtioDevice *dev = blk_if->vdev; int n_size = TEST_IMAGE_SIZE / 2; uint64_t capacity; - qs = pci_test_start(); - - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); - qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US); - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, n_size / 512); - - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - - qtest_shutdown(qs); } -static void pci_msix(void) +static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; + QVirtQueue *vq; + QVirtioBlkPCI *blk = obj; + QVirtioPCIDevice *pdev = &blk->pci_vdev; + QVirtioDevice *dev = &pdev->vdev; QVirtioBlkReq req; int n_size = TEST_IMAGE_SIZE / 2; uint64_t req_addr; @@ -554,36 +458,38 @@ static void pci_msix(void) uint32_t free_head; uint8_t status; char *data; + QOSGraphObject *blk_object = obj; + QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device"); - qs = pci_test_start(); - - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - qpci_msix_enable(dev->pdev); + if (qpci_check_buggy_msi(pci_dev)) { + return; + } - qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); + qpci_msix_enable(pdev->pdev); + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); - features = qvirtio_get_features(&dev->vdev); + features = qvirtio_get_features(dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | (1u << VIRTIO_RING_F_EVENT_IDX) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); + vq = qvirtqueue_setup(dev, t_alloc, 0); + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); - qvirtio_wait_config_isr(&dev->vdev, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_config_isr(dev, QVIRTIO_BLK_TIMEOUT_US); - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, n_size / 512); /* Write request */ @@ -593,22 +499,22 @@ static void pci_msix(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status = readb(req_addr + 528); g_assert_cmpint(status, ==, 0); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -616,18 +522,18 @@ static void pci_msix(void) req.sector = 0; req.data = g_malloc0(512); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, true, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_kick(dev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); status = readb(req_addr + 528); @@ -638,22 +544,19 @@ static void pci_msix(void) g_assert_cmpstr(data, ==, "TEST"); g_free(data); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qpci_msix_disable(dev->pdev); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + qpci_msix_disable(pdev->pdev); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } -static void pci_idx(void) +static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *vqpci; + QVirtQueue *vq; + QVirtioBlkPCI *blk = obj; + QVirtioPCIDevice *pdev = &blk->pci_vdev; + QVirtioDevice *dev = &pdev->vdev; QVirtioBlkReq req; uint64_t req_addr; uint64_t capacity; @@ -663,28 +566,30 @@ static void pci_idx(void) uint32_t desc_idx; uint8_t status; char *data; + QOSGraphObject *blk_object = obj; + QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device"); - qs = pci_test_start(); - - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT); - qpci_msix_enable(dev->pdev); + if (qpci_check_buggy_msi(pci_dev)) { + return; + } - qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); + qpci_msix_enable(pdev->pdev); + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); - features = qvirtio_get_features(&dev->vdev); + features = qvirtio_get_features(dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) | (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | (1u << VIRTIO_BLK_F_SCSI)); - qvirtio_set_features(&dev->vdev, features); + qvirtio_set_features(dev, features); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); + vq = qvirtqueue_setup(dev, t_alloc, 0); + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); - qvirtio_set_driver_ok(&dev->vdev); + qvirtio_set_driver_ok(dev); /* Write request */ req.type = VIRTIO_BLK_T_OUT; @@ -693,16 +598,16 @@ static void pci_idx(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head, NULL, + qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US); /* Write request */ @@ -712,25 +617,25 @@ static void pci_idx(void) req.data = g_malloc0(512); strcpy(req.data, "TEST"); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); /* Notify after processing the third request */ - qvirtqueue_set_used_event(&vqpci->vq, 2); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_set_used_event(vq, 2); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, false, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); + qvirtqueue_kick(dev, vq, free_head); write_head = free_head; /* No notification expected */ - status = qvirtio_wait_status_byte_no_isr(&dev->vdev, - &vqpci->vq, req_addr + 528, + status = qvirtio_wait_status_byte_no_isr(dev, + vq, req_addr + 528, QVIRTIO_BLK_TIMEOUT_US); g_assert_cmpint(status, ==, 0); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); /* Read request */ req.type = VIRTIO_BLK_T_IN; @@ -738,20 +643,20 @@ static void pci_idx(void) req.sector = 1; req.data = g_malloc0(512); - req_addr = virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); g_free(req.data); - free_head = qvirtqueue_add(&vqpci->vq, req_addr, 16, false, true); - qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, true, true); - qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false); + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); + qvirtqueue_add(vq, req_addr + 16, 512, true, true); + qvirtqueue_add(vq, req_addr + 528, 1, true, false); - qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head); + qvirtqueue_kick(dev, vq, free_head); /* We get just one notification for both requests */ - qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, write_head, NULL, + qvirtio_wait_used_elem(dev, vq, write_head, NULL, QVIRTIO_BLK_TIMEOUT_US); - g_assert(qvirtqueue_get_buf(&vqpci->vq, &desc_idx, NULL)); + g_assert(qvirtqueue_get_buf(vq, &desc_idx, NULL)); g_assert_cmpint(desc_idx, ==, free_head); status = readb(req_addr + 528); @@ -762,125 +667,114 @@ static void pci_idx(void) g_assert_cmpstr(data, ==, "TEST"); g_free(data); - guest_free(&qs->alloc, req_addr); + guest_free(t_alloc, req_addr); /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); - qpci_msix_disable(dev->pdev); - qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); - qtest_shutdown(qs); + qpci_msix_disable(pdev->pdev); + + qvirtqueue_cleanup(dev->bus, vq, t_alloc); } -static void pci_hotplug(void) +static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) { + QVirtioPCIDevice *dev1 = obj; QVirtioPCIDevice *dev; - QOSState *qs; - const char *arch = qtest_get_arch(); - - qs = pci_test_start(); /* plug secondary disk */ qtest_qmp_device_add("virtio-blk-pci", "drv1", "{'addr': %s, 'drive': 'drive1'}", - stringify(PCI_SLOT_HP)); + stringify(PCI_SLOT_HP) ".0"); - dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP); - g_assert(dev); + dev = virtio_pci_new(dev1->pdev->bus, + &(QPCIAddress) { .devfn = QPCI_DEVFN(PCI_SLOT_HP, 0) }); + g_assert_nonnull(dev); + g_assert_cmpint(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); - g_free(dev); + qos_object_destroy((QOSGraphObject *)dev); /* unplug secondary disk */ - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); - } - qtest_shutdown(qs); + qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP); } /* * Check that setting the vring addr on a non-existent virtqueue does * not crash. */ -static void test_nonexistent_virtqueue(void) +static void test_nonexistent_virtqueue(void *obj, void *data, + QGuestAllocator *t_alloc) { + QVirtioBlkPCI *blk = obj; + QVirtioPCIDevice *pdev = &blk->pci_vdev; QPCIBar bar0; - QOSState *qs; QPCIDevice *dev; - qs = pci_test_start(); - dev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4, 0)); + dev = qpci_device_find(pdev->pdev->bus, QPCI_DEVFN(4, 0)); g_assert(dev != NULL); - qpci_device_enable(dev); + bar0 = qpci_iomap(dev, 0, NULL); qpci_io_writeb(dev, bar0, VIRTIO_PCI_QUEUE_SEL, 2); qpci_io_writel(dev, bar0, VIRTIO_PCI_QUEUE_PFN, 1); + g_free(dev); - qtest_shutdown(qs); } -static void mmio_basic(void) +static void resize(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioMMIODevice *dev; - QVirtQueue *vq; - QGuestAllocator alloc; + QVirtioBlk *blk_if = obj; + QVirtioDevice *dev = blk_if->vdev; int n_size = TEST_IMAGE_SIZE / 2; uint64_t capacity; + QVirtQueue *vq; - arm_test_start(); - - dev = g_malloc0(sizeof(QVirtioMMIODevice)); - qvirtio_mmio_init_device(dev, global_qtest, MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE); - g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); - - qvirtio_start_device(&dev->vdev); - - generic_alloc_init(&alloc, MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE); - vq = qvirtqueue_setup(&dev->vdev, &alloc, 0); + vq = qvirtqueue_setup(dev, t_alloc, 0); - test_basic(&dev->vdev, &alloc, vq); + test_basic(dev, t_alloc, vq); qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " " 'size': %d } }", n_size); - qvirtio_wait_queue_isr(&dev->vdev, vq, QVIRTIO_BLK_TIMEOUT_US); + qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US); - capacity = qvirtio_config_readq(&dev->vdev, 0); + capacity = qvirtio_config_readq(dev, 0); g_assert_cmpint(capacity, ==, n_size / 512); - /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, vq, &alloc); - g_free(dev); - alloc_destroy(&alloc); - test_end(); + qvirtqueue_cleanup(dev->bus, vq, t_alloc); + } -int main(int argc, char **argv) +static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { - const char *arch = qtest_get_arch(); - - g_test_init(&argc, &argv, NULL); - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0 || - strcmp(arch, "ppc64") == 0) { - qtest_add_func("/virtio/blk/pci/basic", pci_basic); - qtest_add_func("/virtio/blk/pci/indirect", pci_indirect); - qtest_add_func("/virtio/blk/pci/config", pci_config); - qtest_add_func("/virtio/blk/pci/nxvirtq", test_nonexistent_virtqueue); - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qtest_add_func("/virtio/blk/pci/msix", pci_msix); - qtest_add_func("/virtio/blk/pci/idx", pci_idx); - } - qtest_add_func("/virtio/blk/pci/hotplug", pci_hotplug); - } else if (strcmp(arch, "arm") == 0) { - qtest_add_func("/virtio/blk/mmio/basic", mmio_basic); - } + char *tmp_path = drive_create(); - return g_test_run(); + g_string_append_printf(cmd_line, + " -drive if=none,id=drive0,file=%s,format=raw " + "-drive if=none,id=drive1,file=null-co://,format=raw ", + tmp_path); + + return arg; } + +static void register_virtio_blk_test(void) +{ + QOSGraphTestOptions opts = { + .before = virtio_blk_test_setup, + }; + + qos_add_test("indirect", "virtio-blk", indirect, &opts); + qos_add_test("config", "virtio-blk", config, &opts); + qos_add_test("basic", "virtio-blk", basic, &opts); + qos_add_test("resize", "virtio-blk", resize, &opts); + + /* tests just for virtio-blk-pci */ + qos_add_test("msix", "virtio-blk-pci", msix, &opts); + qos_add_test("idx", "virtio-blk-pci", idx, &opts); + qos_add_test("nxvirtq", "virtio-blk-pci", + test_nonexistent_virtqueue, &opts); + qos_add_test("hotplug", "virtio-blk-pci", pci_hotplug, &opts); +} + +libqos_init(register_virtio_blk_test); From patchwork Thu Mar 7 17:29:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ordSGTqy"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff9M0SvDz9s70 for ; Fri, 8 Mar 2019 05:21:58 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xeV-0003NR-QT for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr3-0003VP-Lm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr2-0008KS-1p for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:49 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51168) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr1-0008JB-NJ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: by mail-wm1-x341.google.com with SMTP id x7so10092567wmj.0 for ; Thu, 07 Mar 2019 09:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EMKHLevsT8B5r1Tk5kCMLSWBiR0357EsQElAm0XzhQw=; b=ordSGTqyzzTKmqLBO9IA/Gu8loWp74E6xTPpkrCNUrE9NR542lqUGyO6YDVD07sF+2 em5uroVf0MmeFZwHmjpDAElXMTnH3LCGif2fg2wbRthprxIXzw5qNW1bYicDJTtvT7Yy OPHZMtgeMhTLFqvjbwBGDfd6dZFbL5kSRNbwfEuqLukjBPwF0T0Cpo3W4CCzZhcJxVV+ kcmEr79Ja5wVPhcNNIzy+Ce1XvQS0le8oaqcnszYIJ51wvTJG0oB17V+3BlI+YF4J18s eNHDxDzWCOKCBhRxGYXkkN5M5XhUNrl+tOjxI4+dnvQk8XwBl5nj5hi5Lo5XllKtvhZf IMJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EMKHLevsT8B5r1Tk5kCMLSWBiR0357EsQElAm0XzhQw=; b=NHa+PS1Fp3+TxPABSDywU1cIBBTveBui6UecZQx+ioMpYKXbcRXYN0lbsZKIz0rmiM X8EPsMXWSzNFx0z0Ssdea+81a/ejmG5BnyAL57eiSq3v6d0bB8JQ29RmbDqmfK+Jyv/e I0G7isf3ehaX2PfJsaL/PaUGR4Cwy6wpFg+L3SXW9TFiIjT1AqdXD8oeiphuUuV8VmZi 6hJLhyYgflVWfiatsvqlbxolKbHjjSsfykID4EsjPB7gIc89HRI/5nRo4H+7y7zwfO5/ AjS2GGbPdG7ieWWe1PaPXKV6gBh+qJdAQWnSvRfy2306JGcjMwPc25gDTfK1tb3heKQK Le1w== X-Gm-Message-State: APjAAAV7zeEr8HS1CfJnWfKSq8seCcYA47FLLDbN6PRHPSsTsLIbGEyH 6qMeYllxx2q7Hi4YcL4VJpp1tqyD X-Google-Smtp-Source: APXvYqziPgvK8lijXumkjEKI9wc9C/SNzWpxS80uSddh3vw1pXGO7B0jr70mT7yVqD7lKJMjkQM9YQ== X-Received: by 2002:a1c:2543:: with SMTP id l64mr6678131wml.116.1551979846344; Thu, 07 Mar 2019 09:30:46 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:43 +0100 Message-Id: <1551979804-6060-37-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 36/57] tests/libqos: virtio-net driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-net-pci and virtio-net-device. Both nodes produce virtio-net, but virtio-net-pci receives a pci-bus and overrides virtio-pci QOSGraphObject and its functions, while virtio-net-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-net.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-net.h | 41 +++++++++++ tests/libqos/virtio.c | 1 + tests/libqos/virtio.h | 1 + 5 files changed, 226 insertions(+) create mode 100644 tests/libqos/virtio-net.c create mode 100644 tests/libqos/virtio-net.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 1d3133e..ec23364 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -743,6 +743,7 @@ qos-test-obj-y += $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-balloon.o qos-test-obj-y += tests/libqos/virtio-blk.o +qos-test-obj-y += tests/libqos/virtio-net.o qos-test-obj-y += tests/libqos/virtio-rng.o qos-test-obj-y += tests/libqos/virtio-serial.o diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c new file mode 100644 index 0000000..3ddfbdc --- /dev/null +++ b/tests/libqos/virtio-net.c @@ -0,0 +1,182 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-net.h" +#include "hw/virtio/virtio-net.h" + + +static QGuestAllocator *alloc; + +static void virtio_net_cleanup(QVirtioNet *interface) +{ + qvirtqueue_cleanup(interface->vdev->bus, interface->rx, alloc); + qvirtqueue_cleanup(interface->vdev->bus, interface->tx, alloc); +} + +static void virtio_net_setup(QVirtioNet *interface) +{ + QVirtioDevice *vdev = interface->vdev; + uint64_t features; + + features = qvirtio_get_features(vdev); + features &= ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX)); + qvirtio_set_features(vdev, features); + + interface->rx = qvirtqueue_setup(vdev, alloc, 0); + interface->tx = qvirtqueue_setup(vdev, alloc, 1); + qvirtio_set_driver_ok(vdev); +} + +/* virtio-net-device */ +static void qvirtio_net_device_destructor(QOSGraphObject *obj) +{ + QVirtioNetDevice *v_net = (QVirtioNetDevice *) obj; + virtio_net_cleanup(&v_net->net); +} + +static void qvirtio_net_device_start_hw(QOSGraphObject *obj) +{ + QVirtioNetDevice *v_net = (QVirtioNetDevice *) obj; + QVirtioNet *interface = &v_net->net; + + virtio_net_setup(interface); +} + +static void *qvirtio_net_get_driver(QVirtioNet *v_net, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-net")) { + return v_net; + } + if (!g_strcmp0(interface, "virtio")) { + return v_net->vdev; + } + + fprintf(stderr, "%s not present in virtio-net-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_net_device_get_driver(void *object, + const char *interface) +{ + QVirtioNetDevice *v_net = object; + return qvirtio_net_get_driver(&v_net->net, interface); +} + +static void *virtio_net_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioNetDevice *virtio_ndevice = g_new0(QVirtioNetDevice, 1); + QVirtioNet *interface = &virtio_ndevice->net; + + interface->vdev = virtio_dev; + alloc = t_alloc; + + virtio_ndevice->obj.destructor = qvirtio_net_device_destructor; + virtio_ndevice->obj.get_driver = qvirtio_net_device_get_driver; + virtio_ndevice->obj.start_hw = qvirtio_net_device_start_hw; + + return &virtio_ndevice->obj; +} + +/* virtio-net-pci */ +static void qvirtio_net_pci_destructor(QOSGraphObject *obj) +{ + QVirtioNetPCI *v_net = (QVirtioNetPCI *) obj; + QVirtioNet *interface = &v_net->net; + QOSGraphObject *pci_vobj = &v_net->pci_vdev.obj; + + virtio_net_cleanup(interface); + qvirtio_pci_destructor(pci_vobj); +} + +static void qvirtio_net_pci_start_hw(QOSGraphObject *obj) +{ + QVirtioNetPCI *v_net = (QVirtioNetPCI *) obj; + QVirtioNet *interface = &v_net->net; + QOSGraphObject *pci_vobj = &v_net->pci_vdev.obj; + + qvirtio_pci_start_hw(pci_vobj); + virtio_net_setup(interface); +} + +static void *qvirtio_net_pci_get_driver(void *object, + const char *interface) +{ + QVirtioNetPCI *v_net = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_net->pci_vdev.pdev; + } + return qvirtio_net_get_driver(&v_net->net, interface); +} + +static void *virtio_net_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioNetPCI *virtio_bpci = g_new0(QVirtioNetPCI, 1); + QVirtioNet *interface = &virtio_bpci->net; + QOSGraphObject *obj = &virtio_bpci->pci_vdev.obj; + + virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_bpci->pci_vdev.vdev; + alloc = t_alloc; + + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_NET); + + obj->destructor = qvirtio_net_pci_destructor; + obj->start_hw = qvirtio_net_pci_start_hw; + obj->get_driver = qvirtio_net_pci_get_driver; + + return obj; +} + +static void virtio_net_register_nodes(void) +{ + /* FIXME: every test using these nodes needs to setup a + * -netdev socket,id=hs0 otherwise QEMU is not going to start. + * Therefore, we do not include "produces" edge for virtio + * and pci-device yet. + */ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts = { }; + + /* virtio-net-device */ + opts.extra_device_opts = "netdev=hs0"; + qos_node_create_driver("virtio-net-device", + virtio_net_device_create); + qos_node_consumes("virtio-net-device", "virtio-bus", &opts); + qos_node_produces("virtio-net-device", "virtio-net"); + + /* virtio-net-pci */ + opts.extra_device_opts = "netdev=hs0,addr=04.0"; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-net-pci", virtio_net_pci_create); + qos_node_consumes("virtio-net-pci", "pci-bus", &opts); + qos_node_produces("virtio-net-pci", "virtio-net"); +} + +libqos_init(virtio_net_register_nodes); diff --git a/tests/libqos/virtio-net.h b/tests/libqos/virtio-net.h new file mode 100644 index 0000000..e6905cd --- /dev/null +++ b/tests/libqos/virtio-net.h @@ -0,0 +1,41 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioNet QVirtioNet; +typedef struct QVirtioNetPCI QVirtioNetPCI; +typedef struct QVirtioNetDevice QVirtioNetDevice; + +struct QVirtioNet { + QVirtioDevice *vdev; + QVirtQueue *rx; + QVirtQueue *tx; +}; + +struct QVirtioNetPCI { + QVirtioPCIDevice pci_vdev; + QVirtioNet net; +}; + +struct QVirtioNetDevice { + QOSGraphObject obj; + QVirtioNet net; +}; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 9fc8c7e..e4925d1 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -40,6 +40,7 @@ uint32_t qvirtio_get_features(QVirtioDevice *d) void qvirtio_set_features(QVirtioDevice *d, uint32_t features) { + d->features = features; d->bus->set_features(d, features); } diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 7f0f9dd..3f97d79 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -21,6 +21,7 @@ typedef struct QVirtioDevice { const QVirtioBus *bus; /* Device type */ uint16_t device_type; + uint64_t features; bool big_endian; } QVirtioDevice; From patchwork Thu Mar 7 17:29:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oQI48oAX"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfCj0VgVz9s70 for ; Fri, 8 Mar 2019 05:24:01 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xgU-000580-VF for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:23:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr4-0003WV-Fh for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr2-0008LB-Vg for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:50 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:52928) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr2-0008KN-J7 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:48 -0500 Received: by mail-wm1-x343.google.com with SMTP id f65so10068740wma.2 for ; Thu, 07 Mar 2019 09:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=bd4rlS5il2ZmWiFTOohYxq9m4sCk4jxjMwaQAk41v/0=; b=oQI48oAXm5dbCWpmuxtgNvdIVsfzbKebpGlktc6fNqwNaV42oNXdwPgw8FVnyme/jP 2o2gTvanH0xNPbt/rdEKhrRqtun5/jVB2hnMRXR9eAmu/+g5/fcWdalS4UmVmuHmx2p5 +bWh5wvtD0p11YwcZacO/vpwpwr2qvzPgrZg/qaNjOesexn3fAZLtoZKyGkpznVlNCTH CxdnXdoUodD4WOJaFCbQecKc+Bg0CAxp//nlOwwNw+DN6bS90cj2eXcRf9sOFADUOGtX aGn2jrX2EqPhZx5Bh/PL6gWoOnlLFyDIAGR1EMCJ05bEubi56nqp60RHNb7YuXD9ULfH ZbxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=bd4rlS5il2ZmWiFTOohYxq9m4sCk4jxjMwaQAk41v/0=; b=USlAgpCzQn0i6IupIZtke1/dY+nH88GGX+Q2zAqJQpm2LN/0E3rV4qI8pAQRn6WxfL VpXha+twFAKu/0vdq38X3e9z+zPaPX0oX5ThR1UAbnlU0ZcKgcOdMiuOsGKwKInppDvh VX4fWH+v6Jpv+ymtb0KM5zPFAnsGrVz9WDwdIde2x6RAjVc5ti2Atgt9wv+sd0BKrXk4 XHKocFy1ZxX0xoh2rrubc3VSF3EUkfZYspA3U8zQ/3rsmWN62oW0BnAN1qj/XQziZcDj GIM0usqKMjgHljdhRJEZGn3TS+GTwmZpxTsArimuLpJFayvZM28f6z69bnEjvFvKDiQg 9AEQ== X-Gm-Message-State: APjAAAXBcrpb1x8MWfIyXvmdh1gtu5m4t9rm2gpEun2adcwAssQCoOAA Rvks6xFGc9DRZQ2b9eDTSHA6UK1h X-Google-Smtp-Source: APXvYqy2BIpU/G7SfRGjT1EWrXxTHCgKnUBXffb5o4Ct1sywvXLW2qzbbkcin71/2dVlMUL+Ex/LJQ== X-Received: by 2002:a1c:b709:: with SMTP id h9mr6818062wmf.114.1551979847233; Thu, 07 Mar 2019 09:30:47 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:44 +0100 Message-Id: <1551979804-6060-38-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 37/57] qos-test: virtio-net test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/virtio-net-test in qgraph test node, virtio-net-test. This test consumes a virtio-net interface and checks that its function return the expected values. Some functions are implemented only for virtio-net-pci, so they don't consume virtio-net, but virtio-net-pci Note that this test does not allocate any virtio-net structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/virtio-net-test.c | 224 ++++++++++++++++-------------------------------- 2 files changed, 75 insertions(+), 152 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index ec23364..f45d115 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -153,7 +153,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) -check-qtest-virtio-y += tests/virtio-net-test$(EXESUF) check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) @@ -764,6 +763,7 @@ qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o qos-test-obj-y += tests/virtio-blk-test.o +qos-test-obj-y += tests/virtio-net-test.o qos-test-obj-y += tests/virtio-rng-test.o qos-test-obj-y += tests/virtio-serial-test.o @@ -812,7 +812,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o -tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) $(libqos-virtio-obj-y) tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index 653148e..2d3630c 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -9,18 +9,11 @@ #include "qemu/osdep.h" #include "libqtest.h" -#include "qemu-common.h" -#include "qemu/sockets.h" #include "qemu/iov.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" -#include "libqos/virtio.h" -#include "libqos/virtio-pci.h" #include "qapi/qmp/qdict.h" -#include "qemu/bswap.h" #include "hw/virtio/virtio-net.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_ring.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-net.h" #define PCI_SLOT_HP 0x06 #define PCI_SLOT 0x04 @@ -28,63 +21,8 @@ #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000) #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf) -static void test_end(void) -{ - qtest_end(); -} - #ifndef _WIN32 -static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) -{ - QVirtioPCIDevice *dev; - - dev = qvirtio_pci_device_find(bus, VIRTIO_ID_NET); - g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET); - - qvirtio_pci_device_enable(dev); - qvirtio_start_device(&dev->vdev); - - return dev; -} - -GCC_FMT_ATTR(1, 2) -static QOSState *pci_test_start(const char *cmd, ...) -{ - QOSState *qs; - va_list ap; - const char *arch = qtest_get_arch(); - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - va_start(ap, cmd); - qs = qtest_pc_vboot(cmd, ap); - va_end(ap); - } else if (strcmp(arch, "ppc64") == 0) { - va_start(ap, cmd); - qs = qtest_spapr_vboot(cmd, ap); - va_end(ap); - } else { - g_printerr("virtio-net tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); - } - global_qtest = qs->qts; - return qs; -} - -static void driver_init(QVirtioDevice *dev) -{ - uint32_t features; - - features = qvirtio_get_features(dev); - features = features & ~(QVIRTIO_F_BAD_FEATURE | - (1u << VIRTIO_RING_F_INDIRECT_DESC) | - (1u << VIRTIO_RING_F_EVENT_IDX)); - qvirtio_set_features(dev, features); - - qvirtio_set_driver_ok(dev); -} - static void rx_test(QVirtioDevice *dev, QGuestAllocator *alloc, QVirtQueue *vq, int socket) @@ -194,128 +132,114 @@ static void rx_stop_cont_test(QVirtioDevice *dev, guest_free(alloc, req_addr); } -static void send_recv_test(QVirtioDevice *dev, - QGuestAllocator *alloc, QVirtQueue *rvq, - QVirtQueue *tvq, int socket) +static void send_recv_test(void *obj, void *data, QGuestAllocator *t_alloc) { - rx_test(dev, alloc, rvq, socket); - tx_test(dev, alloc, tvq, socket); + QVirtioNet *net_if = obj; + QVirtioDevice *dev = net_if->vdev; + QVirtQueue *rx = net_if->rx; + QVirtQueue *tx = net_if->tx; + int *sv = data; + + rx_test(dev, t_alloc, rx, sv[0]); + tx_test(dev, t_alloc, tx, sv[0]); } -static void stop_cont_test(QVirtioDevice *dev, - QGuestAllocator *alloc, QVirtQueue *rvq, - QVirtQueue *tvq, int socket) +static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc) { - rx_stop_cont_test(dev, alloc, rvq, socket); + QVirtioNet *net_if = obj; + QVirtioDevice *dev = net_if->vdev; + QVirtQueue *rx = net_if->rx; + int *sv = data; + + rx_stop_cont_test(dev, t_alloc, rx, sv[0]); } -static void pci_basic(gconstpointer data) -{ - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *tx, *rx; - void (*func) (QVirtioDevice *dev, - QGuestAllocator *alloc, - QVirtQueue *rvq, - QVirtQueue *tvq, - int socket) = data; - int sv[2], ret; +#endif - ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv); - g_assert_cmpint(ret, !=, -1); +static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc) +{ + const char *arch = qtest_get_arch(); - qs = pci_test_start("-netdev socket,fd=%d,id=hs0 -device " - "virtio-net-pci,netdev=hs0", sv[1]); - dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT); + qtest_qmp_device_add("virtio-net-pci", "net1", + "{'addr': %s}", stringify(PCI_SLOT_HP)); - rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); - tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 1); + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP); + } +} - driver_init(&dev->vdev); - func(&dev->vdev, &qs->alloc, &rx->vq, &tx->vq, sv[0]); +static void virtio_net_test_cleanup(void *sockets) +{ + int *sv = sockets; - /* End test */ close(sv[0]); - qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, &qs->alloc); - qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, &qs->alloc); - qvirtio_pci_device_disable(dev); - g_free(dev->pdev); - g_free(dev); - qtest_shutdown(qs); + qos_invalidate_command_line(); + close(sv[1]); + g_free(sv); +} + +static void *virtio_net_test_setup(GString *cmd_line, void *arg) +{ + int ret; + int *sv = g_new(int, 2); + + ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv); + g_assert_cmpint(ret, !=, -1); + + g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ", sv[1]); + + g_test_queue_destroy(virtio_net_test_cleanup, sv); + return sv; } -static void large_tx(gconstpointer data) +static void large_tx(void *obj, void *data, QGuestAllocator *t_alloc) { - QVirtioPCIDevice *dev; - QOSState *qs; - QVirtQueuePCI *tx, *rx; - QVirtQueue *vq; + QVirtioNet *dev = obj; + QVirtQueue *vq = dev->queues[1]; uint64_t req_addr; uint32_t free_head; size_t alloc_size = (size_t)data / 64; int i; - qs = pci_test_start("-netdev hubport,id=hp0,hubid=0 " - "-device virtio-net-pci,netdev=hp0"); - dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT); - - rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1); - - driver_init(&dev->vdev); - vq = &tx->vq; - /* Bypass the limitation by pointing several descriptors to a single * smaller area */ - req_addr = guest_alloc(qs->alloc, alloc_size); + req_addr = guest_alloc(t_alloc, alloc_size); free_head = qvirtqueue_add(vq, req_addr, alloc_size, false, true); for (i = 0; i < 64; i++) { qvirtqueue_add(vq, req_addr, alloc_size, false, i != 63); } - qvirtqueue_kick(&dev->vdev, vq, free_head); + qvirtqueue_kick(dev->vdev, vq, free_head); - qvirtio_wait_used_elem(&dev->vdev, vq, free_head, NULL, + qvirtio_wait_used_elem(dev->vdev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US); - - qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc); - qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc); - qvirtio_pci_device_disable(dev); - g_free(dev->pdev); - g_free(dev); - qtest_shutdown(qs); + guest_free(t_alloc, req_addr); } -#endif -static void hotplug(void) +static void *virtio_net_test_setup_nosocket(GString *cmd_line, void *arg) { - const char *arch = qtest_get_arch(); - - qtest_start("-device virtio-net-pci"); - - qtest_qmp_device_add("virtio-net-pci", "net1", - "{'addr': %s}", stringify(PCI_SLOT_HP)); - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP); - } - - test_end(); + g_string_append(cmd_line, " -netdev hubport,hubid=0,id=hs0 "); + return arg; } -int main(int argc, char **argv) +static void register_virtio_net_test(void) { - g_test_init(&argc, &argv, NULL); + QOSGraphTestOptions opts = { + .before = virtio_net_test_setup, + }; + + qos_add_test("hotplug", "virtio-pci", hotplug, &opts); #ifndef _WIN32 - qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic); - qtest_add_data_func("/virtio/net/pci/rx_stop_cont", - stop_cont_test, pci_basic); - qtest_add_data_func("/virtio/net/pci/large_tx_uint_max", - (gconstpointer)UINT_MAX, large_tx); - qtest_add_data_func("/virtio/net/pci/large_tx_net_bufsize", - (gconstpointer)NET_BUFSIZE, large_tx); + qos_add_test("basic", "virtio-net", send_recv_test, &opts); + qos_add_test("rx_stop_cont", "virtio-net", stop_cont_test, &opts); #endif - qtest_add_func("/virtio/net/pci/hotplug", hotplug); - return g_test_run(); + /* These tests do not need a loopback backend. */ + opts.before = virtio_net_test_setup_nosocket; + opts.arg = (gpointer)UINT_MAX; + qos_add_test("large_tx/uint_max", "virtio-net", large_tx, &opts); + opts.arg = (gpointer)NET_BUFSIZE; + qos_add_test("large_tx/net_bufsize", "virtio-net", large_tx, &opts); } + +libqos_init(register_virtio_net_test); From patchwork Thu Mar 7 17:29:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ushVm55n"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdrl0glqz9s70 for ; Fri, 8 Mar 2019 05:07:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xQa-00086V-Vf for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:07:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr9-0003cz-KE for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr4-0008ND-PZ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:55 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:36302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr4-0008MD-Gr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:50 -0500 Received: by mail-wm1-x331.google.com with SMTP id j125so10119108wmj.1 for ; Thu, 07 Mar 2019 09:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=23R2ZOIWRhFaRuPewX+YO6zA6oQ9cyGwQdrmIwSfmo4=; b=ushVm55nBtEZ4IWTGfFHZRt2wcATx/DBpdFuAsKQultG2f0ySxYfoUhhwtgWqLeulT VU/a3GbZwiyuLUHoaqBY+atmsKRIuaR7OlSeAvKFOJ1P82wppTa64lfSdqt2cD3KwHsy OTA+Q9ORODiwsQ+7NafXJIKe5c3JWxuRAR5/fwJj8wzvLfTUcg4JRUi4CoD2G1wiJ9ZO u1Itf88Snn8UqB/aykyKxVdBbG8pnKvScrfBJV7nMaetLamMqnlp1o//TGeOp2wHrwzr bj9xlv+vgJm5qXyoSLS1oVo7tAYP3Zy+iOZ+XbQhGD6K2SMR9Cxryla8a0V1ZF7Y9Vtr ubGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=23R2ZOIWRhFaRuPewX+YO6zA6oQ9cyGwQdrmIwSfmo4=; b=MFY+KPy5fEqTacnDDOAki7cacHwRrn8m9KkmdepJksjDBxFH0WeIcVnt542Gmt5oJB /N4w0BNca2lLgViao1cd9M7c3vW9fXtCIOqpNK4XMEvTzbfKjk99uE2mPmoMhvg5MFp2 1RgCUBLp5Z7/5Qzg/tpxJpcD2eadxt8xgYVnBijCnl0W4J8ADK6FPzBgapV1cyArEeTI 5aWWI4n4IVh82JYer8mL5lXbKoGRDvjaqWhoOB/I6VjZLRk/SznKdcsv3CRqmAgKXf1X KPSxEDb8v/3L2HKL97FlR7Sq6KFWmnldT7J+9liph5pqP62+CrlNQSsIfvlkQYrrVi6/ oW0Q== X-Gm-Message-State: APjAAAV93+vaZlCYx2AayT/YHcGJficzgAtCQsgvzJWBMLPF12zGnAz+ 4i8+ibM7ZymxkuRMHe0eXpKFXmmu X-Google-Smtp-Source: APXvYqw5goHX9FDgbg6XxQLyNEHHhnHOIQU0wFlg/3fxstmvHrBKQSiHNZR/WT7cNyNEWI5s0dZZ/Q== X-Received: by 2002:a1c:2947:: with SMTP id p68mr6474560wmp.104.1551979849094; Thu, 07 Mar 2019 09:30:49 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:45 +0100 Message-Id: <1551979804-6060-39-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::331 Subject: [Qemu-devel] [PULL 38/57] tests/libqos: support multiqueue for virtio-net 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Initialize the additional virtqueues if they are supported. This is needed to switch vhost-user-test's multiqueue test to the virtio-net qgraph. Signed-off-by: Paolo Bonzini --- tests/libqos/virtio-net.c | 21 +++++++++++++++++---- tests/libqos/virtio-net.h | 4 ++-- tests/virtio-net-test.c | 6 +++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c index 3ddfbdc..61c5617 100644 --- a/tests/libqos/virtio-net.c +++ b/tests/libqos/virtio-net.c @@ -27,14 +27,19 @@ static QGuestAllocator *alloc; static void virtio_net_cleanup(QVirtioNet *interface) { - qvirtqueue_cleanup(interface->vdev->bus, interface->rx, alloc); - qvirtqueue_cleanup(interface->vdev->bus, interface->tx, alloc); + int i; + + for (i = 0; i < interface->n_queues; i++) { + qvirtqueue_cleanup(interface->vdev->bus, interface->queues[i], alloc); + } + g_free(interface->queues); } static void virtio_net_setup(QVirtioNet *interface) { QVirtioDevice *vdev = interface->vdev; uint64_t features; + int i; features = qvirtio_get_features(vdev); features &= ~(QVIRTIO_F_BAD_FEATURE | @@ -42,8 +47,16 @@ static void virtio_net_setup(QVirtioNet *interface) (1u << VIRTIO_RING_F_EVENT_IDX)); qvirtio_set_features(vdev, features); - interface->rx = qvirtqueue_setup(vdev, alloc, 0); - interface->tx = qvirtqueue_setup(vdev, alloc, 1); + if (features & (1u << VIRTIO_NET_F_MQ)) { + interface->n_queues = qvirtio_config_readw(vdev, 8) * 2; + } else { + interface->n_queues = 2; + } + + interface->queues = g_new(QVirtQueue *, interface->n_queues); + for (i = 0; i < interface->n_queues; i++) { + interface->queues[i] = qvirtqueue_setup(vdev, alloc, i); + } qvirtio_set_driver_ok(vdev); } diff --git a/tests/libqos/virtio-net.h b/tests/libqos/virtio-net.h index e6905cd..28238a1 100644 --- a/tests/libqos/virtio-net.h +++ b/tests/libqos/virtio-net.h @@ -26,8 +26,8 @@ typedef struct QVirtioNetDevice QVirtioNetDevice; struct QVirtioNet { QVirtioDevice *vdev; - QVirtQueue *rx; - QVirtQueue *tx; + int n_queues; + QVirtQueue **queues; }; struct QVirtioNetPCI { diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index 2d3630c..c58e670 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -136,8 +136,8 @@ static void send_recv_test(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtioNet *net_if = obj; QVirtioDevice *dev = net_if->vdev; - QVirtQueue *rx = net_if->rx; - QVirtQueue *tx = net_if->tx; + QVirtQueue *rx = net_if->queues[0]; + QVirtQueue *tx = net_if->queues[1]; int *sv = data; rx_test(dev, t_alloc, rx, sv[0]); @@ -148,7 +148,7 @@ static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtioNet *net_if = obj; QVirtioDevice *dev = net_if->vdev; - QVirtQueue *rx = net_if->rx; + QVirtQueue *rx = net_if->queues[0]; int *sv = data; rx_stop_cont_test(dev, t_alloc, rx, sv[0]); From patchwork Thu Mar 7 17:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MlYokvKP"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdd06Qdvz9sB3 for ; Fri, 8 Mar 2019 04:57:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xGi-0007xs-Nj for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 12:57:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr6-0003Yt-F7 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr5-0008Np-Gk for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:52 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:45220) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr5-0008Mx-8O for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: by mail-wr1-x436.google.com with SMTP id w17so18399344wrn.12 for ; Thu, 07 Mar 2019 09:30:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=u8iIezkWn7T/enQENb6Ms0kkFpoH/Vshk52lH6nhSt4=; b=MlYokvKPq2roH4b7NAbBW6nzjNxKL3AItK9/YwWxj+NQwu9ZMueAk7zntSA5PUtmr6 8M2Ad1Dn2OWR2eHj4/VCihy5jTiMe6ZrQp0dcGqhGuhHAtnVuG/2eVBmlh17ExFDcwkB WPMiP4KFgyyh+LD9dlEs1R2J3bKGsuL3SYiiGg+B/F2BvdbFK1YDdQTIv6iWdyFJ/M6l eQfgiGAM1a2rjTmEdl9iQn6pc+SG5e38V0CcPcHbl6dHZSPIE6xsyjNKYK6yp39bEUEa cKeyT5Uqqb8reCN2KtOCy5cnT/TCkWOeapSM/tjyt0l2PcOwG5+VrZrUgVxCU39xAgYU NmKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=u8iIezkWn7T/enQENb6Ms0kkFpoH/Vshk52lH6nhSt4=; b=ZhydrojLol8lFrcDURSRCpS0BEj/ohrxK05JTlDcz3mBjggPKevSCoNWUfnTs+/Ri2 QqHTWzOfJmoz8WRQEGqwi/2ejHjl3ey3/sUGcjuNGoZVBwnf2WKTYvR4wIDq8rxOQ16L 4DzvJZ4RX1S2+tcOE+NnHk2rVsRxRjvs3oZDc2SPSZ+jEKc/XYBGLkfRK5HmFlHnqkH6 ujKjotwf3MCofL0v65bUASqyHhX5f4HgYeMvMruQb1yDN1e0B4hAU1B7q70Y0LRLFgEu aJU/KzbaMX07oBANswWwLdLANNXPfcGInmtKhdvIJdWh3Y1MZOly0/KFPTIkqya8vaNd v+cw== X-Gm-Message-State: APjAAAWVjiNF+KyypjZQbfEyIWr1guYot97ltGWRrxB36eOkvGQpsjCs 1jXbHlJUIBHVFu60x3ojEgJbnANj X-Google-Smtp-Source: APXvYqytTMAAf0ZAkNJCOUCWKXUFA2YWTXNmQ73NUp+pBQokw02qI9pB0HxZeieL62590BHr1HwgHg== X-Received: by 2002:adf:ce91:: with SMTP id r17mr7366633wrn.80.1551979849919; Thu, 07 Mar 2019 09:30:49 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:46 +0100 Message-Id: <1551979804-6060-40-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PULL 39/57] vhost-user-test: always use 256 MiB of guest memory 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some tests are using a small amount of RAM for the guest (2 MiB) in order to save host memory, others are using 512 MiB. However, pSeries machines only support multiples of 256 MiB. Using 256 MiB of memory does not use more host memory than now, even for the migration test that starts two guests, and it allows running the test on pSeries too. This of course is not optimal, it would be nice to let the qgraph machine object judge how much memory to provide. This is left for future work, together with a more generic framework that wraps the QEMU command line. Signed-off-by: Paolo Bonzini --- tests/vhost-user-test.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index b1414e2..2a67a99 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -704,7 +704,7 @@ static void test_read_guest_mem(const void *arg) "read-guest-memfd" : "read-guest-mem"); test_server_listen(server); - qemu_cmd = get_qemu_cmd(server, 512, memfd, "", ""); + qemu_cmd = get_qemu_cmd(server, 256, memfd, "", ""); s = qtest_start(qemu_cmd); g_free(qemu_cmd); @@ -739,7 +739,7 @@ static void test_migrate(void) test_server_listen(s); test_server_listen(dest); - cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, "", ""); + cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, "", ""); from = qtest_start(cmd); g_free(cmd); @@ -749,10 +749,10 @@ static void test_migrate(void) } size = get_log_size(s); - g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); + g_assert_cmpint(size, ==, (256 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); tmp = g_strdup_printf(" -incoming %s", uri); - cmd = get_qemu_cmd(dest, 2, TEST_MEMFD_AUTO, "", tmp); + cmd = get_qemu_cmd(dest, 256, TEST_MEMFD_AUTO, "", tmp); g_free(tmp); to = qtest_init(cmd); g_free(cmd); @@ -863,7 +863,7 @@ static void test_reconnect_subprocess(void) char *cmd; g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", ""); + cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); qtest_start(cmd); g_free(cmd); @@ -908,7 +908,7 @@ static void test_connect_fail_subprocess(void) s->test_fail = true; g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", ""); + cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); qtest_start(cmd); g_free(cmd); @@ -941,7 +941,7 @@ static void test_flags_mismatch_subprocess(void) s->test_flags = TEST_FLAGS_DISCONNECT; g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", ""); + cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); qtest_start(cmd); g_free(cmd); @@ -982,14 +982,14 @@ static void test_multiqueue(void) cmd = g_strdup_printf( QEMU_CMD_MEMFD QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", - 512, 512, s->chr_name, + 256, 256, s->chr_name, s->socket_path, "", s->chr_name, s->queues, s->queues * 2 + 2); } else { cmd = g_strdup_printf( QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", - 512, 512, s->mem_path, s->chr_name, + 256, 256, s->mem_path, s->chr_name, s->socket_path, "", s->chr_name, s->queues, s->queues * 2 + 2); } From patchwork Thu Mar 7 17:29:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qUcXNMgd"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdw517S0z9s70 for ; Fri, 8 Mar 2019 05:10:29 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xTO-00025w-Q8 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:10:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr9-0003cj-AZ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr7-0008P8-5N for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:55 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:43673) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr6-0008OL-Q5 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:53 -0500 Received: by mail-wr1-x42d.google.com with SMTP id d17so18395600wre.10 for ; Thu, 07 Mar 2019 09:30:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=MfFNZP6uPLkgEwl3XOuqPRBEvqyyufFyb9vWcSRq8bg=; b=qUcXNMgdaSx/PHQCzKY6nITaZK4sX2pYKNMpQdgZ6HYuiobgkFnMgGE2SgOFxh+9cE oeIhiJiTQB8E7ocgVepthLCccNx99TMHtXPeI2GKheBt1XJDJFsc3+c3Xp3NyuzrfBwS 5TKbfXjnkpXb2Cpys5UlqwIoZsFCGFPutaFQDgguqYvtL2Kw5ApCURgg2fglaGo49kSN yYtKe3mYMj5Cd8jEmDsfHDfLgq2D0muMhLrmdCrlhP1izdLEyZWJtjUnzHwVqAnFEzEN mC+4L8Sn9FcPWe3Iztkzit4SmjMX+bCqh41yP3b5jgg498sdcHFTABxBelVScyzQztKp /Q1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=MfFNZP6uPLkgEwl3XOuqPRBEvqyyufFyb9vWcSRq8bg=; b=ThZHhsAmnO1GPwb6ssNuUl8UXHijhU9ixcPuNymQkxUqeXNQrmCZmQ8I/RIA8fxPuG RPjxEGgs3SopJ+gqnzdMF/LpImD3tmosVzt9CUA3ip3TXIicgDGM9/pF7Tvl9yWYgGse ge92H5BaMZi6oSPxr6ptRn242pYBh0rzQGS/zfpF8msQl20LQRf1zPZmRO1qBiUE4cYv w58S5Eyo4amKwDqpPO7uLZW2QXqt2rCwYKcPRaYv6MM44/5YrLXMqjOTOWgIJ19R7eX1 lxk8cqyQNjoWWmBDS/L5aGEt8ikp4Ut72RQs3DrCAqLDxz1wPUK1T5v/7c7tE6fJlOVJ 0I8Q== X-Gm-Message-State: APjAAAUOBY4KdmMiWniwbX7uXP283NHMXgtIDCsOKcrUDCaPD2spMDx3 ykUxn85wZ9MNBI3zk4bUYKBEQnxn X-Google-Smtp-Source: APXvYqwIZl14N67RIoCkj/1F17P9mEcydA51Koe5Pcry/kqLmLPrB13cX0g7L409LAbu937uwMGyRA== X-Received: by 2002:a5d:4145:: with SMTP id c5mr7588746wrq.256.1551979851101; Thu, 07 Mar 2019 09:30:51 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:47 +0100 Message-Id: <1551979804-6060-41-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42d Subject: [Qemu-devel] [PULL 40/57] qos-test: vhost-user test node 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Convert tests/virtio-net-test in qgraph test node, virtio-net-test. This test consumes a virtio-net interface and checks that its function return the expected values. Note that this test does not allocate any virtio-net structure, it's all done by the qtest walking graph mechanism. Nevertheless, vhost-user-test is a bit more complex than the other tests, because it requires more complicated setup of back-ends and thus almost each test has a slightly different opts.before function. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 5 +- tests/vhost-user-test.c | 381 +++++++++++++++++++----------------------------- 2 files changed, 152 insertions(+), 234 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index f45d115..a0b42c9 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -204,7 +204,6 @@ check-qtest-i386-$(CONFIG_USB_XHCI_NEC) += tests/usb-hcd-xhci-test$(EXESUF) check-qtest-i386-y += tests/cpu-plug-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) check-qtest-i386-y += tests/vmgenid-test$(EXESUF) -check-qtest-i386-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test$(EXESUF) check-qtest-i386-$(CONFIG_TPM_CRB) += tests/tpm-crb-swtpm-test$(EXESUF) check-qtest-i386-$(CONFIG_TPM_CRB) += tests/tpm-crb-test$(EXESUF) check-qtest-i386-$(CONFIG_TPM_TIS) += tests/tpm-tis-swtpm-test$(EXESUF) @@ -760,6 +759,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o +qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o qos-test-obj-y += tests/virtio-blk-test.o @@ -835,9 +835,6 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o tests/migration-test$(EXESUF): tests/migration-test.o tests/test-announce-self$(EXESUF): tests/test-announce-self.o -tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \ - $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \ - $(chardev-obj-y) 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-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-qapi-obj-y) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 2a67a99..92dfeed 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -41,8 +41,7 @@ #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem" #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" -#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce" -#define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0" +#define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce" #define HUGETLBFS_MAGIC 0x958458f6 @@ -136,13 +135,9 @@ enum { }; typedef struct TestServer { - QPCIBus *bus; - QVirtioPCIDevice *dev; - QVirtQueue *vq[VHOST_MAX_VIRTQUEUES]; gchar *socket_path; gchar *mig_path; gchar *chr_name; - const gchar *mem_path; gchar *tmpfs; CharBackend chr; int fds_num; @@ -158,9 +153,9 @@ typedef struct TestServer { bool test_fail; int test_flags; int queues; - QGuestAllocator alloc; } TestServer; +static const char *init_hugepagefs(void); static TestServer *test_server_new(const gchar *name); static void test_server_free(TestServer *server); static void test_server_listen(TestServer *server); @@ -171,64 +166,28 @@ enum test_memfd { TEST_MEMFD_NO, }; -static char *get_qemu_cmd(TestServer *s, - int mem, enum test_memfd memfd, - const char *chr_opts, const char *extra) +static void append_vhost_opts(TestServer *s, GString *cmd_line, + const char *chr_opts) { - if (memfd == TEST_MEMFD_AUTO && qemu_memfd_check(0)) { - memfd = TEST_MEMFD_YES; - } - - if (memfd == TEST_MEMFD_YES) { - return g_strdup_printf(QEMU_CMD_MEMFD QEMU_CMD_CHR - QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, - s->chr_name, s->socket_path, - chr_opts, s->chr_name, extra); - } else { - return g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR - QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem, - s->mem_path, s->chr_name, s->socket_path, - chr_opts, s->chr_name, extra); - } + g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_NETDEV, + s->chr_name, s->socket_path, + chr_opts, s->chr_name); } -static void init_virtio_dev(QTestState *qts, TestServer *s, uint32_t features_mask) +static void append_mem_opts(TestServer *server, GString *cmd_line, + int size, enum test_memfd memfd) { - uint32_t features; - int i; - - s->bus = qpci_new_pc(qts, NULL); - g_assert_nonnull(s->bus); - - s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET); - g_assert_nonnull(s->dev); - - qvirtio_pci_device_enable(s->dev); - qvirtio_start_device(&s->dev->vdev); - - pc_alloc_init(&s->alloc, qts, 0); - - for (i = 0; i < s->queues * 2; i++) { - s->vq[i] = qvirtqueue_setup(&s->dev->vdev, &s->alloc, i); + if (memfd == TEST_MEMFD_AUTO) { + memfd = qemu_memfd_check(0) ? TEST_MEMFD_YES : TEST_MEMFD_NO; } - features = qvirtio_get_features(&s->dev->vdev); - features = features & features_mask; - qvirtio_set_features(&s->dev->vdev, features); - - qvirtio_set_driver_ok(&s->dev->vdev); -} - -static void uninit_virtio_dev(TestServer *s) -{ - int i; + if (memfd == TEST_MEMFD_YES) { + g_string_append_printf(cmd_line, QEMU_CMD_MEMFD, size, size); + } else { + const char *root = init_hugepagefs() ? : server->tmpfs; - for (i = 0; i < s->queues * 2; i++) { - qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], &s->alloc); + g_string_append_printf(cmd_line, QEMU_CMD_MEM, size, size, root); } - alloc_destroy(&s->alloc); - - qvirtio_pci_device_free(s->dev); } static bool wait_for_fds(TestServer *s) @@ -465,17 +424,21 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) static const char *init_hugepagefs(void) { #ifdef CONFIG_LINUX + static const char *hugepagefs; const char *path = getenv("QTEST_HUGETLBFS_PATH"); struct statfs fs; int ret; + if (hugepagefs) { + return hugepagefs; + } if (!path) { return NULL; } if (access(path, R_OK | W_OK | X_OK)) { g_test_message("access on path (%s): %s\n", path, strerror(errno)); - abort(); + g_test_fail(); return NULL; } @@ -485,17 +448,18 @@ static const char *init_hugepagefs(void) if (ret != 0) { g_test_message("statfs on path (%s): %s\n", path, strerror(errno)); - abort(); + g_test_fail(); return NULL; } if (fs.f_type != HUGETLBFS_MAGIC) { g_test_message("Warning: path not on HugeTLBFS: %s\n", path); - abort(); + g_test_fail(); return NULL; } - return path; + hugepagefs = path; + return hugepagefs; #else return NULL; #endif @@ -520,7 +484,6 @@ static TestServer *test_server_new(const gchar *name) g_assert(tmpfs); server->tmpfs = g_strdup(tmpfs); - server->mem_path = init_hugepagefs() ? : server->tmpfs; server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name); server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name); server->chr_name = g_strdup_printf("chr-%s", name); @@ -598,8 +561,6 @@ static void test_server_free(TestServer *server) } g_free(server->chr_name); - g_assert(server->bus); - qpci_free_pc(server->bus); g_main_loop_unref(server->loop); g_main_context_unref(server->context); @@ -693,70 +654,79 @@ GSourceFuncs test_migrate_source_funcs = { .check = test_migrate_source_check, }; -static void test_read_guest_mem(const void *arg) +static void vhost_user_test_cleanup(void *s) +{ + TestServer *server = s; + + qos_invalidate_command_line(); + test_server_free(server); +} + +static void *vhost_user_test_setup(GString *cmd_line, void *arg) { - enum test_memfd memfd = GPOINTER_TO_INT(arg); - TestServer *server = NULL; - char *qemu_cmd = NULL; - QTestState *s = NULL; + TestServer *server = test_server_new("vhost-user-test"); + test_server_listen(server); + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_AUTO); + append_vhost_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} - server = test_server_new(memfd == TEST_MEMFD_YES ? - "read-guest-memfd" : "read-guest-mem"); +static void *vhost_user_test_setup_memfd(GString *cmd_line, void *arg) +{ + TestServer *server = test_server_new("vhost-user-test"); test_server_listen(server); - qemu_cmd = get_qemu_cmd(server, 256, memfd, "", ""); + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_YES); + append_vhost_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); - s = qtest_start(qemu_cmd); - g_free(qemu_cmd); + return server; +} - init_virtio_dev(global_qtest, server, 1u << VIRTIO_NET_F_MAC); +static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *alloc) +{ + TestServer *server = arg; if (!wait_for_fds(server)) { - goto exit; + return; } read_guest_mem_server(global_qtest, server); - -exit: - uninit_virtio_dev(server); - - qtest_quit(s); - test_server_free(server); } -static void test_migrate(void) +static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc) { - TestServer *s = test_server_new("src"); + TestServer *s = arg; TestServer *dest = test_server_new("dest"); + GString *dest_cmdline = g_string_new(qos_get_current_command_line()); char *uri = g_strdup_printf("%s%s", "unix:", dest->mig_path); - QTestState *from, *to; + QTestState *to; GSource *source; - gchar *cmd, *tmp; QDict *rsp; guint8 *log; guint64 size; - test_server_listen(s); - test_server_listen(dest); - - cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, "", ""); - from = qtest_start(cmd); - g_free(cmd); - - init_virtio_dev(from, s, 1u << VIRTIO_NET_F_MAC); if (!wait_for_fds(s)) { - goto exit; + return; } size = get_log_size(s); g_assert_cmpint(size, ==, (256 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); - tmp = g_strdup_printf(" -incoming %s", uri); - cmd = get_qemu_cmd(dest, 256, TEST_MEMFD_AUTO, "", tmp); - g_free(tmp); - to = qtest_init(cmd); - g_free(cmd); - init_virtio_dev(to, dest, 1u << VIRTIO_NET_F_MAC); + test_server_listen(dest); + g_string_append_printf(dest_cmdline, " -incoming %s", uri); + append_mem_opts(dest, dest_cmdline, 256, TEST_MEMFD_AUTO); + append_vhost_opts(dest, dest_cmdline, ""); + to = qtest_init(dest_cmdline->str); + + /* This would be where you call qos_allocate_objects(to, NULL), if you want + * to talk to the QVirtioNet object on the destination. + */ source = g_source_new(&test_migrate_source_funcs, sizeof(TestMigrateSource)); @@ -797,18 +767,11 @@ static void test_migrate(void) g_assert(wait_for_fds(dest)); read_guest_mem_server(to, dest); - uninit_virtio_dev(dest); - qtest_quit(to); - g_source_destroy(source); g_source_unref(source); -exit: - uninit_virtio_dev(s); - + qtest_quit(to); test_server_free(dest); - qtest_quit(from); - test_server_free(s); g_free(uri); } @@ -856,20 +819,26 @@ connect_thread(gpointer data) return NULL; } -static void test_reconnect_subprocess(void) +static void *vhost_user_test_setup_reconnect(GString *cmd_line, void *arg) { TestServer *s = test_server_new("reconnect"); - GSource *src; - char *cmd; g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); - qtest_start(cmd); - g_free(cmd); + append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); + append_vhost_opts(s, cmd_line, ",server"); + + g_test_queue_destroy(vhost_user_test_cleanup, s); + + return s; +} + +static void test_reconnect(void *obj, void *arg, QGuestAllocator *alloc) +{ + TestServer *s = arg; + GSource *src; - init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); if (!wait_for_fds(s)) { - goto exit; + return; } wait_for_rings_started(s, 2); @@ -883,159 +852,111 @@ static void test_reconnect_subprocess(void) g_source_unref(src); g_assert(wait_for_fds(s)); wait_for_rings_started(s, 2); - -exit: - uninit_virtio_dev(s); - - qtest_end(); - test_server_free(s); - return; } -static void test_reconnect(void) -{ - gchar *path = g_strdup_printf("/%s/vhost-user/reconnect/subprocess", - qtest_get_arch()); - g_test_trap_subprocess(path, 0, 0); - g_test_trap_assert_passed(); - g_free(path); -} - -static void test_connect_fail_subprocess(void) +static void *vhost_user_test_setup_connect_fail(GString *cmd_line, void *arg) { TestServer *s = test_server_new("connect-fail"); - char *cmd; s->test_fail = true; - g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); - qtest_start(cmd); - g_free(cmd); - - init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); - if (!wait_for_fds(s)) { - goto exit; - } - wait_for_rings_started(s, 2); -exit: - uninit_virtio_dev(s); + g_thread_new("connect", connect_thread, s); + append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); + append_vhost_opts(s, cmd_line, ",server"); - qtest_end(); - test_server_free(s); -} + g_test_queue_destroy(vhost_user_test_cleanup, s); -static void test_connect_fail(void) -{ - gchar *path = g_strdup_printf("/%s/vhost-user/connect-fail/subprocess", - qtest_get_arch()); - g_test_trap_subprocess(path, 0, 0); - g_test_trap_assert_passed(); - g_free(path); + return s; } -static void test_flags_mismatch_subprocess(void) +static void *vhost_user_test_setup_flags_mismatch(GString *cmd_line, void *arg) { TestServer *s = test_server_new("flags-mismatch"); - char *cmd; s->test_flags = TEST_FLAGS_DISCONNECT; - g_thread_new("connect", connect_thread, s); - cmd = get_qemu_cmd(s, 256, TEST_MEMFD_AUTO, ",server", ""); - qtest_start(cmd); - g_free(cmd); - init_virtio_dev(global_qtest, s, 1u << VIRTIO_NET_F_MAC); - if (!wait_for_fds(s)) { - goto exit; - } - wait_for_rings_started(s, 2); + g_thread_new("connect", connect_thread, s); + append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); + append_vhost_opts(s, cmd_line, ",server"); -exit: - uninit_virtio_dev(s); + g_test_queue_destroy(vhost_user_test_cleanup, s); - qtest_end(); - test_server_free(s); + return s; } -static void test_flags_mismatch(void) +static void test_vhost_user_started(void *obj, void *arg, QGuestAllocator *alloc) { - gchar *path = g_strdup_printf("/%s/vhost-user/flags-mismatch/subprocess", - qtest_get_arch()); - g_test_trap_subprocess(path, 0, 0); - g_test_trap_assert_passed(); - g_free(path); -} + TestServer *s = arg; + if (!wait_for_fds(s)) { + return; + } + wait_for_rings_started(s, 2); +} -static void test_multiqueue(void) +static void *vhost_user_test_setup_multiqueue(GString *cmd_line, void *arg) { - TestServer *s = test_server_new("mq"); - char *cmd; - uint32_t features_mask = ~(QVIRTIO_F_BAD_FEATURE | - (1u << VIRTIO_RING_F_INDIRECT_DESC) | - (1u << VIRTIO_RING_F_EVENT_IDX)); + TestServer *s = vhost_user_test_setup(cmd_line, arg); + s->queues = 2; - test_server_listen(s); + g_string_append_printf(cmd_line, + " -set netdev.hs0.queues=%d" + " -global virtio-net-pci.vectors=%d", + s->queues, s->queues * 2 + 2); - if (qemu_memfd_check(0)) { - cmd = g_strdup_printf( - QEMU_CMD_MEMFD QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " - "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", - 256, 256, s->chr_name, - s->socket_path, "", s->chr_name, - s->queues, s->queues * 2 + 2); - } else { - cmd = g_strdup_printf( - QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d " - "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d", - 256, 256, s->mem_path, s->chr_name, - s->socket_path, "", s->chr_name, - s->queues, s->queues * 2 + 2); - } - qtest_start(cmd); - g_free(cmd); + return s; +} - init_virtio_dev(global_qtest, s, features_mask); +static void test_multiqueue(void *obj, void *arg, QGuestAllocator *alloc) +{ + TestServer *s = arg; wait_for_rings_started(s, s->queues * 2); - - uninit_virtio_dev(s); - - qtest_end(); - - test_server_free(s); } -int main(int argc, char **argv) +static void register_vhost_user_test(void) { - g_test_init(&argc, &argv, NULL); + QOSGraphTestOptions opts = { + .before = vhost_user_test_setup, + .subprocess = true, + }; - module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_chardev_opts); + qos_add_test("vhost-user/read-guest-mem/memfile", + "virtio-net", + test_read_guest_mem, &opts); + if (qemu_memfd_check(0)) { - qtest_add_data_func("/vhost-user/read-guest-mem/memfd", - GINT_TO_POINTER(TEST_MEMFD_YES), - test_read_guest_mem); + opts.before = vhost_user_test_setup_memfd; + qos_add_test("vhost-user/read-guest-mem/memfd", + "virtio-net", + test_read_guest_mem, &opts); } - qtest_add_data_func("/vhost-user/read-guest-mem/memfile", - GINT_TO_POINTER(TEST_MEMFD_NO), test_read_guest_mem); - qtest_add_func("/vhost-user/migrate", test_migrate); - qtest_add_func("/vhost-user/multiqueue", test_multiqueue); + + qos_add_test("vhost-user/migrate", + "virtio-net", + test_migrate, &opts); /* keeps failing on build-system since Aug 15 2017 */ if (getenv("QTEST_VHOST_USER_FIXME")) { - qtest_add_func("/vhost-user/reconnect/subprocess", - test_reconnect_subprocess); - qtest_add_func("/vhost-user/reconnect", test_reconnect); - qtest_add_func("/vhost-user/connect-fail/subprocess", - test_connect_fail_subprocess); - qtest_add_func("/vhost-user/connect-fail", test_connect_fail); - qtest_add_func("/vhost-user/flags-mismatch/subprocess", - test_flags_mismatch_subprocess); - qtest_add_func("/vhost-user/flags-mismatch", test_flags_mismatch); + opts.before = vhost_user_test_setup_reconnect; + qos_add_test("vhost-user/reconnect", "virtio-net", + test_reconnect, &opts); + + opts.before = vhost_user_test_setup_connect_fail; + qos_add_test("vhost-user/connect-fail", "virtio-net", + test_vhost_user_started, &opts); + + opts.before = vhost_user_test_setup_flags_mismatch; + qos_add_test("vhost-user/flags-mismatch", "virtio-net", + test_vhost_user_started, &opts); } - return g_test_run(); + opts.before = vhost_user_test_setup_multiqueue; + opts.edge.extra_device_opts = "mq=on"; + qos_add_test("vhost-user/multiqueue", + "virtio-net", + test_multiqueue, &opts); } +libqos_init(register_vhost_user_test); From patchwork Thu Mar 7 17:29:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M3YXa/0b"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfDg4tr3z9s7T for ; Fri, 8 Mar 2019 05:24:51 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xhJ-0005qy-Hi for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:24:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr8-0003bq-Sc for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr7-0008PY-Jk for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:54 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr7-0008Or-99 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:53 -0500 Received: by mail-wm1-x342.google.com with SMTP id g20so9984426wmh.5 for ; Thu, 07 Mar 2019 09:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=hw2KDZVvMRBZcF9iEF1OCPR1qLYZdoVWF9GY0F8TsQA=; b=M3YXa/0bbkvGiV7P+CaiAcLsCRL2d84rgBIe9PxAhWMR7P6qUwdjcquf6F0OEYYXlr foe645Xqf2/z4jU79NCWE7x/tOKaWrimX8FcJzqAfqYWYMJtwxH22xk2mAi5qh1VVK8V PnsstKlhImYWZ4DTWplDKDD97DW6x1cxzm92KoqXknpK2xX7P1ToKgOLlCn+0U3Iwbvd jIjz1WoSbzZ49C8bq8mPoAjGRSyvumQUyTTUHGcrkvk8aRVm/tHrlLbIAkCSl/uR5YQv xf8/OHIV30W5Pa00Na6/d7Q1hu930IJdkqmFJghjvaTDPsdBt3wV3kTksVFNSlUAj6Ey sTuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hw2KDZVvMRBZcF9iEF1OCPR1qLYZdoVWF9GY0F8TsQA=; b=GX/t3aygdhO+msqkpHWiL3q9tX4QI/IlDmJJurJx5BhofhA0TlqJS85vkjLeSRLpRS Y+D26XYKo/tHwO+UtChO1ouubum/u3jf8oO/uedieAcKMbGUvhHEhIaLhnMbUeoGRyRi c5ibgY4n0rXgY2VYHsHT+dlbBbVMmDHNBl1cdxflm1uMcKb1Xx6cHK7HUI1Zqe6SnrvO lDVlxjFfIM4nKRrAtAFQvoYmeFvoHGB6LuyoFrkBSY0OPbDcdpCf2ND7tCf0yt1/9oUf 6e7xAgJp7Q2yRR66H2cl0juy7OswRoD6NDD3afwONRFJx+QQQG7w4VoluCIpCaJw6jVB nLxg== X-Gm-Message-State: APjAAAWjXXTon4o4UtW+V69871cx9MJG8HUaiRm+zGTXM8R6Gbw36u4V 3mnTicbTbiq0XPi30JYEBXOeMf1l X-Google-Smtp-Source: APXvYqz+ai+fnVSLQLW+KDK/pgsqnnJbGFIGaUxaLORGkAnwAu5Du7Krqe9jmmLbAAbOZJPn2iqnEw== X-Received: by 2002:a1c:ce46:: with SMTP id e67mr6701081wmg.40.1551979851970; Thu, 07 Mar 2019 09:30:51 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:48 +0100 Message-Id: <1551979804-6060-42-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PULL 41/57] tests/libqos: virtio-scsi driver and interface nodes 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-scsi-pci and virtio-scsi-device. Both nodes produce virtio-scsi, but virtio-scsi-pci receives a pci-bus and uses virtio-pci QOSGraphObject and its functions, while virtio-scsi-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-scsi.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-scsi.h | 39 +++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 tests/libqos/virtio-scsi.c create mode 100644 tests/libqos/virtio-scsi.h diff --git a/tests/Makefile.include b/tests/Makefile.include index a0b42c9..48b7cf0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -743,6 +743,7 @@ qos-test-obj-y += tests/libqos/virtio-balloon.o qos-test-obj-y += tests/libqos/virtio-blk.o qos-test-obj-y += tests/libqos/virtio-net.o qos-test-obj-y += tests/libqos/virtio-rng.o +qos-test-obj-y += tests/libqos/virtio-scsi.o qos-test-obj-y += tests/libqos/virtio-serial.o # Machines diff --git a/tests/libqos/virtio-scsi.c b/tests/libqos/virtio-scsi.c new file mode 100644 index 0000000..482684d --- /dev/null +++ b/tests/libqos/virtio-scsi.c @@ -0,0 +1,117 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "standard-headers/linux/virtio_ids.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-scsi.h" + +/* virtio-scsi-device */ +static void *qvirtio_scsi_get_driver(QVirtioSCSI *v_scsi, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-scsi")) { + return v_scsi; + } + if (!g_strcmp0(interface, "virtio")) { + return v_scsi->vdev; + } + + fprintf(stderr, "%s not present in virtio-scsi-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_scsi_device_get_driver(void *object, + const char *interface) +{ + QVirtioSCSIDevice *v_scsi = object; + return qvirtio_scsi_get_driver(&v_scsi->scsi, interface); +} + +static void *virtio_scsi_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSCSIDevice *virtio_bdevice = g_new0(QVirtioSCSIDevice, 1); + QVirtioSCSI *interface = &virtio_bdevice->scsi; + + interface->vdev = virtio_dev; + + virtio_bdevice->obj.get_driver = qvirtio_scsi_device_get_driver; + + return &virtio_bdevice->obj; +} + +/* virtio-scsi-pci */ +static void *qvirtio_scsi_pci_get_driver(void *object, + const char *interface) +{ + QVirtioSCSIPCI *v_scsi = object; + if (!g_strcmp0(interface, "pci-device")) { + return v_scsi->pci_vdev.pdev; + } + return qvirtio_scsi_get_driver(&v_scsi->scsi, interface); +} + +static void *virtio_scsi_pci_create(void *pci_bus, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSCSIPCI *virtio_spci = g_new0(QVirtioSCSIPCI, 1); + QVirtioSCSI *interface = &virtio_spci->scsi; + QOSGraphObject *obj = &virtio_spci->pci_vdev.obj; + + virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr); + interface->vdev = &virtio_spci->pci_vdev.vdev; + + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_SCSI); + + obj->get_driver = qvirtio_scsi_pci_get_driver; + + return obj; +} + +static void virtio_scsi_register_nodes(void) +{ + QPCIAddress addr = { + .devfn = QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts = { + .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw", + .after_cmd_line = "-device scsi-hd,bus=vs0.0,drive=drv0", + }; + + /* virtio-scsi-device */ + opts.extra_device_opts = "id=vs0"; + qos_node_create_driver("virtio-scsi-device", + virtio_scsi_device_create); + qos_node_consumes("virtio-scsi-device", "virtio-bus", &opts); + qos_node_produces("virtio-scsi-device", "virtio-scsi"); + + /* virtio-scsi-pci */ + opts.extra_device_opts = "id=vs0,addr=04.0"; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-scsi-pci", virtio_scsi_pci_create); + qos_node_consumes("virtio-scsi-pci", "pci-bus", &opts); + qos_node_produces("virtio-scsi-pci", "pci-device"); + qos_node_produces("virtio-scsi-pci", "virtio-scsi"); +} + +libqos_init(virtio_scsi_register_nodes); diff --git a/tests/libqos/virtio-scsi.h b/tests/libqos/virtio-scsi.h new file mode 100644 index 0000000..17a47be --- /dev/null +++ b/tests/libqos/virtio-scsi.h @@ -0,0 +1,39 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioSCSI QVirtioSCSI; +typedef struct QVirtioSCSIPCI QVirtioSCSIPCI; +typedef struct QVirtioSCSIDevice QVirtioSCSIDevice; + +struct QVirtioSCSI { + QVirtioDevice *vdev; +}; + +struct QVirtioSCSIPCI { + QVirtioPCIDevice pci_vdev; + QVirtioSCSI scsi; +}; + +struct QVirtioSCSIDevice { + QOSGraphObject obj; + QVirtioSCSI scsi; +}; From patchwork Thu Mar 7 17:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053146 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cXCpwEye"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdh43fspz9sNG for ; Fri, 8 Mar 2019 05:00:04 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xJK-0001xi-Es for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:00:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrA-0003ei-Nm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr9-0008Qv-As for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:56 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:56016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr9-0008QE-2Z for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:55 -0500 Received: by mail-wm1-x342.google.com with SMTP id q187so10151339wme.5 for ; Thu, 07 Mar 2019 09:30:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=HkGgy5COX3XUihodCLAlptHaI6AHdslJQuMj/d4DtZg=; b=cXCpwEye1bhH8vsiw4PShRLNsVNVuisq1aej5saiQ8mT5EVznis1rzAZYnTb3aeC7r M9+nbQhSJ5X9lTh2ULhsUWJu5cIAaLv4gxTyjB3q1dxJINSiICEpJDfngioAzoH6S5/9 p2+JASC2wXQVx9Pls9bOs0m9U1QBaa+kedTPPKhI+tEJhgJ2J2+pvtn6XfUN6wOKGJEd qly1ckdWD2PhlbrPH7qi+8oaoBgfns/a1f7I5YiUx3jXCXtSLpY6YnVJASokNjMPI2kt gdTJc1BcRj2Jv+GnYpbrVAhRAaS4tHDCra5jX9oy8neo5pBm29vZvF9u67a0n6lSRmlm 4zjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=HkGgy5COX3XUihodCLAlptHaI6AHdslJQuMj/d4DtZg=; b=X3CtOAnLg6gIOE8omqoUgWvTTQvGasgLlfx1X78ei/Gzyh58iA0PST4ESO+wrwmx5c 9mqd01xesytfvP4Hlge3FQi9B/0Z1zSsuPZkFSlNaxnhrToHUm9NN39eQJMxzj2YEl0D 30/F8bpq2DkFV4xCI+r3IQLtzunKGANn57rSaQ1YwyfICxdJ2cFFsG0N6z+dUOsO0Lg7 2rJJVRTx2urUySuVr+yiwitTUBNch8nHc2vjTIR4wtuqBSooa+RQtrwWU9wbYCRXaAIa lsyjKHtiD5r8Vffoj/PoVtnzPu2QRnIfbOkiNc/EDP+aN/HvDXsZEB2gs9jA88M3MG/c HRyg== X-Gm-Message-State: APjAAAUBl4xwduBEAv0UnwOALorJK8aVUF4vEDLN4QymX3OjThNDcOGF bd12MXjHeIs1j1LucUY2rgg5O7+b X-Google-Smtp-Source: APXvYqyLLAKePin5P6HrBcoPKvSNiO1l93OLaatyrMH/DUVR5DDc3LbL+oq+IyOxeByJggM3HAz5yg== X-Received: by 2002:a1c:6555:: with SMTP id z82mr6178224wmb.125.1551979853660; Thu, 07 Mar 2019 09:30:53 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:49 +0100 Message-Id: <1551979804-6060-43-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PULL 42/57] qos-test: virtio-scsi test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/virtio-scsi-test in qgraph test node, virtio-scsi-test. This test consumes a virtio-scsi interface and checks that its function return the expected values. Some functions are implemented only for virtio-scsi-pci, so they don't consume virtio-scsi, but virtio-scsi-pci Note that this test does not allocate any virtio-scsi structure, it's all done by the qtest walking graph mechanism Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 4 +- tests/virtio-scsi-test.c | 143 +++++++++++++++++++---------------------------- 2 files changed, 60 insertions(+), 87 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 48b7cf0..09483d0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -153,8 +153,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) -check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF) - check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) @@ -766,6 +764,7 @@ qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o qos-test-obj-y += tests/virtio-blk-test.o qos-test-obj-y += tests/virtio-net-test.o qos-test-obj-y += tests/virtio-rng-test.o +qos-test-obj-y += tests/virtio-scsi-test.o qos-test-obj-y += tests/virtio-serial-test.o check-unit-y += tests/test-qgraph$(EXESUF) @@ -813,7 +812,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o -tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o $(libqos-virtio-obj-y) tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 9298aa8..162b31c 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -18,6 +18,8 @@ #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_pci.h" #include "standard-headers/linux/virtio_scsi.h" +#include "libqos/virtio-scsi.h" +#include "libqos/qgraph.h" #define PCI_SLOT 0x02 #define PCI_FN 0x00 @@ -27,55 +29,28 @@ typedef struct { QVirtioDevice *dev; - QOSState *qs; int num_queues; QVirtQueue *vq[MAX_NUM_QUEUES + 2]; -} QVirtIOSCSI; +} QVirtioSCSIQueues; -static QOSState *qvirtio_scsi_start(const char *extra_opts) -{ - QOSState *qs; - const char *arch = qtest_get_arch(); - const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw " - "-device virtio-scsi-pci,id=vs0 " - "-device scsi-hd,bus=vs0.0,drive=drv0 %s"; - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qs = qtest_pc_boot(cmd, extra_opts ? : ""); - } else if (strcmp(arch, "ppc64") == 0) { - qs = qtest_spapr_boot(cmd, extra_opts ? : ""); - } else { - g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); - } - global_qtest = qs->qts; - return qs; -} - -static void qvirtio_scsi_stop(QOSState *qs) -{ - qtest_shutdown(qs); -} +static QGuestAllocator *alloc; -static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) +static void qvirtio_scsi_pci_free(QVirtioSCSIQueues *vs) { int i; for (i = 0; i < vs->num_queues + 2; i++) { - qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], &vs->qs->alloc); + qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], alloc); } - qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev)); - qvirtio_pci_device_free((QVirtioPCIDevice *)vs->dev); - qvirtio_scsi_stop(vs->qs); g_free(vs); } -static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size, +static uint64_t qvirtio_scsi_alloc(QVirtioSCSIQueues *vs, size_t alloc_size, const void *data) { uint64_t addr; - addr = guest_alloc(&vs->qs->alloc, alloc_size); + addr = guest_alloc(alloc, alloc_size); if (data) { memwrite(addr, data, alloc_size); } @@ -83,7 +58,8 @@ static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size, return addr; } -static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, +static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs, + const uint8_t *cdb, const uint8_t *data_in, size_t data_in_len, uint8_t *data_out, size_t data_out_len, @@ -133,40 +109,28 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, memread(resp_addr, resp_out, sizeof(*resp_out)); } - guest_free(&vs->qs->alloc, req_addr); - guest_free(&vs->qs->alloc, resp_addr); - guest_free(&vs->qs->alloc, data_in_addr); - guest_free(&vs->qs->alloc, data_out_addr); + guest_free(alloc, req_addr); + guest_free(alloc, resp_addr); + guest_free(alloc, data_in_addr); + guest_free(alloc, data_out_addr); return response; } -static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) +static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevice *dev) { + QVirtioSCSIQueues *vs; const uint8_t test_unit_ready_cdb[VIRTIO_SCSI_CDB_SIZE] = {}; - QVirtIOSCSI *vs; - QVirtioPCIDevice *dev; struct virtio_scsi_cmd_resp resp; int i; - vs = g_new0(QVirtIOSCSI, 1); - - vs->qs = qvirtio_scsi_start("-drive file=blkdebug::null-co://," - "if=none,id=dr1,format=raw,file.align=4k " - "-device scsi-hd,drive=dr1,lun=0,scsi-id=1"); - dev = qvirtio_pci_device_find(vs->qs->pcibus, VIRTIO_ID_SCSI); - vs->dev = (QVirtioDevice *)dev; - g_assert(dev != NULL); - g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI); - - qvirtio_pci_device_enable(dev); - qvirtio_start_device(vs->dev); - - vs->num_queues = qvirtio_config_readl(vs->dev, 0); + vs = g_new0(QVirtioSCSIQueues, 1); + vs->dev = dev; + vs->num_queues = qvirtio_config_readl(dev, 0); g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES); for (i = 0; i < vs->num_queues + 2; i++) { - vs->vq[i] = qvirtqueue_setup(vs->dev, &vs->qs->alloc, i); + vs->vq[i] = qvirtqueue_setup(dev, alloc, i); } /* Clear the POWER ON OCCURRED unit attention */ @@ -182,30 +146,18 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) return vs; } -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) -{ - QOSState *qs; - - qs = qvirtio_scsi_start(NULL); - qvirtio_scsi_stop(qs); -} - -static void hotplug(void) +static void hotplug(void *obj, void *data, QGuestAllocator *alloc) { - QOSState *qs; - - qs = qvirtio_scsi_start( - "-drive id=drv1,if=none,file=null-co://,format=raw"); qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drv1'}"); qtest_qmp_device_del("scsihd"); - qvirtio_scsi_stop(qs); } /* Test WRITE SAME with the lba not aligned */ -static void test_unaligned_write_same(void) +static void test_unaligned_write_same(void *obj, void *data, + QGuestAllocator *t_alloc) { - QVirtIOSCSI *vs; + QVirtioSCSI *scsi = obj; + QVirtioSCSIQueues *vs; uint8_t buf1[512] = { 0 }; uint8_t buf2[512] = { 1 }; const uint8_t write_same_cdb_1[VIRTIO_SCSI_CDB_SIZE] = { @@ -218,27 +170,50 @@ static void test_unaligned_write_same(void) 0x41, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x33, 0x00, 0x00 }; - vs = qvirtio_scsi_pci_init(PCI_SLOT); + alloc = t_alloc; + vs = qvirtio_scsi_init(scsi->vdev); g_assert_cmphex(0, ==, - virtio_scsi_do_command(vs, write_same_cdb_1, NULL, 0, buf1, 512, NULL)); + virtio_scsi_do_command(vs, write_same_cdb_1, NULL, 0, buf1, 512, + NULL)); g_assert_cmphex(0, ==, - virtio_scsi_do_command(vs, write_same_cdb_2, NULL, 0, buf2, 512, NULL)); + virtio_scsi_do_command(vs, write_same_cdb_2, NULL, 0, buf2, 512, + NULL)); g_assert_cmphex(0, ==, - virtio_scsi_do_command(vs, write_same_cdb_ndob, NULL, 0, NULL, 0, NULL)); + virtio_scsi_do_command(vs, write_same_cdb_ndob, NULL, 0, NULL, 0, + NULL)); qvirtio_scsi_pci_free(vs); } -int main(int argc, char **argv) +static void *virtio_scsi_hotplug_setup(GString *cmd_line, void *arg) { - g_test_init(&argc, &argv, NULL); - qtest_add_func("/virtio/scsi/pci/nop", pci_nop); - qtest_add_func("/virtio/scsi/pci/hotplug", hotplug); - qtest_add_func("/virtio/scsi/pci/scsi-disk/unaligned-write-same", - test_unaligned_write_same); + g_string_append(cmd_line, + " -drive id=drv1,if=none,file=null-co://,format=raw"); + return arg; +} - return g_test_run(); +static void *virtio_scsi_setup(GString *cmd_line, void *arg) +{ + g_string_append(cmd_line, + " -drive file=blkdebug::null-co://," + "if=none,id=dr1,format=raw,file.align=4k " + "-device scsi-hd,drive=dr1,lun=0,scsi-id=1"); + return arg; } + +static void register_virtio_scsi_test(void) +{ + QOSGraphTestOptions opts = { }; + + opts.before = virtio_scsi_hotplug_setup; + qos_add_test("hotplug", "virtio-scsi", hotplug, &opts); + + opts.before = virtio_scsi_setup; + qos_add_test("unaligned-write-same", "virtio-scsi", + test_unaligned_write_same, &opts); +} + +libqos_init(register_virtio_scsi_test); From patchwork Thu Mar 7 17:29:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="p7523rdt"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdlw4YQPz9s7T for ; Fri, 8 Mar 2019 05:03:24 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xMY-0004dx-Fl for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:03:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrB-0003fX-IV for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrA-0008Ru-Fk for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:57 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:39936) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrA-0008RL-7m for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:56 -0500 Received: by mail-wr1-x42c.google.com with SMTP id y6so3260070wrn.7 for ; Thu, 07 Mar 2019 09:30:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ONpxlFM8KN/oydwuZ3QtAxwwDeeXEMkw+n+ylFICszU=; b=p7523rdtCgRliR8BI8609tbZHQ0HkTAvMdlxE+Y2bdgAEYDDzVy23xYzuXK9BE1LpK zEyISLNRHTU/rx5b9jUG5U2Q4gq4lB425YiDCDlf0vX3yqU/i2iwEzX3LNVThD4r3wVC UafF+TNkm2O74BomsZv+4ONjyKnXq3RmJrf+nqUjZ7XPC+kg7SrvcrqBbIFCQu963eWO Cs66Pj7p6Mojf5gGfraXPbIzM6xpC6h9rnqsELa08tltEjMmHlVFPpW12CiXj1DYhXY0 ZUuQnfYPr1YsEv0LPKRWSzr7ZQC63XBsEmB2Gey8lBN6DrIlLAE8Svf9UFgV7eb6XHAe NaHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ONpxlFM8KN/oydwuZ3QtAxwwDeeXEMkw+n+ylFICszU=; b=Xt/ir0FW3/ZYAntGHiQOUm4BnK0ogf0xG67t6CHqhwGULFSS3fCSGhcV5Uh7ZMWRyM lDJ/Vx1KaK6triK+bC3sW3Zbu/s7Cf58fEMFQPTbPh4guVh180t9BdU9rTrXtqlJBWVs gngXmKtBfYDuO7WOyGs3h35b47pWsi3M95A71AW4x1YG3Tuq4CUojrGDVjsnaEAvNcRz pNofVFLiJjDwF5lhLw2nACZThQDwUvJ8WY3sdn4c65/vW2NVloYWPARm+FdaOL0VYWEs JCnN7YCL3QfvkR7gb5VH1/ssIF/fzqPlRXOHAHMe9FBiqYs+icOHTpR6eXj6DBvjvEED s3Zw== X-Gm-Message-State: APjAAAUlPU3Jn4GwkNzor7YAggH7x4nGGEGQy7WxF0PrBm+nDLW92dhR uNuInRc1gA07xKA9MGpZJrxDHnYS X-Google-Smtp-Source: APXvYqwgcXvvr2DKzzyNjEXiMIs70YlGS8BAL4x1/rSamScbHdPcDP8sB7KcgFSnDWjA3ZG18QV5kA== X-Received: by 2002:adf:dd4d:: with SMTP id u13mr8394452wrm.284.1551979854908; Thu, 07 Mar 2019 09:30:54 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:50 +0100 Message-Id: <1551979804-6060-44-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 43/57] tests/libqos: remove pre-qgraph QVirtioPCIDevice API 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Remove the qvirtio_pci_device_find* and qvirtio_pci_device_free APIs, now that they do not have any users. Signed-off-by: Paolo Bonzini --- tests/libqos/virtio-pci.c | 112 +++++++--------------------------------------- tests/libqos/virtio-pci.h | 4 -- 2 files changed, 17 insertions(+), 99 deletions(-) diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 0b58b74..993d347 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -35,14 +35,6 @@ * original qvirtio_pci_destructor and qvirtio_pci_start_hw. */ -typedef struct QVirtioPCIForeachData { - void (*func)(QVirtioDevice *d, void *data); - uint16_t device_type; - bool has_slot; - int slot; - void *user_data; -} QVirtioPCIForeachData; - static inline bool qvirtio_pci_is_big_endian(QVirtioPCIDevice *dev) { QPCIBus *bus = dev->pdev->bus; @@ -51,50 +43,6 @@ static inline bool qvirtio_pci_is_big_endian(QVirtioPCIDevice *dev) return qtest_big_endian(bus->qts); } -void qvirtio_pci_device_free(QVirtioPCIDevice *dev) -{ - g_free(dev->pdev); -} - -static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevice *dev, QPCIDevice *pci_dev) -{ - dev->pdev = pci_dev; - dev->vdev.device_type = qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); - - dev->config_msix_entry = -1; - - dev->vdev.bus = &qvirtio_pci; - dev->vdev.big_endian = qvirtio_pci_is_big_endian(dev); - - /* each virtio-xxx-pci device should override at least this function */ - dev->obj.get_driver = NULL; - dev->obj.start_hw = qvirtio_pci_start_hw; - dev->obj.destructor = qvirtio_pci_destructor; -} - -static void qvirtio_pci_foreach_callback( - QPCIDevice *dev, int devfn, void *data) -{ - QVirtioPCIForeachData *d = data; - QVirtioPCIDevice *vpcidev = g_new0(QVirtioPCIDevice, 1); - - qvirtio_pci_init_from_pcidev(vpcidev, dev); - if (vpcidev->vdev.device_type == d->device_type && - (!d->has_slot || vpcidev->pdev->devfn == d->slot << 3)) { - d->func(&vpcidev->vdev, d->user_data); - } else { - qvirtio_pci_device_free(vpcidev); - g_free(vpcidev); - } -} - -static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) -{ - QVirtioPCIDevice **vpcidev = data; - assert(!*vpcidev); - *vpcidev = container_of(d, QVirtioPCIDevice, vdev); -} - #define CONFIG_BASE(dev) (VIRTIO_PCI_CONFIG_OFF((dev)->pdev->msix_enabled)) static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off) @@ -317,48 +265,6 @@ const QVirtioBus qvirtio_pci = { .virtqueue_kick = qvirtio_pci_virtqueue_kick, }; -/* TODO: delete this once qgraph is completed */ -static void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type, - bool has_slot, int slot, - void (*func)(QVirtioDevice *d, void *data), void *data) -{ - QVirtioPCIForeachData d = { .func = func, - .device_type = device_type, - .has_slot = has_slot, - .slot = slot, - .user_data = data }; - - qpci_device_foreach(bus, PCI_VENDOR_ID_REDHAT_QUMRANET, -1, - qvirtio_pci_foreach_callback, &d); -} - -QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type) -{ - QVirtioPCIDevice *dev = NULL; - - qvirtio_pci_foreach(bus, device_type, false, 0, - qvirtio_pci_assign_device, &dev); - - if (dev) { - dev->vdev.bus = &qvirtio_pci; - } - - return dev; -} - -QVirtioPCIDevice *qvirtio_pci_device_find_slot(QPCIBus *bus, - uint16_t device_type, int slot) -{ - QVirtioPCIDevice *dev = NULL; - - qvirtio_pci_foreach(bus, device_type, true, slot, - qvirtio_pci_assign_device, &dev); - - dev->vdev.bus = &qvirtio_pci; - - return dev; -} - void qvirtio_pci_device_enable(QVirtioPCIDevice *d) { qpci_device_enable(d->pdev); @@ -445,7 +351,7 @@ void qvirtio_pci_destructor(QOSGraphObject *obj) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)obj; qvirtio_pci_device_disable(dev); - qvirtio_pci_device_free(dev); + g_free(dev->pdev); } void qvirtio_pci_start_hw(QOSGraphObject *obj) @@ -455,6 +361,22 @@ void qvirtio_pci_start_hw(QOSGraphObject *obj) qvirtio_start_device(&dev->vdev); } +static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevice *dev, QPCIDevice *pci_dev) +{ + dev->pdev = pci_dev; + dev->vdev.device_type = qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); + + dev->config_msix_entry = -1; + + dev->vdev.bus = &qvirtio_pci; + dev->vdev.big_endian = qvirtio_pci_is_big_endian(dev); + + /* each virtio-xxx-pci device should override at least this function */ + dev->obj.get_driver = NULL; + dev->obj.start_hw = qvirtio_pci_start_hw; + dev->obj.destructor = qvirtio_pci_destructor; +} + void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr) { QPCIDevice *pci_dev = qpci_device_find(bus, addr->devfn); diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 5631352..728b471 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -35,10 +35,6 @@ extern const QVirtioBus qvirtio_pci; void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr); QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr); -QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type); -QVirtioPCIDevice *qvirtio_pci_device_find_slot(QPCIBus *bus, - uint16_t device_type, int slot); -void qvirtio_pci_device_free(QVirtioPCIDevice *dev); /* virtio-pci object functions available for subclasses that * override the original start_hw and destroy From patchwork Thu Mar 7 17:29:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="l12qZLAj"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdzN26g9z9s70 for ; Fri, 8 Mar 2019 05:13:20 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xWA-0004im-62 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:13:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrD-0003h9-1X for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrB-0008Ss-VF for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:59 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:42118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrB-0008SP-NL for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:57 -0500 Received: by mail-wr1-x42e.google.com with SMTP id r5so18400785wrg.9 for ; Thu, 07 Mar 2019 09:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=WuoT7moNiniyy5E4tyJZKlz/EpLBidJuzX7Y/2osm+I=; b=l12qZLAj8kiCvnC6mt5K81YAlJLxcqKbri65Z5RqMA3Iwo2HBuRQlYQqadNEgDReY2 LkXyJUTSi9yRFz0z0unEBlpTsPi1ndcK/tgnyr/S7i50M5usDrmsB58JJpA8f4Qyjfbc 8NSuNwmjPYx0+VbaXDQO9y+myRJ/w0AfCBD+dxjMm6LWSrXQgUg9/cKpBhcp1OzCKuMA 8heoZc/4KfClVt9e42syVhTEA99rpC43R5Kx1KpbHgq2qRVwFYk3slRRKXTf6t07SwB/ er3i0JGZIFCfvgIbXqKi3YnR/T0FNxEFwMaj34dpIRx68XsY4vHjClpmzMLBqVUpy+Gq lexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=WuoT7moNiniyy5E4tyJZKlz/EpLBidJuzX7Y/2osm+I=; b=YllHyM+WSUL3FX4TNEttIEi8+7oWWwUeDcO1LDaNhvP+RwHkOpzaA1LdBkLxVxcCJm 7pBDSqJdMBXkB99DGhTCH3ewyWImys4bRjFL+8Ffmw+/WSJrHmC/DIDTzkKXDkSk1K+r my2tnyQ/ZoKxNacAzHSrPumIbyU0ogtPaxwo3Y7p9W4ldwaOgsW/rdGFTQ4WZbn/ZuoI oTFspN/qdd1UUdJPPrluJcjomlI3sA8OpqTcbaf5aYx5u+AsatSbDaTQwKOoCwy/rPRL NtWbNyyuQTP1po1cJbntCUgS1W3pfyO3niuzFVDskaytQpvvy5fIcTiJWH2FJckNuyiW Cn7Q== X-Gm-Message-State: APjAAAUQ9uyzizzQpy7YMPUw+pKCWr+cn8BRn/Xhqix7HIiaZB9kHRmY YguqBAs5x81S7x1nCBVQymDGQ4ik X-Google-Smtp-Source: APXvYqyfaaGmQI13gEy0ufNv6iewx5Tt9dWyB7fNHHshxmGy61EiUfxjC701oAWoNoan/e6QMTLnUA== X-Received: by 2002:a5d:558c:: with SMTP id i12mr7577453wrv.19.1551979856493; Thu, 07 Mar 2019 09:30:56 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:51 +0100 Message-Id: <1551979804-6060-45-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [PULL 44/57] tests: move virtio entirely to qos-test 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The only remaining test that needs libqos-virtio-obj-y is drive_del-test, which really only needs a function. Move that function to the test and remove libqos-virtio-obj-y. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 9 ++++----- tests/drive_del-test.c | 25 +++++++++++++++++++------ tests/libqos/virtio.c | 18 ------------------ tests/libqos/virtio.h | 1 - 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 09483d0..b4b53ca 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -161,7 +161,6 @@ check-qtest-pci-$(CONFIG_NE2000_PCI) += tests/ne2000-test$(EXESUF) check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_AC97) += tests/ac97-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) -check-qtest-pci-$(CONFIG_VIRTIO) += $(check-qtest-virtio-y) check-qtest-pci-$(CONFIG_IPACK) += tests/tpci200-test$(EXESUF) check-qtest-pci-$(CONFIG_IPACK) += $(check-qtest-ipack-y) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) @@ -254,7 +253,6 @@ check-qtest-ppc64-$(CONFIG_SLIRP) += tests/pxe-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_OHCI) += tests/usb-hcd-ohci-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_UHCI) += tests/usb-hcd-uhci-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_XHCI_NEC) += tests/usb-hcd-xhci-test$(EXESUF) -check-qtest-ppc64-$(CONFIG_VIRTIO) += $(check-qtest-virtio-y) check-qtest-ppc64-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF) check-qtest-ppc64-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF) check-qtest-ppc64-$(CONFIG_RTL8139_PCI) += tests/test-filter-redirector$(EXESUF) @@ -728,18 +726,19 @@ libqos-pc-obj-y += tests/libqos/ahci.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o -libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o # Devices qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o -qos-test-obj-y += $(libqos-virtio-obj-y) +qos-test-obj-y += tests/libqos/virtio.o qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-balloon.o qos-test-obj-y += tests/libqos/virtio-blk.o +qos-test-obj-y += tests/libqos/virtio-mmio.o qos-test-obj-y += tests/libqos/virtio-net.o +qos-test-obj-y += tests/libqos/virtio-pci.o qos-test-obj-y += tests/libqos/virtio-rng.o qos-test-obj-y += tests/libqos/virtio-scsi.o qos-test-obj-y += tests/libqos/virtio-serial.o @@ -819,7 +818,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o tests/test-hmp$(EXESUF): tests/test-hmp.o tests/machine-none-test$(EXESUF): tests/machine-none-test.o tests/device-plug-test$(EXESUF): tests/device-plug-test.o -tests/drive_del-test$(EXESUF): tests/drive_del-test.o $(libqos-virtio-obj-y) +tests/drive_del-test$(EXESUF): tests/drive_del-test.o tests/nvme-test$(EXESUF): tests/nvme-test.o $(libqos-pc-obj-y) tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 4a1a088..2f9474e 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -63,6 +63,24 @@ static void test_drive_without_dev(void) qtest_end(); } +/* + * qvirtio_get_dev_type: + * Returns: the preferred virtio bus/device type for the current architecture. + * TODO: delete this + */ +static const char *qvirtio_get_dev_type(void) +{ + const char *arch = qtest_get_arch(); + + if (g_str_equal(arch, "arm") || g_str_equal(arch, "aarch64")) { + return "device"; /* for virtio-mmio */ + } else if (g_str_equal(arch, "s390x")) { + return "ccw"; + } else { + return "pci"; + } +} + static void test_after_failed_device_add(void) { char driver[32]; @@ -119,16 +137,11 @@ static void test_drive_del_device_del(void) int main(int argc, char **argv) { - const char *arch = qtest_get_arch(); - g_test_init(&argc, &argv, NULL); qtest_add_func("/drive_del/without-dev", test_drive_without_dev); - /* TODO I guess any arch with a hot-pluggable virtio bus would do */ - if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64") || - !strcmp(arch, "ppc") || !strcmp(arch, "ppc64") || - !strcmp(arch, "s390x")) { + if (qvirtio_get_dev_type() != NULL) { qtest_add_func("/drive_del/after_failed_device_add", test_after_failed_device_add); qtest_add_func("/blockdev/drive_del_device_del", diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index e4925d1..5e8f39b 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -350,24 +350,6 @@ void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx) writew(vq->avail + 4 + (2 * vq->size), idx); } -/* - * qvirtio_get_dev_type: - * Returns: the preferred virtio bus/device type for the current architecture. - * TODO: delete this - */ -const char *qvirtio_get_dev_type(void) -{ - const char *arch = qtest_get_arch(); - - if (g_str_equal(arch, "arm") || g_str_equal(arch, "aarch64")) { - return "device"; /* for virtio-mmio */ - } else if (g_str_equal(arch, "s390x")) { - return "ccw"; - } else { - return "pci"; - } -} - void qvirtio_start_device(QVirtioDevice *vdev) { qvirtio_reset(vdev); diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 3f97d79..51d2359 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -142,7 +142,6 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len); void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx); -const char *qvirtio_get_dev_type(void); void qvirtio_start_device(QVirtioDevice *vdev); #endif From patchwork Thu Mar 7 17:29:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Z1DZz2jH"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfMn5DG4z9s70 for ; Fri, 8 Mar 2019 05:31:01 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xnH-0002sa-Cj for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:30:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrE-0003hw-JY for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrD-0008VS-Lx for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:00 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:39943) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrD-0008U1-EQ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:59 -0500 Received: by mail-wr1-x433.google.com with SMTP id y6so3260281wrn.7 for ; Thu, 07 Mar 2019 09:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=1kYiaIpsHJwbj1Nj0iQD3FOYpTsBVhgkygF1GiEoV2E=; b=Z1DZz2jHh0kUjh5q8UKgR7FQfMXo0PT5nuGehKzXyk5nhxNWCqaqXO28drpyYYnNzK JgzDMMNhaWx8tnZOd0TkzxOqprHwwIMsUalYN04DykeKUgtFEJV5OUvQYX0FuWp6wtIu cTx7z1qELJ8i2awmDYINGl3Dp7MKqLePAJslcNgG+K4q7cqJE9VwlWPT14zzhXR8+i/1 ThW51eifQS1cHu+GRaOPYQUuRf3Sv3Tn7AugL5+RtjJJfSWT3R9ZMK+NWYeeB+rsNhry 41ly516dq9jPekQsVRNvCxEboFNah4Wi/GVt2uENVHZ0ZYYrtng07areYcNRqpnBbVP8 3XXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=1kYiaIpsHJwbj1Nj0iQD3FOYpTsBVhgkygF1GiEoV2E=; b=LQWtQBMZ2iN55/kQNeiI8tKS+DW3+ccIaUdGlXiLXHB859kumpH1qMtIMrlaydbZX9 cMCydJzf26G0XMH+fhE4zUc7qfJ11vB7zXkdYGqtM2uMUgdquqEvezgCcvMvlKu7Ut0R rfknxVM5M/zpulEav7rz+ngNvlWKjqk+MXTvWYrrddjj8mS2WQpiOjDRjRADHA7fkfxK n0tp3ofwhWsozuiyFeqkdategiWHGtRWlo7RkEDJGwW6zIoDdqRfYaMPSVlMSGJjZDM7 b6AAqWF2Ge1eqVPjmXoAKvbtV2T0NU9bbhYm8NanasTbnDZk25imiWFYt6xUe2E2znfD 9O8w== X-Gm-Message-State: APjAAAWnCidvQ+vlFf2wBxvB8pck2ojt32rMr9ddhRRcz3cBo8RJ8g24 O+ABawyn4+EeNlg2yIleSEDVRmcp X-Google-Smtp-Source: APXvYqxsDGulam3buY+MlZlfMxiMWz2qSiW8k8S+xA3czGq4KFgewe0zcoBYyVfRxW2tZMp4TG+EHg== X-Received: by 2002:adf:ec07:: with SMTP id x7mr7461080wrn.174.1551979858142; Thu, 07 Mar 2019 09:30:58 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:52 +0100 Message-Id: <1551979804-6060-46-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::433 Subject: [Qemu-devel] [PULL 45/57] qos-test: ac97 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/ac97-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/ac97-test.c | 47 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index b4b53ca..954b06b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -159,7 +159,6 @@ check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) check-qtest-pci-$(CONFIG_NE2000_PCI) += tests/ne2000-test$(EXESUF) check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) -check-qtest-pci-$(CONFIG_AC97) += tests/ac97-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_IPACK) += tests/tpci200-test$(EXESUF) check-qtest-pci-$(CONFIG_IPACK) += $(check-qtest-ipack-y) @@ -754,6 +753,7 @@ qos-test-obj-y += tests/libqos/ppc64_pseries-machine.o qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests +qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o @@ -822,7 +822,6 @@ tests/drive_del-test$(EXESUF): tests/drive_del-test.o tests/nvme-test$(EXESUF): tests/nvme-test.o $(libqos-pc-obj-y) tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o -tests/ac97-test$(EXESUF): tests/ac97-test.o tests/es1370-test$(EXESUF): tests/es1370-test.o tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o diff --git a/tests/ac97-test.c b/tests/ac97-test.c index e0d177b..532fb1c 100644 --- a/tests/ac97-test.c +++ b/tests/ac97-test.c @@ -9,23 +9,48 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void nop(void) +typedef struct QAC97 QAC97; + +struct QAC97 { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *ac97_get_driver(void *obj, const char *interface) { + QAC97 *ac97 = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &ac97->dev; + } + + fprintf(stderr, "%s not present in e1000e\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *ac97_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QAC97 *ac97 = g_new0(QAC97, 1); + QPCIBus *bus = pci_bus; - g_test_init(&argc, &argv, NULL); - qtest_add_func("/ac97/nop", nop); - - qtest_start("-device AC97"); - ret = g_test_run(); + qpci_device_init(&ac97->dev, bus, addr); + ac97->obj.get_driver = ac97_get_driver; + return &ac97->obj; +} - qtest_end(); +static void ac97_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return ret; + qos_node_create_driver("AC97", ac97_create); + qos_node_produces("AC97", "pci-device"); + qos_node_consumes("AC97", "pci-bus", &opts); } + +libqos_init(ac97_register_nodes); From patchwork Thu Mar 7 17:29:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZQJC7IsO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfJ031jQz9s70 for ; Fri, 8 Mar 2019 05:27:44 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xk4-0008WC-Ot for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:27:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrF-0003jX-VD for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrE-0008WU-L2 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:01 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:35880) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrE-0008VW-Ct for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:00 -0500 Received: by mail-wr1-x431.google.com with SMTP id o17so18422043wrw.3 for ; Thu, 07 Mar 2019 09:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=c8ylAQm2QIUCpEPMIiXz7S8toiAAcf2ahnhOxiZk3Qg=; b=ZQJC7IsOo1BV0U0IgoFOIOyCMLdLCkKTkpx3FrIrBodB2vwWDix5ZxT6onhEMa+rH5 pilI/FYHhKK773pTh7TQ75E+l6f93TsN6vg3d6C8DsZ80SRtGgQaM0okhYL/FuHbeEzq jUby9UFtO4EDBxLU9l8VwCTH2FzNv/0Z/XEQyAAllOpV4IzTdvJ2+eXDC3O06Q5tTxEL f9wJxVJKOzhy93tzfzcd2caEZihgmR7KbtHs76VVIp5t4pGkeuMkDMBb9mPasCZ7nnPl eW8TEubpI3J0r/Pia97y7KQg0fo8KtzboG9vuQa1U8ixvW+MArwSaYAgVpBNJFCVphWd VXVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=c8ylAQm2QIUCpEPMIiXz7S8toiAAcf2ahnhOxiZk3Qg=; b=kNE8qS/GaCV9SGKYmsITcVMhYPTEYvoqKiHCOhRkg5k5xFCH2XD1r4RM9659kUMw2S zKV0Z61crsKk/A1SeAvqpynE4ailAgojwnf7XO6f3Ul7t9tCK3s7YD5wmWHEkHvB9Ruq EMydoscZwzKATmaXSuNXQP/JarFK5uHkOUo5IPQSsOnhnzQRJseP97pvIBudlIqC0Ae7 F3HzMFeK1VUNGmHMyEVQ220XZAcKG++QqrwWMkuqUtag3GSfTO0q4oaJSj/rDnAxqcaN 1mEyc9K/munC16w+/e7cU6Kqg/iKijA5/Kacb2xNamwmXqKPswFDRFWEyQ7S3nmhsh7d wfSw== X-Gm-Message-State: APjAAAU3R5eyeDfuYC95+0krNlSGORiRUQHMcE9jKbw0L7SBkhFz2SzT c1R+vtk/vj0y6WYVHGPwuyj47FVr X-Google-Smtp-Source: APXvYqxj+f8t5YYerXwRuxaIWnsLGpRd1PyQ/6kw3+PnruKe6yo5fsgChFEK8bivo83oimdduLhDcg== X-Received: by 2002:a5d:5042:: with SMTP id h2mr7728716wrt.12.1551979859031; Thu, 07 Mar 2019 09:30:59 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:53 +0100 Message-Id: <1551979804-6060-47-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 Subject: [Qemu-devel] [PULL 46/57] qos-test: tpci200 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/tpci200-test to a driver node; currently it runs the PCI nop test only, but it also produces the ipack interface. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/libqos/tpci200.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/tpci200-test.c | 31 ------------------------ 3 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 tests/libqos/tpci200.c delete mode 100644 tests/tpci200-test.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 954b06b..905a361 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -160,7 +160,6 @@ check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) check-qtest-pci-$(CONFIG_NE2000_PCI) += tests/ne2000-test$(EXESUF) check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) -check-qtest-pci-$(CONFIG_IPACK) += tests/tpci200-test$(EXESUF) check-qtest-pci-$(CONFIG_IPACK) += $(check-qtest-ipack-y) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) @@ -731,6 +730,7 @@ qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y += tests/libqos/e1000e.o qos-test-obj-y += tests/libqos/sdhci.o +qos-test-obj-y += tests/libqos/tpci200.o qos-test-obj-y += tests/libqos/virtio.o qos-test-obj-$(CONFIG_VIRTFS) += tests/libqos/virtio-9p.o qos-test-obj-y += tests/libqos/virtio-balloon.o @@ -811,7 +811,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o -tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o tests/qom-test$(EXESUF): tests/qom-test.o diff --git a/tests/libqos/tpci200.c b/tests/libqos/tpci200.c new file mode 100644 index 0000000..98dc532 --- /dev/null +++ b/tests/libqos/tpci200.c @@ -0,0 +1,65 @@ +/* + * QTest testcase for tpci200 PCI-IndustryPack bridge + * + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * 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 "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" + +typedef struct QTpci200 QTpci200; +typedef struct QIpack QIpack; + +struct QIpack { + +}; +struct QTpci200 { + QOSGraphObject obj; + QPCIDevice dev; + QIpack ipack; +}; + +/* tpci200 */ +static void *tpci200_get_driver(void *obj, const char *interface) +{ + QTpci200 *tpci200 = obj; + if (!g_strcmp0(interface, "ipack")) { + return &tpci200->ipack; + } + if (!g_strcmp0(interface, "pci-device")) { + return &tpci200->dev; + } + + fprintf(stderr, "%s not present in tpci200\n", interface); + g_assert_not_reached(); +} + +static void *tpci200_create(void *pci_bus, QGuestAllocator *alloc, void *addr) +{ + QTpci200 *tpci200 = g_new0(QTpci200, 1); + QPCIBus *bus = pci_bus; + + qpci_device_init(&tpci200->dev, bus, addr); + tpci200->obj.get_driver = tpci200_get_driver; + return &tpci200->obj; +} + +static void tpci200_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0,id=ipack0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); + + qos_node_create_driver("tpci200", tpci200_create); + qos_node_consumes("tpci200", "pci-bus", &opts); + qos_node_produces("tpci200", "ipack"); + qos_node_produces("tpci200", "pci-device"); +} + +libqos_init(tpci200_register_nodes); diff --git a/tests/tpci200-test.c b/tests/tpci200-test.c deleted file mode 100644 index 0321ec2..0000000 --- a/tests/tpci200-test.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * QTest testcase for tpci200 PCI-IndustryPack bridge - * - * Copyright (c) 2014 SUSE LINUX Products GmbH - * - * 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 "qemu/osdep.h" -#include "libqtest.h" - -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void nop(void) -{ -} - -int main(int argc, char **argv) -{ - int ret; - - g_test_init(&argc, &argv, NULL); - qtest_add_func("/tpci200/nop", nop); - - qtest_start("-device tpci200"); - ret = g_test_run(); - - qtest_end(); - - return ret; -} From patchwork Thu Mar 7 17:29:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WjeNqqE6"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfRf1MmPz9s70 for ; Fri, 8 Mar 2019 05:34:19 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xqS-0005U7-2y for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:34:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrH-0003kF-5k for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrG-000069-80 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:03 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:46334) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrF-00005E-Vt for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:02 -0500 Received: by mail-wr1-x430.google.com with SMTP id i16so18390203wrs.13 for ; Thu, 07 Mar 2019 09:31:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v/S/LRbmh7uF37H5wG9u5QOYAF4PDKg5RTF0rQAsEI0=; b=WjeNqqE67yqARpTna9bbbKBlK7ynHqKLVh+n8TOfCuijLB/vaCgjZdOwbzYMZF1haf 2eMoeAGQp0UK5ojEs8JHBzDFHQxF7Md+kFYRgQuzInIyCVO34a+Pzkc0CoJGajFhc3gZ VkjFGzpytZp6Ahc9kK4IN8xInC1n7ThUPwf43Z/whGtUX95/CuxXJ/qwB0PoDWrPsJaJ Ch0wTcGKGkRxPYxT/70qegsQQ7uz/ioAVKdZwz0SRMSpwl346mtLXJC7T63nknZq+iuO 5hnKMurEMkZz7nAt9oE/hWVIasYqjmOp8aWfcdH/4+EFMTBGDTe3++hNXXi5cE4UZr5F p0aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v/S/LRbmh7uF37H5wG9u5QOYAF4PDKg5RTF0rQAsEI0=; b=GS+SRUftT9X73dyre16nEWnE+ELcar0skKqwByXy6DmPSIxF180/3seRe3qaK8inX1 G6xN0UZJxu7Nj0QjiYm1l1UZS+OFYBpJpAuYahGfujcNEVEKZKoQX8bL8mGTsRuivd6+ A5ZYa27LhOiT5edmv1N20se7/sY8X+NjLf6UFwQdGP7/hW5U6nP9djq/V5KckeH7F6vQ DEKUNsHodkJ5u+jiFwWwJ3aUG8xiVeV9Tp0css5mfsmFV8NMnY3Kjy0KhhKfsqWK2jv8 TnfSt25Nu69mAhz7ZUEaYzO7On2bRyqN+QKbh3lRmQkrX1aji0AihV+meqk2tbojvmix EwGg== X-Gm-Message-State: APjAAAUddNWxbIfp2lz3C65BcrIkfH+XEjUB968hLhyTL+8tIhEu6H1V AcFcMw8d2SOkEPNtkZXcALjkccz1 X-Google-Smtp-Source: APXvYqzTiqKNy4q+Z65Exm84IMO1ciqukm7wATKJ+e34ylT+15e3+/lAzqIGh94j7woTDbMdH2Z1BQ== X-Received: by 2002:a5d:6a8e:: with SMTP id s14mr7609506wru.31.1551979860551; Thu, 07 Mar 2019 09:31:00 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:54 +0100 Message-Id: <1551979804-6060-48-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 Subject: [Qemu-devel] [PULL 47/57] qos-test: ipoctal232 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/ipoctal232-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. This test creates a tpci200 node that produces an interface ipack consumed by the ipoctal232 device. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 5 +---- tests/ipoctal232-test.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 905a361..3eaa888 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -151,8 +151,6 @@ check-qtest-generic-y += tests/qmp-cmd-test$(EXESUF) check-qtest-generic-y += tests/device-introspect-test$(EXESUF) check-qtest-generic-y += tests/cdrom-test$(EXESUF) -check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF) - check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) @@ -160,7 +158,6 @@ check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) check-qtest-pci-$(CONFIG_NE2000_PCI) += tests/ne2000-test$(EXESUF) check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) -check-qtest-pci-$(CONFIG_IPACK) += $(check-qtest-ipack-y) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) @@ -755,6 +752,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o +qos-test-obj-y += tests/ipoctal232-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) @@ -812,7 +810,6 @@ tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o -tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o tests/qom-test$(EXESUF): tests/qom-test.o tests/test-hmp$(EXESUF): tests/test-hmp.o tests/machine-none-test$(EXESUF): tests/machine-none-test.o diff --git a/tests/ipoctal232-test.c b/tests/ipoctal232-test.c index 6849141..42d5371 100644 --- a/tests/ipoctal232-test.c +++ b/tests/ipoctal232-test.c @@ -9,23 +9,40 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" + +typedef struct QIpoctal232 QIpoctal232; + +struct QIpoctal232 { + QOSGraphObject obj; +}; /* Tests only initialization so far. TODO: Replace with functional tests */ -static void nop(void) +static void nop(void *obj, void *data, QGuestAllocator *alloc) { } -int main(int argc, char **argv) +static void *ipoctal232_create(void *pci_bus, QGuestAllocator *alloc, + void *addr) { - int ret; + QIpoctal232 *ipoctal232 = g_new0(QIpoctal232, 1); - g_test_init(&argc, &argv, NULL); - qtest_add_func("/ipoctal232/tpci200/nop", nop); + return &ipoctal232->obj; +} - qtest_start("-device tpci200,id=ipack0 -device ipoctal232,bus=ipack0.0"); - ret = g_test_run(); +static void ipoctal232_register_nodes(void) +{ + qos_node_create_driver("ipoctal232", ipoctal232_create); + qos_node_consumes("ipoctal232", "ipack", &(QOSGraphEdgeOptions) { + .extra_device_opts = "bus=ipack0.0", + }); +} - qtest_end(); +libqos_init(ipoctal232_register_nodes); - return ret; +static void register_ipoctal232_test(void) +{ + qos_add_test("nop", "ipoctal232", nop, NULL); } + +libqos_init(register_ipoctal232_test); From patchwork Thu Mar 7 17:29:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lJ9F+0XF"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdqh0b9Wz9s70 for ; Fri, 8 Mar 2019 05:06:39 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xPh-0007NI-33 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:06:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrI-0003n8-IX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrH-00007u-IE for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:04 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:50678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrH-00006Q-Av for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:03 -0500 Received: by mail-wm1-x32f.google.com with SMTP id x7so10093549wmj.0 for ; Thu, 07 Mar 2019 09:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nNnxvyXGn0US9Zwxst0ybcXXkmrc6BG7tH6gTKYJkEM=; b=lJ9F+0XFKb9H6m/tyUvtrkxN8pbNhul+23aH1u0dCV05IVGQnESnXHA0U3qoztGfe8 poNDV8cBvqHhCPV+/PZlKrvyXv95Mq8oJLQpJZa/LW/lFSG8tI1BM9sPXKgN+iFVPtCJ iyu0HmFa4i7ci3RJYDS4QTTkjHvDc2zBmUKFO2xqpc9gJySGX9p2MkP7b+/kYZ9nsgvF f359EFD7opf1dmpv5UUE/6H4WkK8NKUxx76VxAi/d5+O3GjlU2CZ+2PRDa4EokdaJ3pk dj144yYc6WoWzZEe77o3aqI8yrFcCs99AEOIc/fK8i2adm6yih8E8gBOrVS1w3/esYcY EBrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nNnxvyXGn0US9Zwxst0ybcXXkmrc6BG7tH6gTKYJkEM=; b=QwMfzpRjeh5s6CTNYmbR3Xrl59FMkpZpPQq61BKHqeciZUhv0E0mLFymM4hGy5eo/g XbdDmYOfCt1IVrKP8ksc3zoMwpP7H3bg+ZHLp3OgXP2962noaj+Z8AxRikxkLi3iodCg XUihB7AMvK0S2qkC9c7/NgyGZpNBRrKywAQEaYi39rdynOionSTJgb0NZxyjfX6LRiWN HVrNcBhfLbuySVyhR8Ls4v17CziwgXIGHDoVbLTuSaz/6uNe/UObamD5pcNV0Nv94X7R rIjMtSdWRakTq0+tg314MvHuvpG0j71A65rfF6aGzzhVJq8bkcBMuP0IqnJoeHQAJSjF 5gLQ== X-Gm-Message-State: APjAAAUXcDwcRluV52KGqJCf1+Ye2tkEpRryy+ocWEu11gCWVCJzv1Oj AZO0nR0ZM07RiCK1BKia20PnC5pp X-Google-Smtp-Source: APXvYqynqfCSk51bJXdRlFcXjcvP35skffu1Q/H4nP0f6YUXOs6ZYEJqwIO8Hm0edry8dZX5hNEW+g== X-Received: by 2002:a1c:2947:: with SMTP id p68mr6475151wmp.104.1551979861922; Thu, 07 Mar 2019 09:31:01 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:55 +0100 Message-Id: <1551979804-6060-49-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32f Subject: [Qemu-devel] [PULL 48/57] qos-test: ne2k_pci test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/ne2000-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. The actual device consumed by the test is ne2k_pci. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/ne2000-test.c | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 3eaa888..0d06490 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,7 +155,6 @@ check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) -check-qtest-pci-$(CONFIG_NE2000_PCI) += tests/ne2000-test$(EXESUF) check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) @@ -753,6 +752,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/ipoctal232-test.o +qos-test-obj-y += tests/ne2000-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) @@ -805,7 +805,6 @@ tests/pcnet-test$(EXESUF): tests/pcnet-test.o tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o tests/eepro100-test$(EXESUF): tests/eepro100-test.o tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o -tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o diff --git a/tests/ne2000-test.c b/tests/ne2000-test.c index b7cf3dd..097c2ee 100644 --- a/tests/ne2000-test.c +++ b/tests/ne2000-test.c @@ -9,23 +9,49 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) +typedef struct QNe2k_pci QNe2k_pci; + +struct QNe2k_pci { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *ne2k_pci_get_driver(void *obj, const char *interface) { + QNe2k_pci *ne2k_pci = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &ne2k_pci->dev; + } + + fprintf(stderr, "%s not present in ne2k_pci\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *ne2k_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QNe2k_pci *ne2k_pci = g_new0(QNe2k_pci, 1); + QPCIBus *bus = pci_bus; - g_test_init(&argc, &argv, NULL); - qtest_add_func("/ne2000/pci/nop", pci_nop); + qpci_device_init(&ne2k_pci->dev, bus, addr); + ne2k_pci->obj.get_driver = ne2k_pci_get_driver; - qtest_start("-device ne2k_pci"); - ret = g_test_run(); + return &ne2k_pci->obj; +} - qtest_end(); +static void ne2000_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return ret; + qos_node_create_driver("ne2k_pci", ne2k_pci_create); + qos_node_consumes("ne2k_pci", "pci-bus", &opts); + qos_node_produces("ne2k_pci", "pci-device"); } + +libqos_init(ne2000_register_nodes); From patchwork Thu Mar 7 17:29:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ns4/MrYm"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Fdv21qfcz9s7T for ; Fri, 8 Mar 2019 05:09:34 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xSW-0001JG-4W for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:09:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrJ-0003oU-Qb for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrI-00008y-P3 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:05 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35321) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrI-00008R-EX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:04 -0500 Received: by mail-wr1-x444.google.com with SMTP id t18so18425811wrx.2 for ; Thu, 07 Mar 2019 09:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ksqwWLcmi6STx+NL/mUX2ilS3SHd59BXFkubnB4B4kM=; b=Ns4/MrYmITdGzV+qwv+goXAVRaBCmFNbtr86ZbEW+0bDg0zf0c1Vul7TZbEwT29rTH xseCqhOdnILh1Sonf/vfkBuxWLnPppnO+JOhmwZjy17qwW2R+GfnIxrSIWkjJN4sUqaC GwE/9W+fCl/cAyEAEDROq6uj0PIPB7hTF7k+rxvdzjm6kpdRD+o8E1Kk2lHIIGUfxqE5 pTBs7R15EDgIKnGJnzpG1B7jcrszHhlATHyGyeyOivWPTl6SyBit5IJUzKP1b8+1h2hZ xj7KDVJiV6JL1oAr1tjQEMGorQKa2WEa8NbsvlYhWDvGlorRbg8gKcjNe9Lec6dg65CI abNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ksqwWLcmi6STx+NL/mUX2ilS3SHd59BXFkubnB4B4kM=; b=n8fzJjonqG46kHx/c9VVIjNAyEboCoJ+kIiQ2wRJaSooOXH5j/4EJ1H9pV3k63w2WG rz4ueGEuIS7Fltfd9fFeAm9Dw6xtngYDKc8xyP03Gnv0kRk+cmY0GnDlexRVWyoqCqBF 9NRc0ZoYh7qWd8gYj5ZEW3RGCm+1qQRXmNqb4Vc0bfZxPG/14gf0R+W2C7HmhGLpRHsO L3EdB6oAA23FaJI88jE6DNTxV7NLWgk3vieO8aDlELrmSfqPUCngCkux2ZhlI/76n20M MgpQ7D8MEKWO0H1TjIHVLsVU5nmFMO8TtzFzm6ybBnWq+W4v9u/F1PQsbcJc608Z9/hO 5hwA== X-Gm-Message-State: APjAAAXcpyEPrAFlkiQbXdBCvSfyalMu1UfgZWbPpbzP+pW9o3sOBMet jxREQUbjUOcv8nyxVW585ngCEakv X-Google-Smtp-Source: APXvYqzWLmvo/skejfH9fB6nBa87kl3brkm8EEYAr0KPrGb/p5/EiKh+RmrhAU2aRzuFh8UI8P5G9g== X-Received: by 2002:adf:ed11:: with SMTP id a17mr7734551wro.283.1551979863024; Thu, 07 Mar 2019 09:31:03 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:02 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:56 +0100 Message-Id: <1551979804-6060-50-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PULL 49/57] qos-test: nvme test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/nvme-test to a driver node; the code to discover the PCI device is replaced by generic qgraph code, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/nvme-test.c | 78 +++++++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 0d06490..46f8c34 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,7 +155,6 @@ check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) -check-qtest-pci-$(CONFIG_NVME_PCI) += tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) @@ -753,6 +752,7 @@ qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/ipoctal232-test.o qos-test-obj-y += tests/ne2000-test.o +qos-test-obj-y += tests/nvme-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) @@ -814,7 +814,6 @@ tests/test-hmp$(EXESUF): tests/test-hmp.o tests/machine-none-test$(EXESUF): tests/machine-none-test.o tests/device-plug-test$(EXESUF): tests/device-plug-test.o tests/drive_del-test$(EXESUF): tests/drive_del-test.o -tests/nvme-test$(EXESUF): tests/nvme-test.o $(libqos-pc-obj-y) tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o tests/es1370-test$(EXESUF): tests/es1370-test.o diff --git a/tests/nvme-test.c b/tests/nvme-test.c index 2700ba8..b48d3a2 100644 --- a/tests/nvme-test.c +++ b/tests/nvme-test.c @@ -10,49 +10,47 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "libqtest.h" -#include "libqos/libqos-pc.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -static QOSState *qnvme_start(const char *extra_opts) +typedef struct QNvme QNvme; + +struct QNvme { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *nvme_get_driver(void *obj, const char *interface) { - QOSState *qs; - const char *arch = qtest_get_arch(); - const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw " - "-device nvme,addr=0x4.0,serial=foo,drive=drv0 %s"; - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qs = qtest_pc_boot(cmd, extra_opts ? : ""); - global_qtest = qs->qts; - return qs; + QNvme *nvme = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &nvme->dev; } - g_printerr("nvme tests are only available on x86\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "%s not present in nvme\n", interface); + g_assert_not_reached(); } -static void qnvme_stop(QOSState *qs) +static void *nvme_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - qtest_shutdown(qs); -} + QNvme *nvme = g_new0(QNvme, 1); + QPCIBus *bus = pci_bus; -static void nop(void) -{ - QOSState *qs; + qpci_device_init(&nvme->dev, bus, addr); + nvme->obj.get_driver = nvme_get_driver; - qs = qnvme_start(NULL); - qnvme_stop(qs); + return &nvme->obj; } -static void nvmetest_cmb_test(void) +/* This used to cause a NULL pointer dereference. */ +static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *alloc) { const int cmb_bar_size = 2 * MiB; - QOSState *qs; - QPCIDevice *pdev; + QNvme *nvme = obj; + QPCIDevice *pdev = &nvme->dev; QPCIBar bar; - qs = qnvme_start("-global nvme.cmb_size_mb=2"); - pdev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0)); - g_assert(pdev != NULL); - qpci_device_enable(pdev); bar = qpci_iomap(pdev, 2, NULL); @@ -65,16 +63,24 @@ static void nvmetest_cmb_test(void) g_assert_cmpint(qpci_io_readb(pdev, bar, cmb_bar_size - 1), ==, 0x11); g_assert_cmpint(qpci_io_readw(pdev, bar, cmb_bar_size - 1), !=, 0x2211); g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211); - g_free(pdev); - - qnvme_stop(qs); } -int main(int argc, char **argv) +static void nvme_register_nodes(void) { - g_test_init(&argc, &argv, NULL); - qtest_add_func("/nvme/nop", nop); - qtest_add_func("/nvme/cmb_test", nvmetest_cmb_test); + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0,drive=drv0,serial=foo", + .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw", + }; + + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return g_test_run(); + qos_node_create_driver("nvme", nvme_create); + qos_node_consumes("nvme", "pci-bus", &opts); + qos_node_produces("nvme", "pci-device"); + + qos_add_test("oob-cmb-access", "nvme", nvmetest_oob_cmb_test, &(QOSGraphTestOptions) { + .edge.extra_device_opts = "cmb_size_mb=2" + }); } + +libqos_init(nvme_register_nodes); From patchwork Thu Mar 7 17:29:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="twkVcb0F"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfMF1Hg7z9s9h for ; Fri, 8 Mar 2019 05:30:33 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xmo-0002T5-R5 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:30:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrL-0003pY-7C for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrK-00009w-Aa for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:07 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:40977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrK-00009O-1N for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:06 -0500 Received: by mail-wr1-x434.google.com with SMTP id n2so18409129wrw.8 for ; Thu, 07 Mar 2019 09:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=f6iufZumE/RPOI0L+CVS1J4JUVjjzDte2gwZqJFvB0E=; b=twkVcb0FxxjgkBfd42G5aCPPYwTqlCf3dvSsJIo7ZhpInCj0jzUjIps1OAHkOd4Tm/ EfCKvisYYe5/KVgvdBUpRGkNbYuPL7H0QFhmGXJ0kJqT4m0KAyGOC6GlmNlHXfhB/u+Z kxCZvvDSkvmWHI9inIvwi31SxKzsvnkoRMw43QKyic8+rOBWUJmNM8K5adnol3s+dIDU uFIZq1kBa7dID1hT9leAEntE42SffZMzrgdO/arpN7sEH7Wf4I86DpmQks4iZ72/kGRx w5yOWbx8OUyISqIhDmfIWP8cvExLnLHjotPMR3GCTHUSgWKVgSCm5FIOk6qn4Y3DBAqg N4Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=f6iufZumE/RPOI0L+CVS1J4JUVjjzDte2gwZqJFvB0E=; b=obzmEa2sE6ONtx7/K17HxCD9f4D91ceclPcNpah1BzWcTsTfCHAKNXVd6Mk6+km9ns KvVCrbvjk8sYA1uNjhKplfm0tq95qm/Ximy7XK0eoknbuuRkMUqxWSujBexkpA/x8ISz ZN4ravmrhsT5F4DpUAJgC7x3fafoYHVWcXFAHTfbQlowdtY83dTazTSv/s9md+RMS1kI qkdP+qqQ6cehnlsl1oX4A7jjXaN/scqPIDNF/LQbudWX05c9yfI3E/wfm31nL1AJQzzy TcQtYJlxFbBFz85iGyg9kke5aMTzuxJ1ntP+xDIX0mSjxLldz0CkcPXvmrAFNQ3t+u4U Sx1A== X-Gm-Message-State: APjAAAVE4/psjJwNN8RCJ6C6K8o+6gc3A+4h66gmu9jTXAI6iUY8pxgh E8gOIWN+Y+E2knftc7mBvhs0A2TA X-Google-Smtp-Source: APXvYqxopNxDGWwHfwIX0yaXcxTvJCKN7+w1WMEx5QuLq5xTAx9k3sTfqsit1zxnISJGNzxia8MFGQ== X-Received: by 2002:adf:ce91:: with SMTP id r17mr7367444wrn.80.1551979864575; Thu, 07 Mar 2019 09:31:04 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:57 +0100 Message-Id: <1551979804-6060-51-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 Subject: [Qemu-devel] [PULL 50/57] qos-test: pcnet test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/pcnet-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/pcnet-test.c | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 46f8c34..0442be8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -153,7 +153,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) -check-qtest-pci-$(CONFIG_PCNET_PCI) += tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) @@ -754,6 +753,7 @@ qos-test-obj-y += tests/ipoctal232-test.o qos-test-obj-y += tests/ne2000-test.o qos-test-obj-y += tests/nvme-test.o qos-test-obj-y += tests/pci-test.o +qos-test-obj-y += tests/pcnet-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) qos-test-obj-y += tests/virtio-test.o @@ -801,7 +801,6 @@ tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) tests/e1000-test$(EXESUF): tests/e1000-test.o tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y) -tests/pcnet-test$(EXESUF): tests/pcnet-test.o tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o tests/eepro100-test$(EXESUF): tests/eepro100-test.o tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o diff --git a/tests/pcnet-test.c b/tests/pcnet-test.c index efb1ef4..484448c 100644 --- a/tests/pcnet-test.c +++ b/tests/pcnet-test.c @@ -9,23 +9,49 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) +typedef struct QPCNet QPCNet; + +struct QPCNet { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *pcnet_get_driver(void *obj, const char *interface) { + QPCNet *pcnet = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &pcnet->dev; + } + + fprintf(stderr, "%s not present in pcnet\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *pcnet_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QPCNet *pcnet = g_new0(QPCNet, 1); + QPCIBus *bus = pci_bus; - g_test_init(&argc, &argv, NULL); - qtest_add_func("/pcnet/pci/nop", pci_nop); + qpci_device_init(&pcnet->dev, bus, addr); + pcnet->obj.get_driver = pcnet_get_driver; - qtest_start("-device pcnet"); - ret = g_test_run(); + return &pcnet->obj; +} - qtest_end(); +static void pcnet_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return ret; + qos_node_create_driver("pcnet", pcnet_create); + qos_node_consumes("pcnet", "pci-bus", &opts); + qos_node_produces("pcnet", "pci-device"); } + +libqos_init(pcnet_register_nodes); From patchwork Thu Mar 7 17:29:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OiKcqR0R"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfZM2nztz9s70 for ; Fri, 8 Mar 2019 05:40:11 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xw9-000254-AR for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:40:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrP-0003tb-Pf for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrL-0000AM-1y for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:11 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:38204) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrK-00009s-Qb for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:06 -0500 Received: by mail-wr1-x435.google.com with SMTP id g12so18408222wrm.5 for ; Thu, 07 Mar 2019 09:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6wsn5TmlzOb8al0LVcwLC8VFpkAqZc3G03KfRJQLCJI=; b=OiKcqR0Rof4XxzhMmzvsO/xAzBc7X+mOiXOnWyJLwWEuddJpR9simN2Le4lrFiIjc6 mswt4bLSuQZBt9rdIiQb3c+UO+NRSG6KL8ZPwi90SDjKsqYhyN8+BY0nidfCjknTQfNh zIVfO66Y2cc9ljjq2s9fqWrm/Uf1Kop8XMiK6hvvtCu8MenNxR8G/UiU8krdNbaMetj6 YOoX8t+mPUABz+JCHpZ2gJokc+5l/SR8ca76blMSosJNlTnDx+VjktM6aMNKpNx9OkOV bLW5t57IVrBveZk3wqwkrLMz+zNxP3fR+80g0b3p5d9t03NyOpUbFqjQBe4CefYqj5sa aqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6wsn5TmlzOb8al0LVcwLC8VFpkAqZc3G03KfRJQLCJI=; b=bv+0MYOkvHCVKnA1WtEnMWW670gk1Ogfq6+BtsIWPX3ugoeBWAjhkxGyblEHDqU/D5 zHNJaaJPgmHCXh4kfS1ETxSVQnJZHCEjWaP89h98S+3hFn//hkvvGJ1vA9C8hqmRzlrB LE3h5/qF+jDrdrm1Ub2SWIlkI676sPYec8Zp+yrkEs17Rx1pmBEltDD4wcjrsJY+ZdbN ZVXF1zTgFMdXSGnyPZVa9Qkv3Lwa7BWO/57MYc1cd9WZclAYVv98tdMjBnE6Ql2mjdN+ B1OqSa1no6zs4whsz2PacjfwS6MZbMC3nYUJljMp0eCgttGQwoiv049Q5nGINix2jyH0 ARug== X-Gm-Message-State: APjAAAWPclwuGdlIrhjyngdaVlJziKVfVfMGk9hR1ZOI7vU8R9U1+JCJ KXnsZhDYi/PjZ5NvoQZz36aEG+3D X-Google-Smtp-Source: APXvYqznALAL/MKBhL1Uwbyak3Lclj0IyoKfZTm5LaiBQ3AY9gdd4Xlpp7hlei5FeThJ+6Z+zhqhsA== X-Received: by 2002:a5d:4412:: with SMTP id z18mr7616798wrq.111.1551979865474; Thu, 07 Mar 2019 09:31:05 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:58 +0100 Message-Id: <1551979804-6060-52-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::435 Subject: [Qemu-devel] [PULL 51/57] qos-test: spapr-phb test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/spapr-phb-test to a qgraph test node, spapr-phb-test. This test adds another spapr-pci-host-bridge device in the ppc64/pseries machine Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/spapr-phb-test.c | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 0442be8..f257b50 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -235,7 +235,6 @@ check-qtest-ppc-y += tests/boot-serial-test$(EXESUF) check-qtest-ppc-$(CONFIG_M48T59) += tests/m48t59-test$(EXESUF) check-qtest-ppc64-y += $(check-qtest-ppc-y) -check-qtest-ppc64-$(CONFIG_PSERIES) += tests/spapr-phb-test$(EXESUF) check-qtest-ppc64-$(CONFIG_PSERIES) += tests/device-plug-test$(EXESUF) check-qtest-ppc64-$(CONFIG_POWERNV) += tests/pnv-xscom-test$(EXESUF) check-qtest-ppc64-y += tests/migration-test$(EXESUF) @@ -755,6 +754,7 @@ qos-test-obj-y += tests/nvme-test.o qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/pcnet-test.o qos-test-obj-y += tests/sdhci-test.o +qos-test-obj-y += tests/spapr-phb-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o @@ -777,7 +777,6 @@ tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/hexloader-test$(EXESUF): tests/hexloader-test.o tests/endianness-test$(EXESUF): tests/endianness-test.o -tests/spapr-phb-test$(EXESUF): tests/spapr-phb-test.o $(libqos-obj-y) tests/prom-env-test$(EXESUF): tests/prom-env-test.o $(libqos-obj-y) tests/rtas-test$(EXESUF): tests/rtas-test.o $(libqos-spapr-obj-y) tests/fdc-test$(EXESUF): tests/fdc-test.o diff --git a/tests/spapr-phb-test.c b/tests/spapr-phb-test.c index d3522ea..39b5766 100644 --- a/tests/spapr-phb-test.c +++ b/tests/spapr-phb-test.c @@ -7,29 +7,25 @@ * 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 "qemu/osdep.h" +#include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" -#define TYPE_SPAPR_PCI_HOST_BRIDGE "spapr-pci-host-bridge" - -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void test_phb_device(void) +/* Tests only initialization so far. TODO: Replace with functional tests, + * for example by producing pci-bus. + */ +static void test_phb_device(void *obj, void *data, QGuestAllocator *alloc) { } -int main(int argc, char **argv) +static void register_phb_test(void) { - int ret; - - g_test_init(&argc, &argv, NULL); - qtest_add_func("/spapr-phb/device", test_phb_device); - - qtest_start("-device " TYPE_SPAPR_PCI_HOST_BRIDGE ",index=30"); - - ret = g_test_run(); - - qtest_end(); - - return ret; + qos_add_test("spapr-phb-test", "ppc64/pseries", + test_phb_device, &(QOSGraphTestOptions) { + .edge.before_cmd_line = "-device spapr-pci-host-bridge" + ",index=30", + }); } + +libqos_init(register_phb_test); From patchwork Thu Mar 7 17:29:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="X8HWeOmE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfWF2TjTz9s70 for ; Fri, 8 Mar 2019 05:37:27 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xtT-0008AU-2w for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:37:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrN-0003r6-Go for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrM-0000B7-GB for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:09 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:40971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrM-0000Ah-8C for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:08 -0500 Received: by mail-wr1-x42d.google.com with SMTP id n2so18409293wrw.8 for ; Thu, 07 Mar 2019 09:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DGXxvXU0NK3O86DvF8+UlN4hEwOGAaNFtVE522QlH2s=; b=X8HWeOmEDcGgiuweCg4s4nKQ3Wf7kD/Xxx/sRm1+SuVsJVk7hFbqoXBwa2h+F0OUWJ Au1D9Xh1qLQDNZJ9kuB7kjdiH2BvDavjV6uB6XxW0RR4qQGikN0l6dP9st2yHa9CCI+v GLwQS4ury6XxffFewN4wrTC+Qgel5LZfvOVWtPmirDNDB/Xp499bZB21L0lfBuZBrIeo 0bCcVLUOMwI9906NszLL2BjyrvbwdeJ3gmkjdHCP0V5SDr3tDU4WQurgIn06pfxVReIh PCPGe5Sh5lJs0fOWaLpoE/TXkNe5CfszImQf8TfFjVE4bOx4oo6SBeUDwNmichfScrC3 CLNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DGXxvXU0NK3O86DvF8+UlN4hEwOGAaNFtVE522QlH2s=; b=TfDnbpOd7Le4pHyGJCW4tEqg3Ir+o3fCto47eYfGpaHy8R3sMA7z4ldF+QElb1A3gj UE7Jqw86fBnvkR06HlpSe6jJu3Ygim+5RpbkxsHeY+6MI4E9FEYHBAt1yTj7zBbw2PIF hyf0YowO+n5s8/5YkFgM6eage/LnRWC+KklABQXlorLV4do0cEBINEoHHSmbhtBXeC4z AdZGCjP8GpauxsDNcyaEYAcbAeVN80a1Be86w+jt/zzksLOrgxsFpBk/iuM70MUsw/ny kmVgxpdKV8GGMt6CktJ3yU0Gryo8QIU7X7LLD9vE6+m9ZxNNtf8HiXTuiY/20yeH05Sx XeqQ== X-Gm-Message-State: APjAAAXI9tqUywy/Wjvo6ede/ic33oIRiNoK5vFvUVCJ8TbL12g64Ypx QgBkKnwLxAkI18GktQnh1Ts64pdE X-Google-Smtp-Source: APXvYqxPsEiAZoLgGfush488pCpXTOofckgCw8vJ31Hl32b0AVczdsaYCXj+zgEt2va0FmVOcdWODg== X-Received: by 2002:adf:ef05:: with SMTP id e5mr7955627wro.153.1551979867074; Thu, 07 Mar 2019 09:31:07 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:59 +0100 Message-Id: <1551979804-6060-53-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42d Subject: [Qemu-devel] [PULL 52/57] qos-test: usb-hcd-ohci test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/usb-hcd-ohci-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 4 +--- tests/usb-hcd-ohci-test.c | 54 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index f257b50..8ba8e27 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -184,7 +184,6 @@ check-qtest-i386-$(CONFIG_VMXNET3_PCI) += tests/vmxnet3-test$(EXESUF) check-qtest-i386-$(CONFIG_PVPANIC) += tests/pvpanic-test$(EXESUF) check-qtest-i386-$(CONFIG_I82801B11) += tests/i82801b11-test$(EXESUF) check-qtest-i386-$(CONFIG_IOH3420) += tests/ioh3420-test$(EXESUF) -check-qtest-i386-$(CONFIG_USB_OHCI) += tests/usb-hcd-ohci-test$(EXESUF) check-qtest-i386-$(CONFIG_USB_UHCI) += tests/usb-hcd-uhci-test$(EXESUF) ifeq ($(CONFIG_USB_ECHI)$(CONFIG_USB_UHCI),yy) check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF) @@ -241,7 +240,6 @@ check-qtest-ppc64-y += tests/migration-test$(EXESUF) check-qtest-ppc64-y += tests/test-announce-self$(EXESUF) check-qtest-ppc64-$(CONFIG_PSERIES) += tests/rtas-test$(EXESUF) check-qtest-ppc64-$(CONFIG_SLIRP) += tests/pxe-test$(EXESUF) -check-qtest-ppc64-$(CONFIG_USB_OHCI) += tests/usb-hcd-ohci-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_UHCI) += tests/usb-hcd-uhci-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_XHCI_NEC) += tests/usb-hcd-xhci-test$(EXESUF) check-qtest-ppc64-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF) @@ -755,6 +753,7 @@ qos-test-obj-y += tests/pci-test.o qos-test-obj-y += tests/pcnet-test.o qos-test-obj-y += tests/sdhci-test.o qos-test-obj-y += tests/spapr-phb-test.o +qos-test-obj-y += tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y) qos-test-obj-$(CONFIG_VHOST_NET_USER) += tests/vhost-user-test.o $(chardev-obj-y) $(test-io-obj-y) qos-test-obj-y += tests/virtio-test.o qos-test-obj-$(CONFIG_VIRTFS) += tests/virtio-9p-test.o @@ -817,7 +816,6 @@ tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o tests/es1370-test$(EXESUF): tests/es1370-test.o tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o -tests/usb-hcd-ohci-test$(EXESUF): tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y) tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y) 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) diff --git a/tests/usb-hcd-ohci-test.c b/tests/usb-hcd-ohci-test.c index 48ddbfd..98af02e 100644 --- a/tests/usb-hcd-ohci-test.c +++ b/tests/usb-hcd-ohci-test.c @@ -10,30 +10,58 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "libqos/usb.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" +typedef struct QOHCI_PCI QOHCI_PCI; -static void test_ohci_init(void) -{ +struct QOHCI_PCI { + QOSGraphObject obj; + QPCIDevice dev; +}; +static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc) +{ + usb_test_hotplug("ohci", "1", NULL); } -static void test_ohci_hotplug(void) +static void *ohci_pci_get_driver(void *obj, const char *interface) { - usb_test_hotplug("ohci", "1", NULL); + QOHCI_PCI *ohci_pci = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &ohci_pci->dev; + } + + fprintf(stderr, "%s not present in pci-ohci\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *ohci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QOHCI_PCI *ohci_pci = g_new0(QOHCI_PCI, 1); + ohci_pci->obj.get_driver = ohci_pci_get_driver; - g_test_init(&argc, &argv, NULL); + return &ohci_pci->obj; +} + +static void ohci_pci_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0,id=ohci", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - qtest_add_func("/ohci/pci/init", test_ohci_init); - qtest_add_func("/ohci/pci/hotplug", test_ohci_hotplug); + qos_node_create_driver("pci-ohci", ohci_pci_create); + qos_node_consumes("pci-ohci", "pci-bus", &opts); + qos_node_produces("pci-ohci", "pci-device"); +} - qtest_start("-device pci-ohci,id=ohci"); - ret = g_test_run(); - qtest_end(); +libqos_init(ohci_pci_register_nodes); - return ret; +static void register_ohci_pci_test(void) +{ + qos_add_test("ohci_pci-test-hotplug", "pci-ohci", test_ohci_hotplug, NULL); } + +libqos_init(register_ohci_pci_test); From patchwork Thu Mar 7 17:30:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PkMwnxVa"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FdyH4Nt2z9s70 for ; Fri, 8 Mar 2019 05:12:23 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xVE-0003tm-SU for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:12:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrP-0003t9-7z for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrO-0000CA-8G for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:11 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:46337) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrO-0000BN-0n for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:10 -0500 Received: by mail-wr1-x432.google.com with SMTP id i16so18390732wrs.13 for ; Thu, 07 Mar 2019 09:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=u0HTcJnAPuu2RBErVhE0oIR+WQ0hlSpjlb8FtAPrNO8=; b=PkMwnxVaKqQPTTbWtr34hwsSNQPw8mvnvOsbpmM5+/NW8QFfJNxe4wDtoA9fsVOuMu 493g0cL2JT67yfwsSbc/7p/f8qrZQ4cybK2y8Rfw/h+Xo/owlSCJpRw9pog4ujk7ClhB Xf4hEuFP9CPt/bUAWRWsvSa6dKJft8DmPBsJMpl3j9oBy5PkbqVWTtJOBvxkyTFb+xlj lxL/TH+1vgbFCvUm+9l/c9SpCsGuPgjnnnppY30fUAOLdkVbC9j5Tmo4JYg93qfSfr1N SGoFBe3XlIvoJJxyW2n1hrU4ABu5XdtgWa16NL+h4D8Jb5mecgw8g0GrdWJmLRBCYBOw qwuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=u0HTcJnAPuu2RBErVhE0oIR+WQ0hlSpjlb8FtAPrNO8=; b=mtY96HvfCQ+vo++EcU8I8QKvyZ4a9E1u1vzwx9Tk2nmm447OIjERLAc1Tq6mCCxi4t 6LHJ4ClOQK5gk4ThqxRdcrTNVXHvXL3sDsELtTCTJPawsQA0JVFN2NFJQshYJOlPYIUa HAxlDCV2AlRQchJrPv/M9E+ma/p2WMzcAgxIi8yPj10sbmubXDlQV35kfBE3C9iiEizZ rM44c37ohvbuhD8lmYmHFmbBW2ZmvGN1G2IqAxXSQ6ZG9DumG0kfy9TsnbZm9iPOTWs9 f9EaDl4dJ1UIGEpmT2ZdSvJeR8wNXgRq5+gvlRXopPOltrYMcLNm7A7IeMughJV71dZl Oxyw== X-Gm-Message-State: APjAAAXeD9IInB9Gt/KtEb9IYBQ66GsuvKjwJoRFzcYRwA0CHgPgcTV9 vzQHHrqgIJoCvjgWUOGg7vuuASrl X-Google-Smtp-Source: APXvYqwFGEWh+tGsajaokSnyBS5McuGdymjsf/dao1RlhNiDmmDQuwpuwA+11j4GS2NCcCVXfXjYRA== X-Received: by 2002:a5d:558c:: with SMTP id i12mr7578104wrv.19.1551979868267; Thu, 07 Mar 2019 09:31:08 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:30:00 +0100 Message-Id: <1551979804-6060-54-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PULL 53/57] qos-test: vmxnet3 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/vmxnet3-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/vmxnet3-test.c | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 8ba8e27..5be98d7 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -180,7 +180,6 @@ check-qtest-i386-y += tests/drive_del-test$(EXESUF) check-qtest-i386-$(CONFIG_WDT_IB700) += tests/wdt_ib700-test$(EXESUF) check-qtest-i386-y += tests/tco-test$(EXESUF) check-qtest-i386-y += $(check-qtest-pci-y) -check-qtest-i386-$(CONFIG_VMXNET3_PCI) += tests/vmxnet3-test$(EXESUF) check-qtest-i386-$(CONFIG_PVPANIC) += tests/pvpanic-test$(EXESUF) check-qtest-i386-$(CONFIG_I82801B11) += tests/i82801b11-test$(EXESUF) check-qtest-i386-$(CONFIG_IOH3420) += tests/ioh3420-test$(EXESUF) @@ -762,6 +761,7 @@ qos-test-obj-y += tests/virtio-net-test.o qos-test-obj-y += tests/virtio-rng-test.o qos-test-obj-y += tests/virtio-scsi-test.o qos-test-obj-y += tests/virtio-serial-test.o +qos-test-obj-y += tests/vmxnet3-test.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) @@ -801,7 +801,6 @@ tests/e1000-test$(EXESUF): tests/e1000-test.o tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y) tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o tests/eepro100-test$(EXESUF): tests/eepro100-test.o -tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o diff --git a/tests/vmxnet3-test.c b/tests/vmxnet3-test.c index 159c0ad..35cdea9 100644 --- a/tests/vmxnet3-test.c +++ b/tests/vmxnet3-test.c @@ -9,23 +9,49 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void nop(void) +typedef struct QVmxnet3 QVmxnet3; + +struct QVmxnet3 { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *vmxnet3_get_driver(void *obj, const char *interface) { + QVmxnet3 *vmxnet3 = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &vmxnet3->dev; + } + + fprintf(stderr, "%s not present in vmxnet3\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *vmxnet3_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QVmxnet3 *vmxnet3 = g_new0(QVmxnet3, 1); + QPCIBus *bus = pci_bus; - g_test_init(&argc, &argv, NULL); - qtest_add_func("/vmxnet3/nop", nop); + qpci_device_init(&vmxnet3->dev, bus, addr); + vmxnet3->obj.get_driver = vmxnet3_get_driver; - qtest_start("-device vmxnet3"); - ret = g_test_run(); + return &vmxnet3->obj; +} - qtest_end(); +static void vmxnet3_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return ret; + qos_node_create_driver("vmxnet3", vmxnet3_create); + qos_node_consumes("vmxnet3", "pci-bus", &opts); + qos_node_produces("vmxnet3", "pci-device"); } + +libqos_init(vmxnet3_register_nodes); From patchwork Thu Mar 7 17:30:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LThQrrVT"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44FfR11zGzz9s70 for ; Fri, 8 Mar 2019 05:33:48 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xpy-000583-FH for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:33:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrP-0003tR-Jh for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrO-0000Cf-OR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:11 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:37351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrO-0000Bx-GK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:10 -0500 Received: by mail-wr1-x431.google.com with SMTP id w6so18402177wrs.4 for ; Thu, 07 Mar 2019 09:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZHhwnRHJEsoG4vIZAnHBm3h4uUH8V2/QXeg39Cfj7T0=; b=LThQrrVTs00urGzPiCb+IqzWKrpRuPuHN3mf+VT0M60oVhAA4lOLEaBZnodiTsD5Jx RR1b8/lBR9Z+APAgHvCZzajlnqqlwDK2vYiMZ1aek8mo2NaCkUiOq+VkUw0RSJwUFQXo Zfm2o3LQRE4bBy6Jhrbrrd49T0CZc69CEm2qfWtbQ/7iwMrtx0q3qxhAhu6sf67L39yD lzJbeSx5JychO1BzQrZaBQwO0U/UqvfQYvcYHX25HmV5Hqi95Pdj7fxJMvGMoOVMcJZy BaWgYOm4ZS2JIjA7pbQ1R8lul3GnWGT1cHE6FMOuPyaINPWVRyFLID8yiM0iiFV0jmLn KIgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZHhwnRHJEsoG4vIZAnHBm3h4uUH8V2/QXeg39Cfj7T0=; b=Zo5iiNM7cgDgzytr1LwlWFpJs0PBwgKqbT6mmLmA4g0d9PiRq+JR26+qk7QlWFw2ai gEn0NlhBrtp5zM4pDdfUnVNiV4LDDTMWnRshM1oNtVySW+cQECr8wjAHbX3SNhzr0Ma2 uaNnhEnkFShnCzaMJP5YpmgIvPp1Iw8Z7J6yB8qNW+toBKCAwECe0IJyDYzM0sl9fiiU 8Vom+8ANMmb3BA6vwtZwuYsJUlGFFfFbVxRo11J+oY+CCDjPCZjuwBQn167UwF4ja2Tq wfNya8Wa40Z5falO2AF/8TE3FbiAXSdmsAqDhi+jiCayjy6kvrZ9JDDV7Hh0ucHCrIW6 ZitA== X-Gm-Message-State: APjAAAX49mS/6d6ieSj8yEhR/hhvGtzeqGps71zbl5NggBDz3HxT0oc5 42rPaxxDlv9MIm9LyLd99mVcIpTb X-Google-Smtp-Source: APXvYqw2/Up2P8QBv79yAVLY5OA5UaFQcNwTTRausqYScQFo981Q9CxmxSqT9H1HGsKGCRUZ0/zLMg== X-Received: by 2002:adf:d0c9:: with SMTP id z9mr7646414wrh.132.1551979869213; Thu, 07 Mar 2019 09:31:09 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:30:01 +0100 Message-Id: <1551979804-6060-55-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 Subject: [Qemu-devel] [PULL 54/57] qos-test: es1370 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/es1370-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/es1370-test.c | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 5be98d7..4a387b6 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -154,7 +154,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) -check-qtest-pci-$(CONFIG_ES1370) += tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) @@ -745,6 +744,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o +qos-test-obj-y += tests/es1370-test.o qos-test-obj-y += tests/ipoctal232-test.o qos-test-obj-y += tests/ne2000-test.o qos-test-obj-y += tests/nvme-test.o @@ -812,7 +812,6 @@ tests/device-plug-test$(EXESUF): tests/device-plug-test.o tests/drive_del-test$(EXESUF): tests/drive_del-test.o tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o -tests/es1370-test$(EXESUF): tests/es1370-test.o tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y) diff --git a/tests/es1370-test.c b/tests/es1370-test.c index 199fe19..d845cd0 100644 --- a/tests/es1370-test.c +++ b/tests/es1370-test.c @@ -9,23 +9,49 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void nop(void) +typedef struct QES1370 QES1370; + +struct QES1370 { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *es1370_get_driver(void *obj, const char *interface) { + QES1370 *es1370 = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &es1370->dev; + } + + fprintf(stderr, "%s not present in e1000e\n", interface); + g_assert_not_reached(); } -int main(int argc, char **argv) +static void *es1370_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - int ret; + QES1370 *es1370 = g_new0(QES1370, 1); + QPCIBus *bus = pci_bus; - g_test_init(&argc, &argv, NULL); - qtest_add_func("/es1370/nop", nop); + qpci_device_init(&es1370->dev, bus, addr); + es1370->obj.get_driver = es1370_get_driver; - qtest_start("-device ES1370"); - ret = g_test_run(); + return &es1370->obj; +} - qtest_end(); +static void es1370_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return ret; + qos_node_create_driver("ES1370", es1370_create); + qos_node_consumes("ES1370", "pci-bus", &opts); + qos_node_produces("ES1370", "pci-device"); } + +libqos_init(es1370_register_nodes); From patchwork Thu Mar 7 17:30:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RRV0PAr7"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff2d5Rptz9s9N for ; Fri, 8 Mar 2019 05:16:09 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xYt-0007NA-9a for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:16:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrR-0003v6-4i for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrQ-0000Dm-69 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:13 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:39174) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrP-0000D9-TV for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:12 -0500 Received: by mail-wr1-x432.google.com with SMTP id l12so1952282wrp.6 for ; Thu, 07 Mar 2019 09:31:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AQV/Hv4hmIISmxy4lWfaADhegjquDxkFpQ+v8CbihNI=; b=RRV0PAr7SCrzemkK6cmG1Syw0HMd8Mo1OQrDCjUXqaxOdp+a58Id5y6Z+zYNUGtLbk cC4GEVHfeVGaFHYB4RfshM0r4FuXwB0FeSQC/NuiFQVFoqM3R9JMXBghASOrMrrK0+vC 5IPwkTX3zex4VZ3Gf66HSpoIGi9ZrG+TZ1S5OQ/lGrtGq/Y9aIQGkpgOhoCwj8/rFsCr k46lJeEjXYhaej35rhpxIMJmnAZVOcI3+wChP+2QtrSpyObstejqGQ9nHhIitVWPsBPp ZllrhzesJhWX2nESD8RNQJqrFkbkzM1vyNY10MM+bnwJYsEWJTYCxWJuOFJIm7cWCs2a yzvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AQV/Hv4hmIISmxy4lWfaADhegjquDxkFpQ+v8CbihNI=; b=dra7hgLW/vbPftvVAVHP9tE2jmWRt+vd86yzPWYT89u7LJFRvO80KzMGKsG6N/4qfV 4yZulcdn4dFaQOwjbEjMZmBlgL/TaDLzh+WUDfqrWpGx8f05IoSf5ikqCeyaX+dPrtRp a4LR+DNXw9u9sFjBtK9vJXeAqciVpNkIU6XmlOv6HUukddMpRXNI0Qn2b3LcChSsj151 LHFjItfM5EDUMvfQePm1WPCV/uIVPXRqQLzGbRGBJBfvFr4yM74q2sUuPJeExy0Ue/QG PqgsQU6Gnj5w1ByY74qMAQqWEKP+ahdL97Qhxp0z4NFPCZvGY3wYPBqYQH5RDGY7p/B5 ZRSw== X-Gm-Message-State: APjAAAUtBnKmbSxlXGKZXhfHD8f35DIg1JIUmf+hv7ui7gF2PWefmGqn HQofH2AK2Za5gBZdt280Ix6kDmbU X-Google-Smtp-Source: APXvYqw29TesZpkya2oc6mg/Q/sOhDp6fgXxkkmhgTV2ghl2Ha+V6SIo5OYAqdJE2DVsSuk4C9yP3g== X-Received: by 2002:adf:b687:: with SMTP id j7mr8113782wre.81.1551979870702; Thu, 07 Mar 2019 09:31:10 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:30:02 +0100 Message-Id: <1551979804-6060-56-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PULL 55/57] qos-test: eepro100 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/eepro100-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. For now, all nodes share the same constructor and destructor. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/eepro100-test.c | 65 +++++++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 4a387b6..befeb8f 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -153,7 +153,6 @@ check-qtest-generic-y += tests/cdrom-test$(EXESUF) check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) -check-qtest-pci-$(CONFIG_EEPRO100_PCI) += tests/eepro100-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) @@ -744,6 +743,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests qos-test-obj-y += tests/ac97-test.o qos-test-obj-y += tests/e1000e-test.o +qos-test-obj-y += tests/eepro100-test.o qos-test-obj-y += tests/es1370-test.o qos-test-obj-y += tests/ipoctal232-test.o qos-test-obj-y += tests/ne2000-test.o @@ -800,7 +800,6 @@ tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) tests/e1000-test$(EXESUF): tests/e1000-test.o tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y) tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o -tests/eepro100-test$(EXESUF): tests/eepro100-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o diff --git a/tests/eepro100-test.c b/tests/eepro100-test.c index bdc8a67..90b5c1a 100644 --- a/tests/eepro100-test.c +++ b/tests/eepro100-test.c @@ -9,23 +9,15 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -static void test_device(gconstpointer data) -{ - const char *model = data; - QTestState *s; - char *args; - - args = g_strdup_printf("-device %s", model); - s = qtest_start(args); - - /* Tests only initialization so far. TODO: Implement functional tests */ +typedef struct QEEPRO100 QEEPRO100; - if (s) { - qtest_quit(s); - } - g_free(args); -} +struct QEEPRO100 { + QOSGraphObject obj; + QPCIDevice dev; +}; static const char *models[] = { "i82550", @@ -43,19 +35,42 @@ static const char *models[] = { "i82801", }; -int main(int argc, char **argv) +static void *eepro100_get_driver(void *obj, const char *interface) { - int i; + QEEPRO100 *eepro100 = obj; - g_test_init(&argc, &argv, NULL); + if (!g_strcmp0(interface, "pci-device")) { + return &eepro100->dev; + } - for (i = 0; i < ARRAY_SIZE(models); i++) { - char *path; + fprintf(stderr, "%s not present in eepro100\n", interface); + g_assert_not_reached(); +} - path = g_strdup_printf("eepro100/%s", models[i]); - qtest_add_data_func(path, models[i], test_device); - g_free(path); - } +static void *eepro100_create(void *pci_bus, QGuestAllocator *alloc, void *addr) +{ + QEEPRO100 *eepro100 = g_new0(QEEPRO100, 1); + QPCIBus *bus = pci_bus; + + qpci_device_init(&eepro100->dev, bus, addr); + eepro100->obj.get_driver = eepro100_get_driver; + + return &eepro100->obj; +} + +static void eepro100_register_nodes(void) +{ + int i; + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; - return g_test_run(); + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); + for (i = 0; i < ARRAY_SIZE(models); i++) { + qos_node_create_driver(models[i], eepro100_create); + qos_node_consumes(models[i], "pci-bus", &opts); + qos_node_produces(models[i], "pci-device"); + } } + +libqos_init(eepro100_register_nodes); From patchwork Thu Mar 7 17:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Z2ndWU8H"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ff6R2kGBz9s70 for ; Fri, 8 Mar 2019 05:19:27 +1100 (AEDT) Received: from localhost ([127.0.0.1]:56786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xc5-0001Ms-9c for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:19:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrS-0003vo-Eb for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrR-0000Ef-GL for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:14 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:40427) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrR-0000E3-8g for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:13 -0500 Received: by mail-wm1-x333.google.com with SMTP id g20so9985342wmh.5 for ; Thu, 07 Mar 2019 09:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4VfXBQJnjopNit5y6AgATqkoYdvOtk5Cv85by7uizdY=; b=Z2ndWU8HCjQQ2FTErO1BiYvHVQF2ZrkhZNXQ1NUVTK3Mi1FB419EnB1BD0ix14xqfV hUa7hvmKqUNOMyYnmbknqdPn8bxao1B0J+S2cLwx0wecHt7sc5AIXrhhGXgsJwKoLHGU iUkCFSu/pjcGqtYsDsF2nP8c2C+Qr7Bd92sfw2d2vLSKER1U+hQJtbJ+Z0FJDlyLeuKo 2y9V6RqYvivlXFW3V+1M0JcIbB1lzHEbASIS5iChOExxmSoHzBBSwDIBLBehUPYuEgOD wPi8WN13TWFfyVqRxyl3+kw7zW3PXMhcIJBjl92yqaUjWE9a2iCZhqweAHhaXh+Ebk8R wq1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4VfXBQJnjopNit5y6AgATqkoYdvOtk5Cv85by7uizdY=; b=AbjzR740ylHzMtoZVZLno8in50QJB7qTLI6eo+N2TNIEZSj9pONWffAby+K1bGzSH4 ycwCQ9Lw69vm30cT/HoDWcaTXmipdSqfSuFgSoAepP+vhHAA7e+vlDcVvV9/A5d6qtWK ySji8dQGdd9rdx8nFAH3V1LewIYqPQtAS22+ck15IbA3AHT4ASUeBkX69UnleOpRes5a 7d3AeVkwB8Vmf7csCSNbGpEhB5Ba/9UZVFiIL8eN0Dcnm/xdBrZSicH16wKKyY9c8/5R +WWgEeF2rgYl+Sb/QSTmBlrjw77QuNil8n4rY3+lugPuRTRNRX3gFTbfWefs3lREO49h z2dw== X-Gm-Message-State: APjAAAV0GyPG51rYERFV0ul9yQ+vrb2M9MFwXkxYt72Cd1LJwu+SbVxa zBZ4CPBIPgoCK55h2oJk6rBqM8/x X-Google-Smtp-Source: APXvYqwMywPNTYO+pumCMm81CHre7qQesfDCKoZ932rRI4DPkIaUUa3vsO7Vf3pegDKlqc9scsDn+g== X-Received: by 2002:a7b:c74b:: with SMTP id w11mr6286944wmk.79.1551979871947; Thu, 07 Mar 2019 09:31:11 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:30:03 +0100 Message-Id: <1551979804-6060-57-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::333 Subject: [Qemu-devel] [PULL 56/57] qos-test: e1000 test node 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Emanuele Giuseppe Esposito Convert tests/e1000-test to a driver node; currently it runs the PCI nop test only, therefore we're not placing it in tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +-- tests/e1000-test.c | 64 +++++++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index befeb8f..5bc6d63 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -151,7 +151,6 @@ check-qtest-generic-y += tests/qmp-cmd-test$(EXESUF) check-qtest-generic-y += tests/device-introspect-test$(EXESUF) check-qtest-generic-y += tests/cdrom-test$(EXESUF) -check-qtest-pci-y += tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) @@ -742,6 +741,7 @@ qos-test-obj-y += tests/libqos/x86_64_pc-machine.o # Tests qos-test-obj-y += tests/ac97-test.o +qos-test-obj-y += tests/e1000-test.o qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/eepro100-test.o qos-test-obj-y += tests/es1370-test.o @@ -797,7 +797,6 @@ tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) -tests/e1000-test$(EXESUF): tests/e1000-test.o tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y) tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o diff --git a/tests/e1000-test.c b/tests/e1000-test.c index 0c5fcdc..9e67916 100644 --- a/tests/e1000-test.c +++ b/tests/e1000-test.c @@ -9,22 +9,15 @@ #include "qemu/osdep.h" #include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void test_device(gconstpointer data) -{ - const char *model = data; - QTestState *s; - char *args; - - args = g_strdup_printf("-device %s", model); - s = qtest_start(args); +typedef struct QE1000 QE1000; - if (s) { - qtest_quit(s); - } - g_free(args); -} +struct QE1000 { + QOSGraphObject obj; + QPCIDevice dev; +}; static const char *models[] = { "e1000", @@ -33,19 +26,42 @@ static const char *models[] = { "e1000-82545em", }; -int main(int argc, char **argv) +static void *e1000_get_driver(void *obj, const char *interface) { - int i; + QE1000 *e1000 = obj; - g_test_init(&argc, &argv, NULL); + if (!g_strcmp0(interface, "pci-device")) { + return &e1000->dev; + } - for (i = 0; i < ARRAY_SIZE(models); i++) { - char *path; + fprintf(stderr, "%s not present in e1000e\n", interface); + g_assert_not_reached(); +} - path = g_strdup_printf("e1000/%s", models[i]); - qtest_add_data_func(path, models[i], test_device); - g_free(path); - } +static void *e1000_create(void *pci_bus, QGuestAllocator *alloc, void *addr) +{ + QE1000 *e1000 = g_new0(QE1000, 1); + QPCIBus *bus = pci_bus; + + qpci_device_init(&e1000->dev, bus, addr); + e1000->obj.get_driver = e1000_get_driver; + + return &e1000->obj; +} + +static void e1000_register_nodes(void) +{ + int i; + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0", + }; + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); - return g_test_run(); + for (i = 0; i < ARRAY_SIZE(models); i++) { + qos_node_create_driver(models[i], e1000_create); + qos_node_consumes(models[i], "pci-bus", &opts); + qos_node_produces(models[i], "pci-device"); + } } + +libqos_init(e1000_register_nodes); From patchwork Thu Mar 7 17:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tk8p/UAr"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Ffdg09Y3z9s70 for ; Fri, 8 Mar 2019 05:43:03 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xyv-0004lY-14 for incoming@patchwork.ozlabs.org; Thu, 07 Mar 2019 13:43:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrU-0003w0-EK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrT-0000Fd-Bs for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:16 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35877) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrT-0000FC-4o for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:15 -0500 Received: by mail-wr1-x42c.google.com with SMTP id o17so18423096wrw.3 for ; Thu, 07 Mar 2019 09:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fDRbr7hzBptmKgRFcQuQI9yQqF0XOpai/rdg1bvQlhY=; b=tk8p/UAr40EpNiiUY1z0XxYh9cK6/JGatEyr0j9U8RmqDHKZ8Qdn7xCiIL6qj4KcyA FssjVofB4aahLnttFe6yyUJXK+RyCXGdYlx8PKX5sT/nTiX/hcQwcy02QcVeSw5lTOog 6tjEJC/btcjDKKRYCwgcBX4MEHtnKeCADCNnKm8Dd53hfMGDF3LDwVi8IVXQbLo2fNN2 qC2PS7Dmy3yZ3BIonCFExAFf1Th5u8bW0ZrYO6kQ9+wn87kI22g54KytQgUpwE5R9TYQ v9N1EqIO4DP+1uSJYqWNFRYkWLWxiF2egWJaWoVsaRwn+Z8HUOjZjH8ZubV+2z1Rcihh +aFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=fDRbr7hzBptmKgRFcQuQI9yQqF0XOpai/rdg1bvQlhY=; b=r56D1h1xjGpfqhWhyYj9txsTNoUBWHgOdKb6EmByx7dNXziKBV6zLMgzGMOsv5Kt2d m+m7UZXZ5UFR7kVVYMKhoMKUuycmdj5DFRg4BZRF3EAMl0F5cdivSqbGb3m6wI87QPME HFVkf3VebfdMBPKzYRc3S0BJwQ70ximSfGLYe1pZRNSmcNDaqyjIRLVzEVlg1eD4sWsq kGnKTCQ1NQ7zogsKQ1rERLjSCoe7kqL+h+Asj1wE1PTaGsX7P5xGV4VkwPmXrMpKNOwB AN2cep6CmMwNlLyWXoCyGdPjWVf9DKN5YnXJ6v8GDmgZnMTUgVYb1OW8WKxZOhWZnWSt 5kJw== X-Gm-Message-State: APjAAAXwvYfS5RTdppJrTbqhjbLAfUasgjBBjklk1UJ2+rVsjTCfyrAj I58BvPHf0ejUOFri7c4ZBIJwKZAj X-Google-Smtp-Source: APXvYqzxz6UhjFXYrT9HoHDQgsm4d58C/mkke4fquha2jHRtQ/lCNvTBXGcl8yFeqME7/mBDyIToZw== X-Received: by 2002:adf:f6ca:: with SMTP id y10mr7649257wrp.148.1551979873886; Thu, 07 Mar 2019 09:31:13 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:30:04 +0100 Message-Id: <1551979804-6060-58-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 57/57] qos-test: megasas test node 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: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Convert tests/megasas-test to a driver node; the code to discover the PCI device is replaced by generic qgraph code. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/megasas-test.c | 80 +++++++++++++++++++++++++------------------------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 5bc6d63..44af415 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,7 +155,6 @@ check-qtest-pci-$(CONFIG_RTL8139_PCI) += tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) += tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) -check-qtest-pci-$(CONFIG_MEGASAS_SCSI_PCI) += tests/megasas-test$(EXESUF) check-qtest-i386-$(CONFIG_ISA_TESTDEV) = tests/endianness-test$(EXESUF) check-qtest-i386-y += tests/fdc-test$(EXESUF) @@ -746,6 +745,7 @@ qos-test-obj-y += tests/e1000e-test.o qos-test-obj-y += tests/eepro100-test.o qos-test-obj-y += tests/es1370-test.o qos-test-obj-y += tests/ipoctal232-test.o +qos-test-obj-y += tests/megasas-test.o qos-test-obj-y += tests/ne2000-test.o qos-test-obj-y += tests/nvme-test.o qos-test-obj-y += tests/pci-test.o @@ -827,7 +827,6 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y) tests/test-x86-cpuid-compat$(EXESUF): tests/test-x86-cpuid-compat.o $(qtest-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) $(libqos-spapr-obj-y) -tests/megasas-test$(EXESUF): tests/megasas-test.o $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-obj-y) libvhost-user.a tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o diff --git a/tests/megasas-test.c b/tests/megasas-test.c index 81837e1..33aa970 100644 --- a/tests/megasas-test.c +++ b/tests/megasas-test.c @@ -10,55 +10,49 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "qemu/bswap.h" -#include "libqos/libqos-pc.h" -#include "libqos/libqos-spapr.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" -static QOSState *qmegasas_start(const char *extra_opts) +typedef struct QMegasas QMegasas; + +struct QMegasas { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *megasas_get_driver(void *obj, const char *interface) { - QOSState *qs; - const char *arch = qtest_get_arch(); - const char *cmd = "-drive id=hd0,if=none,file=null-co://,format=raw " - "-device megasas,id=scsi0,addr=04.0 " - "-device scsi-hd,bus=scsi0.0,drive=hd0 %s"; - - if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { - qs = qtest_pc_boot(cmd, extra_opts ? : ""); - global_qtest = qs->qts; - return qs; + QMegasas *megasas = obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &megasas->dev; } - g_printerr("virtio-scsi tests are only available on x86 or ppc64\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "%s not present in megasas\n", interface); + g_assert_not_reached(); } -static void qmegasas_stop(QOSState *qs) +static void *megasas_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - qtest_shutdown(qs); -} + QMegasas *megasas = g_new0(QMegasas, 1); + QPCIBus *bus = pci_bus; -/* Tests only initialization so far. TODO: Replace with functional tests */ -static void pci_nop(void) -{ - QOSState *qs; + qpci_device_init(&megasas->dev, bus, addr); + megasas->obj.get_driver = megasas_get_driver; - qs = qmegasas_start(NULL); - qmegasas_stop(qs); + return &megasas->obj; } /* This used to cause a NULL pointer dereference. */ -static void megasas_pd_get_info_fuzz(void) +static void megasas_pd_get_info_fuzz(void *obj, void *data, QGuestAllocator *alloc) { - QPCIDevice *dev; - QOSState *qs; + QMegasas *megasas = obj; + QPCIDevice *dev = &megasas->dev; QPCIBar bar; uint32_t context[256]; uint64_t context_pa; int i; - qs = qmegasas_start(NULL); - dev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0)); - g_assert(dev != NULL); - qpci_device_enable(dev); bar = qpci_iomap(dev, 0, NULL); @@ -71,19 +65,25 @@ static void megasas_pd_get_info_fuzz(void) context[6] = cpu_to_le32(0x02020000); context[7] = cpu_to_le32(0); - context_pa = qmalloc(qs, sizeof(context)); + context_pa = guest_alloc(alloc, sizeof(context)); memwrite(context_pa, context, sizeof(context)); qpci_io_writel(dev, bar, 0x40, context_pa); - - g_free(dev); - qmegasas_stop(qs); } -int main(int argc, char **argv) +static void megasas_register_nodes(void) { - g_test_init(&argc, &argv, NULL); - qtest_add_func("/megasas/pci/nop", pci_nop); - qtest_add_func("/megasas/dcmd/pd-get-info/fuzz", megasas_pd_get_info_fuzz); + QOSGraphEdgeOptions opts = { + .extra_device_opts = "addr=04.0,id=scsi0", + .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw", + .after_cmd_line = "-device scsi-hd,bus=scsi0.0,drive=drv0", + }; + + add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); + + qos_node_create_driver("megasas", megasas_create); + qos_node_consumes("megasas", "pci-bus", &opts); + qos_node_produces("megasas", "pci-device"); - return g_test_run(); + qos_add_test("dcmd/pd-get-info/fuzz", "megasas", megasas_pd_get_info_fuzz, NULL); } +libqos_init(megasas_register_nodes);