1 # vim:ts=4:sw=4:sts=4:expandtab
3 use strict; use warnings;
6 use Socket qw(AF_UNIX SOCK_DGRAM PF_UNSPEC);
7 use IO::Handle; # for ->autoflush
13 use Exporter 'import';
14 our @EXPORT = qw(worker worker_next);
16 use File::Basename qw(basename);
21 my ($display, $x, $outdir, $optref) = @_;
23 # make sure $x hangs around
26 # store the options hashref
29 socketpair(my $ipc_child, my $ipc, AF_UNIX, SOCK_DGRAM, PF_UNSPEC)
30 or die "socketpair: $!";
33 $ipc_child->autoflush(1);
40 my $pid = fork // die "could not fork: $!";
44 undef @complete_run::CLEANUP;
45 # reap dead test children
46 $SIG{CHLD} = sub { waitpid -1, POSIX::WNOHANG };
48 $worker->{ipc} = $ipc_child;
52 # unfortunately this fails currently with:
53 # Could not get reply for: xcb_intern_atom_reply at X11/XCB/Atom.pm line 22.
55 # $i3test::x = bless $x, 'i3test::X11';
56 worker_wait($worker, $outdir);
62 push @complete_run::CLEANUP, sub {
63 # signal via empty line to exit itself
64 syswrite($ipc, "\n") or kill('TERM', $pid);
72 our $EOF = "# end of file\n";
74 my ($self, $outdir) = @_;
76 my $ipc = $self->{ipc};
77 my $ipc_fd = fileno($ipc);
80 my $file = $ipc->getline;
81 if (!defined($file)) {
89 die "tried to launch nonexistend testfile $file: $!\n"
92 # start a new and self contained process:
93 # whatever happens in the testfile should *NOT* effect us.
95 my $pid = fork // die "could not fork: $!";
97 undef @complete_run::CLEANUP;
102 # Re-seed rand() so that File::Temp’s tempnam produces different
103 # results, making a TOCTOU between e.g. t/175-startup-notification.t
104 # and t/180-fd-leaks.t less likely.
107 POSIX::dup2($ipc_fd, 0);
108 POSIX::dup2($ipc_fd, 1);
111 # get Test::Builder singleton
112 my $test = Test::Builder->new;
114 # Test::Builder dups stdout/stderr while loading.
115 # we need to reset them here to point to $ipc
116 $test->output(\*STDOUT);
117 $test->failure_output(\*STDERR);
118 $test->todo_output(\*STDOUT);
120 @ENV{qw(HOME DISPLAY TESTNAME OUTDIR VALGRIND STRACE XTRACE COVERAGE RESTART)}
125 $options->{valgrind},
128 $options->{coverage},
129 $options->{restart});
134 $test->ok(undef, "$@") if $@;
136 # XXX hack, we need to trigger the read watcher once more
137 # to signal eof to TAP::Parser
146 my ($self, $file) = @_;
148 my $ipc = $self->{ipc};
149 syswrite $ipc, "$file\n" or die "syswrite: $!";