]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
runtests: display logs on server failure in singletest()
authorDan Fandrich <dan@coneharvesters.com>
Fri, 21 Apr 2023 19:40:11 +0000 (12:40 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Mon, 24 Apr 2023 23:03:44 +0000 (16:03 -0700)
This is closer to the place where logs are displayed on test failure.
Also, only display these logs if -p is given, which is the same flag
that controls display of test failure logs. Some server log files
need to be deleted later so that they stay around long enough to be
displayed on failure.

Ref: #10818

tests/runner.pm
tests/runtests.pl

index b292a636a4e312b94d72f72a36118d4e209a0613..a4851b8cfbc5f16d9ec46d2b3c8dcda2ecc04e2c 100644 (file)
@@ -97,13 +97,6 @@ sub logmsg {
     return main::logmsg(@_);
 }
 
-#######################################################################
-# Call main's displaylogs
-# TODO: this will eventually stop being called in this package
-sub displaylogs{
-    return main::displaylogs(@_);
-}
-
 #######################################################################
 # Check for a command in the PATH of the machine running curl.
 #
@@ -389,25 +382,31 @@ sub restore_test_env {
 sub singletest_startservers {
     my ($testnum, $testtimings) = @_;
 
-    # remove test server commands file before servers are started/verified
-    unlink($FTPDCMD) if(-f $FTPDCMD);
+    # remove old test server files before servers are started/verified
+    unlink($FTPDCMD);
+    unlink($SERVERIN);
+    unlink($SERVER2IN);
+    unlink($PROXYIN);
 
     # timestamp required servers verification start
     $$testtimings{"timesrvrini"} = Time::HiRes::time();
 
     my $why;
+    my $error;
     if (!$listonly) {
         my @what = getpart("client", "server");
         if(!$what[0]) {
             warn "Test case $testnum has no server(s) specified";
             $why = "no server specified";
+            $error = -1;
         } else {
             my $err;
             ($why, $err) = serverfortest(@what);
             if($err == 1) {
-                # Error indicates an actual problem starting the server, so
-                # display the server logs
-                displaylogs($testnum);
+                # Error indicates an actual problem starting the server
+                $error = -2;
+            } else {
+                $error = -1;
             }
         }
     }
@@ -415,12 +414,7 @@ sub singletest_startservers {
     # timestamp required servers verification end
     $$testtimings{"timesrvrend"} = Time::HiRes::time();
 
-    # remove server output logfile after servers are started/verified
-    unlink($SERVERIN);
-    unlink($SERVER2IN);
-    unlink($PROXYIN);
-
-    return $why;
+    return ($why, $error);
 }
 
 
@@ -533,6 +527,11 @@ sub singletest_prepare {
     }
     unlink("core");
 
+    # remove server output logfiles after servers are started/verified
+    unlink($SERVERIN);
+    unlink($SERVER2IN);
+    unlink($PROXYIN);
+
     # if this section exists, it might be FTP server instructions:
     my @ftpservercmd = getpart("reply", "servercmd");
     push @ftpservercmd, "Testnum $testnum\n";
@@ -915,7 +914,7 @@ sub runner_test_preprocess {
 
     ###################################################################
     # Start the servers needed to run this test case
-    my $why = singletest_startservers($testnum, \%testtimings);
+    my ($why, $error) = singletest_startservers($testnum, \%testtimings);
 
     if(!$why) {
 
@@ -933,9 +932,10 @@ sub runner_test_preprocess {
         # Check that the test environment is fine to run this test case
         if (!$listonly) {
             $why = singletest_precheck($testnum);
+            $error = -1;
         }
     }
-    return ($why, \%testtimings);
+    return ($why, $error, \%testtimings);
 }
 
 
index 0b29a4653a11df363f9ddff930a5731cd8a721a1..8cda319c14f0c71bd31d901b327085197e86c3f2 100755 (executable)
@@ -1646,12 +1646,19 @@ sub singletest {
     # Register the test case with the CI environment
     citest_starttest($testnum);
 
-    my ($why, $testtimings) = runner_test_preprocess($testnum);
+    my ($why, $error, $testtimings) = runner_test_preprocess($testnum);
+    if($error == -2) {
+        if($postmortem) {
+            # Error indicates an actual problem starting the server, so
+            # display the server logs
+            displaylogs($testnum);
+        }
+    }
     updatetesttimings($testnum, %$testtimings);
 
     #######################################################################
     # Print the test name and count tests
-    my $error = singletest_count($testnum, $why);
+    $error = singletest_count($testnum, $why);
     if($error) {
         return $error;
     }