diff --git a/vtest/vtest.h b/vtest/vtest.h index 463c2a0..be75339 100644 --- a/vtest/vtest.h +++ b/vtest/vtest.h @@ -27,7 +27,8 @@ #include -int vtest_create_renderer(int in_fd, int out_fd, uint32_t length); +int vtest_create_renderer(int in_fd, int out_fd, uint32_t length, + int ctx_flags); int vtest_send_caps(uint32_t length_dw); int vtest_send_caps2(uint32_t length_dw); diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index aef0984..f78d6e5 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -187,11 +187,11 @@ int vtest_block_read(int fd, void *buf, int size) return size; } -int vtest_create_renderer(int in_fd, int out_fd, uint32_t length) +int vtest_create_renderer(int in_fd, int out_fd, uint32_t length, + int ctx_flags) { char *vtestname; int ret; - int ctx = VIRGL_RENDERER_USE_EGL; renderer.iovec_hash = util_hash_table_create(hash_func, compare_iovecs, free_iovec); renderer.in_fd = in_fd; @@ -200,28 +200,8 @@ int vtest_create_renderer(int in_fd, int out_fd, uint32_t length) /* By default we support version 0 unless VCMD_PROTOCOL_VERSION is sent */ renderer.protocol_version = 0; - if (getenv("VTEST_USE_GLX")) { - ctx = VIRGL_RENDERER_USE_GLX; - } - - if (getenv("VTEST_USE_EGL_SURFACELESS")) { - if (ctx & VIRGL_RENDERER_USE_GLX) { - fprintf(stderr, "Cannot use surfaceless with GLX.\n"); - return -1; - } - ctx |= VIRGL_RENDERER_USE_SURFACELESS; - } - - if (getenv("VTEST_USE_GLES")) { - if (ctx & VIRGL_RENDERER_USE_GLX) { - fprintf(stderr, "Cannot use GLES with GLX.\n"); - return -1; - } - ctx |= VIRGL_RENDERER_USE_GLES; - } - ret = virgl_renderer_init(&renderer, - ctx | VIRGL_RENDERER_THREAD_SYNC, &vtest_cbs); + ctx_flags | VIRGL_RENDERER_THREAD_SYNC, &vtest_cbs); if (ret) { fprintf(stderr, "failed to initialise renderer.\n"); return -1; diff --git a/vtest/vtest_server.c b/vtest/vtest_server.c index b4670cc..9d4a9df 100644 --- a/vtest/vtest_server.c +++ b/vtest/vtest_server.c @@ -38,6 +38,7 @@ #include "util/u_memory.h" #include "vtest.h" #include "vtest_protocol.h" +#include "virglrenderer.h" @@ -51,6 +52,10 @@ struct vtest_program bool do_fork; bool loop; + + bool use_glx; + bool use_egl_surfaceless; + bool use_gles; }; struct vtest_program prog = { @@ -65,12 +70,13 @@ struct vtest_program prog = { .loop = true, }; +static void vtest_main_getenv(void); static void vtest_main_parse_args(int argc, char **argv); static void vtest_main_set_signal_child(void); static void vtest_main_set_signal_segv(void); static void vtest_main_open_read_file(void); static void vtest_main_open_socket(void); -static void vtest_main_run_renderer(int in_fd, int out_fd); +static void vtest_main_run_renderer(int in_fd, int out_fd, int ctx_flags); static void vtest_main_wait_for_socket_accept(void); static void vtest_main_tidy_fds(void); static void vtest_main_close_socket(void); @@ -82,8 +88,23 @@ int main(int argc, char **argv) while (__AFL_LOOP(1000)) { #endif + vtest_main_getenv(); vtest_main_parse_args(argc, argv); + int ctx_flags = VIRGL_RENDERER_USE_EGL; + if (prog.use_glx) { + if (prog.use_egl_surfaceless || prog.use_gles) { + fprintf(stderr, "Cannot use surfaceless or GLES with GLX.\n"); + exit(EXIT_FAILURE); + } + ctx_flags = VIRGL_RENDERER_USE_GLX; + } else { + if (prog.use_egl_surfaceless) + ctx_flags |= VIRGL_RENDERER_USE_SURFACELESS; + if (prog.use_gles) + ctx_flags |= VIRGL_RENDERER_USE_GLES; + } + if (prog.read_file != NULL) { vtest_main_open_read_file(); goto start; @@ -102,12 +123,12 @@ start: /* fork a renderer process */ if (fork() == 0) { vtest_main_set_signal_segv(); - vtest_main_run_renderer(prog.in_fd, prog.out_fd); + vtest_main_run_renderer(prog.in_fd, prog.out_fd, ctx_flags); exit(0); } } else { vtest_main_set_signal_segv(); - vtest_main_run_renderer(prog.in_fd, prog.out_fd); + vtest_main_run_renderer(prog.in_fd, prog.out_fd, ctx_flags); } vtest_main_tidy_fds(); @@ -167,6 +188,13 @@ static void vtest_main_parse_args(int argc, char **argv) } } +static void vtest_main_getenv(void) +{ + prog.use_glx = getenv("VTEST_USE_GLX") != NULL; + prog.use_egl_surfaceless = getenv("VTEST_USE_EGL_SURFACELESS") != NULL; + prog.use_gles = getenv("VTEST_USE_GLES") != NULL; +} + static void handler(int sig, siginfo_t *si, void *unused) { (void)sig; (void)si, (void)unused; @@ -308,7 +336,7 @@ static const vtest_cmd_fptr_t vtest_commands[] = { vtest_transfer_put2, }; -static void vtest_main_run_renderer(int in_fd, int out_fd) +static void vtest_main_run_renderer(int in_fd, int out_fd, int ctx_flags) { int err, ret; uint32_t header[VTEST_HDR_SIZE]; @@ -334,7 +362,7 @@ static void vtest_main_run_renderer(int in_fd, int out_fd) break; } - ret = vtest_create_renderer(in_fd, out_fd, header[0]); + ret = vtest_create_renderer(in_fd, out_fd, header[0], ctx_flags); if (ret < 0) { err = 4; break;