vtest: Add option and environment variable to select the rendernode

In systems with more then one graphics card the rendernode is currently
picked based on the order in which they are listed in /dev/dri. Add an
command line option and a environment variable to make it possible to
specify the render node explicitely.

Fixes #135

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
macos/master
Gert Wollny 5 years ago committed by Gert Wollny
parent 892e86ad4a
commit ecba12cdac
  1. 2
      vtest/vtest.h
  2. 2
      vtest/vtest_fuzzer.c
  3. 35
      vtest/vtest_renderer.c
  4. 27
      vtest/vtest_server.c

@ -41,7 +41,7 @@ struct vtest_input {
};
int vtest_create_renderer(struct vtest_input *input, int out_fd, uint32_t length,
int ctx_flags);
int ctx_flags, const char *render_device);
int vtest_send_caps(uint32_t length_dw);
int vtest_send_caps2(uint32_t length_dw);

@ -105,7 +105,7 @@ static void vtest_fuzzer_run_renderer(int out_fd, struct vtest_input *input,
break;
}
ret = vtest_create_renderer(input, out_fd, header[0], ctx_flags);
ret = vtest_create_renderer(input, out_fd, header[0], ctx_flags, NULL);
if (ret < 0) {
break;
}

@ -51,23 +51,41 @@ static int ctx_id = 1;
static int fence_id = 1;
static uint32_t max_length = UINT_MAX;
struct vtest_renderer {
struct vtest_input *input;
int out_fd;
unsigned protocol_version;
struct util_hash_table *iovec_hash;
const char *rendernode_name;
};
static int last_fence;
static void vtest_write_fence(UNUSED void *cookie, uint32_t fence_id_in)
{
last_fence = fence_id_in;
}
static int last_fence;
static int vtest_get_drm_fd(void *cookie)
{
int fd = -1;
struct vtest_renderer *renderer = (struct vtest_renderer*)cookie;
if (!renderer->rendernode_name)
return -1;
fd = open(renderer->rendernode_name, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd == -1)
fprintf(stderr, "Unable to open rendernode '%s' falling back to default search\n",
renderer->rendernode_name);
return fd;
}
struct virgl_renderer_callbacks vtest_cbs = {
.version = 1,
.version = 2,
.write_fence = vtest_write_fence,
.get_drm_fd = vtest_get_drm_fd
};
struct vtest_renderer {
struct vtest_input *input;
int out_fd;
unsigned protocol_version;
struct util_hash_table *iovec_hash;
};
struct vtest_renderer renderer;
@ -203,7 +221,7 @@ int vtest_buf_read(struct vtest_input *input, void *buf, int size)
}
int vtest_create_renderer(struct vtest_input *input, int out_fd, uint32_t length,
int ctx_flags)
int ctx_flags, const char * render_device)
{
char *vtestname;
int ret;
@ -211,6 +229,7 @@ int vtest_create_renderer(struct vtest_input *input, int out_fd, uint32_t length
renderer.iovec_hash = util_hash_table_create(hash_func, compare_iovecs, free_iovec);
renderer.input = input;
renderer.out_fd = out_fd;
renderer.rendernode_name = render_device;
/* By default we support version 0 unless VCMD_PROTOCOL_VERSION is sent */
renderer.protocol_version = 0;

@ -51,6 +51,8 @@ struct vtest_program
int out_fd;
struct vtest_input input;
const char *render_device;
bool do_fork;
bool loop;
@ -68,6 +70,7 @@ struct vtest_program prog = {
.in_fd = -1,
.out_fd = -1,
.input = { { -1 }, NULL },
.render_device = 0,
.do_fork = true,
.loop = true,
};
@ -78,8 +81,8 @@ 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,
struct vtest_input *input, int ctx_flags);
static void vtest_main_run_renderer(int in_fd, int out_fd, struct vtest_input *input,
int ctx_flags, const char *render_device);
static void vtest_main_wait_for_socket_accept(void);
static void vtest_main_tidy_fds(void);
static void vtest_main_close_socket(void);
@ -126,12 +129,14 @@ start:
/* fork a renderer process */
if (fork() == 0) {
vtest_main_set_signal_segv();
vtest_main_run_renderer(prog.in_fd, prog.out_fd, &prog.input, ctx_flags);
vtest_main_run_renderer(prog.in_fd, prog.out_fd, &prog.input,
ctx_flags, prog.render_device);
exit(0);
}
} else {
vtest_main_set_signal_segv();
vtest_main_run_renderer(prog.in_fd, prog.out_fd, &prog.input, ctx_flags);
vtest_main_run_renderer(prog.in_fd, prog.out_fd, &prog.input,
ctx_flags, prog.render_device);
}
vtest_main_tidy_fds();
@ -152,6 +157,7 @@ start:
#define OPT_USE_GLX 'x'
#define OPT_USE_EGL_SURFACELESS 's'
#define OPT_USE_GLES 'e'
#define OPT_RENDERNODE 'r'
static void vtest_main_parse_args(int argc, char **argv)
{
@ -163,6 +169,7 @@ static void vtest_main_parse_args(int argc, char **argv)
{"use-glx", no_argument, NULL, OPT_USE_GLX},
{"use-egl-surfaceless", no_argument, NULL, OPT_USE_EGL_SURFACELESS},
{"use-gles", no_argument, NULL, OPT_USE_GLES},
{"rendernode", required_argument, NULL, OPT_RENDERNODE},
{0, 0, 0, 0}
};
@ -191,9 +198,13 @@ static void vtest_main_parse_args(int argc, char **argv)
case OPT_USE_GLES:
prog.use_gles = true;
break;
case OPT_RENDERNODE:
prog.render_device = optarg;
break;
default:
printf("Usage: %s [--no-fork] [--no-loop-or-fork] [--use-glx] "
"[--use-egl-surfaceless] [--use-gles] [file]\n", argv[0]);
"[--use-egl-surfaceless] [--use-gles] [--rendernode <dev>]"
" [file]\n", argv[0]);
exit(EXIT_FAILURE);
break;
}
@ -212,6 +223,7 @@ 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;
prog.render_device = getenv("VTEST_RENDERNODE");
}
static void handler(int sig, siginfo_t *si, void *unused)
@ -360,7 +372,8 @@ static const vtest_cmd_fptr_t vtest_commands[] = {
};
static void vtest_main_run_renderer(int in_fd, int out_fd,
struct vtest_input *input, int ctx_flags)
struct vtest_input *input, int ctx_flags,
const char *render_device)
{
int err, ret;
uint32_t header[VTEST_HDR_SIZE];
@ -386,7 +399,7 @@ static void vtest_main_run_renderer(int in_fd, int out_fd,
break;
}
ret = vtest_create_renderer(input, out_fd, header[0], ctx_flags);
ret = vtest_create_renderer(input, out_fd, header[0], ctx_flags, render_device);
if (ret < 0) {
err = 4;
break;

Loading…
Cancel
Save