/test/runtest
Perl | 3765 lines | 2335 code | 678 blank | 752 comment | 556 complexity | 6171e73b04c453c5118d89556a6bb5a7 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- #! /usr/bin/perl -w
- ###############################################################################
- # This is the controlling script for the "new" test suite for Exim. It should #
- # be possible to export this suite for running on a wide variety of hosts, in #
- # contrast to the old suite, which was very dependent on the environment of #
- # Philip Hazel's desktop computer. This implementation inspects the version #
- # of Exim that it finds, and tests only those features that are included. The #
- # surrounding environment is also tested to discover what is available. See #
- # the README file for details of how it all works. #
- # #
- # Implementation started: 03 August 2005 by Philip Hazel #
- # Placed in the Exim CVS: 06 February 2006 #
- ###############################################################################
- #use strict;
- use Errno;
- use FileHandle;
- use Socket;
- use Time::Local;
- use Cwd;
- use File::Basename;
- use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
- # Start by initializing some global variables
- $testversion = "4.80 (08-May-12)";
- # This gets embedded in the D-H params filename, and the value comes
- # from asking GnuTLS for "normal", but there appears to be no way to
- # use certtool/... to ask what that value currently is. *sigh*
- # We also clamp it because of NSS interop, see addition of tls_dh_max_bits.
- # This value is correct as of GnuTLS 2.12.18 as clamped by tls_dh_max_bits.
- # normal = 2432 tls_dh_max_bits = 2236
- $gnutls_dh_bits_normal = 2236;
- $cf = "bin/cf -exact";
- $cr = "\r";
- $debug = 0;
- $force_continue = 0;
- $force_update = 0;
- $log_failed_filename = "failed-summary.log";
- $more = "less -XF";
- $optargs = "";
- $save_output = 0;
- $server_opts = "";
- $flavour = 'FOO';
- $have_ipv4 = 1;
- $have_ipv6 = 1;
- $have_largefiles = 0;
- $test_start = 1;
- $test_end = $test_top = 8999;
- $test_special_top = 9999;
- @test_list = ();
- @test_dirs = ();
- # Networks to use for DNS tests. We need to choose some networks that will
- # never be used so that there is no chance that the host on which we are
- # running is actually in one of the test networks. Private networks such as
- # the IPv4 10.0.0.0/8 network are no good because hosts may well use them.
- # Rather than use some unassigned numbers (that might become assigned later),
- # I have chosen some multicast networks, in the belief that such addresses
- # won't ever be assigned to hosts. This is the only place where these numbers
- # are defined, so it is trivially possible to change them should that ever
- # become necessary.
- $parm_ipv4_test_net = "224";
- $parm_ipv6_test_net = "ff00";
- # Port numbers are currently hard-wired
- $parm_port_n = 1223; # Nothing listening on this port
- $parm_port_s = 1224; # Used for the "server" command
- $parm_port_d = 1225; # Used for the Exim daemon
- $parm_port_d2 = 1226; # Additional for daemon
- $parm_port_d3 = 1227; # Additional for daemon
- $parm_port_d4 = 1228; # Additional for daemon
- # Manually set locale
- $ENV{'LC_ALL'} = 'C';
- # In some environments USER does not exists, but we
- # need it for some test(s)
- $ENV{USER} = getpwuid($>)
- if not exists $ENV{USER};
- ###############################################################################
- ###############################################################################
- # Define a number of subroutines
- ###############################################################################
- ###############################################################################
- ##################################################
- # Handle signals #
- ##################################################
- sub pipehandler { $sigpipehappened = 1; }
- sub inthandler { print "\n"; tests_exit(-1, "Caught SIGINT"); }
- ##################################################
- # Do global macro substitutions #
- ##################################################
- # This function is applied to configurations, command lines and data lines in
- # scripts, and to lines in the files of the aux-var-src and the dnszones-src
- # directory. It takes one argument: the current test number, or zero when
- # setting up files before running any tests.
- sub do_substitute{
- s?\bCALLER\b?$parm_caller?g;
- s?\bCALLERGROUP\b?$parm_caller_group?g;
- s?\bCALLER_UID\b?$parm_caller_uid?g;
- s?\bCALLER_GID\b?$parm_caller_gid?g;
- s?\bCLAMSOCKET\b?$parm_clamsocket?g;
- s?\bDIR/?$parm_cwd/?g;
- s?\bEXIMGROUP\b?$parm_eximgroup?g;
- s?\bEXIMUSER\b?$parm_eximuser?g;
- s?\bHOSTIPV4\b?$parm_ipv4?g;
- s?\bHOSTIPV6\b?$parm_ipv6?g;
- s?\bHOSTNAME\b?$parm_hostname?g;
- s?\bPORT_D\b?$parm_port_d?g;
- s?\bPORT_D2\b?$parm_port_d2?g;
- s?\bPORT_D3\b?$parm_port_d3?g;
- s?\bPORT_D4\b?$parm_port_d4?g;
- s?\bPORT_N\b?$parm_port_n?g;
- s?\bPORT_S\b?$parm_port_s?g;
- s?\bTESTNUM\b?$_[0]?g;
- s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
- s?\bV6NET:?$parm_ipv6_test_net:?g;
- }
- ##################################################
- # Any state to be preserved across tests #
- ##################################################
- my $TEST_STATE = {};
- ##################################################
- # Subroutine to tidy up and exit #
- ##################################################
- # In all cases, we check for any Exim daemons that have been left running, and
- # kill them. Then remove all the spool data, test output, and the modified Exim
- # binary if we are ending normally.
- # Arguments:
- # $_[0] = 0 for a normal exit; full cleanup done
- # $_[0] > 0 for an error exit; no files cleaned up
- # $_[0] < 0 for a "die" exit; $_[1] contains a message
- sub tests_exit{
- my($rc) = $_[0];
- my($spool);
- # Search for daemon pid files and kill the daemons. We kill with SIGINT rather
- # than SIGTERM to stop it outputting "Terminated" to the terminal when not in
- # the background.
- if (exists $TEST_STATE->{exim_pid})
- {
- $pid = $TEST_STATE->{exim_pid};
- print "Tidyup: killing wait-mode daemon pid=$pid\n";
- system("sudo kill -INT $pid");
- }
- if (opendir(DIR, "spool"))
- {
- my(@spools) = sort readdir(DIR);
- closedir(DIR);
- foreach $spool (@spools)
- {
- next if $spool !~ /^exim-daemon./;
- open(PID, "spool/$spool") || die "** Failed to open \"spool/$spool\": $!\n";
- chomp($pid = <PID>);
- close(PID);
- print "Tidyup: killing daemon pid=$pid\n";
- system("sudo rm -f spool/$spool; sudo kill -INT $pid");
- }
- }
- else
- { die "** Failed to opendir(\"spool\"): $!\n" unless $!{ENOENT}; }
- # Close the terminal input and remove the test files if all went well, unless
- # the option to save them is set. Always remove the patched Exim binary. Then
- # exit normally, or die.
- close(T);
- system("sudo /bin/rm -rf ./spool test-* ./dnszones/*")
- if ($rc == 0 && !$save_output);
- system("sudo /bin/rm -rf ./eximdir/*")
- if (!$save_output);
- print "\nYou were in test $test at the end there.\n\n" if defined $test;
- exit $rc if ($rc >= 0);
- die "** runtest error: $_[1]\n";
- }
- ##################################################
- # Subroutines used by the munging subroutine #
- ##################################################
- # This function is used for things like message ids, where we want to generate
- # more than one value, but keep a consistent mapping throughout.
- #
- # Arguments:
- # $oldid the value from the file
- # $base a base string into which we insert a sequence
- # $sequence the address of the current sequence counter
- sub new_value {
- my($oldid, $base, $sequence) = @_;
- my($newid) = $cache{$oldid};
- if (! defined $newid)
- {
- $newid = sprintf($base, $$sequence++);
- $cache{$oldid} = $newid;
- }
- return $newid;
- }
- # This is used while munging the output from exim_dumpdb.
- # May go wrong across DST changes.
- sub date_seconds {
- my($day,$month,$year,$hour,$min,$sec) =
- $_[0] =~ /^(\d\d)-(\w\w\w)-(\d{4})\s(\d\d):(\d\d):(\d\d)/;
- my($mon);
- if ($month =~ /Jan/) {$mon = 0;}
- elsif($month =~ /Feb/) {$mon = 1;}
- elsif($month =~ /Mar/) {$mon = 2;}
- elsif($month =~ /Apr/) {$mon = 3;}
- elsif($month =~ /May/) {$mon = 4;}
- elsif($month =~ /Jun/) {$mon = 5;}
- elsif($month =~ /Jul/) {$mon = 6;}
- elsif($month =~ /Aug/) {$mon = 7;}
- elsif($month =~ /Sep/) {$mon = 8;}
- elsif($month =~ /Oct/) {$mon = 9;}
- elsif($month =~ /Nov/) {$mon = 10;}
- elsif($month =~ /Dec/) {$mon = 11;}
- return timelocal($sec,$min,$hour,$day,$mon,$year);
- }
- # This is a subroutine to sort maildir files into time-order. The second field
- # is the microsecond field, and may vary in length, so must be compared
- # numerically.
- sub maildirsort {
- return $a cmp $b if ($a !~ /^\d+\.H\d/ || $b !~ /^\d+\.H\d/);
- my($x1,$y1) = $a =~ /^(\d+)\.H(\d+)/;
- my($x2,$y2) = $b =~ /^(\d+)\.H(\d+)/;
- return ($x1 != $x2)? ($x1 <=> $x2) : ($y1 <=> $y2);
- }
- ##################################################
- # Subroutine list files below a directory #
- ##################################################
- # This is used to build up a list of expected mail files below a certain path
- # in the directory tree. It has to be recursive in order to deal with multiple
- # maildir mailboxes.
- sub list_files_below {
- my($dir) = $_[0];
- my(@yield) = ();
- my(@sublist, $file);
- opendir(DIR, $dir) || tests_exit(-1, "Failed to open $dir: $!");
- @sublist = sort maildirsort readdir(DIR);
- closedir(DIR);
- foreach $file (@sublist)
- {
- next if $file eq "." || $file eq ".." || $file eq "CVS";
- if (-d "$dir/$file")
- { @yield = (@yield, list_files_below("$dir/$file")); }
- else
- { push @yield, "$dir/$file"; }
- }
- return @yield;
- }
- ##################################################
- # Munge a file before comparing #
- ##################################################
- # The pre-processing turns all dates, times, Exim versions, message ids, and so
- # on into standard values, so that the compare works. Perl's substitution with
- # an expression provides a neat way to do some of these changes.
- # We keep a global associative array for repeatedly turning the same values
- # into the same standard values throughout the data from a single test.
- # Message ids get this treatment (can't be made reliable for times), and
- # times in dumped retry databases are also handled in a special way, as are
- # incoming port numbers.
- # On entry to the subroutine, the file to write to is already opened with the
- # name MUNGED. The input file name is the only argument to the subroutine.
- # Certain actions are taken only when the name contains "stderr", "stdout",
- # or "log". The yield of the function is 1 if a line matching "*** truncated
- # ***" is encountered; otherwise it is 0.
- sub munge {
- my($file) = $_[0];
- my($extra) = $_[1];
- my($yield) = 0;
- my(@saved) = ();
- local $_;
- open(IN, "$file") || tests_exit(-1, "Failed to open $file: $!");
- my($is_log) = $file =~ /log/;
- my($is_stdout) = $file =~ /stdout/;
- my($is_stderr) = $file =~ /stderr/;
- # Date pattern
- $date = "\\d{2}-\\w{3}-\\d{4}\\s\\d{2}:\\d{2}:\\d{2}";
- # Pattern for matching pids at start of stderr lines; initially something
- # that won't match.
- $spid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- # Scan the file and make the changes. Near the bottom there are some changes
- # that are specific to certain file types, though there are also some of those
- # inline too.
- while(<IN>)
- {
- RESET_AFTER_EXTRA_LINE_READ:
- # Custom munges
- if ($extra)
- {
- next if $extra =~ m%^/% && eval $extra;
- eval $extra if $extra =~ m/^s/;
- }
- # Check for "*** truncated ***"
- $yield = 1 if /\*\*\* truncated \*\*\*/;
- # Replace the name of this host
- s/\Q$parm_hostname\E/the.local.host.name/g;
- # But convert "name=the.local.host address=127.0.0.1" to use "localhost"
- s/name=the\.local\.host address=127\.0\.0\.1/name=localhost address=127.0.0.1/g;
- # The name of the shell may vary
- s/\s\Q$parm_shell\E\b/ ENV_SHELL/;
- # Replace the path to the testsuite directory
- s?\Q$parm_cwd\E?TESTSUITE?g;
- # Replace the Exim version number (may appear in various places)
- # patchexim should have fixed this for us
- #s/(Exim) \d+\.\d+[\w_-]*/$1 x.yz/i;
- # Replace Exim message ids by a unique series
- s/((?:[^\W_]{6}-){2}[^\W_]{2})
- /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
- # The names of lock files appear in some error and debug messages
- s/\.lock(\.[-\w]+)+(\.[\da-f]+){2}/.lock.test.ex.dddddddd.pppppppp/;
- # Unless we are in an IPv6 test, replace IPv4 and/or IPv6 in "listening on
- # port" message, because it is not always the same.
- s/port (\d+) \([^)]+\)/port $1/g
- if !$is_ipv6test && m/listening for SMTP(S?) on port/;
- # Challenges in SPA authentication
- s/TlRMTVNTUAACAAAAAAAAAAAoAAABgg[\w+\/]+/TlRMTVNTUAACAAAAAAAAAAAoAAABggAAAEbBRwqFwwIAAAAAAAAAAAAt1sgAAAAA/;
- # PRVS values
- s?prvs=([^/]+)/[\da-f]{10}@?prvs=$1/xxxxxxxxxx@?g; # Old form
- s?prvs=[\da-f]{10}=([^@]+)@?prvs=xxxxxxxxxx=$1@?g; # New form
- # Error lines on stdout from SSL contain process id values and file names.
- # They also contain a source file name and line number, which may vary from
- # release to release.
- s/^\d+:error:/pppp:error:/;
- s/:(?:\/[^\s:]+\/)?([^\/\s]+\.c):\d+:/:$1:dddd:/;
- # There are differences in error messages between OpenSSL versions
- s/SSL_CTX_set_cipher_list/SSL_connect/;
- # One error test in expansions mentions base 62 or 36
- s/is not a base (36|62) number/is not a base 36\/62 number/;
- # This message sometimes has a different number of seconds
- s/forced fail after \d seconds/forced fail after d seconds/;
- # This message may contain a different DBM library name
- s/Failed to open \S+( \([^\)]+\))? file/Failed to open DBM file/;
- # The message for a non-listening FIFO varies
- s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;
- # Debugging output of lists of hosts may have different sort keys
- s/sort=\S+/sort=xx/ if /^\S+ (?:\d+\.){3}\d+ mx=\S+ sort=\S+/;
- # Random local part in callout cache testing
- s/myhost.test.ex-\d+-testing/myhost.test.ex-dddddddd-testing/;
- s/the.local.host.name-\d+-testing/the.local.host.name-dddddddd-testing/;
- # File descriptor numbers may vary
- s/^writing data block fd=\d+/writing data block fd=dddd/;
- s/running as transport filter: write=\d+ read=\d+/running as transport filter: write=dddd read=dddd/;
- # ======== Dumpdb output ========
- # This must be before the general date/date munging.
- # Time data lines, which look like this:
- # 25-Aug-2000 12:11:37 25-Aug-2000 12:11:37 26-Aug-2000 12:11:37
- if (/^($date)\s+($date)\s+($date)(\s+\*)?\s*$/)
- {
- my($date1,$date2,$date3,$expired) = ($1,$2,$3,$4);
- $expired = "" if !defined $expired;
- my($increment) = date_seconds($date3) - date_seconds($date2);
- # We used to use globally unique replacement values, but timing
- # differences make this impossible. Just show the increment on the
- # last one.
- printf MUNGED ("first failed = time last try = time2 next try = time2 + %s%s\n",
- $increment, $expired);
- next;
- }
- # more_errno values in exim_dumpdb output which are times
- s/T:(\S+)\s-22\s(\S+)\s/T:$1 -22 xxxx /;
- # ======== Dates and times ========
- # Dates and times are all turned into the same value - trying to turn
- # them into different ones cannot be done repeatedly because they are
- # real time stamps generated while running the test. The actual date and
- # time used was fixed when I first started running automatic Exim tests.
- # Date/time in header lines and SMTP responses
- s/[A-Z][a-z]{2},\s\d\d?\s[A-Z][a-z]{2}\s\d\d\d\d\s\d\d\:\d\d:\d\d\s[-+]\d{4}
- /Tue, 2 Mar 1999 09:44:33 +0000/gx;
- # Date/time in logs and in one instance of a filter test
- s/^\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(\s[+-]\d\d\d\d)?/1999-03-02 09:44:33/gx;
- s/^Logwrite\s"\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Logwrite "1999-03-02 09:44:33/gx;
- # Date/time in message separators
- s/(?:[A-Z][a-z]{2}\s){2}\d\d\s\d\d:\d\d:\d\d\s\d\d\d\d
- /Tue Mar 02 09:44:33 1999/gx;
- # Date of message arrival in spool file as shown by -Mvh
- s/^\d{9,10}\s0$/ddddddddd 0/;
- # Date/time in mbx mailbox files
- s/\d\d-\w\w\w-\d\d\d\d\s\d\d:\d\d:\d\d\s[-+]\d\d\d\d,/06-Sep-1999 15:52:48 +0100,/gx;
- # Dates/times in debugging output for writing retry records
- if (/^ first failed=(\d+) last try=(\d+) next try=(\d+) (.*)$/)
- {
- my($next) = $3 - $2;
- $_ = " first failed=dddd last try=dddd next try=+$next $4\n";
- }
- s/^(\s*)now=\d+ first_failed=\d+ next_try=\d+ expired=(\d)/$1now=tttt first_failed=tttt next_try=tttt expired=$2/;
- s/^(\s*)received_time=\d+ diff=\d+ timeout=(\d+)/$1received_time=tttt diff=tttt timeout=$2/;
- # Time to retry may vary
- s/time to retry = \S+/time to retry = tttt/;
- s/retry record exists: age=\S+/retry record exists: age=ttt/;
- s/failing_interval=\S+ message_age=\S+/failing_interval=ttt message_age=ttt/;
- # Date/time in exim -bV output
- s/\d\d-[A-Z][a-z]{2}-\d{4}\s\d\d:\d\d:\d\d/07-Mar-2000 12:21:52/g;
- # Time on queue tolerance
- s/(QT|D)=1s/$1=0s/;
- # Eximstats heading
- s/Exim\sstatistics\sfrom\s\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\sto\s
- \d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Exim statistics from <time> to <time>/x;
- # Treat ECONNRESET the same as ECONNREFUSED. At least some systems give
- # us the former on a new connection.
- s/(could not connect to .*: Connection) reset by peer$/$1 refused/;
- # ======== TLS certificate algorithms ========
- # Test machines might have various different TLS library versions supporting
- # different protocols; can't rely upon TLS 1.2's AES256-GCM-SHA384, so we
- # treat the standard algorithms the same.
- # So far, have seen:
- # TLSv1:AES128-GCM-SHA256:128
- # TLSv1:AES256-SHA:256
- # TLSv1.1:AES256-SHA:256
- # TLSv1.2:AES256-GCM-SHA384:256
- # TLSv1.2:DHE-RSA-AES256-SHA:256
- # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
- # We also need to handle the ciphersuite without the TLS part present, for
- # client-ssl's output. We also see some older forced ciphersuites, but
- # negotiating TLS 1.2 instead of 1.0.
- # Mail headers (...), log-lines X=..., client-ssl output ...
- # (and \b doesn't match between ' ' and '(' )
- s/( (?: (?:\b|\s) [\(=] ) | \s )TLSv1\.[12]:/$1TLSv1:/xg;
- s/\bAES128-GCM-SHA256:128\b/AES256-SHA:256/g;
- s/\bAES128-GCM-SHA256\b/AES256-SHA/g;
- s/\bAES256-GCM-SHA384\b/AES256-SHA/g;
- s/\bDHE-RSA-AES256-SHA\b/AES256-SHA/g;
- # GnuTLS have seen:
- # TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256
- # TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128
- # TLS1.2:RSA_AES_256_CBC_SHA1:256 (canonical)
- # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
- #
- # X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256
- # X=TLS1.2:RSA_AES_256_CBC_SHA1:256
- # X=TLS1.1:RSA_AES_256_CBC_SHA1:256
- # X=TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256
- # and as stand-alone cipher:
- # ECDHE-RSA-AES256-SHA
- # DHE-RSA-AES256-SHA256
- # DHE-RSA-AES256-SHA
- # picking latter as canonical simply because regex easier that way.
- s/\bDHE_RSA_AES_128_CBC_SHA1:128/RSA_AES_256_CBC_SHA1:256/g;
- s/TLS1.[012]:((EC)?DHE_)?RSA_AES_(256|128)_(CBC|GCM)_SHA(1|256|384):(256|128)/TLS1.x:xxxxRSA_AES_256_CBC_SHAnnn:256/g;
- s/\b(ECDHE-RSA-AES256-SHA|DHE-RSA-AES256-SHA256)\b/AES256-SHA/g;
- # GnuTLS library error message changes
- s/No certificate was found/The peer did not send any certificate/g;
- #(dodgy test?) s/\(certificate verification failed\): invalid/\(gnutls_handshake\): The peer did not send any certificate./g;
- s/\(gnutls_priority_set\): No or insufficient priorities were set/\(gnutls_handshake\): Could not negotiate a supported cipher suite/g;
- # (this new one is a generic channel-read error, but the testsuite
- # only hits it in one place)
- s/TLS error on connection \(gnutls_handshake\): Error in the pull function\./a TLS session is required but an attempt to start TLS failed/g;
- # (replace old with new, hoping that old only happens in one situation)
- s/TLS error on connection to \d{1,3}(.\d{1,3}){3} \[\d{1,3}(.\d{1,3}){3}\] \(gnutls_handshake\): A TLS packet with unexpected length was received./a TLS session is required for ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4], but an attempt to start TLS failed/g;
- s/TLS error on connection from \[127.0.0.1\] \(recv\): A TLS packet with unexpected length was received./TLS error on connection from [127.0.0.1] (recv): The TLS connection was non-properly terminated./g;
- # signature algorithm names
- s/RSA-SHA1/RSA-SHA/;
- # ======== Caller's login, uid, gid, home, gecos ========
- s/\Q$parm_caller_home\E/CALLER_HOME/g; # NOTE: these must be done
- s/\b\Q$parm_caller\E\b/CALLER/g; # in this order!
- s/\b\Q$parm_caller_group\E\b/CALLER/g; # In case group name different
- s/\beuid=$parm_caller_uid\b/euid=CALLER_UID/g;
- s/\begid=$parm_caller_gid\b/egid=CALLER_GID/g;
- s/\buid=$parm_caller_uid\b/uid=CALLER_UID/g;
- s/\bgid=$parm_caller_gid\b/gid=CALLER_GID/g;
- s/\bname="?$parm_caller_gecos"?/name=CALLER_GECOS/g;
- # When looking at spool files with -Mvh, we will find not only the caller
- # login, but also the uid and gid. It seems that $) in some Perls gives all
- # the auxiliary gids as well, so don't bother checking for that.
- s/^CALLER $> \d+$/CALLER UID GID/;
- # There is one case where the caller's login is forced to something else,
- # in order to test the processing of logins that contain spaces. Weird what
- # some people do, isn't it?
- s/^spaced user $> \d+$/CALLER UID GID/;
- # ======== Exim's login ========
- # For messages received by the daemon, this is in the -H file, which some
- # tests inspect. For bounce messages, this will appear on the U= lines in
- # logs and also after Received: and in addresses. In one pipe test it appears
- # after "Running as:". It also appears in addresses, and in the names of lock
- # files.
- s/U=$parm_eximuser/U=EXIMUSER/;
- s/user=$parm_eximuser/user=EXIMUSER/;
- s/login=$parm_eximuser/login=EXIMUSER/;
- s/Received: from $parm_eximuser /Received: from EXIMUSER /;
- s/Running as: $parm_eximuser/Running as: EXIMUSER/;
- s/\b$parm_eximuser@/EXIMUSER@/;
- s/\b$parm_eximuser\.lock\./EXIMUSER.lock./;
- s/\beuid=$parm_exim_uid\b/euid=EXIM_UID/g;
- s/\begid=$parm_exim_gid\b/egid=EXIM_GID/g;
- s/\buid=$parm_exim_uid\b/uid=EXIM_UID/g;
- s/\bgid=$parm_exim_gid\b/gid=EXIM_GID/g;
- s/^$parm_eximuser $parm_exim_uid $parm_exim_gid/EXIMUSER EXIM_UID EXIM_GID/;
- # ======== General uids, gids, and pids ========
- # Note: this must come after munges for caller's and exim's uid/gid
- # These are for systems where long int is 64
- s/\buid=4294967295/uid=-1/;
- s/\beuid=4294967295/euid=-1/;
- s/\bgid=4294967295/gid=-1/;
- s/\begid=4294967295/egid=-1/;
- s/\bgid=\d+/gid=gggg/;
- s/\begid=\d+/egid=gggg/;
- s/\bpid=\d+/pid=pppp/;
- s/\buid=\d+/uid=uuuu/;
- s/\beuid=\d+/euid=uuuu/;
- s/set_process_info:\s+\d+/set_process_info: pppp/;
- s/queue run pid \d+/queue run pid ppppp/;
- s/process \d+ running as transport filter/process pppp running as transport filter/;
- s/process \d+ writing to transport filter/process pppp writing to transport filter/;
- s/reading pipe for subprocess \d+/reading pipe for subprocess pppp/;
- s/remote delivery process \d+ ended/remote delivery process pppp ended/;
- # Pid in temp file in appendfile transport
- s"test-mail/temp\.\d+\."test-mail/temp.pppp.";
- # Optional pid in log lines
- s/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)(\s[+-]\d\d\d\d|)(\s\[\d+\])/
- "$1$2 [" . new_value($3, "%s", \$next_pid) . "]"/gxe;
- # Detect a daemon stderr line with a pid and save the pid for subsequent
- # removal from following lines.
- $spid = $1 if /^(\s*\d+) (?:listening|LOG: MAIN|(?:daemon_smtp_port|local_interfaces) overridden by)/;
- s/^$spid //;
- # Queue runner waiting messages
- s/waiting for children of \d+/waiting for children of pppp/;
- s/waiting for (\S+) \(\d+\)/waiting for $1 (pppp)/;
- # ======== Port numbers ========
- # Incoming port numbers may vary, but not in daemon startup line.
- s/^Port: (\d+)/"Port: " . new_value($1, "%s", \$next_port)/e;
- s/\(port=(\d+)/"(port=" . new_value($1, "%s", \$next_port)/e;
- # This handles "connection from" and the like, when the port is given
- if (!/listening for SMTP on/ && !/Connecting to/ && !/=>/ && !/->/
- && !/\*>/ && !/Connection refused/)
- {
- s/\[([a-z\d:]+|\d+(?:\.\d+){3})\]:(\d+)/"[".$1."]:".new_value($2,"%s",\$next_port)/ie;
- }
- # Port in host address in spool file output from -Mvh
- s/^-host_address (.*)\.\d+/-host_address $1.9999/;
- # ======== Local IP addresses ========
- # The amount of space between "host" and the address in verification output
- # depends on the length of the host name. We therefore reduce it to one space
- # for all of them.
- # Also, the length of space at the end of the host line is dependent
- # on the length of the longest line, so strip it also on otherwise
- # un-rewritten lines like localhost
- s/^\s+host\s(\S+)\s+(\S+)/ host $1 $2/;
- s/^\s+(host\s\S+\s\S+)\s+(port=.*)/ host $1 $2/;
- s/^\s+(host\s\S+\s\S+)\s+(?=MX=)/ $1 /;
- s/^\s+host\s.*?\K\s+(ad=\S+)/ $1/;
- s/host\s\Q$parm_ipv4\E\s\[\Q$parm_ipv4\E\]/host ipv4.ipv4.ipv4.ipv4 [ipv4.ipv4.ipv4.ipv4]/;
- s/host\s\Q$parm_ipv6\E\s\[\Q$parm_ipv6\E\]/host ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6 [ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6]/;
- s/\b\Q$parm_ipv4\E\b/ip4.ip4.ip4.ip4/g;
- s/(^|\W)\K\Q$parm_ipv6\E/ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6/g;
- s/\b\Q$parm_ipv4r\E\b/ip4-reverse/g;
- s/(^|\W)\K\Q$parm_ipv6r\E/ip6-reverse/g;
- s/^(\s+host\s\S+\s+\[\S+\]) +$/$1 /;
- # ======== Test network IP addresses ========
- s/(\b|_)\Q$parm_ipv4_test_net\E(?=\.\d+\.\d+\.\d+\b|_|\.rbl|\.in-addr|\.test\.again\.dns)/$1V4NET/g;
- s/\b\Q$parm_ipv6_test_net\E(?=:[\da-f]+:[\da-f]+:[\da-f]+)/V6NET/gi;
- # ======== IP error numbers and messages ========
- # These vary between operating systems
- s/Can't assign requested address/Network Error/;
- s/Cannot assign requested address/Network Error/;
- s/Operation timed out/Connection timed out/;
- s/Address family not supported by protocol family/Network Error/;
- s/Network is unreachable/Network Error/;
- s/Invalid argument/Network Error/;
- s/\(\d+\): Network/(dd): Network/;
- s/\(\d+\): Connection refused/(dd): Connection refused/;
- s/\(\d+\): Connection timed out/(dd): Connection timed out/;
- s/\d+ 65 Connection refused/dd 65 Connection refused/;
- s/\d+ 321 Connection timed out/dd 321 Connection timed out/;
- # ======== Other error numbers ========
- s/errno=\d+/errno=dd/g;
- # ======== System Error Messages ======
- # depending on the underlaying file system the error message seems to differ
- s/(?: is not a regular file)|(?: has too many links \(\d+\))/ not a regular file or too many links/;
- # ======== Output from ls ========
- # Different operating systems use different spacing on long output
- #s/ +/ /g if /^[-rwd]{10} /;
- # (Bug 1226) SUSv3 allows a trailing printable char for modified access method control.
- # Handle only the Gnu and MacOS space, dot, plus and at-sign. A full [[:graph:]]
- # unfortunately matches a non-ls linefull of dashes.
- # Allow the case where we've already picked out the file protection bits.
- if (s/^([-d](?:[-r][-w][-SsTtx]){3})[.+@]?( +|$)/$1$2/) {
- s/ +/ /g;
- }
- # ======== Message sizes =========
- # Message sizes vary, owing to different logins and host names that get
- # automatically inserted. I can't think of any way of even approximately
- # comparing these.
- s/([\s,])S=\d+\b/$1S=sss/;
- s/:S\d+\b/:Ssss/;
- s/^(\s*\d+m\s+)\d+(\s+[a-z0-9-]{16} <)/$1sss$2/i if $is_stdout;
- s/\sSIZE=\d+\b/ SIZE=ssss/;
- s/\ssize=\d+\b/ size=sss/ if $is_stderr;
- s/old size = \d+\b/old size = sssss/;
- s/message size = \d+\b/message size = sss/;
- s/this message = \d+\b/this message = sss/;
- s/Size of headers = \d+/Size of headers = sss/;
- s/sum=(?!0)\d+/sum=dddd/;
- s/(?<=sum=dddd )count=\d+\b/count=dd/;
- s/(?<=sum=0 )count=\d+\b/count=dd/;
- s/,S is \d+\b/,S is ddddd/;
- s/\+0100,\d+;/+0100,ddd;/;
- s/\(\d+ bytes written\)/(ddd bytes written)/;
- s/added '\d+ 1'/added 'ddd 1'/;
- s/Received\s+\d+/Received nnn/;
- s/Delivered\s+\d+/Delivered nnn/;
- # ======== Values in spool space failure message ========
- s/space=\d+ inodes=[+-]?\d+/space=xxxxx inodes=xxxxx/;
- # ======== Filter sizes ========
- # The sizes of filter files may vary because of the substitution of local
- # filenames, logins, etc.
- s/^\d+(?= bytes read from )/ssss/;
- # ======== OpenSSL error messages ========
- # Different releases of the OpenSSL libraries seem to give different error
- # numbers, or handle specific bad conditions in different ways, leading to
- # different wording in the error messages, so we cannot compare them.
- s/(TLS error on connection (?:from .* )?\(SSL_\w+\): error:)(.*)/$1 <<detail omitted>>/;
- # ======== Maildir things ========
- # timestamp output in maildir processing
- s/(timestamp=|\(timestamp_only\): )\d+/$1ddddddd/g;
- # maildir delivery files appearing in log lines (in cases of error)
- s/writing to(?: file)? tmp\/\d+\.[^.]+\.(\S+)/writing to tmp\/MAILDIR.$1/;
- s/renamed tmp\/\d+\.[^.]+\.(\S+) as new\/\d+\.[^.]+\.(\S+)/renamed tmp\/MAILDIR.$1 as new\/MAILDIR.$1/;
- # Maildir file names in general
- s/\b\d+\.H\d+P\d+\b/dddddddddd.HddddddPddddd/;
- # Maildirsize data
- while (/^\d+S,\d+C\s*$/)
- {
- print MUNGED;
- while (<IN>)
- {
- last if !/^\d+ \d+\s*$/;
- print MUNGED "ddd d\n";
- }
- last if !defined $_;
- }
- last if !defined $_;
- # ======== Output from the "fd" program about open descriptors ========
- # The statuses seem to be different on different operating systems, but
- # at least we'll still be checking the number of open fd's.
- s/max fd = \d+/max fd = dddd/;
- s/status=0 RDONLY/STATUS/g;
- s/status=1 WRONLY/STATUS/g;
- s/status=2 RDWR/STATUS/g;
- # ======== Contents of spool files ========
- # A couple of tests dump the contents of the -H file. The length fields
- # will be wrong because of different user names, etc.
- s/^\d\d\d(?=[PFS*])/ddd/;
- # ========= Exim lookups ==================
- # Lookups have a char which depends on the number of lookup types compiled in,
- # in stderr output. Replace with a "0". Recognising this while avoiding
- # other output is fragile; perhaps the debug output should be revised instead.
- s%(?<!sqlite)(?<!lsearch\*@)(?<!lsearch\*)(?<!lsearch)[0-?]TESTSUITE/aux-fixed/%0TESTSUITE/aux-fixed/%g;
- # ==========================================================
- # MIME boundaries in RFC3461 DSN messages
- s/\d{8,10}-eximdsn-\d+/NNNNNNNNNN-eximdsn-MMMMMMMMMM/;
- # ==========================================================
- # Some munging is specific to the specific file types
- # ======== stdout ========
- if ($is_stdout)
- {
- # Skip translate_ip_address and use_classresources in -bP output because
- # they aren't always there.
- next if /translate_ip_address =/;
- next if /use_classresources/;
- # In certain filter tests, remove initial filter lines because they just
- # clog up by repetition.
- if ($rmfiltertest)
- {
- next if /^(Sender\staken\sfrom|
- Return-path\scopied\sfrom|
- Sender\s+=|
- Recipient\s+=)/x;
- if (/^Testing \S+ filter/)
- {
- $_ = <IN>; # remove blank line
- next;
- }
- }
- # openssl version variances
- next if /^SSL info: unknown state/;
- next if /^SSL info: SSLv2\/v3 write client hello A/;
- next if /^SSL info: SSLv3 read server key exchange A/;
- }
- # ======== stderr ========
- elsif ($is_stderr)
- {
- # The very first line of debugging output will vary
- s/^Exim version .*/Exim version x.yz ..../;
- # Debugging lines for Exim terminations
- s/(?<=^>>>>>>>>>>>>>>>> Exim pid=)\d+(?= terminating)/pppp/;
- # IP address lookups use gethostbyname() when IPv6 is not supported,
- # and gethostbyname2() or getipnodebyname() when it is.
- s/\bgethostbyname2?|\bgetipnodebyname/get[host|ipnode]byname[2]/;
- # drop gnutls version strings
- next if /GnuTLS compile-time version: \d+[\.\d]+$/;
- next if /GnuTLS runtime version: \d+[\.\d]+$/;
- # drop openssl version strings
- next if /OpenSSL compile-time version: OpenSSL \d+[\.\da-z]+/;
- next if /OpenSSL runtime version: OpenSSL \d+[\.\da-z]+/;
- # drop lookups
- next if /^Lookups \(built-in\):/;
- next if /^Loading lookup modules from/;
- next if /^Loaded \d+ lookup modules/;
- next if /^Total \d+ lookups/;
- # drop compiler information
- next if /^Compiler:/;
- # and the ugly bit
- # different libraries will have different numbers (possibly 0) of follow-up
- # lines, indenting with more data
- if (/^Library version:/) {
- while (1) {
- $_ = <IN>;
- next if /^\s/;
- goto RESET_AFTER_EXTRA_LINE_READ;
- }
- }
- # drop other build-time controls emitted for debugging
- next if /^WHITELIST_D_MACROS:/;
- next if /^TRUSTED_CONFIG_LIST:/;
- # As of Exim 4.74, we log when a setgid fails; because we invoke Exim
- # with -be, privileges will have been dropped, so this will always
- # be the case
- next if /^changing group to \d+ failed: (Operation not permitted|Not owner)/;
- # We might not keep this check; rather than change all the tests, just
- # ignore it as long as it succeeds; then we only need to change the
- # TLS tests where tls_require_ciphers has been set.
- if (m{^changed uid/gid: calling tls_validate_require_cipher}) {
- my $discard = <IN>;
- next;
- }
- next if /^tls_validate_require_cipher child \d+ ended: status=0x0/;
- # We invoke Exim with -D, so we hit this new messag as of Exim 4.73:
- next if /^macros_trusted overridden to true by whitelisting/;
- # We have to omit the localhost ::1 address so that all is well in
- # the IPv4-only case.
- print MUNGED "MUNGED: ::1 will be omitted in what follows\n"
- if (/looked up these IP addresses/);
- next if /name=localhost address=::1/;
- # drop pdkim debugging header
- next if /^PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+$/;
- # Various other IPv6 lines must be omitted too
- next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
- next if /get\[host\|ipnode\]byname\[2\]\(af=inet6\)/;
- next if /DNS lookup of \S+ \(AAAA\) using fakens/;
- next if / in dns_ipv4_lookup?/;
- if (/DNS lookup of \S+ \(AAAA\) gave NO_DATA/)
- {
- $_= <IN>; # Gets "returning DNS_NODATA"
- next;
- }
- # Skip tls_advertise_hosts and hosts_require_tls checks when the options
- # are unset, because tls ain't always there.
- next if /in\s(?:tls_advertise_hosts\?|hosts_require_tls\?)
- \sno\s\(option\sunset\)/x;
- # Skip auxiliary group lists because they will vary.
- next if /auxiliary group list:/;
- # Skip "extracted from gecos field" because the gecos field varies
- next if /extracted from gecos field/;
- # Skip "waiting for data on socket" and "read response data: size=" lines
- # because some systems pack more stuff into packets than others.
- next if /waiting for data on socket/;
- next if /read response data: size=/;
- # If Exim is compiled with readline support but it can't find the library
- # to load, there will be an extra debug line. Omit it.
- next if /failed to load readline:/;
- # Some DBM libraries seem to make DBM files on opening with O_RDWR without
- # O_CREAT; other's don't. In the latter case there is some debugging output
- # which is not present in the former. Skip the relevant lines (there are
- # two of them).
- if (/TESTSUITE\/spool\/db\/\S+ appears not to exist: trying to create/)
- {
- $_ = <IN>;
- next;
- }
- # Some tests turn on +expand debugging to check on expansions.
- # Unfortunately, the Received: expansion varies, depending on whether TLS
- # is compiled or not. So we must remove the relevant debugging if it is.
- if (/^condition: def:tls_cipher/)
- {
- while (<IN>) { last if /^condition: def:sender_address/; }
- }
- elsif (/^expanding: Received: /)
- {
- while (<IN>) { last if !/^\s/; }
- }
- # When Exim is checking the size of directories for maildir, it uses
- # the check_dir_size() function to scan directories. Of course, the order
- # of the files that are obtained using readdir() varies from system to
- # system. We therefore buffer up debugging lines from check_dir_size()
- # and sort them before outputting them.
- if (/^check_dir_size:/ || /^skipping TESTSUITE\/test-mail\//)
- {
- push @saved, $_;
- }
- else
- {
- if (@saved > 0)
- {
- print MUNGED "MUNGED: the check_dir_size lines have been sorted " .
- "to ensure consistency\n";
- @saved = sort(@saved);
- print MUNGED @saved;
- @saved = ();
- }
- # Skip hosts_require_dane checks when the options
- # are unset, because dane ain't always there.
- next if /in\shosts_require_dane\?\sno\s\(option\sunset\)/x;
- # Experimental_International
- next if / in smtputf8_advertise_hosts\? no \(option unset\)/;
- # Skip some lines that Exim puts out at the start of debugging output
- # because they will be different in different binaries.
- print MUNGED
- unless (/^Berkeley DB: / ||
- /^Probably (?:Berkeley DB|ndbm|GDBM)/ ||
- /^Authenticators:/ ||
- /^Lookups:/ ||
- /^Support for:/ ||
- /^Routers:/ ||
- /^Transports:/ ||
- /^log selectors =/ ||
- /^cwd=/ ||
- /^Fixed never_users:/ ||
- /^Size of off_t:/
- );
- }
- next;
- }
- # ======== log ========
- elsif ($is_log)
- {
- # Berkeley DB version differences
- next if / Berkeley DB error: /;
- }
- # ======== All files other than stderr ========
- print MUNGED;
- }
- close(IN);
- return $yield;
- }
- ##################################################
- # Subroutine to interact with caller #
- ##################################################
- # Arguments: [0] the prompt string
- # [1] if there is a U in the prompt and $force_update is true
- # [2] if there is a C in the prompt and $force_continue is true
- # Returns: returns the answer
- sub interact{
- print $_[0];
- if ($_[1]) { $_ = "u"; print "... update forced\n"; }
- elsif ($_[2]) { $_ = "c"; print "... continue forced\n"; }
- else { $_ = <T>; }
- }
- ##################################################
- # Subroutine to log in force_continue mode #
- ##################################################
- # In force_continue mode, we just want a terse output to a statically
- # named logfile. If multiple files in same batch (stdout, stderr, etc)
- # all have mismatches, it will log multiple times.
- #
- # Arguments: [0] the logfile to append to
- # [1] the testno that failed
- # Returns: nothing
- sub log_failure {
- my $logfile = shift();
- my $testno = shift();
- my $detail = shift() || '';
- if ( open(my $fh, ">>", $logfile) ) {
- print $fh "Test $testno $detail failed\n";
- close $fh;
- }
- }
- ##################################################
- # Subroutine to compare one output file #
- ##################################################
- # When an Exim server is part of the test, its output is in separate files from
- # an Exim client. The server data is concatenated with the client data as part
- # of the munging operation.
- #
- # Arguments: [0] the name of the main raw output file
- # [1] the name of the server raw output file or undef
- # [2] where to put the munged copy
- # [3] the name of the saved file
- # [4] TRUE if this is a log file whose deliveries must be sorted
- # [5] optionally, a custom munge command
- #
- # Returns: 0 comparison succeeded or differences to be ignored
- # 1 comparison failed; files may have been updated (=> re-compare)
- #
- # Does not return if the user replies "Q" to a prompt.
- sub check_file{
- my($rf,$rsf,$mf,$sf,$sortfile,$extra) = @_;
- # If there is no saved file, the raw files must either not exist, or be
- # empty. The test ! -s is TRUE if the file does not exist or is empty.
- # we check if there is a flavour specific file, but we remember
- # the original file name as "generic"
- $sf_generic = $sf;
- $sf_flavour = "$sf_generic.$flavour";
- $sf_current = -e $sf_flavour ? $sf_flavour : $sf_generic;
- if (! -e $sf_current)
- {
- return 0 if (! -s $rf && (! defined $rsf || ! -s $rsf));
- print "\n";
- print "** $rf is not empty\n" if (-s $rf);
- print "** $rsf is not empty\n" if (defined $rsf && -s $rsf);
- for (;;)
- {
- print "Continue, Show, or Quit? [Q] ";
- $_ = $force_continue ? "c" : <T>;
- tests_exit(1) if /^q?$/i;
- log_failure($log_failed_filename, $testno, $rf) if (/^c$/i && $force_continue);
- return 0 if /^c$/i;
- last if (/^s$/);
- }
- foreach $f ($rf, $rsf)
- {
- if (defined $f && -s $f)
- {
- print "\n";
- print "------------ $f -----------\n"
- if (defined $rf && -s $rf && defined $rsf && -s $rsf);
- system("$more '$f'");
- }
- }
- print "\n";
- for (;;)
- {
- interact("Continue, Update & retry, Quit? [Q] ", $force_update, $force_continue);
- tests_exit(1) if /^q?$/i;
- log_failure($log_failed_filename, $testno, $rsf) if (/^c$/i && $force_continue);
- return 0 if /^c$/i;
- last if (/^u$/i);
- }
- }
- #### $_
- # Control reaches here if either (a) there is a saved file ($sf), or (b) there
- # was a request to create a saved file. First, create the munged file from any
- # data that does exist.
- open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
- my($truncated) = munge($rf, $extra) if -e $rf;
- if (defined $rsf && -e $rsf)
- {
- print MUNGED "\n******** SERVER ********\n";
- $truncated |= munge($rsf, $extra);
- }
- close(MUNGED);
- # If a saved file exists, do the comparison. There are two awkward cases:
- #
- # If "*** truncated ***" was found in the new file, it means that a log line
- # was overlong, and truncated. The problem is that it may be truncated at
- # different points on different systems, because of different user name
- # lengths. We reload the file and the saved file, and remove lines from the new
- # file that precede "*** truncated ***" until we reach one that matches the
- # line that precedes it in the saved file.
- #
- # If $sortfile is set, we are dealing with a mainlog file where the deliveries
- # for an individual message might vary in their order from system to system, as
- # a result of parallel deliveries. We load the munged file and sort sequences
- # of delivery lines.
- if (-e $sf_current)
- {
- # Deal with truncated text items
- if ($truncated)
- {
- my(@munged, @saved, $i, $j, $k);
- open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
- @munged = <MUNGED>;
- close(MUNGED);
- open(SAVED, $sf_current) || tests_exit(-1, "Failed to open $sf_current: $!");
- @saved = <SAVED>;
- close(SAVED);
- $j = 0;
- for ($i = 0; $i < @munged; $i++)
- {
- if ($munged[$i] =~ /\*\*\* truncated \*\*\*/)
- {
- for (; $j < @saved; $j++)
- { last if $saved[$j] =~ /\*\*\* truncated \*\*\*/; }
- last if $j >= @saved; # not found in saved
- for ($k = $i - 1; $k >= 0; $k--)
- { last if $munged[$k] eq $saved[$j - 1]; }
- last if $k <= 0; # failed to find previous match
- splice @munged, $k + 1, $i - $k - 1;
- $i = $k + 1;
- }
- }
- open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
- for ($i = 0; $i < @munged; $i++)
- { print MUNGED $munged[$i]; }
- close(MUNGED);
- }
- # Deal with log sorting
- if ($sortfile)
- {
- my(@munged, $i, $j);
- open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
- @munged = <MUNGED>;
- close(MUNGED);
- for ($i = 0; $i < @munged; $i++)
- {
- if ($munged[$i] =~ /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/)
- {
- for ($j = $i + 1; $j < @munged; $j++)
- {
- last if $munged[$j] !~
- /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/;
- }
- @temp = splice(@munged, $i, $j - $i);
- @temp = sort(@temp);
- splice(@munged, $i, 0, @temp);
- }
- }
- open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
- print MUNGED "**NOTE: The delivery lines in this file have been sorted.\n";
- for ($i = 0; $i < @munged; $i++)
- { print MUNGED $munged[$i]; }
- close(MUNGED);
- }
- # Do the comparison
- return 0 if (system("$cf '$mf' '$sf_current' >test-cf") == 0);
- # Handle comparison failure
- print "** Comparison of $mf with $sf_current failed";
- system("$more test-cf");
- print "\n";
- for (;;)
- {
- interact("Continue, Retry, Update current"
- . ($sf_current ne $sf_flavour ? "/Save for flavour '$flavour'" : "")
- . " & retry, Quit? [Q] ", $force_update, $force_continue);
- tests_exit(1) if /^q?$/i;
- log_failure($log_failed_filename, $testno, $sf_current) if (/^c$/i && $force_continue);
- return 0 if /^c$/i;
- return 1 if /^r$/i;
- last if (/^[us]$/i);
- }
- }
- # Update or delete the saved file, and give the appropriate return code.
- if (-s $mf)
- {
- my $sf = /^u/i ? $sf_current : $sf_flavour;
- tests_exit(-1, "Failed to cp $mf $sf") if system("cp '$mf' '$sf'") != 0;
- }
- else
- {
- # if we deal with a flavour file, we can't delete it, because next time the generic
- # file would be used again
- if ($sf_current eq $sf_flavour) {
- open(FOO, ">$sf_current");
- close(FOO);
- }
- else {
- tests_exit(-1, "Failed to unlink $sf_current") if !unlink($sf_current);
- }
- }
- return 1;
- }
- ##################################################
- # Custom munges
- # keyed by name of munge; value is a ref to a hash
- # which is keyed by file, value a string to look for.
- # Usable files are:
- # paniclog, rejectlog, mainlog, stdout, stderr, msglog, mail
- # Search strings starting with 's' do substitutions;
- # with '/' do line-skips.
- # Triggered by a scriptfile line "munge <name>"
- ##################################################
- $munges =
- { 'dnssec' =>
- { 'stderr' => '/^Reverse DNS security status: unverified\n/' },
- 'gnutls_unexpected' =>
- { 'mainlog' => '/\(recv\): A TLS packet with unexpected length was received./' },
- 'gnutls_handshake' =>
- { 'mainlog' => 's/\(gnutls_handshake\): Error in the push function/\(gnutls_handshake\): A TLS packet with unexpected length was received/' },
- 'optional_events' =>
- { 'stdout' => '/event_action =/' },
- 'optional_ocsp' =>
- { 'stderr' => '/127.0.0.1 in hosts_requ(ire|est)_ocsp/' },
- 'no_tpt_filter_epipe' =>
- { 'stderr' => '/^writing error 32: Broken pipe$/' },
- 'optional_cert_hostnames' =>
- { 'stderr' => '/in tls_verify_cert_hostnames\? no/' },
- 'loopback' =>
- { 'stdout' => 's/[[](127\.0\.0\.1|::1)]/[IP_LOOPBACK_ADDR]/' },
- 'scanfile_size' =>
- { 'stdout' => 's/(Content-length:) \d\d\d/$1 ddd/' },
- 'delay_1500' =>
- { 'stderr' => 's/(1[5-9]|23\d)\d\d msec/ssss msec/' },
- };
- ##################################################
- # Subroutine to check the output of a test #
- ##################################################
- # This function is called when the series of subtests is complete. It makes
- # use of check_file(), whose arguments are:
- #
- # [0] the name of the main raw output file
- # [1] the name of the server raw output file or undef
- # [2] where to put the munged copy
- # [3] the name of the saved file
- # [4] TRUE if this is a log file whose deliveries must be sorted
- # [5] an optional custom munge command
- #
- # Arguments: Optionally, name of a single custom munge to run.
- # Returns: 0 if the output compared equal
- # 1 if re-run needed (files may have been updated)
- sub check_output{
- my($mungename) = $_[0];
- my($yield) = 0;
- my($munge) = $munges->{$mungename} if defined $mungename;
- $yield = 1 if check_file("spool/log/paniclog",
- "spool/log/serverpaniclog",
- "test-paniclog-munged",
- "paniclog/$testno", 0,
- $munge->{'paniclog'});
- $yield = 1 if check_file("spool/log/rejectlog",
- "spool/log/serverrejectlog",
- "test-rejectlog-munged",
- "rejectlog/$testno", 0,
- $munge->{'rejectlog'});
- $yield = 1 if check_file("spool/log/mainlog",
- "spool/log/servermainlog",
- "test-mainlog-munged",
- "log/$testno", $sortlog,
- $munge->{'mainlog'});
- if (!$stdout_skip)
- {
- $yield = 1 if check_file("test-stdout",
- "test-stdout-server",
- "test-stdout-munged",
- "stdout/$testno", 0,
- $munge->{'stdout'});
- }
- if (!$stderr_skip)
- {
- $yield = 1 if check_file("test-stderr",
- "test-stderr-server",
- "test-stderr-munged",
- "stderr/$testno", 0,
- $munge->{'stderr'});
- }
- # Compare any delivered messages, unless this test is skipped.
- if (! $message_skip)
- {
- my($msgno) = 0;
- # Get a list of expected mailbox files for this script. We don't bother with
- # directories, just the files within them.
- foreach $oldmail (@oldmails)
- {
- next unless $oldmail =~ /^mail\/$testno\./;
- print ">> EXPECT $oldmail\n" if $debug;
- $expected_mails{$oldmail} = 1;
- }
- # If there are any files in test-mail, compare them. Note that "." and
- # ".." are automatically omitted by list_files_below().
- @mails = list_files_below("test-mail");
- foreach $mail (@mails)
- {
- next if $mail eq "test-mail/oncelog";
- $saved_mail = substr($mail, 10); # Remove "test-mail/"
- $saved_mail =~ s/^$parm_caller(\/|$)/CALLER/; # Convert caller name
- if ($saved_mail =~ /(\d+\.[^.]+\.)/)
- {
- $msgno++;
- $saved_mail =~ s/(\d+\.[^.]+\.)/$msgno./gx;
- }
- …
Large files files are truncated, but you can click here to view the full file