[Spice-commits] 2 commits - server/tests
Frediano Ziglio
fziglio at kemper.freedesktop.org
Tue Feb 27 10:44:28 UTC 2018
server/tests/test-stream-device.c | 79 +++++++++++++++++++++++++++++++++++++-
1 file changed, 77 insertions(+), 2 deletions(-)
New commits:
commit 5327d0f559c0d835ec517d3c86aaae6f3516f4e5
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Sat Jan 13 21:42:11 2018 +0000
test-stream-device: Test batched multiple messages
Test all batched (send together) messages are handled correctly
and device is not stuck.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index ea40054c..7f3ec43c 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -215,12 +215,48 @@ static void test_stream_device_unfinished(void)
basic_event_loop_destroy();
}
+// check if sending multiple messages cause stall
+static void test_stream_device_multiple(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;
+
+ // add some messages into device buffer
+ p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG);
+ p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG);
+ p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG);
+ *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 prevent the program from getting stuck
+ alarm(5);
+ spice_server_port_event(&vmc_instance, SPICE_PORT_EVENT_OPENED);
+ spice_server_char_device_wakeup(&vmc_instance);
+ alarm(0);
+
+ // we should have 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);
+ g_test_add_func("/server/stream-device-multiple", test_stream_device_multiple);
return g_test_run();
}
commit c5ad710056fd9068d89e473e4f6682e4528ea4b8
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Dec 6 16:42:54 2017 +0000
test-stream-device: Better Qemu emulation for data reading
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>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index 656bf56b..ea40054c 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();
}
+// check if sending a partial message causes issues
+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 infinite 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 prevent the program from getting stuck
+ alarm(5);
+ spice_server_port_event(&vmc_instance, SPICE_PORT_EVENT_OPENED);
+ spice_server_char_device_wakeup(&vmc_instance);
+ alarm(0);
+
+ // we should have 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-commits
mailing list