[PATCH spice-server v2 5/6] test-stream-device: Check we don't read past data message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Test case for the issue fixed by previous commit.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>
---
 server/tests/test-stream-device.c | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index 7c573acc..3c9209a4 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -286,6 +286,47 @@ static void test_stream_device_multiple(void)
     basic_event_loop_destroy();
 }
 
+// check if data message consume even following message
+static void test_stream_device_format_after_data(void)
+{
+    uint8_t *p = message;
+    SpiceCoreInterface *core = basic_event_loop_init();
+    Test *test = test_new(core);
+
+    pos = 0;
+    vmc_write_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_stream_hdr(p, STREAM_TYPE_DATA, 5);
+    memcpy(p, "hello", 5);
+    p += 5;
+    p = add_stream_hdr(p, STREAM_TYPE_INVALID, 0);
+    *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);
+
+    // we should have an error back
+    check_vmc_error_message();
+
+    test_destroy(test);
+    basic_event_loop_destroy();
+}
+
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
@@ -293,6 +334,7 @@ int main(int argc, char *argv[])
     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);
+    g_test_add_func("/server/stream-device-format-after-data", test_stream_device_format_after_data);
 
     return g_test_run();
 }
-- 
2.14.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]