vtest: defer virgl_renderer_context_create

Move virgl_renderer_context_create call from vtest_create_context to
the new vtest_lazy_init_context.  This defers context initialization
until the first command after VCMD_CREATE_RENDERER.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Isaac Bosompem <mrisaacb@google.com>
macos/master
Chia-I Wu 5 years ago
parent 654771bca1
commit 3802f56a3b
  1. 1
      vtest/vtest.h
  2. 3
      vtest/vtest_fuzzer.c
  3. 42
      vtest/vtest_renderer.c
  4. 5
      vtest/vtest_server.c

@ -47,6 +47,7 @@ void vtest_cleanup_renderer(void);
int vtest_create_context(struct vtest_input *input, int out_fd,
uint32_t length_dw, struct vtest_context **out_ctx);
int vtest_lazy_init_context(struct vtest_context *ctx);
void vtest_destroy_context(struct vtest_context *ctx);
void vtest_set_current_context(struct vtest_context *ctx);

@ -109,6 +109,9 @@ static void vtest_fuzzer_run_renderer(int out_fd, struct vtest_input *input,
if (ret >= 0) {
ret = vtest_create_context(input, out_fd, header[0], &context);
}
if (ret >= 0) {
ret = vtest_lazy_init_context(context);
}
if (ret < 0) {
break;
}

@ -61,7 +61,10 @@ struct vtest_context {
struct vtest_input *input;
int out_fd;
char *debug_name;
unsigned protocol_version;
bool context_initialized;
struct util_hash_table *resource_table;
};
@ -321,8 +324,10 @@ static struct vtest_context *vtest_new_context(struct vtest_input *input,
ctx->input = input;
ctx->out_fd = out_fd;
ctx->debug_name = NULL;
/* By default we support version 0 unless VCMD_PROTOCOL_VERSION is sent */
ctx->protocol_version = 0;
ctx->context_initialized = false;
return ctx;
}
@ -356,26 +361,39 @@ int vtest_create_context(struct vtest_input *input, int out_fd,
vtestname = calloc(1, length + 1);
if (!vtestname) {
ret = -1;
goto end;
goto err;
}
ret = ctx->input->read(ctx->input, vtestname, length);
if (ret != (int)length) {
ret = -1;
goto end;
goto err;
}
ret = virgl_renderer_context_create(ctx->ctx_id, strlen(vtestname), vtestname);
ctx->debug_name = vtestname;
end:
list_addtail(&ctx->head, &renderer.active_contexts);
*out_ctx = ctx;
return 0;
err:
free(vtestname);
vtest_free_context(ctx, false);
return ret;
}
if (ret) {
vtest_free_context(ctx, false);
} else {
list_addtail(&ctx->head, &renderer.active_contexts);
*out_ctx = ctx;
}
int vtest_lazy_init_context(struct vtest_context *ctx)
{
int ret;
if (ctx->context_initialized)
return 0;
ret = virgl_renderer_context_create(ctx->ctx_id,
strlen(ctx->debug_name),
ctx->debug_name);
ctx->context_initialized = (ret == 0);
return ret;
}
@ -387,7 +405,9 @@ void vtest_destroy_context(struct vtest_context *ctx)
}
list_del(&ctx->head);
virgl_renderer_context_destroy(ctx->ctx_id);
free(ctx->debug_name);
if (ctx->context_initialized)
virgl_renderer_context_destroy(ctx->ctx_id);
util_hash_table_clear(ctx->resource_table);
vtest_free_context(ctx, false);
}

@ -636,6 +636,11 @@ static int vtest_client_dispatch_commands(struct vtest_client *client)
return VTEST_CLIENT_ERROR_COMMAND_UNEXPECTED;
}
ret = vtest_lazy_init_context(client->context);
if (ret) {
return VTEST_CLIENT_ERROR_CONTEXT_FAILED;
}
vtest_set_current_context(client->context);
ret = vtest_commands[header[1]](header[0]);

Loading…
Cancel
Save