Qtest driver framework
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 drivers 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
Emanuele Giuseppe Esposito (7):
tests: qgraph API for the qtest driver framework tests/qgraph: pci-pc driver and interface nodes tests/qgraph: sdhci driver and interface nodes tests/qgraph: arm/raspi2 machine node tests/qgraph: x86_64/pc machine node tests/qgraph: gtest integration tests/qgraph: sdhci test node
configure | 2 +- include/qemu/module.h | 2 + tests/Makefile.include | 16 +- tests/libqos/pci-pc.c | 53 ++- tests/libqos/pci-pc.h | 8 + tests/libqos/pci.c | 8 + tests/libqos/qgraph.c | 676 +++++++++++++++++++++++++++++++ tests/libqos/qgraph.h | 259 ++++++++++++ tests/libqos/qgraph_extra.h | 155 +++++++ tests/libqos/raspi2-machine.c | 68 ++++ tests/libqos/sdhci.c | 142 +++++++ tests/libqos/sdhci.h | 68 ++++ tests/libqos/x86_64_pc-machine.c | 93 +++++ tests/qos-test.c | 310 ++++++++++++++ tests/sdhci-test.c | 222 +++------- tests/test-qgraph.c | 446 ++++++++++++++++++++ 16 files changed, 2357 insertions(+), 171 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/libqos/raspi2-machine.c create mode 100644 tests/libqos/sdhci.c create mode 100644 tests/libqos/sdhci.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
Signature · 1 line
2.17.1
PATCH 2/7 tests/qgraph: pci-pc driver and interface nodes
Add pci-bus-pc node and pci-bus interface, moved QPCIBusPC struct declaration in its header (since it will be needed by other drivers) and introduced a setter method for drivers that do not need to allocate but have to initialize QPCIBusPC.
--- tests/libqos/pci-pc.c | 53 ++++++++++++++++++++++++++++++++++++------- tests/libqos/pci-pc.h | 8 +++++++ tests/libqos/pci.c | 8 +++++++ 3 files changed, 61 insertions(+), 8 deletions(-)
tests/libqos/pci-pc.c +45 -8
@@ -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,10 +109,33 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3outl (0xcfc , value); } -QPCIBus *qpci_init_pc (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" , interface); +abort (); +} +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn) +{ +if (!bus) { +return ; + } + dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("PCI Device not found\n" ); +abort (); + } +qpci_device_enable (dev); +} + +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc) +{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;
@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 ); +qpci_set_pc (ret, qts, alloc); +return &ret->bus; }void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + } +QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);
@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +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 +8 -0
@@ -15,7 +15,15 @@#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h" +typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ; + +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn); +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);
tests/libqos/pci.c +8 -0
@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "qgraph.h" void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *data),
@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);
Signature · 1 line
2.17.1
PATCH 3/7 tests/qgraph: sdhci driver and interface nodes
In reply to Emanuele Giuseppe EspositoAdd 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 | 142 +++++++++++++++++++++++++++++++++++++++++ tests/libqos/sdhci.h | 68 ++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 tests/libqos/sdhci.c create mode 100644 tests/libqos/sdhci.h
tests/Makefile.include +1 -0
@@ -770,6 +770,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-obj-y = tests/libqos/qgraph.o +libqgraph-pc-obj-y = $(libqos-pc-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 +142 -0
142 lines not on this page · raw message
tests/libqos/sdhci.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/7 tests/qgraph: arm/raspi2 machine node
In reply to Emanuele Giuseppe EspositoAdd 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 | 3 +- tests/libqos/raspi2-machine.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/libqos/raspi2-machine.c
tests/Makefile.include +2 -1
@@ -770,7 +770,8 @@ 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-obj-y = tests/libqos/qgraph.o -libqgraph-pc-obj-y = $(libqos-pc-obj-y) tests/libqos/sdhci.o +libqgraph-pc-obj-y = $(libqos-pc-obj-y) $(libqgraph-obj-y) tests/libqos/sdhci.o +libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/raspi2-machine.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 5/7 tests/qgraph: x86_64/pc machine node
In reply to Emanuele Giuseppe EspositoAdd 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 | 2 +- tests/libqos/x86_64_pc-machine.c | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/libqos/x86_64_pc-machine.c
tests/Makefile.include +1 -1
@@ -771,7 +771,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virt libqgraph-obj-y = tests/libqos/qgraph.o libqgraph-pc-obj-y = $(libqos-pc-obj-y) $(libqgraph-obj-y) tests/libqos/sdhci.o -libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o +libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o tests/libqos/x86_64_pc-machine.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
tests/libqos/x86_64_pc-machine.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 6/7 tests/qgraph: gtest integration
In reply to Emanuele Giuseppe EspositoAdd main executable that takes care of starting the framework, create the nodes, set the available drivers/machines, discover the path and run tests.
--- tests/Makefile.include | 3 + tests/qos-test.c | 310 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+) create mode 100644 tests/qos-test.c
tests/Makefile.include +3 -0
@@ -776,6 +776,9 @@ libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o tests/libqos/x86_64_pc-machi 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-pc-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/qos-test.c new file +310 -0
310 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 1/7 tests: qgraph API for the qtest driver framework
In reply to Emanuele Giuseppe EspositoAdd 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.
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
--- configure | 2 +- include/qemu/module.h | 2 + tests/Makefile.include | 5 + tests/libqos/qgraph.c | 676 ++++++++++++++++++++++++++++++++++++ tests/libqos/qgraph.h | 259 ++++++++++++++ tests/libqos/qgraph_extra.h | 155 +++++++++ tests/test-qgraph.c | 446 ++++++++++++++++++++++++ 7 files changed, 1544 insertions(+), 1 deletion(-) 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/test-qgraph.c
configure +1 -1
@@ -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
@@ -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 +5 -0
@@ -769,6 +769,11 @@ 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-obj-y = tests/libqos/qgraph.o + +check-unit-y += tests/test-qgraph$(EXESUF) +tests/test-qgraph$(EXESUF): tests/test-qgraph.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 +676 -0
676 lines not on this page · raw message
tests/libqos/qgraph.h new file +259 -0
259 lines not on this page · raw message
tests/libqos/qgraph_extra.h new file +155 -0
155 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
PATCH 7/7 tests/qgraph: sdhci test node
In reply to Emanuele Giuseppe EspositoConvert 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 | 8 +- tests/sdhci-test.c | 222 ++++++++++++----------------------------- 2 files changed, 67 insertions(+), 163 deletions(-)
tests/Makefile.include +3 -5
@@ -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)
@@ -773,11 +770,13 @@ libqgraph-obj-y = tests/libqos/qgraph.o libqgraph-pc-obj-y = $(libqos-pc-obj-y) $(libqgraph-obj-y) tests/libqos/sdhci.o libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o tests/libqos/x86_64_pc-machine.o +libqgraph-tests-obj-y = $(libqgraph-pc-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-pc-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
@@ -863,7 +862,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
Quoted 4 lines · Emanuele Giuseppe Esposito
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 drivers and machines
QEMU doesn't know about qtest drivers. Does "drivers" mean "devices" (i.e. qemu -device \?) and they have a 1:1 correspondence with qtest drivers?
The concept of qgraph makes sense. Ease of use and documentation will be critical to gain adoption. The extra complexity makes it hard for people writing and running tests, so it's important that it's clear which tests will get run and why (or why not).
Quoted 8 lines · Stefan Hajnoczi
Quoted 4 lines · Emanuele Giuseppe Esposito
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 drivers and machinesQEMU doesn't know about qtest drivers. Does "drivers" mean "devices" (i.e. qemu -device \?) and they have a 1:1 correspondence with qtest drivers?
Yes, they are QEMU devices, it was a typo.
Not all qtest drivers are mapped with the QEMU devices, though. In fact, for now all drivers "contained" or "produced" by other nodes are not QEMU devices.
The others (machines and nodes that "consume"), are mapped to QEMU using the { "execute": "qom-list-types", "arguments" : { "implements" : "device" } } for "consume" and
{ "execute": "query-machines" }
for machines.
With "consume" I mean in situation like "node X" ---> consumes --> "node Y", "X" should be in the output of qom-list-types query.
Quoted 4 lines
The concept of qgraph makes sense. Ease of use and documentation will be critical to gain adoption. The extra complexity makes it hard for people writing and running tests, so it's important that it's clear which tests will get run and why (or why not).
I am trying to document and makes it as easy and clean as possible :)
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Emanuele Giuseppe Espositotests/libqos/qgraph.c line 32
Quoted 5 lines · Emanuele Giuseppe Esposito
tests/libqos/qgraph.c new file +5
-0+/* Graph Edge.*/ +struct QOSGraphEdge { +QOSEdgeType type; +char *dest; +char *arg;/* just for CONTAIS and CONSUMED_BY */
CONTAINS?
tests/libqos/qgraph.c line 132
Quoted 6 lines
tests/libqos/qgraph.c new file +6
-0+/** +* remove_node(): removes a node @val from the nodes hash table. +* Note that node->name is not free'd since it will represent the +* hash table key +*/ +static void remove_node (void *val)
This is a confusing function name and doc comment. It does not remove the node from a hash table, it just frees it.
Please call this destroy_node(). The g_hash_table_new_full() argument is GDestroyNotify value_destroy_func, so that would be consistent with glib naming too.
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + QOSGraphNode *node = (QOSGraphNode *) val;
There is no need to cast void pointers in C. Just "QOSGraphNode *node = val;" will do.
tests/libqos/qgraph.c line 247
Quoted 11 lines
tests/libqos/qgraph.c new file +11
-0+/** +* build_driver_cmd_line(): builds the command line for the driver +* @node. The node name must be a valid qemu identifier, since it +* will be used to build the command line. +* +* It is also possible to pass an optional @args that will be +* concatenated to the command line. +* +* For drivers, prepend -device to the driver name. +*/ +static void build_driver_cmd_line (QOSGraphNode *node,const char *args)
Why is this called "driver" instead of "device"?
Quoted 14 lines
tests/libqos/qgraph.c new file +14
-0+{ +if (args) { + node->command_line =g_strconcat ("-device " , node->name,"," , + args,NULL ); + }else { + node->command_line =g_strconcat ("-device " , node->name,NULL ); + } +} + +/** +* build_test_cmd_line(): builds the command line for the test +* @node. The node name need not to be a valid qemu identifier, since it +* will not be used to build the command line. +*
tests/libqos/qgraph.c line 271
Quoted 10 lines
tests/libqos/qgraph.c new file +10
-0+* It is also possible to pass an optional @args that will be +* used as additional command line. +*/ +static void build_test_cmd_line (QOSGraphNode *node,const char *args) +{ +if (args) { + node->command_line =g_strdup (args); + }else { + node->command_line =NULL ; + }
This is equivalent to:
node->command_line = g_strdup(args);
https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup
tests/libqos/qgraph.h line 2
Quoted 8 lines
tests/libqos/qgraph.h new file +2
-0@@ -0,0 +1,259 @@ +/* +* libqos driver framework
The per-function doc comment are good. Please also include higher-level examples of how to use this. At first glance all these functions are overwhelming and it's not clear how to implement new tests, drivers, interfaces, or machines.
See include/qom/object.h for inspiration.
Quoted 4 lines
tests/libqos/qgraph.h new file +4
-0+/* edge types*/ +enum QOSEdgeType { +CONTAINS , +PRODUCES ,
tests/libqos/qgraph.h line 63
Quoted 10 lines
tests/libqos/qgraph.h new file +10
-0+ CONSUMED_BY +}; + +/* node types*/ +enum QOSNodeType { +MACHINE , +DRIVER , +INTERFACE , +TEST +};
The QOSEdgeType and QOSNodeType enum constants use commonly-used names in the global namespace. Please prefix them since this is a header file that will be included from many source files.
tests/libqos/qgraph.h line 75
Quoted 12 lines
tests/libqos/qgraph.h new file +12
-0+ +/** +* Each driver, test or machine will have this as first field. +* Depending on the edge, the node will call the corresponding +* function when walking the path. +* +* QOSGraphObject also provides a destructor, used to deallocate the +* after the test has been executed. +*/ +struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;
Unused?
tests/libqos/qgraph.h line 77
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;
Unused?
Quoted 19 lines
tests/libqos/qgraph_extra.h new file +13
-0@@ -0,0 +1,155 @@ +/* +* 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.
tests/libqos/qgraph_extra.h line 23
Quoted 10 lines
tests/libqos/qgraph_extra.h new file +10
-0+* +* 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/> +*/ + +#ifndef QGRAPH_EXTRA_H +#define QGRAPH_EXTRA_H + +#include "qgraph.h" +#define PRINT_DEBUG 0
I would expect the #ifdef to be in the C file that uses it. PRINT_DEBUG is too generic a name for a .h file, it may cause namespace collisions.
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Emanuele Giuseppe Espositotests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 120
Quoted 11 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +8
-2-QPCIBus *qpci_init_pc (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" , interface); +abort (); +}
At this point I wonder if it makes sense to use the QEMU Object Model (QOM), which has interfaces and inheritance. qgraph duplicates part of the object model.
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 126
Quoted 5 lines
tests/libqos/pci-pc.c +5
-0+void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn) +{ +if (!bus) { +return ; + }
When does this happen and why?
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 137
Quoted 11 lines
tests/libqos/pci-pc.c +11
-0+ dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("PCI Device not found\n" ); +abort (); + } +qpci_device_enable (dev); +} + +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc)
It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in qpci_init_pc() instead of keeping a separate function?
Quoted 14 lines
tests/libqos/pci-pc.c +7
-0+{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 );
tests/libqos/pci-pc.c QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) · line 182
Quoted 10 lines
tests/libqos/pci-pc.c +5
-0+qpci_set_pc (ret, qts, alloc); +return &ret->bus; }void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + }
Why is this needed now?
tests/libqos/pci-pc.c void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) · line 212
Quoted 13 lines
tests/libqos/pci-pc.c +6
-0+QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +qos_node_create_driver ("pci-bus-pc" ,NULL ); +qos_node_produces ("pci-bus-pc" ,"pci-bus" );
In QOM pci-bus-pc would be a class, pci-bus would be an interface. From a driver perspective it seems QOM can already do what is needed and the qgraph infrastructure isn't necessary.
Obviously the depth-first search *is* unique and not in QOM, although QOM does offer a tree namespace which can be used for looking up object instances and I guess this could be used to configure tests at runtime.
I'll think about this more as I read the rest of the patches.
Quoted 8 lines
tests/libqos/pci-pc.c +3
-0+} + +libqos_init (qpci_pc);tests/libqos/pci-pc.h +0
-0
tests/libqos/pci-pc.h line 23
Quoted 9 lines
tests/libqos/pci-pc.h +5
-0@@ -15,7 +15,15 @@#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h" +typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ;
Why does this need to be public?
tests/libqos/pci-pc.h line 25
Quoted 2 lines
tests/libqos/pci-pc.h +2
-0+ +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn);
Why does this need to be public?
tests/libqos/pci-pc.h line 26
Quoted 1 line
tests/libqos/pci-pc.h +1
-0+void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);
Why does this need to be public?
Quoted 16 lines
tests/libqos/pci-pc.h +0
-0QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);tests/libqos/pci.c +1
-0@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "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_plug_device_test(const char *driver, const char *id, · line 412
Quoted 10 lines
tests/libqos/pci.c +7
-0@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);
Why does an interface need to be created? The drivers declare which interfaces they support?
I don't think this can be used to detect typoes in the driver's qos_node_produces() call since there is no explicit control over the order in which libqos_init() functions are called. So the driver may call qos_node_produces() before the qos_node_create_interface() is called?
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Stefan HajnocziQuoted 10 lines · Stefan Hajnoczi
Quoted 10 lines
+ *
build_driver_cmd_line(): builds the command line for the driver
+ * @node. The node name must be a valid qemu identifier, since it
+ * will be used to build the command line.
+ *
+ * It is also possible to pass an optional @args that will be
+ * concatenated to the command line.
+ *
+ * For drivers, prepend -device to the driver name.
+ */
+static voidbuild_driver_cmd_line(QOSGraphNode *node, const char *args)
Quoted 2 lines
Why is this called "driver" instead of "device"?
It's the command line that is needed for the driver to work; it can include also e.g. a -netdev or -blockdev option, though the most common case is to have just -device.
Quoted 8 lines
tests/libqos/qgraph.h line 75
Quoted 7 lines
+ *
+ * QOSGraphObject also provides a destructor, used to deallocate the
+ * after the test has been executed.
+ */tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;
Quoted 6 lines
Unused?
tests/libqos/qgraph.h line 77
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;Unused?
What is unused?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 4/7] tests/qgraph: arm/raspi2 machine node
In reply to Emanuele Giuseppe EspositoQuoted 88 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.
Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- tests/Makefile.include | 3 +- tests/libqos/raspi2-machine.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/libqos/raspi2-machine.ctests/Makefile.include +2
-1@@ -770,7 +770,8 @@ 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-obj-y = tests/libqos/qgraph.o -libqgraph-pc-obj-y = $(libqos-pc-obj-y) tests/libqos/sdhci.o +libqgraph-pc-obj-y = $(libqos-pc-obj-y) $(libqgraph-obj-y) tests/libqos/sdhci.o +libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)tests/libqos/raspi2-machine.c new file +58
-0@@ -0,0 +1,68 @@ +/* +* 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 "qgraph.h" +#include "sdhci.h" + +typedef struct QRaspi2Machine QRaspi2Machine ; + +struct QRaspi2Machine { +QOSGraphObject obj; +QSDHCI_MemoryMapped sdhci; +}; + +static void raspi2_destroy (QOSGraphObject *obj) +{ +g_free (obj); +} + +static QOSGraphObject *raspi2_get_device (void *obj,const char *device) +{ +QRaspi2Machine *machine = obj; +if (!g_strcmp0 (device,"generic-sdhci" )) { +return &machine->sdhci.obj; + } + +printf ("%s not present in arm/raspi2" , device); +abort (); +} + +static void *qos_create_machine_arm_raspi2 (void ) +{ +QRaspi2Machine *machine =g_new0 (QRaspi2Machine,1 ); + + machine->obj.get_device = raspi2_get_device; + machine->obj.destructor = raspi2_destroy; +qos_create_sdhci_mm (&machine->sdhci,0x3f300000 , &(QSDHCIProperties ) { + .version =3 , + .baseclock =52 , + .capab.sdma = false, + .capab.reg =0x052134b4 + });
tests/libqos/raspi2-machine.c line 68
Quoted 10 lines
tests/libqos/raspi2-machine.c new file +10
-0+return &machine->obj; +} + +static void raspi2 (void ) +{ +qos_node_create_machine ("arm/raspi2" , qos_create_machine_arm_raspi2); +qos_node_contains ("arm/raspi2" ,"generic-sdhci" ); +} + +libqos_init (raspi2);
Hmm...I didn't realize it would be necessary to manually define each machine type. I thought qgraph would use qemu-system-x86_64 -machine/-device/info qtree to introspect QEMU and instantiate the appropriate drivers.
My concern is that this manual approach of defining machines complicates qtests. This file will need to be modified by multiple people - each of them will be interested in a specific driver and not interested in the driver that other people have added.
This makes things more complicated where previous qtests simply had an if (x86) { add_test(test_x86_foo); } else if (arm) { add_test(test_arm_foo); } in their source file. It's ugly but it's obvious.
Stefan
Re: [Qemu-devel] [PATCH 6/7] tests/qgraph: gtest integration
In reply to Emanuele Giuseppe EspositoQuoted 2 lines · Emanuele Giuseppe Esposito
Add main executable that takes care of starting the framework, create the nodes, set the available
drivers/machines, discover the path and run tests.
This is elegant, I like it.
Quoted 341 lines
Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- tests/Makefile.include | 3 + tests/qos-test.c | 310 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+) create mode 100644 tests/qos-test.ctests/Makefile.include +3
-0@@ -776,6 +776,9 @@ libqgraph-pc-obj-y += tests/libqos/raspi2-machine.o tests/libqos/x86_64_pc-machi 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-pc-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.otests/qos-test.c new file +310
-0@@ -0,0 +1,310 @@ +/* +* 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 "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qlist.h" +#include "libqos/qgraph.h" +#include "libqos/qgraph_extra.h" + +/** +* create_machine_name(): appends the architecture to @name if +* @is_machine is valid. +*/ +static void create_machine_name (const char **name,bool is_machine) +{ +const char *arch; +if (!is_machine) { +return ; + } + arch =qtest_get_arch (); + *name =g_strconcat (arch,"/" , *name,NULL ); +} + +/** +* destroy_machine_name(): frees the given @name if +* @is_machine is valid. +*/ +static void destroy_machine_name (const char *name,bool is_machine) +{ +if (!is_machine) { +return ; + } +g_free ((char *)name); +} + +/** +* apply_to_qlist(): using QMP queries QEMU for a list of +* machines and devices available, and sets the respective node +* as TRUE. If a node is found, also all its produced and contained +* child are marked available. +* +* See qos_graph_node_set_availability() for more info +*/ +static void apply_to_qlist (QList *list,bool is_machine) +{ +const QListEntry *p; +const char *name; +QDict *minfo; +QObject *qobj; +QString *qstr; + +for (p =qlist_first (list); p; p =qlist_next (p)) { + minfo =qobject_to (QDict,qlist_entry_obj (p)); +g_assert (minfo); + qobj =qdict_get (minfo,"name" ); +g_assert (qobj); + qstr =qobject_to (QString, qobj); +g_assert (qstr); + name =qstring_get_str (qstr); +create_machine_name (&name, is_machine); +qos_graph_node_set_availability (name, TRUE); +destroy_machine_name (name, is_machine); + qobj =qdict_get (minfo,"alias" ); +if (qobj) { +g_assert (qobj); + qstr =qobject_to (QString, qobj); +g_assert (qstr); + name =qstring_get_str (qstr); +create_machine_name (&name, is_machine); +qos_graph_node_set_availability (name, TRUE); +destroy_machine_name (name, is_machine); + } + } +} + +/** +* qos_set_machines_devices_available(): sets availability of qgraph +* machines and devices. +* +* This function firstly starts QEMU with "-machine none" option, +* and then executes the QMP protocol asking for the list of devices +* and machines available. +* +* for each of these items, it looks up the corresponding qgraph node, +* setting it as available. The list currently returns all devices that +* are either machines or CONSUMED_BY other nodes. +* Therefore, in order to mark all other nodes, it recursively sets +* all its CONTAINS and PRODUCES child as available too. +*/ +static void qos_set_machines_devices_available (void ) +{ +QDict *response; +QDict *args =qdict_new (); +QList *list; + +qtest_start ("-machine none" ); + response =qmp ("{ 'execute': 'query-machines' }" ); +g_assert (response); + list =qdict_get_qlist (response,"return" ); +g_assert (list); + +apply_to_qlist (list, TRUE); + +qobject_unref (response); + +qdict_put_bool (args,"abstract" , TRUE); +qdict_put_str (args,"implements" ,"device" ); + + response =qmp ("{'execute': 'qom-list-types'," +" 'arguments': %p }" , args); +g_assert (qdict_haskey (response,"return" )); + list =qdict_get_qlist (response,"return" ); + +apply_to_qlist (list, FALSE); + +qtest_end (); +qobject_unref (response); + +} + +/** +* allocate_objects(): given an array of nodes @arg, +* walks the path invoking all constructors and +* passing the corresponding parameter in order to +* continue the objects allocation. +* Once the test is reached, its function is executed. +* +* Since only the machine and CONSUMED_BY nodes actually +* allocate something in the constructor, a garbage collector +* saves their pointer in an array, so that after execution +* they can be safely free'd. +* +* Note: as specified in walk_path() too, @arg is an array of +* char *, where arg[0] is a pointer to the command line +* string that will be used to properly start QEMU when executing +* the test, and the remaining elements represent the actual objects +* that will be allocated. +*/ +static void allocate_objects (const void *arg) +{ +QOSGraphObject *garbage_collector[(QOS_PATH_MAX_ELEMENT_SIZE *2 )]; +int garbage_size =0 ; +QOSEdgeType etype; +QOSGraphNode *node; +QOSGraphObject *o; +int current =1 , has_to_allocate =0 ; +void *obj =NULL ; +char **path = (char **) arg; + + node =qos_graph_get_node (path[current]); + +while (current <QOS_PATH_MAX_ELEMENT_SIZE ) { + +if (node->type ==MACHINE ) { + global_qtest =qtest_start (path[0 ]); + + obj = node->u.machine.constructor (); + garbage_collector[garbage_size++] = obj; + + }else if (has_to_allocate && node->type ==DRIVER ) { + obj = node->u.driver.constructor (obj,NULL ); + garbage_collector[garbage_size++] = obj; + + }else if (!path[(current +1 )] && node->type ==TEST ) { + node->u.test.function (obj, node->u.test.arg); +break ; + } + + etype =qos_graph_get_edge_type (path[current], path[(current +1 )]); + current++; + node =qos_graph_get_node (path[current]); + + o = obj; + +switch (etype) { +case PRODUCES : + obj = o->get_driver (obj, path[current]); +break ; +case CONSUMED_BY : + has_to_allocate =1 ; +break ; +case CONTAINS : + obj = o->get_device (obj, path[current]); +break ; + } + + } + +g_free (path[0 ]); +g_free (path); +for (int i =0 ; i < garbage_size; i++) { + garbage_collector[i]->destructor (garbage_collector[i]); + } +qtest_end (); +} + +/* +* in this function, 2 path will be built: +* str_path, a one-string path (ex "pc/i440FX-pcihost/...") +* ro_path, a string-array path (ex [0] = "pc", [1] = "i440FX-pcihost"). +* +* str_path will be only used to build the test name, and won't need the +* architecture name at beginning, since it will be added by qtest_add_func(). +* +* ro_path is used to allocate all constructors of the path nodes. +* Each name in this array except position 0 must correspond to a valid +* QOSGraphNode name. +* Position 0 is special, initially contains just the <machine> name of +* the node, (ex for "x86_64/pc" it will be "pc"), used to build the test +* path (see below). After it will contain the command line used to start +* qemu with all required devices. +* +* Note that the machine node name must be with format <arch>/<machine> +* (ex "x86_64/pc"), because it will identify the node "x86_64/pc" +* and start QEMU with "-M pc". For this reason, +* when building str_path, ro_path +* initially contains the <machine> at position 0 ("pc"), +* and the node name at position 1 (<arch>/<machine>) +* ("x86_64/pc"), followed by the rest of the nodes. +*/ +static void walk_path (QOSGraphNode *orig_path,int len) +{ +QOSGraphNode *path; +/* twice QOS_PATH_MAX_ELEMENT_SIZE since each edge can have its arg */ + char **ro_path = g_new0(char *, (QOS_PATH_MAX_ELEMENT_SIZE * 2)); +int ro_path_size =0 ; +char *machine =NULL , *arch =NULL , *tmp_cmd =NULL , *str_path; +char *tmp = orig_path->name, *gfreed; +GString *cmd_line =g_string_new ("" ); + +do { + path =qos_graph_get_node (tmp); + tmp =qos_graph_get_edge_dest (path->path_edge); + +/* append node command line + previous edge command line */ +if (path->command_line && tmp_cmd) { +g_string_append (cmd_line, path->command_line); +g_string_append_printf (cmd_line,"%s " , tmp_cmd); + } + +if (path->type ==MACHINE ) { +qos_separate_arch_machine (path->name, &arch, &machine); + ro_path[ro_path_size++] = arch; + ro_path[ro_path_size++] = machine; +g_string_append_printf (cmd_line,"%s " , path->command_line); + }else { +/* detect if edge has command line args */ + ro_path[ro_path_size++] = path->name; + tmp_cmd =qos_graph_get_edge_arg (path->path_edge); + } + + }while (path->path_edge); + + +/* here position 0 has <arch>/<machine>, position 1 <machine>. +* the path must not have the <arch>, that's why ro_path + 1 +*/ + str_path =g_strjoinv ("/" , (ro_path +1 )); + gfreed =g_string_free (cmd_line, FALSE); +/* put arch/machine in position 1 so allocate_objects can do its work +* and add the command line at position 0. +*/ + ro_path[0 ] =g_strdup (gfreed); + ro_path[1 ] = arch; + +qtest_add_data_func (str_path, ro_path, allocate_objects); +g_free (str_path); +} + +/** +* main(): heart of the qgraph framework. +* +* - Initializes the glib test framework +* - Creates the graph by invoking the various _init constructors +* - Starts QEMU to mark the available devices +* - Walks the graph, and each path is added to +* the glib test framework (walk_path) +* - Runs the tests, calling allocate_object() and allocating the +* machine/drivers/test objects +* - Cleans up everything +*/ +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); +qos_graph_init (); +module_call_init (MODULE_INIT_LIBQOS ); +qos_set_machines_devices_available (); + +qos_graph_foreach_test_path (walk_path); +g_test_run (); +qos_graph_destroy (); +return 0 ; +}Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 7/7] tests/qgraph: sdhci test node
In reply to Emanuele Giuseppe EspositoQuoted 2 lines · Emanuele Giuseppe Esposito
+/**
+ * Oldsdhci_tstructure:
Do you intend to delete this comment before this series is merged? It seems like a TODO that doesn't need to be kept around.
Quoted 1 line
+
qos_add_test("sdhci-test", "sdhci", test_machine);
How does this work for tests that need access to more than 1 device? Can they request a driver instance via the API?
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Stefan HajnocziQuoted 16 lines · Stefan Hajnoczi
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 120
Quoted 11 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +8
-2-QPCIBus *qpci_init_pc (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" , interface); +abort (); +}At this point I wonder if it makes sense to use the QEMU Object Model (QOM), which has interfaces and inheritance. qgraph duplicates part of the object model.
Replying for Emanuele on this point since we didn't really go through QOM yet; I'll let him answer the comments that are more related to the code.
QOM is much heavier weight than qgraph, and adds a lot more boilerplate:
- QOM properties interact with QAPI and bring in a lot of baggage; qgraph would only use "child" properties to implement containment.
- QOM objects are long-lived, qgraph objects only last for the duration of a single test. qgraph doesn't need reference counting or complex two-phase initialization like "realize" or "user_complete"
- QOM's hierarchy is shallow, but qgraph doesn't really need _any_ hierarchy. Because it focuses on interface rather than hierarchy, everything can be expressed simply through structs contained into one another.
Consider that qgraph is 1/4th the size of QOM, and a large part of it is the graph data structure that (as you said) would not be provided by QOM.
There are two things where using QOM would save a little bit of duplicated concepts, namely the get_driver (get interface, what you quote above) and get_device (get contained object) callbacks. However, it wouldn't simplify the code at all, because it would require the introduction of separate instance and class structs. We didn't want to add all too much boilerplate for people that want to write qtest, as you pointed out in the review of patch 4.
Quoted 6 lines
Quoted 1 line
+void
qpci_set_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc)It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in
qpci_init_pc()instead of keeping a separate function?
I agree about the naming. Perhaps we can rename the existing qpci_init_pc to qpci_pc_new, and qpci_set_pc to qpci_pc_init.
Would you prefer if the split was done in the patch that introduces the user for qpci_set_pc (patch 5)? We did it here because this patch prepares qpci-pc
Thanks,
Paolo
Quoted 116 lines
Quoted 14 lines
tests/libqos/pci-pc.c +7
-0+{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 );tests/libqos/pci-pc.c QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) · line 182
Quoted 10 lines
tests/libqos/pci-pc.c +5
-0+qpci_set_pc (ret, qts, alloc); +return &ret->bus; }void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + }Why is this needed now?
tests/libqos/pci-pc.c void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) · line 212
Quoted 13 lines
tests/libqos/pci-pc.c +6
-0+QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +qos_node_create_driver ("pci-bus-pc" ,NULL ); +qos_node_produces ("pci-bus-pc" ,"pci-bus" );In QOM pci-bus-pc would be a class, pci-bus would be an interface. From a driver perspective it seems QOM can already do what is needed and the qgraph infrastructure isn't necessary.
Obviously the depth-first search *is* unique and not in QOM, although QOM does offer a tree namespace which can be used for looking up object instances and I guess this could be used to configure tests at runtime.
I'll think about this more as I read the rest of the patches.
Quoted 8 lines
tests/libqos/pci-pc.c +3
-0+} + +libqos_init (qpci_pc);tests/libqos/pci-pc.h +0
-0tests/libqos/pci-pc.h line 23
Quoted 9 lines
tests/libqos/pci-pc.h +5
-0@@ -15,7 +15,15 @@#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h" +typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ;Why does this need to be public?
tests/libqos/pci-pc.h line 25
Quoted 2 lines
tests/libqos/pci-pc.h +2
-0+ +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn);Why does this need to be public?
tests/libqos/pci-pc.h line 26
Quoted 1 line
tests/libqos/pci-pc.h +1
-0+void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);Why does this need to be public?
Quoted 16 lines
tests/libqos/pci-pc.h +0
-0QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);tests/libqos/pci.c +1
-0@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "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_plug_device_test(const char *driver, const char *id, · line 412
Quoted 10 lines
tests/libqos/pci.c +7
-0@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);Why does an interface need to be created? The drivers declare which interfaces they support?
I don't think this can be used to detect typoes in the driver's
qos_node_produces()call since there is no explicit control over the order in whichlibqos_init()functions are called. So the driver may callqos_node_produces()before theqos_node_create_interface()is called?
Quoted 4 lines · Emanuele Giuseppe Esposito
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
Thanks, I've finished reviewing this version. It looks like a good start!
The main challenge to me seems "how can we make tests simpler?". The presence of a new API and object model raises the bar for writing and running tests. I hope all qtests will use qgraph but if the complexity is too high then qgraph may only be used in a few niche cases where authors think it's worth abstracting machine types and others will continue to write qtests without qgraph.
What are the next steps and do you have plans for making qgraph more integral to libqos?
Stefan
Re: [Qemu-devel] [PATCH 4/7] tests/qgraph: arm/raspi2 machine node
In reply to Stefan HajnocziQuoted 14 lines · Stefan Hajnoczi
Quoted 14 lines
tests/libqos/raspi2-machine.c new file +14
-0+ machine->obj.get_device = raspi2_get_device; + machine->obj.destructor = raspi2_destroy; +qos_create_sdhci_mm (&machine->sdhci,0x3f300000 , &(QSDHCIProperties ) { + .version =3 , + .baseclock =52 , + .capab.sdma = false, + .capab.reg =0x052134b4 + }); +return &machine->obj; +} + +static void raspi2 (void ) +{ +qos_node_create_machine ("arm/raspi2" , qos_create_machine_arm_raspi2);
Quoted 8 lines
tests/libqos/raspi2-machine.c line 68
Quoted 4 lines
tests/libqos/raspi2-machine.c new file +4
-0+qos_node_contains ("arm/raspi2" ,"generic-sdhci" ); +} + +libqos_init (raspi2);Hmm...I didn't realize it would be necessary to manually define each machine type. I thought qgraph would use qemu-system-x86_64 -machine/-device/info qtree to introspect QEMU and instantiate the appropriate drivers.
That doesn't provide enough information yet. However, PCI devices are already discovered automatically and the next step (next year :)) could be to use device tree or ACPI to discover embedded devices.
Using QOM properties instead of duplicating things like QSDHCIProperties is a great idea. Of course the duplication was already there ("old sdhci_t structure" in patch 7), so I don't think it should be a blocker, but indeed there's a better way to do it.
Quoted 4 lines
My concern is that this manual approach of defining machines complicates qtests. This file will need to be modified by multiple people - each of them will be interested in a specific driver and not interested in the driver that other people have added.
This is exactly the opposite problem that we have now: when you write a test you are interested typically only in one machine, and the "if(x86)elseif(arm)" gets in the way. (Also: it's also difficult to split the ifs across files, i.e. it scales worse; and there's lots of duplicated code across tests to do "for" loops of g_test_add, because the ifs don't lend itself to "automatic" generation of test cases via path walk).
The advantage is that (just like for OS vs. QEMU) the structure of this file matches closely the board files in hw/arm/, which is something you should already be familiar with if you're adding a new board to QEMU.
Paolo
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Stefan HajnocziQuoted 16 lines · Stefan Hajnoczi
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 120
Quoted 11 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +8
-2-QPCIBus *qpci_init_pc (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" , interface); +abort (); +}At this point I wonder if it makes sense to use the QEMU Object Model (QOM), which has interfaces and inheritance. qgraph duplicates part of the object model.
Quoted 6 lines
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 126
Quoted 5 lines
tests/libqos/pci-pc.c +5
-0+void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn) +{ +if (!bus) { +return ; + }When does this happen and why?
Ok maybe this is unneeded, I added it because I was creating a test with a NULL bus, but we ended up putting it aside. So you're right, this should be eliminated.
Quoted 7 lines
Quoted 7 lines
tests/libqos/pci-pc.c +7
-0+ dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("PCI Device not found\n" ); +abort (); + }
Quoted 8 lines
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 137
Quoted 4 lines
tests/libqos/pci-pc.c +4
-0+qpci_device_enable (dev); +} + +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc)It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in
qpci_init_pc()instead of keeping a separate function?
The idea is that, following the graph that Paolo wrote in the GSoC project wiki (https://wiki.qemu.org/Features/qtest_driver_framework), QPCIBusPC is "contained" in i440FX-pcihost. This means that the i440FX-pcihost struct has a QPCIBusPC field.
Therefore I had to put QPCIBusPC as public (in order to have it as field), even though qpci_init_pc() was not what I needed to initialize it, because that function is allocating a new QPCIBusPC, while I just needed to "set" its values. From here, qpci_set_pc().
Quoted 19 lines
Quoted 19 lines
tests/libqos/pci-pc.c +9
-0+{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 ); +qpci_set_pc (ret, qts, alloc); +return &ret->bus; }
Quoted 6 lines
tests/libqos/pci-pc.c QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) · line 182
Quoted 5 lines
tests/libqos/pci-pc.c +3
-0void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + }Why is this needed now?
Not having this would mean failure of tests like vrtio-user-test, because now QPCIBusPC has two fields, and QPCIBus bus; is not the first one either. Therefore, if I remember correctly doing something likecontainer_of(NULL, QPCIBusPC, bus)
where bus is not the first field of QPCIBusPC would result in a negative number, and freeing that would make the test crash.
I discovered this issue while doing some checks, and already proposed a patch for it, even though we ended up agreeing that this fix was only needed in my patch and not in the current QEMU implementation.
Quoted 36 lines
tests/libqos/pci-pc.c void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) · line 212
Quoted 13 lines
tests/libqos/pci-pc.c +6
-0+QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +qos_node_create_driver ("pci-bus-pc" ,NULL ); +qos_node_produces ("pci-bus-pc" ,"pci-bus" );In QOM pci-bus-pc would be a class, pci-bus would be an interface. From a driver perspective it seems QOM can already do what is needed and the qgraph infrastructure isn't necessary.
Obviously the depth-first search *is* unique and not in QOM, although QOM does offer a tree namespace which can be used for looking up object instances and I guess this could be used to configure tests at runtime.
I'll think about this more as I read the rest of the patches.
Quoted 13 lines
tests/libqos/pci-pc.c +3
-0+} + +libqos_init (qpci_pc);tests/libqos/pci-pc.h +1
-0@@ -15,7 +15,15 @@#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h"
Quoted 5 lines
tests/libqos/pci-pc.h line 23
Quoted 4 lines
tests/libqos/pci-pc.h +4
-0+typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ;Why does this need to be public?
See previous answer
Quoted 4 lines
tests/libqos/pci-pc.h line 25
Quoted 3 lines
tests/libqos/pci-pc.h +2
-0+ +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn);Why does this need to be public?
I'll use that in the next patches. I also realized this function should go in pci.h, and not pci-pc.h
Quoted 3 lines
tests/libqos/pci-pc.h line 26
Quoted 2 lines
tests/libqos/pci-pc.h +1
-0+void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);Why does this need to be public?
Because I use it in the next patch to set the QPCIBusPC in the x86_64/pc machine.
Quoted 30 lines
Quoted 17 lines
tests/libqos/pci-pc.h +0
-0QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);tests/libqos/pci.c +1
-0@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "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_plug_device_test(const char *driver, const char *id, · line 412
Quoted 10 lines
tests/libqos/pci.c +7
-0@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);Why does an interface need to be created? The drivers declare which interfaces they support?
Quoted 5 lines
I don't think this can be used to detect typoes in the driver's
qos_node_produces()call since there is no explicit control over the order in whichlibqos_init()functions are called. So the driver may callqos_node_produces()before theqos_node_create_interface()is called?
The interface is what is actually given to the test, so from there it can test the functions and fields regardless of which driver is actually implementing them. For example, sdhci-test uses the QSDHCI functions, and depending on the path the generic-sdhci or sdhci-pci functions will be used.
It is possible to call produce() before create(), since an edge just keeps a reference on the name of the node, and not the actual node. If a produce relationship includes the name of a node that does not exist, the application will detect it only during the graph walk, triggering an abort(). If both nodes of the edge will refer to non-existent nodes, the edge won't be detected during the graph walk.
Re: [Qemu-devel] [PATCH 7/7] tests/qgraph: sdhci test node
In reply to Stefan HajnocziQuoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Emanuele Giuseppe Esposito
+/**
+ * Oldsdhci_tstructure:Do you intend to delete this comment before this series is merged? It seems like a TODO that doesn't need to be kept around.
Paolo suggested me to put it there, because there still are some devices that need to be implemented.
Quoted 4 lines
Quoted 2 lines
+
qos_add_test("sdhci-test", "sdhci", test_machine);How does this work for tests that need access to more than 1 device? Can they request a driver instance via the API?
Uhm accessing more than one device is something I did not take into account. It is possible to add additional command line to the test, with qos_add_test_args(), but no multiple devices. I'll add it as TODO in my list, thanks
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Emanuele Giuseppe EspositoHi Emanuele,
Quoted 1 line · Emanuele Giuseppe Esposito
Add pci-bus-pc node and pci-bus interface, moved QPCIBusPC struct
"move"
Quoted 2 lines
declaration in its header (since it will be needed by other drivers) and introduced a setter method for drivers that do not need to allocate
"introduce"
Quoted 36 lines
but have to initialize QPCIBusPC.
Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- tests/libqos/pci-pc.c | 53 ++++++++++++++++++++++++++++++++++++------- tests/libqos/pci-pc.h | 8 +++++++ tests/libqos/pci.c | 8 +++++++ 3 files changed, 61 insertions(+), 8 deletions(-)tests/libqos/pci-pc.c +1
-7@@ -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,10 +109,33 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3outl (0xcfc , value); } -QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +static void *qpci_get_driver (void *obj,const char *interface) {
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 122
Quoted 10 lines
tests/libqos/pci-pc.c +8
-1-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" , interface); +abort (); +} +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn)
Maybe this one belongs to "pci.c" (not being 'pc' related).
Quoted 61 lines
tests/libqos/pci-pc.c +36
-0+{ +if (!bus) { +return ; + } + dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("PCI Device not found\n" ); +abort (); + } +qpci_device_enable (dev); +} + +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc) +{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 ); +qpci_set_pc (ret, qts, alloc); +return &ret->bus; }void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + } +QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +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 +0
-0@@ -15,7 +15,15 @@
tests/libqos/pci-pc.h line 25
Quoted 10 lines
tests/libqos/pci-pc.h +7
-0#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h" +typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ; + +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn);
Ditto, belongs to "libqos/pci.h".
Quoted 28 lines
tests/libqos/pci-pc.h +1
-0+void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);tests/libqos/pci.c +8
-0@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "qgraph.h" void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void (*func)(QPCIDevice *dev, int devfn, void *data),@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);
Re: [Qemu-devel] [PATCH 3/7] tests/qgraph: sdhci driver and interface nodes
In reply to Emanuele Giuseppe EspositoHi Emanuele,
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.
Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- tests/Makefile.include | 1 + tests/libqos/sdhci.c | 142 +++++++++++++++++++++++++++++++++++++++++ tests/libqos/sdhci.h | 68 ++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 tests/libqos/sdhci.c create mode 100644 tests/libqos/sdhci.htests/Makefile.include +0
-0
tests/Makefile.include libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o · line 773
Quoted 4 lines
tests/Makefile.include +1
-0@@ -770,6 +770,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-obj-y = tests/libqos/qgraph.o +libqgraph-pc-obj-y = $(libqos-pc-obj-y) tests/libqos/sdhci.o
Shouldn't this be:
libqgraph-obj-y = tests/libqos/qgraph.o tests/libqos/sdhci.o
(not PC related)
Quoted 69 lines
tests/Makefile.include +0
-0check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)tests/libqos/sdhci.c new file +60
-0@@ -0,0 +1,142 @@ +/* +* 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 "pci.h" +#include "pci-pc.h" +#include "qgraph.h" +#include "sdhci.h" +#include "hw/pci/pci.h" + +static void set_qsdhci_fields (QSDHCI *s,uint8_t version,uint8_t baseclock, +bool sdma,uint64_t reg) +{ + s->props.version = version; + s->props.baseclock = baseclock; + s->props.capab.sdma = sdma; + s->props.capab.reg = reg; +} + +/* Memory mapped implementation of QSDHCI */ + +static uint16_t sdhci_mm_readw (QSDHCI *s,uint32_t reg) +{ +QSDHCI_MemoryMapped *smm =container_of (s, QSDHCI_MemoryMapped, sdhci); +return qtest_readw (global_qtest, smm->addr + reg); +} + +static uint64_t sdhci_mm_readq (QSDHCI *s,uint32_t reg) +{ +QSDHCI_MemoryMapped *smm =container_of (s, QSDHCI_MemoryMapped, sdhci); +return qtest_readq (global_qtest, smm->addr + reg); +} + +static void sdhci_mm_writeq (QSDHCI *s,uint32_t reg,uint64_t val) +{ +QSDHCI_MemoryMapped *smm =container_of (s, QSDHCI_MemoryMapped, sdhci); +qtest_writeq (global_qtest, smm->addr + reg, val); +} + +static void *sdhci_mm_get_driver (void *obj,const char *interface) +{ +QSDHCI_MemoryMapped *spci = obj; +if (!g_strcmp0 (interface,"sdhci" )) { +return &spci->sdhci;
tests/libqos/sdhci.c line 70
Quoted 10 lines
tests/libqos/sdhci.c new file +10
-0+ } +printf ("%s not present in generic-sdhci\n" , interface); +abort (); +} + +void qos_create_sdhci_mm (QSDHCI_MemoryMapped *sdhci,uint32_t addr, +QSDHCIProperties *common) +{ + sdhci->obj.get_driver = sdhci_mm_get_driver; + sdhci->sdhci.sdhci_readw = sdhci_mm_readw;
Lot of 'shdci'!
I'd name the argument 'QSDHCI_MemoryMapped *smm' to be consistent with the previous sdhci_mm_read/write*(), that'd become more readable IMO:
smm->sdhci.readw = sdhci_mm_readw;
Quoted 110 lines
tests/libqos/sdhci.c new file +72
-0+ sdhci->sdhci.sdhci_readq = sdhci_mm_readq; + sdhci->sdhci.sdhci_writeq = sdhci_mm_writeq; +memcpy (&sdhci->sdhci.props, common,sizeof (QSDHCIProperties)); + sdhci->addr = addr; +} + +/* PCI implementation of QSDHCI */ + +static uint16_t sdhci_pci_readw (QSDHCI *s,uint32_t reg) +{ +QSDHCI_PCI *spci =container_of (s,QSDHCI_PCI , sdhci); +return qpci_io_readw (&spci->dev, spci->mem_bar, reg); +} + +static uint64_t sdhci_readq (QSDHCI *s,uint32_t reg) +{ +QSDHCI_PCI *spci =container_of (s,QSDHCI_PCI , sdhci); +return qpci_io_readq (&spci->dev, spci->mem_bar, reg); +} + +static void sdhci_writeq (QSDHCI *s,uint32_t reg,uint64_t val) +{ +QSDHCI_PCI *spci =container_of (s,QSDHCI_PCI , sdhci); +return qpci_io_writeq (&spci->dev, spci->mem_bar, reg, val); +} + +static void *sdhci_pci_get_driver (void *object,const char *interface) +{ +QSDHCI_PCI *spci = object; +if (!g_strcmp0 (interface,"sdhci" )) { +return &spci->sdhci; + } + +printf ("%s not present in sdhci-pci\n" , interface); +abort (); +} + +static void sdhci_destroy (QOSGraphObject *obj) +{ +g_free (obj); +} + +static void *sdhci_pci_create (void *pci_bus,QOSGraphObject *alloc) +{ +QSDHCI_PCI *spci =g_new0 (QSDHCI_PCI ,1 ); +QPCIBus *bus = pci_bus; +uint64_t barsize; + +qpci_device_init (&spci->dev, bus,QPCI_DEVFN (4 ,0 )); +if (bus) { + spci->mem_bar =qpci_iomap (&spci->dev,0 , &barsize); + } + spci->obj.get_driver = sdhci_pci_get_driver; + spci->obj.destructor = sdhci_destroy; + spci->sdhci.sdhci_readw = sdhci_pci_readw; + spci->sdhci.sdhci_readq = sdhci_readq; + spci->sdhci.sdhci_writeq = sdhci_writeq; +set_qsdhci_fields (&spci->sdhci,2 ,0 ,1 ,0x057834b4 ); +return &spci->obj; +} + +static void qsdhci (void ) +{ +qos_node_create_interface ("sdhci" ); +qos_node_create_driver ("generic-sdhci" ,NULL ); +qos_node_produces ("generic-sdhci" ,"sdhci" ); +qos_node_create_driver ("sdhci-pci" , sdhci_pci_create); +qos_node_produces ("sdhci-pci" ,"sdhci" ); +qos_node_consumes_arg ("sdhci-pci" ,"pci-bus" ,"addr=04.0" ); +} + +libqos_init (qsdhci);tests/libqos/sdhci.h new file +32
-0@@ -0,0 +1,68 @@ +/* +* 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/> +*/ + +#ifndef QGRAPH_QSDHCI +#define QGRAPH_QSDHCI +#include "pci.h" + +typedef struct QSDHCI QSDHCI; +typedef struct QSDHCI_MemoryMapped QSDHCI_MemoryMapped; +typedef struct QSDHCI_PCI QSDHCI_PCI; +typedef struct QSDHCIProperties QSDHCIProperties; + +/* Properties common to all QSDHCI devices */ +struct QSDHCIProperties { + uint8_t version; + uint8_t baseclock; + struct {
tests/libqos/sdhci.h line 42
Quoted 10 lines
tests/libqos/sdhci.h new file +10
-0+bool sdma; +uint64_t reg; + } capab; +}; + +struct QSDHCI { +QOSGraphObject obj; +uint16_t (*sdhci_readw)(QSDHCI *s,uint32_t reg); +uint64_t (*sdhci_readq)(QSDHCI *s,uint32_t reg); +void (*sdhci_writeq)(QSDHCI *s,uint32_t reg,uint64_t val);
Please simplify as 'readw/readq/writeq'.
Quoted 14 lines
tests/libqos/sdhci.h new file +14
-0+QSDHCIProperties props; +}; + +/* Memory Mapped implementation of QSDHCI */ +struct QSDHCI_MemoryMapped { +QOSGraphObject obj; +QSDHCI sdhci; +uint64_t addr; +}; + +/* PCI implementation of QSDHCI */ +struct QSDHCI_PCI { +QOSGraphObject obj; +QPCIDevice dev;
tests/libqos/sdhci.h line 66
Quoted 10 lines
tests/libqos/sdhci.h new file +10
-0+QSDHCI sdhci; +QPCIBar mem_bar; +}; + +/** +* qos_create_sdhci_mm(): external constructor used by all drivers/machines +* that "contain" a #QSDHCI_MemoryMapped driver +*/ +void qos_create_sdhci_mm (QSDHCI_MemoryMapped *sdhci,uint32_t addr, +QSDHCIProperties *common);
Your IDE uses a weird indentation.
Quoted 3 lines
tests/libqos/sdhci.h new file +2
-0+ +#endif
Re: [Qemu-devel] [PATCH 4/7] tests/qgraph: arm/raspi2 machine node
In reply to Paolo BonziniQuoted 46 lines · Paolo Bonzini
Quoted 14 lines · Stefan Hajnoczi
Quoted 14 lines
tests/libqos/raspi2-machine.c new file +14
-0+ machine->obj.get_device = raspi2_get_device; + machine->obj.destructor = raspi2_destroy; +qos_create_sdhci_mm (&machine->sdhci,0x3f300000 , &(QSDHCIProperties ) { + .version =3 , + .baseclock =52 , + .capab.sdma = false, + .capab.reg =0x052134b4 + }); +return &machine->obj; +} + +static void raspi2 (void ) +{ +qos_node_create_machine ("arm/raspi2" , qos_create_machine_arm_raspi2);Quoted 8 lines
tests/libqos/raspi2-machine.c line 68
Quoted 4 lines
tests/libqos/raspi2-machine.c new file +4
-0+qos_node_contains ("arm/raspi2" ,"generic-sdhci" ); +} + +libqos_init (raspi2);Hmm...I didn't realize it would be necessary to manually define each machine type. I thought qgraph would use qemu-system-x86_64 -machine/-device/info qtree to introspect QEMU and instantiate the appropriate drivers.
That doesn't provide enough information yet. However, PCI devices are already discovered automatically and the next step (next year :)) could be to use device tree or ACPI to discover embedded devices.
Using QOM properties instead of duplicating things like QSDHCIProperties is a great idea. Of course the duplication was already there ("old
sdhci_tstructure" in patch 7), so I don't think it should be a blocker, but indeed there's a better way to do it.Quoted 4 lines
My concern is that this manual approach of defining machines complicates qtests. This file will need to be modified by multiple people - each of them will be interested in a specific driver and not interested in the driver that other people have added.
This is exactly the opposite problem that we have now: when you write a test you are interested typically only in one machine, and the "if(x86)elseif(arm)" gets in the way. (Also: it's also difficult to split the ifs across files, i.e. it scales worse; and there's lots of duplicated code across tests to do "for" loops of
g_test_add, because the ifs don't lend itself to "automatic" generation of test cases via path walk).
Quoted 3 lines
The advantage is that (just like for OS vs. QEMU) the structure of this file matches closely the board files in hw/arm/, which is something you should already be familiar with if you're adding a new board to QEMU.
Some projects organize their tests alongside the source to be tested. This is often messy, but might be clearer to see source testing coverage. That said, I'd rather keep it out of 'source' tree (as of now). Using a simple script we can notice the same (which device models matches a test).
Re: [Qemu-devel] [PATCH 3/7] tests/qgraph: sdhci driver and interface nodes
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 23 lines · Philippe Mathieu-Daudé
Hi Emanuele,
Quoted 20 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.
Signed-off-by Emanuele Giuseppe Esposito <[email protected]>--- tests/Makefile.include | 1 + tests/libqos/sdhci.c | 142 +++++++++++++++++++++++++++++++++++++++++ tests/libqos/sdhci.h | 68 ++++++++++++++++++++ 3 files changed, 211 insertions(+)create mode 100644
tests/libqos/sdhci.c
create mode 100644tests/libqos/sdhci.htests/Makefile.include +0
-0@@ -770,6 +770,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
Quoted 7 lines
tests/Makefile.include libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o · line 773
Quoted 2 lines
tests/Makefile.include +1
-0libqgraph-obj-y = tests/libqos/qgraph.o +libqgraph-pc-obj-y = $(libqos-pc-obj-y) tests/libqos/sdhci.oShouldn't this be:
libqgraph-obj-y =
tests/libqos/qgraph.otests/libqos/sdhci.o(not PC related)
I need to add $(libqos-pc-obj-y) because it will include pc-pci.c and all the pci targerts, loading their libqos_init() functions and building the graph.
Doing as you suggested won't work for these reasons:
- pci-bus-pc and pci-bus nodes won't be created, so graph would be incomplete
- sdhci needs libqos to use global_qtest, qpci_device_init, etc. that won't be provided by check-unit-y even by adding $(libqos-pc-obj-y).
So since test-qgraph do not need libqos, I (suggested by Paolo) added the test to the check-unit-y target, adding to it just libqgraph-obj.
For other devices like sdhci that need libqos, I created libqgraph-pc-obj-y (to be renamed to libqgraph-pci-obj-y, since it will also contain libqos-spapr ?) that will be added to target check-qtest-pci-y (that provides libqos).
Quoted 17 lines
Quoted 17 lines
tests/Makefile.include +17
-0+ QSDHCIProperties props; +}; + +/* Memory Mapped implementation of QSDHCI */ +struct QSDHCI_MemoryMapped { + QOSGraphObject obj; + QSDHCI sdhci; + uint64_t addr; +}; + +/* PCI implementation of QSDHCI */ +struct QSDHCI_PCI { + QOSGraphObject obj; + QPCIDevice dev; + QSDHCI sdhci; + QPCIBar mem_bar; +};
Quoted 8 lines
tests/Makefile.include
Quoted 7 lines
tests/Makefile.include +7
-0+ +/** + * qos_create_sdhci_mm(): external constructor used by all drivers/machines + * that "contain" a #QSDHCI_MemoryMapped driver + */ +void qos_create_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr, + QSDHCIProperties *common);Your IDE uses a weird indentation.
I actually did by hand, not sure how the indentation to split >80 lines should be. Maybe I should remove a tab? Like this:
+void qos_create_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr, + QSDHCIProperties *common);
Re: [Qemu-devel] [PATCH 7/7] tests/qgraph: sdhci test node
In reply to EmanueleQuoted 6 lines · Emanuele
Quoted 3 lines
Quoted 1 line
Do you intend to delete this comment before this series is merged? It seems like a TODO that doesn't need to be kept around.
Paolo suggested me to put it there, because there still are some devices that need to be implemented.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
qos_add_test("sdhci-test", "sdhci", test_machine);How does this work for tests that need access to more than 1 device? Can they request a driver instance via the API?
Uhm accessing more than one device is something I did not take into account. It is possible to add additional command line to the test, with
qos_add_test_args(), but no multiple devices. I'll add it as TODO in my list, thanks
Note that there is only one test that requires multiple devices on the same bus, namely usb-hcd-ehci-test.c which instantiates the EHCI controller under test together with three companion UHCI controllers.
One possibility is to define a driver which contains all of the devices you need in the test, and make the test depend on the driver. Maybe there is a better way to do it, the above is just what came to my mind.
Paolo
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Paolo BonziniQuoted 38 lines · Paolo Bonzini
Quoted 16 lines · Stefan Hajnoczi
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 120
Quoted 11 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +8
-2-QPCIBus *qpci_init_pc (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" , interface); +abort (); +}At this point I wonder if it makes sense to use the QEMU Object Model (QOM), which has interfaces and inheritance. qgraph duplicates part of the object model.
Replying for Emanuele on this point since we didn't really go through QOM yet; I'll let him answer the comments that are more related to the code.
QOM is much heavier weight than qgraph, and adds a lot more boilerplate:
- QOM properties interact with QAPI and bring in a lot of baggage; qgraph would only use "child" properties to implement containment.
- QOM objects are long-lived, qgraph objects only last for the duration of a single test. qgraph doesn't need reference counting or complex two-phase initialization like "realize" or "
user_complete"- QOM's hierarchy is shallow, but qgraph doesn't really need _any_ hierarchy. Because it focuses on interface rather than hierarchy, everything can be expressed simply through structs contained into one another.
Consider that qgraph is 1/4th the size of QOM, and a large part of it is the graph data structure that (as you said) would not be provided by QOM.
Quoted 7 lines
There are two things where using QOM would save a little bit of duplicated concepts, namely the
get_driver(get interface, what you quote above) andget_device(get contained object) callbacks. However, it wouldn't simplify the code at all, because it would require the introduction of separate instance and class structs. We didn't want to add all too much boilerplate for people that want to write qtest, as you pointed out in the review of patch 4.
Yes, I think these are good points. QOM does involve a lot of boilerplate for defining objects.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
+void
qpci_set_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc)It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in
qpci_init_pc()instead of keeping a separate function?
Quoted 6 lines
I agree about the naming. Perhaps we can rename the existing
qpci_init_pctoqpci_pc_new, andqpci_set_pctoqpci_pc_init.Would you prefer if the split was done in the patch that introduces the user for
qpci_set_pc(patch 5)? We did it here because this patch prepares qpci-pc
Either way is fine. I suggested inlining mainly because it avoids the need to pick a good name :).
Stefan
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Paolo BonziniQuoted 9 lines · Paolo Bonzini
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines
+ *
+ * QOSGraphObject also provides a destructor, used to deallocate the
+ * after the test has been executed.
+ */tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;
Quoted 8 lines
Quoted 6 lines
Unused?
tests/libqos/qgraph.h line 77
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;Unused?
What is unused?
Neither of these fields are used in this patch. Please introduce them in the first patch that actually uses them. This way code review can proceed linearly and it also prevents deadcode when just part of a patch series is merged or backported.
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to EmanueleQuoted 11 lines · Emanuele
Quoted 7 lines · Stefan Hajnoczi
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 126
Quoted 5 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +5
-0+void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn) +{ +if (!bus) { +return ; + }When does this happen and why?
Ok maybe this is unneeded, I added it because I was creating a test with a NULL bus, but we ended up putting it aside. So you're right, this should be eliminated.
Thanks!
Quoted 20 lines
Quoted 7 lines
Quoted 7 lines
tests/libqos/pci-pc.c +7
-0+ dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("PCI Device not found\n" ); +abort (); + }Quoted 8 lines
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 137
Quoted 4 lines
tests/libqos/pci-pc.c +4
-0+qpci_device_enable (dev); +} + +void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc)It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in
qpci_init_pc()instead of keeping a separate function?The idea is that, following the graph that Paolo wrote in the GSoC project wiki (https://wiki.qemu.org/Features/qtest_driver_framework), QPCIBusPC is "contained" in i440FX-pcihost. This means that the i440FX-pcihost struct has a QPCIBusPC field.
Quoted 5 lines
Therefore I had to put QPCIBusPC as public (in order to have it as field), even though
qpci_init_pc()was not what I needed to initialize it, because that function is allocating a new QPCIBusPC, while I just needed to "set" its values.
From here,qpci_set_pc().
I see. Renaming qpci_set_pc() to qpci_pc_init() and including a doc comment explaining that this is the in-place initialization function would make things clear.
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines
tests/libqos/pci-pc.c +9
-0+{assert (qts); ret->bus.pio_readb = qpci_pc_pio_readb;@@ -147,11 +164,23 @@ QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) ret->bus.mmio_alloc_ptr =0xE0000000 ; ret->bus.mmio_limit =0x100000000ULL ; + ret->obj.get_driver = qpci_get_driver; +} + +QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc) +{ +QPCIBusPC *ret =g_new0 (QPCIBusPC,1 ); +qpci_set_pc (ret, qts, alloc); +Quoted 8 lines
tests/libqos/pci-pc.c QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) · line 182
Quoted 7 lines
tests/libqos/pci-pc.c +3
-0return &ret->bus; }void qpci_free_pc (QPCIBus *bus) { +if (!bus) { +return ; + }Why is this needed now?
Not having this would mean failure of tests like vrtio-user-test, because now QPCIBusPC has two fields, and QPCIBus bus; is not the first one either. Therefore, if I remember correctly doing something like
container_of(NULL, QPCIBusPC, bus)
where bus is not the first field of QPCIBusPC would result in a negative number, and freeing that would make the test crash.
Quoted 3 lines
I discovered this issue while doing some checks, and already proposed a patch for it, even though we ended up agreeing that this fix was only needed in my patch and not in the current QEMU implementation.
I see now:
void free_ahci_device(QPCIDevice *dev)
{
QPCIBus *pcibus = dev ? dev->bus : NULL; /* libqos doesn't have a function for this, so free it manually */
g_free(dev);
qpci_free_pc(pcibus);}
The caller is assuming it's okay to pass NULL.
This is a good candidate for a separate patch so that you can explain the rationale ("Although containerof(NULL, QPCIBusPC, bus) happens to evaluate to NULL today thanks to the QPCIBusPC struct layout, it's generally bad practice to rely on that. Normally containerof() is used precisely because an offset into the struct is required and a straightforward cast would not work. We got lucky, but don't depend on it anymore.").
Quoted 42 lines
Quoted 21 lines
tests/libqos/pci-pc.c void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) · line 211
Quoted 11 lines
tests/libqos/pci-pc.c +6
-0+QPCIBusPC *s =container_of (bus, QPCIBusPC, bus);g_free (s);@@ -176,3 +205,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)qmp_eventwait ("DEVICE_DELETED" ); } + +static void qpci_pc (void ) +{ +qos_node_create_driver ("pci-bus-pc" ,NULL ); +qos_node_produces ("pci-bus-pc" ,"pci-bus" );In QOM pci-bus-pc would be a class, pci-bus would be an interface. From a driver perspective it seems QOM can already do what is needed and the qgraph infrastructure isn't necessary.
Obviously the depth-first search *is* unique and not in QOM, although QOM does offer a tree namespace which can be used for looking up object instances and I guess this could be used to configure tests at runtime.
I'll think about this more as I read the rest of the patches.
Quoted 16 lines
Quoted 8 lines
tests/libqos/pci-pc.c +3
-0+} + +libqos_init (qpci_pc);tests/libqos/pci-pc.h +0
-0tests/libqos/pci-pc.h line 21
Quoted 7 lines
tests/libqos/pci-pc.h +5
-0@@ -15,7 +15,15 @@#include "libqos/pci.h" #include "libqos/malloc.h" +#include "qgraph.h" +typedef struct QPCIBusPC { +QOSGraphObject obj; +QPCIBus bus; +}QPCIBusPC ;Why does this need to be public?
See previous answer
Quoted 4 lines
tests/libqos/pci-pc.h line 25
Quoted 3 lines
tests/libqos/pci-pc.h +2
-0+ +void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,int devfn);Why does this need to be public?
Quoted 7 lines
I'll use that in the next patches. I also realized this function should go in
pci.h, and notpci-pc.hQuoted 3 lines
tests/libqos/pci-pc.h line 26
Quoted 2 lines
tests/libqos/pci-pc.h +1
-0+void qpci_set_pc (QPCIBusPC *ret,QTestState *qts,QGuestAllocator *alloc);Why does this need to be public?
Because I use it in the next patch to set the QPCIBusPC in the x86_64/pc machine.
These changes aren't self-contained, making it hard to review the patch series. I review patch series in order, so anything that anticipates future changes without an explanation in the comments or commit description causes me to ask questions.
Patches are easiest to review when there are no forward references. This can be achieved by only introducing things when they are needed.
Quoted 38 lines
Quoted 27 lines
Quoted 14 lines
tests/libqos/pci-pc.h +0
-0QPCIBus *qpci_init_pc (QTestState *qts,QGuestAllocator *alloc);void qpci_free_pc (QPCIBus *bus);tests/libqos/pci.c +1
-0@@ -15,6 +15,7 @@#include "hw/pci/pci_regs.h" #include "qemu/host-utils.h" +#include "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_plug_device_test(const char *driver, const char *id, · line 412
Quoted 10 lines
tests/libqos/pci.c +7
-0@@ -402,3 +403,10 @@ 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 :"" ); } + +static void qpci (void ) +{ +qos_node_create_interface ("pci-bus" ); +} + +libqos_init (qpci);Why does an interface need to be created? The drivers declare which interfaces they support?
Quoted 5 lines
I don't think this can be used to detect typoes in the driver's
qos_node_produces()call since there is no explicit control over the order in whichlibqos_init()functions are called. So the driver may callqos_node_produces()before theqos_node_create_interface()is called?The interface is what is actually given to the test, so from there it can test the functions and fields regardless of which driver is actually implementing them.
For example, sdhci-test uses the QSDHCI functions, and depending on the path the generic-sdhci or sdhci-pci functions will be used.
Quoted 6 lines
It is possible to call
produce()beforecreate(), since an edge just keeps a reference on the name of the node, and not the actual node. If a produce relationship includes the name of a node that does not exist, the application will detect it only during the graph walk, triggering anabort(). If both nodes of the edge will refer to non-existent nodes, the edge won't be detected during the graph walk.
Drivers declare which interface they implement. Tests request an interface. That should be enough information to connect the two together. Why is qos_node_create_interface() necessary?
Quoted 9 lines · Stefan Hajnoczi
Quoted 4 lines · Emanuele Giuseppe Esposito
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_frameworkThanks, I've finished reviewing this version. It looks like a good start!
Quoted 6 lines
The main challenge to me seems "how can we make tests simpler?". The presence of a new API and object model raises the bar for writing and running tests. I hope all qtests will use qgraph but if the complexity is too high then qgraph may only be used in a few niche cases where authors think it's worth abstracting machine types and others will continue to write qtests without qgraph.
The #1 reason for writing code a certain way is following existing examples. As long as "qtest without qgraph" is prevalent in existing tests, it'll remain prevalent in new tests. I'm afraid we'll need a conversion effort.
Quoted 2 lines
What are the next steps and do you have plans for making qgraph more integral to libqos?
Good questions.
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Stefan HajnocziQuoted 11 lines · Stefan Hajnoczi
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Stefan Hajnoczi
tests/libqos/qgraph.h line 75
Quoted 7 lines
+ *
+ * QOSGraphObject also provides a destructor, used to deallocate the
+ * after the test has been executed.
+ */tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;Unused?
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
tests/libqos/qgraph.h line 77
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;Unused?
What is unused?
Neither of these fields are used in this patch. Please introduce them in the first patch that actually uses them. This way code review can proceed linearly and it also prevents deadcode when just part of a patch series is merged or backported.
I'm sorry but at this point also sdhci.c, raspi2-machine.c and x86_64_pc-machine.c (patch 3-4-5) are not actually even compiled before qos-test.c (patch 6). Is that wrong too?
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Stefan HajnocziQuoted 52 lines · Stefan Hajnoczi
Quoted 36 lines · Paolo Bonzini
Quoted 15 lines · Stefan Hajnoczi
tests/libqos/pci-pc.c static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3 · line 120
Quoted 11 lines · Emanuele Giuseppe Esposito
tests/libqos/pci-pc.c +8
-2-QPCIBus *qpci_init_pc (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" , interface); +abort (); +}At this point I wonder if it makes sense to use the QEMU Object Model (QOM), which has interfaces and inheritance. qgraph duplicates part of the object model.
Replying for Emanuele on this point since we didn't really go through QOM yet; I'll let him answer the comments that are more related to the code.
QOM is much heavier weight than qgraph, and adds a lot more boilerplate:
- QOM properties interact with QAPI and bring in a lot of baggage; qgraph would only use "child" properties to implement containment.
- QOM objects are long-lived, qgraph objects only last for the duration of a single test. qgraph doesn't need reference counting or complex two-phase initialization like "realize" or "
user_complete"- QOM's hierarchy is shallow, but qgraph doesn't really need _any_ hierarchy. Because it focuses on interface rather than hierarchy, everything can be expressed simply through structs contained into one another.
Consider that qgraph is 1/4th the size of QOM, and a large part of it is the graph data structure that (as you said) would not be provided by QOM.
Quoted 7 lines
There are two things where using QOM would save a little bit of duplicated concepts, namely the
get_driver(get interface, what you quote above) andget_device(get contained object) callbacks. However, it wouldn't simplify the code at all, because it would require the introduction of separate instance and class structs. We didn't want to add all too much boilerplate for people that want to write qtest, as you pointed out in the review of patch 4.Yes, I think these are good points. QOM does involve a lot of boilerplate for defining objects.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
+void
qpci_set_pc(QPCIBusPC *ret, QTestState *qts, QGuestAllocator *alloc)It's not clear to me what the purpose of this function is - at least the name is a bit cryptic since it seems more like an initialization function than 'setting pc' on QPCIBusPC. How about inlining this in
qpci_init_pc()instead of keeping a separate function?
Quoted 8 lines
Quoted 6 lines
I agree about the naming. Perhaps we can rename the existing
qpci_init_pctoqpci_pc_new, andqpci_set_pctoqpci_pc_init.Would you prefer if the split was done in the patch that introduces the user for
qpci_set_pc(patch 5)? We did it here because this patch prepares qpci-pcEither way is fine. I suggested inlining mainly because it avoids the need to pick a good name :).
I had to put this patch here because it also introduces qpci_device_init, used by sdhci (patch 3).
For the next version I plan to have a patch X where I rename all occurrences of qpci_init_pc in qpci_pc_new, and a patch X+1 that introduces qpci_init_pc (was qpci_set_pc) and the other changes.
Should I only introduce qpci_device_init in patch 3 and the remaining things in patch 5?
I think the general problem here is that in some patches I create functions that are planned to only be used only in next patches (of the current series).
Quoted 1 line
Stefan
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Stefan HajnocziQuoted 5 lines · Stefan Hajnoczi
Quoted 5 lines
Quoted 5 lines
tests/libqos/qgraph.h line 75
Quoted 3 lines
tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;Unused?
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
tests/libqos/qgraph.h line 77
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;Unused?
What is unused?
Neither of these fields are used in this patch. Please introduce them in the first patch that actually uses them. This way code review can proceed linearly and it also prevents deadcode when just part of a patch series is merged or backported.
So do you suggest to squash patch 6 into this one, so that a user of QOSGraphObject exists already here?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to EmanueleQuoted 7 lines · Emanuele
I had to put this patch here because it also introduces
qpci_device_init, used by sdhci (patch 3).For the next version I plan to have a patch X where I rename all occurrences of
qpci_init_pcinqpci_pc_new, and a patch X+1 that introducesqpci_init_pc(wasqpci_set_pc) and the other changes.
Quoted 6 lines
Should I only introduce
qpci_device_initin patch 3 and the remaining things in patch 5?I think the general problem here is that in some patches I create functions that are planned to only be used only in next patches (of the current series).
I think it's okay this way, however you should justify the changes you make to "qgraph-ify" each component.
For patch 1, let's wait for Stefan's reply. Because patch 1 is introducing the infrastructure, I think it is acceptable that some definitions are introduced early as long as they have doc comments; it would make little sense to introduce get_device in patch 4 just because there are no "contains" edges until then.
However, introducing the qos-test directly at the beginning is also a possibility.
In either case, we need better doc comments for the function pointers in QOSGraphObject.
Paolo
Quoted 11 lines · Markus Armbruster
Quoted 6 lines
The main challenge to me seems "how can we make tests simpler?". The presence of a new API and object model raises the bar for writing and running tests. I hope all qtests will use qgraph but if the complexity is too high then qgraph may only be used in a few niche cases where authors think it's worth abstracting machine types and others will continue to write qtests without qgraph.
The #1 reason for writing code a certain way is following existing examples. As long as "qtest without qgraph" is prevalent in existing tests, it'll remain prevalent in new tests. I'm afraid we'll need a conversion effort.
Indeed, Emanuele is already working on converting virtio-serial tests (virtio is possibly the largest part of libqos). The various nop tests are also more or less trivial to adjust.
Paolo
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to EmanueleQuoted 14 lines · Emanuele
Quoted 9 lines
tests/libqos/pci.c void qpci_plug_device_test(const char *driver, const char *id, · line 412
Quoted 6 lines
tests/libqos/pci.c +6
-0+static void qpci (void ) +{ + qos_node_create_interface("pci-bus"); +} + +libqos_init (qpci);Why does an interface need to be created? The drivers declare which interfaces they support?
Quoted 5 lines
I don't think this can be used to detect typoes in the driver's
qos_node_produces()call since there is no explicit control over the order in whichlibqos_init()functions are called. So the driver may callqos_node_produces()before theqos_node_create_interface()is called?
Quoted 5 lines
The interface is what is actually given to the test, so from there it can test the functions and fields regardless of which driver is actually implementing them.
For example, sdhci-test uses the QSDHCI functions, and depending on the path the generic-sdhci or sdhci-pci functions will be used.
I think Stefan is right, if you adjust qos_node_create_interface so that it is idempotent(*), you can make it static and call it from qos_node_produces and qos_node_consumes.
(*) that is, fail like now if the node exists and is not an interface;
but, succeed if the node exists and is an interface.
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes
In reply to Paolo BonziniQuoted 23 lines · Paolo Bonzini
Quoted 7 lines · Emanuele
I had to put this patch here because it also introduces
qpci_device_init, used by sdhci (patch 3).For the next version I plan to have a patch X where I rename all occurrences of
qpci_init_pcinqpci_pc_new, and a patch X+1 that introducesqpci_init_pc(wasqpci_set_pc) and the other changes.Quoted 6 lines
Should I only introduce
qpci_device_initin patch 3 and the remaining things in patch 5?I think the general problem here is that in some patches I create functions that are planned to only be used only in next patches (of the current series).
I think it's okay this way, however you should justify the changes you make to "qgraph-ify" each component.
For patch 1, let's wait for Stefan's reply. Because patch 1 is introducing the infrastructure, I think it is acceptable that some definitions are introduced early as long as they have doc comments; it would make little sense to introduce
get_devicein patch 4 just because there are no "contains" edges until then.
Quoted 5 lines
However, introducing the qos-test directly at the beginning is also a possibility.
In either case, we need better doc comments for the function pointers in QOSGraphObject.
What would you suggest as better doc comments? For version 2 I have written a little introduction like in qom/object.h, essentially pasting the cover letter and a working example.
Quoted 1 line
Paolo
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
In reply to Paolo BonziniQuoted 8 lines · Paolo Bonzini
Quoted 7 lines · Stefan Hajnoczi
Quoted 7 lines
Quoted 7 lines
tests/libqos/qgraph.h line 75
Quoted 3 lines
tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;Unused?
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Unused?
What is unused?
Neither of these fields are used in this patch. Please introduce them in the first patch that actually uses them. This way code review can proceed linearly and it also prevents deadcode when just part of a patch series is merged or backported.
So do you suggest to squash patch 6 into this one, so that a user of QOSGraphObject exists already here?
I think he's right, it makes no sense to have qos-graph as patch 6, it could go as patch 2, even though by that time no object/node exist yet.
Moreover, right now no file in patch 3-4-5 is actually compiled until patch 6, which is easily prone to errors in case of future edits (I too have this problem right now, when I need to modify sdhci.c and I'm forced to return to the branch head to compile), so adding it before would make things more clear.
Quoted 3 lines
Thanks,
Paolo
Re: [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest driver framework
Quoted 19 lines · Emanuele
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Stefan Hajnoczi
Quoted 7 lines
Quoted 7 lines
tests/libqos/qgraph.h line 75
Quoted 3 lines
tests/libqos/qgraph.h new file +3
-0+struct QOSGraphObject { +/* for produces, returns void * */ +QOSGetDriver get_driver;Unused?
Quoted 2 lines
tests/libqos/qgraph.h new file +2
-0+/* for contains, returns a QOSGraphObject * */ +QOSGetDevice get_device;Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Unused?
What is unused?
Neither of these fields are used in this patch. Please introduce them in the first patch that actually uses them. This way code review can proceed linearly and it also prevents deadcode when just part of a patch series is merged or backported.
So do you suggest to squash patch 6 into this one, so that a user of QOSGraphObject exists already here?
Quoted 8 lines
I think he's right, it makes no sense to have qos-graph as patch 6, it could go as patch 2, even though by that time no object/node exist yet.
Moreover, right now no file in patch 3-4-5 is actually compiled until patch 6, which is easily prone to errors in case of future edits (I too have this problem right now, when I need to modify
sdhci.cand I'm forced to return to the branch head to compile), so adding it before would make things more clear.
Sounds good.
Stefan