vtest: add support for restarting after read error

allows running a few times in a row
macos/master
Dave Airlie 10 years ago
parent 16c60d5abf
commit 0a3ccfcb01
  1. 2
      vtest/vtest.h
  2. 61
      vtest/vtest_renderer.c
  3. 30
      vtest/vtest_server.c

@ -18,5 +18,7 @@ int vtest_block_read(int fd, void *buf, int size);
int vtest_resource_busy_wait(void); int vtest_resource_busy_wait(void);
int vtest_renderer_create_fence(void); int vtest_renderer_create_fence(void);
int vtest_poll(void); int vtest_poll(void);
void vtest_destroy_renderer(void);
#endif #endif

@ -58,8 +58,8 @@ int vtest_block_read(int fd, void *buf, int size)
left = size; left = size;
do { do {
ret = read(fd, ptr, left); ret = read(fd, ptr, left);
if (ret < 0) if (ret <= 0)
return -errno; return ret == -1 ? -errno : 0;
left -= ret; left -= ret;
ptr += ret; ptr += ret;
} while (left); } while (left);
@ -78,11 +78,20 @@ int vtest_create_renderer(int fd)
return ret; return ret;
} }
void vtest_destroy_renderer(void)
{
virgl_renderer_context_destroy(ctx_id);
virgl_renderer_cleanup(&renderer);
renderer.remote_fd = 0;
}
int vtest_send_caps(void) int vtest_send_caps(void)
{ {
uint32_t max_ver, max_size; uint32_t max_ver, max_size;
void *caps_buf; void *caps_buf;
uint32_t hdr_buf[2]; uint32_t hdr_buf[2];
int ret;
virgl_renderer_get_cap_set(1, &max_ver, &max_size); virgl_renderer_get_cap_set(1, &max_ver, &max_size);
caps_buf = malloc(max_size); caps_buf = malloc(max_size);
@ -93,8 +102,13 @@ int vtest_send_caps(void)
hdr_buf[0] = max_size + 1; hdr_buf[0] = max_size + 1;
hdr_buf[1] = 1; hdr_buf[1] = 1;
vtest_block_write(renderer.remote_fd, hdr_buf, 8); ret = vtest_block_write(renderer.remote_fd, hdr_buf, 8);
if (ret < 0)
return ret;
vtest_block_write(renderer.remote_fd, caps_buf, max_size); vtest_block_write(renderer.remote_fd, caps_buf, max_size);
if (ret < 0)
return ret;
return 0; return 0;
} }
@ -201,7 +215,7 @@ int vtest_transfer_get(uint32_t length_dw)
iovec.iov_len = data_size; iovec.iov_len = data_size;
iovec.iov_base = ptr; iovec.iov_base = ptr;
virgl_renderer_transfer_read_iov(handle, ret = virgl_renderer_transfer_read_iov(handle,
ctx_id, ctx_id,
level, level,
stride, stride,
@ -209,8 +223,12 @@ int vtest_transfer_get(uint32_t length_dw)
&box, &box,
0, 0,
&iovec, 1); &iovec, 1);
if (ret)
fprintf(stderr," transfer read failed %d\n", ret);
ret = vtest_block_write(renderer.remote_fd, ptr, data_size);
if (ret < 0)
return ret;
vtest_block_write(renderer.remote_fd, ptr, data_size);
free(ptr); free(ptr);
return 0; return 0;
} }
@ -235,18 +253,22 @@ int vtest_transfer_put(uint32_t length_dw)
if (!ptr) if (!ptr)
return -ENOMEM; return -ENOMEM;
vtest_block_read(renderer.remote_fd, ptr, data_size); ret = vtest_block_read(renderer.remote_fd, ptr, data_size);
if (ret < 0)
return ret;
iovec.iov_len = data_size; iovec.iov_len = data_size;
iovec.iov_base = ptr; iovec.iov_base = ptr;
virgl_renderer_transfer_write_iov(handle, ret = virgl_renderer_transfer_write_iov(handle,
ctx_id, ctx_id,
level, level,
stride, stride,
layer_stride, layer_stride,
&box, &box,
0, 0,
&iovec, 1); &iovec, 1);
if (ret)
fprintf(stderr," transfer write failed %d\n", ret);
free(ptr); free(ptr);
return 0; return 0;
} }
@ -284,8 +306,14 @@ int vtest_resource_busy_wait(void)
reply_buf[0] = busy ? 1 : 0; reply_buf[0] = busy ? 1 : 0;
fprintf(stderr, "busy check %d, %d\n", handle, flags); fprintf(stderr, "busy check %d, %d\n", handle, flags);
vtest_block_write(renderer.remote_fd, hdr_buf, sizeof(hdr_buf)); ret = vtest_block_write(renderer.remote_fd, hdr_buf, sizeof(hdr_buf));
vtest_block_write(renderer.remote_fd, reply_buf, sizeof(reply_buf)); if (ret < 0)
return ret;
ret = vtest_block_write(renderer.remote_fd, reply_buf, sizeof(reply_buf));
if (ret < 0)
return ret;
return 0; return 0;
} }
@ -298,4 +326,5 @@ int vtest_renderer_create_fence(void)
int vtest_poll(void) int vtest_poll(void)
{ {
virgl_renderer_poll(); virgl_renderer_poll();
return 0;
} }

@ -84,7 +84,7 @@ int main(void)
static int fence_id = 1; static int fence_id = 1;
bool do_fence; bool do_fence;
sock = vtest_open_socket("/tmp/.virgl_test"); sock = vtest_open_socket("/tmp/.virgl_test");
restart:
new_fd = wait_for_socket_accept(sock); new_fd = wait_for_socket_accept(sock);
vtest_create_renderer(new_fd); vtest_create_renderer(new_fd);
@ -101,34 +101,48 @@ again:
do_fence = false; do_fence = false;
switch (header[1]) { switch (header[1]) {
case VCMD_GET_CAPS: case VCMD_GET_CAPS:
vtest_send_caps(); ret = vtest_send_caps();
break; break;
case VCMD_RESOURCE_CREATE: case VCMD_RESOURCE_CREATE:
vtest_create_resource(); ret = vtest_create_resource();
break; break;
case VCMD_RESOURCE_UNREF: case VCMD_RESOURCE_UNREF:
vtest_resource_unref(); ret = vtest_resource_unref();
break; break;
case VCMD_SUBMIT_CMD: case VCMD_SUBMIT_CMD:
vtest_submit_cmd(header[0]); ret = vtest_submit_cmd(header[0]);
do_fence = true; do_fence = true;
break; break;
case VCMD_TRANSFER_GET: case VCMD_TRANSFER_GET:
vtest_transfer_get(header[0]); ret = vtest_transfer_get(header[0]);
break; break;
case VCMD_TRANSFER_PUT: case VCMD_TRANSFER_PUT:
vtest_transfer_put(header[0]); ret = vtest_transfer_put(header[0]);
do_fence = true; do_fence = true;
break; break;
case VCMD_RESOURCE_BUSY_WAIT: case VCMD_RESOURCE_BUSY_WAIT:
vtest_resource_busy_wait(); ret = vtest_resource_busy_wait();
default: default:
break; break;
} }
if (ret < 0) {
fprintf(stderr, "socket failed - relistening\n");
close(new_fd);
vtest_destroy_renderer();
goto restart;
}
if (do_fence) if (do_fence)
vtest_renderer_create_fence(); vtest_renderer_create_fence();
goto again; goto again;
} }
if (ret <= 0) {
fprintf(stderr, "socket failed - relistening\n");
close(new_fd);
vtest_destroy_renderer();
goto restart;
}
err: err:
close(new_fd); close(new_fd);
close(sock); close(sock);

Loading…
Cancel
Save