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. 135
      vtest/vtest_server.c

@ -27,21 +27,21 @@
#include <errno.h>
int vtest_create_renderer(int in_fd, int out_fd, uint32_t length);
int vtest_send_caps(void);
int vtest_send_caps2(void);
int vtest_create_resource(void);
int vtest_create_resource2(void);
int vtest_resource_unref(void);
int vtest_send_caps(uint32_t length_dw);
int vtest_send_caps2(uint32_t length_dw);
int vtest_create_resource(uint32_t length_dw);
int vtest_create_resource2(uint32_t length_dw);
int vtest_resource_unref(uint32_t length_dw);
int vtest_submit_cmd(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_put2(void);
int vtest_transfer_put2(uint32_t length_dw);
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_poll(void);

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

@ -33,6 +33,7 @@
#include <fcntl.h>
#include "util.h"
#include "util/u_memory.h"
#include "vtest.h"
#include "vtest_protocol.h"
@ -86,85 +87,83 @@ static int wait_for_socket_accept(int sock)
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)
{
int ret;
uint32_t header[VTEST_HDR_SIZE];
bool inited = false;
again:
ret = vtest_wait_for_fd_read(in_fd);
if (ret < 0)
goto fail;
int err, ret;
uint32_t header[VTEST_HDR_SIZE];
int initialized = 0;
do {
ret = vtest_wait_for_fd_read(in_fd);
if (ret < 0) {
err = 1;
break;
}
ret = vtest_block_read(in_fd, &header, sizeof(header));
if (ret < 0 || (size_t)ret < sizeof(header)) {
err = 2;
break;
}
ret = vtest_block_read(in_fd, &header, sizeof(header));
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]);
inited = true;
ret = vtest_create_renderer(in_fd, out_fd, header[0]);
initialized = 1;
printf("%s: vtest initialized.\n", __func__);
vtest_poll();
continue;
}
vtest_poll();
switch (header[1]) {
case VCMD_GET_CAPS:
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;
case VCMD_SUBMIT_CMD:
ret = vtest_submit_cmd(header[0]);
break;
case VCMD_TRANSFER_GET:
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;
if (header[1] <= 0 || header[1] >= ARRAY_SIZE(vtest_commands)) {
err = 4;
break;
}
if (vtest_commands[header[1]] == NULL) {
err = 5;
break;
}
ret = vtest_commands[header[1]](header[0]);
if (ret < 0) {
goto fail;
err = 6;
break;
}
} while (1);
goto again;
}
if (ret <= 0) {
goto fail;
}
fail:
fprintf(stderr, "socket failed - closing renderer\n");
vtest_destroy_renderer();
close(in_fd);
return 0;
fprintf(stderr, "socket failed (%d) - closing renderer\n", err);
vtest_destroy_renderer();
close(in_fd);
return 0;
}
int main(int argc, char **argv)

Loading…
Cancel
Save