[Spice-devel] [PATCH spice-server 3/3] test-stream-device: Check monitor ID messages
Frediano Ziglio
fziglio at redhat.com
Mon Feb 4 14:27:53 UTC 2019
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/tests/test-stream-device.c | 53 +++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index f1707d2f..b0448cf8 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -34,6 +34,8 @@
#include "stream-channel.h"
#include "reds.h"
+#include "../reds.c"
+
static SpiceCharDeviceInstance vmc_instance;
// device buffer to read from
@@ -491,6 +493,56 @@ static void test_stream_device_data_message(TestFixture *fixture, gconstpointer
g_assert_cmpint(send_data_bytes, ==, 1017);
}
+static void test_display_info(TestFixture *fixture, gconstpointer user_data)
+{
+ // build a message for the streaming device
+ static const char address[] = "pci/a/b.cde";
+ StreamMsgDeviceDisplayInfo info = {
+ .stream_id = GUINT32_TO_LE(0x01020304),
+ .device_display_id = GUINT32_TO_LE(0x0a0b0c0d),
+ .device_address_len = GUINT32_TO_LE(sizeof(address)),
+ };
+ uint8_t *p = message;
+ p = add_stream_hdr(p, STREAM_TYPE_DEVICE_DISPLAY_INFO, sizeof(info) + sizeof(address));
+ memcpy(p, &info, sizeof(info));
+ p += sizeof(info);
+ strcpy((char*)p, address);
+ p += sizeof(address);
+
+ *message_sizes_end = p - message;
+ ++message_sizes_end;
+
+ // parse the message we crafted
+ test_kick();
+
+ // initialize a QXL interface
+ test_add_display_interface(test);
+ spice_qxl_set_device_info(&test->qxl_instance, "pci/0/1.2", 0, 2);
+
+ // make sure the streaming device has a channel
+ reds_late_initialization(test->server);
+
+ // build the buffer to send to the agent for display information
+ size_t size_in = reds_compute_device_display_info(test->server, NULL);
+ void *buf = g_malloc(size_in);
+ size_t size_out = reds_compute_device_display_info(test->server, buf);
+ g_assert_cmpint(size_in, ==, size_out);
+
+ // check output buffer
+ static const uint8_t expected_buffer[] = {
+ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 10, 0, 0, 0,112, 99,105, 47, 48, 47, 49, 46, 50, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0,112, 99,
+ 105, 47, 48, 47, 49, 46, 50, 0, 0, 0, 0, 0, 4, 3, 2, 1,
+ 13, 12, 11, 10, 12, 0, 0, 0,112, 99,105, 47, 97, 47, 98, 46,
+ 99,100,101, 0
+ };
+ g_assert_cmpint(size_in, ==, sizeof(expected_buffer));
+ g_assert_true(memcmp(buf, expected_buffer, size_in) == 0);
+
+ g_free(buf);
+}
+
static void test_add(const char *name, void (*func)(TestFixture *, gconstpointer), gconstpointer arg)
{
g_test_add(name, TestFixture, arg, test_stream_device_setup, func, test_stream_device_teardown);
@@ -516,6 +568,7 @@ int main(int argc, char *argv[])
test_stream_device_huge_data, NULL);
test_add("/server/stream-device-data-message",
test_stream_device_data_message, NULL);
+ test_add("/server/display-info", test_display_info, NULL);
return g_test_run();
}
--
2.20.1
More information about the Spice-devel
mailing list