DKIM: fix build with older GnuTLS
[exim.git] / test / runtest
index c590ffc3189ca7bc9f6552097920466547b45fe6..f595634e9622b589f699e787bdb62a5c42990fb7 100755 (executable)
@@ -29,10 +29,11 @@ use File::Basename;
 use Pod::Usage;
 use Getopt::Long;
 use FindBin qw'$RealBin';
+use File::Copy;
 
 use lib "$RealBin/lib";
 use Exim::Runtest;
-use Exim::Utils qw(uniq numerically);
+use Exim::Utils qw(uniq numerically cp);
 
 use if $ENV{DEBUG} && scalar($ENV{DEBUG} =~ /\bruntest\b/) => 'Smart::Comments' => '####';
 use if $ENV{DEBUG} && scalar($ENV{DEBUG} =~ /\bruntest\b/) => 'Data::Dumper';
@@ -404,7 +405,7 @@ RESET_AFTER_EXTRA_LINE_READ:
 
   # 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;
+  #s/Exim \K\d+[._]\d+[\w_-]*/x.yz/i;
 
   # Replace Exim message ids by a unique series
   s/((?:[^\W_]{6}-){2}[^\W_]{2})
@@ -598,11 +599,13 @@ RESET_AFTER_EXTRA_LINE_READ:
   # LibreSSL
   # TLSv1:AES256-GCM-SHA384:256
   # TLSv1:ECDHE-RSA-CHACHA20-POLY1305:256
+  # TLS1.3:AEAD-AES256-GCM-SHA384:256
   #
   # ECDHE-RSA-CHACHA20-POLY1305
   # AES256-GCM-SHA384
 
   s/(?<!-)(AES256-GCM-SHA384)/RSA-$1/;
+  s/AEAD-(AES256-GCM-SHA384)/RSA-$1/g;
   s/(?<!ke-)((EC)?DHE-)?(RSA|ECDSA)-(AES256|CHACHA20)-(GCM-SHA384|POLY1305)(?!:)/ke-$3-AES256-SHAnnn/g;
   s/(?<!ke-)((EC)?DHE-)?(RSA|ECDSA)-(AES256|CHACHA20)-(GCM-SHA384|POLY1305):256/ke-$3-AES256-SHAnnn:xxx/g;
 
@@ -738,18 +741,17 @@ RESET_AFTER_EXTRA_LINE_READ:
 
   s/\bgid=\d+/gid=gggg/;
   s/\begid=\d+/egid=gggg/;
-  s/\b(pid=|PID: )\d+/$1pppp/;
+  s/\b(pid=|pid |PID: )\d+/$1pppp/;
   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.";
+  s"test-mail/(subdir/)?temp\K\.\d+\.".pppp.";
 
   # Optional pid in log lines
   s/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)(\.\d{3}|)(\s[+-]\d{4}|)(\s\[\d+\])/
@@ -780,7 +782,7 @@ RESET_AFTER_EXTRA_LINE_READ:
 
   # This handles "connection from" and the like, when the port is given
   if (!/listening for SMTP on/ && !/Connecting to/ && !/=>/ && !/->/
-      && !/\*>/ && !/Connection refused/)
+      && !/\*>/&& !/==/  && !/\*\*/ && !/Connection refused/ && !/in response to/)
     {
     s/\[([a-z\d:]+|\d+(?:\.\d+){3})\]:(\d+)/"[".$1."]:".new_value($2,"%s",\$next_port)/ie;
     }
@@ -827,11 +829,10 @@ RESET_AFTER_EXTRA_LINE_READ:
 
   # ======== 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/Can(no|')t 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/Network( is)? unreachable/Network Error/;
   s/Invalid argument/Network Error/;
 
   s/\(\d+\): Network/(dd): Network/;
@@ -917,7 +918,7 @@ RESET_AFTER_EXTRA_LINE_READ:
   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/;
+  s/\b\d+\.M\d+P\d+\b/dddddddddd.HddddddPddddd/;
 
   # Maildirsize data
   while (/^\d+S,\d+C\s*$/)
@@ -935,7 +936,7 @@ RESET_AFTER_EXTRA_LINE_READ:
 
   # SRS timestamps and signatures vary by hostname and from run to run
 
-  s/SRS0=....=..=[^=]+=[^@]+\@test.ex/SRS0=ZZZZ=YY=the.local.host.name=CALLER\@test.ex/;
+  s/(?i)SRS0=....=.[^=]?=([^=]+)=([^@]+)\@([^ ]+)/SRS0=ZZZZ=YY=$1=$2\@$3/g;
 
 
   # ======== Output from the "fd" program about open descriptors ========
@@ -952,12 +953,6 @@ RESET_AFTER_EXTRA_LINE_READ:
   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/;
@@ -1014,7 +1009,8 @@ RESET_AFTER_EXTRA_LINE_READ:
     s/conversion: german.xn--strae-oqa.de/conversion: german.straße.de/;
 
     # subsecond timstamp info in reported header-files
-    s/^(-received_time_usec \.)\d{6}$/$1uuuuuu/;
+    s/^-received_time_usec \.\K\d{6}$/uuuuuu/;
+    s/^-received_time_complete \K\d+\.\d{6}$/tttt.uuuuuu/;
 
     # Postgres server takes varible time to shut down; lives in various places
     s/^waiting for server to shut down\.+ done$/waiting for server to shut down.... done/;
@@ -1026,9 +1022,15 @@ RESET_AFTER_EXTRA_LINE_READ:
     # ARC is not always supported by the build
     next if /^arc_sign =/;
 
+    # LIMITS is not always supported by the build
+    next if /^limits_advertise_hosts =/;
+
     # TLS resumption is not always supported by the build
     next if /^tls_resumption_hosts =/;
     next if /^-tls_resumption/;
+
+    # gsasl library version may not support some methods
+    s/250-AUTH ANONYMOUS PLAIN SCRAM-SHA-1\K SCRAM-SHA-256//;
     }
 
   # ======== stderr ========
@@ -1044,15 +1046,25 @@ RESET_AFTER_EXTRA_LINE_READ:
     s/(?<=^>>>>>>>>>>>>>>>> Exim pid=)\d+(?= terminating)/pppp/;
     s/^(proxy-proc \w{5}-pid) \d+$/$1 pppp/;
     s/^(?:\s*\d+ )(exec .* -oPX)$/pppp $1/;
+    next if /(?:postfork: | fork(?:ing|ed) for )/;
 
     # IP address lookups use gethostbyname() when IPv6 is not supported,
     # and gethostbyname2() or getipnodebyname() when it is.
 
     s/\b(gethostbyname2?|\bgetipnodebyname)(\(af=inet\))?/get[host|ipnode]byname[2]/;
 
+    # Extra lookups done when ipv6 is supported
+    next if /^host_fake_gethostbyname\(af=inet6\) returned 1 \(HOST_NOT_FOUND\)$/;
+
     # we don't care what TZ enviroment the testhost was running
     next if /^Reset TZ to/;
 
+    # ========= 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%^\s+(:?closing )?\K[0-?]TESTSUITE/aux-fixed/%0TESTSUITE/aux-fixed/%g;
+
     # drop gnutls version strings
     next if /GnuTLS compile-time version: \d+[\.\d]+$/;
     next if /GnuTLS runtime version: \d+[\.\d]+$/;
@@ -1063,6 +1075,42 @@ RESET_AFTER_EXTRA_LINE_READ:
 
     # this is timing-dependent
     next if /^OpenSSL: creating STEK$/;
+    next if /^selfsign cert rotate$/;
+
+    # TLS preload
+    # only OpenSSL speaks of these
+    next if /^TLS: (preloading (DH params|ECDH curve|CA bundle) for server|generating selfsigned server cert)/;
+    next if /^Diffie-Hellman initialized from default/;
+    next if /^ECDH OpenSSL (< )?[\d.+]+: temp key parameter settings:/;
+    next if /^ECDH: .*'prime256v1'/;
+    next if /^tls_verify_certificates: system$/;
+    next if /^tls_set_watch: .*\/cert.pem/;
+    next if /^Generating 2048 bit RSA key/;
+
+    # TLS preload
+    # only GnuTLS speaks of these
+    next if /^GnuTLS global init required$/;
+    next if /^TLS: basic cred init, server/;
+    next if /^TLS: preloading cipher list for server: NULL$/;
+    s/^GnuTLS using default session cipher\/priority "NORMAL"$/TLS: not preloading cipher list for server/;
+    next if /^GnuTLS<2>: added \d+ protocols, \d+ ciphersuites, \d+ sig algos and \d+ groups into priority list$/;
+    next if /^GnuTLS<2>: (Disabling X.509 extensions|signing structure using RSA-SHA256)/;
+    next if /^GnuTLS.*(wrap_nettle_mpi_print|gnutls_subject_alt_names_get|get_alt_name)/;
+    next if /^GnuTLS<[23]>: (p11|ASSERT: pkcs11.c|Initializing needed PKCS #11 modules)/;
+    next if /^GnuTLS<2>: Intel (AES|GCM) accelerator was detected/;
+    next if /^Added \d{3} certificate authorities/;
+    next if /^TLS: not preloading CRL for server/;
+
+    # only kevent platforms (FreeBSD, OpenBSD) say this
+    next if /^watch dir/;
+    next if /^watch file .*\/usr\/local/;
+    next if /^watch file .*\/etc\/ssl/;
+
+    # TLS preload
+    # there happen in different orders for OpenSSL/GnuTLS/noTLS
+    next if /^TLS: generating selfsigned server cert/;
+    next if /^TLS: not preloading (CA bundle|cipher list) for server$/;
+    next if /^TLS: not preloading server certs$/;
 
     # drop lookups
     next if /^Lookups \(built-in\):/;
@@ -1115,6 +1163,8 @@ RESET_AFTER_EXTRA_LINE_READ:
     # drop pdkim debugging header
     next if /^DKIM( <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+|: no signatures)$/;
 
+    # Some platforms have TIOCOUTome do not
+    next if /\d+ bytes remain in socket output buffer$/;
     # Various other IPv6 lines must be omitted too
 
     next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
@@ -1130,14 +1180,16 @@ RESET_AFTER_EXTRA_LINE_READ:
       next;
       }
 
-    # Non-TLS bulds have a different Recieved: header expansion
-    s/^((.*)\t}}}}by \$primary_hostname \$\{if def:received_protocol \{with \$received_protocol }})\(Exim \$version_number\)$/$1\${if def:tls_in_cipher_std { tls \$tls_in_cipher_std\n$2\t}}(Exim \$version_number)/;
-    s/^((\s*).*considering: with \$received_protocol }})\(Exim \$version_number\)$/$1\${if def:tls_in_cipher_std { tls \$tls_in_cipher_std\n$2\t}}(Exim \$version_number)/;
-    if (/condition: def:tls_in_cipher_std$/)
+    # Non-TLS builds have a different default Recieved: header expansion
+    s/^((.*)\t}}}}by \$primary_hostname \$\{if def:received_protocol \{with \$received_protocol }})\(Exim \$version_number\)$/$1\${if def:tls_in_ver        { (\$tls_in_ver)}}\${if def:tls_in_cipher_std { tls \$tls_in_cipher_std\n$2\t}}(Exim \$version_number)/;
+    s/^((\s*).*considering: with \$received_protocol }})\(Exim \$version_number\)$/$1\${if def:tls_in_ver        { (\$tls_in_ver)}}\${if def:tls_in_cipher_std { tls \$tls_in_cipher_std\n$2\t}}(Exim \$version_number)/;
+    if (/condition: def:tls_in_ver$/)
       {
       $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>;
       $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>;
-      $_= <IN>; $_= <IN>; $_= <IN>; next;
+      $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>;
+      $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>;
+      $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>; $_= <IN>; next;
       }
 
 
@@ -1207,10 +1259,28 @@ RESET_AFTER_EXTRA_LINE_READ:
     # timing variance, run-to-run
     s/^time on queue = \K1s/0s/;
 
+    # content-scan: file order can vary in directory
+    s%unspool_mbox\(\): unlinking 'TESTSUITE/spool/scan/[^/]*/\K[^\']*%FFFFFFFFF%;
+
     # 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;
 
+    # daemon notifier socket
+    s/^(\s*\d+|ppppp) (creating notifier socket)$/ppppp $2/;
+    s/^ \@(.*exim_daemon_notify)$/ $1/;
+    s/^(\s*\d+|ppppp)  \@?(.*exim_daemon_notify)$/ppppp  $2/;
+    next if /unlinking notifier socket/;
+
+    # daemon notifier socket
+    # Timing variance over runs.  Collapse repeated memssages.
+    if (/notify triggered queue run/)
+      {
+      my $line = $_;
+      while (/notify triggered queue run/) { $_ = <IN>; }
+      $_ = $line . $_;
+      }
+
     # DISABLE_OCSP
     next if /in hosts_requ(est|ire)_ocsp\? (no|yes)/;
 
@@ -1226,6 +1296,9 @@ RESET_AFTER_EXTRA_LINE_READ:
     # Experimental_REQUIRETLS
     next if / in tls_advertise_requiretls?\? no \(end of list\)/;
 
+    # Experimental_LIMITS
+    next if / in limits_advertise_hosts?\? no \(matched "!\*"\)/;
+
     # TCP Fast Open
     next if /^(ppppp )?setsockopt FASTOPEN: Network Error/;
 
@@ -1233,7 +1306,7 @@ RESET_AFTER_EXTRA_LINE_READ:
     next if /\w+ in keep_environment\? (yes|no)/;
 
     # Sizes vary with test hostname
-    s/^cmd buf flush \d+ bytes$/cmd buf flush ddd bytes/;
+    s/^cmd buf flush \d+ bytes/cmd buf flush ddd bytes/;
 
     # Spool filesystem free space changes on different systems.
     s/^((?:spool|log) directory space =) -?\d+K (inodes =)\s*-?\d+/$1 nnnnnK $2 nnnnn/;
@@ -1312,6 +1385,9 @@ RESET_AFTER_EXTRA_LINE_READ:
     next if /^Waiting for MySQL server to answer/;
     next if /mysqladmin: CREATE DATABASE failed; .* database exists/;
 
+    # Postgres version-dependent differences
+    s/^initdb: warning: (enabling "trust" authentication for local connections)$/\nWARNING: $1/;
+
     # Not all builds include DMARC
     next if /^DMARC: no (dmarc_tld_file|sender_host_address)$/ ;
 
@@ -1325,6 +1401,9 @@ RESET_AFTER_EXTRA_LINE_READ:
     s/^errno = \d+$/errno = EEE/;
     s/^writing error \d+: /writing error EEE: /;
 
+    # Some platforms have to flip to slow-mode taint-checking
+    next if /switching to slow-mode taint checking/;
+
     # 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
@@ -1409,6 +1488,9 @@ RESET_AFTER_EXTRA_LINE_READ:
       my ($prefix, $t_diff) = ($1, $3 - $2);
       s/DKIM: d=.* t=[0-9]* x=[0-9]* /${prefix} t=T x=T+${t_diff} /;
       }
+    # GnuTLS reports a different keysize vs. OpenSSL, for ed25519 keys
+    s/signer: [^ ]* bits:\K 256/ 253/;
+    s/public key too short:\K 256 bits/ 253 bits/;
 
     # port numbers
     s/(?:\[[^\]]*\]:|port )\K$parm_port_d/PORT_D/;
@@ -1421,6 +1503,16 @@ RESET_AFTER_EXTRA_LINE_READ:
 
     # Platform differences for errno values (eg. Hurd).  Leave 0 and negative numbers alone.
     s/R=\w+ T=\w+ defer\K \([1-9]\d*\): / (EEE): /;
+
+    # Platform differences in errno strings
+    s/Arg list too long/Argument list too long/;
+
+    # OpenSSL vs. GnuTLS
+    s/session: \K\((SSL_connect|gnutls_handshake)\): timed out/(tls lib connect fn): timed out/;
+    s/TLS error on connection from .*\K\((SSL_accept|gnutls_handshake)\): timed out/(tls lib accept fn): timed out/;
+    s/TLS error on connection from .*\K(SSL_accept: TCP connection closed by peer|\(gnutls_handshake\): The TLS connection was non-properly terminated.)/(tls lib accept fn): TCP connection closed by peer/;
+    s/TLS session: \K\(gnutls_handshake\): No supported application protocol could be negotiated/(SSL_connect): error: <<detail omitted>>/;
+    s/\(gnutls_handshake\): No common application protocol could be negotiated./(SSL_accept): error: <<detail omitted>>/;
     }
 
   # ======== mail ========
@@ -1721,7 +1813,7 @@ if (-e $sf_current)
 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;
+    copy($mf, $sf) or tests_exit(-1, "Failed to copy $mf $sf");
   }
 else
   {
@@ -2084,7 +2176,7 @@ if ($debug)
   $prcmd =~ s/; /;\n>> /;
   print ">> $prcmd\n";
   }
-system("$cmd");
+system($cmd);
 }
 
 
@@ -2321,8 +2413,7 @@ if (/^gnutls/)
 
 
 # The "killdaemon" command should ultimately follow the starting of any Exim
-# daemon with the -bd option. We kill with SIGINT rather than SIGTERM to stop
-# it outputting "Terminated" to the terminal when not in the background.
+# daemon with the -bd option.
 
 if (/^killdaemon/)
   {
@@ -2334,14 +2425,14 @@ if (/^killdaemon/)
     print ">> killdaemon: recovered pid $pid\n" if $debug;
     if ($pid)
       {
-      run_system("sudo /bin/kill -INT $pid");
+      run_system("sudo /bin/kill -TERM $pid");
       wait;
       }
     } else {
     $pid = `cat $parm_cwd/spool/exim-daemon.*`;
     if ($pid)
       {
-      run_system("sudo /bin/kill -INT $pid");
+      run_system("sudo /bin/kill -TERM $pid");
       close DAEMONCMD;                                   # Waits for process
       }
     }
@@ -2743,8 +2834,9 @@ else { tests_exit(-1, "Command unrecognized in line $lineno: $_"); }
 
 
 # Run the command, with stdin connected to a pipe, and write the stdin data
-# to it, with appropriate substitutions. If a line ends with \NONL\, chop off
-# the terminating newline (and the \NONL\). If the command contains
+# to it, with appropriate substitutions. If a starts with '>>> ', process it
+# via Perl's string eval().
+# If the command contains
 # -DSERVER=server add "-server" to the command, where it will adjoin the name
 # for the stderr file. See comment above about the use of -DSERVER.
 
@@ -2753,12 +2845,29 @@ print ">> |${cmd}${stderrsuffix}\n" if ($debug);
 open CMD, "|${cmd}${stderrsuffix}" || tests_exit(1, "Failed to run $cmd");
 
 CMD->autoflush(1);
-while (<SCRIPT>)
+LINE: while (<SCRIPT>)
   {
   $lineno++;
   last if /^\*{4}\s*$/;
   do_substitute($testno);
-  if (/^(.*)\\NONL\\\s*$/) { print CMD $1; } else { print CMD; }
+  if (my ($cmd, $line) = /^(:\S+?:)(.*)/) {
+    $_ = $line;
+      {
+      $cmd eq ':eval:' and do {
+        $_ = eval "\"$_\"";
+        last;
+      };
+      $cmd eq ':noeol:' and do {
+        s/[\r\n]*$//;
+        last;
+      };
+      $cmd eq ':sleep:' and do {
+        sleep $_;
+        next LINE;
+      };
+    }
+  }
+  print CMD;
   }
 
 # For timeout tests, wait before closing the pipe; we expect a
@@ -2850,6 +2959,7 @@ GetOptions(
     'valgrind' => \$valgrind,
     'range=s{2}'       => \my @range_wanted,
     'test=i@'          => \my @tests_wanted,
+    'fail-any!'        => \my $fail_any,
     'flavor|flavour=s' => \$flavour,
     'help'             => sub { pod2usage(-exit => 0) },
     'man'              => sub {
@@ -2958,7 +3068,7 @@ my $eximinfo = "$parm_exim -d -C $parm_cwd/test-config -DDIR=$parm_cwd -bP exim_
 chomp(my @eximinfo = `$eximinfo 2>&1`);
 die "$0: Can't run $eximinfo\n" if $? == -1;
 
-warn 'Got ' . $?>>8 . " from $eximinfo\n" if $?;
+warn 'Got ' . ($?>>8) . " from $eximinfo\n" if $?;
 foreach (@eximinfo)
   {
   if (my ($version) = /^Exim version (\S+)/) {
@@ -3027,7 +3137,7 @@ if (defined $parm_trusted_config_list)
   open(TCL, $parm_trusted_config_list) or die "Can't open $parm_trusted_config_list: $!\n";
   my $test_config = getcwd() . '/test-config';
   die "Can't find '$test_config' in TRUSTED_CONFIG_LIST $parm_trusted_config_list."
-  if not grep { /^\Q$test_config\E$/ } <TCL>;
+    if not grep { /^\Q$test_config\E$/ } <TCL>;
   }
 else
   {
@@ -3653,37 +3763,16 @@ system("sudo cp eximdir/exim eximdir/exim_exim;" .
 ($parm_exim_dir) = $parm_exim =~ m?^(.*)/exim?;
 
 $dbm_build_deleted = 0;
-if (defined $parm_lookups{dbm} &&
-    system("cp $parm_exim_dir/exim_dbmbuild eximdir") != 0)
+if (defined $parm_lookups{dbm} && not cp("$parm_exim_dir/exim_dbmbuild", "eximdir/exim_dbmbuild"))
   {
   delete $parm_lookups{dbm};
   $dbm_build_deleted = 1;
   }
 
-if (system("cp $parm_exim_dir/exim_dumpdb eximdir") != 0)
-  {
-  tests_exit(-1, "Failed to make a copy of exim_dumpdb: $!");
-  }
-
-if (system("cp $parm_exim_dir/exim_lock eximdir") != 0)
-  {
-  tests_exit(-1, "Failed to make a copy of exim_lock: $!");
-  }
-
-if (system("cp $parm_exim_dir/exinext eximdir") != 0)
-  {
-  tests_exit(-1, "Failed to make a copy of exinext: $!");
-  }
-
-if (system("cp $parm_exim_dir/exigrep eximdir") != 0)
-  {
-  tests_exit(-1, "Failed to make a copy of exigrep: $!");
-  }
-
-if (system("cp $parm_exim_dir/eximstats eximdir") != 0)
-  {
-  tests_exit(-1, "Failed to make a copy of eximstats: $!");
-  }
+foreach my $tool (qw(exim_dumpdb exim_lock exinext exigrep eximstats)) {
+  cp("$parm_exim_dir/$tool" => "eximdir/$tool")
+    or tests_exit(-1, "Failed to make a copy of $tool: $!");
+}
 
 # Collect some version information
 print '-' x 78, "\n";
@@ -4076,6 +4165,7 @@ if (not $force_continue) {
 }
 
 
+my $failures = 0;
 foreach $test (@test_list)
   {
   state $lasttestdir = '';
@@ -4122,15 +4212,15 @@ foreach $test (@test_list)
   # the test-mail directory for appendfile deliveries.
 
   system "sudo /bin/rm -rf spool test-*";
-  system "mkdir test-mail 2>/dev/null";
+  mkdir "test-mail";
 
   # A privileged Exim will normally make its own spool directory, but some of
   # the tests run in unprivileged modes that don't always work if the spool
   # directory isn't already there. What is more, we want anybody to be able
   # to read it in order to find the daemon's pid.
 
-  system "mkdir spool; " .
-         "sudo chown $parm_eximuser:$parm_eximgroup spool; " .
+  mkdir "spool";
+  system "sudo chown $parm_eximuser:$parm_eximgroup spool; " .
          "sudo chmod 0755 spool";
 
   # Empty the cache that keeps track of things like message id mappings, and
@@ -4309,10 +4399,12 @@ foreach $test (@test_list)
         print "\nshow stdErr, show stdOut, Retry, Continue (without file comparison), or Quit? [Q] ";
         $_ = $force_continue ? "c" : <T>;
         tests_exit(1) if /^q?$/i;
-       if (/^c$/ && $force_continue) {
-         log_failure($log_failed_filename, $testno, "exit code unexpected");
-         log_test($log_summary_filename, $testno, 'F')
-       }
+        if (/^c$/ && $force_continue)
+          {
+          log_failure($log_failed_filename, $testno, "exit code unexpected");
+          log_test($log_summary_filename, $testno, 'F');
+          $failures++;
+          }
         if ($force_continue)
           {
           print "\nstdout tail:\n";
@@ -4365,7 +4457,7 @@ foreach $test (@test_list)
         {
         if (($? & 0xff) == 0)
           { printf("Server return code %d for test %d starting line %d", $?/256,
-               $testno, $subtest_startline); }
+                $testno, $subtest_startline); }
         elsif (($? & 0xff00) == 0)
           { printf("Server killed by signal %d", $? & 255); }
         else
@@ -4376,10 +4468,12 @@ foreach $test (@test_list)
           print "\nShow server stdout, Retry, Continue, or Quit? [Q] ";
           $_ = $force_continue ? "c" : <T>;
           tests_exit(1) if /^q?$/i;
-         if (/^c$/ && $force_continue) {
-           log_failure($log_failed_filename, $testno, "exit code unexpected");
-           log_test($log_summary_filename, $testno, 'F')
-         }
+          if (/^c$/ && $force_continue)
+            {
+            log_failure($log_failed_filename, $testno, "exit code unexpected");
+            log_test($log_summary_filename, $testno, 'F');
+            $failures++;
+            }
           print "... continue forced\n" if $force_continue;
           last if /^[rc]$/i;
 
@@ -4414,7 +4508,14 @@ foreach $test (@test_list)
     {
     sleep 1 if $slow;
     my $rc = check_output($TEST_STATE->{munge});
-    log_test($log_summary_filename, $testno, 'P') if ($rc == 0);
+    if ($rc == 0)
+      {
+      log_test($log_summary_filename, $testno, 'P');
+      }
+    else
+      {
+      $failures++;
+      }
     if ($rc < 2)
       {
       print ("  Script completed\n");
@@ -4433,7 +4534,7 @@ foreach $test (@test_list)
 ##################################################
 
 tests_exit(-1, "No runnable tests selected") if not @test_list;
-tests_exit(0);
+tests_exit($fail_any ? $failures : 0);
 
 __END__