]> Sergey Matveev's repositories - public-inbox.git/commitdiff
t/run: support TEST_RUN_LOG to diagnose process death
authorEric Wong <e@80x24.org>
Wed, 28 Apr 2021 19:37:28 +0000 (19:37 +0000)
committerEric Wong <e@80x24.org>
Wed, 28 Apr 2021 19:47:28 +0000 (19:47 +0000)
Knowing which process ran what before dying unexpectedly
helps with debugging.

t/run.perl

index 2fbe403393eb58e0e95d3ae12e2e04bb9d327d45..acd60ff519356de8013788510507aaaa402a30bc 100755 (executable)
@@ -19,6 +19,7 @@ use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use Errno qw(EINTR);
 use Fcntl qw(:seek);
 use POSIX qw(_POSIX_PIPE_BUF WNOHANG);
+use File::Temp ();
 my $jobs = 1;
 my $repeat = 1;
 $| = 1;
@@ -39,6 +40,15 @@ open my $OLDERR, '>&STDERR' or die "dup STDERR: $!";
 $OLDOUT->autoflush(1);
 $OLDERR->autoflush(1);
 
+my ($run_log, $tmp_rl);
+my $rl = $ENV{TEST_RUN_LOG};
+unless ($rl) {
+       $tmp_rl = File::Temp->new(CLEANUP => 1);
+       $rl = $tmp_rl->filename;
+}
+open $run_log, '+>>', $rl or die "open $rl: $!";
+$run_log->autoflush(1); # one reader, many writers
+
 key2sub($_) for @tests; # precache
 
 my ($for_destroy, $lei_env, $lei_daemon_pid, $owner_pid);
@@ -120,6 +130,7 @@ END { test_status() if (defined($worker_test) && $worker == $$) }
 
 sub run_test ($) {
        my ($test) = @_;
+       syswrite($run_log, "$$ $test\n");
        my $log_fh;
        if ($log_suffix ne '') {
                my $log = $test;
@@ -205,7 +216,12 @@ for (my $i = $repeat; $i != 0; $i--) {
                                push @err, "reaped unknown $pid ($?)";
                                next;
                        }
-                       push @err, "job[$j] ($?)" if $?;
+                       if ($?) {
+                               seek($run_log, 0, SEEK_SET);
+                               chomp(my @t = grep(/^$pid /, <$run_log>));
+                               $t[0] //= "$pid unknown";
+                               push @err, "job[$j] ($?) PID=$t[-1]";
+                       }
                        # skip_all can exit(0), respawn if needed:
                        if (!$eof) {
                                print $OLDERR "# respawning job[$j]\n";