vtest: refactorized the run_renderer function

run_renderer now uses an array to get the corresponding function
pointer for a command.
Some vtest_* function headers had to be uniformized.

Reviewed-by: Jakob Bornecrantz <jakob@collabora.com>
Signed-off-by: Nathan Gauer <nathan@gauer.org>
Signed-off-by: Jakob Bornecrantz <jakob@collabora.com>
macos/master
Nathan Gauer 6 years ago committed by Jakob Bornecrantz
parent 061c854de8
commit 298059b97e
  1. 16
      vtest/vtest.h
  2. 18
      vtest/vtest_renderer.c
  3. 117
      vtest/vtest_server.c

@ -27,21 +27,21 @@
#include <errno.h> #include <errno.h>
int vtest_create_renderer(int in_fd, int out_fd, uint32_t length); int vtest_create_renderer(int in_fd, int out_fd, uint32_t length);
int vtest_send_caps(void); int vtest_send_caps(uint32_t length_dw);
int vtest_send_caps2(void); int vtest_send_caps2(uint32_t length_dw);
int vtest_create_resource(void); int vtest_create_resource(uint32_t length_dw);
int vtest_create_resource2(void); int vtest_create_resource2(uint32_t length_dw);
int vtest_resource_unref(void); int vtest_resource_unref(uint32_t length_dw);
int vtest_submit_cmd(uint32_t length_dw); int vtest_submit_cmd(uint32_t length_dw);
int vtest_transfer_get(uint32_t length_dw); int vtest_transfer_get(uint32_t length_dw);
int vtest_transfer_get2(void); int vtest_transfer_get2(uint32_t length_dw);
int vtest_transfer_put(uint32_t length_dw); int vtest_transfer_put(uint32_t length_dw);
int vtest_transfer_put2(void); int vtest_transfer_put2(uint32_t length_dw);
int vtest_block_read(int fd, void *buf, int size); int vtest_block_read(int fd, void *buf, int size);
int vtest_resource_busy_wait(void); int vtest_resource_busy_wait(uint32_t length_dw);
int vtest_renderer_create_fence(void); int vtest_renderer_create_fence(void);
int vtest_poll(void); int vtest_poll(void);

@ -282,7 +282,7 @@ void vtest_destroy_renderer(void)
renderer.out_fd = -1; renderer.out_fd = -1;
} }
int vtest_send_caps2(void) int vtest_send_caps2(UNUSED uint32_t length_dw)
{ {
uint32_t hdr_buf[2]; uint32_t hdr_buf[2];
void *caps_buf; void *caps_buf;
@ -313,7 +313,7 @@ end:
return 0; return 0;
} }
int vtest_send_caps(void) int vtest_send_caps(UNUSED uint32_t length_dw)
{ {
uint32_t max_ver, max_size; uint32_t max_ver, max_size;
void *caps_buf; void *caps_buf;
@ -342,7 +342,7 @@ end:
return 0; return 0;
} }
int vtest_create_resource(void) int vtest_create_resource(UNUSED uint32_t length_dw)
{ {
uint32_t res_create_buf[VCMD_RES_CREATE_SIZE]; uint32_t res_create_buf[VCMD_RES_CREATE_SIZE];
struct virgl_renderer_resource_create_args args; struct virgl_renderer_resource_create_args args;
@ -371,7 +371,7 @@ int vtest_create_resource(void)
return ret; return ret;
} }
int vtest_create_resource2(void) int vtest_create_resource2(UNUSED uint32_t length_dw)
{ {
uint32_t res_create_buf[VCMD_RES_CREATE2_SIZE]; uint32_t res_create_buf[VCMD_RES_CREATE2_SIZE];
struct virgl_renderer_resource_create_args args; struct virgl_renderer_resource_create_args args;
@ -420,7 +420,7 @@ int vtest_create_resource2(void)
return ret; return ret;
} }
int vtest_resource_unref(void) int vtest_resource_unref(UNUSED uint32_t length_dw)
{ {
uint32_t res_unref_buf[VCMD_RES_UNREF_SIZE]; uint32_t res_unref_buf[VCMD_RES_UNREF_SIZE];
int ret; int ret;
@ -575,7 +575,7 @@ int vtest_transfer_put(UNUSED uint32_t length_dw)
} while(0) } while(0)
int vtest_transfer_get2(void) int vtest_transfer_get2(UNUSED uint32_t length_dw)
{ {
uint32_t thdr_buf[VCMD_TRANSFER2_HDR_SIZE]; uint32_t thdr_buf[VCMD_TRANSFER2_HDR_SIZE];
int ret; int ret;
@ -638,7 +638,7 @@ int vtest_transfer_get2(void)
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
int vtest_transfer_put2(void) int vtest_transfer_put2(UNUSED uint32_t length_dw)
{ {
uint32_t thdr_buf[VCMD_TRANSFER2_HDR_SIZE]; uint32_t thdr_buf[VCMD_TRANSFER2_HDR_SIZE];
int ret; int ret;
@ -680,7 +680,7 @@ int vtest_transfer_put2(void)
return 0; return 0;
} }
int vtest_resource_busy_wait(void) int vtest_resource_busy_wait(UNUSED uint32_t length_dw)
{ {
uint32_t bw_buf[VCMD_BUSY_WAIT_SIZE]; uint32_t bw_buf[VCMD_BUSY_WAIT_SIZE];
int ret, fd; int ret, fd;
@ -688,6 +688,8 @@ int vtest_resource_busy_wait(void)
uint32_t hdr_buf[VTEST_HDR_SIZE]; uint32_t hdr_buf[VTEST_HDR_SIZE];
uint32_t reply_buf[1]; uint32_t reply_buf[1];
bool busy = false; bool busy = false;
vtest_renderer_create_fence();
ret = vtest_block_read(renderer.in_fd, &bw_buf, sizeof(bw_buf)); ret = vtest_block_read(renderer.in_fd, &bw_buf, sizeof(bw_buf));
if (ret != sizeof(bw_buf)) if (ret != sizeof(bw_buf))
return -1; return -1;

@ -33,6 +33,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "util.h" #include "util.h"
#include "util/u_memory.h"
#include "vtest.h" #include "vtest.h"
#include "vtest_protocol.h" #include "vtest_protocol.h"
@ -86,84 +87,82 @@ static int wait_for_socket_accept(int sock)
return -1; return -1;
} }
typedef int (*vtest_cmd_fptr_t)(uint32_t);
static const vtest_cmd_fptr_t vtest_commands[] = {
NULL /* CMD ids starts at 1 */,
vtest_send_caps,
vtest_create_resource,
vtest_resource_unref,
vtest_transfer_get,
vtest_transfer_put,
vtest_submit_cmd,
vtest_resource_busy_wait,
NULL, /* vtest_create_renderer is a specific case */
vtest_send_caps2,
vtest_ping_protocol_version,
vtest_protocol_version,
vtest_create_resource2,
vtest_transfer_get2,
vtest_transfer_put2,
};
static int run_renderer(int in_fd, int out_fd) static int run_renderer(int in_fd, int out_fd)
{ {
int ret; int err, ret;
uint32_t header[VTEST_HDR_SIZE]; uint32_t header[VTEST_HDR_SIZE];
bool inited = false; int initialized = 0;
again:
do {
ret = vtest_wait_for_fd_read(in_fd); ret = vtest_wait_for_fd_read(in_fd);
if (ret < 0) if (ret < 0) {
goto fail; err = 1;
break;
}
ret = vtest_block_read(in_fd, &header, sizeof(header)); ret = vtest_block_read(in_fd, &header, sizeof(header));
if (ret < 0 || (size_t)ret < sizeof(header)) {
err = 2;
break;
}
if (!initialized) {
/* The first command MUST be VCMD_CREATE_RENDERER */
if (header[1] != VCMD_CREATE_RENDERER) {
err = 3;
break;
}
if (ret == 8) {
if (!inited) {
if (header[1] != VCMD_CREATE_RENDERER)
goto fail;
ret = vtest_create_renderer(in_fd, out_fd, header[0]); ret = vtest_create_renderer(in_fd, out_fd, header[0]);
inited = true; initialized = 1;
printf("%s: vtest initialized.\n", __func__);
vtest_poll();
continue;
} }
vtest_poll(); vtest_poll();
switch (header[1]) { if (header[1] <= 0 || header[1] >= ARRAY_SIZE(vtest_commands)) {
case VCMD_GET_CAPS: err = 4;
ret = vtest_send_caps();
break;
case VCMD_RESOURCE_CREATE:
ret = vtest_create_resource();
break;
case VCMD_RESOURCE_CREATE2:
ret = vtest_create_resource2();
break;
case VCMD_RESOURCE_UNREF:
ret = vtest_resource_unref();
break; break;
case VCMD_SUBMIT_CMD: }
ret = vtest_submit_cmd(header[0]);
break; if (vtest_commands[header[1]] == NULL) {
case VCMD_TRANSFER_GET: err = 5;
ret = vtest_transfer_get(header[0]);
break;
case VCMD_TRANSFER_PUT:
ret = vtest_transfer_put(header[0]);
break;
case VCMD_TRANSFER_GET2:
ret = vtest_transfer_get2();
break;
case VCMD_TRANSFER_PUT2:
ret = vtest_transfer_put2();
break;
case VCMD_RESOURCE_BUSY_WAIT:
vtest_renderer_create_fence();
ret = vtest_resource_busy_wait();
break;
case VCMD_GET_CAPS2:
ret = vtest_send_caps2();
break;
case VCMD_PING_PROTOCOL_VERSION:
ret = vtest_ping_protocol_version();
break;
case VCMD_PROTOCOL_VERSION:
ret = vtest_protocol_version();
break;
default:
break; break;
} }
ret = vtest_commands[header[1]](header[0]);
if (ret < 0) { if (ret < 0) {
goto fail; err = 6;
break;
} }
} while (1);
fprintf(stderr, "socket failed (%d) - closing renderer\n", err);
goto again;
}
if (ret <= 0) {
goto fail;
}
fail:
fprintf(stderr, "socket failed - closing renderer\n");
vtest_destroy_renderer(); vtest_destroy_renderer();
close(in_fd); close(in_fd);
return 0; return 0;
} }

Loading…
Cancel
Save