The normal xinit is racy because it doesn't use -displayfd. This
implements the bare minimum for testing purposes, using -displayfd to
sequence starting the client, and avoids adding yet another dependency
to the server.
Signed-off-by: Eric Anholt
---
test/.gitignore | 1 +
test/Makefile.am| 13 +++-
test/simple-xinit.c | 216
3 files changed, 226 insertions(+), 4 deletions(-)
create mode 100644 test/simple-xinit.c
diff --git a/test/.gitignore b/test/.gitignore
index a62fc3d70651..c44fc827ac13 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -11,5 +11,6 @@ xfree86
xkb
xtest
signal-logging
+simple-xinit
*.log
*.trs
diff --git a/test/Makefile.am b/test/Makefile.am
index 4ccadf5b0005..24bfc35bc88a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,17 +1,22 @@
if ENABLE_UNIT_TESTS
SUBDIRS= .
-noinst_PROGRAMS = list string
+TEST_PROGS = list string
if XORG
# Tests that require at least some DDX functions in order to fully link
# For now, requires xf86 ddx, could be adjusted to use another
SUBDIRS += xi1 xi2
-noinst_PROGRAMS += xkb input xtest misc fixes xfree86 signal-logging touch
+TEST_PROGS += xkb input xtest misc fixes xfree86 signal-logging touch
if RES
-noinst_PROGRAMS += hashtabletest
+TEST_PROGS += hashtabletest
endif
endif
check_LTLIBRARIES = libxservertest.la
+noinst_PROGRAMS = \
+ simple-xinit \
+ $(TEST_PROGS) \
+ $(NULL)
+
if XVFB
XVFB_TESTS = scripts/xvfb-piglit.sh
endif
@@ -21,7 +26,7 @@ SCRIPT_TESTS = \
$(NULL)
TESTS = \
- $(noinst_PROGRAMS) \
+ $(TEST_PROGS) \
$(SCRIPT_TESTS) \
$(NULL)
diff --git a/test/simple-xinit.c b/test/simple-xinit.c
new file mode 100644
index ..d078a9c3a004
--- /dev/null
+++ b/test/simple-xinit.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+static void
+kill_server(int serverpid)
+{
+int ret = kill(serverpid, SIGTERM);
+int wstatus;
+
+if (ret) {
+fprintf(stderr, "Failed to send kill to the server: %s\n",
+strerror(errno));
+exit(1);
+}
+
+ret = waitpid(serverpid, , 0);
+if (ret < 0) {
+fprintf(stderr, "Failed to wait for X to die: %s\n", strerror(errno));
+exit(1);
+}
+}
+
+static void
+usage(int argc, char **argv)
+{
+fprintf(stderr, "%s -- \n", argv[0]);
+exit(1);
+}
+
+/* Starts the X server, returning its pid. */
+static int
+start_server(char *const *server_args)
+{
+int serverpid = fork();
+
+if (serverpid != 0) {
+/* Continue along the main process that will exec the client. */
+return serverpid;
+}
+
+/* Execute the server. This only returns if an error occurred. */
+execvp(server_args[0], server_args);
+fprintf(stderr, "Error starting the server: %s\n", strerror(errno));
+exit(1);
+}
+
+/* Reads the display number out of the started server's display socket. */
+static int
+get_display(int displayfd)
+{
+char display_string[10];
+ssize_t ret;
+
+ret = read(displayfd, display_string, sizeof(display_string - 1));
+if (ret <= 0) {
+fprintf(stderr, "Failed reading displayfd: %s\n", strerror(errno));
+exit(1);
+}
+
+/* We've read in the display number as a string terminated by
+ * '\n', but not '\0'. Cap it and parse the number.
+ */
+display_string[ret] = '\0';
+return atoi(display_string);
+}
+
+static int
+start_client(char *const *client_args, int display)
+{
+char *display_string;
+int ret;
+int client_pid;
+
+asprintf(_string, ":%d", display);
+ret = setenv("DISPLAY", display_string, true);
+if (ret) {
+