]> git.sur5r.net Git - i3/i3/blobdiff - testcases/complete-run.pl
Merge branch 'master' into next
[i3/i3] / testcases / complete-run.pl
index cb7b5c8c107fb4bb83ff29746afc027b61a4a036..d73bb3327d242344f641930d8e34534d5ec725f5 100755 (executable)
@@ -15,6 +15,7 @@ use TAP::Harness;
 use TAP::Parser;
 use TAP::Parser::Aggregator;
 use Time::HiRes qw(time);
+use IO::Handle;
 # these are shipped with the testsuite
 use lib qw(lib);
 use StartXDummy;
@@ -37,20 +38,27 @@ my $log;
 sub Log { say $log "@_" }
 
 my %timings;
-my $coverage_testing = 0;
-my $valgrind = 0;
-my $strace = 0;
 my $help = 0;
 # Number of tests to run in parallel. Important to know how many Xdummy
 # instances we need to start (unless @displays are given). Defaults to
 # num_cores * 2.
 my $parallel = undef;
 my @displays = ();
+my %options = (
+    valgrind => 0,
+    strace => 0,
+    xtrace => 0,
+    coverage => 0,
+    restart => 0,
+);
+my $keep_xdummy_output = 0;
 
 my $result = GetOptions(
-    "coverage-testing" => \$coverage_testing,
-    "valgrind" => \$valgrind,
-    "strace" => \$strace,
+    "coverage-testing" => \$options{coverage},
+    "keep-xdummy-output" => \$keep_xdummy_output,
+    "valgrind" => \$options{valgrind},
+    "strace" => \$options{strace},
+    "xtrace" => \$options{xtrace},
     "display=s" => \@displays,
     "parallel=i" => \$parallel,
     "help|?" => \$help,
@@ -58,6 +66,22 @@ my $result = GetOptions(
 
 pod2usage(-verbose => 2, -exitcode => 0) if $help;
 
+# Check for missing executables
+my @binaries = qw(
+                   ../i3
+                   ../i3bar/i3bar
+                   ../i3-config-wizard/i3-config-wizard
+                   ../i3-dump-log/i3-dump-log
+                   ../i3-input/i3-input
+                   ../i3-msg/i3-msg
+                   ../i3-nagbar/i3-nagbar
+               );
+
+foreach my $binary (@binaries) {
+    die "$binary executable not found" unless -e $binary;
+    die "$binary is not an executable" unless -x $binary;
+}
+
 @displays = split(/,/, join(',', @displays));
 @displays = map { s/ //g; $_ } @displays;
 
@@ -70,7 +94,9 @@ my @testfiles = @ARGV;
 my $numtests = scalar @testfiles;
 
 # No displays specified, let’s start some Xdummy instances.
-@displays = start_xdummy($parallel, $numtests) if @displays == 0;
+if (@displays == 0) {
+    @displays = start_xdummy($parallel, $numtests, $keep_xdummy_output);
+}
 
 # 1: create an output directory for this test-run
 my $outdir = "testsuite-";
@@ -87,7 +113,7 @@ symlink("$outdir", "latest") or die "Could not symlink latest to $outdir";
 # 2: keep the connection open so that i3 is not the only client. this prevents
 #    the X server from exiting (Xdummy will restart it, but not quick enough
 #    sometimes)
-my @worker;
+my @single_worker;
 for my $display (@displays) {
     my $screen;
     my $x = X11::XCB::Connection->new(display => $display);
@@ -95,7 +121,7 @@ for my $display (@displays) {
         die "Could not connect to display $display\n";
     } else {
         # start a TestWorker for each display
-        push @worker, worker($display, $x, $outdir);
+        push @single_worker, worker($display, $x, $outdir, \%options);
     }
 }
 
@@ -120,6 +146,7 @@ printf("\nRough time estimate for this run: %.2f seconds\n\n", $timings{GLOBAL})
 
 my $logfile = "$outdir/complete-run.log";
 open $log, '>', $logfile or die "Could not create '$logfile': $!";
+$log->autoflush(1);
 say "Writing logfile to '$logfile'...";
 
 # 3: run all tests
@@ -132,13 +159,16 @@ $aggregator->start();
 
 status_init(displays => \@displays, tests => $num);
 
-my $cv = AE::cv;
+my $single_cv = AE::cv;
 
 # We start tests concurrently: For each display, one test gets started. Every
 # test starts another test after completing.
-for (@worker) { $cv->begin; take_job($_) }
+for (@single_worker) {
+    $single_cv->begin;
+    take_job($_, $single_cv, \@testfiles);
+}
 
-$cv->recv;
+$single_cv->recv;
 
 $aggregator->stop();
 
@@ -198,9 +228,9 @@ exit 0;
 # triggered to finish testing.
 #
 sub take_job {
-    my ($worker) = @_;
+    my ($worker, $cv, $tests) = @_;
 
-    my $test = shift @testfiles
+    my $test = shift @$tests
         or return $cv->end;
 
     my $display = $worker->{display};
@@ -253,9 +283,16 @@ sub take_job {
 
             for (1 .. $lines) {
                 my $result = $parser->next;
-                if (defined($result) and $result->is_test) {
+                next unless defined($result);
+                if ($result->is_test) {
                     $tests_completed++;
                     status($display, "$test: [$tests_completed/??] ");
+                } elsif ($result->is_bailout) {
+                    Log status($display, "$test: BAILOUT");
+                    status_completed(scalar @done);
+                    say "";
+                    say "test $test bailed out: " . $result->explanation;
+                    exit 1;
                 }
             }
 
@@ -269,7 +306,7 @@ sub take_job {
             push @done, [ $test, $output ];
 
             undef $w;
-            take_job($worker);
+            take_job($worker, $cv, $tests);
         }
     );
 }
@@ -334,6 +371,11 @@ C<latest/valgrind-for-$test.log>.
 Runs i3 under strace to trace system calls. The output will be available in
 C<latest/strace-for-$test.log>.
 
+=item B<--xtrace>
+
+Runs i3 under xtrace to trace X11 requests/replies. The output will be
+available in C<latest/xtrace-for-$test.log>.
+
 =item B<--coverage-testing>
 
 Exits i3 cleanly (instead of kill -9) to make coverage testing work properly.