test: one Xvfb launcher and one daemon for the live tests
The XIM test carried its own Xvfb and daemon spawner, its own child struct, log files and process-group teardown, and the GTK test a second Xvfb launcher, because live.c's startdaemon always unset DISPLAY. Live now carries the display its own startxvfb reports, startdaemon passes it on, and both tests use the shared pair: 300 lines fewer, one place that knows how a child is started, watched, and stopped.
This commit is contained in:
@@ -437,73 +437,6 @@ runquery(char *module, char *cache)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
startxvfb(pid_t *pidp, char *display, size_t ndisplay)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
char fdarg[32], line[32];
|
||||
int p[2], n, status;
|
||||
pid_t pid;
|
||||
|
||||
if(pipe(p) < 0)
|
||||
return fail("Xvfb display pipe: %s", strerror(errno));
|
||||
pid = fork();
|
||||
if(pid < 0){
|
||||
close(p[0]);
|
||||
close(p[1]);
|
||||
return fail("fork Xvfb: %s", strerror(errno));
|
||||
}
|
||||
if(pid == 0){
|
||||
close(p[0]);
|
||||
snprintf(fdarg, sizeof fdarg, "%d", p[1]);
|
||||
execlp("Xvfb", "Xvfb", "-displayfd", fdarg, "-screen", "0",
|
||||
"1024x768x24", "-nolisten", "tcp", "-noreset", (char*)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
close(p[1]);
|
||||
pfd.fd = p[0];
|
||||
pfd.events = POLLIN;
|
||||
if(poll(&pfd, 1, Timeout) <= 0){
|
||||
kill(pid, SIGTERM);
|
||||
waitpid(pid, NULL, 0);
|
||||
close(p[0]);
|
||||
return fail("Xvfb did not publish a display");
|
||||
}
|
||||
n = read(p[0], line, sizeof line - 1);
|
||||
close(p[0]);
|
||||
if(n <= 0){
|
||||
waitpid(pid, &status, 0);
|
||||
return fail("read Xvfb display number");
|
||||
}
|
||||
line[n] = '\0';
|
||||
line[strcspn(line, "\r\n")] = '\0';
|
||||
if(snprintf(display, ndisplay, ":%s", line) >= (int)ndisplay){
|
||||
kill(pid, SIGTERM);
|
||||
waitpid(pid, NULL, 0);
|
||||
return fail("Xvfb display number is too long");
|
||||
}
|
||||
*pidp = pid;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
stopxvfb(pid_t *pidp)
|
||||
{
|
||||
int status;
|
||||
int64_t deadline;
|
||||
|
||||
if(*pidp <= 0)
|
||||
return;
|
||||
kill(*pidp, SIGTERM);
|
||||
deadline = nowms() + Timeout;
|
||||
while(waitpid(*pidp, &status, WNOHANG) == 0 && leftms(deadline) > 0)
|
||||
g_usleep(10000);
|
||||
if(waitpid(*pidp, &status, WNOHANG) == 0){
|
||||
kill(*pidp, SIGKILL);
|
||||
waitpid(*pidp, &status, 0);
|
||||
}
|
||||
*pidp = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
pump(void)
|
||||
@@ -656,16 +589,17 @@ main(int argc, char **argv)
|
||||
static const int badresponses[] = { Rbadcommit, Rbadpreedit };
|
||||
char root[] = "/tmp/strans-gtk.XXXXXX";
|
||||
char runtime[320] = "", socket[384] = "", cache[384] = "";
|
||||
char display[32];
|
||||
char *module;
|
||||
pid_t xvfb;
|
||||
Daemon xvfb;
|
||||
Live l;
|
||||
int first, i, ox, oy, scale, closes, ok, rootmade, serverup;
|
||||
int64_t stalledms, started;
|
||||
|
||||
testname = "gtk_live_test";
|
||||
ctx = oldctx = badctx = NULL;
|
||||
top = NULL;
|
||||
xvfb = -1;
|
||||
memset(&l, 0, sizeof l);
|
||||
daemoninit(&xvfb, "Xvfb");
|
||||
rootmade = 0;
|
||||
serverup = 0;
|
||||
ok = 0;
|
||||
@@ -687,8 +621,8 @@ main(int argc, char **argv)
|
||||
Check(snprintf(cache, sizeof cache, "%s/immodules.cache", root) <
|
||||
(int)sizeof cache, "cache path is too long");
|
||||
Check(mkdir(runtime, 0700) == 0, "mkdir runtime: %s", strerror(errno));
|
||||
Check(startxvfb(&xvfb, display, sizeof display), "start private Xvfb");
|
||||
Check(setenv("DISPLAY", display, 1) == 0 &&
|
||||
Check(startxvfb(&l, &xvfb, "Xvfb"), "start private Xvfb");
|
||||
Check(setenv("DISPLAY", l.display, 1) == 0 &&
|
||||
setenv("GDK_BACKEND", "x11", 1) == 0 &&
|
||||
setenv("GDK_SCALE", "2", 1) == 0 &&
|
||||
setenv("XDG_RUNTIME_DIR", runtime, 1) == 0,
|
||||
@@ -951,7 +885,8 @@ out:
|
||||
rmdir(runtime);
|
||||
if(rootmade)
|
||||
rmdir(root);
|
||||
stopxvfb(&xvfb);
|
||||
stopdaemon(&xvfb);
|
||||
closeerrors(&xvfb);
|
||||
free(module);
|
||||
if(ok)
|
||||
printf("gtk_live_test: ok (scale %d, stalled peer %lld ms)\n",
|
||||
|
||||
Reference in New Issue
Block a user