Skip to content

Commit 8da49c9

Browse files
committed
runtests: display logs on server failure in singletest()
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: curl#10818
1 parent 90158f0 commit 8da49c9

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

tests/runner.pm

+20-20
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ sub logmsg {
9797
return main::logmsg(@_);
9898
}
9999

100-
#######################################################################
101-
# Call main's displaylogs
102-
# TODO: this will eventually stop being called in this package
103-
sub displaylogs{
104-
return main::displaylogs(@_);
105-
}
106-
107100
#######################################################################
108101
# Check for a command in the PATH of the machine running curl.
109102
#
@@ -389,38 +382,39 @@ sub restore_test_env {
389382
sub singletest_startservers {
390383
my ($testnum, $testtimings) = @_;
391384

392-
# remove test server commands file before servers are started/verified
393-
unlink($FTPDCMD) if(-f $FTPDCMD);
385+
# remove old test server files before servers are started/verified
386+
unlink($FTPDCMD);
387+
unlink($SERVERIN);
388+
unlink($SERVER2IN);
389+
unlink($PROXYIN);
394390

395391
# timestamp required servers verification start
396392
$$testtimings{"timesrvrini"} = Time::HiRes::time();
397393

398394
my $why;
395+
my $error;
399396
if (!$listonly) {
400397
my @what = getpart("client", "server");
401398
if(!$what[0]) {
402399
warn "Test case $testnum has no server(s) specified";
403400
$why = "no server specified";
401+
$error = -1;
404402
} else {
405403
my $err;
406404
($why, $err) = serverfortest(@what);
407405
if($err == 1) {
408-
# Error indicates an actual problem starting the server, so
409-
# display the server logs
410-
displaylogs($testnum);
406+
# Error indicates an actual problem starting the server
407+
$error = -2;
408+
} else {
409+
$error = -1;
411410
}
412411
}
413412
}
414413

415414
# timestamp required servers verification end
416415
$$testtimings{"timesrvrend"} = Time::HiRes::time();
417416

418-
# remove server output logfile after servers are started/verified
419-
unlink($SERVERIN);
420-
unlink($SERVER2IN);
421-
unlink($PROXYIN);
422-
423-
return $why;
417+
return ($why, $error);
424418
}
425419

426420

@@ -533,6 +527,11 @@ sub singletest_prepare {
533527
}
534528
unlink("core");
535529

530+
# remove server output logfiles after servers are started/verified
531+
unlink($SERVERIN);
532+
unlink($SERVER2IN);
533+
unlink($PROXYIN);
534+
536535
# if this section exists, it might be FTP server instructions:
537536
my @ftpservercmd = getpart("reply", "servercmd");
538537
push @ftpservercmd, "Testnum $testnum\n";
@@ -915,7 +914,7 @@ sub runner_test_preprocess {
915914

916915
###################################################################
917916
# Start the servers needed to run this test case
918-
my $why = singletest_startservers($testnum, \%testtimings);
917+
my ($why, $error) = singletest_startservers($testnum, \%testtimings);
919918

920919
if(!$why) {
921920

@@ -933,9 +932,10 @@ sub runner_test_preprocess {
933932
# Check that the test environment is fine to run this test case
934933
if (!$listonly) {
935934
$why = singletest_precheck($testnum);
935+
$error = -1;
936936
}
937937
}
938-
return ($why, \%testtimings);
938+
return ($why, $error, \%testtimings);
939939
}
940940

941941

tests/runtests.pl

+9-2
Original file line numberDiff line numberDiff line change
@@ -1646,12 +1646,19 @@ sub singletest {
16461646
# Register the test case with the CI environment
16471647
citest_starttest($testnum);
16481648

1649-
my ($why, $testtimings) = runner_test_preprocess($testnum);
1649+
my ($why, $error, $testtimings) = runner_test_preprocess($testnum);
1650+
if($error == -2) {
1651+
if($postmortem) {
1652+
# Error indicates an actual problem starting the server, so
1653+
# display the server logs
1654+
displaylogs($testnum);
1655+
}
1656+
}
16501657
updatetesttimings($testnum, %$testtimings);
16511658

16521659
#######################################################################
16531660
# Print the test name and count tests
1654-
my $error = singletest_count($testnum, $why);
1661+
$error = singletest_count($testnum, $why);
16551662
if($error) {
16561663
return $error;
16571664
}

0 commit comments

Comments
 (0)