about summary refs log tree commit homepage
path: root/t/run.perl
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-07-14 09:28:47 +0000
committerEric Wong <e@80x24.org>2023-07-14 20:35:37 +0000
commit57f0c3206fdf94076e23c1ac6d49cbbf547971e5 (patch)
treea39813bb8800c201a7c3a1a3cb7e10b2e6048bf8 /t/run.perl
parent7234e6718e62840d94de3d04b87eee28bf5c4682 (diff)
downloadpublic-inbox-57f0c3206fdf94076e23c1ac6d49cbbf547971e5.tar.gz
tests: t/run.perl: fix invocations with <10 tests
We must account for the maximum index of an array to avoid
filling unused slots with `undef' from out-of-bounds reads.
This is needed to avoid undefined entry errors in workers when
fewer than 10 tests are run.  We'll also silence the message
when a single test is run.

While I was diagnosing this, I also noticed a small
simplification and optimization in our generation of $todo_buf
since I initially thought that was the cause of undefined
entry errors in the $todo arrayref.
Diffstat (limited to 't/run.perl')
-rwxr-xr-xt/run.perl12
1 files changed, 8 insertions, 4 deletions
diff --git a/t/run.perl b/t/run.perl
index f68dab60..9c8129d5 100755
--- a/t/run.perl
+++ b/t/run.perl
@@ -85,9 +85,13 @@ if ($shuffle) {
         @tests = sort {
                 ($t->{$b}->{elapsed} // 0) <=> ($t->{$a}->{elapsed} // 0)
         } @tests;
-        say "# top 10 longest tests (`make check' regenerates)";
-        for (@tests[0..9]) {
-                printf "# %0.6f %s\n", $t->{$_}->{elapsed}, $_;
+        if (scalar(@tests) > 1) {
+                my $end = $#tests > 9 ? 9 : $#tests;
+                my $nr = $end + 1;
+                say "# top $nr longest tests (`make check' regenerates)";
+                for (grep defined, @tests[0..$end]) {
+                        printf "# %0.6f %s\n", $t->{$_}->{elapsed}, $_;
+                }
         }
 }
 
@@ -208,7 +212,7 @@ for (my $i = $repeat; $i != 0; $i--) {
         # fill the queue before forking so children can start earlier
         $wr->autoflush(1);
         $wr->blocking(0);
-        my $todo_buf = join('', map { pack('I', $_) } (0..$#todo));
+        my $todo_buf = pack('I*', 0..$#todo);
         my $woff = syswrite($wr, $todo_buf) // DIE "syswrite: $!";
         substr($todo_buf, 0, $woff, '');
         $eof = undef;