use Cwd;
use Digest::MD5 qw(md5);
use MIME::Base64;
+use List::Util 'sum';
# Subs imported from serverhelp module
use serverhelp qw(
my $pwd = getcwd(); # current working directory
my $posix_pwd = $pwd;
-my $start;
+my $start; # time at which testing started
my $ftpchecktime=1; # time it took to verify our test FTP server
-my $scrambleorder;
my $stunnel = checkcmd("stunnel4") || checkcmd("tstunnel") || checkcmd("stunnel");
my $valgrind = checktestcmd("valgrind");
-my $valgrind_logfile="--logfile";
+my $valgrind_logfile="--logfile"; # the option name for valgrind 2.X
my $valgrind_tool;
my $gdb = checktestcmd("gdb");
my $httptlssrv = find_httptlssrv();
# on files. Windows for example
my @protocols; # array of lowercase supported protocol servers
-my $skipped=0; # number of tests skipped; reported in main loop
my %skipped; # skipped{reason}=counter, reasons for skip
my @teststat; # teststat[testnum]=reason, reasons for skip
my %disabled_keywords; # key words of tests to skip
my %timevrfyend; # timestamp for each test result verification end
my $testnumcheck; # test number, set in singletest sub.
-my %oldenv;
+my %oldenv; # environment variables before test is started
my %feature; # array of enabled features
my %keywords; # array of keywords from the test spec
my $err_unexpected; # error instead of warning on server unexpectedly alive
my $run_event_based; # run curl with --test-event to test the event API
my $run_disabled; # run the specific tests even if listed in DISABLED
+my $scrambleorder;
my %run; # running server
my %doesntrun; # servers that don't work, identified by pidfile
return 0;
}
+
+# restore environment variables that were modified in test
+sub restore_test_env {
+ my $deleteoldenv = $_[0]; # 1 to delete the saved contents after restore
+ foreach my $var (keys %oldenv) {
+ if($oldenv{$var} eq 'notset') {
+ delete $ENV{$var} if($ENV{$var});
+ }
+ else {
+ $ENV{$var} = $oldenv{$var};
+ }
+ if($deleteoldenv) {
+ delete $oldenv{$var};
+ }
+ }
+}
+
+
+# Setup CI Test Run
+sub citest_starttestrun {
+ if(azure_check_environment()) {
+ $AZURE_RUN_ID = azure_create_test_run($ACURL);
+ logmsg "Azure Run ID: $AZURE_RUN_ID\n" if ($verbose);
+ }
+ # Appveyor doesn't require anything here
+}
+
+
+# Register the test case with the CI runner
+sub citest_starttest {
+ my $testnum = $_[0];
+
+ # get the name of the test early
+ my $testname= (getpart("client", "name"))[0];
+ chomp $testname;
+
+ # create test result in CI services
+ if(azure_check_environment() && $AZURE_RUN_ID) {
+ $AZURE_RESULT_ID = azure_create_test_result($ACURL, $AZURE_RUN_ID, $testnum, $testname);
+ }
+ elsif(appveyor_check_environment()) {
+ appveyor_create_test_result($ACURL, $testnum, $testname);
+ }
+}
+
+
+# Submit the test case result with the CI runner
+sub citest_finishtest {
+ my ($testnum, $error) = @_;
+ # update test result in CI services
+ if(azure_check_environment() && $AZURE_RUN_ID && $AZURE_RESULT_ID) {
+ $AZURE_RESULT_ID = azure_update_test_result($ACURL, $AZURE_RUN_ID, $AZURE_RESULT_ID, $testnum, $error,
+ $timeprepini{$testnum}, $timevrfyend{$testnum});
+ }
+ elsif(appveyor_check_environment()) {
+ appveyor_update_test_result($ACURL, $testnum, $error, $timeprepini{$testnum}, $timevrfyend{$testnum});
+ }
+}
+
+# Complete CI test run
+sub citest_finishtestrun {
+ if(azure_check_environment() && $AZURE_RUN_ID) {
+ $AZURE_RUN_ID = azure_update_test_run($ACURL, $AZURE_RUN_ID);
+ }
+ # Appveyor doesn't require anything here
+}
+
+
#######################################################################
# Verify that this test case should be run
sub singletest_shouldrun {
}
-#######################################################################
-# Register the test case with the CI environment
-sub singletest_registerci {
- my $testnum = $_[0];
-
- # test definition may instruct to (un)set environment vars
- # this is done this early, so that the precheck can use environment
- # variables and still bail out fine on errors
-
- # restore environment variables that were modified in a previous run
- foreach my $var (keys %oldenv) {
- if($oldenv{$var} eq 'notset') {
- delete $ENV{$var} if($ENV{$var});
- }
- else {
- $ENV{$var} = $oldenv{$var};
- }
- delete $oldenv{$var};
- }
-
- # get the name of the test early
- my $testname= (getpart("client", "name"))[0];
- chomp $testname;
-
- # create test result in CI services
- if(azure_check_environment() && $AZURE_RUN_ID) {
- $AZURE_RESULT_ID = azure_create_test_result($ACURL, $AZURE_RUN_ID, $testnum, $testname);
- }
- elsif(appveyor_check_environment()) {
- appveyor_create_test_result($ACURL, $testnum, $testname);
- }
-}
-
-
#######################################################################
# Start the servers needed to run this test case
sub singletest_startservers {
if($why && !$listonly) {
# there's a problem, count it as "skipped"
- $skipped++;
$skipped{$why}++;
$teststat[$testnum]=$why; # store reason for this test case
}
# restore environment variables that were modified
- if(%oldenv) {
- foreach my $var (keys %oldenv) {
- if($oldenv{$var} eq 'notset') {
- delete $ENV{$var} if($ENV{$var});
- }
- else {
- $ENV{$var} = "$oldenv{$var}";
- }
- }
- }
+ restore_test_env(0);
# Skip all the verification on torture tests
if ($torture) {
my ($why, $errorreturncode) = singletest_shouldrun($testnum);
+ #######################################################################
+ # Restore environment variables that were modified in a previous run.
+ # Test definition may instruct to (un)set environment vars.
+ # This is done this early so that leftover variables don't affect starting
+ # servers.
+ restore_test_env(1);
+
+
#######################################################################
# Register the test case with the CI environment
- singletest_registerci($testnum);
+ citest_starttest($testnum);
#######################################################################
if($disabled{$n}) {
# skip disabled test cases
my $why = "configured as DISABLED";
- $skipped++;
$skipped{$why}++;
$teststat[$n]=$why; # store reason for this test case
next;
}
#######################################################################
-# Setup Azure Pipelines Test Run (if running in Azure DevOps)
-#
-
-if(azure_check_environment()) {
- $AZURE_RUN_ID = azure_create_test_run($ACURL);
- logmsg "Azure Run ID: $AZURE_RUN_ID\n" if ($verbose);
-}
+# Setup CI Test Run
+citest_starttestrun();
#######################################################################
# The main test-loop
$lasttest = $testnum if($testnum > $lasttest);
$count++;
+ # execute one test case
my $error = singletest($testnum, $count, scalar(@at));
- # update test result in CI services
- if(azure_check_environment() && $AZURE_RUN_ID && $AZURE_RESULT_ID) {
- $AZURE_RESULT_ID = azure_update_test_result($ACURL, $AZURE_RUN_ID, $AZURE_RESULT_ID, $testnum, $error,
- $timeprepini{$testnum}, $timevrfyend{$testnum});
- }
- elsif(appveyor_check_environment()) {
- appveyor_update_test_result($ACURL, $testnum, $error, $timeprepini{$testnum}, $timevrfyend{$testnum});
- }
+ # Submit the test case result with the CI environment
+ citest_finishtest($testnum, $error);
if($error < 0) {
# not a test we can run
my $sofar = time() - $start;
#######################################################################
-# Finish Azure Pipelines Test Run (if running in Azure DevOps)
-#
-
-if(azure_check_environment() && $AZURE_RUN_ID) {
- $AZURE_RUN_ID = azure_update_test_run($ACURL, $AZURE_RUN_ID);
-}
+# Finish CI Test Run
+citest_finishtestrun();
# Tests done, stop the servers
my $unexpected = stopservers($verbose);
-my $all = $total + $skipped;
+my $numskipped = %skipped ? sum values %skipped : 0;
+my $all = $total + $numskipped;
runtimestats($lasttest);
sprintf("%.0f", $sofar) ." seconds.\n";
}
-if($skipped && !$short) {
+if(%skipped && !$short) {
my $s=0;
# Temporary hash to print the restraints sorted by the number
# of their occurrences
my %restraints;
- logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
+ logmsg "TESTINFO: $numskipped tests were skipped due to these restraints:\n";
for(keys %skipped) {
my $r = $_;