[virglrenderer-devel] [PATCH 3/3] vtest: Add versioning mechanism to protocol

Tomeu Vizoso tomeu.vizoso at collabora.com
Thu Aug 2 09:09:45 UTC 2018


This commit negotiates a common protocol version with the clients,
allowing for backwards compatibility on both sides.
---
 vtest/vtest_protocol.h |  7 ++++++-
 vtest/vtest_renderer.c | 33 +++++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/vtest/vtest_protocol.h b/vtest/vtest_protocol.h
index 1d3e426998d1..826498434a13 100644
--- a/vtest/vtest_protocol.h
+++ b/vtest/vtest_protocol.h
@@ -25,6 +25,7 @@
 #define VTEST_PROTOCOL
 
 #define VTEST_DEFAULT_SOCKET_NAME "/tmp/.virgl_test"
+#define VTEST_PROTOCOL_VERSION 1
 
 /* 32-bit length field */
 /* 32-bit cmd field */
@@ -46,7 +47,7 @@
 
 #define VCMD_RESOURCE_BUSY_WAIT 7
 
-/* pass the process cmd line for debugging */
+/* pass the process cmd line for debugging, and max version supported */
 #define VCMD_CREATE_RENDERER 8
 
 #define VCMD_GET_CAPS2 9
@@ -90,4 +91,8 @@
 #define VCMD_BUSY_WAIT_HANDLE 0
 #define VCMD_BUSY_WAIT_FLAGS 1
 
+#define VCMD_CREATE_RENDERER_SIZE 2
+#define VCMD_CREATE_RENDERER_VERSION 0
+#define VCMD_CREATE_RENDERER_NAME_SIZE 1
+
 #endif
diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c
index 6607f20c4bb6..6d31dab065ae 100644
--- a/vtest/vtest_renderer.c
+++ b/vtest/vtest_renderer.c
@@ -36,6 +36,7 @@
 #include "util.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
+#include "util/u_math.h"
 
 static int ctx_id = 1;
 static int fence_id = 1;
@@ -63,6 +64,7 @@ struct virgl_renderer_callbacks vtest_cbs = {
 struct vtest_renderer {
   int in_fd;
   int out_fd;
+  unsigned protocol_version;
 };
 
 struct vtest_renderer renderer;
@@ -120,15 +122,24 @@ int vtest_block_read(int fd, void *buf, int size)
    return size;
 }
 
-int vtest_create_renderer(int in_fd, int out_fd, uint32_t length)
+int vtest_create_renderer(int in_fd, int out_fd, UNUSED uint32_t length)
 {
     char *vtestname;
     int ret;
     int ctx = VIRGL_RENDERER_USE_EGL;
+    uint32_t hdr_buf[VTEST_HDR_SIZE], create_buf[VCMD_CREATE_RENDERER_SIZE];
+    uint32_t reply_buf[1];
 
     renderer.in_fd = in_fd;
     renderer.out_fd = out_fd;
 
+    ret = vtest_block_read(renderer.in_fd, &create_buf, sizeof(create_buf));
+    if (ret != sizeof(create_buf))
+        return -1;
+
+    renderer.protocol_version = MIN2(create_buf[VCMD_CREATE_RENDERER_VERSION],
+                                     VTEST_PROTOCOL_VERSION);
+
     if (getenv("VTEST_USE_GLX"))
        ctx = VIRGL_RENDERER_USE_GLX;
 
@@ -155,18 +166,32 @@ int vtest_create_renderer(int in_fd, int out_fd, uint32_t length)
       return -1;
     }
 
-    vtestname = calloc(1, length + 1);
+    vtestname = calloc(1, create_buf[VCMD_CREATE_RENDERER_NAME_SIZE] + 1);
     if (!vtestname)
       return -1;
 
-    ret = vtest_block_read(renderer.in_fd, vtestname, length);
-    if (ret != (int)length) {
+    ret = vtest_block_read(renderer.in_fd, vtestname, create_buf[VCMD_CREATE_RENDERER_NAME_SIZE]);
+    if (ret != (int)create_buf[VCMD_CREATE_RENDERER_NAME_SIZE]) {
        ret = -1;
        goto end;
     }
 
     ret = virgl_renderer_context_create(ctx_id, strlen(vtestname), vtestname);
 
+    hdr_buf[VTEST_CMD_LEN] = 1;
+    hdr_buf[VTEST_CMD_ID] = VCMD_CREATE_RENDERER;
+    reply_buf[0] = renderer.protocol_version;
+
+    ret = vtest_block_write(renderer.out_fd, hdr_buf, sizeof(hdr_buf));
+    if (ret < 0)
+      goto end;
+
+    ret = vtest_block_write(renderer.out_fd, reply_buf, sizeof(reply_buf));
+    if (ret < 0)
+      goto end;
+
+    ret = 0;
+
 end:
     free(vtestname);
     return ret;
-- 
2.17.1



More information about the virglrenderer-devel mailing list