From 3802f56a3b9ba6d402057e94d8212b09c9d2b969 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 1 Jul 2020 16:03:31 -0700 Subject: [PATCH] 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 Reviewed-by: Isaac Bosompem --- vtest/vtest.h | 1 + vtest/vtest_fuzzer.c | 3 +++ vtest/vtest_renderer.c | 42 +++++++++++++++++++++++++++++++----------- vtest/vtest_server.c | 5 +++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/vtest/vtest.h b/vtest/vtest.h index d8f5a41..f4038ea 100644 --- a/vtest/vtest.h +++ b/vtest/vtest.h @@ -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); diff --git a/vtest/vtest_fuzzer.c b/vtest/vtest_fuzzer.c index 68d1b14..9fe0958 100644 --- a/vtest/vtest_fuzzer.c +++ b/vtest/vtest_fuzzer.c @@ -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; } diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index 3d12bc3..0ed5512 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -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); } diff --git a/vtest/vtest_server.c b/vtest/vtest_server.c index 821577d..4d09724 100644 --- a/vtest/vtest_server.c +++ b/vtest/vtest_server.c @@ -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]);