[gtk-vnc] Allow for writes to fail in server test



commit b99ee613feb00544b3699e05cd75c67af53777cf
Author: Daniel P. Berrangé <berrange redhat com>
Date:   Fri May 3 16:14:34 2019 +0100

    Allow for writes to fail in server test
    
    There is a race condition between the client and the server code. Once
    the client has detected an error condition it might close the connection
    before the server has finished writing its protocol message fully. Set a
    flag to allow for some writes to fail.
    
    Signed-off-by: Daniel P. Berrangé <berrange redhat com>

 src/vncconnectiontest.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/vncconnectiontest.c b/src/vncconnectiontest.c
index b2cbee1..c095bad 100644
--- a/src/vncconnectiontest.c
+++ b/src/vncconnectiontest.c
@@ -28,6 +28,7 @@
 #include "vncbaseframebuffer.h"
 
 static gboolean debug;
+static gboolean allowfail;
 
 struct GVncTest {
     GMutex lock;
@@ -48,30 +49,30 @@ struct GVncTest {
 
 static void test_send_bytes(GOutputStream *os, const guint8 *str, gsize len)
 {
-    g_assert(g_output_stream_write_all(os, str, len, NULL, NULL, NULL));
+    g_assert(g_output_stream_write_all(os, str, len, NULL, NULL, NULL) || allowfail);
 }
 
 static void test_send_u8(GOutputStream *os, guint8 v)
 {
-    g_assert(g_output_stream_write_all(os, &v, 1, NULL, NULL, NULL));
+    g_assert(g_output_stream_write_all(os, &v, 1, NULL, NULL, NULL) || allowfail);
 }
 
 static void test_send_u16(GOutputStream *os, guint16 v)
 {
     v = GUINT16_TO_BE(v);
-    g_assert(g_output_stream_write_all(os, &v, 2, NULL, NULL, NULL));
+    g_assert(g_output_stream_write_all(os, &v, 2, NULL, NULL, NULL) || allowfail);
 }
 
 static void test_send_u32(GOutputStream *os, guint32 v)
 {
     v = GUINT32_TO_BE(v);
-    g_assert(g_output_stream_write_all(os, &v, 4, NULL, NULL, NULL));
+    g_assert(g_output_stream_write_all(os, &v, 4, NULL, NULL, NULL) || allowfail);
 }
 
 static void test_send_s32(GOutputStream *os, gint32 v)
 {
     v = GINT32_TO_BE(v);
-    g_assert(g_output_stream_write_all(os, &v, 4, NULL, NULL, NULL));
+    g_assert(g_output_stream_write_all(os, &v, 4, NULL, NULL, NULL) || allowfail);
 }
 
 static void test_recv_bytes(GInputStream *is, guint8 *str, gsize len)
@@ -311,10 +312,12 @@ static void test_rre_bounds_server(GInputStream *is, GOutputStream *os)
     test_send_u32(os, 0x42424242);
 
     /* x, y, w, h */
+    allowfail = TRUE;
     test_send_u16(os, 10);
     test_send_u16(os, 10000);
     test_send_u16(os, 1);
     test_send_u16(os, 1);
+    allowfail = FALSE;
 }
 
 
@@ -347,8 +350,10 @@ static void test_hextile_bounds_server(GInputStream *is, GOutputStream *os)
     test_send_u32(os, 0x12345678);
 
     /* x, y */
+    allowfail = TRUE;
     test_send_u8(os, 0xff);
     test_send_u8(os, 0xff);
+    allowfail = FALSE;
 }
 
 
@@ -372,8 +377,10 @@ static void test_copyrect_bounds_server(GInputStream *is, GOutputStream *os)
     test_send_s32(os, 1);
 
     /* src x, y */
+    allowfail = TRUE;
     test_send_u16(os, 91);
     test_send_u16(os, 91);
+    allowfail = FALSE;
 }
 
 
@@ -434,6 +441,8 @@ static void test_unexpected_cmap_server(GInputStream *is, GOutputStream *os)
     test_send_u8(os, 1);
     /* pad */
     test_send_u8(os, 0);
+
+    allowfail = TRUE;
     /* first color, ncolors */
     test_send_u16(os, 0);
     test_send_u16(os, 1);
@@ -442,6 +451,7 @@ static void test_unexpected_cmap_server(GInputStream *is, GOutputStream *os)
     test_send_u16(os, 128);
     test_send_u16(os, 128);
     test_send_u16(os, 128);
+    allowfail = FALSE;
 }
 
 
@@ -506,12 +516,14 @@ static void test_overflow_cmap_server(GInputStream *is, GOutputStream *os)
     test_send_u16(os, 65535);
     test_send_u16(os, 2);
 
+    allowfail = TRUE;
     /* r,g,b */
     for (int i = 0 ; i < 2; i++) {
         test_send_u16(os, i);
         test_send_u16(os, i);
         test_send_u16(os, i);
     }
+    allowfail = FALSE;
 }
 
 


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