Six live tests carried private copies of the same daemon harness: the
private XDG_RUNTIME_DIR, the fork/exec with captured stderr, the
readiness waits, the SIGTERM and SIGKILL paths, the IBus address file
reader, the socket connect, and the IPC probe. Three of them also
carried the same libdbus helpers.
Extract one implementation into tests/live.c and, so that the binaries
that do not link dbus-1 keep not linking it, the D-Bus half into
tests/livebus.c. Both are compiled into each binary the way ../ipc.c
already is. gtk_live_test keeps its own fake-server harness and only
takes fail, nowms and leftms; xim_live_test keeps its own Xvfb and
process-group daemon spawn, which must inherit DISPLAY, and takes the
temporary directory, timing and cleanup halves.
The copies had drifted; the harness keeps the stricter behaviour.
- nowms reports a broken clock (-1) instead of pretending it read
zero, and leftms turns that into an expired deadline, so a loop
ends in a timeout failure rather than spinning. livesetup checks
the clock once up front, as daemon_restart_test did.
- Timeouts compare with <= 0, not == 0.
- readuntil keeps the three-way result (complete, peer closed, error)
from ipc_live_test and daemon_restart_test rather than folding
peer closure into ECONNRESET.
- The daemon's stdout and stderr are both captured, and a failing
setenv is reported, for every daemon; daemon_failure_test captured
stderr only and said nothing about setenv.
- The child keeps daemon_restart_test's careful redirect that also
works when the pipe lands on fd 1 or 2.
- parseaddress requires a positive declared PID.
- killdaemon reports ECHILD after SIGKILL as a failure; one copy
accepted it. It now reaps with a blocking waitpid, which SIGKILL
guarantees will return, instead of daemon_restart_test's polled
wait with its own timeout diagnostic.
- stopdaemon tolerates ESRCH on SIGTERM, a benign race two copies
reported as an error.
- liveclean removes the socket and address files and then rmdirs
each directory, reporting leftovers, rather than deleting the
temporary root recursively.
- ibus_live_test now waits for the IPC socket and the address file
by polling, dropping its inotify variant; it asserted only the
address file before.
74 lines
1.5 KiB
C
74 lines
1.5 KiB
C
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
/*
|
|
* Harness shared by the live tests: a strans daemon started in a private
|
|
* XDG_RUNTIME_DIR with its output captured, the endpoints it publishes,
|
|
* and the IPC probe used to prove the daemon answers.
|
|
* Set testname before anything else; fail prefixes it to every message.
|
|
*/
|
|
|
|
typedef struct Daemon Daemon;
|
|
typedef struct Live Live;
|
|
|
|
enum
|
|
{
|
|
Calltimeout = 4000,
|
|
Starttimeout = 8000,
|
|
Stoptimeout = 3000,
|
|
Errmax = 8192,
|
|
};
|
|
|
|
struct Daemon
|
|
{
|
|
pid_t pid;
|
|
int errfd;
|
|
char *name;
|
|
char err[Errmax];
|
|
size_t nerr;
|
|
};
|
|
|
|
struct Live
|
|
{
|
|
char root[256];
|
|
char runtime[320];
|
|
char config[320];
|
|
char ibus[384];
|
|
char bus[448];
|
|
char home[320];
|
|
char socket[384];
|
|
char addrfile[512];
|
|
};
|
|
|
|
extern char *testname;
|
|
|
|
int fail(char*, ...);
|
|
int64_t nowms(void);
|
|
int leftms(int64_t);
|
|
void pausems(int);
|
|
int makedir(char*);
|
|
int cleardir(char*);
|
|
|
|
int livesetup(Live*, char*);
|
|
int liveclean(Live*);
|
|
|
|
void daemoninit(Daemon*, char*);
|
|
int startdaemon(Live*, Daemon*, char*, char*);
|
|
int waitready(Live*, Daemon*, char*, size_t);
|
|
int daemonalive(Daemon*);
|
|
int stopdaemon(Daemon*);
|
|
int killdaemon(Daemon*, int*);
|
|
void readerrors(Daemon*);
|
|
void showerrors(Daemon*);
|
|
int closeerrors(Daemon*);
|
|
|
|
int findaddress(Live*);
|
|
int readfile(char*, char*, size_t, size_t*);
|
|
int parseaddress(char*, size_t, char*, size_t, pid_t*);
|
|
|
|
int connectsocket(char*, int64_t);
|
|
int readuntil(int, void*, size_t, int64_t);
|
|
int ipcrequest(int, uint32_t, uint32_t, unsigned char*, size_t, char*);
|
|
int ipcprobe(int, char*);
|