diff --git a/vtest/vtest.h b/vtest/vtest.h index ae2e196..d91ef51 100644 --- a/vtest/vtest.h +++ b/vtest/vtest.h @@ -18,5 +18,7 @@ int vtest_block_read(int fd, void *buf, int size); int vtest_resource_busy_wait(void); int vtest_renderer_create_fence(void); int vtest_poll(void); + +void vtest_destroy_renderer(void); #endif diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index 6fc9d3f..a8a5184 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -58,8 +58,8 @@ int vtest_block_read(int fd, void *buf, int size) left = size; do { ret = read(fd, ptr, left); - if (ret < 0) - return -errno; + if (ret <= 0) + return ret == -1 ? -errno : 0; left -= ret; ptr += ret; } while (left); @@ -78,11 +78,20 @@ int vtest_create_renderer(int fd) 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) { uint32_t max_ver, max_size; void *caps_buf; uint32_t hdr_buf[2]; + int ret; + virgl_renderer_get_cap_set(1, &max_ver, &max_size); caps_buf = malloc(max_size); @@ -93,8 +102,13 @@ int vtest_send_caps(void) hdr_buf[0] = max_size + 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); + if (ret < 0) + return ret; + return 0; } @@ -201,7 +215,7 @@ int vtest_transfer_get(uint32_t length_dw) iovec.iov_len = data_size; iovec.iov_base = ptr; - virgl_renderer_transfer_read_iov(handle, + ret = virgl_renderer_transfer_read_iov(handle, ctx_id, level, stride, @@ -209,8 +223,12 @@ int vtest_transfer_get(uint32_t length_dw) &box, 0, &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); return 0; } @@ -235,18 +253,22 @@ int vtest_transfer_put(uint32_t length_dw) if (!ptr) 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_base = ptr; - virgl_renderer_transfer_write_iov(handle, - ctx_id, - level, - stride, - layer_stride, - &box, - 0, - &iovec, 1); + ret = virgl_renderer_transfer_write_iov(handle, + ctx_id, + level, + stride, + layer_stride, + &box, + 0, + &iovec, 1); + if (ret) + fprintf(stderr," transfer write failed %d\n", ret); free(ptr); return 0; } @@ -284,8 +306,14 @@ int vtest_resource_busy_wait(void) reply_buf[0] = busy ? 1 : 0; fprintf(stderr, "busy check %d, %d\n", handle, flags); - vtest_block_write(renderer.remote_fd, hdr_buf, sizeof(hdr_buf)); - vtest_block_write(renderer.remote_fd, reply_buf, sizeof(reply_buf)); + ret = vtest_block_write(renderer.remote_fd, hdr_buf, sizeof(hdr_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; } @@ -298,4 +326,5 @@ int vtest_renderer_create_fence(void) int vtest_poll(void) { virgl_renderer_poll(); + return 0; } diff --git a/vtest/vtest_server.c b/vtest/vtest_server.c index 0486305..af36272 100644 --- a/vtest/vtest_server.c +++ b/vtest/vtest_server.c @@ -84,7 +84,7 @@ int main(void) static int fence_id = 1; bool do_fence; sock = vtest_open_socket("/tmp/.virgl_test"); - +restart: new_fd = wait_for_socket_accept(sock); vtest_create_renderer(new_fd); @@ -101,34 +101,48 @@ again: do_fence = false; switch (header[1]) { case VCMD_GET_CAPS: - vtest_send_caps(); + ret = vtest_send_caps(); break; case VCMD_RESOURCE_CREATE: - vtest_create_resource(); + ret = vtest_create_resource(); break; case VCMD_RESOURCE_UNREF: - vtest_resource_unref(); + ret = vtest_resource_unref(); break; case VCMD_SUBMIT_CMD: - vtest_submit_cmd(header[0]); + ret = vtest_submit_cmd(header[0]); do_fence = true; break; case VCMD_TRANSFER_GET: - vtest_transfer_get(header[0]); + ret = vtest_transfer_get(header[0]); break; case VCMD_TRANSFER_PUT: - vtest_transfer_put(header[0]); + ret = vtest_transfer_put(header[0]); do_fence = true; break; case VCMD_RESOURCE_BUSY_WAIT: - vtest_resource_busy_wait(); + ret = vtest_resource_busy_wait(); default: break; } + + if (ret < 0) { + fprintf(stderr, "socket failed - relistening\n"); + close(new_fd); + vtest_destroy_renderer(); + goto restart; + } + if (do_fence) vtest_renderer_create_fence(); goto again; } + if (ret <= 0) { + fprintf(stderr, "socket failed - relistening\n"); + close(new_fd); + vtest_destroy_renderer(); + goto restart; + } err: close(new_fd); close(sock);