Skip to contentSkip to conversation

Qtest driver framework

PATCH In review Emanuele Giuseppe Esposito 3 participants 71 messages Aug 6, 2018 – Aug 10, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

v2 cover Qtest driver framework

qgraph API for the qtest driver framework

This series of patches introduce a different qtest driver organization, viewing machines, drivers and tests as node in a graph, each having one or multiple edges relations.

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:
- MACHINE: for example "arm/raspi2"
- DRIVER: for example "generic-sdhci"
- INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers)
- TEST: for example "sdhci-test", consumes an interface and tests
the functions provided

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
- 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.

This work is being done as Google Summer of Code 2018 project for QEMU, my mentors are Paolo Bonzini and Laurent Vivier.
Additional infos on the project can be found at:
https://wiki.qemu.org/Features/qtest_driver_framework

v2:
- added command line arguments caching
- converted all virtio tests
- converted e1000e test
- added two more machines (virt and ppc64)
- introduced separation between edge-name (used by get_driver) and node-name (matched with QMP query result)
- edge carries also additional arguments, like the pci address of destination device
- test now can execute a function before and after the command line is allocated, to allocate various file and sockets needed by command line and test
- better documentation with working example in qgraph.h
- removed esplicit creation of interfaces

Emanuele Giuseppe Esposito (33):
tests: qgraph API for the qtest driver framework tests/qgraph: rename qpci_init_pc functions tests/qgraph: pci-pc driver and interface nodes tests/qgraph: x86_64/pc machine node tests/qgraph: sdhci driver and interface nodes tests/qgraph: sdhci test node
tests/qgraph: arm/raspi2 machine node tests/qgraph: rename qpci_init_spapr functions tests/qgraph: pci-spapr driver and interface nodes tests/qgraph: ppc64/pseries machine node test/qgraph: e1000e driver and interface nodes test/qgraph: e1000e-test node
test/qgraph: virtio_start_device function test/qgraph: virtio-pci driver and interface nodes tests/qgraph: rename qvirtio_mmio_init_device functions test/qgraph: virtio-mmio driver and interface nodes test/qgraph: arm/virt machine node test/qgraph: virtio-serial driver and interface nodes test/qgraph: virtio-console test node test/qgraph: virtio-serial test node test/qgraph: virtio-9p driver and interface nodes test/qgraph: virtio-9p test node
test/qgraph: virtio-balloon driver and interface nodes test/qgraph: virtio-balloon test node test/qgraph: virtio-rng driver and interface nodes test/qgraph: virtio-rng test node
test/qgraph: virtio-blk driver and interface nodes test/qgraph: virtio-blk test node
test/qgraph: virtio-net driver and interface nodes test/qgraph: virtio-net test node
test/qgraph: virtio-scsi driver and interface nodes test/qgraph: virtio-scsi test node test/qgraph: temporarly commented vhost-user-test

Paolo Bonzini (1):
tests: virtio: separate ccw tests from libqos

 configure                            |   2 +-
 include/qemu/module.h                |   2 +
 tests/Makefile.include               |  79 +--
 tests/e1000e-test.c                  | 354 +++----------
 tests/i440fx-test.c                  |   2 +-
 tests/ide-test.c                     |   2 +-
 tests/libqos/ahci.c                  |   2 +-
 tests/libqos/e1000e.c                | 262 ++++++++++
 tests/libqos/e1000e.h                |  53 ++
 tests/libqos/libqos-pc.c             |   2 +-
 tests/libqos/libqos-spapr.c          |   2 +-
 tests/libqos/pci-pc.c                |  41 +-
 tests/libqos/pci-pc.h                |  22 +-
 tests/libqos/pci-spapr.c             |  57 ++-
 tests/libqos/pci-spapr.h             |  26 +-
 tests/libqos/pci.c                   |  48 +-
 tests/libqos/pci.h                   |  15 +
 tests/libqos/ppc64_pseries-machine.c | 111 +++++
 tests/libqos/qgraph.c                | 721 +++++++++++++++++++++++++++
 tests/libqos/qgraph.h                | 514 +++++++++++++++++++
 tests/libqos/qgraph_extra.h          | 263 ++++++++++
 tests/libqos/raspi2-machine.c        |  82 +++
 tests/libqos/sdhci.c                 | 163 ++++++
 tests/libqos/sdhci.h                 |  69 +++
 tests/libqos/virt-machine.c          |  90 ++++
 tests/libqos/virtio-9p.c             | 164 ++++++
 tests/libqos/virtio-9p.h             |  42 ++
 tests/libqos/virtio-balloon.c        | 111 +++++
 tests/libqos/virtio-balloon.h        |  39 ++
 tests/libqos/virtio-blk.c            | 126 +++++
 tests/libqos/virtio-blk.h            |  40 ++
 tests/libqos/virtio-mmio.c           |  72 ++-
 tests/libqos/virtio-mmio.h           |   6 +-
 tests/libqos/virtio-net.c            | 177 +++++++
 tests/libqos/virtio-net.h            |  41 ++
 tests/libqos/virtio-pci.c            |  80 ++-
 tests/libqos/virtio-pci.h            |  12 +
 tests/libqos/virtio-rng.c            | 108 ++++
 tests/libqos/virtio-rng.h            |  39 ++
 tests/libqos/virtio-scsi.c           | 117 +++++
 tests/libqos/virtio-scsi.h           |  39 ++
 tests/libqos/virtio-serial.c         | 109 ++++
 tests/libqos/virtio-serial.h         |  39 ++
 tests/libqos/virtio.c                |   9 +
 tests/libqos/virtio.h                |   1 +
 tests/libqos/x86_64_pc-machine.c     | 110 ++++
 tests/q35-test.c                     |   4 +-
 tests/qos-test.c                     | 480 ++++++++++++++++++
 tests/rtl8139-test.c                 |   2 +-
 tests/sdhci-test.c                   | 222 +++------
 tests/tco-test.c                     |   2 +-
 tests/test-qgraph.c                  | 446 +++++++++++++++++
 tests/usb-hcd-ehci-test.c            |   2 +-
 tests/vhost-user-test.c              |   7 +-
 tests/virtio-9p-test.c               | 221 +++-----
 tests/virtio-balloon-test.c          |  22 +-
 tests/virtio-blk-test.c              | 473 +++++++-----------
 tests/virtio-ccw-test.c              | 121 +++++
 tests/virtio-console-test.c          |  30 +-
 tests/virtio-net-test.c              | 163 ++----
 tests/virtio-rng-test.c              |  25 +-
 tests/virtio-scsi-test.c             | 155 +++---
 tests/virtio-serial-test.c           |  27 +-
 63 files changed, 5624 insertions(+), 1243 deletions(-)
 create mode 100644 tests/libqos/e1000e.c
 create mode 100644 tests/libqos/e1000e.h
 create mode 100644 tests/libqos/ppc64_pseries-machine.c
 create mode 100644 tests/libqos/qgraph.c
 create mode 100644 tests/libqos/qgraph.h
 create mode 100644 tests/libqos/qgraph_extra.h
 create mode 100644 tests/libqos/raspi2-machine.c
 create mode 100644 tests/libqos/sdhci.c
 create mode 100644 tests/libqos/sdhci.h
 create mode 100644 tests/libqos/virt-machine.c
 create mode 100644 tests/libqos/virtio-9p.c
 create mode 100644 tests/libqos/virtio-9p.h
 create mode 100644 tests/libqos/virtio-balloon.c
 create mode 100644 tests/libqos/virtio-balloon.h
 create mode 100644 tests/libqos/virtio-blk.c
 create mode 100644 tests/libqos/virtio-blk.h
 create mode 100644 tests/libqos/virtio-net.c
 create mode 100644 tests/libqos/virtio-net.h
 create mode 100644 tests/libqos/virtio-rng.c
 create mode 100644 tests/libqos/virtio-rng.h
 create mode 100644 tests/libqos/virtio-scsi.c
 create mode 100644 tests/libqos/virtio-scsi.h
 create mode 100644 tests/libqos/virtio-serial.c
 create mode 100644 tests/libqos/virtio-serial.h
 create mode 100644 tests/libqos/x86_64_pc-machine.c
 create mode 100644 tests/qos-test.c
 create mode 100644 tests/test-qgraph.c
 create mode 100644 tests/virtio-ccw-test.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/34 tests: qgraph API for the qtest driver framework

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

---
 configure                   |   2 +-
 include/qemu/module.h       |   2 +
 tests/Makefile.include      |  12 +-
 tests/libqos/qgraph.c       | 721 ++++++++++++++++++++++++++++++++++++
 tests/libqos/qgraph.h       | 514 +++++++++++++++++++++++++
 tests/libqos/qgraph_extra.h | 263 +++++++++++++
 tests/qos-test.c            | 480 ++++++++++++++++++++++++
 tests/test-qgraph.c         | 446 ++++++++++++++++++++++
 8 files changed, 2437 insertions(+), 3 deletions(-)
 create mode 100644 tests/libqos/qgraph.c
 create mode 100644 tests/libqos/qgraph.h
 create mode 100644 tests/libqos/qgraph_extra.h
 create mode 100644 tests/qos-test.c
 create mode 100644 tests/test-qgraph.c
configure +1 -1
index 2a7796ea80..85a108506a 100755
@@ -7352,7 +7352,7 @@ if test "$ccache_cpp2" = "yes"; then
 fi
 
 # build tree in object directory in case the source is not in the current directory
-DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm"
+DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm 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"
include/qemu/module.h +2 -0
index 54300ab6e5..1fcdca084d 100644
@@ -44,6 +44,7 @@ typedef enum {
     MODULE_INIT_OPTS,
     MODULE_INIT_QOM,
     MODULE_INIT_TRACE,
+    MODULE_INIT_LIBQOS,
     MODULE_INIT_MAX
 } module_init_type;
 
@@ -51,6 +52,7 @@ typedef enum {
 #define opts_init(function) module_init(function, MODULE_INIT_OPTS)
 #define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
+#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)
tests/Makefile.include +10 -2
index a49282704e..eabf9ed8b4 100644
@@ -755,8 +755,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
-libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.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/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
 libqos-spapr-obj-y += tests/libqos/rtas.o
@@ -769,6 +771,12 @@ 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
 
+check-unit-y += tests/test-qgraph$(EXESUF)
+tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
+
+check-qtest-pci-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/device-introspect-test$(EXESUF): tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
tests/libqos/qgraph.c new file +721 -0

721 lines not on this page · raw message

tests/libqos/qgraph.h new file +514 -0

514 lines not on this page · raw message

tests/libqos/qgraph_extra.h new file +263 -0

263 lines not on this page · raw message

tests/qos-test.c new file +480 -0

480 lines not on this page · raw message

tests/test-qgraph.c new file +446 -0

446 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/34 tests/qgraph: rename qpci_init_pc functions

In reply to Emanuele Giuseppe Esposito

Rename qpci_init_pc in qpci_new_pc, since the function actually allocates a new QPCIBusPC and initialize it.

---
 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/pci-pc.c     | 2 +-
 tests/libqos/pci-pc.h     | 9 ++++++++-
 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 +-
 13 files changed, 21 insertions(+), 14 deletions(-)
tests/e1000e-test.c +1 -1
index 32aa738b72..51b9dda404 100644
@@ -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_pc_new(global_qtest, test_alloc);
     g_assert_nonnull(test_bus);
 
     e1000e_device_init(test_bus, d);
tests/i440fx-test.c +1 -1
index 4390e5591e..acee5e6572 100644
@@ -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_pc_new(global_qtest, NULL);
 }
 
 static void test_i440fx_defaults(gconstpointer opaque)
tests/ide-test.c +1 -1
index 2384c2c3e2..fce9692ba2 100644
@@ -150,7 +150,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_pc_new(global_qtest, NULL);
     }
 
     /* Find PCI device and verify it's the right one */
tests/libqos/ahci.c +1 -1
index 42d3f76933..4ec516a8c9 100644
@@ -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_pc_new(qts, NULL);
 
     /* Find the AHCI PCI device and verify it's the right one. */
     ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02));
tests/libqos/libqos-pc.c +1 -1
index a9c1aceaa7..72b3eb46f5 100644
@@ -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_init = qpci_pc_new,
     .qpci_free = qpci_free_pc,
     .shutdown = qtest_pc_shutdown,
 };
tests/libqos/pci-pc.c +1 -1
index a7803308b7..83a3a32129 100644
@@ -115,7 +115,7 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
     outl(0xcfc, value);
 }
 
-QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
+QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusPC *ret = g_new0(QPCIBusPC, 1);
 
tests/libqos/pci-pc.h +8 -1
index 491eeac756..88be29eaf3 100644
@@ -16,7 +16,14 @@
 #include "libqos/pci.h"
 #include "libqos/malloc.h"
 
-QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc);
+/* qpci_pc_new():
+* this function creates a new QPCIBusPC object,
+ * and properly initialize its fields.
+ *
+ * returns the QPCIBus *bus field of a newly
+ * allocated QPCIBusPC.
+ */
+QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_pc(QPCIBus *bus);
 
 #endif
tests/q35-test.c +2 -2
index 7ea7acc9d8..e3da12ee8c 100644
@@ -87,7 +87,7 @@ static void test_smram_lock(void)
 
     qtest_start("-M q35");
 
-    pcibus = qpci_init_pc(global_qtest, NULL);
+    pcibus = qpci_pc_new(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_pc_new(global_qtest, NULL);
     g_assert(pcibus != NULL);
     pcidev = qpci_device_find(pcibus, 0);
     g_assert(pcidev != NULL);
tests/rtl8139-test.c +1 -1
index 68bfc42178..d9045b46c2 100644
@@ -35,7 +35,7 @@ static QPCIDevice *get_device(void)
 {
     QPCIDevice *dev;
 
-    pcibus = qpci_init_pc(global_qtest, NULL);
+    pcibus = qpci_pc_new(global_qtest, NULL);
     qpci_device_foreach(pcibus, 0x10ec, 0x8139, save_fn, &dev);
     g_assert(dev != NULL);
 
tests/sdhci-test.c +1 -1
index 1d825eb010..5e97590573 100644
@@ -187,7 +187,7 @@ static QSDHCI *machine_start(const struct sdhci_t *test)
         global_qtest = qtest_startf("-machine %s -device sdhci-pci",
                                     test->machine);
 
-        s->pci.bus = qpci_init_pc(global_qtest, NULL);
+        s->pci.bus = qpci_pc_new(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));
tests/tco-test.c +1 -1
index 9945fb8469..2f99824d54 100644
@@ -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_pc_new(qs, NULL);
     d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00));
     g_assert(d->dev != NULL);
 
tests/usb-hcd-ehci-test.c +1 -1
index 55d4743a2a..037e17f496 100644
@@ -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_pc_new(global_qtest, NULL);
     g_assert(pcibus != NULL);
 
     qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4);
tests/vhost-user-test.c +1 -1
index fecc832d99..a01b81d342 100644
@@ -191,7 +191,7 @@ static void init_virtio_dev(TestServer *s, uint32_t features_mask)
     uint32_t features;
     int i;
 
-    s->bus = qpci_init_pc(global_qtest, NULL);
+    s->bus = qpci_pc_new(global_qtest, NULL);
     g_assert_nonnull(s->bus);
 
     s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);
Signature · 1 line
2.17.1
#3 lore raw

Re: [Qemu-devel] [PATCH v2 02/34] tests/qgraph: rename qpci_init_pc functions

Quoted 20 lines · Emanuele Giuseppe Esposito

Rename qpci_init_pc in qpci_new_pc, since the function actually allocates a new QPCIBusPC and initialize it.

---
 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/pci-pc.c     | 2 +-
 tests/libqos/pci-pc.h     | 9 ++++++++-
 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 +-
 13 files changed, 21 insertions(+), 14 deletions(-)

...

tests/libqos/libqos-pc.c line 12

Quoted 13 lines
tests/libqos/libqos-pc.c +1 -1
index a9c1aceaa7..72b3eb46f5 100644
@@ -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_init = qpci_pc_new,
     .qpci_free = qpci_free_pc,
     .shutdown = qtest_pc_shutdown,
 };

I think you should also rename the "qpci_init" field to "qpci_new". And as we have "qpci_free_pc", it should be "qpci_new_pc", and you should do the same for qpci_init_spapr -> qpci_new_spapr.

Thanks,
Laurent

#4 lore raw

PATCH v2 3/34 tests/qgraph: pci-pc driver and interface nodes

In reply to 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.

---
 tests/Makefile.include |  4 +++-
 tests/libqos/pci-pc.c  | 41 +++++++++++++++++++++++++++++-------
 tests/libqos/pci-pc.h  | 15 ++++++++++++-
 tests/libqos/pci.c     | 48 +++++++++++++++++++++++++++++++++++++++---
 tests/libqos/pci.h     | 15 +++++++++++++
 5 files changed, 110 insertions(+), 13 deletions(-)
tests/Makefile.include +3 -1
index eabf9ed8b4..f04f9fbc3a 100644
@@ -771,11 +771,13 @@ 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
 
+libqgraph-pci-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-pci-y += tests/qos-test$(EXESUF)
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y)
+tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-pci-obj-y)
 
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
tests/libqos/pci-pc.c +33 -8

74 lines not on this page · raw message

tests/libqos/pci-pc.h +14 -1
index 88be29eaf3..a3754c1c86 100644
@@ -15,9 +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():
+ * this function initialize an already allocated
+ * QPCIBusPC object.
+ *
+ * @ret must be a valid QPCIBusPC * pointer.
+ */
+void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc);
 /* qpci_pc_new():
-* this function creates a new QPCIBusPC object,
+ * this function creates a new QPCIBusPC object,
  * and properly initialize its fields.
  *
  * returns the QPCIBus *bus field of a newly
tests/libqos/pci.c +45 -3

75 lines not on this page · raw message

tests/libqos/pci.h +15 -0
index 429c382282..5fb3c550c5 100644
@@ -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,8 @@ 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 */
+
 };
 
 struct QPCIBar {
@@ -66,10 +70,19 @@ 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);
+/* returns the bus has_buggy_msi flag */
+bool qpci_has_buggy_msi(QPCIDevice *dev);
 
 void qpci_device_enable(QPCIDevice *dev);
 uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
@@ -112,4 +125,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
 void qpci_plug_device_test(const char *driver, const char *id,
                            uint8_t slot, const char *opts);
 void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr);
 #endif
Signature · 1 line
2.17.1
#5 lore raw

Re: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes

Quoted 55 lines · 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.

---
 tests/Makefile.include |  4 +++-
 tests/libqos/pci-pc.c  | 41 +++++++++++++++++++++++++++++-------
 tests/libqos/pci-pc.h  | 15 ++++++++++++-
 tests/libqos/pci.c     | 48 +++++++++++++++++++++++++++++++++++++++---
 tests/libqos/pci.h     | 15 +++++++++++++
 5 files changed, 110 insertions(+), 13 deletions(-)
tests/Makefile.include +3 -1
index eabf9ed8b4..f04f9fbc3a 100644
@@ -771,11 +771,13 @@ 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
 
+libqgraph-pci-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-pci-y += tests/qos-test$(EXESUF)
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y)
+tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-pci-obj-y)
 
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
tests/libqos/pci-pc.c +0 -6
index 83a3a32129..f5fb94eabc 100644
@@ -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 inb(addr);
@@ -115,12 +109,23 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
     outl(0xcfc, value);
 }

tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 118

Quoted 10 lines
tests/libqos/pci-pc.c +6 -2
 
-QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_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;
+    }
+    printf("%s not present in pci-bus-pc\n", interface);

fprintf(stderr, ...) ?

tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 119

Quoted 1 line
tests/libqos/pci-pc.c +1 -0
+    abort();

You should use g_assert_not_reached().

tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 127

Quoted 8 lines
tests/libqos/pci-pc.c +5 -0
+}
 
+void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc)
+{
     assert(qts);
 
+    /* tests can use pci-bus */
+    ret->bus.has_buggy_msi = FALSE;

I think you should introduce the field has_buggy_msi when it will be really needed: with patch 09/34 adn pci-spapr.

tests/libqos/pci-pc.c QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc) · line 158

Quoted 12 lines
tests/libqos/pci-pc.c +5 -0
+
     ret->bus.pio_readb = qpci_pc_pio_readb;
     ret->bus.pio_readw = qpci_pc_pio_readw;
     ret->bus.pio_readl = qpci_pc_pio_readl;
@@ -147,11 +152,23 @@ QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc)
     ret->bus.mmio_alloc_ptr = 0xE0000000;
     ret->bus.mmio_limit = 0x100000000ULL;
 
+    ret->obj.get_driver = qpci_get_driver;
+}
+
+QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc)

As I said for 02/34, I think qpci_new_pc() should be a better name to like the one we have for qpci_free_pc().

tests/libqos/pci-pc.c QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc) · line 160

Quoted 2 lines
tests/libqos/pci-pc.c +2 -0
+{
+    QPCIBusPC *ret = g_new0(QPCIBusPC, 1);

perhaps you can rename "ret" to "qpci"?

tests/libqos/pci-pc.c QPCIBus *qpci_pc_new(QTestState *qts, QGuestAllocator *alloc) · line 172

Quoted 12 lines
tests/libqos/pci-pc.c +6 -0
+    qpci_init_pc(ret, qts, alloc);
+
     return &ret->bus;
 }
 
 void qpci_free_pc(QPCIBus *bus)
 {
+    if (!bus) {
+        return;
+    }
+
     QPCIBusPC *s = container_of(bus, QPCIBusPC, bus);

Generally, gcc doesn't like to mix declarations and instructions. I think something like this would be nicer:

    QPCIBusPC *s;

    if (!bus) {
        return;
    }
    s = container_of(bus, QPCIBusPC, bus);

tests/libqos/pci-pc.c void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) · line 197

Quoted 8 lines
tests/libqos/pci-pc.c +2 -0
     g_free(s);
@@ -176,3 +193,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)
 
     qmp_eventwait("DEVICE_DELETED");
 }
+
+static void qpci_pc(void)

This name is not very clear, for the qemu part, type_init() is generally used with XXX_register_types name.

Perhaps you can use something like "qpci_pc_register_nodes" name?

Quoted 47 lines
tests/libqos/pci-pc.c +6 -0
+{
+    qos_node_create_driver("pci-bus-pc", NULL);
+    qos_node_produces("pci-bus-pc", "pci-bus");
+}
+
+libqos_init(qpci_pc);
tests/libqos/pci-pc.h +14 -1
index 88be29eaf3..a3754c1c86 100644
@@ -15,9 +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():
+ * this function initialize an already allocated
+ * QPCIBusPC object.
+ *
+ * @ret must be a valid QPCIBusPC * pointer.
+ */
+void qpci_init_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc);
 /* qpci_pc_new():
-* this function creates a new QPCIBusPC object,
+ * this function creates a new QPCIBusPC object,
  * and properly initialize its fields.
  *
  * returns the QPCIBus *bus field of a newly
tests/libqos/pci.c +1 -0
index 0b73cb23d0..91440ece5c 100644
@@ -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),

tests/libqos/pci.c void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, · line 57

Quoted 9 lines
tests/libqos/pci.c +3 -2
@@ -50,15 +51,31 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
     }
 }
 
-QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
+bool qpci_has_buggy_msi(QPCIDevice *dev)
 {
-    QPCIDevice *dev;
+    return dev->bus->has_buggy_msi;
+}

As above, introduce this when you need it.

tests/libqos/pci.c void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, · line 67

Quoted 10 lines
tests/libqos/pci.c +5 -1
-    dev = g_malloc0(sizeof(*dev));
+/* returns TRUE if everything goes fine, FALSE if not */
+static bool qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)
+{
     dev->bus = bus;
     dev->devfn = devfn;
 
     if (qpci_config_readw(dev, PCI_VENDOR_ID) == 0xFFFF) {
+        return FALSE;
+    }

I think what we check here is to see if the PCI device is available. 0xFFFF means there is a problem.

I think you should add a function "qpci_device_available(devn, bus)"

Quoted 16 lines
tests/libqos/pci.c +11 -0
+
+    return TRUE;
+}
+
+QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
+{
+    QPCIDevice *dev;
+
+    dev = g_malloc0(sizeof(*dev));
+
+    if (!qpci_device_set(dev, bus, devfn)) {
         g_free(dev);
         return NULL;
     }
@@ -66,6 +83,21 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
     return dev;

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 93

Quoted 10 lines
tests/libqos/pci.c +8 -0
 }
 
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)
+{
+    uint16_t vendor_id, device_id;
+
+    if (!qpci_device_set(dev, bus, addr->devfn)) {
+        printf("PCI Device not found\n");
+        abort();
+    }

so, here, you should use qpci_device_set() and qpci_device_available()...

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 95

Quoted 2 lines
tests/libqos/pci.c +2 -0
+
+    vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);

or you can only check vendor_id to see it is 0xffff or not...

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 97

Quoted 2 lines
tests/libqos/pci.c +2 -0
+    device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
+    g_assert(vendor_id == addr->vendor_id);

that should be in fact detected by this g_assert().

Quoted 7 lines
tests/libqos/pci.c +3 -0
+    g_assert(device_id == addr->device_id);
+}
+
 void qpci_device_enable(QPCIDevice *dev)
 {
     uint16_t cmd;

tests/libqos/pci.c void qpci_plug_device_test(const char *driver, const char *id, · line 442

Quoted 9 lines
tests/libqos/pci.c +6 -0
@@ -402,3 +434,13 @@ void qpci_plug_device_test(const char *driver, const char *id,
     qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot,
                          opts ? ", " : "", opts ? opts : "");
 }
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr)
+{
+    if (!addr || !opts) {
+        return;
+    }

Should it be an error case and fails (g_assert())?

Quoted 25 lines
tests/libqos/pci.c +4 -0
+
+    opts->arg = addr;
+    opts->size_arg = sizeof(QPCIAddress);
+}
tests/libqos/pci.h +2 -0
index 429c382282..5fb3c550c5 100644
@@ -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);

tests/libqos/pci.h struct QPCIBus { · line 56

Quoted 4 lines
tests/libqos/pci.h +1 -0
@@ -51,6 +53,8 @@ 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 */

as above, introduce it when you need it.

Quoted 32 lines
tests/libqos/pci.h +12 -0
+
 };
 
 struct QPCIBar {
@@ -66,10 +70,19 @@ 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);
+/* returns the bus has_buggy_msi flag */
+bool qpci_has_buggy_msi(QPCIDevice *dev);
 
 void qpci_device_enable(QPCIDevice *dev);
 uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
@@ -112,4 +125,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
 void qpci_plug_device_test(const char *driver, const char *id,
                            uint8_t slot, const char *opts);
 void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
+
+void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr);
 #endif
author
#6 lore raw

Re: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes

Quoted 18 lines
Quoted 18 lines
tests/libqos/pci.c +10 -0
+    return TRUE;
+}
+
+QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
+{
+    QPCIDevice *dev;
+
+    dev = g_malloc0(sizeof(*dev));
+
+    if (!qpci_device_set(dev, bus, devfn)) {
          g_free(dev);
          return NULL;
      }
@@ -66,6 +83,21 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
      return dev;
  }
 
Quoted 9 lines

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 93

Quoted 8 lines
tests/libqos/pci.c +8 -0
+void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)
+{
+    uint16_t vendor_id, device_id;
+
+    if (!qpci_device_set(dev, bus, addr->devfn)) {
+        printf("PCI Device not found\n");
+        abort();
+    }

so, here, you should use qpci_device_set() and qpci_device_available()...

I changed qpci_device_set to just set the fields, while qpci_device_available simply is doing
{
    return qpci_config_readw(...) != 0xFFFF
}
Now both qpci_device_init and qpci_device_find call qpci_device_set, and check that  qpci_device_available is not false, otherwise it will trigger g_assert_not_reached().

Quoted 8 lines

Review QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 95

Quoted 3 lines
(quoted diff) +2 -0
+
+    vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);

or you can only check vendor_id to see it is 0xffff or not...

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 97

Quoted 2 lines
tests/libqos/pci.c +2 -0
+    device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
+    g_assert(vendor_id == addr->vendor_id);

that should be in fact detected by this g_assert().

since this case is covered by qpci_device_available, I don't think there's the need to insert the assertion.

Thank you,
Emanuele

#7 lore raw

Re: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes

Quoted 38 lines · Emanuele
Quoted 19 lines
Quoted 19 lines

+    return TRUE;

tests/libqos/pci.c +9 -0
+}
+
+QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
+{
+    QPCIDevice *dev;
+
+    dev = g_malloc0(sizeof(*dev));
+
+    if (!qpci_device_set(dev, bus, devfn)) {

          g_free(dev);
          return NULL;
      }

tests/libqos/pci.c +0 -0
@@ -66,6 +83,21 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
       return dev;
   }

  +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)

Quoted 8 lines

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 93

Quoted 7 lines
tests/libqos/pci.c +7 -0
+{
+    uint16_t vendor_id, device_id;
+
+    if (!qpci_device_set(dev, bus, addr->devfn)) {
+        printf("PCI Device not found\n");
+        abort();
+    }

so, here, you should use qpci_device_set() and qpci_device_available()...

I changed qpci_device_set to just set the fields, while qpci_device_available simply is doing
{
    return qpci_config_readw(...) != 0xFFFF
}
Now both qpci_device_init and qpci_device_find call qpci_device_set, and check that  qpci_device_available is not false, otherwise it will trigger g_assert_not_reached().

Quoted 3 lines
Quoted 3 lines

+
+    vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);

Quoted 7 lines
Quoted 5 lines

or you can only check vendor_id to see it is 0xffff or not...

Quoted 2 lines

+    device_id = qpci_config_readw(dev, PCI_DEVICE_ID); +    g_assert(vendor_id == addr->vendor_id);

that should be in fact detected by this g_assert().

since this case is covered by qpci_device_available, I don't think there's the need to insert the assertion.

What I mean is you don't need the qpci_device_available().

The 0xffff case is detected by "g_assert(vendor_id == addr->vendor_id)".

The functions could be:

static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)

{
     dev->bus = bus;
     dev->devfn = devfn;
}

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(vendor_id == addr->vendor_id);
    g_assert(device_id == addr->device_id);
}

Thanks,
Laurent

author
#8 lore raw

Re: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes

Quoted 57 lines · Laurent Vivier
Quoted 36 lines · Emanuele
Quoted 18 lines
Quoted 18 lines

+    return TRUE;

tests/libqos/pci.c +9 -0
+}
+
+QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
+{
+    QPCIDevice *dev;
+
+    dev = g_malloc0(sizeof(*dev));
+
+    if (!qpci_device_set(dev, bus, devfn)) {
           g_free(dev);
           return NULL;
       }
@@ -66,6 +83,21 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
       return dev;
   }
   +void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress
 *addr)
Quoted 8 lines

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 93

Quoted 7 lines
tests/libqos/pci.c +7 -0
+{
+    uint16_t vendor_id, device_id;
+
+    if (!qpci_device_set(dev, bus, addr->devfn)) {
+        printf("PCI Device not found\n");
+        abort();
+    }

so, here, you should use qpci_device_set() and qpci_device_available()...

I changed qpci_device_set to just set the fields, while qpci_device_available simply is doing
{
    return qpci_config_readw(...) != 0xFFFF
}
Now both qpci_device_init and qpci_device_find call qpci_device_set, and check that  qpci_device_available is not false, otherwise it will trigger g_assert_not_reached().

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+
+    vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);
Quoted 7 lines
Quoted 5 lines

or you can only check vendor_id to see it is 0xffff or not...

tests/libqos/pci.c QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn) · line 97

Quoted 2 lines
tests/libqos/pci.c +2 -0
+    device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
+    g_assert(vendor_id == addr->vendor_id);

that should be in fact detected by this g_assert().

since this case is covered by qpci_device_available, I don't think there's the need to insert the assertion.

What I mean is you don't need the qpci_device_available().

The 0xffff case is detected by "g_assert(vendor_id == addr->vendor_id)".

The functions could be:

static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)

{
      dev->bus = bus;
      dev->devfn = devfn;
}

void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr)

Quoted 10 lines
{
     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(vendor_id == addr->vendor_id);
     g_assert(device_id == addr->device_id);
}

Ok, makes sense for qpci_device_init, but I still need to perform that check for qpci_device_find. Emanuele

#9 lore raw

Re: [Qemu-devel] [PATCH v2 03/34] tests/qgraph: pci-pc driver and interface nodes

Quoted 2 lines · Emanuele

Ok, makes sense for qpci_device_init, but I still need to perform that check for qpci_device_find.

Yes, you're right.

Thanks,
Laurent

#10 lore raw

PATCH v2 4/34 tests/qgraph: x86_64/pc machine node

In reply to 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.

---
 tests/Makefile.include           |   3 +
 tests/libqos/x86_64_pc-machine.c | 110 +++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 tests/libqos/x86_64_pc-machine.c
tests/Makefile.include +3 -0
index f04f9fbc3a..4e7b4bb614 100644
@@ -771,7 +771,10 @@ 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
 
+libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
+
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/x86_64_pc-machine.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

Re: [Qemu-devel] [PATCH v2 04/34] tests/qgraph: x86_64/pc machine node

Quoted 69 lines · 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.

---
 tests/Makefile.include           |   3 +
 tests/libqos/x86_64_pc-machine.c | 110 +++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 tests/libqos/x86_64_pc-machine.c
tests/Makefile.include +3 -0
index f04f9fbc3a..4e7b4bb614 100644
@@ -771,7 +771,10 @@ 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
 
+libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
+
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/x86_64_pc-machine.c new file +38 -0
new file mode 100644
index 0000000000..e3eddf2eba
@@ -0,0 +1,110 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "libqos/qgraph.h"
+#include "pci-pc.h"
+#include "malloc-pc.h"
+
+typedef struct QX86_64_PCMachine QX86_64_PCMachine;
+typedef struct i440FX_pcihost i440FX_pcihost;
+typedef struct QSDHCI_PCI  QSDHCI_PCI;
+
+struct i440FX_pcihost {
+    QOSGraphObject obj;
+    QPCIBusPC pci;
+};
+
+struct QX86_64_PCMachine {
+    QOSGraphObject obj;
+    QGuestAllocator *alloc;
+    i440FX_pcihost bridge;
+};

tests/libqos/x86_64_pc-machine.c line 48

Quoted 10 lines
tests/libqos/x86_64_pc-machine.c new file +10 -0
+
+/* 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;
+    }
+    printf("%s not present in i440FX-pcihost\n", device);

fprintf(stderr, ...

tests/libqos/x86_64_pc-machine.c line 49

Quoted 1 line
tests/libqos/x86_64_pc-machine.c new file +1 -0
+    abort();

g_assert_not_reached()

Quoted 12 lines
tests/libqos/x86_64_pc-machine.c new file +12 -0
+}
+
+static void qos_create_i440FX_host(i440FX_pcihost *host,
+                                   QGuestAllocator *alloc)
+{
+    host->obj.get_device = i440FX_host_get_device;
+    qpci_init_pc(&host->pci, global_qtest, alloc);
+}
+
+/* x86_64/pc machine */
+
+static void pc_destroy(QOSGraphObject *obj)

tests/libqos/x86_64_pc-machine.c line 71

Quoted 10 lines
tests/libqos/x86_64_pc-machine.c new file +10 -0
+{
+    QX86_64_PCMachine *machine = (QX86_64_PCMachine *) obj;
+    pc_alloc_uninit(machine->alloc);
+    g_free(machine);
+}
+
+static void *pc_get_driver(void *object, const char *interface)
+{
+    QX86_64_PCMachine *machine = object;
+    if (!g_strcmp0(interface, "guest_allocator")) {

Perhaps we can call that "memory" rather than "guest_allocator", as it gives access to the memory of the guest?

tests/libqos/x86_64_pc-machine.c line 75

Quoted 4 lines
tests/libqos/x86_64_pc-machine.c new file +4 -0
+        return machine->alloc;
+    }
+
+    printf("%s not present in x86_64/pc\n", interface);

fprintf(stderr, ...

tests/libqos/x86_64_pc-machine.c line 76

Quoted 1 line
tests/libqos/x86_64_pc-machine.c new file +1 -0
+    abort();

g_assert_not_reached()

tests/libqos/x86_64_pc-machine.c line 86

Quoted 10 lines
tests/libqos/x86_64_pc-machine.c new file +10 -0
+}
+
+static QOSGraphObject *pc_get_device(void *obj, const char *device)
+{
+    QX86_64_PCMachine *machine = obj;
+    if (!g_strcmp0(device, "i440FX-pcihost")) {
+        return &machine->bridge.obj;
+    }
+
+    printf("%s not present in x86_64/pc\n", device);

fprintf(stderr, ...

tests/libqos/x86_64_pc-machine.c line 87

Quoted 1 line
tests/libqos/x86_64_pc-machine.c new file +1 -0
+    abort();

g_assert_not_reached()

Quoted 10 lines
tests/libqos/x86_64_pc-machine.c new file +10 -0
+}
+
+static void *qos_create_machine_pc(void)
+{
+    QX86_64_PCMachine *machine = g_new0(QX86_64_PCMachine, 1);
+    machine->obj.get_device = pc_get_device;
+    machine->obj.get_driver = pc_get_driver;
+    machine->obj.destructor = pc_destroy;
+    machine->alloc = pc_alloc_init_flags(global_qtest, ALLOC_NO_FLAGS);
+    qos_create_i440FX_host(&machine->bridge, machine->alloc);

tests/libqos/x86_64_pc-machine.c line 107

Quoted 10 lines
tests/libqos/x86_64_pc-machine.c new file +10 -0
+
+    return &machine->obj;
+}
+
+static void pc_machine(void)
+{
+    qos_node_create_machine("x86_64/pc", qos_create_machine_pc);
+    qos_node_create_driver("i440FX-pcihost", NULL);
+    qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL);
+    qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL);

and qos_node_produces("x86_64/pc", "memory"); (or "guest_allocator")?

and perhaps later, a qos_add_test("test-memory-allocator", "memory", test_memory_allocator, NULL)?

tests/libqos/x86_64_pc-machine.c line 110

Quoted 3 lines
tests/libqos/x86_64_pc-machine.c new file +3 -0
+}
+
+libqos_init(pc_machine);

pc_machine_register_nodes?

Thanks,
Laurent

author
#12 lore raw

Re: [Qemu-devel] [PATCH v2 04/34] tests/qgraph: x86_64/pc machine node

Quoted 6 lines

Perhaps we can call that "memory" rather than "guest_allocator", as it gives access to the memory of the guest?
and qos_node_produces("x86_64/pc", "memory"); (or "guest_allocator")?

and perhaps later, a qos_add_test("test-memory-allocator", "memory", test_memory_allocator, NULL)?

I don't know, is there a test for the memory allocator? I gave it that name just because the actual structure representing it is called QGuestAllocator.

Thank you,
Emanuele

#13 lore raw

Re: [Qemu-devel] [PATCH v2 04/34] tests/qgraph: x86_64/pc machine node

Quoted 7 lines · Emanuele
Quoted 6 lines

Perhaps we can call that "memory"  rather than "guest_allocator", as it gives access to the memory of the guest?
and qos_node_produces("x86_64/pc", "memory");  (or "guest_allocator")?

and perhaps later, a qos_add_test("test-memory-allocator", "memory", test_memory_allocator, NULL)?

I don't know, is there a test for the memory allocator? I gave it that

No, I don't think so.

Quoted 2 lines

name just because the actual structure representing it is called QGuestAllocator.

Yes, you can give the name you want, but for me "memory" sounds nicer than "guest_allocator"...

Thanks,
Laurent

#14 lore raw

PATCH v2 5/34 tests/qgraph: sdhci driver and interface nodes

In reply to 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.

---
 tests/Makefile.include |   1 +
 tests/libqos/sdhci.c   | 163 +++++++++++++++++++++++++++++++++++++++++
 tests/libqos/sdhci.h   |  69 +++++++++++++++++
 3 files changed, 233 insertions(+)
 create mode 100644 tests/libqos/sdhci.c
 create mode 100644 tests/libqos/sdhci.h
tests/Makefile.include +1 -0
index 4e7b4bb614..be00fb71ec 100644
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/sdhci.c new file +163 -0

163 lines not on this page · raw message

tests/libqos/sdhci.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.17.1
#15 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

Quoted 18 lines · 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.

---
 tests/Makefile.include |   1 +
 tests/libqos/sdhci.c   | 163 +++++++++++++++++++++++++++++++++++++++++
 tests/libqos/sdhci.h   |  69 +++++++++++++++++
 3 files changed, 233 insertions(+)
 create mode 100644 tests/libqos/sdhci.c
 create mode 100644 tests/libqos/sdhci.h
tests/Makefile.include +0 -0
index 4e7b4bb614..be00fb71ec 100644

tests/Makefile.include libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o · line 778

Quoted 4 lines
tests/Makefile.include +1 -0
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += tests/libqos/sdhci.o

The file also implements memory mapped SDHCI, should we split the file in two files, one added to libqgraph-pci-obj-y and the other to check-qtest-arm-y and check-qtest-aarch64-y?

Quoted 42 lines
tests/Makefile.include +0 -0
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/sdhci.c new file +34 -0
new file mode 100644
index 0000000000..f5eb2c5459
@@ -0,0 +1,163 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+}
+

...

tests/libqos/sdhci.c line 57

Quoted 9 lines
tests/libqos/sdhci.c new file +9 -0
+static void sdhci_mm_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
+{
+    QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+    qtest_writeq(global_qtest, smm->addr + reg, val);
+}
+
+static void *sdhci_mm_get_driver(void *obj, const char *interface)
+{
+    QSDHCI_MemoryMapped *spci = obj;

You should call it "smm" rather than "spci"

tests/libqos/sdhci.c line 61

Quoted 4 lines
tests/libqos/sdhci.c new file +4 -0
+    if (!g_strcmp0(interface, "sdhci")) {
+        return &spci->sdhci;
+    }
+    printf("%s not present in generic-sdhci\n", interface);

fprintf(stderr, ....

Quoted 1 line

+ abort();

g_assert_not_reached()

tests/libqos/sdhci.c line 65

Quoted 3 lines
tests/libqos/sdhci.c new file +3 -0
+}
+
+void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,

To be consistent with previous functions, you should it "smm" rather than "sdhci".

...

Quoted 1 line

+/* PCI implementation of QSDHCI */

...

tests/libqos/sdhci.c

Quoted 2 lines
tests/libqos/sdhci.c new file +2 -0
+
+static uint64_t sdhci_readq(QSDHCI *s, uint32_t reg)

"sdhci_pci_readq()"

tests/libqos/sdhci.c line 90

Quoted 6 lines
tests/libqos/sdhci.c new file +6 -0
+{
+    QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+    return qpci_io_readq(&spci->dev, spci->mem_bar, reg);
+}
+
+static void sdhci_writeq(QSDHCI *s, uint32_t reg, uint64_t val)

"sdhci_pci_writeq()"

tests/libqos/sdhci.c line 103

Quoted 13 lines
tests/libqos/sdhci.c new file +13 -0
+{
+    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;
+    }
+
+    printf("%s not present in sdhci-pci\n", interface);

fprintf(stderr, ...

Quoted 1 line

+ abort();

g_assert_not_reached()

tests/libqos/sdhci.c line 107

Quoted 3 lines
tests/libqos/sdhci.c new file +3 -0
+}
+
+static void sdhci_start_hw(QOSGraphObject *obj)

perhaps you can call this "sdhci_pci_start_hw()"?

tests/libqos/sdhci.c line 113

Quoted 6 lines
tests/libqos/sdhci.c new file +6 -0
+{
+    QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+    qpci_device_enable(&spci->dev);
+}
+
+static void sdhci_destroy(QOSGraphObject *obj)

"sdhci_pci_destructor()"?

Quoted 6 lines
tests/libqos/sdhci.c new file +6 -0
+{
+    QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+    qpci_iounmap(&spci->dev, spci->mem_bar);
+    g_free(spci);
+}
+

tests/libqos/sdhci.c line 129

Quoted 10 lines
tests/libqos/sdhci.c new file +10 -0
+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_readq;

... = sdhci_pci_readq;

Quoted 1 line

+ spci->sdhci.writeq = sdhci_writeq;

... = sdhci_pci_writeq;

Quoted 23 lines
tests/libqos/sdhci.c new file +23 -0
+    set_qsdhci_fields(&spci->sdhci, 2, 0, 1, 0x057834b4);
+
+    spci->obj.get_driver = sdhci_pci_get_driver;
+    spci->obj.start_hw = sdhci_start_hw;
+    spci->obj.destructor = sdhci_destroy;
+    return &spci->obj;
+}
+
+static void qsdhci(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");

tests/libqos/sdhci.c line 163

Quoted 10 lines
tests/libqos/sdhci.c new file +10 -0
+
+    /* 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);

Perhaps we can have two functions qsdhci_mm_register_nodes() and qsdhci_pci_register_nodes(), with two libqos_init() and split the file in two files sdhci_pci.c and sdhci_mm.c?

Thanks,
Laurent

#16 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

Quoted 7 lines · Laurent Vivier
Quoted 3 lines

libqgraph-pci-obj-y = $(libqos-pc-obj-y) libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += tests/libqos/sdhci.o

The file also implements memory mapped SDHCI, should we split the file in two files, one added to libqgraph-pci-obj-y and the other to check-qtest-arm-y and check-qtest-aarch64-y?

No, there is only one libqgraph. The same test (qos-test) can run for both PCI and non-PCI machines, and will cull the unnecessary part of the graph automatically simply because there is no path from a machine to a PCI device.

Paolo

#17 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Laurent Vivier
Quoted 3 lines

libqgraph-pci-obj-y = $(libqos-pc-obj-y) libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += tests/libqos/sdhci.o

The file also implements memory mapped SDHCI, should we split the file in two files, one added to libqgraph-pci-obj-y and the other to check-qtest-arm-y and check-qtest-aarch64-y?

Quoted 4 lines

No, there is only one libqgraph. The same test (qos-test) can run for both PCI and non-PCI machines, and will cull the unnecessary part of the graph automatically simply because there is no path from a machine to a PCI device.

So, all libqgraph files should be added to check-qtest-generic-y?

Thanks,
Laurent

#18 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

Quoted 5 lines · Laurent Vivier
Quoted 4 lines

No, there is only one libqgraph. The same test (qos-test) can run for both PCI and non-PCI machines, and will cull the unnecessary part of the graph automatically simply because there is no path from a machine to a PCI device.

So, all libqgraph files should be added to check-qtest-generic-y?

Yes.

Paolo

author
#19 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

In reply to Laurent Vivier
Quoted 8 lines

tests/libqos/sdhci.c line 113

Quoted 7 lines
tests/libqos/sdhci.c new file +6 -0
+{
+    QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+    qpci_device_enable(&spci->dev);
+}
+
+static void sdhci_destroy(QOSGraphObject *obj)

"sdhci_pci_destructor()"?

In general, I called the constructor name  *_create, so in theory to keep it consistent the destructor should be *_destroy, no?

Thank you,
Emanuele

#20 lore raw

Re: [Qemu-devel] [PATCH v2 05/34] tests/qgraph: sdhci driver and interface nodes

Quoted 10 lines · Emanuele
Quoted 8 lines

tests/libqos/sdhci.c line 113

Quoted 7 lines
tests/libqos/sdhci.c new file +6 -0
+{
+    QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+    qpci_device_enable(&spci->dev);
+}
+
+static void sdhci_destroy(QOSGraphObject *obj)

"sdhci_pci_destructor()"?

In general, I called the constructor name  *_create, so in theory to keep it consistent the destructor should be *_destroy, no?

Yes, but the field name in QOSGraphObject is "destructor".

You have:

    obj.get_device = XXX_get_device;
    obj.get_driver = XXX_get_driver;
    obj.start_hw   = XXX_start_hw;

So we can expect:

   obj.destructor = XXX_destructor;

Thanks,
Laurent

#21 lore raw

PATCH v2 6/34 tests/qgraph: sdhci test node

In reply to 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

---
 tests/Makefile.include |   9 +-
 tests/sdhci-test.c     | 222 ++++++++++++-----------------------------
 2 files changed, 68 insertions(+), 163 deletions(-)
tests/Makefile.include +4 -5
index be00fb71ec..fec6cf35bb 100644
@@ -311,7 +311,6 @@ check-qtest-i386-y += tests/migration-test$(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-y += tests/sdhci-test$(EXESUF)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
 
@@ -385,10 +384,8 @@ gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
-check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
-check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
@@ -777,11 +774,14 @@ libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
+libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
+libqgraph-tests-obj-y += tests/sdhci-test.o
+
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
 check-qtest-pci-y += tests/qos-test$(EXESUF)
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-pci-obj-y)
+tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-tests-obj-y)
 
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
@@ -867,7 +867,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
tests/sdhci-test.c +64 -158

286 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v2 6/34
#22 lore raw

Re: [Qemu-devel] [PATCH v2 06/34] tests/qgraph: sdhci test node

Quoted 12 lines · 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

---
 tests/Makefile.include |   9 +-
 tests/sdhci-test.c     | 222 ++++++++++++-----------------------------
 2 files changed, 68 insertions(+), 163 deletions(-)

...

tests/sdhci-test.c static void check_capab_v3(QSDHCI *s, uint8_t version) · line 158

Quoted 2 lines
tests/sdhci-test.c +2 -0
+
+libqos_init(sdhci_test);

"libqos_init(register_sdhci_tests)"?

Thanks,
Laurent

#23 lore raw

PATCH v2 7/34 tests/qgraph: arm/raspi2 machine node

In reply to 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.

---
 tests/Makefile.include        |  1 +
 tests/libqos/raspi2-machine.c | 82 +++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 tests/libqos/raspi2-machine.c
tests/Makefile.include +1 -0
index fec6cf35bb..d826a09919 100644
@@ -769,6 +769,7 @@ 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
 
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
+libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/raspi2-machine.c new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.17.1
#24 lore raw

Re: [Qemu-devel] [PATCH v2 07/34] tests/qgraph: arm/raspi2 machine node

Quoted 9 lines · 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.

---
 tests/Makefile.include        |  1 +
 tests/libqos/raspi2-machine.c | 82 +++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 tests/libqos/raspi2-machine.c

globally, same cosmetic comments (destructor, fprintf, register, ...) as for PC, otherwise it looks good.

Thanks,
Laurent

#25 lore raw

PATCH v2 8/34 tests/qgraph: rename qpci_init_spapr functions

In reply to Emanuele Giuseppe Esposito

Rename qpci_init_spapr in qpci_new_spapr, since the function actually allocates a new QPCIBusSPAPR and initialize it.

---
 tests/libqos/libqos-spapr.c | 2 +-
 tests/libqos/pci-spapr.c    | 2 +-
 tests/libqos/pci-spapr.h    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
tests/libqos/libqos-spapr.c +1 -1
index a37791e5d0..b3ba421cee 100644
@@ -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_init = qpci_spapr_new,
     .qpci_free = qpci_free_spapr,
     .shutdown = qtest_spapr_shutdown,
 };
tests/libqos/pci-spapr.c +1 -1
index c0f7e6db9b..30b6d5b5a7 100644
@@ -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_spapr_new(QTestState *qts, QGuestAllocator *alloc)
 {
     QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1);
 
tests/libqos/pci-spapr.h +1 -1
index 387686dfc8..d5305d16f8 100644
@@ -11,7 +11,7 @@
 #include "libqos/malloc.h"
 #include "libqos/pci.h"
 
-QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc);
+QPCIBus *qpci_spapr_new(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_spapr(QPCIBus *bus);
 
 #endif
Signature · 1 line
2.17.1
#26 lore raw

Re: [Qemu-devel] [PATCH v2 08/34] tests/qgraph: rename qpci_init_spapr functions

Quoted 3 lines · Emanuele Giuseppe Esposito

Rename qpci_init_spapr in qpci_new_spapr, since the function actually allocates a new QPCIBusSPAPR and initialize it.

I think you should merge this one with 02/34.

Thanks,
Laurent

#27 lore raw

PATCH v2 9/34 tests/qgraph: pci-spapr driver and interface nodes

In reply to 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.

---
 tests/Makefile.include   |  2 +-
 tests/libqos/pci-spapr.c | 57 ++++++++++++++++++++++++----------------
 tests/libqos/pci-spapr.h | 24 +++++++++++++++++
 3 files changed, 59 insertions(+), 24 deletions(-)
tests/Makefile.include +1 -1
index d826a09919..5ce905bd82 100644
@@ -771,7 +771,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 
-libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
tests/libqos/pci-spapr.c +34 -23

91 lines not on this page · raw message

tests/libqos/pci-spapr.h +24 -0
index d5305d16f8..74cd183c9a 100644
@@ -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_spapr_new(QTestState *qts, QGuestAllocator *alloc);
 void     qpci_free_spapr(QPCIBus *bus);
 
Signature · 1 line
2.17.1
#28 lore raw

Re: [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes

Quoted 11 lines · 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.

---
 tests/Makefile.include   |  2 +-
 tests/libqos/pci-spapr.c | 57 ++++++++++++++++++++++++----------------
 tests/libqos/pci-spapr.h | 24 +++++++++++++++++
 3 files changed, 59 insertions(+), 24 deletions(-)

globally, same comments as for pci-pc.c

Thanks,
Laurent

#29 lore raw

Re: [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes

In reply to Emanuele Giuseppe Esposito

tests/libqos/pci-spapr.c static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, · line 159

Quoted 7 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-spapr.c +5 -0
+void qpci_init_spapr(QPCIBusSPAPR *ret, QTestState *qts, QGuestAllocator *alloc)
+{
     assert(qts);
 
+    /* tests cannot use spapr, needs to be fixed first */
+    ret->bus.has_buggy_msi = TRUE;
+

Perhaps you can revert the logic and call that "msi_is_available"? It's more generic than "buggy". It says if we can or not use MSI.

Thanks,
Laurent

author
#30 lore raw

Re: [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes

Quoted 10 lines · Laurent Vivier

tests/libqos/pci-spapr.c static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset, · line 159

Quoted 7 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-spapr.c +5 -0
+void qpci_init_spapr(QPCIBusSPAPR *ret, QTestState *qts, QGuestAllocator *alloc)
+{
      assert(qts);
 
+    /* tests cannot use spapr, needs to be fixed first */
+    ret->bus.has_buggy_msi = TRUE;
+

Perhaps you can revert the logic and call that "msi_is_available"? It's more generic than "buggy". It says if we can or not use MSI.

This name was suggested by Paolo, I honestly don't know which is better, maybe it's better to ask him for this.

Quoted 2 lines

Thanks,
Laurent

#31 lore raw

Re: [Qemu-devel] [PATCH v2 09/34] tests/qgraph: pci-spapr driver and interface nodes

Quoted 13 lines · Emanuele
Quoted 10 lines · Laurent Vivier
Quoted 7 lines · Emanuele Giuseppe Esposito

+void qpci_init_spapr(QPCIBusSPAPR *ret, QTestState *qts, QGuestAllocator *alloc)
+{
      assert(qts);
  +    /* tests cannot use spapr, needs to be fixed first */ +    ret->bus.has_buggy_msi = TRUE;
+

Perhaps you can revert the logic and call that "msi_is_available"? It's more generic than "buggy". It says if we can or not use MSI.

Quoted 2 lines

This name was suggested by Paolo, I honestly don't know which is better, maybe it's better to ask him for this.

The MSIs here are not interrupts, they are just random memory writes. Even if it's not clear if the bug is in libqos or QEMU, there is no reason why they shouldn't work.

Paolo

#32 lore raw

PATCH v2 10/34 tests/qgraph: ppc64/pseries machine node

In reply to 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.

---
 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
tests/Makefile.include +1 -0
index 5ce905bd82..b86aa52546 100644
@@ -770,6 +770,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt
 
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
+libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/ppc64_pseries-machine.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
2.17.1
#33 lore raw

PATCH v2 11/34 test/qgraph: e1000e driver and interface nodes

In reply to 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).

---
 tests/Makefile.include |   1 +
 tests/libqos/e1000e.c  | 262 +++++++++++++++++++++++++++++++++++++++++
 tests/libqos/e1000e.h  |  53 +++++++++
 3 files changed, 316 insertions(+)
 create mode 100644 tests/libqos/e1000e.c
 create mode 100644 tests/libqos/e1000e.h
tests/Makefile.include +1 -0
index b86aa52546..66d6270ace 100644
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
+libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
tests/libqos/e1000e.c new file +262 -0

262 lines not on this page · raw message

tests/libqos/e1000e.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.17.1
#34 lore raw

PATCH v2 12/34 test/qgraph: e1000e-test node

In reply to 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

---
 tests/Makefile.include |   3 +-
 tests/e1000e-test.c    | 354 +++++++++--------------------------------
 2 files changed, 78 insertions(+), 279 deletions(-)
tests/Makefile.include +1 -2
index 66d6270ace..50f1af34be 100644
@@ -213,7 +213,6 @@ gcov-files-virtio-y += $(gcov-files-virtioserial-y)
 
 check-qtest-pci-y += tests/e1000-test$(EXESUF)
 gcov-files-pci-y += hw/net/e1000.c
-check-qtest-pci-y += tests/e1000e-test$(EXESUF)
 gcov-files-pci-y += hw/net/e1000e.c hw/net/e1000e_core.c
 check-qtest-pci-y += tests/rtl8139-test$(EXESUF)
 gcov-files-pci-y += hw/net/rtl8139.c
@@ -779,6 +778,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
+libqgraph-tests-obj-y += tests/e1000e-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -813,7 +813,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
tests/e1000e-test.c +77 -277

422 lines not on this page · raw message

Signature · 1 line
2.17.1
#35 lore raw

PATCH v2 13/34 test/qgraph: virtio_start_device function

In reply to 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.

---
 tests/libqos/virtio.c    |  8 ++++++++
 tests/libqos/virtio.h    |  1 +
 tests/vhost-user-test.c  |  5 +----
 tests/virtio-9p-test.c   |  6 +-----
 tests/virtio-blk-test.c  | 18 ++----------------
 tests/virtio-net-test.c  |  6 +-----
 tests/virtio-scsi-test.c |  4 +---
 7 files changed, 15 insertions(+), 33 deletions(-)
tests/libqos/virtio.c +8 -0
index 0dad5c19ac..56007ef11b 100644
@@ -365,3 +365,11 @@ 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);
+    qvirtio_set_driver_ok(vdev);
+}
tests/libqos/virtio.h +1 -0
index 69b5b13840..2c68668de0 100644
@@ -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
tests/vhost-user-test.c +1 -4
index a01b81d342..c8270fa6ed 100644
@@ -198,9 +198,7 @@ static void init_virtio_dev(TestServer *s, uint32_t features_mask)
     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(global_qtest);
 
@@ -212,7 +210,6 @@ static void init_virtio_dev(TestServer *s, uint32_t features_mask)
     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)
tests/virtio-9p-test.c +1 -5
index a2b31085f6..4f4a1fb8b4 100644
@@ -65,14 +65,10 @@ 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);
 
-    qvirtio_set_driver_ok(v9p->dev);
-
     return v9p;
 }
 
tests/virtio-blk-test.c +2 -16
index 9be9ffb378..3e8f98e528 100644
@@ -112,10 +112,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;
 }
 
@@ -174,8 +171,6 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
                     (1u << VIRTIO_BLK_F_SCSI));
     qvirtio_set_features(dev, features);
 
-    qvirtio_set_driver_ok(dev);
-
     /* Write and read with 3 descriptor layout */
     /* Write request */
     req.type = VIRTIO_BLK_T_OUT;
@@ -329,7 +324,6 @@ static void pci_indirect(void)
     qvirtio_set_features(&dev->vdev, features);
 
     vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
-    qvirtio_set_driver_ok(&dev->vdev);
 
     /* Write request */
     req.type = VIRTIO_BLK_T_OUT;
@@ -407,8 +401,6 @@ static void pci_config(void)
     capacity = qvirtio_config_readq(&dev->vdev, 0);
     g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
 
-    qvirtio_set_driver_ok(&dev->vdev);
-
     qmp_discard_response("{ 'execute': 'block_resize', "
                          " 'arguments': { 'device': 'drive0', "
                          " 'size': %d } }", n_size);
@@ -457,8 +449,6 @@ static void pci_msix(void)
     vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
     qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1);
 
-    qvirtio_set_driver_ok(&dev->vdev);
-
     qmp_discard_response("{ 'execute': 'block_resize', "
                          " 'arguments': { 'device': 'drive0', "
                          " 'size': %d } }", n_size);
@@ -565,8 +555,6 @@ static void pci_idx(void)
     vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
     qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1);
 
-    qvirtio_set_driver_ok(&dev->vdev);
-
     /* Write request */
     req.type = VIRTIO_BLK_T_OUT;
     req.ioprio = 1;
@@ -715,9 +703,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);
tests/virtio-net-test.c +1 -5
index b285a262e9..b2a5f5a350 100644
@@ -45,9 +45,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;
 }
@@ -80,8 +78,6 @@ static void driver_init(QVirtioDevice *dev)
                             (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,
tests/virtio-scsi-test.c +1 -3
index 037872bb98..1581b6926c 100644
@@ -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);
 
Signature · 1 line
2.17.1
#36 lore raw

Re: [Qemu-devel] [PATCH v2 13/34] test/qgraph: virtio_start_device function

Quoted 20 lines · 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.

---
 tests/libqos/virtio.c    |  8 ++++++++
 tests/libqos/virtio.h    |  1 +
 tests/vhost-user-test.c  |  5 +----
 tests/virtio-9p-test.c   |  6 +-----
 tests/virtio-blk-test.c  | 18 ++----------------
 tests/virtio-net-test.c  |  6 +-----
 tests/virtio-scsi-test.c |  4 +---
 7 files changed, 15 insertions(+), 33 deletions(-)
tests/libqos/virtio.c +0 -0
index 0dad5c19ac..56007ef11b 100644

tests/libqos/virtio.c const char *qvirtio_get_dev_type(void) · line 374

Quoted 10 lines
tests/libqos/virtio.c +7 -0
@@ -365,3 +365,11 @@ 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);
+    qvirtio_set_driver_ok(vdev);

I'm not sure you can put qvirtio_set_driver_ok() here.

qvirtio_set_driver_ok() must be called when the driver is OK, it means that the virtio device must be fully initialized before (features, virtqueue, MSI, ...).

http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf

3.1.1 Driver Requirements: Device Initialization

The driver MUST follow this sequence to initialize a device:

1. Reset the device.

2. Set the ACKNOWLEDGE status bit: the guest OS has notice the device.

3. Set the DRIVER status bit: the guest OS knows how to drive the device.

4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.

5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.

6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.

7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.

8. Set the DRIVER_OK status bit. At this point the device is “live”.

Thanks,
Laurent

author
#37 lore raw

Re: [Qemu-devel] [PATCH v2 13/34] test/qgraph: virtio_start_device function

Quoted 67 lines · Laurent Vivier
Quoted 20 lines · 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.

---
  tests/libqos/virtio.c    |  8 ++++++++
  tests/libqos/virtio.h    |  1 +
  tests/vhost-user-test.c  |  5 +----
  tests/virtio-9p-test.c   |  6 +-----
  tests/virtio-blk-test.c  | 18 ++----------------
  tests/virtio-net-test.c  |  6 +-----
  tests/virtio-scsi-test.c |  4 +---
  7 files changed, 15 insertions(+), 33 deletions(-)
tests/libqos/virtio.c +0 -0
index 0dad5c19ac..56007ef11b 100644

tests/libqos/virtio.c const char *qvirtio_get_dev_type(void) · line 374

Quoted 10 lines
tests/libqos/virtio.c +7 -0
@@ -365,3 +365,11 @@ 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);
+    qvirtio_set_driver_ok(vdev);

I'm not sure you can put qvirtio_set_driver_ok() here.

qvirtio_set_driver_ok() must be called when the driver is OK, it means that the virtio device must be fully initialized before (features, virtqueue, MSI, ...).

http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf

3.1.1 Driver Requirements: Device Initialization

The driver MUST follow this sequence to initialize a device:

1. Reset the device.

2. Set the ACKNOWLEDGE status bit: the guest OS has notice the device.

3. Set the DRIVER status bit: the guest OS knows how to drive the device.

4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the
device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration
fields to check that it can support the device before accepting it.

5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step.

6. Re-read device status to ensure the FEATURES_OK bit is still set:
otherwise, the device does not
support our subset of features and the device is unusable.

7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup,
reading and possibly writing the device’s virtio configuration space, and population of virtqueues.

Quoted 4 lines

8. Set the DRIVER_OK status bit. At this point the device is “live”.

Thanks,
Laurent

You're right, I removed qvirtio_set_driver_ok from qvirtio_start_device and put it back where it was before.
I noticed that while virtqueues need to have features set before they are setup, the device still works even though features are set after the ok.

Thank you,
Emanuele

#38 lore raw

PATCH v2 14/34 test/qgraph: virtio-pci driver and interface nodes

In reply to 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)

---
 tests/Makefile.include    |  2 +-
 tests/libqos/virtio-pci.c | 80 +++++++++++++++++++++++++++++++--------
 tests/libqos/virtio-pci.h | 12 ++++++
 3 files changed, 77 insertions(+), 17 deletions(-)
tests/Makefile.include +1 -1
index 50f1af34be..8dfbe049e7 100644
@@ -771,7 +771,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 
-libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
+libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 libqgraph-pci-obj-y += tests/libqos/e1000e.o
tests/libqos/virtio-pci.c +64 -16

190 lines not on this page · raw message

tests/libqos/virtio-pci.h +12 -0
index 6ef19094cb..2df71861bf 100644
@@ -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,10 +33,20 @@ typedef struct QVirtQueuePCI {
 
 extern const QVirtioBus qvirtio_pci;
 
+void virtio_pci_init(QVirtioPCIDevice *dev, 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_destroy(QOSGraphObject *obj);
+void qvirtio_pci_start_hw(QOSGraphObject *obj);
+
 
 void qvirtio_pci_device_enable(QVirtioPCIDevice *d);
 void qvirtio_pci_device_disable(QVirtioPCIDevice *d);
Signature · 1 line
2.17.1
#39 lore raw

Re: [Qemu-devel] [PATCH v2 14/34] test/qgraph: virtio-pci driver and interface nodes

tests/libqos/virtio-pci.c void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, · line 446

Quoted 13 lines · Emanuele Giuseppe Esposito
tests/libqos/virtio-pci.c +13 -0
+void qvirtio_pci_destroy(QOSGraphObject *obj)
+{
+    QVirtioPCIDevice *v9p = (QVirtioPCIDevice *)obj;
+    qvirtio_pci_device_disable(v9p);
+    qvirtio_pci_device_free(v9p);
+}
+
+void qvirtio_pci_start_hw(QOSGraphObject *obj)
+{
+    QVirtioPCIDevice *v9p = (QVirtioPCIDevice *)obj;
+    qvirtio_pci_device_enable(v9p);
+    qvirtio_start_device(&v9p->vdev);
+}

Perhaps you can use a generic name rather than v9p?

Thanks,
Laurent

#40 lore raw

PATCH v2 15/34 tests/qgraph: rename qvirtio_mmio_init_device functions

In reply to Emanuele Giuseppe Esposito

Rename qvirtio_mmio_init_device in qvirtio_mmio_device_new, since the function actually allocates a new QVirtioMMIODevice and initialize it.

---
 tests/libqos/virtio-mmio.c | 2 +-
 tests/libqos/virtio-mmio.h | 2 +-
 tests/virtio-blk-test.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
tests/libqos/virtio-mmio.c +1 -1
index 7aa8383338..6f4c1b0955 100644
@@ -187,7 +187,7 @@ const QVirtioBus qvirtio_mmio = {
     .virtqueue_kick = qvirtio_mmio_virtqueue_kick,
 };
 
-QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size)
+QVirtioMMIODevice *qvirtio_mmio_device_new(uint64_t addr, uint32_t page_size)
 {
     QVirtioMMIODevice *dev;
     uint32_t magic;
tests/libqos/virtio-mmio.h +1 -1
index e3e52b9ce1..bcc09895fd 100644
@@ -41,6 +41,6 @@ typedef struct QVirtioMMIODevice {
 
 extern const QVirtioBus qvirtio_mmio;
 
-QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size);
+QVirtioMMIODevice *qvirtio_mmio_device_new(uint64_t addr, uint32_t page_size);
 
 #endif
tests/virtio-blk-test.c +1 -1
index 3e8f98e528..267cf28376 100644
@@ -699,7 +699,7 @@ static void mmio_basic(void)
 
     arm_test_start();
 
-    dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);
+    dev = qvirtio_mmio_device_new(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);
     g_assert(dev != NULL);
     g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
 
Signature · 1 line
2.17.1
#41 lore raw

Re: [Qemu-devel] [PATCH v2 15/34] tests/qgraph: rename qvirtio_mmio_init_device functions

Quoted 9 lines · Emanuele Giuseppe Esposito

Rename qvirtio_mmio_init_device in qvirtio_mmio_device_new, since the function actually allocates a new QVirtioMMIODevice and initialize it.

---
 tests/libqos/virtio-mmio.c | 2 +-
 tests/libqos/virtio-mmio.h | 2 +-
 tests/virtio-blk-test.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

I think you can merge this patch with the following one because the only reason you do that is to be able to define a new qvirtio_mmio_init() of your own.

Thanks,
Laurent

#42 lore raw

PATCH v2 16/34 test/qgraph: virtio-mmio driver and interface nodes

In reply to Emanuele Giuseppe Esposito

Add virtio-mmio node in qgraph framework.
virtio-mmio produces virtio, 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.

---
 tests/libqos/virtio-mmio.c | 70 ++++++++++++++++++++++++++++----------
 tests/libqos/virtio-mmio.h |  4 +++
 2 files changed, 56 insertions(+), 18 deletions(-)
tests/libqos/virtio-mmio.c +52 -18
index 6f4c1b0955..68bceb9a17 100644
@@ -13,42 +13,43 @@
 #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;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return readb(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint16_t qvirtio_mmio_config_readw(QVirtioDevice *d, uint64_t off)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return readw(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint32_t qvirtio_mmio_config_readl(QVirtioDevice *d, uint64_t off)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return readl(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint64_t qvirtio_mmio_config_readq(QVirtioDevice *d, uint64_t off)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return readq(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint32_t qvirtio_mmio_get_features(QVirtioDevice *d)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     writel(dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0);
     return readl(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);
@@ -56,25 +57,25 @@ static void qvirtio_mmio_set_features(QVirtioDevice *d, uint32_t 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;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return (uint8_t)readl(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS);
 }
 
 static void qvirtio_mmio_set_status(QVirtioDevice *d, uint8_t status)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     writel(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;
@@ -88,7 +89,7 @@ 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;
@@ -102,7 +103,7 @@ 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;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     writel(dev->addr + QVIRTIO_MMIO_QUEUE_SEL, (uint32_t)index);
 
     g_assert_cmphex(readl(dev->addr + QVIRTIO_MMIO_QUEUE_PFN), ==, 0);
@@ -110,20 +111,20 @@ static void qvirtio_mmio_queue_select(QVirtioDevice *d, uint16_t index)
 
 static uint16_t qvirtio_mmio_get_queue_size(QVirtioDevice *d)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     return (uint16_t)readl(dev->addr + QVIRTIO_MMIO_QUEUE_NUM_MAX);
 }
 
 static void qvirtio_mmio_set_queue_address(QVirtioDevice *d, uint32_t pfn)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     writel(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;
 
@@ -163,7 +164,7 @@ static void qvirtio_mmio_virtqueue_cleanup(QVirtQueue *vq,
 
 static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq)
 {
-    QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+    QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
     writel(dev->addr + QVIRTIO_MMIO_QUEUE_NOTIFY, vq->index);
 }
 
@@ -187,12 +188,36 @@ const QVirtioBus qvirtio_mmio = {
     .virtqueue_kick = qvirtio_mmio_virtqueue_kick,
 };
 
+static void *qvirtio_mmio_get_driver(void *obj, const char *interface)
+{
+    QVirtioMMIODevice *virtio_mmio = obj;
+    if (!g_strcmp0(interface, "virtio")) {
+        return &virtio_mmio->vdev;
+    }
+    printf("%s not present in virtio-mmio\n", interface);
+    abort();
+}
+
 QVirtioMMIODevice *qvirtio_mmio_device_new(uint64_t addr, uint32_t page_size)
 {
     QVirtioMMIODevice *dev;
-    uint32_t magic;
     dev = g_malloc0(sizeof(*dev));
 
+    qvirtio_mmio_init_device(dev, addr, page_size);
+
+    return dev;
+}
+
+static void qvirtio_mmio_start_hw(QOSGraphObject *obj)
+{
+    QVirtioMMIODevice *dev = (QVirtioMMIODevice *) obj;
+    qvirtio_start_device(&dev->vdev);
+}
+
+void qvirtio_mmio_init_device(QVirtioMMIODevice *dev, uint64_t addr,
+                             uint32_t page_size)
+{
+    uint32_t magic;
     magic = readl(addr + QVIRTIO_MMIO_MAGIC_VALUE);
     g_assert(magic == ('v' | 'i' << 8 | 'r' << 16 | 't' << 24));
 
@@ -203,5 +228,14 @@ QVirtioMMIODevice *qvirtio_mmio_device_new(uint64_t addr, uint32_t page_size)
 
     writel(addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size);
 
-    return dev;
+    dev->obj.get_driver = qvirtio_mmio_get_driver;
+    dev->obj.start_hw = qvirtio_mmio_start_hw;
 }
+
+static void virtio_mmio(void)
+{
+    qos_node_create_driver("virtio-mmio", NULL);
+    qos_node_produces("virtio-mmio", "virtio");
+}
+
+libqos_init(virtio_mmio);
tests/libqos/virtio-mmio.h +4 -0
index bcc09895fd..9d5af70cfc 100644
@@ -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,6 +34,7 @@
 #define QVIRTIO_MMIO_DEVICE_SPECIFIC    0x100
 
 typedef struct QVirtioMMIODevice {
+    QOSGraphObject obj;
     QVirtioDevice vdev;
     uint64_t addr;
     uint32_t page_size;
@@ -42,5 +44,7 @@ typedef struct QVirtioMMIODevice {
 extern const QVirtioBus qvirtio_mmio;
 
 QVirtioMMIODevice *qvirtio_mmio_device_new(uint64_t addr, uint32_t page_size);
+void qvirtio_mmio_init_device(QVirtioMMIODevice *dev, uint64_t addr,
+                             uint32_t page_size);
 
 #endif
Signature · 1 line
2.17.1
Reviewed-by on v2 16/34
#43 lore raw

Re: [Qemu-devel] [PATCH v2 16/34] test/qgraph: virtio-mmio driver and interface nodes

Quoted 4 lines · Emanuele Giuseppe Esposito

Add virtio-mmio node in qgraph framework.
virtio-mmio produces virtio, the interface consumed by all virtio-*-device nodes.

Quoted 8 lines

Being a memory-mapped device, it doesn't have to provide a constructor to qgraph, since it's always "contained" inside some other nodes.

---
 tests/libqos/virtio-mmio.c | 70 ++++++++++++++++++++++++++++----------
 tests/libqos/virtio-mmio.h |  4 +++
 2 files changed, 56 insertions(+), 18 deletions(-)
#44 lore raw

PATCH v2 17/34 test/qgraph: arm/virt machine node

In reply to 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.

---
 tests/Makefile.include      |  1 +
 tests/libqos/virt-machine.c | 90 +++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 tests/libqos/virt-machine.c
tests/Makefile.include +1 -0
index 8dfbe049e7..4659785baf 100644
@@ -770,6 +770,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
+libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virt-machine.c new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
2.17.1
#45 lore raw

PATCH v2 18/34 tests: virtio: separate ccw tests from libqos

In reply to Emanuele Giuseppe Esposito

From: Paolo Bonzini <[email protected]>

Because qtest does not support s390 channel I/O, s390 only performs smoke tests on those few devices that do not have any functional tests. Therefore, every time we add functional tests for a virtio device, the choice is between removing those tests from the s390 suite (so that s390 actually _loses_ coverage) or sprinkling the test with architecture checks.

This patch simply creates a ccw-specific test that only performs smoke tests on all virtio-ccw devices. If channel I/O support is ever added to qtest and libqos, then this file can go away. In the meanwhile, it simplifies maintenance and makes sure that all virtio devices are tested.

---
 tests/Makefile.include  |   5 +-
 tests/virtio-ccw-test.c | 121 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+), 3 deletions(-)
 create mode 100644 tests/virtio-ccw-test.c
tests/Makefile.include +2 -3
index 4659785baf..d72d0d65b4 100644
@@ -397,9 +397,7 @@ check-qtest-s390x-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-console-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
+check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -824,6 +822,7 @@ 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)
 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-ccw-test.c new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.17.1
#46 lore raw

Re: [Qemu-devel] [PATCH v2 18/34] tests: virtio: separate ccw tests from libqos

Quoted 8 lines · Emanuele Giuseppe Esposito

From: Paolo Bonzini <[email protected]>

Because qtest does not support s390 channel I/O, s390 only performs smoke tests on those few devices that do not have any functional tests. Therefore, every time we add functional tests for a virtio device, the choice is between removing those tests from the s390 suite (so that s390 actually _loses_ coverage) or sprinkling the test with architecture checks.

Quoted 7 lines

This patch simply creates a ccw-specific test that only performs smoke tests on all virtio-ccw devices. If channel I/O support is ever added to qtest and libqos, then this file can go away. In the meanwhile, it simplifies maintenance and makes sure that all virtio devices are tested.

You can add the "Acked-by" from Cornelia and the "Reviewed-by" from Thomas.

Thanks,
Laurent

#47 lore raw

PATCH v2 19/34 test/qgraph: virtio-serial driver and interface nodes

In reply to 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 and implements its own functions

---
 tests/Makefile.include       |   3 +
 tests/libqos/virtio-serial.c | 109 +++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-serial.h |  39 +++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 tests/libqos/virtio-serial.c
 create mode 100644 tests/libqos/virtio-serial.h
tests/Makefile.include +3 -0
index d72d0d65b4..ad784a3e84 100644
@@ -770,8 +770,11 @@ libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
+libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
+
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-virtio-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
tests/libqos/virtio-serial.c new file +109 -0

109 lines not on this page · raw message

tests/libqos/virtio-serial.h new file +39 -0
new file mode 100644
index 0000000000..b7e2a5d178
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+};
Signature · 1 line
2.17.1
#48 lore raw

PATCH v2 20/34 test/qgraph: virtio-console test node

In reply to Emanuele Giuseppe Esposito

Convert tests/virtio-console-test in qgraph test node, virtio-console-test. 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 structure, it's all done by the qtest walking graph mechanism

---
 tests/Makefile.include      |  5 +++--
 tests/libqos/virtio.c       |  1 +
 tests/virtio-console-test.c | 30 +++++++++++++++---------------
 3 files changed, 19 insertions(+), 17 deletions(-)
tests/Makefile.include +3 -2
index ad784a3e84..6742f97058 100644
@@ -187,7 +187,6 @@ gcov-files-ipack-y += hw/ipack/ipack.c
 check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF)
 gcov-files-ipack-y += hw/char/ipoctal232.c
 
-check-qtest-virtioserial-y += tests/virtio-console-test$(EXESUF)
 gcov-files-virtioserial-y += hw/char/virtio-console.c
 
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
@@ -398,6 +397,8 @@ check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-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/virtio-serial-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -781,6 +782,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
+libqgraph-tests-obj-y += tests/virtio-console-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -831,7 +833,6 @@ 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
tests/libqos/virtio.c +1 -0
index 56007ef11b..9b97ab0625 100644
@@ -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)
 {
tests/virtio-console-test.c +15 -15
index 945bae5a15..55d5c0f138 100644
@@ -10,29 +10,29 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "libqos/virtio.h"
+#include "libqos/qgraph.h"
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void console_nop(void)
+static void console_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
-    global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
-                                "-device virtconsole,bus=vser0.0",
-                                qvirtio_get_dev_type());
-    qtest_end();
+    /* no operation */
 }
 
-static void serialport_nop(void)
+static void serialport_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
-    global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
-                                "-device virtserialport,bus=vser0.0",
-                                qvirtio_get_dev_type());
-    qtest_end();
+    /* no operation */
 }
 
-int main(int argc, char **argv)
+static void virtio_console_test(void)
 {
-    g_test_init(&argc, &argv, NULL);
-    qtest_add_func("/virtio/console/nop", console_nop);
-    qtest_add_func("/virtio/serialport/nop", serialport_nop);
+    QOSGraphTestOptions opts = { };
+    QOSGraphEdgeOptions *edge_opts = &opts.edge;
 
-    return g_test_run();
+    edge_opts->before_cmd_line = "-device virtconsole,bus=vser0.0";
+    qos_add_test("console-nop", "virtio-serial", console_nop, &opts);
+
+    edge_opts->before_cmd_line = "-device virtserialport,bus=vser0.0";
+    qos_add_test("serialport-nop", "virtio-serial", serialport_nop, &opts);
 }
+
+libqos_init(virtio_console_test);
Signature · 1 line
2.17.1
#49 lore raw

PATCH v2 21/34 test/qgraph: virtio-serial test node

In reply to Emanuele Giuseppe Esposito

Convert tests/virtio-serial-test in qgraph test node, virtio-serial-test. 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-serial structure, it's all done by the qtest walking graph mechanism

---
 tests/Makefile.include     |  4 +---
 tests/virtio-serial-test.c | 27 +++++++++------------------
 2 files changed, 10 insertions(+), 21 deletions(-)
tests/Makefile.include +1 -3
index 6742f97058..f258a7778e 100644
@@ -205,7 +205,6 @@ check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
 gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c
 endif
-check-qtest-virtio-y += tests/virtio-serial-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/char/virtio-serial-bus.c
 check-qtest-virtio-y += $(check-qtest-virtioserial-y)
 gcov-files-virtio-y += $(gcov-files-virtioserial-y)
@@ -398,7 +397,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/virtio-ccw-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -782,6 +780,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
+libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
@@ -832,7 +831,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/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/virtio-serial-test.c +9 -18
index 7cc7060264..1691811f85 100644
@@ -9,33 +9,24 @@
 
 #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", NULL);
-
     qtest_qmp_device_del("hp-port");
 }
 
-int main(int argc, char **argv)
+static void 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);
-
-    global_qtest = qtest_startf("-device virtio-serial-%s",
-                                qvirtio_get_dev_type());
-    ret = g_test_run();
-
-    qtest_end();
-
-    return ret;
+    qos_add_test("serial-nop", "virtio-serial", virtio_serial_nop, NULL);
+    qos_add_test("serial-hotplug", "virtio-serial", serial_hotplug, NULL);
 }
+
+libqos_init(virtio_serial_test);
Signature · 1 line
2.17.1
#50 lore raw

PATCH v2 22/34 test/qgraph: virtio-9p driver and interface nodes

In reply to 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

---
 tests/Makefile.include   |   1 +
 tests/libqos/virtio-9p.c | 164 +++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-9p.h |  42 ++++++++++
 3 files changed, 207 insertions(+)
 create mode 100644 tests/libqos/virtio-9p.c
 create mode 100644 tests/libqos/virtio-9p.h
tests/Makefile.include +1 -0
index f258a7778e..e4385555e3 100644
@@ -770,6 +770,7 @@ libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-9p.c new file +164 -0

164 lines not on this page · raw message

tests/libqos/virtio-9p.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.17.1
#51 lore raw

PATCH v2 23/34 test/qgraph: virtio-9p test node

In reply to 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 uses virtio-pci QOSGraphObject and functions, while virtio-9p-device receives a virtio and implements its own functions

---
 tests/Makefile.include |   3 +-
 tests/virtio-9p-test.c | 217 +++++++++++++++--------------------------
 2 files changed, 82 insertions(+), 138 deletions(-)
tests/Makefile.include +1 -2
index e4385555e3..f367e9e321 100644
@@ -201,7 +201,6 @@ gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
-check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
 gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c
 endif
@@ -783,6 +782,7 @@ libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
 libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
+libqgraph-tests-obj-y += tests/virtio-9p-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -831,7 +831,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
tests/virtio-9p-test.c +81 -136

419 lines not on this page · raw message

Signature · 1 line
2.17.1
#52 lore raw

PATCH v2 24/34 test/qgraph: virtio-balloon driver and interface nodes

In reply to 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

---
 tests/Makefile.include        |   1 +
 tests/libqos/virtio-balloon.c | 111 ++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-balloon.h |  39 ++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 tests/libqos/virtio-balloon.c
 create mode 100644 tests/libqos/virtio-balloon.h
tests/Makefile.include +1 -0
index f367e9e321..a3d425918f 100644
@@ -770,6 +770,7 @@ libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-balloon.c new file +111 -0

111 lines not on this page · raw message

tests/libqos/virtio-balloon.h new file +39 -0
new file mode 100644
index 0000000000..e8066c42bb
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+};
Signature · 1 line
2.17.1
#53 lore raw

PATCH v2 25/34 test/qgraph: virtio-balloon test node

In reply to Emanuele Giuseppe Esposito

Convert tests/virtio-balloon-test in qgraph test node, virtio-balloon-test. This test consumes a virtio-balloon interface and checks that its function return the expected values.

Note that this test does not allocate any virtio-balloon structure, it's all done by the qtest walking graph mechanism

---
 tests/Makefile.include      |  4 +---
 tests/virtio-balloon-test.c | 22 +++++++---------------
 2 files changed, 8 insertions(+), 18 deletions(-)
tests/Makefile.include +1 -3
index a3d425918f..5b33ffbc57 100644
@@ -192,7 +192,6 @@ gcov-files-virtioserial-y += hw/char/virtio-console.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
 check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
-check-qtest-virtio-y += tests/virtio-balloon-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
@@ -395,7 +394,6 @@ check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-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-generic-y += tests/machine-none-test$(EXESUF)
@@ -784,6 +782,7 @@ libqgraph-tests-obj-y += tests/e1000e-test.o
 libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
+libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -826,7 +825,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)
tests/virtio-balloon-test.c +7 -15
index 0a07e036bb..1604b7f430 100644
@@ -9,25 +9,17 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "libqos/virtio.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-balloon.h"
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void balloon_nop(void)
+static void balloon_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
 }
 
-int main(int argc, char **argv)
+static void virtio_balloon_test(void)
 {
-    int ret;
-
-    g_test_init(&argc, &argv, NULL);
-    qtest_add_func("/virtio/balloon/nop", balloon_nop);
-
-    global_qtest = qtest_startf("-device virtio-balloon-%s",
-                                qvirtio_get_dev_type());
-    ret = g_test_run();
-
-    qtest_end();
-
-    return ret;
+    qos_add_test("balloon-nop", "virtio-balloon", balloon_nop, NULL);
 }
+
+libqos_init(virtio_balloon_test);
Signature · 1 line
2.17.1
#54 lore raw

PATCH v2 26/34 test/qgraph: virtio-rng driver and interface nodes

In reply to 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

---
 tests/Makefile.include    |   1 +
 tests/libqos/virtio-rng.c | 108 ++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-rng.h |  39 ++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 tests/libqos/virtio-rng.c
 create mode 100644 tests/libqos/virtio-rng.h
tests/Makefile.include +1 -0
index 5b33ffbc57..6ebd6463a9 100644
@@ -769,6 +769,7 @@ libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-rng.c new file +108 -0

108 lines not on this page · raw message

tests/libqos/virtio-rng.h new file +39 -0
new file mode 100644
index 0000000000..fbba988875
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+};
Signature · 1 line
2.17.1
#55 lore raw

PATCH v2 27/34 test/qgraph: virtio-rng test node

In reply to 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

---
 tests/Makefile.include  |  3 +--
 tests/virtio-rng-test.c | 25 +++++++++----------------
 2 files changed, 10 insertions(+), 18 deletions(-)
tests/Makefile.include +1 -2
index 6ebd6463a9..3a1a99b8c8 100644
@@ -195,7 +195,6 @@ gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
-check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF)
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
@@ -784,6 +783,7 @@ libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
+libqgraph-tests-obj-y += tests/virtio-rng-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -829,7 +829,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
tests/virtio-rng-test.c +9 -16
index dcecf77463..24fd62f44f 100644
@@ -9,16 +9,17 @@
 
 #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 nop(void *obj, void *data, QGuestAllocator *alloc)
 {
 }
 
-static void hotplug(void)
+static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
     const char *arch = qtest_get_arch();
 
@@ -29,18 +30,10 @@ static void hotplug(void)
     }
 }
 
-int main(int argc, char **argv)
+static void 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("rng-nop", "virtio-rng", nop, NULL);
+    qos_add_test("rng-hotplug", "virtio-rng-pci", rng_hotplug, NULL);
 }
+
+libqos_init(virtio_rng_test);
Signature · 1 line
2.17.1
#56 lore raw

PATCH v2 28/34 test/qgraph: virtio-blk driver and interface nodes

In reply to 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

---
 tests/Makefile.include    |   1 +
 tests/libqos/virtio-blk.c | 126 ++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-blk.h |  40 ++++++++++++
 3 files changed, 167 insertions(+)
 create mode 100644 tests/libqos/virtio-blk.c
 create mode 100644 tests/libqos/virtio-blk.h
tests/Makefile.include +1 -0
index 3a1a99b8c8..1d68e7d223 100644
@@ -769,6 +769,7 @@ libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-blk.c new file +126 -0

126 lines not on this page · raw message

tests/libqos/virtio-blk.h new file +40 -0
new file mode 100644
index 0000000000..dc258496ba
@@ -0,0 +1,40 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+};
Signature · 1 line
2.17.1
#57 lore raw

PATCH v2 29/34 test/qgraph: virtio-blk test node

In reply to Emanuele Giuseppe Esposito

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

---
 tests/Makefile.include  |   4 +-
 tests/virtio-blk-test.c | 459 ++++++++++++++++------------------------
 2 files changed, 186 insertions(+), 277 deletions(-)
tests/Makefile.include +1 -3
index 1d68e7d223..b628d2b821 100644
@@ -193,7 +193,6 @@ gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
 check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
-check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
@@ -373,7 +372,6 @@ check-qtest-arm-y += tests/pca9552-test$(EXESUF)
 check-qtest-arm-y += tests/ds1338-test$(EXESUF)
 check-qtest-arm-y += tests/m25p80-test$(EXESUF)
 gcov-files-arm-y += hw/misc/tmp105.c
-check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
@@ -785,6 +783,7 @@ libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
+libqgraph-tests-obj-y += tests/virtio-blk-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -827,7 +826,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)
tests/virtio-blk-test.c +185 -274

732 lines not on this page · raw message

Signature · 1 line
2.17.1
#58 lore raw

Re: [Qemu-devel] [PATCH v2 29/34] test/qgraph: virtio-blk test node

Quoted 5 lines · Emanuele Giuseppe Esposito
tests/virtio-blk-test.c +1 -3
-static void mmio_basic(void)
+static void basic_resize(void *obj, void *data, QGuestAllocator *t_alloc)
 {
-    QVirtioMMIODevice *dev;
-    QVirtQueue *vq;

tests/virtio-blk-test.c static void pci_idx(void) · line 702

Quoted 10 lines
tests/virtio-blk-test.c +3 -4
-    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 = qvirtio_mmio_device_new(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);

This is the only user of qvirtio_mmio_device_new(), so if you remove the call here, you could also remove the function definition.

Thanks,
Laurent

author
#59 lore raw

Re: [Qemu-devel] [PATCH v2 29/34] test/qgraph: virtio-blk test node

Quoted 13 lines · Laurent Vivier
Quoted 12 lines · Emanuele Giuseppe Esposito
tests/virtio-blk-test.c +4 -4
-static void mmio_basic(void)
+static void basic_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;
Quoted 5 lines

tests/virtio-blk-test.c static void pci_idx(void) · line 702

Quoted 3 lines
tests/virtio-blk-test.c +0 -3
-    arm_test_start();
-
-    dev = qvirtio_mmio_device_new(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);

This is the only user of qvirtio_mmio_device_new(), so if you remove the call here, you could also remove the function definition.

So you suggest to get rid completely of qvirtio_mmio_device_new() in virtio-mmio.c  ? Couldn't it be useful in future maybe?

Emanuele

#60 lore raw

Re: [Qemu-devel] [PATCH v2 29/34] test/qgraph: virtio-blk test node

Quoted 19 lines · Emanuele
Quoted 10 lines · Laurent Vivier
Quoted 9 lines · Emanuele Giuseppe Esposito
(quoted diff) +1 -1
-static void mmio_basic(void)
+static void basic_resize(void *obj, void *data, QGuestAllocator

*t_alloc)
  {
-    QVirtioMMIODevice *dev;
-    QVirtQueue *vq;
-    QGuestAllocator *alloc;
+    QVirtioBlk *blk_if = obj;
+    QVirtioDevice *dev = blk_if->vdev;

Quoted 8 lines
Quoted 6 lines

      int n_size = TEST_IMAGE_SIZE / 2;
      uint64_t capacity;
+    QVirtQueue *vq;
  -    arm_test_start();
-
-    dev = qvirtio_mmio_device_new(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE);

This is the only user of qvirtio_mmio_device_new(), so if you remove the call here, you could also remove the function definition.

Quoted 2 lines

So you suggest to get rid completely of qvirtio_mmio_device_new() in virtio-mmio.c  ?

Yes.

Quoted 1 line

Couldn't it be useful in future maybe?

We'll be able to use qvirtio_mmio_init_device() instead, so I don't think it's a problem.

Thanks,
Laurent

#61 lore raw

PATCH v2 30/34 test/qgraph: virtio-net driver and interface nodes

In reply to 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

---
 tests/Makefile.include    |   1 +
 tests/libqos/virtio-net.c | 177 ++++++++++++++++++++++++++++++++++++++
 tests/libqos/virtio-net.h |  41 +++++++++
 3 files changed, 219 insertions(+)
 create mode 100644 tests/libqos/virtio-net.c
 create mode 100644 tests/libqos/virtio-net.h
tests/Makefile.include +1 -0
index b628d2b821..ecab26b7b2 100644
@@ -768,6 +768,7 @@ libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-net.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-net.c new file +177 -0

177 lines not on this page · raw message

tests/libqos/virtio-net.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.17.1
#62 lore raw

PATCH v2 31/34 test/qgraph: virtio-net test node

In reply to 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

---
 tests/Makefile.include  |   3 +-
 tests/virtio-net-test.c | 159 ++++++++++++----------------------------
 2 files changed, 49 insertions(+), 113 deletions(-)
tests/Makefile.include +1 -2
index ecab26b7b2..4634fd8ef1 100644
@@ -190,7 +190,6 @@ gcov-files-ipack-y += hw/char/ipoctal232.c
 gcov-files-virtioserial-y += hw/char/virtio-console.c
 
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
-check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
@@ -785,6 +784,7 @@ libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
 libqgraph-tests-obj-y += tests/virtio-blk-test.o
+libqgraph-tests-obj-y += tests/virtio-net-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -828,7 +828,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
tests/virtio-net-test.c +48 -111

203 lines not on this page · raw message

Signature · 1 line
2.17.1
#63 lore raw

PATCH v2 32/34 test/qgraph: virtio-scsi driver and interface nodes

In reply to 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

---
 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
tests/Makefile.include +1 -0
index 4634fd8ef1..c5aa9f18b7 100644
@@ -768,6 +768,7 @@ libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-net.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-scsi.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
tests/libqos/virtio-scsi.c new file +117 -0

117 lines not on this page · raw message

tests/libqos/virtio-scsi.h new file +39 -0
new file mode 100644
index 0000000000..17a47beddc
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>
+ */
+
+#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;
+};
Signature · 1 line
2.17.1
#64 lore raw

PATCH v2 33/34 test/qgraph: virtio-scsi test node

In reply to 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

---
 tests/Makefile.include   |   3 +-
 tests/virtio-scsi-test.c | 153 +++++++++++++++++++--------------------
 2 files changed, 75 insertions(+), 81 deletions(-)
tests/Makefile.include +1 -2
index c5aa9f18b7..69877b3702 100644
@@ -194,7 +194,6 @@ gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
-check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
@@ -786,6 +785,7 @@ libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
 libqgraph-tests-obj-y += tests/virtio-blk-test.o
 libqgraph-tests-obj-y += tests/virtio-net-test.o
+libqgraph-tests-obj-y += tests/virtio-scsi-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -829,7 +829,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
tests/virtio-scsi-test.c +74 -79

238 lines not on this page · raw message

Signature · 1 line
2.17.1
#65 lore raw

PATCH v2 34/34 test/qgraph: temporarly commented vhost-user-test

In reply to Emanuele Giuseppe Esposito

vhost-user-test has not converted to qgraph yet, and since it uses virtio interface, it won't work, causing make check to fail.
Commented out until it does not get converted to graph node.

---
 tests/Makefile.include | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/Makefile.include +4 -4
index 69877b3702..14f19ebcdb 100644
@@ -287,10 +287,10 @@ 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)
 gcov-files-i386-y += hw/pci-host/q35.c
-check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += tests/vhost-user-test$(EXESUF)
-ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
-check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += tests/vhost-user-test$(EXESUF)
-endif
+# check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += tests/vhost-user-test$(EXESUF)
+# ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
+# check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += tests/vhost-user-test$(EXESUF)
+# endif
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
Signature · 1 line
2.17.1
#66 lore raw
In reply to Emanuele Giuseppe Esposito
Quoted 33 lines · Emanuele Giuseppe Esposito

qgraph API for the qtest driver framework

This series of patches introduce a different qtest driver organization, viewing machines, drivers and tests as node in a graph, each having one or multiple edges relations.

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:
- MACHINE: for example "arm/raspi2"
- DRIVER: for example "generic-sdhci"
- INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers)
- TEST: for example "sdhci-test", consumes an interface and tests
the functions provided

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
- 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

Quoted 7 lines

Depending on the QEMU binary used, only some drivers/machines will be available and only test that are reached by them will be executed.

This work is being done as Google Summer of Code 2018 project for QEMU, my mentors are Paolo Bonzini and Laurent Vivier.
Additional infos on the project can be found at:
https://wiki.qemu.org/Features/qtest_driver_framework

Tests are not cleaning up properly. There are two bugs, both related to qtest_end not being called (from main in one case, after qos_invalidate_command_line in the other). I tried this fix but then the e1000e tests start failing:

tests/libqtest.h +3 -0
index ac52872..7a6fa6e 100644
@@ -555,6 +555,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;
 }
tests/qos-test.c +6 -5
index 1c3a7fc..a22d176 100644
@@ -233,10 +233,7 @@ static void restart_qemu_or_continue(char *path)
     * new command line
     */
     if (g_strcmp0(old_path, path)) {
-        if (old_path) {
-            qtest_end();
-            g_free(old_path);
-        }
+        qtest_end();
         old_path = path;
         global_qtest = qtest_start(path);
     } else { /* if cmd line is the same, reset the guest */
@@ -247,7 +244,10 @@ static void restart_qemu_or_continue(char *path)
 
 void qos_invalidate_command_line(void)
 {
-    old_path = NULL;
+    if (old_path) {
+        g_free(old_path);
+        old_path = NULL;
+    }
 }
 
 /**
@@ -475,6 +475,7 @@ int main(int argc, char **argv)
 
     qos_graph_foreach_test_path(walk_path);
     g_test_run();
+    qtest_end();
     qos_graph_destroy();
     return 0;
 }

Also, qos-test can be added to check-qtest-generic-y, since it is not PCI-specific.

tests/Makefile.include +1 -3
index 14f19eb..6012f6e 100644
@@ -182,6 +182,7 @@ gcov-files-generic-y = monitor.c qapi/qmp-dispatch.c
 check-qtest-generic-y += tests/device-introspect-test$(EXESUF)
 gcov-files-generic-y = qdev-monitor.c qmp.c
 check-qtest-generic-y += tests/cdrom-test$(EXESUF)
+check-qtest-generic-y += tests/qos-test$(EXESUF)
 
 gcov-files-ipack-y += hw/ipack/ipack.c
 check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF)
@@ -790,9 +791,6 @@ libqgraph-tests-obj-y += tests/virtio-scsi-test.o
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
-check-qtest-pci-y += tests/qos-test$(EXESUF)
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-tests-obj-y)
-
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o

Another small bug is that virtio-net-test should also call qos_invalidate_command_line, since it is closing the socket that is opened in virtio_net_test_setup.

Paolo

Quoted 148 lines

v2:
- added command line arguments caching
- converted all virtio tests
- converted e1000e test
- added two more machines (virt and ppc64)
- introduced separation between edge-name (used by get_driver) and node-name (matched with QMP query result)
- edge carries also additional arguments, like the pci address of destination device
- test now can execute a function before and after the command line is allocated, to allocate various file and sockets needed by command line and test
- better documentation with working example in qgraph.h
- removed esplicit creation of interfaces

Emanuele Giuseppe Esposito (33):
tests: qgraph API for the qtest driver framework tests/qgraph: rename qpci_init_pc functions tests/qgraph: pci-pc driver and interface nodes tests/qgraph: x86_64/pc machine node tests/qgraph: sdhci driver and interface nodes tests/qgraph: sdhci test node
tests/qgraph: arm/raspi2 machine node tests/qgraph: rename qpci_init_spapr functions tests/qgraph: pci-spapr driver and interface nodes tests/qgraph: ppc64/pseries machine node test/qgraph: e1000e driver and interface nodes test/qgraph: e1000e-test node
test/qgraph: virtio_start_device function test/qgraph: virtio-pci driver and interface nodes tests/qgraph: rename qvirtio_mmio_init_device functions test/qgraph: virtio-mmio driver and interface nodes test/qgraph: arm/virt machine node test/qgraph: virtio-serial driver and interface nodes test/qgraph: virtio-console test node test/qgraph: virtio-serial test node test/qgraph: virtio-9p driver and interface nodes test/qgraph: virtio-9p test node
test/qgraph: virtio-balloon driver and interface nodes test/qgraph: virtio-balloon test node test/qgraph: virtio-rng driver and interface nodes test/qgraph: virtio-rng test node
test/qgraph: virtio-blk driver and interface nodes test/qgraph: virtio-blk test node
test/qgraph: virtio-net driver and interface nodes test/qgraph: virtio-net test node
test/qgraph: virtio-scsi driver and interface nodes test/qgraph: virtio-scsi test node test/qgraph: temporarly commented vhost-user-test

Paolo Bonzini (1):
tests: virtio: separate ccw tests from libqos

 configure                            |   2 +-
 include/qemu/module.h                |   2 +
 tests/Makefile.include               |  79 +--
 tests/e1000e-test.c                  | 354 +++----------
 tests/i440fx-test.c                  |   2 +-
 tests/ide-test.c                     |   2 +-
 tests/libqos/ahci.c                  |   2 +-
 tests/libqos/e1000e.c                | 262 ++++++++++
 tests/libqos/e1000e.h                |  53 ++
 tests/libqos/libqos-pc.c             |   2 +-
 tests/libqos/libqos-spapr.c          |   2 +-
 tests/libqos/pci-pc.c                |  41 +-
 tests/libqos/pci-pc.h                |  22 +-
 tests/libqos/pci-spapr.c             |  57 ++-
 tests/libqos/pci-spapr.h             |  26 +-
 tests/libqos/pci.c                   |  48 +-
 tests/libqos/pci.h                   |  15 +
 tests/libqos/ppc64_pseries-machine.c | 111 +++++
 tests/libqos/qgraph.c                | 721 +++++++++++++++++++++++++++
 tests/libqos/qgraph.h                | 514 +++++++++++++++++++
 tests/libqos/qgraph_extra.h          | 263 ++++++++++
 tests/libqos/raspi2-machine.c        |  82 +++
 tests/libqos/sdhci.c                 | 163 ++++++
 tests/libqos/sdhci.h                 |  69 +++
 tests/libqos/virt-machine.c          |  90 ++++
 tests/libqos/virtio-9p.c             | 164 ++++++
 tests/libqos/virtio-9p.h             |  42 ++
 tests/libqos/virtio-balloon.c        | 111 +++++
 tests/libqos/virtio-balloon.h        |  39 ++
 tests/libqos/virtio-blk.c            | 126 +++++
 tests/libqos/virtio-blk.h            |  40 ++
 tests/libqos/virtio-mmio.c           |  72 ++-
 tests/libqos/virtio-mmio.h           |   6 +-
 tests/libqos/virtio-net.c            | 177 +++++++
 tests/libqos/virtio-net.h            |  41 ++
 tests/libqos/virtio-pci.c            |  80 ++-
 tests/libqos/virtio-pci.h            |  12 +
 tests/libqos/virtio-rng.c            | 108 ++++
 tests/libqos/virtio-rng.h            |  39 ++
 tests/libqos/virtio-scsi.c           | 117 +++++
 tests/libqos/virtio-scsi.h           |  39 ++
 tests/libqos/virtio-serial.c         | 109 ++++
 tests/libqos/virtio-serial.h         |  39 ++
 tests/libqos/virtio.c                |   9 +
 tests/libqos/virtio.h                |   1 +
 tests/libqos/x86_64_pc-machine.c     | 110 ++++
 tests/q35-test.c                     |   4 +-
 tests/qos-test.c                     | 480 ++++++++++++++++++
 tests/rtl8139-test.c                 |   2 +-
 tests/sdhci-test.c                   | 222 +++------
 tests/tco-test.c                     |   2 +-
 tests/test-qgraph.c                  | 446 +++++++++++++++++
 tests/usb-hcd-ehci-test.c            |   2 +-
 tests/vhost-user-test.c              |   7 +-
 tests/virtio-9p-test.c               | 221 +++-----
 tests/virtio-balloon-test.c          |  22 +-
 tests/virtio-blk-test.c              | 473 +++++++-----------
 tests/virtio-ccw-test.c              | 121 +++++
 tests/virtio-console-test.c          |  30 +-
 tests/virtio-net-test.c              | 163 ++----
 tests/virtio-rng-test.c              |  25 +-
 tests/virtio-scsi-test.c             | 155 +++---
 tests/virtio-serial-test.c           |  27 +-
 63 files changed, 5624 insertions(+), 1243 deletions(-)
 create mode 100644 tests/libqos/e1000e.c
 create mode 100644 tests/libqos/e1000e.h
 create mode 100644 tests/libqos/ppc64_pseries-machine.c
 create mode 100644 tests/libqos/qgraph.c
 create mode 100644 tests/libqos/qgraph.h
 create mode 100644 tests/libqos/qgraph_extra.h
 create mode 100644 tests/libqos/raspi2-machine.c
 create mode 100644 tests/libqos/sdhci.c
 create mode 100644 tests/libqos/sdhci.h
 create mode 100644 tests/libqos/virt-machine.c
 create mode 100644 tests/libqos/virtio-9p.c
 create mode 100644 tests/libqos/virtio-9p.h
 create mode 100644 tests/libqos/virtio-balloon.c
 create mode 100644 tests/libqos/virtio-balloon.h
 create mode 100644 tests/libqos/virtio-blk.c
 create mode 100644 tests/libqos/virtio-blk.h
 create mode 100644 tests/libqos/virtio-net.c
 create mode 100644 tests/libqos/virtio-net.h
 create mode 100644 tests/libqos/virtio-rng.c
 create mode 100644 tests/libqos/virtio-rng.h
 create mode 100644 tests/libqos/virtio-scsi.c
 create mode 100644 tests/libqos/virtio-scsi.h
 create mode 100644 tests/libqos/virtio-serial.c
 create mode 100644 tests/libqos/virtio-serial.h
 create mode 100644 tests/libqos/x86_64_pc-machine.c
 create mode 100644 tests/qos-test.c
 create mode 100644 tests/test-qgraph.c
 create mode 100644 tests/virtio-ccw-test.c
author
#67 lore raw
Quoted 65 lines · Paolo Bonzini
Quoted 33 lines · Emanuele Giuseppe Esposito

qgraph API for the qtest driver framework

This series of patches introduce a different qtest driver organization, viewing machines, drivers and tests as node in a graph, each having one or multiple edges relations.

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:
- MACHINE: for example "arm/raspi2"
- DRIVER: for example "generic-sdhci"
- INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers)
- TEST: for example "sdhci-test", consumes an interface and tests
the functions provided

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
- 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

Quoted 7 lines

Depending on the QEMU binary used, only some drivers/machines will be available and only test that are reached by them will be executed.

This work is being done as Google Summer of Code 2018 project for QEMU, my mentors are Paolo Bonzini and Laurent Vivier.
Additional infos on the project can be found at:
https://wiki.qemu.org/Features/qtest_driver_framework

Tests are not cleaning up properly. There are two bugs, both related to qtest_end not being called (from main in one case, after qos_invalidate_command_line in the other). I tried this fix but then the e1000e tests start failing:

tests/libqtest.h +3 -0
index ac52872..7a6fa6e 100644
@@ -555,6 +555,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;
  }
tests/qos-test.c +0 -0
index 1c3a7fc..a22d176 100644

tests/qos-test.c static void restart_qemu_or_continue(char *path) · line 236

Quoted 8 lines
tests/qos-test.c +1 -4
@@ -233,10 +233,7 @@ static void restart_qemu_or_continue(char *path)
      * new command line
      */
      if (g_strcmp0(old_path, path)) {
-        if (old_path) {
-            qtest_end();
-            g_free(old_path);
-        }
+        qtest_end();

Why this? Shouldn't it be:

if (g_strcmp0(old_path, path)) {
        qtest_end(); /* handles global_qtest = NULL */ g_free(old_path); /* handles NULL */ old_path = path;
        global_qtest = qtest_start(path);
} else ....

tests/qos-test.c static void restart_qemu_or_continue(char *path) · line 251

Quoted 13 lines
tests/qos-test.c +4 -1
          old_path = path;
          global_qtest = qtest_start(path);
      } else { /* if cmd line is the same, reset the guest */
@@ -247,7 +244,10 @@ static void restart_qemu_or_continue(char *path)
 
  void qos_invalidate_command_line(void)
  {
-    old_path = NULL;
+    if (old_path) {
+        g_free(old_path);
+        old_path = NULL;
+    }
  }

Same here, just

{
    g_free(old_path);
    old_path=NULL;
}

 should be enough I think.

Quoted 28 lines
tests/qos-test.c +1 -0
  /**
@@ -475,6 +475,7 @@ int main(int argc, char **argv)
 
      qos_graph_foreach_test_path(walk_path);
      g_test_run();
+    qtest_end();
      qos_graph_destroy();
      return 0;
  }

Also, qos-test can be added to check-qtest-generic-y, since it is not PCI-specific.

tests/Makefile.include +1 -0
index 14f19eb..6012f6e 100644
@@ -182,6 +182,7 @@ gcov-files-generic-y = monitor.c qapi/qmp-dispatch.c
  check-qtest-generic-y += tests/device-introspect-test$(EXESUF)
  gcov-files-generic-y = qdev-monitor.c qmp.c
  check-qtest-generic-y += tests/cdrom-test$(EXESUF)
+check-qtest-generic-y += tests/qos-test$(EXESUF)
 
  gcov-files-ipack-y += hw/ipack/ipack.c
  check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF)

tests/Makefile.include libqgraph-tests-obj-y += tests/virtio-scsi-test.o · line 795

Quoted 6 lines
tests/Makefile.include +0 -2
@@ -790,9 +791,6 @@ libqgraph-tests-obj-y += tests/virtio-scsi-test.o
  check-unit-y += tests/test-qgraph$(EXESUF)
  tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
-check-qtest-pci-y += tests/qos-test$(EXESUF)
 
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-tests-obj-y)

Why did you comment this line? To me it does not compile without it.

Quoted 8 lines
tests/Makefile.include +0 -1
-
  tests/qmp-test$(EXESUF): tests/qmp-test.o
  tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
  tests/rtc-test$(EXESUF): tests/rtc-test.o

Another small bug is that virtio-net-test should also call qos_invalidate_command_line, since it is closing the socket that is opened in virtio_net_test_setup.

Right, I forgot. Also virtio-blk-test needs to do it.

I tried to apply your changes with my suggested modifications, and everything seems to work to me.

Quoted 148 lines
Quoted 148 lines

v2:
- added command line arguments caching
- converted all virtio tests
- converted e1000e test
- added two more machines (virt and ppc64)
- introduced separation between edge-name (used by get_driver) and node-name (matched with QMP query result)
- edge carries also additional arguments, like the pci address of destination device
- test now can execute a function before and after the command line is allocated, to allocate various file and sockets needed by command line and test
- better documentation with working example in qgraph.h
- removed esplicit creation of interfaces

Emanuele Giuseppe Esposito (33):
tests: qgraph API for the qtest driver framework tests/qgraph: rename qpci_init_pc functions tests/qgraph: pci-pc driver and interface nodes tests/qgraph: x86_64/pc machine node tests/qgraph: sdhci driver and interface nodes tests/qgraph: sdhci test node
tests/qgraph: arm/raspi2 machine node tests/qgraph: rename qpci_init_spapr functions tests/qgraph: pci-spapr driver and interface nodes tests/qgraph: ppc64/pseries machine node test/qgraph: e1000e driver and interface nodes test/qgraph: e1000e-test node
test/qgraph: virtio_start_device function test/qgraph: virtio-pci driver and interface nodes tests/qgraph: rename qvirtio_mmio_init_device functions test/qgraph: virtio-mmio driver and interface nodes test/qgraph: arm/virt machine node test/qgraph: virtio-serial driver and interface nodes test/qgraph: virtio-console test node test/qgraph: virtio-serial test node test/qgraph: virtio-9p driver and interface nodes test/qgraph: virtio-9p test node
test/qgraph: virtio-balloon driver and interface nodes test/qgraph: virtio-balloon test node test/qgraph: virtio-rng driver and interface nodes test/qgraph: virtio-rng test node
test/qgraph: virtio-blk driver and interface nodes test/qgraph: virtio-blk test node
test/qgraph: virtio-net driver and interface nodes test/qgraph: virtio-net test node
test/qgraph: virtio-scsi driver and interface nodes test/qgraph: virtio-scsi test node test/qgraph: temporarly commented vhost-user-test

Paolo Bonzini (1):
tests: virtio: separate ccw tests from libqos

  configure                            |   2 +-
  include/qemu/module.h                |   2 +
  tests/Makefile.include               |  79 +--
  tests/e1000e-test.c                  | 354 +++----------
  tests/i440fx-test.c                  |   2 +-
  tests/ide-test.c                     |   2 +-
  tests/libqos/ahci.c                  |   2 +-
  tests/libqos/e1000e.c                | 262 ++++++++++
  tests/libqos/e1000e.h                |  53 ++
  tests/libqos/libqos-pc.c             |   2 +-
  tests/libqos/libqos-spapr.c          |   2 +-
  tests/libqos/pci-pc.c                |  41 +-
  tests/libqos/pci-pc.h                |  22 +-
  tests/libqos/pci-spapr.c             |  57 ++-
  tests/libqos/pci-spapr.h             |  26 +-
  tests/libqos/pci.c                   |  48 +-
  tests/libqos/pci.h                   |  15 +
  tests/libqos/ppc64_pseries-machine.c | 111 +++++
  tests/libqos/qgraph.c                | 721 +++++++++++++++++++++++++++
  tests/libqos/qgraph.h                | 514 +++++++++++++++++++
  tests/libqos/qgraph_extra.h          | 263 ++++++++++
  tests/libqos/raspi2-machine.c        |  82 +++
  tests/libqos/sdhci.c                 | 163 ++++++
  tests/libqos/sdhci.h                 |  69 +++
  tests/libqos/virt-machine.c          |  90 ++++
  tests/libqos/virtio-9p.c             | 164 ++++++
  tests/libqos/virtio-9p.h             |  42 ++
  tests/libqos/virtio-balloon.c        | 111 +++++
  tests/libqos/virtio-balloon.h        |  39 ++
  tests/libqos/virtio-blk.c            | 126 +++++
  tests/libqos/virtio-blk.h            |  40 ++
  tests/libqos/virtio-mmio.c           |  72 ++-
  tests/libqos/virtio-mmio.h           |   6 +-
  tests/libqos/virtio-net.c            | 177 +++++++
  tests/libqos/virtio-net.h            |  41 ++
  tests/libqos/virtio-pci.c            |  80 ++-
  tests/libqos/virtio-pci.h            |  12 +
  tests/libqos/virtio-rng.c            | 108 ++++
  tests/libqos/virtio-rng.h            |  39 ++
  tests/libqos/virtio-scsi.c           | 117 +++++
  tests/libqos/virtio-scsi.h           |  39 ++
  tests/libqos/virtio-serial.c         | 109 ++++
  tests/libqos/virtio-serial.h         |  39 ++
  tests/libqos/virtio.c                |   9 +
  tests/libqos/virtio.h                |   1 +
  tests/libqos/x86_64_pc-machine.c     | 110 ++++
  tests/q35-test.c                     |   4 +-
  tests/qos-test.c                     | 480 ++++++++++++++++++
  tests/rtl8139-test.c                 |   2 +-
  tests/sdhci-test.c                   | 222 +++------
  tests/tco-test.c                     |   2 +-
  tests/test-qgraph.c                  | 446 +++++++++++++++++
  tests/usb-hcd-ehci-test.c            |   2 +-
  tests/vhost-user-test.c              |   7 +-
  tests/virtio-9p-test.c               | 221 +++-----
  tests/virtio-balloon-test.c          |  22 +-
  tests/virtio-blk-test.c              | 473 +++++++-----------
  tests/virtio-ccw-test.c              | 121 +++++
  tests/virtio-console-test.c          |  30 +-
  tests/virtio-net-test.c              | 163 ++----
  tests/virtio-rng-test.c              |  25 +-
  tests/virtio-scsi-test.c             | 155 +++---
  tests/virtio-serial-test.c           |  27 +-
  63 files changed, 5624 insertions(+), 1243 deletions(-)

create mode 100644 tests/libqos/e1000e.c create mode 100644 tests/libqos/e1000e.h create mode 100644 tests/libqos/ppc64_pseries-machine.c create mode 100644 tests/libqos/qgraph.c create mode 100644 tests/libqos/qgraph.h create mode 100644 tests/libqos/qgraph_extra.h create mode 100644 tests/libqos/raspi2-machine.c create mode 100644 tests/libqos/sdhci.c
create mode 100644 tests/libqos/sdhci.h
create mode 100644 tests/libqos/virt-machine.c create mode 100644 tests/libqos/virtio-9p.c create mode 100644 tests/libqos/virtio-9p.h create mode 100644 tests/libqos/virtio-balloon.c create mode 100644 tests/libqos/virtio-balloon.h create mode 100644 tests/libqos/virtio-blk.c create mode 100644 tests/libqos/virtio-blk.h create mode 100644 tests/libqos/virtio-net.c create mode 100644 tests/libqos/virtio-net.h create mode 100644 tests/libqos/virtio-rng.c create mode 100644 tests/libqos/virtio-rng.h create mode 100644 tests/libqos/virtio-scsi.c create mode 100644 tests/libqos/virtio-scsi.h create mode 100644 tests/libqos/virtio-serial.c create mode 100644 tests/libqos/virtio-serial.h create mode 100644 tests/libqos/x86_64_pc-machine.c create mode 100644 tests/qos-test.c
create mode 100644 tests/test-qgraph.c
create mode 100644 tests/virtio-ccw-test.c

#68 lore raw
Quoted 9 lines · Emanuele
Quoted 1 line

Why this? Shouldn't it be:

if (g_strcmp0(old_path, path)) {
        qtest_end(); /* handles global_qtest = NULL */ g_free(old_path); /* handles NULL */ old_path = path;
        global_qtest = qtest_start(path);
} else ....

Yes, of course. Though I'd have thought that my version has "just" a memory leak. Even better, this could call qos_invalidate_command_line.

Can you post the fixes to a separate commit on github?

Paolo

author
#69 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Emanuele

Why this? Shouldn't it be:

if (g_strcmp0(old_path, path)) {
        qtest_end(); /* handles global_qtest = NULL */ g_free(old_path); /* handles NULL */ old_path = path;
        global_qtest = qtest_start(path);
} else ....

Quoted 4 lines

Yes, of course. Though I'd have thought that my version has "just" a memory leak. Even better, this could call qos_invalidate_command_line.

Can you post the fixes to a separate commit on github?

https://github.com/esposem/qemu/commit/4389e83522c06ce7001382284153d59105692061

I also added g_free(old_path); in qos-test main function, since last old_path is not free'd. This commit is part of qgraph-v3, where I am also applying Laurent's suggestions.

Emanuele

author
#70 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Emanuele

Why this? Shouldn't it be:

if (g_strcmp0(old_path, path)) {
        qtest_end(); /* handles global_qtest = NULL */ g_free(old_path); /* handles NULL */ old_path = path;
        global_qtest = qtest_start(path);
} else ....

Quoted 4 lines

Yes, of course. Though I'd have thought that my version has "just" a memory leak. Even better, this could call qos_invalidate_command_line.

Can you post the fixes to a separate commit on github?

Paolo, did you have a chance to test the fixes? I tried, it seems to be working fine.
About valgrind, it only detects an "invalide read of size 8" in blk-hotplug test (tests/virtio-blk-test.c), but I don't know why is it doing this. For the rest, there shouldn't be any memory leak.

Should I rebase them in the proper commits? I am ready to submit patch v3.

Emanuele