Skip to contentSkip to conversation

backends: Introduce chr-testdev

PATCH In review Andrew Jones 3 participants 3 messages Jul 11, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backends: Introduce chr-testdev

From: Paolo Bonzini <[email protected]>

From: Paolo Bonzini <[email protected]>

chr-testdev enables a virtio serial channel to be used for guest initiated qemu exits. hw/misc/debugexit already enables guest initiated qemu exits, but only for PC targets. chr-testdev supports any virtio-capable target. kvm-unit-tests/arm is already making use of this backend.

Currently there is a single command implemented, "q". It takes a (prefix) argument for the exit code, thus an exit is implemented by writing, e.g. "1q", to the virtio-serial port.

It can be used as:
$QEMU ... \
-device virtio-serial-device \
-device virtserialport,chardev=ctd -chardev testdev,id=ctd

or, use:
$QEMU ... \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd

to bind it to virtio-serial port0.

---
 backends/Makefile.objs |   2 +-
 backends/testdev.c     | 131 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/char.h  |   3 ++
 qapi-schema.json       |   1 +
 qemu-char.c            |   4 ++
 5 files changed, 140 insertions(+), 1 deletion(-)
 create mode 100644 backends/testdev.c
backends/Makefile.objs +1 -1
index 506a46c33b057..31a3a894f5ead 100644
@@ -1,7 +1,7 @@
 common-obj-y += rng.o rng-egd.o
 common-obj-$(CONFIG_POSIX) += rng-random.o
 
-common-obj-y += msmouse.o
+common-obj-y += msmouse.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 
backends/testdev.c new file +131 -0

131 lines not on this page · raw message

include/sysemu/char.h +3 -0
index 0bbd631e72a47..98cd4c958e723 100644
@@ -358,6 +358,9 @@ CharDriverState *qemu_char_get_next_serial(void);
 /* msmouse */
 CharDriverState *qemu_chr_open_msmouse(void);
 
+/* testdev.c */
+CharDriverState *chr_testdev_init(void);
+
 /* baum.c */
 CharDriverState *chr_baum_init(void);
 
qapi-schema.json +1 -0
index b11aad2068118..80b8f9cf5d677 100644
@@ -2764,6 +2764,7 @@
                                        'mux'    : 'ChardevMux',
                                        'msmouse': 'ChardevDummy',
                                        'braille': 'ChardevDummy',
+                                       'testdev': 'ChardevDummy',
                                        'stdio'  : 'ChardevStdio',
                                        'console': 'ChardevDummy',
                                        'spicevmc' : 'ChardevSpiceChannel',
qemu-char.c +4 -0
index 55e372cf320d2..544c21a4937ca 100644
@@ -3234,6 +3234,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
         strcmp(filename, "pty")     == 0 ||
         strcmp(filename, "msmouse") == 0 ||
         strcmp(filename, "braille") == 0 ||
+        strcmp(filename, "testdev") == 0 ||
         strcmp(filename, "stdio")   == 0) {
         qemu_opt_set(opts, "backend", filename);
         return opts;
@@ -4031,6 +4032,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
         chr = chr_baum_init();
         break;
 #endif
+    case CHARDEV_BACKEND_KIND_TESTDEV:
+        chr = chr_testdev_init();
+        break;
     case CHARDEV_BACKEND_KIND_STDIO:
         chr = qemu_chr_open_stdio(backend->stdio);
         break;
Signature · 1 line
1.9.3
#1 lore raw
Quoted 27 lines · Andrew Jones

From: Paolo Bonzini <[email protected]>

From: Paolo Bonzini <[email protected]>

chr-testdev enables a virtio serial channel to be used for guest initiated qemu exits. hw/misc/debugexit already enables guest initiated qemu exits, but only for PC targets. chr-testdev supports any virtio-capable target. kvm-unit-tests/arm is already making use of this backend.

Currently there is a single command implemented, "q". It takes a (prefix) argument for the exit code, thus an exit is implemented by writing, e.g. "1q", to the virtio-serial port.

It can be used as:

   $QEMU ... \
     -device virtio-serial-device \
     -device virtserialport,chardev=ctd -chardev testdev,id=ctd

or, use:

   $QEMU ... \
     -device virtio-serial-device \
     -device virtconsole,chardev=ctd -chardev testdev,id=ctd

to bind it to virtio-serial port0.

backends/testdev.c line 71

Quoted 5 lines
backends/testdev.c new file +5 -0
+
+    switch (c) {
+    case 'q':
+        exit((arg << 1) | 1);
+        break;

I'm trying to figure out the motive for only exiting with odd numbers. That is, 'q' => 1, '1q' => 3, '2q' => 5, '3q' => 7. It means that at most, I can do '127q' => 255 before I suffer from exit() limiting things to 8 bits. This wasn't explained in the commit message.

qapi-schema.json line 2768

Quoted 7 lines

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -2764,6 +2764,7 @@
                                        'mux'    : 'ChardevMux',
                                        'msmouse': 'ChardevDummy',
                                        'braille': 'ChardevDummy',
+                                       'testdev': 'ChardevDummy',
                                        'stdio'  : 'ChardevStdio',

It would be nice to have some sort of 'testdev since 2.2' documentation.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw

Il 11/07/2014 17:30, Eric Blake ha scritto:

Quoted 34 lines · Andrew Jones
Quoted 27 lines

From: Paolo Bonzini <[email protected]>

From: Paolo Bonzini <[email protected]>

chr-testdev enables a virtio serial channel to be used for guest initiated qemu exits. hw/misc/debugexit already enables guest initiated qemu exits, but only for PC targets. chr-testdev supports any virtio-capable target. kvm-unit-tests/arm is already making use of this backend.

Currently there is a single command implemented, "q". It takes a (prefix) argument for the exit code, thus an exit is implemented by writing, e.g. "1q", to the virtio-serial port.

It can be used as:

   $QEMU ... \
     -device virtio-serial-device \
     -device virtserialport,chardev=ctd -chardev testdev,id=ctd

or, use:

   $QEMU ... \
     -device virtio-serial-device \
     -device virtconsole,chardev=ctd -chardev testdev,id=ctd

to bind it to virtio-serial port0.

backends/testdev.c line 71

Quoted 5 lines
backends/testdev.c new file +5 -0
+
+    switch (c) {
+    case 'q':
+        exit((arg << 1) | 1);
+        break;
Quoted 4 lines

I'm trying to figure out the motive for only exiting with odd numbers. That is, 'q' => 1, '1q' => 3, '2q' => 5, '3q' => 7. It means that at most, I can do '127q' => 255 before I suffer from exit() limiting things to 8 bits. This wasn't explained in the commit message.

It's just for parity with isa-debugexit.

Paolo