]> git.sur5r.net Git - i3/i3/blobdiff - testcases/complete-run.pl.in
Merge pull request #3441 from stapelberg/template
[i3/i3] / testcases / complete-run.pl.in
index ba192469e6867fa8ebda0c8b7c5a6b6733776a9e..96b93bed085a07fd4d4d49832d00ab26daee10f3 100755 (executable)
@@ -38,6 +38,8 @@ binmode STDERR, ':utf8';
 # subshell or situations like that.
 AnyEvent::Util::close_all_fds_except(0, 1, 2);
 
+our @CLEANUP;
+
 # convenience wrapper to write to the log file
 my $log;
 sub Log { say $log "@_" }
@@ -55,6 +57,7 @@ my %options = (
     xtrace => 0,
     coverage => 0,
     restart => 0,
+    xvfb => 1,
 );
 my $keep_xserver_output = 0;
 
@@ -64,6 +67,7 @@ my $result = GetOptions(
     "valgrind" => \$options{valgrind},
     "strace" => \$options{strace},
     "xtrace" => \$options{xtrace},
+    "xvfb!" => \$options{xvfb},
     "display=s" => \@displays,
     "parallel=i" => \$parallel,
     "help|?" => \$help,
@@ -112,6 +116,44 @@ $ENV{PATH} = join(':',
 qx(Xephyr -help 2>&1);
 die "Xephyr was not found in your path. Please install Xephyr (xserver-xephyr on Debian)." if $?;
 
+qx(xvfb-run --help 2>&1);
+if ($? && $options{xvfb}) {
+    say "xvfb-run not found, not running tests under xvfb. Install the xvfb package to speed up tests";
+    $options{xvfb} = 0;
+}
+
+if ($options{xvfb}) {
+    for (my $n = 99; $n < 120; $n++) {
+       my $path = File::Temp::tmpnam($ENV{TMPDIR} // "/tmp", "i3-testsXXXXXX");
+       if (!defined(POSIX::mkfifo($path, 0600))) {
+           die "mkfifo: $!";
+       }
+       my $pid = fork // die "fork: $!";
+       if ($pid == 0) {
+           # Child
+
+           # Xvfb checks whether the parent ignores USR1 and sends USR1 to the
+           # parent when ready, so that the wait call will be interrupted.  We
+           # can’t implement this in Perl, as Perl’s waitpid transparently
+           # handles -EINTR.
+           exec('/bin/sh', '-c', qq|trap "exit" INT; trap : USR1; (trap '' USR1; exec Xvfb :$n -screen 0 640x480x8 -nolisten tcp) & PID=\$!; wait; if ! kill -0 \$PID 2>/dev/null; then echo 1:\$PID > $path; else echo 0:\$PID > $path; wait \$PID; fi|);
+           die "exec: $!";
+       }
+       chomp(my $kill = slurp($path));
+       unlink($path);
+       my ($code, $xvfbpid) = ($kill =~ m,^([0-1]):(.*)$,);
+       next unless $code eq '0';
+
+       $ENV{DISPLAY} = ":$n";
+       say "Running tests under Xvfb display $ENV{DISPLAY}";
+
+       push(@CLEANUP, sub {
+           kill(15, $xvfbpid);
+       });
+       last;
+    }
+}
+
 @displays = split(/,/, join(',', @displays));
 @displays = map { s/ //g; $_ } @displays;
 
@@ -177,11 +219,18 @@ my $timingsjson = slurp('.last_run_timings.json') if -e '.last_run_timings.json'
              map  { [$_, $timings{$_} // 999] } @testfiles;
 
 # Run 000-load-deps.t first to bail out early when dependencies are missing.
-my $loadtest = "t/000-load-deps.t";
-if ((scalar grep { $_ eq $loadtest } @testfiles) > 0) {
+my ($loadtest) = grep { $_ =~ m,t/000-load-deps.t$, } @testfiles;
+if (defined($loadtest)) {
     @testfiles = ($loadtest, grep { $_ ne $loadtest } @testfiles);
 }
 
+# Run 533-randr15.t last because it destructively modifies the RandR
+# configuration of the X session, interfering with any test started afterwards.
+my ($randrtest) = grep { $_ =~ m,t/533-randr15.t$, } @testfiles;
+if (defined($randrtest)) {
+    @testfiles = ((grep { $_ ne $randrtest } @testfiles), $randrtest);
+}
+
 printf("\nRough time estimate for this run: %.2f seconds\n\n", $timings{GLOBAL})
     if exists($timings{GLOBAL});
 
@@ -372,7 +421,7 @@ sub take_job {
 
 sub cleanup {
     my $exitcode = $?;
-    $_->() for our @CLEANUP;
+    $_->() for @CLEANUP;
     exit $exitcode;
 }
 
@@ -436,6 +485,12 @@ C<latest/strace-for-$test.log>.
 Runs i3 under xtrace to trace X11 requests/replies. The output will be
 available in C<latest/xtrace-for-$test.log>.
 
+=item B<--xvfb>
+
+=item B<--no-xvfb>
+
+Enable or disable running tests under Xvfb. Enabled by default.
+
 =item B<--coverage-testing>
 
 Generates a test coverage report at C<latest/i3-coverage>. Exits i3 cleanly