]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
runtests: handle repeating tests in multiprocess mode
authorDan Fandrich <dan@coneharvesters.com>
Tue, 23 May 2023 04:47:46 +0000 (21:47 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Mon, 5 Jun 2023 18:16:06 +0000 (11:16 -0700)
Such as what happens with the --repeat option.  Some functions are
changed to pass the runner ID instead of relying on the non-unique test
number.

Ref: #10818

tests/runtests.pl

index 16a9d636a44d176de4f43bed84c9b7dabd4d9b77..d00759783194029e5aaa83d41f641cc2d23fddb5 100755 (executable)
@@ -165,8 +165,7 @@ my %singletest_logs;   # log messages while in singletest array ref by runner
 my $singletest_bufferedrunner; # runner ID which is buffering logs
 my %runnerids;         # runner IDs by number
 my @runnersidle;       # runner IDs idle and ready to execute a test
-my %runnerfortest;     # runner IDs by testnum
-my %countfortest;      # test count by testnum
+my %countforrunner;    # test count by runner ID
 my %runnersrunning;    # tests currently running by runner ID
 
 #######################################################################
@@ -399,7 +398,7 @@ sub showdiff {
 # some pattern that is allowed to differ, output test results
 #
 sub compare {
-    my ($testnum, $testname, $subject, $firstref, $secondref)=@_;
+    my ($runnerid, $testnum, $testname, $subject, $firstref, $secondref)=@_;
 
     my $result = compareparts($firstref, $secondref);
 
@@ -409,7 +408,7 @@ sub compare {
 
         if(!$short) {
             logmsg "\n $testnum: $subject FAILED:\n";
-            my $logdir = getlogdir($testnum);
+            my $logdir = getrunnerlogdir($runnerid);
             logmsg showdiff($logdir, $firstref, $secondref);
         }
         elsif(!$automakestyle) {
@@ -967,10 +966,9 @@ sub updatetesttimings {
 
 
 #######################################################################
-# Return the log directory for the given test
-# There is only one directory for the moment
-sub getlogdir {
-    my $testnum = $_[0];
+# Return the log directory for the given test runner ID
+sub getrunnerlogdir {
+    my $runnerid = $_[0];
     return $LOGDIR;
 }
 
@@ -1149,7 +1147,7 @@ sub singletest_check {
         return -2;
     }
 
-    my $logdir = getlogdir($testnum);
+    my $logdir = getrunnerlogdir($runnerid);
     my @err = getpart("verify", "errorcode");
     my $errorcode = $err[0] || "0";
     my $ok="";
@@ -1202,7 +1200,7 @@ sub singletest_check {
             subnewlines(0, \$_) for @validstdout;
         }
 
-        $res = compare($testnum, $testname, "stdout", \@actual, \@validstdout);
+        $res = compare($runnerid, $testnum, $testname, "stdout", \@actual, \@validstdout);
         if($res) {
             return -1;
         }
@@ -1254,7 +1252,7 @@ sub singletest_check {
             chomp($validstderr[-1]);
         }
 
-        $res = compare($testnum, $testname, "stderr", \@actual, \@validstderr);
+        $res = compare($runnerid, $testnum, $testname, "stderr", \@actual, \@validstderr);
         if($res) {
             return -1;
         }
@@ -1312,7 +1310,7 @@ sub singletest_check {
             return -1;
         }
 
-        $res = compare($testnum, $testname, "protocol", \@out, \@protocol);
+        $res = compare($runnerid, $testnum, $testname, "protocol", \@out, \@protocol);
         if($res) {
             return -1;
         }
@@ -1378,7 +1376,7 @@ sub singletest_check {
     if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
         # verify the received data
         my @out = loadarray($CURLOUT);
-        $res = compare($testnum, $testname, "data", \@out, \@reply);
+        $res = compare($runnerid, $testnum, $testname, "data", \@out, \@reply);
         if ($res) {
             return -1;
         }
@@ -1406,7 +1404,7 @@ sub singletest_check {
             }
         }
 
-        $res = compare($testnum, $testname, "upload", \@out, \@upload);
+        $res = compare($runnerid, $testnum, $testname, "upload", \@out, \@upload);
         if ($res) {
             return -1;
         }
@@ -1449,7 +1447,7 @@ sub singletest_check {
             subnewlines(0, \$_) for @proxyprot;
         }
 
-        $res = compare($testnum, $testname, "proxy", \@out, \@proxyprot);
+        $res = compare($runnerid, $testnum, $testname, "proxy", \@out, \@proxyprot);
         if($res) {
             return -1;
         }
@@ -1513,7 +1511,7 @@ sub singletest_check {
                 @generated = @newgen;
             }
 
-            $res = compare($testnum, $testname, "output ($filename)",
+            $res = compare($runnerid, $testnum, $testname, "output ($filename)",
                            \@generated, \@outfile);
             if($res) {
                 return -1;
@@ -1529,7 +1527,7 @@ sub singletest_check {
     if(@socksprot) {
         # Verify the sent SOCKS proxy details
         my @out = loadarray("$logdir/$SOCKSIN");
-        $res = compare($testnum, $testname, "socks", \@out, \@socksprot);
+        $res = compare($runnerid, $testnum, $testname, "socks", \@out, \@socksprot);
         if($res) {
             return -1;
         }
@@ -1701,7 +1699,7 @@ sub singletest {
     }
 
     if($singletest_state{$runnerid} == ST_INIT) {
-        my $logdir = getlogdir($testnum);
+        my $logdir = getrunnerlogdir($runnerid);
         # first, remove all lingering log files
         if(!cleardir($logdir) && $clearlocks) {
             runnerac_clearlocks($runnerid, $logdir);
@@ -1716,7 +1714,7 @@ sub singletest {
     } elsif($singletest_state{$runnerid} == ST_CLEARLOCKS) {
         my ($rid, $logs) = runnerar($runnerid);
         logmsg $logs;
-        my $logdir = getlogdir($testnum);
+        my $logdir = getrunnerlogdir($runnerid);
         cleardir($logdir);
         $singletest_state{$runnerid} = ST_INITED;
         # Recursively call the state machine again because there is no
@@ -1751,13 +1749,13 @@ sub singletest {
             if($postmortem) {
                 # Error indicates an actual problem starting the server, so
                 # display the server logs
-                displaylogs($testnum);
+                displaylogs($rid, $testnum);
             }
         }
 
         #######################################################################
         # Load test file for this test number
-        my $logdir = getlogdir($testnum);
+        my $logdir = getrunnerlogdir($runnerid);
         loadtest("${logdir}/test${testnum}");
 
         #######################################################################
@@ -1818,7 +1816,7 @@ sub singletest {
         # Verify that the test succeeded
         #
         # Load test file for this test number
-        my $logdir = getlogdir($testnum);
+        my $logdir = getrunnerlogdir($runnerid);
         loadtest("${logdir}/test${testnum}");
         readtestkeywords();
 
@@ -2024,6 +2022,7 @@ sub createrunners {
     cleardir($LOGDIR);
     mkdir($LOGDIR, 0777);
     $runnerids{$runnernum} = runner_init($LOGDIR, $jobs);
+    my $dir = getrunnerlogdir($runnerids{$runnernum});
     runnerready($runnerids{$runnernum});
 }
 
@@ -2591,8 +2590,8 @@ sub displaylogcontent {
 }
 
 sub displaylogs {
-    my ($testnum)=@_;
-    my $logdir = getlogdir($testnum);
+    my ($runnerid, $testnum)=@_;
+    my $logdir = getrunnerlogdir($runnerid);
     opendir(DIR, "$logdir") ||
         die "can't open dir: $!";
     my @logs = readdir(DIR);
@@ -2727,16 +2726,13 @@ while () {
 
         # pick a runner for this new test
         my $runnerid = pickrunner($testnum);
-        exists $runnerfortest{$testnum} && die "Internal error: test already running";
-        $runnerfortest{$testnum} = $runnerid;
-        $countfortest{$testnum} = $count;
+        $countforrunner{$runnerid} = $count;
 
         # Start the test
-        my $rid = $runnerfortest{$testnum};
-        my ($error, $again) = singletest($rid, $testnum, $countfortest{$testnum}, $totaltests);
+        my ($error, $again) = singletest($runnerid, $testnum, $countforrunner{$runnerid}, $totaltests);
         if($again) {
             # this runner is busy running a test
-            $runnersrunning{$rid} = $testnum;
+            $runnersrunning{$runnerid} = $testnum;
         } else {
             # We make this assumption to avoid having to handle $error here
             die "Internal error: test must not complete on first call";
@@ -2760,7 +2756,7 @@ while () {
         # This runner is ready to be serviced
         my $testnum = $runnersrunning{$ridready};
         delete $runnersrunning{$ridready};
-        my ($error, $again) = singletest($ridready, $testnum, $countfortest{$testnum}, $totaltests);
+        my ($error, $again) = singletest($ridready, $testnum, $countforrunner{$ridready}, $totaltests);
         if($again) {
             # this runner is busy running a test
             $runnersrunning{$ridready} = $testnum;
@@ -2786,7 +2782,7 @@ print "COMPLETED $testnum \n" if($verbose); #. join(",", keys(%runnersrunning))
                 }
                 if($postmortem) {
                     # display all files in $LOGDIR/ in a nice way
-                    displaylogs($testnum);
+                    displaylogs($ridready, $testnum);
                 }
                 if($error==2) {
                     $ign++; # ignored test result counter