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);
19 my ($display, $x, $outdir, $optref) = @_;
21 # make sure $x hangs around
24 # store the options hashref
27 socketpair(my $ipc_child, my $ipc, AF_UNIX, SOCK_DGRAM, PF_UNSPEC)
28 or die "socketpair: $!";
31 $ipc_child->autoflush(1);
38 my $pid = fork // die "could not fork: $!";
42 undef @complete_run::CLEANUP;
43 # reap dead test children
44 $SIG{CHLD} = sub { waitpid -1, POSIX::WNOHANG };
46 $worker->{ipc} = $ipc_child;
50 # unfortunately this fails currently with:
51 # Could not get reply for: xcb_intern_atom_reply at X11/XCB/Atom.pm line 22.
53 # $i3test::x = bless $x, 'i3test::X11';
54 worker_wait($worker, $outdir);
60 push @complete_run::CLEANUP, sub {
61 # signal via empty line to exit itself
62 syswrite($ipc, "\n") or kill('TERM', $pid);
70 our $EOF = "# end of file\n";
72 my ($self, $outdir) = @_;
74 my $ipc = $self->{ipc};
75 my $ipc_fd = fileno($ipc);
77 while (defined(my $file = $ipc->getline)) {
82 die "tried to launch nonexistend testfile $file: $!\n"
85 # start a new and self contained process:
86 # whatever happens in the testfile should *NOT* effect us.
88 my $pid = fork // die "could not fork: $!";
90 undef @complete_run::CLEANUP;
95 POSIX::dup2($ipc_fd, 0);
96 POSIX::dup2($ipc_fd, 1);
99 # get Test::Builder singleton
100 my $test = Test::Builder->new;
102 # Test::Builder dups stdout/stderr while loading.
103 # we need to reset them here to point to $ipc
104 $test->output(\*STDOUT);
105 $test->failure_output(\*STDERR);
106 $test->todo_output(\*STDOUT);
108 @ENV{qw(DISPLAY TESTNAME OUTDIR VALGRIND STRACE COVERAGE RESTART)}
112 $options->{valgrind},
114 $options->{coverage},
115 $options->{restart});
120 $test->ok(undef, "$@") if $@;
122 # XXX hack, we need to trigger the read watcher once more
123 # to signal eof to TAP::Parser
132 my ($self, $file) = @_;
134 my $ipc = $self->{ipc};
135 syswrite $ipc, "$file\n" or die "syswrite: $!";