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
11 use Exporter 'import';
12 our @EXPORT = qw(worker worker_next);
14 use File::Basename qw(basename);
18 my ($display, $x, $outdir) = @_;
20 # make sure $x hangs around
23 socketpair(my $ipc_child, my $ipc, AF_UNIX, SOCK_DGRAM, PF_UNSPEC)
24 or die "socketpair: $!";
27 $ipc_child->autoflush(1);
34 my $pid = fork // die "could not fork: $!";
38 undef @complete_run::CLEANUP;
39 # reap dead test children
40 $SIG{CHLD} = sub { waitpid -1, POSIX::WNOHANG };
42 $worker->{ipc} = $ipc_child;
46 # unfortunately this fails currently with:
47 # Could not get reply for: xcb_intern_atom_reply at X11/XCB/Atom.pm line 22.
49 # $i3test::x = bless $x, 'i3test::X11';
50 worker_wait($worker, $outdir);
56 push @complete_run::CLEANUP, sub {
57 # signal via empty line to exit itself
58 syswrite($ipc, "\n") or kill('TERM', $pid);
66 our $EOF = "# end of file\n";
68 my ($self, $outdir) = @_;
70 my $ipc = $self->{ipc};
71 my $ipc_fd = fileno($ipc);
73 while (defined(my $file = $ipc->getline)) {
78 die "tried to launch nonexistend testfile $file: $!\n"
81 # start a new and self contained process:
82 # whatever happens in the testfile should *NOT* effect us.
84 my $pid = fork // die "could not fork: $!";
86 undef @complete_run::CLEANUP;
91 POSIX::dup2($ipc_fd, 0);
92 POSIX::dup2($ipc_fd, 1);
95 # get Test::Builder singleton
96 my $test = Test::Builder->new;
98 # Test::Builder dups stdout/stderr while loading.
99 # we need to reset them here to point to $ipc
100 $test->output(\*STDOUT);
101 $test->failure_output(\*STDERR);
102 $test->todo_output(\*STDOUT);
104 @ENV{qw(DISPLAY TESTNAME OUTDIR VALGRIND STRACE COVERAGE RESTART)}
105 = ($self->{display}, basename($file), $outdir, 0, 0, 0, 0);
110 $test->ok(undef, "$@") if $@;
112 # XXX hack, we need to trigger the read watcher once more
113 # to signal eof to TAP::Parser
122 my ($self, $file) = @_;
124 my $ipc = $self->{ipc};
125 syswrite $ipc, "$file\n" or die "syswrite: $!";