This switches the test to using the GTest API, and add several tests related to https://bugzilla.redhat.com/show_bug.cgi?id=1411194 The "multiple-vmc-devices" is based off code written by Frediano Ziglio. --- server/tests/Makefile.am | 1 + server/tests/test-vdagent.c | 87 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am index f696f9f..ee891c5 100644 --- a/server/tests/Makefile.am +++ b/server/tests/Makefile.am @@ -45,6 +45,7 @@ check_PROGRAMS = \ test-loop \ test-qxl-parsing \ test-stat-file \ + test-vdagent \ $(NULL) noinst_PROGRAMS = \ diff --git a/server/tests/test-vdagent.c b/server/tests/test-vdagent.c index e06229e..49c6a3b 100644 --- a/server/tests/test-vdagent.c +++ b/server/tests/test-vdagent.c @@ -37,14 +37,6 @@ int ping_ms = 100; #define MIN(a, b) ((a) > (b) ? (b) : (a)) #endif -static void pinger(SPICE_GNUC_UNUSED void *opaque) -{ - // show_channels is not thread safe - fails if disconnections / connections occur - //show_channels(server); - - core->timer_start(ping_timer, ping_ms); -} - static int vmc_write(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin, SPICE_GNUC_UNUSED const uint8_t *buf, int len) @@ -62,6 +54,11 @@ static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin, static unsigned message_size; int ret; + if (pos == sizeof(message)) { + g_message("sent whole message"); + pos++; /* Only print message once */ + return 0; + } if (pos == 0) { VDIChunkHeader *hdr = (VDIChunkHeader *)message; VDAgentMessage *msg = (VDAgentMessage *)&hdr[1]; @@ -83,9 +80,6 @@ static int vmc_read(SPICE_GNUC_UNUSED SpiceCharDeviceInstance *sin, 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; } @@ -105,24 +99,77 @@ static SpiceCharDeviceInterface vmc_interface = { .read = vmc_read, }; -SpiceCharDeviceInstance vmc_instance = { +static SpiceCharDeviceInstance vmc_instance = { .subtype = "vdagent", }; -int main(void) +static void test_multiple_vmc_devices(void) { - Test *test; + SpiceCharDeviceInstance vmc_instances[2] = { + { .subtype = "vdagent", }, + { .subtype = "vdagent", } + }; + int status; - core = basic_event_loop_init(); - test = test_new(core); + SpiceCoreInterface *core = basic_event_loop_init(); + Test *test = test_new(core); + g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, + "*spice_server_char_device_add_interface: vdagent already attached"); + g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, + "*spice_server_remove_interface: assertion 'char_device->st != NULL'*"); + vmc_instances[0].base.sif = &vmc_interface.base; + spice_server_add_interface(test->server, &vmc_instances[0].base); + vmc_instances[1].base.sif = &vmc_interface.base; + spice_server_add_interface(test->server, &vmc_instances[1].base); + status = spice_server_remove_interface(&vmc_instances[1].base); + g_assert_cmpint(status, ==, -1); + status = spice_server_remove_interface(&vmc_instances[0].base); + g_assert_cmpint(status, ==, 0); + g_test_assert_expected_messages(); + test_destroy(test); + basic_event_loop_destroy(); +} + +static void test_duplicate_removal(void) +{ + SpiceCoreInterface *core = basic_event_loop_init(); + Test *test = test_new(core); + int status; + + g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, + "*spice_server_remove_interface: assertion 'char_device->st != NULL'*"); + vmc_instance.base.sif = &vmc_interface.base; + spice_server_add_interface(test->server, &vmc_instance.base); + status = spice_server_remove_interface(&vmc_instance.base); + g_assert_cmpint(status, ==, 0); + status = spice_server_remove_interface(&vmc_instance.base); + g_assert_cmpint(status, ==, -1); + g_test_assert_expected_messages(); + test_destroy(test); + basic_event_loop_destroy(); +} + +static void test_agent_to_server(void) +{ + SpiceCoreInterface *core = basic_event_loop_init(); + Test *test = test_new(core); + + g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "sent whole message"); vmc_instance.base.sif = &vmc_interface.base; spice_server_add_interface(test->server, &vmc_instance.base); + g_test_assert_expected_messages(); + test_destroy(test); + basic_event_loop_destroy(); +} - ping_timer = core->timer_add(pinger, NULL); - core->timer_start(ping_timer, ping_ms); +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); - basic_event_loop_mainloop(); + g_test_add_func("/server/vdagent/agent-to-server", test_agent_to_server); + g_test_add_func("/server/vdagent/duplicate-removal", test_duplicate_removal); + g_test_add_func("/server/vdagent/multiple-vmc-devices", test_multiple_vmc_devices); - return 0; + return g_test_run(); } -- 2.9.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel