[Spice-devel] [PATCH spice-server v2 1/2] test-stream-device: Better Qemu emulation for data reading
Frediano Ziglio
fziglio at redhat.com
Tue Jan 9 19:20:23 UTC 2018
ping
>
> ping series
>
> >
> > Qemu does not trigger a new data read if we don't read all data in
> > the buffer.
> >
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> > server/stream-device.c | 9 ++++++++
> > server/tests/test-stream-device.c | 43
> > +++++++++++++++++++++++++++++++++++++--
> > 2 files changed, 50 insertions(+), 2 deletions(-)
> >
> > Changes since v1:
> > - avoid an inifinite loop, test added.
> >
> > diff --git a/server/stream-device.c b/server/stream-device.c
> > index 4eaa959b..897fc665 100644
> > --- a/server/stream-device.c
> > +++ b/server/stream-device.c
> > @@ -123,6 +123,15 @@ stream_device_read_msg_from_dev(RedCharDevice *self,
> > SpiceCharDeviceInstance *si
> > dev->hdr_pos = 0;
> > }
> >
> > + if (handled || dev->has_error) {
> > + // Qemu put the device on blocking state if we don't read all data
> > + // so schedule another read.
> > + // We arrive here if we processed that entire message or we
> > + // got an error, try to read another message or discard the
> > + // wrong data
> > + red_char_device_wakeup(self);
> > + }
> > +
> > return NULL;
> > }
> >
> > diff --git a/server/tests/test-stream-device.c
> > b/server/tests/test-stream-device.c
> > index 656bf56b..85c7ab1a 100644
> > --- a/server/tests/test-stream-device.c
> > +++ b/server/tests/test-stream-device.c
> > @@ -23,6 +23,7 @@
> > #include <string.h>
> > #include <stdlib.h>
> > #include <stdio.h>
> > +#include <unistd.h>
> >
> > #include <spice/protocol.h>
> > #include <spice/stream-device.h>
> > @@ -68,8 +69,12 @@ static int vmc_read(SPICE_GNUC_UNUSED
> > SpiceCharDeviceInstance *sin,
> > pos += ret;
> > // kick off next message read
> > // currently Qemu kicks the device so we need to do it manually
> > - // here
> > - spice_server_char_device_wakeup(&vmc_instance);
> > + // here. If not all data are read the device goes into blocking
> > + // state and we get the wake only when we read from the device
> > + // again
> > + if (pos >= *message_sizes_curr) {
> > + spice_server_char_device_wakeup(&vmc_instance);
> > + }
> > return ret;
> > }
> >
> > @@ -177,11 +182,45 @@ static void test_stream_device(void)
> > basic_event_loop_destroy();
> > }
> >
> > +static void test_stream_device_unfinished(void)
> > +{
> > + uint8_t *p = message;
> > + SpiceCoreInterface *core = basic_event_loop_init();
> > + Test *test = test_new(core);
> > +
> > + pos = 0;
> > + message_sizes_curr = message_sizes;
> > + message_sizes_end = message_sizes;
> > +
> > + // this long and not finished message should not cause an inifinite
> > loop
> > + p = add_stream_hdr(p, STREAM_TYPE_DATA, 100000);
> > + *message_sizes_end = p - message;
> > + ++message_sizes_end;
> > +
> > + vmc_instance.base.sif = &vmc_interface.base;
> > + spice_server_add_interface(test->server, &vmc_instance.base);
> > +
> > + // we need to open the device and kick the start
> > + // the alarm is to avoid program to stuck
> > + alarm(5);
> > + spice_server_port_event(&vmc_instance, SPICE_PORT_EVENT_OPENED);
> > + spice_server_char_device_wakeup(&vmc_instance);
> > + alarm(0);
> > +
> > + // we should read all data
> > + g_assert(message_sizes_curr - message_sizes == 1);
> > +
> > + test_destroy(test);
> > + basic_event_loop_destroy();
> > +}
> > +
> > +
> > int main(int argc, char *argv[])
> > {
> > g_test_init(&argc, &argv, NULL);
> >
> > g_test_add_func("/server/stream-device", test_stream_device);
> > + g_test_add_func("/server/stream-device-unfinished",
> > test_stream_device_unfinished);
> >
> > return g_test_run();
> > }
More information about the Spice-devel
mailing list