diff options
author | Jeremy White <jwhite@codeweavers.com> | 2019-07-30 11:01:49 -0500 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2020-03-15 13:46:18 +0000 |
commit | 45481c5281aa8a9960718960be6f6fec33973691 (patch) | |
tree | a82c1b463bc5764c50255b8938930f90e12a51fc | |
parent | 83180d7c6a1329c03fac888966f261c034a286cb (diff) |
Use the Spice video dummy driver for our tests if enabled.
Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | src/tests/Makefile.am | 5 | ||||
-rw-r--r-- | src/tests/xdummy.c | 64 | ||||
-rw-r--r-- | src/tests/xdummy.h | 1 |
3 files changed, 69 insertions, 1 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index e401840..b129be9 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -18,6 +18,11 @@ x11spice_test_SOURCES = \ x11spice_test_CPPFLAGS = -DPATH_TO_TEST_SRC=\"$(abs_srcdir)\" +# Instruct the xdummy utility where to find the spice-video-driver library +if DUMMY +x11spice_test_CPPFLAGS += -DSPICEDUMMY=\"$(abs_top_builddir)/spice-video-dummy/src/.libs\" +endif + TESTS += options_test options_test_CPPFLAGS = -I$(top_srcdir)/src options_test_LDADD = $(GLIB2_LIBS) diff --git a/src/tests/xdummy.c b/src/tests/xdummy.c index ce57b1c..c197578 100644 --- a/src/tests/xdummy.c +++ b/src/tests/xdummy.c @@ -30,6 +30,7 @@ #include <sys/wait.h> #include <signal.h> #include <fcntl.h> +#include <ctype.h> #include "xdummy.h" @@ -76,7 +77,11 @@ static void write_xorg_conf(FILE * fp, xdummy_t *server) "EndSection\n" "Section \"Device\"\n" " Identifier \"dummy_videocard\"\n" +#if defined(SPICEDUMMY) + " Driver \"spicedummy\"\n" +#else " Driver \"dummy\"\n" +#endif " VideoRam %ld\n" "EndSection\n" "\n" @@ -87,6 +92,7 @@ static void write_xorg_conf(FILE * fp, xdummy_t *server) " DefaultDepth 24\n" "SubSection \"Display\"\n" " Modes %s\n" + " Virtual %s\n" "EndSubSection\n" "EndSection\n" "\n" @@ -95,7 +101,7 @@ static void write_xorg_conf(FILE * fp, xdummy_t *server) " Screen \"dummy_screen\"\n" " InputDevice \"dummy_mouse\"\n" " InputDevice \"dummy_keyboard\"\n" - "EndSection\n", server->desired_vram, server->modes); + "EndSection\n", server->desired_vram, server->modes, server->vmode); } static int generate_paths(xdummy_t *server, gconstpointer user_data) @@ -136,11 +142,61 @@ static int generate_paths(xdummy_t *server, gconstpointer user_data) return 0; } +static void get_module_paths(const char *xorg_binary, char *module_paths, int size) +{ + int pipes[2]; + int rc; + int pid; + char *p; + + memset(module_paths, 0, size); +#if defined(SPICEDUMMY) + strncpy(module_paths, SPICEDUMMY, size - 1); + module_paths += strlen(module_paths); + size -= strlen(module_paths); +#endif + + /* We invoke Xorg -showDefaultModulePath, which frustratingly + writes the path we crave to stderr. Because of the stderr + requirement, we need to manage file handles manually instead + of using popen() */ + if (pipe(pipes) == 0) { + pid = fork(); + if (pid == 0) { + close(pipes[0]); + dup2(pipes[1], STDERR_FILENO); + close(pipes[1]); + execlp(xorg_binary, xorg_binary, "-showDefaultModulePath", NULL); + exit(0); + } + else { + waitpid(pid, NULL, 0); + rc = read(pipes[0], module_paths, size - 2); + if (rc > 0) { + for (p = module_paths + rc - 1; p >= module_paths && isspace(*p); p--) + *p = '\0'; + /* Don't use bogus paths or errors masquerading as paths */ + if (access(module_paths, X_OK) != 0) + *module_paths = 0; + +#if defined(SPICEDUMMY) + /* Comma separate multiple directories */ + memmove(module_paths + 1, module_paths, rc); + *module_paths = ','; +#endif + } + close(pipes[0]); + close(pipes[1]); + } + } +} + static int exec_xorg(xdummy_t *server, gconstpointer user_data G_GNUC_UNUSED) { FILE *fp; char fdbuf[100]; char xorg_binary[100]; + char module_paths[4096]; fp = fopen(server->xorg_fname, "w"); if (!fp) @@ -160,8 +216,11 @@ static int exec_xorg(xdummy_t *server, gconstpointer user_data G_GNUC_UNUSED) else if (access("/usr/lib/xorg/Xorg", X_OK) == 0) strcpy(xorg_binary, "/usr/lib/xorg/Xorg"); + get_module_paths(xorg_binary, module_paths, sizeof(module_paths)); + return execlp(xorg_binary, xorg_binary, "-ac", "-config", server->xorg_fname, + "-modulepath", module_paths, "-logfile", server->logfile, "-displayfd", fdbuf, NULL); } @@ -169,15 +228,18 @@ static void configure_xorg_parameters(xdummy_t *server, gconstpointer user_data) { server->desired_vram = ((1024 * 768 * 4) + 1023)/ 1024; server->modes = "\"1024x768\""; + server->vmode = "1024 768"; if (strcmp(user_data , "resize") == 0) { server->desired_vram = ((1920 * 1080 * 4) + 1023) / 1024; server->modes = "\"1920x1080\""; + server->vmode = "1920 1080"; } if (strlen(user_data) > 7 && memcmp(user_data, "client_", 7) == 0) { server->desired_vram = ((1280 * 1024 * 4) + 1023) / 1024; server->modes = "\"1280x1024\""; + server->vmode = "1280 1024"; } } diff --git a/src/tests/xdummy.h b/src/tests/xdummy.h index a6e112d..678eed1 100644 --- a/src/tests/xdummy.h +++ b/src/tests/xdummy.h @@ -31,6 +31,7 @@ typedef struct { int pipe; long desired_vram; gchar *modes; + gchar *vmode; gboolean running; gchar *xorg_fname; gchar *logfile; |