Features/qtest driver framework: Difference between revisions

From QEMU
No edit summary
No edit summary
Line 13: Line 13:
You can construct a graph where the nodes are interfaces, drivers and unit tests, connected by relations such as "X produces Y" or "X consumes Y":
You can construct a graph where the nodes are interfaces, drivers and unit tests, connected by relations such as "X produces Y" or "X consumes Y":


   (driver)          (driver)            (driver)       (interface)       (driver)
   (machine)          (driver)            (driver)         (interface)       (driver)
       pc  ────────→ i440FX-host ───────→ QPCIBusPC  ───────→ QPCIBus ───────→ QSDHCIPCI
       pc  ────────→ i440FX-host ───────→ QPCIBusPC  ───────→ QPCIBus ───────→ QSDHCI_PCI
           produces             produces           produces         consumes    │ produces
           contains             contains           produces       consumed by  │ produces
                                                                                  │
                                                                                   ↓
                                                                                   ↓
                                                                            (interface)
                                                        (driver)            (interface)
                                                                              QSDHCI
                                                        QSDHCI_MM ────────────→ QSDHCI
                                                                                  consumes
                                                        produces                  consumed by
                                                                                   ↓
                                                                                   ↓
                                                                               register-test
                                                                               register-test


(The above is just a single path in a potentially very large graph, covering the whole "x86_64" QEMU target architecture!). The relations are hard-coded in the classes and in the tests.  For example, a unit test for the SD-HCI device (let's call it "registers-test") would add itself to the graph like this:
The above is a subset in a potentially very large graph. The relations are hard-coded in the classes and in the tests, and even include some unused classes such as QSDHCI_MM (a memory-mapped SD-HCI device).


  qos_add_test("register-test", "sdhci");
Let's look at the path from pc to register-test.  register-test is a unit test for the SD-HCI device and it would add itself to the graph like this:
                    │            ╰────── Interface consumed by the test
                    ╰──────────────────── Test name


and likewise all the edges in the graph would be hard coded.
  qos_add_test("register-test", "sdhci", sdhci_register_test_func);
                    │            │            ╰─────── Function invoked to the run test
                    │            ╰──────────────────── Interface consumed by the test
                    ╰────────────────────────────────── Test name


and likewise all the edges in the graph would be hard coded:
  pc = qos_node_create_machine("x86_64", "pc", qos_create_machine_x86_pc);
  qos_node_contains(pc, "i440FX-host");
  qos_node_create_driver("i440FX-host");
  qos_node_create_driver("pci-bus-pc");
  qos_node_contains("i440FX-host", "pci-bus-pc");
  qos_node_create_interface("pci-bus");
  qos_node_produces("pci-bus-pc", "pci-bus");
  qos_node_create_driver("sdhci-pci");
  qos_node_consumes("sdhci-pci", "pci-bus");  // edge from pci-bus to sdhci-pci
  qos_node_produces("sdhci-pci", "sdhci");
  qos_node_create_driver("sdhci-mm");
  qos_node_produces("sdhci-mm", "sdhci");
Here is how another machine could be added:
  raspi3 = qos_node_create_machine("arm", "raspi3", qos_create_machine_arm_raspi3);
  qos_node_contains(raspi3, "sdhci-mm");
 
After the graph is built, tests can be discovered by walking the graph: each test to run corresponds to a path from the root of the graphs to a unit test. The above path could represent a test like "/x86_64/pc/i440FX-host/pcibus-pci/sdhci-pci/sdhci/registers-test":
After the graph is built, tests can be discovered by walking the graph: each test to run corresponds to a path from the root of the graphs to a unit test. The above path could represent a test like "/x86_64/pc/i440FX-host/pcibus-pci/sdhci-pci/sdhci/registers-test":


   /x86_64/pc/i440FX-host/pcibus-pc/sdhci-pci/sdhci/registers-test
   /x86_64/pc/i440FX-host/pcibus-pc/pci-bus/sdhci-pci/sdhci/registers-test
         │  │      │          │        │      │      ╰────── Test name
         │  │      │          │        │    │      │      ╰────── Test name
         │  │      │          │        │      ╰────────────── Driver or interface provided by "sdhci-pci"
         │  │      │          │        │    │      ╰────────────── Interface provided by "sdhci-pci"
         │  │      │          │        ╰───────────────────── Device on the PCI bus
         │  │      │          │        │    ╰───────────────────── Device on the PCI bus
         │  │      │          ╰─────────────────────────────── Driver or interface provided by "i440FX-host"
         │  │      │          │        ╰─────────────────────────── Interface provided by "pcibus-pc"
         │  │      ╰────────────────────────────────────────── Device embedded by "pc"
        │  │      │          ╰───────────────────────────────────── Driver provided by "i440FX-host"
         │  ╰────────────────────────────────────────────────── QEMU machine
         │  │      ╰──────────────────────────────────────────────── Device embedded by "pc"
         ╰───────────────────────────────────────────────────── Target architecture
         │  ╰──────────────────────────────────────────────────────── QEMU machine
         ╰─────────────────────────────────────────────────────────── Target architecture


or reading it in the other direction (right to left):
or reading it in the other direction (right to left):


 
   /x86_64/pc/i440FX-host/pcibus-pc/pci-bus/sdhci-pci/sdhci/registers-test
   /x86_64/pc/i440FX-host/pcibus-pc/sdhci-pci/sdhci/registers-test
         │  │      │          │       │      │        │      ╰────── Test name
         │  │      │          │         │      │      ╰────── Test name
         │  │      │          │       │      │        ╰────────────── Driver or interface consumed by the test
         │  │      │          │         │      ╰────────────── Driver or interface consumed by the test
         │  │      │          │       │      ╰─────────────────────── Driver providing the "sdhci" interface
         │  │      │          │         ╰───────────────────── Device providing the "sdhci-pci" interface
         │  │      │          │      ╰────────────────────────────── Interface consumed by "sdhci-pci"
         │  │      │          ╰─────────────────────────────── Driver or interface consumed by "sdhci-pci"
         │  │      │          ╰────────────────────────────────────── Driver providing the "pcibus" interface
         │  │      ╰────────────────────────────────────────── Device providing the "pcibus-pc" interface
        │  │      ╰───────────────────────────────────────────────── Driver embedding a "pcibus-pc" device
         │  ╰────────────────────────────────────────────────── QEMU machine
         │  ╰───────────────────────────────────────────────────────── QEMU machine embedding an "i440FX-host" device
         ╰───────────────────────────────────────────────────── Target architecture
         ╰──────────────────────────────────────────────────────────── Target architecture


At run-time, a lot of steps are hidden in the framework, and are realized by walking the path:
At run-time, a lot of steps are hidden in the framework, and are realized by walking the path:

Revision as of 22:29, 21 March 2018

Through a driver framework, libqos can expose a description of QEMU's supported machine types and a set of drivers; unit tests can request a driver, and the framework takes care of starting QEMU with options that provide that driver.

For example, the framework could provide:

  1. an interface for SD-HCI (SD Host Controller Interface) devices (abstract class QSDHCI)
  2. a driver for PCI SD-HCI devices (a subclass of QSDHCI, for example QSDHCI_PCI)
  3. a description of how QEMU's "sdhci-pci" device maps to QSDHCI_PCI (for simplicity this can be part of QSDHCI_PCI)
  4. an interface for a PCI bus (abstract class QPCIBus)
  5. a driver for the PCI bus in an x86 PC machine (a subclass of QPCIBus, for example QPCIBusPC)
  6. a description of QEMU's "pc" machine (a subclass of QOSMachine) and its embedded devices (in this case a QPCIBusPC)

(Right now libqos provides items 4 and 5 only).

You can construct a graph where the nodes are interfaces, drivers and unit tests, connected by relations such as "X produces Y" or "X consumes Y":

 (machine)           (driver)             (driver)          (interface)       (driver)
     pc  ────────→ i440FX-host ───────→ QPCIBusPC  ───────→ QPCIBus ───────→ QSDHCI_PCI
          contains             contains            produces        consumed by   │ produces
                                                                                 │
                                                                                 ↓
                                                       (driver)             (interface)
                                                       QSDHCI_MM ────────────→ QSDHCI
                                                       produces                  │ consumed by
                                                                                 ↓
                                                                             register-test

The above is a subset in a potentially very large graph. The relations are hard-coded in the classes and in the tests, and even include some unused classes such as QSDHCI_MM (a memory-mapped SD-HCI device).

Let's look at the path from pc to register-test. register-test is a unit test for the SD-HCI device and it would add itself to the graph like this:

 qos_add_test("register-test", "sdhci", sdhci_register_test_func);
                    │             │            ╰─────── Function invoked to the run test
                    │             ╰──────────────────── Interface consumed by the test
                    ╰────────────────────────────────── Test name

and likewise all the edges in the graph would be hard coded:

 pc = qos_node_create_machine("x86_64", "pc", qos_create_machine_x86_pc);
 qos_node_contains(pc, "i440FX-host");
 qos_node_create_driver("i440FX-host");
 qos_node_create_driver("pci-bus-pc");
 qos_node_contains("i440FX-host", "pci-bus-pc");
 qos_node_create_interface("pci-bus");
 qos_node_produces("pci-bus-pc", "pci-bus");
 qos_node_create_driver("sdhci-pci");
 qos_node_consumes("sdhci-pci", "pci-bus");   // edge from pci-bus to sdhci-pci
 qos_node_produces("sdhci-pci", "sdhci");
 qos_node_create_driver("sdhci-mm");
 qos_node_produces("sdhci-mm", "sdhci");

Here is how another machine could be added:

 raspi3 = qos_node_create_machine("arm", "raspi3", qos_create_machine_arm_raspi3);
 qos_node_contains(raspi3, "sdhci-mm");
 

After the graph is built, tests can be discovered by walking the graph: each test to run corresponds to a path from the root of the graphs to a unit test. The above path could represent a test like "/x86_64/pc/i440FX-host/pcibus-pci/sdhci-pci/sdhci/registers-test":

  /x86_64/pc/i440FX-host/pcibus-pc/pci-bus/sdhci-pci/sdhci/registers-test
        │  │       │          │         │     │      │       ╰────── Test name
        │  │       │          │         │     │      ╰────────────── Interface provided by "sdhci-pci"
        │  │       │          │         │     ╰───────────────────── Device on the PCI bus
        │  │       │          │         ╰─────────────────────────── Interface provided by "pcibus-pc"
        │  │       │          ╰───────────────────────────────────── Driver provided by "i440FX-host"
        │  │       ╰──────────────────────────────────────────────── Device embedded by "pc"
        │  ╰──────────────────────────────────────────────────────── QEMU machine
        ╰─────────────────────────────────────────────────────────── Target architecture

or reading it in the other direction (right to left):

  /x86_64/pc/i440FX-host/pcibus-pc/pci-bus/sdhci-pci/sdhci/registers-test
        │  │       │          │       │      │        │       ╰────── Test name
        │  │       │          │       │      │        ╰────────────── Driver or interface consumed by the test
        │  │       │          │       │      ╰─────────────────────── Driver providing the "sdhci" interface
        │  │       │          │       ╰────────────────────────────── Interface consumed by "sdhci-pci"
        │  │       │          ╰────────────────────────────────────── Driver providing the "pcibus" interface
        │  │       ╰───────────────────────────────────────────────── Driver embedding a "pcibus-pc" device
        │  ╰───────────────────────────────────────────────────────── QEMU machine embedding an "i440FX-host" device
        ╰──────────────────────────────────────────────────────────── Target architecture

At run-time, a lot of steps are hidden in the framework, and are realized by walking the path:

  • QOSMachine walks the path to the device under test
    • the machine itself adds "-M pc" to the command line
    • QPCIBusPC need not add anything to the command line because the device is embedded
    • QSDHCI_PCI adds "-device sdhci-pci" to the command line
  • QOSMachine starts QEMU
  • QOSMachine finally executes the code for the unit test
    • The test asks QSDHCI_PCI to start the device
      • QSDHCI_PCI sets up the PCI device using the methods of QPCIBus
    • The test runs and tests the SDHCI device

Possible milestones

  1. Create graph framework and write unit tests
  2. Convert all PC-based PCI device tests to use the graph framework
  3. Convert all PCI device tests to use the graph framework, so that all PC-based PCI device tests can work on more than one machine
  4. Create more drivers (e.g. SD-HCI)