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 POSIX::dup2($ipc_fd, 0);
103 POSIX::dup2($ipc_fd, 1);
106 # get Test::Builder singleton
107 my $test = Test::Builder->new;
109 # Test::Builder dups stdout/stderr while loading.
110 # we need to reset them here to point to $ipc
111 $test->output(\*STDOUT);
112 $test->failure_output(\*STDERR);
113 $test->todo_output(\*STDOUT);
115 @ENV{qw(DISPLAY TESTNAME OUTDIR VALGRIND STRACE XTRACE COVERAGE RESTART)}
119 $options->{valgrind},
122 $options->{coverage},
123 $options->{restart});
128 $test->ok(undef, "$@") if $@;
130 # XXX hack, we need to trigger the read watcher once more
131 # to signal eof to TAP::Parser
140 my ($self, $file) = @_;
142 my $ipc = $self->{ipc};
143 syswrite $ipc, "$file\n" or die "syswrite: $!";