Commit cfc702c6 authored by Erik Faye-Lund 's avatar Erik Faye-Lund

vtest: lift out getenv calls closer to main

This means we can change them a bit more easily, for instance... from
command-line arguments!
Signed-off-by: Erik Faye-Lund 's avatarErik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-By: Gert Wollny's avatarGert Wollny <gert.wollny@collabora.com>
parent 3afe6f4d
......@@ -27,7 +27,8 @@
#include <errno.h>
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);
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment