Qemu scenario engine
cover Qemu scenario engine
This patch introduce a testing component for Qemu guest OS: the scenario engine.
The Qemu scenario engine is a framework designed to test the software running on the guest machine. It allows interacting with the guest virtual devices by stimulating inputs and reading outputs from outside of the virtual machine. It also provides an utility to schedule precise time based events to run through a "test scenario".
As it is a whole subsystem, a github repository providing a complete documentation and a demonstration is available at the following address:
https://github.com/Openwide-Ingenierie/qemu-scenario-engine-demo
Victor CLEMENT (7):
configure: add --enable-scenario-engine option
gpio-pl061: add a scenario engine interaction API
chardev: add a scenario engine backend
scenario-engine: add utilities
scenario-engine: add a time based event scheduler scenario engine: provide a scenario file template scenario engine: add a Qemu option to start it
Makefile.objs | 8 ++ backends/Makefile.objs | 1 + backends/scenario.c | 107 +++++++++++++++++++++++++ configure | 8 ++ hw/gpio/pl061.c | 38 +++++++++ include/hw/gpio/pl061_simu.h | 20 +++++ include/scenario/scenario.h | 5 ++ include/scenario/scheduler.h | 26 ++++++ include/scenario/utils.h | 23 ++++++ include/sysemu/char.h | 13 +++ qapi-schema.json | 3 +- qemu-char.c | 5 ++ qemu-options.hx | 12 +++ scenario/scenario.c | 168 ++++++++++++++++++++++++++++++++++++++ scenario/scheduler.c | 186 +++++++++++++++++++++++++++++++++++++++++++ scenario/utils.c | 65 +++++++++++++++ vl.c | 45 ++++++++++- 17 files changed, 731 insertions(+), 2 deletions(-) create mode 100644 backends/scenario.c create mode 100644 include/hw/gpio/pl061_simu.h create mode 100644 include/scenario/scenario.h create mode 100644 include/scenario/scheduler.h create mode 100644 include/scenario/utils.h create mode 100644 scenario/scenario.c create mode 100644 scenario/scheduler.c create mode 100644 scenario/utils.c
Signature · 1 line
2.5.1
PATCH 1/7 configure: add --enable-scenario-engine option
Add an option to ./configure script to enable the scenario engine. It defines the CONFIG_SCENARIO constant.
--- configure | 8 ++++++++ 1 file changed, 8 insertions(+)
configure +8 -0
@@ -300,6 +300,7 @@ pkgversion="" pie="" zero_malloc="" qom_cast_debug="yes" +scenario="no" trace_backends="nop" trace_file="trace" spice=""
@@ -788,6 +789,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --enable-scenario-engine) scenario="yes" + ;; --enable-trace-backends=*) trace_backends="$optarg" ;; # XXX: backwards compatibility
@@ -4552,6 +4555,7 @@ echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" +echo "Scenario engine $scenario" echo "Trace backends $trace_backends" if test "$trace_backend" = "simple"; then echo "Trace output file $trace_file-<pid>"
@@ -5084,6 +5088,10 @@ if test "$tpm" = "yes"; then fi fi +if test "$scenario" = "yes" ; then + echo "CONFIG_SCENARIO=y" >> $config_host_mak +fi + echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak if have_backend "nop"; then echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
Signature · 1 line
2.5.1
PATCH 2/7 gpio-pl061: add a scenario engine interaction API
In reply to Victor CLEMENTAdd a scenario API to interact with guest GPIOs.
It implements read and write functions in order to check or modify the guest GPIO data register from the scenario test file.
It also provides an event notification callback to the scenario engine by calling a user-defined handler after each "pl061_update".
--- hw/gpio/pl061.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/gpio/pl061_simu.h | 20 ++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 include/hw/gpio/pl061_simu.h
hw/gpio/pl061.c +38 -0
@@ -9,6 +9,7 @@*/ #include "hw/sysbus.h" +#include "hw/gpio/pl061_simu.h" //#define DEBUG_PL061 1
@@ -60,6 +61,10 @@ typedef struct PL061State {qemu_irq irq;qemu_irq out[8 ];const unsigned char *id; +#ifdef CONFIG_SCENARIO +simu_event_cb_t *simu_cb; +unsigned int simu_id; +#endif } PL061State;static const VMStateDescription vmstate_pl061 = {
@@ -145,6 +150,13 @@ static void pl061_update(PL061State *s)DPRINTF ("istate = %02X\n" , s->istate); +#ifdef CONFIG_SCENARIO +if (s->simu_cb) { + s->simu_cb (s,TYPE_PL061 , s->simu_id); + } +#endif + +qemu_set_irq (s->irq, (s->istate & s->im) !=0 ); }
@@ -205,6 +217,32 @@ static uint64_t pl061_read(void *opaque, hwaddr offset, } } +#ifdef CONFIG_SCENARIO +void pl061_simu_write (void *opaque,uint8_t mask,uint8_t value) +{ +PL061State *s = (PL061State *)opaque; + + s->data = (s->data & ~mask) | (value & mask); +pl061_update (s); +} +uint8_t pl061_simu_read (void *opaque,uint8_t mask) +{ +PL061State *s = (PL061State *)opaque; + +return s->data & mask; +} +void pl061_simu_register_cb (void *opaque,unsigned int simu_id,void *opaque_cb) +{ +PL061State *s =PL061 (opaque); +simu_event_cb_t *cb = (simu_event_cb_t *) opaque_cb; + +if (!(s->simu_cb)) { + s->simu_cb = cb; + s->simu_id = simu_id; + } +} +#endif +static void pl061_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) {
include/hw/gpio/pl061_simu.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifdef CONFIG_SCENARIO + +#ifndef PL061_SIMU_H +#define PL061_SIMU_H + +typedef void simu_event_cb_t (void *opaque, +const char *type, +unsigned int simu_id); + +void pl061_simu_write (void *opaque,uint8_t mask,uint8_t value); + +uint8_t pl061_simu_read (void *opaque,uint8_t mask); + +void pl061_simu_register_cb (void *opaque, +unsigned int simu_id, +void *opaque_cb); + +#endif + +#endif
Signature · 1 line
2.5.1
PATCH 3/7 chardev: add a scenario engine backend
In reply to Victor CLEMENTThis scenario backend implements the scenario interaction API for all character device emulators.
It provides a callback registration function which registers a chr_write callback. It will call the user defined callback on incoming data. To write to this character device, qemu_chr_be_write can be used.
--- backends/Makefile.objs | 1 + backends/scenario.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/char.h | 13 ++++++ qapi-schema.json | 3 +- qemu-char.c | 5 +++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 backends/scenario.c
backends/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ common-obj-y += rng.o rng-egd.o common-obj-$(CONFIG_POSIX) += rng-random.o +common-obj-$(CONFIG_SCENARIO) += scenario.o common-obj-y += msmouse.o testdev.o common-obj-$(CONFIG_BRLAPI) += baum.o baum.o-cflags := $(SDL_CFLAGS)
backends/scenario.c new file +107 -0
107 lines not on this page · raw message
include/sysemu/char.h +13 -0
@@ -368,4 +368,17 @@ typedef CharDriverState *(VcHandler)(ChardevVC *vc);void register_vc_handler (VcHandler *handler);CharDriverState *vc_init (ChardevVC *vc); + +/* scenario.c */ +#ifdef CONFIG_SCENARIO +CharDriverState *qemu_chr_open_scenario (void ); + +typedef int scenario_chardev_cb_t (struct CharDriverState *s, +const uint8_t *buf, +int len); +void scenario_register_chardev_cb (const char *name, +scenario_chardev_cb_t *cb, +bool create); +#endif +#endif
qapi-schema.json +2 -1
@@ -3042,7 +3042,8 @@ 'vc' : 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility - 'memory' : 'ChardevRingbuf' } } + 'memory' : 'ChardevRingbuf', + 'scenario': 'ChardevDummy' } } ## # @ChardevReturn:
qemu-char.c +5 -0
@@ -4295,6 +4295,11 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,case CHARDEV_BACKEND_KIND_MEMORY : chr =qemu_chr_open_ringbuf (backend->ringbuf, errp);break ; +#ifdef CONFIG_SCENARIO +case CHARDEV_BACKEND_KIND_SCENARIO : + chr =qemu_chr_open_scenario (); +break ; +#endif default :error_setg (errp,"unknown chardev backend (%d)" , backend->kind);break ;
Signature · 1 line
2.5.1
Re: [Qemu-devel] [PATCH 3/7] chardev: add a scenario engine backend
Quoted 11 lines · Victor CLEMENT
This scenario backend implements the scenario interaction API for all character device emulators.
It provides a callback registration function which registers achr_writecallback. It will call the user defined callback on incoming data. To write to this character device,qemu_chr_be_writecan be used.Signed-off-by Victor CLEMENT <[email protected]>---
+++
b/qapi-schema.json
qapi-schema.json line 3046
Quoted 6 lines
qapi-schema.json +2
-1@@ -3042,7 +3042,8 @@ 'vc' : 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility - 'memory' : 'ChardevRingbuf' } } + 'memory' : 'ChardevRingbuf', + 'scenario': 'ChardevDummy' } }
Missing documentation of the new union branch, including mention that it was added in 2.5.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 4/7 scenario-engine: add utilities
In reply to Victor CLEMENTThis scenario utilities file currently implements one function. This function is the event callback registration function which walks through all guest devices to find those of a given type then registers their event callback.
--- Makefile.objs | 6 +++++ include/scenario/utils.h | 23 +++++++++++++++++ scenario/utils.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 include/scenario/utils.h create mode 100644 scenario/utils.c
Makefile.objs +6 -0
@@ -105,6 +105,12 @@ util-obj-y += trace/ target-obj-y += trace/ ###################################################################### + +###################################################################### +# scenario +util-obj-$(CONFIG_SCENARIO) += scenario/utils.o + +###################################################################### # guest agent # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
include/scenario/utils.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef SCENARIO_UTILS_H +#define SCENARIO_UTILS_H + +/* +* Every emulator callback register should implement this prototype in order to +* allow the recursive callback registration function to call it +*/ +typedef void scenario_emulator_cb_register_t \ + (void *opaque,unsigned int id,void *emulator_cb); + +/* +* Registers emulator callbacks of every devices of specified type +* +* type: a string representing the target device emulator type (ex. "pl061") +* cb_register: the device emulator scenario API callback register function +* emulator_cb: the user implemented callback to register (its prototype should +* be predefined in the device emulator API) +*/ +unsigned int scenario_register_emulator_cb (const char *type, +scenario_emulator_cb_register_t *cb_register, +void *emulator_cb); + +#endif
scenario/utils.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.5.1
PATCH 5/7 scenario-engine: add a time based event scheduler
In reply to Victor CLEMENTThe scheduler reads an event description file containing timestamps and parameters then schedules those events. A user defined function is called when those events expire. It is used for precise time simulations.
--- Makefile.objs | 1 + include/scenario/scheduler.h | 26 ++++++ scenario/scheduler.c | 186 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 include/scenario/scheduler.h create mode 100644 scenario/scheduler.c
Makefile.objs +1 -0
@@ -108,6 +108,7 @@ target-obj-y += trace/ ###################################################################### # scenario +util-obj-$(CONFIG_SCENARIO) += scenario/scheduler.o util-obj-$(CONFIG_SCENARIO) += scenario/utils.o ######################################################################
include/scenario/scheduler.h new file +26 -0
@@ -0,0 +1,26 @@ +#include "qemu/timer.h" +#ifndef SCENARIO_H +#define SCENARIO_H + +/* +* Prototype of callback function to implement in a scenario using scheduler +* +* opaque: an opaque pointer you choose when calling sched_start +* ts: the timestamp triggering this callback +* param: the parameter string associated to this timestamp +*/ +typedef void scenario_scheduler_cb_t (void *opaque,uint64_t ts,char *param); + +/* +* Call this function to start the scheduler +* +* cb: the callback function to call when a scheduled event occurs +* opaque: the opaque pointer to give to the callback +* file: a file with timestamps and optional parameters associated +*/ +int scenario_scheduler_start (scenario_scheduler_cb_t *cb, +void *opaque, +const char *file); + +#endif +
scenario/scheduler.c new file +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.5.1
PATCH 6/7 scenario engine: provide a scenario file template
In reply to Victor CLEMENTThis template implements the mandatory functions of the main scenario source file and provides an example use case.
--- Makefile.objs | 1 + include/scenario/scenario.h | 5 ++ scenario/scenario.c | 168 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 include/scenario/scenario.h create mode 100644 scenario/scenario.c
Makefile.objs +1 -0
@@ -108,6 +108,7 @@ target-obj-y += trace/ ###################################################################### # scenario +util-obj-$(CONFIG_SCENARIO) += scenario/scenario.o util-obj-$(CONFIG_SCENARIO) += scenario/scheduler.o util-obj-$(CONFIG_SCENARIO) += scenario/utils.o
include/scenario/scenario.h new file +5 -0
@@ -0,0 +1,5 @@ +#include "scenario/scheduler.h" +#include "hw/gpio/pl061_simu.h" + +void init_scenario_engine (const char *filename); +
scenario/scenario.c new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
2.5.1
PATCH 7/7 scenario engine: add a Qemu option to start it
In reply to Victor CLEMENTAdd an option to Qemu in order to start the scenario engine at the end of Qemu initialization.
--- qemu-options.hx | 12 ++++++++++++ vl.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-)
qemu-options.hx +12 -0
@@ -3436,6 +3436,18 @@ The @code{-no-user-config} option makes QEMU not load any of the user-provided config files on @var{sysconfdir}, but won't make it skip the QEMU-provided config files from @var{datadir}. ETEXI +DEF("scenario", HAS_ARG, QEMU_OPTION_scenario, + "-scenario [file=<file>]\n" + " enable scenario engine\n", + QEMU_ARCH_ALL) +STEXI +@item -scenario [file=@var{file}] +@findex -scenario + +Enable scenario engine. + +This option is only available if QEMU has been compiled with scenario engine. +ETEXI DEF("trace", HAS_ARG, QEMU_OPTION_trace, "-trace [events=<file>][,file=<file>]\n" " specify tracing options\n",
vl.c +44 -1
81 lines not on this page · raw message
Signature · 1 line
2.5.1
Am 11.09.2015 um 14:50 schrieb Victor CLEMENT:
Quoted 9 lines
This patch introduce a testing component for Qemu guest OS: the scenario engine.
The Qemu scenario engine is a framework designed to test the software running on the guest machine. It allows interacting with the guest virtual devices by stimulating inputs and reading outputs from outside of the virtual machine. It also provides an utility to schedule precise time based events to run through a "test scenario".
Quoted 3 lines
As it is a whole subsystem, a github repository providing a complete documentation and a demonstration is available at the following address:
https://github.com/Openwide-Ingenierie/qemu-scenario-engine-demo
This is lacking an explanation of why this cannot be done with our existing QTest interface.
Regards,
Andreas
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)