]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
runtests: use a function to obtain $LOGDIR for a test
authorDan Fandrich <dan@coneharvesters.com>
Thu, 27 Apr 2023 06:01:35 +0000 (23:01 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Fri, 5 May 2023 07:45:43 +0000 (00:45 -0700)
This will no longer be static soon.

Ref: #10818

tests/runner.pm
tests/runtests.pl

index 5e7c73d7859d399583c443cdfd9b67503b88c1a3..90af5b722588d7b01ed7a56f772e42c340f45fa0 100644 (file)
@@ -40,7 +40,8 @@ BEGIN {
         runner_stopservers
         runner_test_preprocess
         runner_test_run
-        setlogfunc
+        stderrfilename
+        stdoutfilename
         $DBGCURL
         $gdb
         $gdbthis
@@ -105,6 +106,17 @@ my $defserverlogslocktimeout = 2; # timeout to await server logs lock removal
 my $defpostcommanddelay = 0; # delay between command and postcheck sections
 
 
+# redirected stdout/stderr to these files
+sub stdoutfilename {
+    my ($logdir, $testnum)=@_;
+    return "$logdir/stdout$testnum";
+}
+
+sub stderrfilename {
+    my ($logdir, $testnum)=@_;
+    return "$logdir/stderr$testnum";
+}
+
 #######################################################################
 # Check for a command in the PATH of the machine running curl.
 #
@@ -618,10 +630,6 @@ sub singletest_run {
         }
     }
 
-    # redirected stdout/stderr to these files
-    $STDOUT="$LOGDIR/stdout$testnum";
-    $STDERR="$LOGDIR/stderr$testnum";
-
     my @codepieces = getpart("client", "tool");
     my $tool="";
     if(@codepieces) {
@@ -675,7 +683,7 @@ sub singletest_run {
     }
     else {
         $cmdargs = " $cmd"; # $cmd is the command line for the test file
-        $CURLOUT = $STDOUT; # sends received data to stdout
+        $CURLOUT = stdoutfilename($LOGDIR, $testnum); # sends received data to stdout
 
         # Default the tool to a unit test with the same name as the test spec
         if($keywords{"unittest"} && !$tool) {
@@ -739,7 +747,8 @@ sub singletest_run {
         $CMDLINE = "$valgrindcmd $CMDLINE";
     }
 
-    $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
+    $CMDLINE .= "$cmdargs > " . stdoutfilename($LOGDIR, $testnum) .
+                " 2> " . stderrfilename($LOGDIR, $testnum);
 
     if($verbose) {
         logmsg "$CMDLINE\n";
index 14dfdffb808c29630336989966325edd8e86531b..9121d8ff438b35331213f4d8b9c31b254a38f548 100755 (executable)
@@ -354,7 +354,8 @@ sub compare {
 
         if(!$short) {
             logmsg "\n $testnum: $subject FAILED:\n";
-            logmsg showdiff($LOGDIR, $firstref, $secondref);
+            my $logdir = getlogdir($testnum);
+            logmsg showdiff($logdir, $firstref, $secondref);
         }
         elsif(!$automakestyle) {
             logmsg "FAILED\n";
@@ -917,6 +918,15 @@ sub updatetesttimings {
 }
 
 
+#######################################################################
+# Return the log directory for the given test
+# There is only one directory for the moment
+sub getlogdir {
+    my $testnum = $_[0];
+    return $LOGDIR;
+}
+
+
 #######################################################################
 # Verify that this test case should be run
 sub singletest_shouldrun {
@@ -1091,6 +1101,7 @@ sub singletest_check {
         return -2;
     }
 
+    my $logdir = getlogdir($testnum);
     my @err = getpart("verify", "errorcode");
     my $errorcode = $err[0] || "0";
     my $ok="";
@@ -1104,7 +1115,7 @@ sub singletest_check {
     my @validstdout = getpart("verify", "stdout");
     if (@validstdout) {
         # verify redirected stdout
-        my @actual = loadarray($STDOUT);
+        my @actual = loadarray(stdoutfilename($logdir, $testnum));
 
         foreach my $strip (@stripfile) {
             chomp $strip;
@@ -1156,7 +1167,7 @@ sub singletest_check {
     my @validstderr = getpart("verify", "stderr");
     if (@validstderr) {
         # verify redirected stderr
-        my @actual = loadarray($STDERR);
+        my @actual = loadarray(stderrfilename($logdir, $testnum));
 
         foreach my $strip (@stripfile) {
             chomp $strip;
@@ -1339,7 +1350,7 @@ sub singletest_check {
         }
 
         # verify uploaded data
-        my @out = loadarray("$LOGDIR/upload.$testnum");
+        my @out = loadarray("$logdir/upload.$testnum");
         for my $strip (@strippart) {
             chomp $strip;
             for(@out) {
@@ -1532,8 +1543,8 @@ sub singletest_check {
 
     if($valgrind) {
         if($usedvalgrind) {
-            if(!opendir(DIR, "$LOGDIR")) {
-                logmsg "ERROR: unable to read $LOGDIR\n";
+            if(!opendir(DIR, "$logdir")) {
+                logmsg "ERROR: unable to read $logdir\n";
                 # timestamp test result verification end
                 $timevrfyend{$testnum} = Time::HiRes::time();
                 return -1;
@@ -1553,7 +1564,7 @@ sub singletest_check {
                 $timevrfyend{$testnum} = Time::HiRes::time();
                 return -1;
             }
-            my @e = valgrindparse("$LOGDIR/$vgfile");
+            my @e = valgrindparse("$logdir/$vgfile");
             if(@e && $e[0]) {
                 if($automakestyle) {
                     logmsg "FAIL: $testnum - $testname - valgrind\n";
@@ -1626,11 +1637,13 @@ sub singletest_success {
 sub singletest {
     my ($testnum, $count, $total)=@_;
 
+    my $logdir = getlogdir($testnum);
+
     # first, remove all lingering log files
-    if(!cleardir($LOGDIR) && $clearlocks) {
-        my $logs = runner_clearlocks($LOGDIR);
+    if(!cleardir($logdir) && $clearlocks) {
+        my $logs = runner_clearlocks($logdir);
         logmsg $logs;
-        cleardir($LOGDIR);
+        cleardir($logdir);
     }
 
     ###################################################################
@@ -2409,12 +2422,13 @@ sub displaylogcontent {
 
 sub displaylogs {
     my ($testnum)=@_;
-    opendir(DIR, "$LOGDIR") ||
+    my $logdir = getlogdir($testnum);
+    opendir(DIR, "$logdir") ||
         die "can't open dir: $!";
     my @logs = readdir(DIR);
     closedir(DIR);
 
-    logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
+    logmsg "== Contents of files in the $logdir/ dir after test $testnum\n";
     foreach my $log (sort @logs) {
         if($log =~ /\.(\.|)$/) {
             next; # skip "." and ".."
@@ -2425,7 +2439,7 @@ sub displaylogs {
         if(($log eq "memdump") || ($log eq "core")) {
             next; # skip "memdump" and  "core"
         }
-        if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
+        if((-d "$logdir/$log") || (! -s "$logdir/$log")) {
             next; # skip directory and empty files
         }
         if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
@@ -2459,7 +2473,7 @@ sub displaylogs {
             next; # skip test$testnum since it can be very big
         }
         logmsg "=== Start of file $log\n";
-        displaylogcontent("$LOGDIR/$log");
+        displaylogcontent("$logdir/$log");
         logmsg "=== End of file $log\n";
     }
 }