[Spice-commits] server/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 24 21:11:28 UTC 2020


 server/tests/test-smartcard.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

New commits:
commit 1e13fb13c72cd857d1ac7af4a642f4a8ef8c0d6d
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Oct 13 21:28:10 2019 +0100

    test-smartcard: Test invalid reader closes the channel
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/tests/test-smartcard.c b/server/tests/test-smartcard.c
index f102452f..25a1bc2b 100644
--- a/server/tests/test-smartcard.c
+++ b/server/tests/test-smartcard.c
@@ -48,6 +48,7 @@ static SpiceBuffer channel_buf;
 static SpiceBuffer channel_expected;
 // expected buffer in device
 static SpiceBuffer device_expected;
+static SpiceWatch *watch;
 
 static void next_test(void);
 
@@ -148,6 +149,13 @@ static void data_from_channel(int fd, int event, void *opaque)
     uint8_t buf[128];
     ssize_t ret = socket_read(fd, buf, sizeof(buf));
     if (ret <= 0) {
+        g_assert(ret == 0 || errno == EAGAIN || errno == EINTR);
+        if (ret == 0) {
+            g_warning("TEST: connection closed");
+            core->watch_remove(watch);
+            watch = NULL;
+            next_test();
+        }
         return;
     }
     spice_buffer_append(&channel_buf, buf, ret);
@@ -294,7 +302,19 @@ static void next_test(void)
 
         spice_server_char_device_wakeup(&vmc->instance);
         } break;
-    case 8:
+    // Eighth test, a message with invalid reader ID from device caused the channel
+    // to be closed
+    case 8: {
+        g_test_assert_expected_messages();
+
+        g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+                              "*ERROR: received message for non existing reader*");
+        g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+                              "*TEST: connection closed*");
+
+        send_data(client_socket, VSC_APDU, 0xabcd);
+        } break;
+    case 9:
         g_test_assert_expected_messages();
         basic_event_loop_quit();
         break;
@@ -350,8 +370,7 @@ static void test_smartcard(TestFixture *fixture, gconstpointer user_data)
     send_ack_sync(client_socket, 1);
 
     // check data are processed
-    SpiceWatch *watch = core->watch_add(client_socket, SPICE_WATCH_EVENT_READ,
-                                        data_from_channel, NULL);
+    watch = core->watch_add(client_socket, SPICE_WATCH_EVENT_READ, data_from_channel, NULL);
     vmc->data_written_cb = check_data;
 
     // start all test
@@ -361,7 +380,9 @@ static void test_smartcard(TestFixture *fixture, gconstpointer user_data)
     alarm(0);
 
     // cleanup
-    core->watch_remove(watch);
+    if (watch) {
+        core->watch_remove(watch);
+    }
     red_client_destroy(client);
     g_object_unref(main_channel);
     g_object_unref(channel);


More information about the Spice-commits mailing list