[Spice-commits] 3 commits - server/tests
Christophe Fergau
teuf at kemper.freedesktop.org
Wed Feb 15 11:14:05 UTC 2017
server/tests/test-display-base.c | 39 +++++++++++++++++++----
server/tests/test-playback.c | 12 +++----
server/tests/test-vdagent.c | 65 +++++++++++++++++++++++++++++++++++----
3 files changed, 98 insertions(+), 18 deletions(-)
New commits:
commit f5494cfa9be16964dfc72bc3a179f7a4844140f9
Author: Christophe Fergeau <cfergeau at redhat.com>
Date: Thu Jan 26 18:31:23 2017 +0100
test-playback: Pass proper types to spice_server_add_interface
This is a revert of b76e561d.
For a SpicePlaybackInstance, the base interface must be a
SpicePlaybackInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.
Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
diff --git a/server/tests/test-playback.c b/server/tests/test-playback.c
index 564d42a..bad11a0 100644
--- a/server/tests/test-playback.c
+++ b/server/tests/test-playback.c
@@ -36,11 +36,11 @@
SpicePlaybackInstance playback_instance;
-static const SpiceBaseInterface base = {
- .type = SPICE_INTERFACE_PLAYBACK,
- .description = "test playback",
- .major_version = SPICE_INTERFACE_PLAYBACK_MAJOR,
- .minor_version = SPICE_INTERFACE_PLAYBACK_MINOR,
+static const SpicePlaybackInterface playback_sif = {
+ .base.type = SPICE_INTERFACE_PLAYBACK,
+ .base.description = "test playback",
+ .base.major_version = SPICE_INTERFACE_PLAYBACK_MAJOR,
+ .base.minor_version = SPICE_INTERFACE_PLAYBACK_MINOR,
};
uint32_t *frame;
@@ -112,7 +112,7 @@ int main(void)
spice_server_set_noauth(server);
spice_server_init(server, core);
- playback_instance.base.sif = &base;
+ playback_instance.base.sif = &playback_sif.base;
spice_server_add_interface(server, &playback_instance.base);
spice_server_playback_start(&playback_instance);
commit 1afa86c3eefa8b98443139d34da7ad86b51ddd27
Author: Christophe Fergeau <cfergeau at redhat.com>
Date: Thu Jan 26 18:30:54 2017 +0100
test-display-base: Pass proper types to spice_server_add_interface
This is a revert of 93b4f4050^ and 93b4f4050.
For a SpiceCharDeviceInstance, the base interface must be a
SpiceCharDeviceInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.
vmc_state/vmc_write/vmc_read implementations also have to be provided.
Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 04c6403..55e37a5 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -816,16 +816,43 @@ void test_add_display_interface(Test* test)
spice_server_add_interface(test->server, &test->qxl_instance.base);
}
-static SpiceBaseInterface base = {
- .type = SPICE_INTERFACE_CHAR_DEVICE,
- .description = "test spice virtual channel char device",
- .major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
- .minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
+static int vmc_write(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ SPICE_GNUC_UNUSED const uint8_t *buf,
+ int len)
+{
+ printf("%s: %d\n", __func__, len);
+ return len;
+}
+
+static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ SPICE_GNUC_UNUSED uint8_t *buf,
+ int len)
+{
+ printf("%s: %d\n", __func__, len);
+ return 0;
+}
+
+static void vmc_state(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ int connected)
+{
+ printf("%s: %d\n", __func__, connected);
+}
+
+
+static SpiceCharDeviceInterface vdagent_sif = {
+ .base.type = SPICE_INTERFACE_CHAR_DEVICE,
+ .base.description = "test spice virtual channel char device",
+ .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
+ .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
+ .state = vmc_state,
+ .write = vmc_write,
+ .read = vmc_read,
+
};
SpiceCharDeviceInstance vdagent_sin = {
.base = {
- .sif = &base,
+ .sif = &vdagent_sif.base,
},
.subtype = "vdagent",
};
commit 14b2f053aba2b996d4aa8dec791bf451b34cde8a
Author: Christophe Fergeau <cfergeau at redhat.com>
Date: Thu Jan 26 18:24:19 2017 +0100
test-vdagent: Pass proper types to spice_server_add_interface
This is a revert of 93b4f4050^ and 93b4f4050.
For a SpiceCharDeviceInstance, the base interface must be a
SpiceCharDeviceInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.
vmc_state/vmc_write/vmc_read implementations also have to be provided.
Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
diff --git a/server/tests/test-vdagent.c b/server/tests/test-vdagent.c
index 7f905ad..e06229e 100644
--- a/server/tests/test-vdagent.c
+++ b/server/tests/test-vdagent.c
@@ -45,11 +45,64 @@ static void pinger(SPICE_GNUC_UNUSED void *opaque)
core->timer_start(ping_timer, ping_ms);
}
-static SpiceBaseInterface base = {
- .type = SPICE_INTERFACE_CHAR_DEVICE,
- .description = "test spice virtual channel char device",
- .major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
- .minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
+static int vmc_write(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ SPICE_GNUC_UNUSED const uint8_t *buf,
+ int len)
+{
+ return len;
+}
+
+static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ uint8_t *buf,
+ int len)
+{
+ static uint8_t c = 0;
+ static uint8_t message[2048];
+ static unsigned pos = 0;
+ static unsigned message_size;
+ int ret;
+
+ if (pos == 0) {
+ VDIChunkHeader *hdr = (VDIChunkHeader *)message;
+ VDAgentMessage *msg = (VDAgentMessage *)&hdr[1];
+ uint8_t *p = message;
+ int size = sizeof(message);
+ message_size = size;
+ /* fill in message */
+ hdr->port = VDP_SERVER_PORT;
+ hdr->size = message_size - sizeof(VDIChunkHeader);
+ msg->protocol = VD_AGENT_PROTOCOL;
+ msg->type = VD_AGENT_END_MESSAGE;
+ msg->opaque = 0;
+ msg->size = message_size - sizeof(VDIChunkHeader) - sizeof(VDAgentMessage);
+ size -= sizeof(VDIChunkHeader) + sizeof(VDAgentMessage);
+ p += sizeof(VDIChunkHeader) + sizeof(VDAgentMessage);
+ for (; size; --size, ++p, ++c)
+ *p = c;
+ }
+ ret = MIN(message_size - pos, len);
+ memcpy(buf, &message[pos], ret);
+ pos += ret;
+ if (pos == message_size) {
+ pos = 0;
+ }
+ //printf("vmc_read %d (ret %d)\n", len, ret);
+ return ret;
+}
+
+static void vmc_state(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin,
+ SPICE_GNUC_UNUSED int connected)
+{
+}
+
+static SpiceCharDeviceInterface vmc_interface = {
+ .base.type = SPICE_INTERFACE_CHAR_DEVICE,
+ .base.description = "test spice virtual channel char device",
+ .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
+ .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
+ .state = vmc_state,
+ .write = vmc_write,
+ .read = vmc_read,
};
SpiceCharDeviceInstance vmc_instance = {
@@ -63,7 +116,7 @@ int main(void)
core = basic_event_loop_init();
test = test_new(core);
- vmc_instance.base.sif = &base;
+ vmc_instance.base.sif = &vmc_interface.base;
spice_server_add_interface(test->server, &vmc_instance.base);
ping_timer = core->timer_add(pinger, NULL);
More information about the Spice-commits
mailing list