On Mon, Nov 20, 2017 at 11:48:53AM +0000, Frediano Ziglio wrote: > +*/ > +/** > + * Test streaming device > + */ > + > +#include <config.h> > +#include <string.h> > +#include <stdlib.h> > +#include <stdio.h> > + > +#include <spice/protocol.h> > +#include <spice/stream-device.h> > + > +#include "test-display-base.h" > +#include "test-glib-compat.h" > + > +#ifndef MIN > +#define MIN(a, b) ((a) > (b) ? (b) : (a)) > +#endif You get this when including glib.h, so I would expect this is not needed. > + > +static SpiceCharDeviceInstance vmc_instance; > + > +// device buffer to read from > +static uint8_t message[2048]; > +// position to read from > +static unsigned pos; > +// array of limits when the read should return > +// the array is defined as [message_sizes_curr, message_sizes_end) > +// then the size is reach we move on next one till exausted > +static unsigned message_sizes[16]; > +static unsigned *message_sizes_end, *message_sizes_curr; > + > +// handle writes to the device > +static int vmc_write(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin, > + SPICE_GNUC_UNUSED const uint8_t *buf, > + int len) > +{ > + // currently we don't test any on write so reply we wrote it s/any/anything? > + return len; > +} > + > +static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin, > + uint8_t *buf, > + int len) > +{ > + int ret; > + > + if (pos >= *message_sizes_curr && message_sizes_curr < message_sizes_end) { > + ++message_sizes_curr; > + } > + if (message_sizes_curr >= message_sizes_end || pos >= *message_sizes_curr) { > + return 0; > + } > + ret = MIN(*message_sizes_curr - pos, len); > + memcpy(buf, &message[pos], ret); > + pos += ret; > + // kick of next message read s/of/off? [...] > +static void test_stream_device(void) > +{ > + uint8_t *p = message; > + SpiceCoreInterface *core = basic_event_loop_init(); > + Test *test = test_new(core); > + > + message_sizes_curr = message_sizes; > + message_sizes_end = message_sizes; > + > + // add some messages into device buffer > + // here we are testing the device is reading at least two > + // consecutive format messages > + // first message part has 2 extra bytes to check for header split > + p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG); > + *message_sizes_end++ = p - message + 2; I'd split this and the ones below in 2 lines > + > + p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_VP9); > + *message_sizes_end++ = p - message; > + > + // add a message to stop data to be read > + p = add_stream_hdr(p, STREAM_TYPE_INVALID, 0); > + *message_sizes_end++ = p - message; > + > + // this message should not be read > + p = add_stream_hdr(p, STREAM_TYPE_INVALID, 0); > + *message_sizes_end++ = p - message; > + > + vmc_instance.base.sif = &vmc_interface.base; > + spice_server_add_interface(test->server, &vmc_instance.base); > + > + // device should not have readed data before we open it s/readed/read Apart from this, looks good to me, Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel