[v2,2/2] vtest: Add versioning mechanism to protocol

Submitted by Tomeu Vizoso on Aug. 3, 2018, 7:15 a.m.

Details

Message ID 20180803071545.35033-3-tomeu.vizoso@collabora.com
State New
Series "vtest: Back resources with buffers"
Headers show

Commit Message

Tomeu Vizoso Aug. 3, 2018, 7:15 a.m.
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(-)

Patch hide | download patch | download mbox

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 af2ebf1cef43..c29536396bde 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;
@@ -55,6 +56,7 @@  struct virgl_renderer_callbacks vtest_cbs = {
 struct vtest_renderer {
   int in_fd;
   int out_fd;
+  unsigned protocol_version;
 };
 
 struct vtest_renderer renderer;
@@ -112,15 +114,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;
 
@@ -147,18 +158,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;