Do not use shutdown() when talking to rspamd. Fixes 1802
[exim.git] / test / runtest
... / ...
CommitLineData
1#! /usr/bin/env perl
2# We use env, because in some environments of our build farm
3# the Perl 5.010 interpreter is only reachable via $PATH
4
5###############################################################################
6# This is the controlling script for the "new" test suite for Exim. It should #
7# be possible to export this suite for running on a wide variety of hosts, in #
8# contrast to the old suite, which was very dependent on the environment of #
9# Philip Hazel's desktop computer. This implementation inspects the version #
10# of Exim that it finds, and tests only those features that are included. The #
11# surrounding environment is also tested to discover what is available. See #
12# the README file for details of how it all works. #
13# #
14# Implementation started: 03 August 2005 by Philip Hazel #
15# Placed in the Exim CVS: 06 February 2006 #
16###############################################################################
17
18#use strict;
19use 5.010;
20use feature 'state'; # included in 5.010
21use warnings;
22
23use Errno;
24use FileHandle;
25use Socket;
26use Time::Local;
27use Cwd;
28use File::Basename;
29use FindBin qw'$Bin';
30
31use lib "$Bin/lib";
32use Exim::Runtest;
33
34use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
35
36
37# Start by initializing some global variables
38
39$testversion = "4.80 (08-May-12)";
40
41# This gets embedded in the D-H params filename, and the value comes
42# from asking GnuTLS for "normal", but there appears to be no way to
43# use certtool/... to ask what that value currently is. *sigh*
44# We also clamp it because of NSS interop, see addition of tls_dh_max_bits.
45# This value is correct as of GnuTLS 2.12.18 as clamped by tls_dh_max_bits.
46# normal = 2432 tls_dh_max_bits = 2236
47$gnutls_dh_bits_normal = 2236;
48
49$cf = "bin/cf -exact";
50$cr = "\r";
51$debug = 0;
52$flavour = 'FOO';
53$force_continue = 0;
54$force_update = 0;
55$log_failed_filename = "failed-summary.log";
56$more = "less -XF";
57$optargs = "";
58$save_output = 0;
59$server_opts = "";
60$valgrind = 0;
61
62$have_ipv4 = 1;
63$have_ipv6 = 1;
64$have_largefiles = 0;
65
66$test_start = 1;
67$test_end = $test_top = 8999;
68$test_special_top = 9999;
69@test_list = ();
70@test_dirs = ();
71
72
73# Networks to use for DNS tests. We need to choose some networks that will
74# never be used so that there is no chance that the host on which we are
75# running is actually in one of the test networks. Private networks such as
76# the IPv4 10.0.0.0/8 network are no good because hosts may well use them.
77# Rather than use some unassigned numbers (that might become assigned later),
78# I have chosen some multicast networks, in the belief that such addresses
79# won't ever be assigned to hosts. This is the only place where these numbers
80# are defined, so it is trivially possible to change them should that ever
81# become necessary.
82
83$parm_ipv4_test_net = "224";
84$parm_ipv6_test_net = "ff00";
85
86# Port numbers are currently hard-wired
87
88$parm_port_n = 1223; # Nothing listening on this port
89$parm_port_s = 1224; # Used for the "server" command
90$parm_port_d = 1225; # Used for the Exim daemon
91$parm_port_d2 = 1226; # Additional for daemon
92$parm_port_d3 = 1227; # Additional for daemon
93$parm_port_d4 = 1228; # Additional for daemon
94my $dynamic_socket; # allocated later for PORT_DYNAMIC
95
96# Find a suiteable group name for test (currently only 0001
97# uses a group name. A numeric group id would do
98my $parm_mailgroup = Exim::Runtest::mailgroup('mail');
99
100# Manually set locale
101$ENV{LC_ALL} = 'C';
102
103# In some environments USER does not exists, but we
104# need it for some test(s)
105$ENV{USER} = getpwuid($>)
106 if not exists $ENV{USER};
107
108my ($parm_configure_owner, $parm_configure_group);
109my ($parm_ipv4, $parm_ipv6);
110my $parm_hostname;
111
112###############################################################################
113###############################################################################
114
115# Define a number of subroutines
116
117###############################################################################
118###############################################################################
119
120
121##################################################
122# Handle signals #
123##################################################
124
125sub pipehandler { $sigpipehappened = 1; }
126
127sub inthandler { print "\n"; tests_exit(-1, "Caught SIGINT"); }
128
129
130##################################################
131# Do global macro substitutions #
132##################################################
133
134# This function is applied to configurations, command lines and data lines in
135# scripts, and to lines in the files of the aux-var-src and the dnszones-src
136# directory. It takes one argument: the current test number, or zero when
137# setting up files before running any tests.
138
139sub do_substitute{
140s?\bCALLER\b?$parm_caller?g;
141s?\bCALLERGROUP\b?$parm_caller_group?g;
142s?\bCALLER_UID\b?$parm_caller_uid?g;
143s?\bCALLER_GID\b?$parm_caller_gid?g;
144s?\bCLAMSOCKET\b?$parm_clamsocket?g;
145s?\bDIR/?$parm_cwd/?g;
146s?\bEXIMGROUP\b?$parm_eximgroup?g;
147s?\bEXIMUSER\b?$parm_eximuser?g;
148s?\bHOSTIPV4\b?$parm_ipv4?g;
149s?\bHOSTIPV6\b?$parm_ipv6?g;
150s?\bHOSTNAME\b?$parm_hostname?g;
151s?\bPORT_D\b?$parm_port_d?g;
152s?\bPORT_D2\b?$parm_port_d2?g;
153s?\bPORT_D3\b?$parm_port_d3?g;
154s?\bPORT_D4\b?$parm_port_d4?g;
155s?\bPORT_N\b?$parm_port_n?g;
156s?\bPORT_S\b?$parm_port_s?g;
157s?\bTESTNUM\b?$_[0]?g;
158s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
159s?\bV6NET:?$parm_ipv6_test_net:?g;
160s?\bPORT_DYNAMIC\b?$dynamic_socket->sockport()?eg;
161s?\bMAILGROUP\b?$parm_mailgroup?g;
162}
163
164
165##################################################
166# Any state to be preserved across tests #
167##################################################
168
169my $TEST_STATE = {};
170
171
172##################################################
173# Subroutine to tidy up and exit #
174##################################################
175
176# In all cases, we check for any Exim daemons that have been left running, and
177# kill them. Then remove all the spool data, test output, and the modified Exim
178# binary if we are ending normally.
179
180# Arguments:
181# $_[0] = 0 for a normal exit; full cleanup done
182# $_[0] > 0 for an error exit; no files cleaned up
183# $_[0] < 0 for a "die" exit; $_[1] contains a message
184
185sub tests_exit{
186my($rc) = $_[0];
187my($spool);
188
189# Search for daemon pid files and kill the daemons. We kill with SIGINT rather
190# than SIGTERM to stop it outputting "Terminated" to the terminal when not in
191# the background.
192
193if (exists $TEST_STATE->{exim_pid})
194 {
195 $pid = $TEST_STATE->{exim_pid};
196 print "Tidyup: killing wait-mode daemon pid=$pid\n";
197 system("sudo kill -INT $pid");
198 }
199
200if (opendir(DIR, "spool"))
201 {
202 my(@spools) = sort readdir(DIR);
203 closedir(DIR);
204 foreach $spool (@spools)
205 {
206 next if $spool !~ /^exim-daemon./;
207 open(PID, "spool/$spool") || die "** Failed to open \"spool/$spool\": $!\n";
208 chomp($pid = <PID>);
209 close(PID);
210 print "Tidyup: killing daemon pid=$pid\n";
211 system("sudo rm -f spool/$spool; sudo kill -INT $pid");
212 }
213 }
214else
215 { die "** Failed to opendir(\"spool\"): $!\n" unless $!{ENOENT}; }
216
217# Close the terminal input and remove the test files if all went well, unless
218# the option to save them is set. Always remove the patched Exim binary. Then
219# exit normally, or die.
220
221close(T);
222system("sudo /bin/rm -rf ./spool test-* ./dnszones/*")
223 if ($rc == 0 && !$save_output);
224
225system("sudo /bin/rm -rf ./eximdir/*")
226 if (!$save_output);
227
228print "\nYou were in test $test at the end there.\n\n" if defined $test;
229exit $rc if ($rc >= 0);
230die "** runtest error: $_[1]\n";
231}
232
233
234
235##################################################
236# Subroutines used by the munging subroutine #
237##################################################
238
239# This function is used for things like message ids, where we want to generate
240# more than one value, but keep a consistent mapping throughout.
241#
242# Arguments:
243# $oldid the value from the file
244# $base a base string into which we insert a sequence
245# $sequence the address of the current sequence counter
246
247sub new_value {
248my($oldid, $base, $sequence) = @_;
249my($newid) = $cache{$oldid};
250if (! defined $newid)
251 {
252 $newid = sprintf($base, $$sequence++);
253 $cache{$oldid} = $newid;
254 }
255return $newid;
256}
257
258
259# This is used while munging the output from exim_dumpdb.
260# May go wrong across DST changes.
261
262sub date_seconds {
263my($day,$month,$year,$hour,$min,$sec) =
264 $_[0] =~ /^(\d\d)-(\w\w\w)-(\d{4})\s(\d\d):(\d\d):(\d\d)/;
265my($mon);
266if ($month =~ /Jan/) {$mon = 0;}
267elsif($month =~ /Feb/) {$mon = 1;}
268elsif($month =~ /Mar/) {$mon = 2;}
269elsif($month =~ /Apr/) {$mon = 3;}
270elsif($month =~ /May/) {$mon = 4;}
271elsif($month =~ /Jun/) {$mon = 5;}
272elsif($month =~ /Jul/) {$mon = 6;}
273elsif($month =~ /Aug/) {$mon = 7;}
274elsif($month =~ /Sep/) {$mon = 8;}
275elsif($month =~ /Oct/) {$mon = 9;}
276elsif($month =~ /Nov/) {$mon = 10;}
277elsif($month =~ /Dec/) {$mon = 11;}
278return timelocal($sec,$min,$hour,$day,$mon,$year);
279}
280
281
282# This is a subroutine to sort maildir files into time-order. The second field
283# is the microsecond field, and may vary in length, so must be compared
284# numerically.
285
286sub maildirsort {
287return $a cmp $b if ($a !~ /^\d+\.H\d/ || $b !~ /^\d+\.H\d/);
288my($x1,$y1) = $a =~ /^(\d+)\.H(\d+)/;
289my($x2,$y2) = $b =~ /^(\d+)\.H(\d+)/;
290return ($x1 != $x2)? ($x1 <=> $x2) : ($y1 <=> $y2);
291}
292
293
294
295##################################################
296# Subroutine list files below a directory #
297##################################################
298
299# This is used to build up a list of expected mail files below a certain path
300# in the directory tree. It has to be recursive in order to deal with multiple
301# maildir mailboxes.
302
303sub list_files_below {
304my($dir) = $_[0];
305my(@yield) = ();
306my(@sublist, $file);
307
308opendir(DIR, $dir) || tests_exit(-1, "Failed to open $dir: $!");
309@sublist = sort maildirsort readdir(DIR);
310closedir(DIR);
311
312foreach $file (@sublist)
313 {
314 next if $file eq "." || $file eq ".." || $file eq "CVS";
315 if (-d "$dir/$file")
316 { @yield = (@yield, list_files_below("$dir/$file")); }
317 else
318 { push @yield, "$dir/$file"; }
319 }
320
321return @yield;
322}
323
324
325
326##################################################
327# Munge a file before comparing #
328##################################################
329
330# The pre-processing turns all dates, times, Exim versions, message ids, and so
331# on into standard values, so that the compare works. Perl's substitution with
332# an expression provides a neat way to do some of these changes.
333
334# We keep a global associative array for repeatedly turning the same values
335# into the same standard values throughout the data from a single test.
336# Message ids get this treatment (can't be made reliable for times), and
337# times in dumped retry databases are also handled in a special way, as are
338# incoming port numbers.
339
340# On entry to the subroutine, the file to write to is already opened with the
341# name MUNGED. The input file name is the only argument to the subroutine.
342# Certain actions are taken only when the name contains "stderr", "stdout",
343# or "log". The yield of the function is 1 if a line matching "*** truncated
344# ***" is encountered; otherwise it is 0.
345
346sub munge {
347my($file) = $_[0];
348my($extra) = $_[1];
349my($yield) = 0;
350my(@saved) = ();
351
352local $_;
353
354open(IN, "$file") || tests_exit(-1, "Failed to open $file: $!");
355
356my($is_log) = $file =~ /log/;
357my($is_stdout) = $file =~ /stdout/;
358my($is_stderr) = $file =~ /stderr/;
359
360# Date pattern
361
362$date = "\\d{2}-\\w{3}-\\d{4}\\s\\d{2}:\\d{2}:\\d{2}";
363
364# Pattern for matching pids at start of stderr lines; initially something
365# that won't match.
366
367$spid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
368
369# Scan the file and make the changes. Near the bottom there are some changes
370# that are specific to certain file types, though there are also some of those
371# inline too.
372
373LINE: while(<IN>)
374 {
375RESET_AFTER_EXTRA_LINE_READ:
376 # Custom munges
377 if ($extra)
378 {
379 next if $extra =~ m%^/% && eval $extra;
380 eval $extra if $extra =~ m/^s/;
381 }
382
383 # Check for "*** truncated ***"
384 $yield = 1 if /\*\*\* truncated \*\*\*/;
385
386 # Replace the name of this host
387 s/\Q$parm_hostname\E/the.local.host.name/g;
388
389 # But convert "name=the.local.host address=127.0.0.1" to use "localhost"
390 s/name=the\.local\.host address=127\.0\.0\.1/name=localhost address=127.0.0.1/g;
391
392 # The name of the shell may vary
393 s/\s\Q$parm_shell\E\b/ ENV_SHELL/;
394
395 # Replace the path to the testsuite directory
396 s?\Q$parm_cwd\E?TESTSUITE?g;
397
398 # Replace the Exim version number (may appear in various places)
399 # patchexim should have fixed this for us
400 #s/(Exim) \d+\.\d+[\w_-]*/$1 x.yz/i;
401
402 # Replace Exim message ids by a unique series
403 s/((?:[^\W_]{6}-){2}[^\W_]{2})
404 /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
405
406 # The names of lock files appear in some error and debug messages
407 s/\.lock(\.[-\w]+)+(\.[\da-f]+){2}/.lock.test.ex.dddddddd.pppppppp/;
408
409 # Unless we are in an IPv6 test, replace IPv4 and/or IPv6 in "listening on
410 # port" message, because it is not always the same.
411 s/port (\d+) \([^)]+\)/port $1/g
412 if !$is_ipv6test && m/listening for SMTP(S?) on port/;
413
414 # Challenges in SPA authentication
415 s/TlRMTVNTUAACAAAAAAAAAAAoAAABgg[\w+\/]+/TlRMTVNTUAACAAAAAAAAAAAoAAABggAAAEbBRwqFwwIAAAAAAAAAAAAt1sgAAAAA/;
416
417 # PRVS values
418 s?prvs=([^/]+)/[\da-f]{10}@?prvs=$1/xxxxxxxxxx@?g; # Old form
419 s?prvs=[\da-f]{10}=([^@]+)@?prvs=xxxxxxxxxx=$1@?g; # New form
420
421 # Error lines on stdout from SSL contain process id values and file names.
422 # They also contain a source file name and line number, which may vary from
423 # release to release.
424 s/^\d+:error:/pppp:error:/;
425 s/:(?:\/[^\s:]+\/)?([^\/\s]+\.c):\d+:/:$1:dddd:/;
426
427 # There are differences in error messages between OpenSSL versions
428 s/SSL_CTX_set_cipher_list/SSL_connect/;
429
430 # One error test in expansions mentions base 62 or 36
431 s/is not a base (36|62) number/is not a base 36\/62 number/;
432
433 # This message sometimes has a different number of seconds
434 s/forced fail after \d seconds/forced fail after d seconds/;
435
436 # This message may contain a different DBM library name
437 s/Failed to open \S+( \([^\)]+\))? file/Failed to open DBM file/;
438
439 # The message for a non-listening FIFO varies
440 s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;
441
442 # Debugging output of lists of hosts may have different sort keys
443 s/sort=\S+/sort=xx/ if /^\S+ (?:\d+\.){3}\d+ mx=\S+ sort=\S+/;
444
445 # Random local part in callout cache testing
446 s/myhost.test.ex-\d+-testing/myhost.test.ex-dddddddd-testing/;
447 s/the.local.host.name-\d+-testing/the.local.host.name-dddddddd-testing/;
448
449 # File descriptor numbers may vary
450 s/^writing data block fd=\d+/writing data block fd=dddd/;
451 s/(running as transport filter:) fd_write=\d+ fd_read=\d+/$1 fd_write=dddd fd_read=dddd/;
452
453
454 # ======== Dumpdb output ========
455 # This must be before the general date/date munging.
456 # Time data lines, which look like this:
457 # 25-Aug-2000 12:11:37 25-Aug-2000 12:11:37 26-Aug-2000 12:11:37
458 if (/^($date)\s+($date)\s+($date)(\s+\*)?\s*$/)
459 {
460 my($date1,$date2,$date3,$expired) = ($1,$2,$3,$4);
461 $expired = "" if !defined $expired;
462 my($increment) = date_seconds($date3) - date_seconds($date2);
463
464 # We used to use globally unique replacement values, but timing
465 # differences make this impossible. Just show the increment on the
466 # last one.
467
468 printf MUNGED ("first failed = time last try = time2 next try = time2 + %s%s\n",
469 $increment, $expired);
470 next;
471 }
472
473 # more_errno values in exim_dumpdb output which are times
474 s/T:(\S+)\s-22\s(\S+)\s/T:$1 -22 xxxx /;
475
476
477 # ======== Dates and times ========
478
479 # Dates and times are all turned into the same value - trying to turn
480 # them into different ones cannot be done repeatedly because they are
481 # real time stamps generated while running the test. The actual date and
482 # time used was fixed when I first started running automatic Exim tests.
483
484 # Date/time in header lines and SMTP responses
485 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}
486 /Tue, 2 Mar 1999 09:44:33 +0000/gx;
487
488 # Date/time in logs and in one instance of a filter test
489 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;
490 s/^Logwrite\s"\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Logwrite "1999-03-02 09:44:33/gx;
491
492 # Date/time in message separators
493 s/(?:[A-Z][a-z]{2}\s){2}\d\d\s\d\d:\d\d:\d\d\s\d\d\d\d
494 /Tue Mar 02 09:44:33 1999/gx;
495
496 # Date of message arrival in spool file as shown by -Mvh
497 s/^\d{9,10}\s0$/ddddddddd 0/;
498
499 # Date/time in mbx mailbox files
500 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;
501
502 # Dates/times in debugging output for writing retry records
503 if (/^ first failed=(\d+) last try=(\d+) next try=(\d+) (.*)$/)
504 {
505 my($next) = $3 - $2;
506 $_ = " first failed=dddd last try=dddd next try=+$next $4\n";
507 }
508 s/^(\s*)now=\d+ first_failed=\d+ next_try=\d+ expired=(\d)/$1now=tttt first_failed=tttt next_try=tttt expired=$2/;
509 s/^(\s*)received_time=\d+ diff=\d+ timeout=(\d+)/$1received_time=tttt diff=tttt timeout=$2/;
510
511 # Time to retry may vary
512 s/time to retry = \S+/time to retry = tttt/;
513 s/retry record exists: age=\S+/retry record exists: age=ttt/;
514 s/failing_interval=\S+ message_age=\S+/failing_interval=ttt message_age=ttt/;
515
516 # Date/time in exim -bV output
517 s/\d\d-[A-Z][a-z]{2}-\d{4}\s\d\d:\d\d:\d\d/07-Mar-2000 12:21:52/g;
518
519 # Time on queue tolerance
520 s/(QT|D)=1s/$1=0s/;
521
522 # Eximstats heading
523 s/Exim\sstatistics\sfrom\s\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\sto\s
524 \d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Exim statistics from <time> to <time>/x;
525
526 # Treat ECONNRESET the same as ECONNREFUSED. At least some systems give
527 # us the former on a new connection.
528 s/(could not connect to .*: Connection) reset by peer$/$1 refused/;
529
530 # ======== TLS certificate algorithms ========
531 # Test machines might have various different TLS library versions supporting
532 # different protocols; can't rely upon TLS 1.2's AES256-GCM-SHA384, so we
533 # treat the standard algorithms the same.
534 # So far, have seen:
535 # TLSv1:AES128-GCM-SHA256:128
536 # TLSv1:AES256-SHA:256
537 # TLSv1.1:AES256-SHA:256
538 # TLSv1.2:AES256-GCM-SHA384:256
539 # TLSv1.2:DHE-RSA-AES256-SHA:256
540 # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
541 # We also need to handle the ciphersuite without the TLS part present, for
542 # client-ssl's output. We also see some older forced ciphersuites, but
543 # negotiating TLS 1.2 instead of 1.0.
544 # Mail headers (...), log-lines X=..., client-ssl output ...
545 # (and \b doesn't match between ' ' and '(' )
546
547 s/( (?: (?:\b|\s) [\(=] ) | \s )TLSv1\.[12]:/$1TLSv1:/xg;
548 s/\bAES128-GCM-SHA256:128\b/AES256-SHA:256/g;
549 s/\bAES128-GCM-SHA256\b/AES256-SHA/g;
550 s/\bAES256-GCM-SHA384\b/AES256-SHA/g;
551 s/\bDHE-RSA-AES256-SHA\b/AES256-SHA/g;
552
553 # GnuTLS have seen:
554 # TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256
555 # TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128
556 # TLS1.2:RSA_AES_256_CBC_SHA1:256 (canonical)
557 # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
558 #
559 # X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256
560 # X=TLS1.2:RSA_AES_256_CBC_SHA1:256
561 # X=TLS1.1:RSA_AES_256_CBC_SHA1:256
562 # X=TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256
563 # and as stand-alone cipher:
564 # ECDHE-RSA-AES256-SHA
565 # DHE-RSA-AES256-SHA256
566 # DHE-RSA-AES256-SHA
567 # picking latter as canonical simply because regex easier that way.
568 s/\bDHE_RSA_AES_128_CBC_SHA1:128/RSA_AES_256_CBC_SHA1:256/g;
569 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;
570 s/\b(ECDHE-RSA-AES256-SHA|DHE-RSA-AES256-SHA256)\b/AES256-SHA/g;
571
572 # GnuTLS library error message changes
573 s/No certificate was found/The peer did not send any certificate/g;
574#(dodgy test?) s/\(certificate verification failed\): invalid/\(gnutls_handshake\): The peer did not send any certificate./g;
575 s/\(gnutls_priority_set\): No or insufficient priorities were set/\(gnutls_handshake\): Could not negotiate a supported cipher suite/g;
576
577 # (this new one is a generic channel-read error, but the testsuite
578 # only hits it in one place)
579 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;
580
581 # (replace old with new, hoping that old only happens in one situation)
582 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;
583 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;
584
585 # signature algorithm names
586 s/RSA-SHA1/RSA-SHA/;
587
588
589 # ======== Caller's login, uid, gid, home, gecos ========
590
591 s/\Q$parm_caller_home\E/CALLER_HOME/g; # NOTE: these must be done
592 s/\b\Q$parm_caller\E\b/CALLER/g; # in this order!
593 s/\b\Q$parm_caller_group\E\b/CALLER/g; # In case group name different
594
595 s/\beuid=$parm_caller_uid\b/euid=CALLER_UID/g;
596 s/\begid=$parm_caller_gid\b/egid=CALLER_GID/g;
597
598 s/\buid=$parm_caller_uid\b/uid=CALLER_UID/g;
599 s/\bgid=$parm_caller_gid\b/gid=CALLER_GID/g;
600
601 s/\bname="?$parm_caller_gecos"?/name=CALLER_GECOS/g;
602
603 # When looking at spool files with -Mvh, we will find not only the caller
604 # login, but also the uid and gid. It seems that $) in some Perls gives all
605 # the auxiliary gids as well, so don't bother checking for that.
606
607 s/^CALLER $> \d+$/CALLER UID GID/;
608
609 # There is one case where the caller's login is forced to something else,
610 # in order to test the processing of logins that contain spaces. Weird what
611 # some people do, isn't it?
612
613 s/^spaced user $> \d+$/CALLER UID GID/;
614
615
616 # ======== Exim's login ========
617 # For messages received by the daemon, this is in the -H file, which some
618 # tests inspect. For bounce messages, this will appear on the U= lines in
619 # logs and also after Received: and in addresses. In one pipe test it appears
620 # after "Running as:". It also appears in addresses, and in the names of lock
621 # files.
622
623 s/U=$parm_eximuser/U=EXIMUSER/;
624 s/user=$parm_eximuser/user=EXIMUSER/;
625 s/login=$parm_eximuser/login=EXIMUSER/;
626 s/Received: from $parm_eximuser /Received: from EXIMUSER /;
627 s/Running as: $parm_eximuser/Running as: EXIMUSER/;
628 s/\b$parm_eximuser@/EXIMUSER@/;
629 s/\b$parm_eximuser\.lock\./EXIMUSER.lock./;
630
631 s/\beuid=$parm_exim_uid\b/euid=EXIM_UID/g;
632 s/\begid=$parm_exim_gid\b/egid=EXIM_GID/g;
633
634 s/\buid=$parm_exim_uid\b/uid=EXIM_UID/g;
635 s/\bgid=$parm_exim_gid\b/gid=EXIM_GID/g;
636
637 s/^$parm_eximuser $parm_exim_uid $parm_exim_gid/EXIMUSER EXIM_UID EXIM_GID/;
638
639
640 # ======== General uids, gids, and pids ========
641 # Note: this must come after munges for caller's and exim's uid/gid
642
643 # These are for systems where long int is 64
644 s/\buid=4294967295/uid=-1/;
645 s/\beuid=4294967295/euid=-1/;
646 s/\bgid=4294967295/gid=-1/;
647 s/\begid=4294967295/egid=-1/;
648
649 s/\bgid=\d+/gid=gggg/;
650 s/\begid=\d+/egid=gggg/;
651 s/\bpid=\d+/pid=pppp/;
652 s/\buid=\d+/uid=uuuu/;
653 s/\beuid=\d+/euid=uuuu/;
654 s/set_process_info:\s+\d+/set_process_info: pppp/;
655 s/queue run pid \d+/queue run pid ppppp/;
656 s/process \d+ running as transport filter/process pppp running as transport filter/;
657 s/process \d+ writing to transport filter/process pppp writing to transport filter/;
658 s/reading pipe for subprocess \d+/reading pipe for subprocess pppp/;
659 s/remote delivery process \d+ ended/remote delivery process pppp ended/;
660
661 # Pid in temp file in appendfile transport
662 s"test-mail/temp\.\d+\."test-mail/temp.pppp.";
663
664 # Optional pid in log lines
665 s/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)(\s[+-]\d\d\d\d|)(\s\[\d+\])/
666 "$1$2 [" . new_value($3, "%s", \$next_pid) . "]"/gxe;
667
668 # Detect a daemon stderr line with a pid and save the pid for subsequent
669 # removal from following lines.
670 $spid = $1 if /^(\s*\d+) (?:listening|LOG: MAIN|(?:daemon_smtp_port|local_interfaces) overridden by)/;
671 s/^$spid //;
672
673 # Queue runner waiting messages
674 s/waiting for children of \d+/waiting for children of pppp/;
675 s/waiting for (\S+) \(\d+\)/waiting for $1 (pppp)/;
676
677 # The spool header file name varies with PID
678 s%^(Writing spool header file: .*/hdr).[0-9]{1,5}%$1.pppp%;
679
680 # ======== Port numbers ========
681 # Incoming port numbers may vary, but not in daemon startup line.
682
683 s/^Port: (\d+)/"Port: " . new_value($1, "%s", \$next_port)/e;
684 s/\(port=(\d+)/"(port=" . new_value($1, "%s", \$next_port)/e;
685
686 # This handles "connection from" and the like, when the port is given
687 if (!/listening for SMTP on/ && !/Connecting to/ && !/=>/ && !/->/
688 && !/\*>/ && !/Connection refused/)
689 {
690 s/\[([a-z\d:]+|\d+(?:\.\d+){3})\]:(\d+)/"[".$1."]:".new_value($2,"%s",\$next_port)/ie;
691 }
692
693 # Port in host address in spool file output from -Mvh
694 s/^-host_address (.*)\.\d+/-host_address $1.9999/;
695
696 if ($dynamic_socket and $dynamic_socket->opened and my $port = $dynamic_socket->sockport) {
697 s/^Connecting to 127\.0\.0\.1 port \K$port/<dynamic port>/;
698 }
699
700
701 # ======== Local IP addresses ========
702 # The amount of space between "host" and the address in verification output
703 # depends on the length of the host name. We therefore reduce it to one space
704 # for all of them.
705 # Also, the length of space at the end of the host line is dependent
706 # on the length of the longest line, so strip it also on otherwise
707 # un-rewritten lines like localhost
708
709 s/^\s+host\s(\S+)\s+(\S+)/ host $1 $2/;
710 s/^\s+(host\s\S+\s\S+)\s+(port=.*)/ host $1 $2/;
711 s/^\s+(host\s\S+\s\S+)\s+(?=MX=)/ $1 /;
712 s/host\s\Q$parm_ipv4\E\s\[\Q$parm_ipv4\E\]/host ipv4.ipv4.ipv4.ipv4 [ipv4.ipv4.ipv4.ipv4]/;
713 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]/;
714 s/\b\Q$parm_ipv4\E\b/ip4.ip4.ip4.ip4/g;
715 s/(^|\W)\K\Q$parm_ipv6\E/ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6/g;
716 s/\b\Q$parm_ipv4r\E\b/ip4-reverse/g;
717 s/(^|\W)\K\Q$parm_ipv6r\E/ip6-reverse/g;
718 s/^(\s+host\s\S+\s+\[\S+\]) +$/$1 /;
719
720
721 # ======== Test network IP addresses ========
722 s/(\b|_)\Q$parm_ipv4_test_net\E(?=\.\d+\.\d+\.\d+\b|_|\.rbl|\.in-addr|\.test\.again\.dns)/$1V4NET/g;
723 s/\b\Q$parm_ipv6_test_net\E(?=:[\da-f]+:[\da-f]+:[\da-f]+)/V6NET/gi;
724
725
726 # ======== IP error numbers and messages ========
727 # These vary between operating systems
728 s/Can't assign requested address/Network Error/;
729 s/Cannot assign requested address/Network Error/;
730 s/Operation timed out/Connection timed out/;
731 s/Address family not supported by protocol family/Network Error/;
732 s/Network is unreachable/Network Error/;
733 s/Invalid argument/Network Error/;
734
735 s/\(\d+\): Network/(dd): Network/;
736 s/\(\d+\): Connection refused/(dd): Connection refused/;
737 s/\(\d+\): Connection timed out/(dd): Connection timed out/;
738 s/\d+ 65 Connection refused/dd 65 Connection refused/;
739 s/\d+ 321 Connection timed out/dd 321 Connection timed out/;
740
741
742 # ======== Other error numbers ========
743 s/errno=\d+/errno=dd/g;
744
745 # ======== System Error Messages ======
746 # depending on the underlaying file system the error message seems to differ
747 s/(?: is not a regular file)|(?: has too many links \(\d+\))/ not a regular file or too many links/;
748
749 # ======== Output from ls ========
750 # Different operating systems use different spacing on long output
751 #s/ +/ /g if /^[-rwd]{10} /;
752 # (Bug 1226) SUSv3 allows a trailing printable char for modified access method control.
753 # Handle only the Gnu and MacOS space, dot, plus and at-sign. A full [[:graph:]]
754 # unfortunately matches a non-ls linefull of dashes.
755 # Allow the case where we've already picked out the file protection bits.
756 if (s/^([-d](?:[-r][-w][-SsTtx]){3})[.+@]?( +|$)/$1$2/) {
757 s/ +/ /g;
758 }
759
760
761 # ======== Message sizes =========
762 # Message sizes vary, owing to different logins and host names that get
763 # automatically inserted. I can't think of any way of even approximately
764 # comparing these.
765
766 s/([\s,])S=\d+\b/$1S=sss/;
767 s/:S\d+\b/:Ssss/;
768 s/^(\s*\d+m\s+)\d+(\s+[a-z0-9-]{16} <)/$1sss$2/i if $is_stdout;
769 s/\sSIZE=\d+\b/ SIZE=ssss/;
770 s/\ssize=\d+\b/ size=sss/ if $is_stderr;
771 s/old size = \d+\b/old size = sssss/;
772 s/message size = \d+\b/message size = sss/;
773 s/this message = \d+\b/this message = sss/;
774 s/Size of headers = \d+/Size of headers = sss/;
775 s/sum=(?!0)\d+/sum=dddd/;
776 s/(?<=sum=dddd )count=\d+\b/count=dd/;
777 s/(?<=sum=0 )count=\d+\b/count=dd/;
778 s/,S is \d+\b/,S is ddddd/;
779 s/\+0100,\d+;/+0100,ddd;/;
780 s/\(\d+ bytes written\)/(ddd bytes written)/;
781 s/added '\d+ 1'/added 'ddd 1'/;
782 s/Received\s+\d+/Received nnn/;
783 s/Delivered\s+\d+/Delivered nnn/;
784
785
786 # ======== Values in spool space failure message ========
787 s/space=\d+ inodes=[+-]?\d+/space=xxxxx inodes=xxxxx/;
788
789
790 # ======== Filter sizes ========
791 # The sizes of filter files may vary because of the substitution of local
792 # filenames, logins, etc.
793
794 s/^\d+(?= bytes read from )/ssss/;
795
796
797 # ======== OpenSSL error messages ========
798 # Different releases of the OpenSSL libraries seem to give different error
799 # numbers, or handle specific bad conditions in different ways, leading to
800 # different wording in the error messages, so we cannot compare them.
801
802 s/(TLS error on connection (?:from .* )?\(SSL_\w+\): error:)(.*)/$1 <<detail omitted>>/;
803 next if /SSL verify error: depth=0 error=certificate not trusted/;
804
805 # ======== Maildir things ========
806 # timestamp output in maildir processing
807 s/(timestamp=|\(timestamp_only\): )\d+/$1ddddddd/g;
808
809 # maildir delivery files appearing in log lines (in cases of error)
810 s/writing to(?: file)? tmp\/\d+\.[^.]+\.(\S+)/writing to tmp\/MAILDIR.$1/;
811
812 s/renamed tmp\/\d+\.[^.]+\.(\S+) as new\/\d+\.[^.]+\.(\S+)/renamed tmp\/MAILDIR.$1 as new\/MAILDIR.$1/;
813
814 # Maildir file names in general
815 s/\b\d+\.H\d+P\d+\b/dddddddddd.HddddddPddddd/;
816
817 # Maildirsize data
818 while (/^\d+S,\d+C\s*$/)
819 {
820 print MUNGED;
821 while (<IN>)
822 {
823 last if !/^\d+ \d+\s*$/;
824 print MUNGED "ddd d\n";
825 }
826 last if !defined $_;
827 }
828 last if !defined $_;
829
830
831 # ======== Output from the "fd" program about open descriptors ========
832 # The statuses seem to be different on different operating systems, but
833 # at least we'll still be checking the number of open fd's.
834
835 s/max fd = \d+/max fd = dddd/;
836 s/status=0 RDONLY/STATUS/g;
837 s/status=1 WRONLY/STATUS/g;
838 s/status=2 RDWR/STATUS/g;
839
840
841 # ======== Contents of spool files ========
842 # A couple of tests dump the contents of the -H file. The length fields
843 # will be wrong because of different user names, etc.
844 s/^\d\d\d(?=[PFS*])/ddd/;
845
846
847 # ========= Exim lookups ==================
848 # Lookups have a char which depends on the number of lookup types compiled in,
849 # in stderr output. Replace with a "0". Recognising this while avoiding
850 # other output is fragile; perhaps the debug output should be revised instead.
851 s%(?<!sqlite)(?<!lsearch\*@)(?<!lsearch\*)(?<!lsearch)[0-?]TESTSUITE/aux-fixed/%0TESTSUITE/aux-fixed/%g;
852
853 # ==========================================================
854 # MIME boundaries in RFC3461 DSN messages
855 s/\d{8,10}-eximdsn-\d+/NNNNNNNNNN-eximdsn-MMMMMMMMMM/;
856
857 # ==========================================================
858 # Some munging is specific to the specific file types
859
860 # ======== stdout ========
861
862 if ($is_stdout)
863 {
864 # Skip translate_ip_address and use_classresources in -bP output because
865 # they aren't always there.
866
867 next if /translate_ip_address =/;
868 next if /use_classresources/;
869
870 # In certain filter tests, remove initial filter lines because they just
871 # clog up by repetition.
872
873 if ($rmfiltertest)
874 {
875 next if /^(Sender\staken\sfrom|
876 Return-path\scopied\sfrom|
877 Sender\s+=|
878 Recipient\s+=)/x;
879 if (/^Testing \S+ filter/)
880 {
881 $_ = <IN>; # remove blank line
882 next;
883 }
884 }
885
886 # openssl version variances
887 next if /^SSL info: unknown state/;
888 next if /^SSL info: SSLv2\/v3 write client hello A/;
889 next if /^SSL info: SSLv3 read server key exchange A/;
890 next if /SSL verify error: depth=0 error=certificate not trusted/;
891 s/SSL3_READ_BYTES/ssl3_read_bytes/;
892
893 # gnutls version variances
894 next if /^Error in the pull function./;
895 }
896
897 # ======== stderr ========
898
899 elsif ($is_stderr)
900 {
901 # The very first line of debugging output will vary
902
903 s/^Exim version .*/Exim version x.yz ..../;
904
905 # Debugging lines for Exim terminations
906
907 s/(?<=^>>>>>>>>>>>>>>>> Exim pid=)\d+(?= terminating)/pppp/;
908
909 # IP address lookups use gethostbyname() when IPv6 is not supported,
910 # and gethostbyname2() or getipnodebyname() when it is.
911
912 s/\b(gethostbyname2?|\bgetipnodebyname)(\(af=inet\))?/get[host|ipnode]byname[2]/;
913
914 # drop gnutls version strings
915 next if /GnuTLS compile-time version: \d+[\.\d]+$/;
916 next if /GnuTLS runtime version: \d+[\.\d]+$/;
917
918 # drop openssl version strings
919 next if /OpenSSL compile-time version: OpenSSL \d+[\.\da-z]+/;
920 next if /OpenSSL runtime version: OpenSSL \d+[\.\da-z]+/;
921
922 # drop lookups
923 next if /^Lookups \(built-in\):/;
924 next if /^Loading lookup modules from/;
925 next if /^Loaded \d+ lookup modules/;
926 next if /^Total \d+ lookups/;
927
928 # drop compiler information
929 next if /^Compiler:/;
930
931 # and the ugly bit
932 # different libraries will have different numbers (possibly 0) of follow-up
933 # lines, indenting with more data
934 if (/^Library version:/) {
935 while (1) {
936 $_ = <IN>;
937 next if /^\s/;
938 goto RESET_AFTER_EXTRA_LINE_READ;
939 }
940 }
941
942 # drop other build-time controls emitted for debugging
943 next if /^WHITELIST_D_MACROS:/;
944 next if /^TRUSTED_CONFIG_LIST:/;
945
946 # As of Exim 4.74, we log when a setgid fails; because we invoke Exim
947 # with -be, privileges will have been dropped, so this will always
948 # be the case
949 next if /^changing group to \d+ failed: (Operation not permitted|Not owner)/;
950
951 # We might not keep this check; rather than change all the tests, just
952 # ignore it as long as it succeeds; then we only need to change the
953 # TLS tests where tls_require_ciphers has been set.
954 if (m{^changed uid/gid: calling tls_validate_require_cipher}) {
955 my $discard = <IN>;
956 next;
957 }
958 next if /^tls_validate_require_cipher child \d+ ended: status=0x0/;
959
960 # We invoke Exim with -D, so we hit this new messag as of Exim 4.73:
961 next if /^macros_trusted overridden to true by whitelisting/;
962
963 # We have to omit the localhost ::1 address so that all is well in
964 # the IPv4-only case.
965
966 print MUNGED "MUNGED: ::1 will be omitted in what follows\n"
967 if (/looked up these IP addresses/);
968 next if /name=localhost address=::1/;
969
970 # drop pdkim debugging header
971 next if /^PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+$/;
972
973 # Various other IPv6 lines must be omitted too
974
975 next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
976 next if /get\[host\|ipnode\]byname\[2\]\(af=inet6\)/;
977 next if /DNS lookup of \S+ \(AAAA\) using fakens/;
978 next if / in dns_ipv4_lookup?/;
979
980 if (/DNS lookup of \S+ \(AAAA\) gave NO_DATA/)
981 {
982 $_= <IN>; # Gets "returning DNS_NODATA"
983 next;
984 }
985
986 # Skip tls_advertise_hosts and hosts_require_tls checks when the options
987 # are unset, because tls ain't always there.
988
989 next if /in\s(?:tls_advertise_hosts\?|hosts_require_tls\?)
990 \sno\s\((option\sunset|end\sof\slist)\)/x;
991
992 # Skip auxiliary group lists because they will vary.
993
994 next if /auxiliary group list:/;
995
996 # Skip "extracted from gecos field" because the gecos field varies
997
998 next if /extracted from gecos field/;
999
1000 # Skip "waiting for data on socket" and "read response data: size=" lines
1001 # because some systems pack more stuff into packets than others.
1002
1003 next if /waiting for data on socket/;
1004 next if /read response data: size=/;
1005
1006 # If Exim is compiled with readline support but it can't find the library
1007 # to load, there will be an extra debug line. Omit it.
1008
1009 next if /failed to load readline:/;
1010
1011 # Some DBM libraries seem to make DBM files on opening with O_RDWR without
1012 # O_CREAT; other's don't. In the latter case there is some debugging output
1013 # which is not present in the former. Skip the relevant lines (there are
1014 # two of them).
1015
1016 if (/TESTSUITE\/spool\/db\/\S+ appears not to exist: trying to create/)
1017 {
1018 $_ = <IN>;
1019 next;
1020 }
1021
1022 # Some tests turn on +expand debugging to check on expansions.
1023 # Unfortunately, the Received: expansion varies, depending on whether TLS
1024 # is compiled or not. So we must remove the relevant debugging if it is.
1025
1026 if (/^condition: def:tls_cipher/)
1027 {
1028 while (<IN>) { last if /^condition: def:sender_address/; }
1029 }
1030 elsif (/^expanding: Received: /)
1031 {
1032 while (<IN>) { last if !/^\s/; }
1033 }
1034
1035 # remote port numbers vary
1036 s/(Connection request from 127.0.0.1 port) \d{1,5}/$1 sssss/;
1037
1038 # Skip hosts_require_dane checks when the options
1039 # are unset, because dane ain't always there.
1040
1041 next if /in\shosts_require_dane\?\sno\s\(option\sunset\)/x;
1042
1043 # SUPPORT_PROXY
1044 next if /host in hosts_proxy\?/;
1045
1046 # Experimental_International
1047 next if / in smtputf8_advertise_hosts\? no \(option unset\)/;
1048
1049 # Environment cleaning
1050 next if /\w+ in keep_environment\? (yes|no)/;
1051
1052 # Sizes vary with test hostname
1053 s/^cmd buf flush \d+ bytes$/cmd buf flush ddd bytes/;
1054
1055 # Spool filesystem free space changes on different systems.
1056 s/^((?:spool|log) directory space =) -?\d+K (inodes =)\s*-?\d+/$1 nnnnnK $2 nnnnn/;
1057
1058 # Non-TLS builds have different expansions for received_header_text
1059 if (s/(with \$received_protocol)\}\} \$\{if def:tls_cipher \{\(\$tls_cipher\)\n$/$1/)
1060 {
1061 $_ .= <IN>;
1062 s/\s+\}\}(?=\(Exim )/\}\} /;
1063 }
1064 if (/^ condition: def:tls_cipher$/)
1065 {
1066 <IN>; <IN>; <IN>; <IN>; <IN>; <IN>;
1067 <IN>; <IN>; <IN>; <IN>; <IN>; next;
1068 }
1069
1070 # Not all platforms build with DKIM enabled
1071 next if /^PDKIM >> Body data for hash, canonicalized/;
1072
1073 # Not all platforms support TCP Fast Open, and the compile omits the check
1074 if (s/\S+ in hosts_try_fastopen\? no \(option unset\)\n$//)
1075 {
1076 $_ .= <IN>;
1077 s/ \.\.\. >>> / ... /;
1078 }
1079
1080 next if /^(ppppp )?setsockopt FASTOPEN: Protocol not available$/;
1081
1082 # When Exim is checking the size of directories for maildir, it uses
1083 # the check_dir_size() function to scan directories. Of course, the order
1084 # of the files that are obtained using readdir() varies from system to
1085 # system. We therefore buffer up debugging lines from check_dir_size()
1086 # and sort them before outputting them.
1087
1088 if (/^check_dir_size:/ || /^skipping TESTSUITE\/test-mail\//)
1089 {
1090 push @saved, $_;
1091 }
1092 else
1093 {
1094 if (@saved > 0)
1095 {
1096 print MUNGED "MUNGED: the check_dir_size lines have been sorted " .
1097 "to ensure consistency\n";
1098 @saved = sort(@saved);
1099 print MUNGED @saved;
1100 @saved = ();
1101 }
1102
1103 # Skip some lines that Exim puts out at the start of debugging output
1104 # because they will be different in different binaries.
1105
1106 print MUNGED
1107 unless (/^Berkeley DB: / ||
1108 /^Probably (?:Berkeley DB|ndbm|GDBM)/ ||
1109 /^Authenticators:/ ||
1110 /^Lookups:/ ||
1111 /^Support for:/ ||
1112 /^Routers:/ ||
1113 /^Transports:/ ||
1114 /^log selectors =/ ||
1115 /^cwd=/ ||
1116 /^Fixed never_users:/ ||
1117 /^Configure owner:/ ||
1118 /^Size of off_t:/
1119 );
1120
1121
1122 }
1123
1124 next;
1125 }
1126
1127 # ======== log ========
1128
1129 elsif ($is_log)
1130 {
1131 # Berkeley DB version differences
1132 next if / Berkeley DB error: /;
1133 }
1134
1135 # ======== All files other than stderr ========
1136
1137 print MUNGED;
1138 }
1139
1140close(IN);
1141return $yield;
1142}
1143
1144
1145
1146
1147##################################################
1148# Subroutine to interact with caller #
1149##################################################
1150
1151# Arguments: [0] the prompt string
1152# [1] if there is a U in the prompt and $force_update is true
1153# [2] if there is a C in the prompt and $force_continue is true
1154# Returns: returns the answer
1155
1156sub interact{
1157print $_[0];
1158if ($_[1]) { $_ = "u"; print "... update forced\n"; }
1159 elsif ($_[2]) { $_ = "c"; print "... continue forced\n"; }
1160 else { $_ = <T>; }
1161}
1162
1163
1164
1165##################################################
1166# Subroutine to log in force_continue mode #
1167##################################################
1168
1169# In force_continue mode, we just want a terse output to a statically
1170# named logfile. If multiple files in same batch (stdout, stderr, etc)
1171# all have mismatches, it will log multiple times.
1172#
1173# Arguments: [0] the logfile to append to
1174# [1] the testno that failed
1175# Returns: nothing
1176
1177
1178
1179sub log_failure {
1180 my $logfile = shift();
1181 my $testno = shift();
1182 my $detail = shift() || '';
1183 if ( open(my $fh, ">>", $logfile) ) {
1184 print $fh "Test $testno $detail failed\n";
1185 close $fh;
1186 }
1187}
1188
1189
1190
1191##################################################
1192# Subroutine to compare one output file #
1193##################################################
1194
1195# When an Exim server is part of the test, its output is in separate files from
1196# an Exim client. The server data is concatenated with the client data as part
1197# of the munging operation.
1198#
1199# Arguments: [0] the name of the main raw output file
1200# [1] the name of the server raw output file or undef
1201# [2] where to put the munged copy
1202# [3] the name of the saved file
1203# [4] TRUE if this is a log file whose deliveries must be sorted
1204# [5] optionally, a custom munge command
1205#
1206# Returns: 0 comparison succeeded or differences to be ignored
1207# 1 comparison failed; files may have been updated (=> re-compare)
1208#
1209# Does not return if the user replies "Q" to a prompt.
1210
1211sub check_file{
1212my($rf,$rsf,$mf,$sf,$sortfile,$extra) = @_;
1213
1214# If there is no saved file, the raw files must either not exist, or be
1215# empty. The test ! -s is TRUE if the file does not exist or is empty.
1216
1217# we check if there is a flavour specific file, but we remember
1218# the original file name as "generic"
1219$sf_generic = $sf;
1220$sf_flavour = "$sf_generic.$flavour";
1221$sf_current = -e $sf_flavour ? $sf_flavour : $sf_generic;
1222
1223if (! -e $sf_current)
1224 {
1225 return 0 if (! -s $rf && (! defined $rsf || ! -s $rsf));
1226
1227 print "\n";
1228 print "** $rf is not empty\n" if (-s $rf);
1229 print "** $rsf is not empty\n" if (defined $rsf && -s $rsf);
1230
1231 for (;;)
1232 {
1233 print "Continue, Show, or Quit? [Q] ";
1234 $_ = $force_continue ? "c" : <T>;
1235 tests_exit(1) if /^q?$/i;
1236 log_failure($log_failed_filename, $testno, $rf) if (/^c$/i && $force_continue);
1237 return 0 if /^c$/i;
1238 last if (/^s$/);
1239 }
1240
1241 foreach $f ($rf, $rsf)
1242 {
1243 if (defined $f && -s $f)
1244 {
1245 print "\n";
1246 print "------------ $f -----------\n"
1247 if (defined $rf && -s $rf && defined $rsf && -s $rsf);
1248 system("$more '$f'");
1249 }
1250 }
1251
1252 print "\n";
1253 for (;;)
1254 {
1255 interact("Continue, Update & retry, Quit? [Q] ", $force_update, $force_continue);
1256 tests_exit(1) if /^q?$/i;
1257 log_failure($log_failed_filename, $testno, $rsf) if (/^c$/i && $force_continue);
1258 return 0 if /^c$/i;
1259 last if (/^u$/i);
1260 }
1261 }
1262
1263#### $_
1264
1265# Control reaches here if either (a) there is a saved file ($sf), or (b) there
1266# was a request to create a saved file. First, create the munged file from any
1267# data that does exist.
1268
1269open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
1270my($truncated) = munge($rf, $extra) if -e $rf;
1271if (defined $rsf && -e $rsf)
1272 {
1273 print MUNGED "\n******** SERVER ********\n";
1274 $truncated |= munge($rsf, $extra);
1275 }
1276close(MUNGED);
1277
1278# If a saved file exists, do the comparison. There are two awkward cases:
1279#
1280# If "*** truncated ***" was found in the new file, it means that a log line
1281# was overlong, and truncated. The problem is that it may be truncated at
1282# different points on different systems, because of different user name
1283# lengths. We reload the file and the saved file, and remove lines from the new
1284# file that precede "*** truncated ***" until we reach one that matches the
1285# line that precedes it in the saved file.
1286#
1287# If $sortfile is set, we are dealing with a mainlog file where the deliveries
1288# for an individual message might vary in their order from system to system, as
1289# a result of parallel deliveries. We load the munged file and sort sequences
1290# of delivery lines.
1291
1292if (-e $sf_current)
1293 {
1294 # Deal with truncated text items
1295
1296 if ($truncated)
1297 {
1298 my(@munged, @saved, $i, $j, $k);
1299
1300 open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
1301 @munged = <MUNGED>;
1302 close(MUNGED);
1303 open(SAVED, $sf_current) || tests_exit(-1, "Failed to open $sf_current: $!");
1304 @saved = <SAVED>;
1305 close(SAVED);
1306
1307 $j = 0;
1308 for ($i = 0; $i < @munged; $i++)
1309 {
1310 if ($munged[$i] =~ /\*\*\* truncated \*\*\*/)
1311 {
1312 for (; $j < @saved; $j++)
1313 { last if $saved[$j] =~ /\*\*\* truncated \*\*\*/; }
1314 last if $j >= @saved; # not found in saved
1315
1316 for ($k = $i - 1; $k >= 0; $k--)
1317 { last if $munged[$k] eq $saved[$j - 1]; }
1318
1319 last if $k <= 0; # failed to find previous match
1320 splice @munged, $k + 1, $i - $k - 1;
1321 $i = $k + 1;
1322 }
1323 }
1324
1325 open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
1326 for ($i = 0; $i < @munged; $i++)
1327 { print MUNGED $munged[$i]; }
1328 close(MUNGED);
1329 }
1330
1331 # Deal with log sorting
1332
1333 if ($sortfile)
1334 {
1335 my(@munged, $i, $j);
1336
1337 open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
1338 @munged = <MUNGED>;
1339 close(MUNGED);
1340
1341 for ($i = 0; $i < @munged; $i++)
1342 {
1343 if ($munged[$i] =~ /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/)
1344 {
1345 for ($j = $i + 1; $j < @munged; $j++)
1346 {
1347 last if $munged[$j] !~
1348 /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/;
1349 }
1350 @temp = splice(@munged, $i, $j - $i);
1351 @temp = sort(@temp);
1352 splice(@munged, $i, 0, @temp);
1353 }
1354 }
1355
1356 open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
1357 print MUNGED "**NOTE: The delivery lines in this file have been sorted.\n";
1358 for ($i = 0; $i < @munged; $i++)
1359 { print MUNGED $munged[$i]; }
1360 close(MUNGED);
1361 }
1362
1363 # Do the comparison
1364
1365 return 0 if (system("$cf '$mf' '$sf_current' >test-cf") == 0);
1366
1367 # Handle comparison failure
1368
1369 print "** Comparison of $mf with $sf_current failed";
1370 system("$more test-cf");
1371
1372 print "\n";
1373 for (;;)
1374 {
1375 interact("Continue, Retry, Update current"
1376 . ($sf_current ne $sf_flavour ? "/Save for flavour '$flavour'" : "")
1377 . " & retry, Quit? [Q] ", $force_update, $force_continue);
1378 tests_exit(1) if /^q?$/i;
1379 log_failure($log_failed_filename, $testno, $sf_current) if (/^c$/i && $force_continue);
1380 return 0 if /^c$/i;
1381 return 1 if /^r$/i;
1382 last if (/^[us]$/i);
1383 }
1384 }
1385
1386# Update or delete the saved file, and give the appropriate return code.
1387
1388if (-s $mf)
1389 {
1390 my $sf = /^u/i ? $sf_current : $sf_flavour;
1391 tests_exit(-1, "Failed to cp $mf $sf") if system("cp '$mf' '$sf'") != 0;
1392 }
1393else
1394 {
1395 # if we deal with a flavour file, we can't delete it, because next time the generic
1396 # file would be used again
1397 if ($sf_current eq $sf_flavour) {
1398 open(FOO, ">$sf_current");
1399 close(FOO);
1400 }
1401 else {
1402 tests_exit(-1, "Failed to unlink $sf_current") if !unlink($sf_current);
1403 }
1404 }
1405
1406return 1;
1407}
1408
1409
1410
1411##################################################
1412# Custom munges
1413# keyed by name of munge; value is a ref to a hash
1414# which is keyed by file, value a string to look for.
1415# Usable files are:
1416# paniclog, rejectlog, mainlog, stdout, stderr, msglog, mail
1417# Search strings starting with 's' do substitutions;
1418# with '/' do line-skips.
1419# Triggered by a scriptfile line "munge <name>"
1420##################################################
1421$munges =
1422 { 'dnssec' =>
1423 { 'stderr' => '/^Reverse DNS security status: unverified\n/' },
1424
1425 'gnutls_unexpected' =>
1426 { 'mainlog' => '/\(recv\): A TLS packet with unexpected length was received./' },
1427
1428 'gnutls_handshake' =>
1429 { 'mainlog' => 's/\(gnutls_handshake\): Error in the push function/\(gnutls_handshake\): A TLS packet with unexpected length was received/' },
1430
1431 'optional_events' =>
1432 { 'stdout' => '/event_action =/' },
1433
1434 'optional_ocsp' =>
1435 { 'stderr' => '/127.0.0.1 in hosts_requ(ire|est)_ocsp/' },
1436
1437 'optional_cert_hostnames' =>
1438 { 'stderr' => '/in tls_verify_cert_hostnames\? no/' },
1439
1440 'loopback' =>
1441 { 'stdout' => 's/[[](127\.0\.0\.1|::1)]/[IP_LOOPBACK_ADDR]/' },
1442
1443 'scanfile_size' =>
1444 { 'stdout' => 's/(Content-length:) \d\d\d/$1 ddd/' },
1445
1446 'delay_1500' =>
1447 { 'stderr' => 's/(1[5-9]|23\d)\d\d msec/ssss msec/' },
1448
1449 'tls_anycipher' =>
1450 { 'mainlog' => 's/ X=TLS\S+ / X=TLS_proto_and_cipher /' },
1451
1452 'debug_pid' =>
1453 { 'stderr' => 's/(^\s{0,4}|(?<=Process )|(?<=child ))\d{1,5}/ppppp/g' },
1454
1455 'optional_dsn_info' =>
1456 { 'mail' => '/^(X-(Remote-MTA-(smtp-greeting|helo-response)|Exim-Diagnostic|(body|message)-linecount):|Remote-MTA: X-ip;)/'
1457 },
1458
1459 'optional_config' =>
1460 { 'stdout' => '/^(
1461 dkim_(canon|domain|private_key|selector|sign_headers|strict)
1462 |gnutls_require_(kx|mac|protocols)
1463 |hosts_(requ(est|ire)|try)_(dane|ocsp)
1464 |hosts_(avoid|nopass|require|verify_avoid)_tls
1465 |socks_proxy
1466 |tls_[^ ]*
1467 )($|[ ]=)/x' },
1468
1469 'sys_bindir' =>
1470 { 'mainlog' => 's%/(usr/)?bin/%SYSBINDIR/%' },
1471
1472 'sync_check_data' =>
1473 { 'mainlog' => 's/^(.* SMTP protocol synchronization error .* next input=.{8}).*$/$1<suppressed>/',
1474 'rejectlog' => 's/^(.* SMTP protocol synchronization error .* next input=.{8}).*$/$1<suppressed>/'},
1475
1476 'debuglog_stdout' =>
1477 { 'stdout' => 's/^\d\d:\d\d:\d\d\s+\d+ //;
1478 s/Process \d+ is ready for new message/Process pppp is ready for new message/'
1479 },
1480
1481 'timeout_errno' => # actual errno differs Solaris vs. Linux
1482 { 'mainlog' => 's/(host deferral .* errno) <\d+> /$1 <EEE> /' },
1483 };
1484
1485
1486##################################################
1487# Subroutine to check the output of a test #
1488##################################################
1489
1490# This function is called when the series of subtests is complete. It makes
1491# use of check_file(), whose arguments are:
1492#
1493# [0] the name of the main raw output file
1494# [1] the name of the server raw output file or undef
1495# [2] where to put the munged copy
1496# [3] the name of the saved file
1497# [4] TRUE if this is a log file whose deliveries must be sorted
1498# [5] an optional custom munge command
1499#
1500# Arguments: Optionally, name of a single custom munge to run.
1501# Returns: 0 if the output compared equal
1502# 1 if re-run needed (files may have been updated)
1503
1504sub check_output{
1505my($mungename) = $_[0];
1506my($yield) = 0;
1507my($munge) = $munges->{$mungename} if defined $mungename;
1508
1509$yield = 1 if check_file("spool/log/paniclog",
1510 "spool/log/serverpaniclog",
1511 "test-paniclog-munged",
1512 "paniclog/$testno", 0,
1513 $munge->{'paniclog'});
1514
1515$yield = 1 if check_file("spool/log/rejectlog",
1516 "spool/log/serverrejectlog",
1517 "test-rejectlog-munged",
1518 "rejectlog/$testno", 0,
1519 $munge->{'rejectlog'});
1520
1521$yield = 1 if check_file("spool/log/mainlog",
1522 "spool/log/servermainlog",
1523 "test-mainlog-munged",
1524 "log/$testno", $sortlog,
1525 $munge->{'mainlog'});
1526
1527if (!$stdout_skip)
1528 {
1529 $yield = 1 if check_file("test-stdout",
1530 "test-stdout-server",
1531 "test-stdout-munged",
1532 "stdout/$testno", 0,
1533 $munge->{'stdout'});
1534 }
1535
1536if (!$stderr_skip)
1537 {
1538 $yield = 1 if check_file("test-stderr",
1539 "test-stderr-server",
1540 "test-stderr-munged",
1541 "stderr/$testno", 0,
1542 $munge->{'stderr'});
1543 }
1544
1545# Compare any delivered messages, unless this test is skipped.
1546
1547if (! $message_skip)
1548 {
1549 my($msgno) = 0;
1550
1551 # Get a list of expected mailbox files for this script. We don't bother with
1552 # directories, just the files within them.
1553
1554 foreach $oldmail (@oldmails)
1555 {
1556 next unless $oldmail =~ /^mail\/$testno\./;
1557 print ">> EXPECT $oldmail\n" if $debug;
1558 $expected_mails{$oldmail} = 1;
1559 }
1560
1561 # If there are any files in test-mail, compare them. Note that "." and
1562 # ".." are automatically omitted by list_files_below().
1563
1564 @mails = list_files_below("test-mail");
1565
1566 foreach $mail (@mails)
1567 {
1568 next if $mail eq "test-mail/oncelog";
1569
1570 $saved_mail = substr($mail, 10); # Remove "test-mail/"
1571 $saved_mail =~ s/^$parm_caller(\/|$)/CALLER/; # Convert caller name
1572
1573 if ($saved_mail =~ /(\d+\.[^.]+\.)/)
1574 {
1575 $msgno++;
1576 $saved_mail =~ s/(\d+\.[^.]+\.)/$msgno./gx;
1577 }
1578
1579 print ">> COMPARE $mail mail/$testno.$saved_mail\n" if $debug;
1580 $yield = 1 if check_file($mail, undef, "test-mail-munged",
1581 "mail/$testno.$saved_mail", 0,
1582 $munge->{'mail'});
1583 delete $expected_mails{"mail/$testno.$saved_mail"};
1584 }
1585
1586 # Complain if not all expected mails have been found
1587
1588 if (scalar(keys %expected_mails) != 0)
1589 {
1590 foreach $key (keys %expected_mails)
1591 { print "** no test file found for $key\n"; }
1592
1593 for (;;)
1594 {
1595 interact("Continue, Update & retry, or Quit? [Q] ", $force_update, $force_continue);
1596 tests_exit(1) if /^q?$/i;
1597 log_failure($log_failed_filename, $testno, "missing email") if (/^c$/i && $force_continue);
1598 last if /^c$/i;
1599
1600 # For update, we not only have to unlink the file, but we must also
1601 # remove it from the @oldmails vector, as otherwise it will still be
1602 # checked for when we re-run the test.
1603
1604 if (/^u$/i)
1605 {
1606 foreach $key (keys %expected_mails)
1607 {
1608 my($i);
1609 tests_exit(-1, "Failed to unlink $key") if !unlink("$key");
1610 for ($i = 0; $i < @oldmails; $i++)
1611 {
1612 if ($oldmails[$i] eq $key)
1613 {
1614 splice @oldmails, $i, 1;
1615 last;
1616 }
1617 }
1618 }
1619 last;
1620 }
1621 }
1622 }
1623 }
1624
1625# Compare any remaining message logs, unless this test is skipped.
1626
1627if (! $msglog_skip)
1628 {
1629 # Get a list of expected msglog files for this test
1630
1631 foreach $oldmsglog (@oldmsglogs)
1632 {
1633 next unless $oldmsglog =~ /^$testno\./;
1634 $expected_msglogs{$oldmsglog} = 1;
1635 }
1636
1637 # If there are any files in spool/msglog, compare them. However, we have
1638 # to munge the file names because they are message ids, which are
1639 # time dependent.
1640
1641 if (opendir(DIR, "spool/msglog"))
1642 {
1643 @msglogs = sort readdir(DIR);
1644 closedir(DIR);
1645
1646 foreach $msglog (@msglogs)
1647 {
1648 next if ($msglog eq "." || $msglog eq ".." || $msglog eq "CVS");
1649 ($munged_msglog = $msglog) =~
1650 s/((?:[^\W_]{6}-){2}[^\W_]{2})
1651 /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
1652 $yield = 1 if check_file("spool/msglog/$msglog", undef,
1653 "test-msglog-munged", "msglog/$testno.$munged_msglog", 0,
1654 $munge->{'msglog'});
1655 delete $expected_msglogs{"$testno.$munged_msglog"};
1656 }
1657 }
1658
1659 # Complain if not all expected msglogs have been found
1660
1661 if (scalar(keys %expected_msglogs) != 0)
1662 {
1663 foreach $key (keys %expected_msglogs)
1664 {
1665 print "** no test msglog found for msglog/$key\n";
1666 ($msgid) = $key =~ /^\d+\.(.*)$/;
1667 foreach $cachekey (keys %cache)
1668 {
1669 if ($cache{$cachekey} eq $msgid)
1670 {
1671 print "** original msgid $cachekey\n";
1672 last;
1673 }
1674 }
1675 }
1676
1677 for (;;)
1678 {
1679 interact("Continue, Update, or Quit? [Q] ", $force_update, $force_continue);
1680 tests_exit(1) if /^q?$/i;
1681 log_failure($log_failed_filename, $testno, "missing msglog") if (/^c$/i && $force_continue);
1682 last if /^c$/i;
1683 if (/^u$/i)
1684 {
1685 foreach $key (keys %expected_msglogs)
1686 {
1687 tests_exit(-1, "Failed to unlink msglog/$key")
1688 if !unlink("msglog/$key");
1689 }
1690 last;
1691 }
1692 }
1693 }
1694 }
1695
1696return $yield;
1697}
1698
1699
1700
1701##################################################
1702# Subroutine to run one "system" command #
1703##################################################
1704
1705# We put this in a subroutine so that the command can be reflected when
1706# debugging.
1707#
1708# Argument: the command to be run
1709# Returns: nothing
1710
1711sub run_system {
1712my($cmd) = $_[0];
1713if ($debug)
1714 {
1715 my($prcmd) = $cmd;
1716 $prcmd =~ s/; /;\n>> /;
1717 print ">> $prcmd\n";
1718 }
1719system("$cmd");
1720}
1721
1722
1723
1724##################################################
1725# Subroutine to run one script command #
1726##################################################
1727
1728# The <SCRIPT> file is open for us to read an optional return code line,
1729# followed by the command line and any following data lines for stdin. The
1730# command line can be continued by the use of \. Data lines are not continued
1731# in this way. In all lines, the following substutions are made:
1732#
1733# DIR => the current directory
1734# CALLER => the caller of this script
1735#
1736# Arguments: the current test number
1737# reference to the subtest number, holding previous value
1738# reference to the expected return code value
1739# reference to where to put the command name (for messages)
1740# auxilliary information returned from a previous run
1741#
1742# Returns: 0 the commmand was executed inline, no subprocess was run
1743# 1 a non-exim command was run and waited for
1744# 2 an exim command was run and waited for
1745# 3 a command was run and not waited for (daemon, server, exim_lock)
1746# 4 EOF was encountered after an initial return code line
1747# Optionally alse a second parameter, a hash-ref, with auxilliary information:
1748# exim_pid: pid of a run process
1749# munge: name of a post-script results munger
1750
1751sub run_command{
1752my($testno) = $_[0];
1753my($subtestref) = $_[1];
1754my($commandnameref) = $_[3];
1755my($aux_info) = $_[4];
1756my($yield) = 1;
1757
1758our %ENV = map { $_ => $ENV{$_} } grep { /^(?:USER|SHELL|PATH|TERM|EXIM_TEST_.*)$/ } keys %ENV;
1759
1760if (/^(\d+)\s*$/) # Handle unusual return code
1761 {
1762 my($r) = $_[2];
1763 $$r = $1 << 8;
1764 $_ = <SCRIPT>;
1765 return 4 if !defined $_; # Missing command
1766 $lineno++;
1767 }
1768
1769chomp;
1770$wait_time = 0;
1771
1772# Handle concatenated command lines
1773
1774s/\s+$//;
1775while (substr($_, -1) eq"\\")
1776 {
1777 my($temp);
1778 $_ = substr($_, 0, -1);
1779 chomp($temp = <SCRIPT>);
1780 if (defined $temp)
1781 {
1782 $lineno++;
1783 $temp =~ s/\s+$//;
1784 $temp =~ s/^\s+//;
1785 $_ .= $temp;
1786 }
1787 }
1788
1789# Do substitutions
1790
1791do_substitute($testno);
1792if ($debug) { printf ">> $_\n"; }
1793
1794# Pass back the command name (for messages)
1795
1796($$commandnameref) = /^(\S+)/;
1797
1798# Here follows code for handling the various different commands that are
1799# supported by this script. The first group of commands are all freestanding
1800# in that they share no common code and are not followed by any data lines.
1801
1802
1803###################
1804###################
1805
1806# The "dbmbuild" command runs exim_dbmbuild. This is used both to test the
1807# utility and to make DBM files for testing DBM lookups.
1808
1809if (/^dbmbuild\s+(\S+)\s+(\S+)/)
1810 {
1811 run_system("(./eximdir/exim_dbmbuild $parm_cwd/$1 $parm_cwd/$2;" .
1812 "echo exim_dbmbuild exit code = \$?)" .
1813 ">>test-stdout");
1814 return 1;
1815 }
1816
1817
1818# The "dump" command runs exim_dumpdb. On different systems, the output for
1819# some types of dump may appear in a different order because it's just hauled
1820# out of the DBM file. We can solve this by sorting. Ignore the leading
1821# date/time, as it will be flattened later during munging.
1822
1823if (/^dump\s+(\S+)/)
1824 {
1825 my($which) = $1;
1826 my(@temp);
1827 print ">> ./eximdir/exim_dumpdb $parm_cwd/spool $which\n" if $debug;
1828 open(IN, "./eximdir/exim_dumpdb $parm_cwd/spool $which |");
1829 open(OUT, ">>test-stdout");
1830 print OUT "+++++++++++++++++++++++++++\n";
1831
1832 if ($which eq "retry")
1833 {
1834 $/ = "\n ";
1835 @temp = <IN>;
1836 $/ = "\n";
1837
1838 @temp = sort {
1839 my($aa) = split(' ', $a);
1840 my($bb) = split(' ', $b);
1841 return $aa cmp $bb;
1842 } @temp;
1843
1844 foreach $item (@temp)
1845 {
1846 $item =~ s/^\s*(.*)\n(.*)\n?\s*$/$1\n$2/m;
1847 print OUT " $item\n";
1848 }
1849 }
1850 else
1851 {
1852 @temp = <IN>;
1853 if ($which eq "callout")
1854 {
1855 @temp = sort {
1856 my($aa) = substr $a, 21;
1857 my($bb) = substr $b, 21;
1858 return $aa cmp $bb;
1859 } @temp;
1860 }
1861 print OUT @temp;
1862 }
1863
1864 close(IN);
1865 close(OUT);
1866 return 1;
1867 }
1868
1869
1870# The "echo" command is a way of writing comments to the screen.
1871
1872if (/^echo\s+(.*)$/)
1873 {
1874 print "$1\n";
1875 return 0;
1876 }
1877
1878
1879# The "exim_lock" command runs exim_lock in the same manner as "server",
1880# but it doesn't use any input.
1881
1882if (/^exim_lock\s+(.*)$/)
1883 {
1884 $cmd = "./eximdir/exim_lock $1 >>test-stdout";
1885 $server_pid = open SERVERCMD, "|$cmd" ||
1886 tests_exit(-1, "Failed to run $cmd\n");
1887
1888 # This gives the process time to get started; otherwise the next
1889 # process may not find it there when it expects it.
1890
1891 select(undef, undef, undef, 0.1);
1892 return 3;
1893 }
1894
1895
1896# The "exinext" command runs exinext
1897
1898if (/^exinext\s+(.*)/)
1899 {
1900 run_system("(./eximdir/exinext " .
1901 "-DEXIM_PATH=$parm_cwd/eximdir/exim " .
1902 "-C $parm_cwd/test-config $1;" .
1903 "echo exinext exit code = \$?)" .
1904 ">>test-stdout");
1905 return 1;
1906 }
1907
1908
1909# The "exigrep" command runs exigrep on the current mainlog
1910
1911if (/^exigrep\s+(.*)/)
1912 {
1913 run_system("(./eximdir/exigrep " .
1914 "$1 $parm_cwd/spool/log/mainlog;" .
1915 "echo exigrep exit code = \$?)" .
1916 ">>test-stdout");
1917 return 1;
1918 }
1919
1920
1921# The "eximstats" command runs eximstats on the current mainlog
1922
1923if (/^eximstats\s+(.*)/)
1924 {
1925 run_system("(./eximdir/eximstats " .
1926 "$1 $parm_cwd/spool/log/mainlog;" .
1927 "echo eximstats exit code = \$?)" .
1928 ">>test-stdout");
1929 return 1;
1930 }
1931
1932
1933# The "gnutls" command makes a copy of saved GnuTLS parameter data in the
1934# spool directory, to save Exim from re-creating it each time.
1935
1936if (/^gnutls/)
1937 {
1938 my $gen_fn = "spool/gnutls-params-$gnutls_dh_bits_normal";
1939 run_system "sudo cp -p aux-fixed/gnutls-params $gen_fn;" .
1940 "sudo chown $parm_eximuser:$parm_eximgroup $gen_fn;" .
1941 "sudo chmod 0400 $gen_fn";
1942 return 1;
1943 }
1944
1945
1946# The "killdaemon" command should ultimately follow the starting of any Exim
1947# daemon with the -bd option. We kill with SIGINT rather than SIGTERM to stop
1948# it outputting "Terminated" to the terminal when not in the background.
1949
1950if (/^killdaemon/)
1951 {
1952 my $return_extra = {};
1953 if (exists $aux_info->{exim_pid})
1954 {
1955 $pid = $aux_info->{exim_pid};
1956 $return_extra->{exim_pid} = undef;
1957 print ">> killdaemon: recovered pid $pid\n" if $debug;
1958 if ($pid)
1959 {
1960 run_system("sudo /bin/kill -INT $pid");
1961 wait;
1962 }
1963 } else {
1964 $pid = `cat $parm_cwd/spool/exim-daemon.*`;
1965 if ($pid)
1966 {
1967 run_system("sudo /bin/kill -INT $pid");
1968 close DAEMONCMD; # Waits for process
1969 }
1970 }
1971 run_system("sudo /bin/rm -f spool/exim-daemon.*");
1972 return (1, $return_extra);
1973 }
1974
1975
1976# The "millisleep" command is like "sleep" except that its argument is in
1977# milliseconds, thus allowing for a subsecond sleep, which is, in fact, all it
1978# is used for.
1979
1980elsif (/^millisleep\s+(.*)$/)
1981 {
1982 select(undef, undef, undef, $1/1000);
1983 return 0;
1984 }
1985
1986
1987# The "munge" command selects one of a hardwired set of test-result modifications
1988# to be made before result compares are run agains the golden set. This lets
1989# us account for test-system dependent things which only affect a few, but known,
1990# test-cases.
1991# Currently only the last munge takes effect.
1992
1993if (/^munge\s+(.*)$/)
1994 {
1995 return (0, { munge => $1 });
1996 }
1997
1998
1999# The "sleep" command does just that. For sleeps longer than 1 second we
2000# tell the user what's going on.
2001
2002if (/^sleep\s+(.*)$/)
2003 {
2004 if ($1 == 1)
2005 {
2006 sleep(1);
2007 }
2008 else
2009 {
2010 printf(" Test %d sleep $1 ", $$subtestref);
2011 for (1..$1)
2012 {
2013 print ".";
2014 sleep(1);
2015 }
2016 printf("\r Test %d $cr", $$subtestref);
2017 }
2018 return 0;
2019 }
2020
2021
2022# Various Unix management commands are recognized
2023
2024if (/^(ln|ls|du|mkdir|mkfifo|touch|cp|cat)\s/ ||
2025 /^sudo\s(rmdir|rm|mv|chown|chmod)\s/)
2026 {
2027 run_system("$_ >>test-stdout 2>>test-stderr");
2028 return 1;
2029 }
2030
2031
2032
2033###################
2034###################
2035
2036# The next group of commands are also freestanding, but they are all followed
2037# by data lines.
2038
2039
2040# The "server" command starts up a script-driven server that runs in parallel
2041# with the following exim command. Therefore, we want to run a subprocess and
2042# not yet wait for it to complete. The waiting happens after the next exim
2043# command, triggered by $server_pid being non-zero. The server sends its output
2044# to a different file. The variable $server_opts, if not empty, contains
2045# options to disable IPv4 or IPv6 if necessary.
2046# This works because "server" swallows its stdin before waiting for a connection.
2047
2048if (/^server\s+(.*)$/)
2049 {
2050 $pidfile = "$parm_cwd/aux-var/server-daemon.pid";
2051 $cmd = "./bin/server $server_opts -oP $pidfile $1 >>test-stdout-server";
2052 print ">> $cmd\n" if ($debug);
2053 $server_pid = open SERVERCMD, "|$cmd" || tests_exit(-1, "Failed to run $cmd");
2054 SERVERCMD->autoflush(1);
2055 print ">> Server pid is $server_pid\n" if $debug;
2056 while (<SCRIPT>)
2057 {
2058 $lineno++;
2059 last if /^\*{4}\s*$/;
2060 print SERVERCMD;
2061 }
2062 print SERVERCMD "++++\n"; # Send end to server; can't send EOF yet
2063 # because close() waits for the process.
2064
2065 # Interlock the server startup; otherwise the next
2066 # process may not find it there when it expects it.
2067 while (! stat("$pidfile") ) { select(undef, undef, undef, 0.3); }
2068 return 3;
2069 }
2070
2071
2072# The "write" command is a way of creating files of specific sizes for
2073# buffering tests, or containing specific data lines from within the script
2074# (rather than hold lots of little files). The "catwrite" command does the
2075# same, but it also copies the lines to test-stdout.
2076
2077if (/^(cat)?write\s+(\S+)(?:\s+(.*))?\s*$/)
2078 {
2079 my($cat) = defined $1;
2080 @sizes = ();
2081 @sizes = split /\s+/, $3 if defined $3;
2082 open FILE, ">$2" || tests_exit(-1, "Failed to open \"$2\": $!");
2083
2084 if ($cat)
2085 {
2086 open CAT, ">>test-stdout" ||
2087 tests_exit(-1, "Failed to open test-stdout: $!");
2088 print CAT "==========\n";
2089 }
2090
2091 if (scalar @sizes > 0)
2092 {
2093 # Pre-data
2094
2095 while (<SCRIPT>)
2096 {
2097 $lineno++;
2098 last if /^\+{4}\s*$/;
2099 print FILE;
2100 print CAT if $cat;
2101 }
2102
2103 # Sized data
2104
2105 while (scalar @sizes > 0)
2106 {
2107 ($count,$len,$leadin) = (shift @sizes) =~ /(\d+)x(\d+)(?:=(.*))?/;
2108 $leadin = "" if !defined $leadin;
2109 $leadin =~ s/_/ /g;
2110 $len -= length($leadin) + 1;
2111 while ($count-- > 0)
2112 {
2113 print FILE $leadin, "a" x $len, "\n";
2114 print CAT $leadin, "a" x $len, "\n" if $cat;
2115 }
2116 }
2117 }
2118
2119 # Post data, or only data if no sized data
2120
2121 while (<SCRIPT>)
2122 {
2123 $lineno++;
2124 last if /^\*{4}\s*$/;
2125 print FILE;
2126 print CAT if $cat;
2127 }
2128 close FILE;
2129
2130 if ($cat)
2131 {
2132 print CAT "==========\n";
2133 close CAT;
2134 }
2135
2136 return 0;
2137 }
2138
2139
2140###################
2141###################
2142
2143# From this point on, script commands are implemented by setting up a shell
2144# command in the variable $cmd. Shared code to run this command and handle its
2145# input and output follows.
2146
2147# The "client", "client-gnutls", and "client-ssl" commands run a script-driven
2148# program that plays the part of an email client. We also have the availability
2149# of running Perl for doing one-off special things. Note that all these
2150# commands expect stdin data to be supplied.
2151
2152if (/^client/ || /^(sudo\s+)?perl\b/)
2153 {
2154 s"client"./bin/client";
2155 $cmd = "$_ >>test-stdout 2>>test-stderr";
2156 }
2157
2158# For the "exim" command, replace the text "exim" with the path for the test
2159# binary, plus -D options to pass over various parameters, and a -C option for
2160# the testing configuration file. When running in the test harness, Exim does
2161# not drop privilege when -C and -D options are present. To run the exim
2162# command as root, we use sudo.
2163
2164elsif (/^((?i:[A-Z\d_]+=\S+\s+)+)?(\d+)?\s*(sudo(?:\s+-u\s+(\w+))?\s+)?exim(_\S+)?\s+(.*)$/)
2165 {
2166 $args = $6;
2167 my($envset) = (defined $1)? $1 : "";
2168 my($sudo) = (defined $3)? "sudo " . (defined $4 ? "-u $4 ":"") : "";
2169 my($special)= (defined $5)? $5 : "";
2170 $wait_time = (defined $2)? $2 : 0;
2171
2172 # Return 2 rather than 1 afterwards
2173
2174 $yield = 2;
2175
2176 # Update the test number
2177
2178 $$subtestref = $$subtestref + 1;
2179 printf(" Test %d $cr", $$subtestref);
2180
2181 # Copy the configuration file, making the usual substitutions.
2182
2183 open (IN, "$parm_cwd/confs/$testno") ||
2184 tests_exit(-1, "Couldn't open $parm_cwd/confs/$testno: $!\n");
2185 open (OUT, ">test-config") ||
2186 tests_exit(-1, "Couldn't open test-config: $!\n");
2187 while (<IN>)
2188 {
2189 do_substitute($testno);
2190 print OUT;
2191 }
2192 close(IN);
2193 close(OUT);
2194
2195 # The string $msg1 in args substitutes the message id of the first
2196 # message on the queue, and so on. */
2197
2198 if ($args =~ /\$msg/)
2199 {
2200 my($listcmd) = "$parm_cwd/eximdir/exim -bp " .
2201 "-DEXIM_PATH=$parm_cwd/eximdir/exim " .
2202 "-C $parm_cwd/test-config |";
2203 print ">> Getting queue list from:\n>> $listcmd\n" if ($debug);
2204 open (QLIST, $listcmd) || tests_exit(-1, "Couldn't run \"exim -bp\": $!\n");
2205 my(@msglist) = ();
2206 while (<QLIST>) { push (@msglist, $1) if /^\s*\d+[smhdw]\s+\S+\s+(\S+)/; }
2207 close(QLIST);
2208
2209 # Done backwards just in case there are more than 9
2210
2211 for (my $i = @msglist; $i > 0; $i--) { $args =~ s/\$msg$i/$msglist[$i-1]/g; }
2212 if ( $args =~ /\$msg\d/ )
2213 {
2214 tests_exit(-1, "Not enough messages in spool, for test $testno line $lineno\n")
2215 unless $force_continue;
2216 }
2217 }
2218
2219 # If -d is specified in $optargs, remove it from $args; i.e. let
2220 # the command line for runtest override. Then run Exim.
2221
2222 $args =~ s/(?:^|\s)-d\S*// if $optargs =~ /(?:^|\s)-d/;
2223
2224 my $opt_valgrind = $valgrind ? "valgrind --leak-check=yes --suppressions=$parm_cwd/aux-fixed/valgrind.supp " : "";
2225
2226 $cmd = "$envset$sudo$opt_valgrind" .
2227 "$parm_cwd/eximdir/exim$special$optargs " .
2228 "-DEXIM_PATH=$parm_cwd/eximdir/exim$special " .
2229 "-C $parm_cwd/test-config $args " .
2230 ">>test-stdout 2>>test-stderr";
2231 # If the command is starting an Exim daemon, we run it in the same
2232 # way as the "server" command above, that is, we don't want to wait
2233 # for the process to finish. That happens when "killdaemon" is obeyed later
2234 # in the script. We also send the stderr output to test-stderr-server. The
2235 # daemon has its log files put in a different place too (by configuring with
2236 # log_file_path). This requires the directory to be set up in advance.
2237 #
2238 # There are also times when we want to run a non-daemon version of Exim
2239 # (e.g. a queue runner) with the server configuration. In this case,
2240 # we also define -DNOTDAEMON.
2241
2242 if ($cmd =~ /\s-DSERVER=server\s/ && $cmd !~ /\s-DNOTDAEMON\s/)
2243 {
2244 $pidfile = "$parm_cwd/spool/exim-daemon.pid";
2245 if ($debug) { printf ">> daemon: $cmd\n"; }
2246 run_system("sudo mkdir spool/log 2>/dev/null");
2247 run_system("sudo chown $parm_eximuser:$parm_eximgroup spool/log");
2248
2249 # Before running the command, convert the -bd option into -bdf so that an
2250 # Exim daemon doesn't double fork. This means that when we wait close
2251 # DAEMONCMD, it waits for the correct process. Also, ensure that the pid
2252 # file is written to the spool directory, in case the Exim binary was
2253 # built with PID_FILE_PATH pointing somewhere else.
2254
2255 if ($cmd =~ /\s-oP\s/)
2256 {
2257 ($pidfile = $cmd) =~ s/^.*-oP ([^ ]+).*$/$1/;
2258 $cmd =~ s!\s-bd\s! -bdf !;
2259 }
2260 else
2261 {
2262 $pidfile = "$parm_cwd/spool/exim-daemon.pid";
2263 $cmd =~ s!\s-bd\s! -bdf -oP $pidfile !;
2264 }
2265 print ">> |${cmd}-server\n" if ($debug);
2266 open DAEMONCMD, "|${cmd}-server" || tests_exit(-1, "Failed to run $cmd");
2267 DAEMONCMD->autoflush(1);
2268 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
2269
2270 # Interlock with daemon startup
2271 while (! stat("$pidfile") ) { select(undef, undef, undef, 0.3); }
2272 return 3; # Don't wait
2273 }
2274 elsif ($cmd =~ /\s-DSERVER=wait:(\d+)\s/)
2275 {
2276
2277 # The port and the $dynamic_socket was already allocated while parsing the
2278 # script file, where -DSERVER=wait:PORT_DYNAMIC was encountered.
2279
2280 my $listen_port = $1;
2281 if ($debug) { printf ">> wait-mode daemon: $cmd\n"; }
2282 run_system("sudo mkdir spool/log 2>/dev/null");
2283 run_system("sudo chown $parm_eximuser:$parm_eximgroup spool/log");
2284
2285 my $pid = fork();
2286 if (not defined $pid) { die "** fork failed: $!\n" }
2287 if (not $pid) {
2288 close(STDIN);
2289 open(STDIN, '<&', $dynamic_socket) or die "** dup sock to stdin failed: $!\n";
2290 close($dynamic_socket);
2291 print "[$$]>> ${cmd}-server\n" if ($debug);
2292 exec "exec ${cmd}-server";
2293 die "Can't exec ${cmd}-server: $!\n";
2294 }
2295 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
2296 select(undef, undef, undef, 0.3); # Let the daemon get going
2297 return (3, { exim_pid => $pid }); # Don't wait
2298 }
2299 }
2300
2301# The "background" command is run but not waited-for, like exim -DSERVER=server.
2302# One script line is read and fork-exec'd. The PID is stored for a later
2303# killdaemon.
2304
2305elsif (/^background$/)
2306 {
2307 my $line;
2308# $pidfile = "$parm_cwd/aux-var/server-daemon.pid";
2309
2310 $_ = <SCRIPT>; $lineno++;
2311 chomp;
2312 $line = $_;
2313 if ($debug) { printf ">> daemon: $line >>test-stdout 2>>test-stderr\n"; }
2314
2315 my $pid = fork();
2316 if (not defined $pid) { die "** fork failed: $!\n" }
2317 if (not $pid) {
2318 print "[$$]>> ${line}\n" if ($debug);
2319 close(STDIN);
2320 open(STDIN, "<", "test-stdout");
2321 close(STDOUT);
2322 open(STDOUT, ">>", "test-stdout");
2323 close(STDERR);
2324 open(STDERR, ">>", "test-stderr-server");
2325 exec "exec ${line}";
2326 exit(1);
2327 }
2328
2329# open(my $fh, ">", $pidfile) ||
2330# tests_exit(-1, "Failed to open $pidfile: $!");
2331# printf($fh, "%d\n", $pid);
2332# close($fh);
2333
2334 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
2335 select(undef, undef, undef, 0.3); # Let the daemon get going
2336 return (3, { exim_pid => $pid }); # Don't wait
2337 }
2338
2339
2340
2341# Unknown command
2342
2343else { tests_exit(-1, "Command unrecognized in line $lineno: $_"); }
2344
2345
2346# Run the command, with stdin connected to a pipe, and write the stdin data
2347# to it, with appropriate substitutions. If a line ends with \NONL\, chop off
2348# the terminating newline (and the \NONL\). If the command contains
2349# -DSERVER=server add "-server" to the command, where it will adjoin the name
2350# for the stderr file. See comment above about the use of -DSERVER.
2351
2352$stderrsuffix = ($cmd =~ /\s-DSERVER=server\s/)? "-server" : "";
2353print ">> |${cmd}${stderrsuffix}\n" if ($debug);
2354open CMD, "|${cmd}${stderrsuffix}" || tests_exit(1, "Failed to run $cmd");
2355
2356CMD->autoflush(1);
2357while (<SCRIPT>)
2358 {
2359 $lineno++;
2360 last if /^\*{4}\s*$/;
2361 do_substitute($testno);
2362 if (/^(.*)\\NONL\\\s*$/) { print CMD $1; } else { print CMD; }
2363 }
2364
2365# For timeout tests, wait before closing the pipe; we expect a
2366# SIGPIPE error in this case.
2367
2368if ($wait_time > 0)
2369 {
2370 printf(" Test %d sleep $wait_time ", $$subtestref);
2371 while ($wait_time-- > 0)
2372 {
2373 print ".";
2374 sleep(1);
2375 }
2376 printf("\r Test %d $cr", $$subtestref);
2377 }
2378
2379$sigpipehappened = 0;
2380close CMD; # Waits for command to finish
2381return $yield; # Ran command and waited
2382}
2383
2384
2385
2386
2387###############################################################################
2388###############################################################################
2389
2390# Here begins the Main Program ...
2391
2392###############################################################################
2393###############################################################################
2394
2395
2396autoflush STDOUT 1;
2397print "Exim tester $testversion\n";
2398
2399# extend the PATH with .../sbin
2400# we map all (.../bin) to (.../sbin:.../bin)
2401$ENV{PATH} = do {
2402 my %seen = map { $_, 1 } split /:/, $ENV{PATH};
2403 join ':' => map { m{(.*)/bin$}
2404 ? ( $seen{"$1/sbin"} ? () : ("$1/sbin"), $_)
2405 : ($_) }
2406 split /:/, $ENV{PATH};
2407};
2408
2409##################################################
2410# Some tests check created file modes #
2411##################################################
2412
2413umask 022;
2414
2415
2416##################################################
2417# Check for the "less" command #
2418##################################################
2419
2420$more = 'more' if system('which less >/dev/null 2>&1') != 0;
2421
2422
2423
2424##################################################
2425# Check for sudo access to root #
2426##################################################
2427
2428print "You need to have sudo access to root to run these tests. Checking ...\n";
2429if (system('sudo true >/dev/null') != 0)
2430 {
2431 die "** Test for sudo failed: testing abandoned.\n";
2432 }
2433else
2434 {
2435 print "Test for sudo OK\n";
2436 }
2437
2438
2439
2440##################################################
2441# See if an Exim binary has been given #
2442##################################################
2443
2444# If the first character of the first argument is '/', the argument is taken
2445# as the path to the binary. If the first argument does not start with a
2446# '/' but exists in the file system, it's assumed to be the Exim binary.
2447
2448($parm_exim, @ARGV) = Exim::Runtest::exim_binary(@ARGV);
2449print "Exim binary is $parm_exim\n" if $parm_exim ne "";
2450
2451
2452
2453##################################################
2454# Sort out options and which tests are to be run #
2455##################################################
2456
2457# There are a few possible options for the test script itself; after these, any
2458# options are passed on to Exim calls within the tests. Typically, this is used
2459# to turn on Exim debugging while setting up a test.
2460
2461while (@ARGV > 0 && $ARGV[0] =~ /^-/)
2462 {
2463 my($arg) = shift @ARGV;
2464 if ($optargs eq "")
2465 {
2466 if ($arg eq "-DEBUG") { $debug = 1; $cr = "\n"; next; }
2467 if ($arg eq "-DIFF") { $cf = "diff -u"; next; }
2468 if ($arg eq "-CONTINUE"){$force_continue = 1;
2469 $more = "cat";
2470 next; }
2471 if ($arg eq "-UPDATE") { $force_update = 1; next; }
2472 if ($arg eq "-NOIPV4") { $have_ipv4 = 0; next; }
2473 if ($arg eq "-NOIPV6") { $have_ipv6 = 0; next; }
2474 if ($arg eq "-KEEP") { $save_output = 1; next; }
2475 if ($arg eq "-VALGRIND") { $valgrind = 1; next; }
2476 if ($arg =~ /^-FLAVOU?R$/) { $flavour = shift; next; }
2477 }
2478 $optargs .= " $arg";
2479 }
2480
2481# Any subsequent arguments are a range of test numbers.
2482
2483if (@ARGV > 0)
2484 {
2485 $test_end = $test_start = $ARGV[0];
2486 $test_end = $ARGV[1] if (@ARGV > 1);
2487 $test_end = ($test_start >= 9000)? $test_special_top : $test_top
2488 if $test_end eq "+";
2489 die "** Test numbers out of order\n" if ($test_end < $test_start);
2490 }
2491
2492
2493##################################################
2494# Make the command's directory current #
2495##################################################
2496
2497# After doing so, we find its absolute path name.
2498
2499$cwd = $0;
2500$cwd = '.' if ($cwd !~ s|/[^/]+$||);
2501chdir($cwd) || die "** Failed to chdir to \"$cwd\": $!\n";
2502$parm_cwd = Cwd::getcwd();
2503
2504
2505##################################################
2506# Search for an Exim binary to test #
2507##################################################
2508
2509# If an Exim binary hasn't been provided, try to find one. We can handle the
2510# case where exim-testsuite is installed alongside Exim source directories. For
2511# PH's private convenience, if there's a directory just called "exim4", that
2512# takes precedence; otherwise exim-snapshot takes precedence over any numbered
2513# releases.
2514
2515# If $parm_exim is still empty, ask the caller
2516
2517if ($parm_exim eq "")
2518 {
2519 print "** Did not find an Exim binary to test\n";
2520 for ($i = 0; $i < 5; $i++)
2521 {
2522 my($trybin);
2523 print "** Enter pathname for Exim binary: ";
2524 chomp($trybin = <STDIN>);
2525 if (-e $trybin)
2526 {
2527 $parm_exim = $trybin;
2528 last;
2529 }
2530 else
2531 {
2532 print "** $trybin does not exist\n";
2533 }
2534 }
2535 die "** Too many tries\n" if $parm_exim eq "";
2536 }
2537
2538
2539
2540##################################################
2541# Find what is in the binary #
2542##################################################
2543
2544# deal with TRUSTED_CONFIG_LIST restrictions
2545unlink("$parm_cwd/test-config") if -e "$parm_cwd/test-config";
2546open (IN, "$parm_cwd/confs/0000") ||
2547 tests_exit(-1, "Couldn't open $parm_cwd/confs/0000: $!\n");
2548open (OUT, ">test-config") ||
2549 tests_exit(-1, "Couldn't open test-config: $!\n");
2550while (<IN>) { print OUT; }
2551close(IN);
2552close(OUT);
2553
2554print("Probing with config file: $parm_cwd/test-config\n");
2555open(EXIMINFO, "$parm_exim -d -C $parm_cwd/test-config -DDIR=$parm_cwd " .
2556 "-bP exim_user exim_group 2>&1|") ||
2557 die "** Cannot run $parm_exim: $!\n";
2558while(<EXIMINFO>)
2559 {
2560 if (my ($version) = /^Exim version (\S+)/) {
2561 my $git = `git describe --dirty=-XX --match 'exim-4*'`;
2562 if (defined $git and $? == 0) {
2563 chomp $git;
2564 $version =~ s/^\d+\K\./_/;
2565 $git =~ s/^exim-//i;
2566 $git =~ s/.*-\Kg([[:xdigit:]]+(?:-XX)?)/$1/;
2567 print <<___
2568
2569*** Version mismatch
2570*** Exim binary: $version
2571*** Git : $git
2572
2573___
2574 if not $version eq $git;
2575 }
2576 }
2577 $parm_eximuser = $1 if /^exim_user = (.*)$/;
2578 $parm_eximgroup = $1 if /^exim_group = (.*)$/;
2579 $parm_trusted_config_list = $1 if /^TRUSTED_CONFIG_LIST:.*?"(.*?)"$/;
2580 ($parm_configure_owner, $parm_configure_group) = ($1, $2)
2581 if /^Configure owner:\s*(\d+):(\d+)/;
2582 print "$_" if /wrong owner/;
2583 }
2584close(EXIMINFO);
2585
2586if (defined $parm_eximuser)
2587 {
2588 if ($parm_eximuser =~ /^\d+$/) { $parm_exim_uid = $parm_eximuser; }
2589 else { $parm_exim_uid = getpwnam($parm_eximuser); }
2590 }
2591else
2592 {
2593 print "Unable to extract exim_user from binary.\n";
2594 print "Check if Exim refused to run; if so, consider:\n";
2595 print " TRUSTED_CONFIG_LIST ALT_CONFIG_PREFIX WHITELIST_D_MACROS\n";
2596 print "If debug permission denied, are you in the exim group?\n";
2597 die "Failing to get information from binary.\n";
2598 }
2599
2600if (defined $parm_eximgroup)
2601 {
2602 if ($parm_eximgroup =~ /^\d+$/) { $parm_exim_gid = $parm_eximgroup; }
2603 else { $parm_exim_gid = getgrnam($parm_eximgroup); }
2604 }
2605
2606# check the permissions on the TRUSTED_CONFIG_LIST
2607if (defined $parm_trusted_config_list)
2608 {
2609 die "TRUSTED_CONFIG_LIST: $parm_trusted_config_list: $!\n"
2610 if not -f $parm_trusted_config_list;
2611
2612 die "TRUSTED_CONFIG_LIST $parm_trusted_config_list must not be world writable!\n"
2613 if 02 & (stat _)[2];
2614
2615 die sprintf "TRUSTED_CONFIG_LIST: $parm_trusted_config_list %d is group writable, but not owned by group '%s' or '%s'.\n",
2616 (stat _)[1],
2617 scalar(getgrgid 0), scalar(getgrgid $>)
2618 if (020 & (stat _)[2]) and not ((stat _)[5] == $> or (stat _)[5] == 0);
2619
2620 die sprintf "TRUSTED_CONFIG_LIST: $parm_trusted_config_list is not owned by user '%s' or '%s'.\n",
2621 scalar(getpwuid 0), scalar(getpwuid $>)
2622 if (not (-o _ or (stat _)[4] == 0));
2623
2624 open(TCL, $parm_trusted_config_list) or die "Can't open $parm_trusted_config_list: $!\n";
2625 my $test_config = getcwd() . '/test-config';
2626 die "Can't find '$test_config' in TRUSTED_CONFIG_LIST $parm_trusted_config_list."
2627 if not grep { /^$test_config$/ } <TCL>;
2628 }
2629else
2630 {
2631 die "Unable to check the TRUSTED_CONFIG_LIST, seems to be empty?\n";
2632 }
2633
2634die "CONFIGURE_OWNER ($parm_configure_owner) does not match the user invoking $0 ($>)\n"
2635 if $parm_configure_owner != $>;
2636
2637die "CONFIGURE_GROUP ($parm_configure_group) does not match the group invoking $0 ($))\n"
2638 if 0020 & (stat "$parm_cwd/test-config")[2]
2639 and $parm_configure_group != $);
2640
2641
2642open(EXIMINFO, "$parm_exim -d-all+transport -bV -C $parm_cwd/test-config -DDIR=$parm_cwd |") ||
2643 die "** Cannot run $parm_exim: $!\n";
2644
2645print "-" x 78, "\n";
2646
2647while (<EXIMINFO>)
2648 {
2649 my(@temp);
2650
2651 if (/^(Exim|Library) version/) { print; }
2652
2653 elsif (/^Size of off_t: (\d+)/)
2654 {
2655 print;
2656 $have_largefiles = 1 if $1 > 4;
2657 die "** Size of off_t > 32 which seems improbable, not running tests\n"
2658 if ($1 > 32);
2659 }
2660
2661 elsif (/^Support for: (.*)/)
2662 {
2663 print;
2664 @temp = split /(\s+)/, $1;
2665 push(@temp, ' ');
2666 %parm_support = @temp;
2667 }
2668
2669 elsif (/^Lookups \(built-in\): (.*)/)
2670 {
2671 print;
2672 @temp = split /(\s+)/, $1;
2673 push(@temp, ' ');
2674 %parm_lookups = @temp;
2675 }
2676
2677 elsif (/^Authenticators: (.*)/)
2678 {
2679 print;
2680 @temp = split /(\s+)/, $1;
2681 push(@temp, ' ');
2682 %parm_authenticators = @temp;
2683 }
2684
2685 elsif (/^Routers: (.*)/)
2686 {
2687 print;
2688 @temp = split /(\s+)/, $1;
2689 push(@temp, ' ');
2690 %parm_routers = @temp;
2691 }
2692
2693 # Some transports have options, e.g. appendfile/maildir. For those, ensure
2694 # that the basic transport name is set, and then the name with each of the
2695 # options.
2696
2697 elsif (/^Transports: (.*)/)
2698 {
2699 print;
2700 @temp = split /(\s+)/, $1;
2701 my($i,$k);
2702 push(@temp, ' ');
2703 %parm_transports = @temp;
2704 foreach $k (keys %parm_transports)
2705 {
2706 if ($k =~ "/")
2707 {
2708 @temp = split /\//, $k;
2709 $parm_transports{"$temp[0]"} = " ";
2710 for ($i = 1; $i < @temp; $i++)
2711 { $parm_transports{"$temp[0]/$temp[$i]"} = " "; }
2712 }
2713 }
2714 }
2715 }
2716close(EXIMINFO);
2717print "-" x 78, "\n";
2718
2719unlink("$parm_cwd/test-config");
2720
2721##################################################
2722# Check for SpamAssassin and ClamAV #
2723##################################################
2724
2725# These are crude tests. If they aren't good enough, we'll have to improve
2726# them, for example by actually passing a message through spamc or clamscan.
2727
2728if (defined $parm_support{'Content_Scanning'})
2729 {
2730 my $sock = new FileHandle;
2731
2732 if (system("spamc -h 2>/dev/null >/dev/null") == 0)
2733 {
2734 print "The spamc command works:\n";
2735
2736 # This test for an active SpamAssassin is courtesy of John Jetmore.
2737 # The tests are hard coded to localhost:783, so no point in making
2738 # this test flexible like the clamav test until the test scripts are
2739 # changed. spamd doesn't have the nice PING/PONG protoccol that
2740 # clamd does, but it does respond to errors in an informative manner,
2741 # so use that.
2742
2743 my($sint,$sport) = ('127.0.0.1',783);
2744 eval
2745 {
2746 my $sin = sockaddr_in($sport, inet_aton($sint))
2747 or die "** Failed packing $sint:$sport\n";
2748 socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp'))
2749 or die "** Unable to open socket $sint:$sport\n";
2750
2751 local $SIG{ALRM} =
2752 sub { die "** Timeout while connecting to socket $sint:$sport\n"; };
2753 alarm(5);
2754 connect($sock, $sin)
2755 or die "** Unable to connect to socket $sint:$sport\n";
2756 alarm(0);
2757
2758 select((select($sock), $| = 1)[0]);
2759 print $sock "bad command\r\n";
2760
2761 $SIG{ALRM} =
2762 sub { die "** Timeout while reading from socket $sint:$sport\n"; };
2763 alarm(10);
2764 my $res = <$sock>;
2765 alarm(0);
2766
2767 $res =~ m|^SPAMD/|
2768 or die "** Did not get SPAMD from socket $sint:$sport. "
2769 ."It said: $res\n";
2770 };
2771 alarm(0);
2772 if($@)
2773 {
2774 print " $@";
2775 print " Assume SpamAssassin (spamd) is not running\n";
2776 }
2777 else
2778 {
2779 $parm_running{'SpamAssassin'} = ' ';
2780 print " SpamAssassin (spamd) seems to be running\n";
2781 }
2782 }
2783 else
2784 {
2785 print "The spamc command failed: assume SpamAssassin (spamd) is not running\n";
2786 }
2787
2788 # For ClamAV, we need to find the clamd socket for use in the Exim
2789 # configuration. Search for the clamd configuration file.
2790
2791 if (system("clamscan -h 2>/dev/null >/dev/null") == 0)
2792 {
2793 my($f, $clamconf, $test_prefix);
2794
2795 print "The clamscan command works";
2796
2797 $test_prefix = $ENV{EXIM_TEST_PREFIX};
2798 $test_prefix = "" if !defined $test_prefix;
2799
2800 foreach $f ("$test_prefix/etc/clamd.conf",
2801 "$test_prefix/usr/local/etc/clamd.conf",
2802 "$test_prefix/etc/clamav/clamd.conf", "")
2803 {
2804 if (-e $f)
2805 {
2806 $clamconf = $f;
2807 last;
2808 }
2809 }
2810
2811 # Read the ClamAV configuration file and find the socket interface.
2812
2813 if ($clamconf ne "")
2814 {
2815 my $socket_domain;
2816 open(IN, "$clamconf") || die "\n** Unable to open $clamconf: $!\n";
2817 while (<IN>)
2818 {
2819 if (/^LocalSocket\s+(.*)/)
2820 {
2821 $parm_clamsocket = $1;
2822 $socket_domain = AF_UNIX;
2823 last;
2824 }
2825 if (/^TCPSocket\s+(\d+)/)
2826 {
2827 if (defined $parm_clamsocket)
2828 {
2829 $parm_clamsocket .= " $1";
2830 $socket_domain = AF_INET;
2831 last;
2832 }
2833 else
2834 {
2835 $parm_clamsocket = " $1";
2836 }
2837 }
2838 elsif (/^TCPAddr\s+(\S+)/)
2839 {
2840 if (defined $parm_clamsocket)
2841 {
2842 $parm_clamsocket = $1 . $parm_clamsocket;
2843 $socket_domain = AF_INET;
2844 last;
2845 }
2846 else
2847 {
2848 $parm_clamsocket = $1;
2849 }
2850 }
2851 }
2852 close(IN);
2853
2854 if (defined $socket_domain)
2855 {
2856 print ":\n The clamd socket is $parm_clamsocket\n";
2857 # This test for an active ClamAV is courtesy of Daniel Tiefnig.
2858 eval
2859 {
2860 my $socket;
2861 if ($socket_domain == AF_UNIX)
2862 {
2863 $socket = sockaddr_un($parm_clamsocket) or die "** Failed packing '$parm_clamsocket'\n";
2864 }
2865 elsif ($socket_domain == AF_INET)
2866 {
2867 my ($ca_host, $ca_port) = split(/\s+/,$parm_clamsocket);
2868 my $ca_hostent = gethostbyname($ca_host) or die "** Failed to get raw address for host '$ca_host'\n";
2869 $socket = sockaddr_in($ca_port, $ca_hostent) or die "** Failed packing '$parm_clamsocket'\n";
2870 }
2871 else
2872 {
2873 die "** Unknown socket domain '$socket_domain' (should not happen)\n";
2874 }
2875 socket($sock, $socket_domain, SOCK_STREAM, 0) or die "** Unable to open socket '$parm_clamsocket'\n";
2876 local $SIG{ALRM} = sub { die "** Timeout while connecting to socket '$parm_clamsocket'\n"; };
2877 alarm(5);
2878 connect($sock, $socket) or die "** Unable to connect to socket '$parm_clamsocket'\n";
2879 alarm(0);
2880
2881 my $ofh = select $sock; $| = 1; select $ofh;
2882 print $sock "PING\n";
2883
2884 $SIG{ALRM} = sub { die "** Timeout while reading from socket '$parm_clamsocket'\n"; };
2885 alarm(10);
2886 my $res = <$sock>;
2887 alarm(0);
2888
2889 $res =~ /PONG/ or die "** Did not get PONG from socket '$parm_clamsocket'. It said: $res\n";
2890 };
2891 alarm(0);
2892
2893 if($@)
2894 {
2895 print " $@";
2896 print " Assume ClamAV is not running\n";
2897 }
2898 else
2899 {
2900 $parm_running{'ClamAV'} = ' ';
2901 print " ClamAV seems to be running\n";
2902 }
2903 }
2904 else
2905 {
2906 print ", but the socket for clamd could not be determined\n";
2907 print "Assume ClamAV is not running\n";
2908 }
2909 }
2910
2911 else
2912 {
2913 print ", but I can't find a configuration for clamd\n";
2914 print "Assume ClamAV is not running\n";
2915 }
2916 }
2917 }
2918
2919
2920##################################################
2921# Check for redis #
2922##################################################
2923if (defined $parm_lookups{'redis'})
2924 {
2925 if (system("redis-server -v 2>/dev/null >/dev/null") == 0)
2926 {
2927 print "The redis-server command works\n";
2928 $parm_running{'redis'} = ' ';
2929 }
2930 else
2931 {
2932 print "The redis-server command failed: assume Redis not installed\n";
2933 }
2934 }
2935
2936##################################################
2937# Test for the basic requirements #
2938##################################################
2939
2940# This test suite assumes that Exim has been built with at least the "usual"
2941# set of routers, transports, and lookups. Ensure that this is so.
2942
2943$missing = "";
2944
2945$missing .= " Lookup: lsearch\n" if (!defined $parm_lookups{'lsearch'});
2946
2947$missing .= " Router: accept\n" if (!defined $parm_routers{'accept'});
2948$missing .= " Router: dnslookup\n" if (!defined $parm_routers{'dnslookup'});
2949$missing .= " Router: manualroute\n" if (!defined $parm_routers{'manualroute'});
2950$missing .= " Router: redirect\n" if (!defined $parm_routers{'redirect'});
2951
2952$missing .= " Transport: appendfile\n" if (!defined $parm_transports{'appendfile'});
2953$missing .= " Transport: autoreply\n" if (!defined $parm_transports{'autoreply'});
2954$missing .= " Transport: pipe\n" if (!defined $parm_transports{'pipe'});
2955$missing .= " Transport: smtp\n" if (!defined $parm_transports{'smtp'});
2956
2957if ($missing ne "")
2958 {
2959 print "\n";
2960 print "** Many features can be included or excluded from Exim binaries.\n";
2961 print "** This test suite requires that Exim is built to contain a certain\n";
2962 print "** set of basic facilities. It seems that some of these are missing\n";
2963 print "** from the binary that is under test, so the test cannot proceed.\n";
2964 print "** The missing facilities are:\n";
2965 print "$missing";
2966 die "** Test script abandoned\n";
2967 }
2968
2969
2970##################################################
2971# Check for the auxiliary programs #
2972##################################################
2973
2974# These are always required:
2975
2976for $prog ("cf", "checkaccess", "client", "client-ssl", "client-gnutls",
2977 "fakens", "iefbr14", "server")
2978 {
2979 next if ($prog eq "client-ssl" && !defined $parm_support{'OpenSSL'});
2980 next if ($prog eq "client-gnutls" && !defined $parm_support{'GnuTLS'});
2981 if (!-e "bin/$prog")
2982 {
2983 print "\n";
2984 print "** bin/$prog does not exist. Have you run ./configure and make?\n";
2985 die "** Test script abandoned\n";
2986 }
2987 }
2988
2989# If the "loaded" binary is missing, we cut out tests for ${dlfunc. It isn't
2990# compiled on systems where we don't know how to. However, if Exim does not
2991# have that functionality compiled, we needn't bother.
2992
2993$dlfunc_deleted = 0;
2994if (defined $parm_support{'Expand_dlfunc'} && !-e "bin/loaded")
2995 {
2996 delete $parm_support{'Expand_dlfunc'};
2997 $dlfunc_deleted = 1;
2998 }
2999
3000
3001##################################################
3002# Find environmental details #
3003##################################################
3004
3005# Find the caller of this program.
3006
3007($parm_caller,$pwpw,$parm_caller_uid,$parm_caller_gid,$pwquota,$pwcomm,
3008 $parm_caller_gecos, $parm_caller_home) = getpwuid($>);
3009
3010$pwpw = $pwpw; # Kill Perl warnings
3011$pwquota = $pwquota;
3012$pwcomm = $pwcomm;
3013
3014$parm_caller_group = getgrgid($parm_caller_gid);
3015
3016print "Program caller is $parm_caller ($parm_caller_uid), whose group is $parm_caller_group ($parm_caller_gid)\n";
3017print "Home directory is $parm_caller_home\n";
3018
3019unless (defined $parm_eximgroup)
3020 {
3021 print "Unable to derive \$parm_eximgroup.\n";
3022 die "** ABANDONING.\n";
3023 }
3024
3025print "You need to be in the Exim group to run these tests. Checking ...";
3026
3027if (`groups` =~ /\b\Q$parm_eximgroup\E\b/)
3028 {
3029 print " OK\n";
3030 }
3031else
3032 {
3033 print "\nOh dear, you are not in the Exim group.\n";
3034 die "** Testing abandoned.\n";
3035 }
3036
3037# Find this host's IP addresses - there may be many, of course, but we keep
3038# one of each type (IPv4 and IPv6).
3039
3040open(IFCONFIG, '-|', (grep { -x "$_/ip" } split /:/, $ENV{PATH}) ? 'ip address' : 'ifconfig -a')
3041 or die "** Cannot run 'ip address' or 'ifconfig -a'\n";
3042while (not ($parm_ipv4 and $parm_ipv6) and defined($_ = <IFCONFIG>))
3043 {
3044 if (not $parm_ipv4 and /^\s*inet(?:\saddr)?:?\s?(\d+\.\d+\.\d+\.\d+)(?:\/\d+)?\s/i)
3045 {
3046 next if $1 =~ /^(?:127|10)\./;
3047 $parm_ipv4 = $1;
3048 }
3049
3050 if (not $parm_ipv6 and /^\s*inet6(?:\saddr)?:?\s?([abcdef\d:]+)(?:\/\d+)/i)
3051 {
3052 next if $1 eq '::1' or $1 =~ /^fe80/i;
3053 $parm_ipv6 = $1;
3054 }
3055 }
3056close(IFCONFIG);
3057
3058# Use private IP addresses if there are no public ones.
3059
3060# If either type of IP address is missing, we need to set the value to
3061# something other than empty, because that wrecks the substitutions. The value
3062# is reflected, so use a meaningful string. Set appropriate options for the
3063# "server" command. In practice, however, many tests assume 127.0.0.1 is
3064# available, so things will go wrong if there is no IPv4 address. The lack
3065# of IPV4 or IPv6 can be simulated by command options, which force $have_ipv4
3066# and $have_ipv6 false.
3067
3068if (not $parm_ipv4)
3069 {
3070 $have_ipv4 = 0;
3071 $parm_ipv4 = "<no IPv4 address found>";
3072 $server_opts .= " -noipv4";
3073 }
3074elsif ($have_ipv4 == 0)
3075 {
3076 $parm_ipv4 = "<IPv4 testing disabled>";
3077 $server_opts .= " -noipv4";
3078 }
3079else
3080 {
3081 $parm_running{"IPv4"} = " ";
3082 }
3083
3084if (not $parm_ipv6)
3085 {
3086 $have_ipv6 = 0;
3087 $parm_ipv6 = "<no IPv6 address found>";
3088 $server_opts .= " -noipv6";
3089 delete($parm_support{"IPv6"});
3090 }
3091elsif ($have_ipv6 == 0)
3092 {
3093 $parm_ipv6 = "<IPv6 testing disabled>";
3094 $server_opts .= " -noipv6";
3095 delete($parm_support{"IPv6"});
3096 }
3097elsif (!defined $parm_support{'IPv6'})
3098 {
3099 $have_ipv6 = 0;
3100 $parm_ipv6 = "<no IPv6 support in Exim binary>";
3101 $server_opts .= " -noipv6";
3102 }
3103else
3104 {
3105 $parm_running{"IPv6"} = " ";
3106 }
3107
3108print "IPv4 address is $parm_ipv4\n";
3109print "IPv6 address is $parm_ipv6\n";
3110
3111# For munging test output, we need the reversed IP addresses.
3112
3113$parm_ipv4r = ($parm_ipv4 !~ /^\d/)? "" :
3114 join(".", reverse(split /\./, $parm_ipv4));
3115
3116$parm_ipv6r = $parm_ipv6; # Appropriate if not in use
3117if ($parm_ipv6 =~ /^[\da-f]/)
3118 {
3119 my(@comps) = split /:/, $parm_ipv6;
3120 my(@nibbles);
3121 foreach $comp (@comps)
3122 {
3123 push @nibbles, sprintf("%lx", hex($comp) >> 8);
3124 push @nibbles, sprintf("%lx", hex($comp) & 0xff);
3125 }
3126 $parm_ipv6r = join(".", reverse(@nibbles));
3127 }
3128
3129# Find the host name, fully qualified.
3130
3131chomp($temp = `hostname`);
3132die "'hostname' didn't return anything\n" unless defined $temp and length $temp;
3133if ($temp =~ /\./)
3134 {
3135 $parm_hostname = $temp;
3136 }
3137else
3138 {
3139 $parm_hostname = (gethostbyname($temp))[0];
3140 $parm_hostname = "no.host.name.found" unless defined $parm_hostname and length $parm_hostname;
3141 }
3142print "Hostname is $parm_hostname\n";
3143
3144if ($parm_hostname !~ /\./)
3145 {
3146 print "\n*** Host name is not fully qualified: this may cause problems ***\n\n";
3147 }
3148
3149if ($parm_hostname =~ /[[:upper:]]/)
3150 {
3151 print "\n*** Host name has upper case characters: this may cause problems ***\n\n";
3152 }
3153
3154
3155
3156##################################################
3157# Create a testing version of Exim #
3158##################################################
3159
3160# We want to be able to run Exim with a variety of configurations. Normally,
3161# the use of -C to change configuration causes Exim to give up its root
3162# privilege (unless the caller is exim or root). For these tests, we do not
3163# want this to happen. Also, we want Exim to know that it is running in its
3164# test harness.
3165
3166# We achieve this by copying the binary and patching it as we go. The new
3167# binary knows it is a testing copy, and it allows -C and -D without loss of
3168# privilege. Clearly, this file is dangerous to have lying around on systems
3169# where there are general users with login accounts. To protect against this,
3170# we put the new binary in a special directory that is accessible only to the
3171# caller of this script, who is known to have sudo root privilege from the test
3172# that was done above. Furthermore, we ensure that the binary is deleted at the
3173# end of the test. First ensure the directory exists.
3174
3175if (-d "eximdir")
3176 { unlink "eximdir/exim"; } # Just in case
3177else
3178 {
3179 mkdir("eximdir", 0710) || die "** Unable to mkdir $parm_cwd/eximdir: $!\n";
3180 system("sudo chgrp $parm_eximgroup eximdir");
3181 }
3182
3183# The construction of the patched binary must be done as root, so we use
3184# a separate script. As well as indicating that this is a test-harness binary,
3185# the version number is patched to "x.yz" so that its length is always the
3186# same. Otherwise, when it appears in Received: headers, it affects the length
3187# of the message, which breaks certain comparisons.
3188
3189die "** Unable to make patched exim: $!\n"
3190 if (system("sudo ./patchexim $parm_exim") != 0);
3191
3192# From this point on, exits from the program must go via the subroutine
3193# tests_exit(), so that suitable cleaning up can be done when required.
3194# Arrange to catch interrupting signals, to assist with this.
3195
3196$SIG{'INT'} = \&inthandler;
3197$SIG{'PIPE'} = \&pipehandler;
3198
3199# For some tests, we need another copy of the binary that is setuid exim rather
3200# than root.
3201
3202system("sudo cp eximdir/exim eximdir/exim_exim;" .
3203 "sudo chown $parm_eximuser eximdir/exim_exim;" .
3204 "sudo chgrp $parm_eximgroup eximdir/exim_exim;" .
3205 "sudo chmod 06755 eximdir/exim_exim");
3206
3207
3208##################################################
3209# Make copies of utilities we might need #
3210##################################################
3211
3212# Certain of the tests make use of some of Exim's utilities. We do not need
3213# to be root to copy these.
3214
3215($parm_exim_dir) = $parm_exim =~ m?^(.*)/exim?;
3216
3217$dbm_build_deleted = 0;
3218if (defined $parm_lookups{'dbm'} &&
3219 system("cp $parm_exim_dir/exim_dbmbuild eximdir") != 0)
3220 {
3221 delete $parm_lookups{'dbm'};
3222 $dbm_build_deleted = 1;
3223 }
3224
3225if (system("cp $parm_exim_dir/exim_dumpdb eximdir") != 0)
3226 {
3227 tests_exit(-1, "Failed to make a copy of exim_dumpdb: $!");
3228 }
3229
3230if (system("cp $parm_exim_dir/exim_lock eximdir") != 0)
3231 {
3232 tests_exit(-1, "Failed to make a copy of exim_lock: $!");
3233 }
3234
3235if (system("cp $parm_exim_dir/exinext eximdir") != 0)
3236 {
3237 tests_exit(-1, "Failed to make a copy of exinext: $!");
3238 }
3239
3240if (system("cp $parm_exim_dir/exigrep eximdir") != 0)
3241 {
3242 tests_exit(-1, "Failed to make a copy of exigrep: $!");
3243 }
3244
3245if (system("cp $parm_exim_dir/eximstats eximdir") != 0)
3246 {
3247 tests_exit(-1, "Failed to make a copy of eximstats: $!");
3248 }
3249
3250
3251##################################################
3252# Check that the Exim user can access stuff #
3253##################################################
3254
3255# We delay this test till here so that we can check access to the actual test
3256# binary. This will be needed when Exim re-exec's itself to do deliveries.
3257
3258print "Exim user is $parm_eximuser ($parm_exim_uid)\n";
3259print "Exim group is $parm_eximgroup ($parm_exim_gid)\n";
3260
3261if ($parm_caller_uid eq $parm_exim_uid) {
3262 tests_exit(-1, "Exim user ($parm_eximuser,$parm_exim_uid) cannot be "
3263 ."the same as caller ($parm_caller,$parm_caller_uid)");
3264}
3265if ($parm_caller_gid eq $parm_exim_gid) {
3266 tests_exit(-1, "Exim group ($parm_eximgroup,$parm_exim_gid) cannot be "
3267 ."the same as caller's ($parm_caller) group as it confuses "
3268 ."results analysis");
3269}
3270
3271print "The Exim user needs access to the test suite directory. Checking ...";
3272
3273if (($rc = system("sudo bin/checkaccess $parm_cwd/eximdir/exim $parm_eximuser $parm_eximgroup")) != 0)
3274 {
3275 my($why) = "unknown failure $rc";
3276 $rc >>= 8;
3277 $why = "Couldn't find user \"$parm_eximuser\"" if $rc == 1;
3278 $why = "Couldn't find group \"$parm_eximgroup\"" if $rc == 2;
3279 $why = "Couldn't read auxiliary group list" if $rc == 3;
3280 $why = "Couldn't get rid of auxiliary groups" if $rc == 4;
3281 $why = "Couldn't set gid" if $rc == 5;
3282 $why = "Couldn't set uid" if $rc == 6;
3283 $why = "Couldn't open \"$parm_cwd/eximdir/exim\"" if $rc == 7;
3284 print "\n** $why\n";
3285 tests_exit(-1, "$parm_eximuser cannot access the test suite directory");
3286 }
3287else
3288 {
3289 print " OK\n";
3290 }
3291
3292
3293##################################################
3294# Create a list of available tests #
3295##################################################
3296
3297# The scripts directory contains a number of subdirectories whose names are
3298# of the form 0000-xxxx, 1100-xxxx, 2000-xxxx, etc. Each set of tests apart
3299# from the first requires certain optional features to be included in the Exim
3300# binary. These requirements are contained in a file called "REQUIRES" within
3301# the directory. We scan all these tests, discarding those that cannot be run
3302# because the current binary does not support the right facilities, and also
3303# those that are outside the numerical range selected.
3304
3305print "\nTest range is $test_start to $test_end (flavour $flavour)\n";
3306print "Omitting \${dlfunc expansion tests (loadable module not present)\n"
3307 if $dlfunc_deleted;
3308print "Omitting dbm tests (unable to copy exim_dbmbuild)\n"
3309 if $dbm_build_deleted;
3310
3311opendir(DIR, "scripts") || tests_exit(-1, "Failed to opendir(\"scripts\"): $!");
3312@test_dirs = sort readdir(DIR);
3313closedir(DIR);
3314
3315# Remove . and .. and CVS from the list.
3316
3317for ($i = 0; $i < @test_dirs; $i++)
3318 {
3319 my($d) = $test_dirs[$i];
3320 if ($d eq "." || $d eq ".." || $d eq "CVS")
3321 {
3322 splice @test_dirs, $i, 1;
3323 $i--;
3324 }
3325 }
3326
3327# Scan for relevant tests
3328
3329for ($i = 0; $i < @test_dirs; $i++)
3330 {
3331 my($testdir) = $test_dirs[$i];
3332 my($wantthis) = 1;
3333
3334 print ">>Checking $testdir\n" if $debug;
3335
3336 # Skip this directory if the first test is equal or greater than the first
3337 # test in the next directory.
3338
3339 next if ($i < @test_dirs - 1) &&
3340 ($test_start >= substr($test_dirs[$i+1], 0, 4));
3341
3342 # No need to carry on if the end test is less than the first test in this
3343 # subdirectory.
3344
3345 last if $test_end < substr($testdir, 0, 4);
3346
3347 # Check requirements, if any.
3348
3349 if (open(REQUIRES, "scripts/$testdir/REQUIRES"))
3350 {
3351 while (<REQUIRES>)
3352 {
3353 next if /^\s*$/;
3354 s/\s+$//;
3355 if (/^support (.*)$/)
3356 {
3357 if (!defined $parm_support{$1}) { $wantthis = 0; last; }
3358 }
3359 elsif (/^running (.*)$/)
3360 {
3361 if (!defined $parm_running{$1}) { $wantthis = 0; last; }
3362 }
3363 elsif (/^lookup (.*)$/)
3364 {
3365 if (!defined $parm_lookups{$1}) { $wantthis = 0; last; }
3366 }
3367 elsif (/^authenticators? (.*)$/)
3368 {
3369 if (!defined $parm_authenticators{$1}) { $wantthis = 0; last; }
3370 }
3371 elsif (/^router (.*)$/)
3372 {
3373 if (!defined $parm_routers{$1}) { $wantthis = 0; last; }
3374 }
3375 elsif (/^transport (.*)$/)
3376 {
3377 if (!defined $parm_transports{$1}) { $wantthis = 0; last; }
3378 }
3379 else
3380 {
3381 tests_exit(-1, "Unknown line in \"scripts/$testdir/REQUIRES\": \"$_\"");
3382 }
3383 }
3384 close(REQUIRES);
3385 }
3386 else
3387 {
3388 tests_exit(-1, "Failed to open \"scripts/$testdir/REQUIRES\": $!")
3389 unless $!{ENOENT};
3390 }
3391
3392 # Loop if we do not want the tests in this subdirectory.
3393
3394 if (!$wantthis)
3395 {
3396 chomp;
3397 print "Omitting tests in $testdir (missing $_)\n";
3398 next;
3399 }
3400
3401 # We want the tests from this subdirectory, provided they are in the
3402 # range that was selected.
3403
3404 opendir(SUBDIR, "scripts/$testdir") ||
3405 tests_exit(-1, "Failed to opendir(\"scripts/$testdir\"): $!");
3406 @testlist = sort readdir(SUBDIR);
3407 close(SUBDIR);
3408
3409 foreach $test (@testlist)
3410 {
3411 next if $test !~ /^\d{4}(?:\.\d+)?$/;
3412 next if $test < $test_start || $test > $test_end;
3413 push @test_list, "$testdir/$test";
3414 }
3415 }
3416
3417print ">>Test List: @test_list\n", if $debug;
3418
3419
3420##################################################
3421# Munge variable auxiliary data #
3422##################################################
3423
3424# Some of the auxiliary data files have to refer to the current testing
3425# directory and other parameter data. The generic versions of these files are
3426# stored in the aux-var-src directory. At this point, we copy each of them
3427# to the aux-var directory, making appropriate substitutions. There aren't very
3428# many of them, so it's easiest just to do this every time. Ensure the mode
3429# is standardized, as this path is used as a test for the ${stat: expansion.
3430
3431# A similar job has to be done for the files in the dnszones-src directory, to
3432# make the fake DNS zones for testing. Most of the zone files are copied to
3433# files of the same name, but db.ipv4.V4NET and db.ipv6.V6NET use the testing
3434# networks that are defined by parameter.
3435
3436foreach $basedir ("aux-var", "dnszones")
3437 {
3438 system("sudo rm -rf $parm_cwd/$basedir");
3439 mkdir("$parm_cwd/$basedir", 0777);
3440 chmod(0755, "$parm_cwd/$basedir");
3441
3442 opendir(AUX, "$parm_cwd/$basedir-src") ||
3443 tests_exit(-1, "Failed to opendir $parm_cwd/$basedir-src: $!");
3444 my(@filelist) = readdir(AUX);
3445 close(AUX);
3446
3447 foreach $file (@filelist)
3448 {
3449 my($outfile) = $file;
3450 next if $file =~ /^\./;
3451
3452 if ($file eq "db.ip4.V4NET")
3453 {
3454 $outfile = "db.ip4.$parm_ipv4_test_net";
3455 }
3456 elsif ($file eq "db.ip6.V6NET")
3457 {
3458 my(@nibbles) = reverse(split /\s*/, $parm_ipv6_test_net);
3459 $" = '.';
3460 $outfile = "db.ip6.@nibbles";
3461 $" = ' ';
3462 }
3463
3464 print ">>Copying $basedir-src/$file to $basedir/$outfile\n" if $debug;
3465 open(IN, "$parm_cwd/$basedir-src/$file") ||
3466 tests_exit(-1, "Failed to open $parm_cwd/$basedir-src/$file: $!");
3467 open(OUT, ">$parm_cwd/$basedir/$outfile") ||
3468 tests_exit(-1, "Failed to open $parm_cwd/$basedir/$outfile: $!");
3469 while (<IN>)
3470 {
3471 do_substitute(0);
3472 print OUT;
3473 }
3474 close(IN);
3475 close(OUT);
3476 }
3477 }
3478
3479# Set a user's shell, distinguishable from /bin/sh
3480
3481symlink("/bin/sh","aux-var/sh");
3482$ENV{'SHELL'} = $parm_shell = $parm_cwd . "/aux-var/sh";
3483
3484##################################################
3485# Create fake DNS zones for this host #
3486##################################################
3487
3488# There are fixed zone files for 127.0.0.1 and ::1, but we also want to be
3489# sure that there are forward and reverse registrations for this host, using
3490# its real IP addresses. Dynamically created zone files achieve this.
3491
3492if ($have_ipv4 || $have_ipv6)
3493 {
3494 my($shortname,$domain) = $parm_hostname =~ /^([^.]+)(.*)/;
3495 open(OUT, ">$parm_cwd/dnszones/db$domain") ||
3496 tests_exit(-1, "Failed to open $parm_cwd/dnszones/db$domain: $!");
3497 print OUT "; This is a dynamically constructed fake zone file.\n" .
3498 "; The following line causes fakens to return PASS_ON\n" .
3499 "; for queries that it cannot answer\n\n" .
3500 "PASS ON NOT FOUND\n\n";
3501 print OUT "$shortname A $parm_ipv4\n" if $have_ipv4;
3502 print OUT "$shortname AAAA $parm_ipv6\n" if $have_ipv6;
3503 print OUT "\n; End\n";
3504 close(OUT);
3505 }
3506
3507if ($have_ipv4 && $parm_ipv4 ne "127.0.0.1")
3508 {
3509 my(@components) = $parm_ipv4 =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)/;
3510 open(OUT, ">$parm_cwd/dnszones/db.ip4.$components[0]") ||
3511 tests_exit(-1,
3512 "Failed to open $parm_cwd/dnszones/db.ip4.$components[0]: $!");
3513 print OUT "; This is a dynamically constructed fake zone file.\n" .
3514 "; The zone is $components[0].in-addr.arpa.\n\n" .
3515 "$components[3].$components[2].$components[1] PTR $parm_hostname.\n\n" .
3516 "; End\n";
3517 close(OUT);
3518 }
3519
3520if ($have_ipv6 && $parm_ipv6 ne "::1")
3521 {
3522 my($exp_v6) = $parm_ipv6;
3523 $exp_v6 =~ s/[^:]//g;
3524 if ( $parm_ipv6 =~ /^([^:].+)::$/ ) {
3525 $exp_v6 = $1 . ':0' x (9-length($exp_v6));
3526 } elsif ( $parm_ipv6 =~ /^(.+)::(.+)$/ ) {
3527 $exp_v6 = $1 . ':0' x (8-length($exp_v6)) . ':' . $2;
3528 } elsif ( $parm_ipv6 =~ /^::(.+[^:])$/ ) {
3529 $exp_v6 = '0:' x (9-length($exp_v6)) . $1;
3530 } else {
3531 $exp_v6 = $parm_ipv6;
3532 }
3533 my(@components) = split /:/, $exp_v6;
3534 my(@nibbles) = reverse (split /\s*/, shift @components);
3535 my($sep) = "";
3536
3537 $" = ".";
3538 open(OUT, ">$parm_cwd/dnszones/db.ip6.@nibbles") ||
3539 tests_exit(-1,
3540 "Failed to open $parm_cwd/dnszones/db.ip6.@nibbles: $!");
3541 print OUT "; This is a dynamically constructed fake zone file.\n" .
3542 "; The zone is @nibbles.ip6.arpa.\n\n";
3543
3544 @components = reverse @components;
3545 foreach $c (@components)
3546 {
3547 $c = "0$c" until $c =~ /^..../;
3548 @nibbles = reverse(split /\s*/, $c);
3549 print OUT "$sep@nibbles";
3550 $sep = ".";
3551 }
3552
3553 print OUT " PTR $parm_hostname.\n\n; End\n";
3554 close(OUT);
3555 $" = " ";
3556 }
3557
3558
3559
3560##################################################
3561# Create lists of mailboxes and message logs #
3562##################################################
3563
3564# We use these lists to check that a test has created the expected files. It
3565# should be faster than looking for the file each time. For mailboxes, we have
3566# to scan a complete subtree, in order to handle maildirs. For msglogs, there
3567# is just a flat list of files.
3568
3569@oldmails = list_files_below("mail");
3570opendir(DIR, "msglog") || tests_exit(-1, "Failed to opendir msglog: $!");
3571@oldmsglogs = readdir(DIR);
3572closedir(DIR);
3573
3574
3575
3576##################################################
3577# Run the required tests #
3578##################################################
3579
3580# Each test script contains a number of tests, separated by a line that
3581# contains ****. We open input from the terminal so that we can read responses
3582# to prompts.
3583
3584if (not $force_continue) {
3585 # runtest needs to interact if we're not in continue
3586 # mode. It does so by communicate to /dev/tty
3587 open(T, "/dev/tty") or tests_exit(-1, "Failed to open /dev/tty: $!");
3588}
3589
3590
3591print "\nPress RETURN to run the tests: ";
3592$_ = $force_continue ? "c" : <T>;
3593print "\n";
3594
3595$lasttestdir = "";
3596
3597foreach $test (@test_list)
3598 {
3599 local($lineno) = 0;
3600 local($commandno) = 0;
3601 local($subtestno) = 0;
3602 (local $testno = $test) =~ s|.*/||;
3603 local($sortlog) = 0;
3604
3605 my($gnutls) = 0;
3606 my($docheck) = 1;
3607 my($thistestdir) = substr($test, 0, -5);
3608
3609 $dynamic_socket->close() if $dynamic_socket;
3610
3611 if ($lasttestdir ne $thistestdir)
3612 {
3613 $gnutls = 0;
3614 if (-s "scripts/$thistestdir/REQUIRES")
3615 {
3616 my($indent) = "";
3617 print "\n>>> The following tests require: ";
3618 open(IN, "scripts/$thistestdir/REQUIRES") ||
3619 tests_exit(-1, "Failed to open scripts/$thistestdir/REQUIRES: $1");
3620 while (<IN>)
3621 {
3622 $gnutls = 1 if /^support GnuTLS/;
3623 print $indent, $_;
3624 $indent = ">>> ";
3625 }
3626 close(IN);
3627 }
3628 }
3629 $lasttestdir = $thistestdir;
3630
3631 # Remove any debris in the spool directory and the test-mail directory
3632 # and also the files for collecting stdout and stderr. Then put back
3633 # the test-mail directory for appendfile deliveries.
3634
3635 system "sudo /bin/rm -rf spool test-*";
3636 system "mkdir test-mail 2>/dev/null";
3637
3638 # A privileged Exim will normally make its own spool directory, but some of
3639 # the tests run in unprivileged modes that don't always work if the spool
3640 # directory isn't already there. What is more, we want anybody to be able
3641 # to read it in order to find the daemon's pid.
3642
3643 system "mkdir spool; " .
3644 "sudo chown $parm_eximuser:$parm_eximgroup spool; " .
3645 "sudo chmod 0755 spool";
3646
3647 # Empty the cache that keeps track of things like message id mappings, and
3648 # set up the initial sequence strings.
3649
3650 undef %cache;
3651 $next_msgid = "aX";
3652 $next_pid = 1234;
3653 $next_port = 1111;
3654 $message_skip = 0;
3655 $msglog_skip = 0;
3656 $stderr_skip = 0;
3657 $stdout_skip = 0;
3658 $rmfiltertest = 0;
3659 $is_ipv6test = 0;
3660 $TEST_STATE->{munge} = "";
3661
3662 # Remove the associative arrays used to hold checked mail files and msglogs
3663
3664 undef %expected_mails;
3665 undef %expected_msglogs;
3666
3667 # Open the test's script
3668 open(SCRIPT, "scripts/$test") ||
3669 tests_exit(-1, "Failed to open \"scripts/$test\": $!");
3670 # Run through the script once to set variables which should be global
3671 while (<SCRIPT>)
3672 {
3673 if (/^no_message_check/) { $message_skip = 1; next; }
3674 if (/^no_msglog_check/) { $msglog_skip = 1; next; }
3675 if (/^no_stderr_check/) { $stderr_skip = 1; next; }
3676 if (/^no_stdout_check/) { $stdout_skip = 1; next; }
3677 if (/^rmfiltertest/) { $rmfiltertest = 1; next; }
3678 if (/^sortlog/) { $sortlog = 1; next; }
3679 if (/\bPORT_DYNAMIC\b/) { $dynamic_socket = Exim::Runtest::dynamic_socket(); next; }
3680 }
3681 # Reset to beginning of file for per test interpreting/processing
3682 seek(SCRIPT, 0, 0);
3683
3684 # The first line in the script must be a comment that is used to identify
3685 # the set of tests as a whole.
3686
3687 $_ = <SCRIPT>;
3688 $lineno++;
3689 tests_exit(-1, "Missing identifying comment at start of $test") if (!/^#/);
3690 printf("%s %s", (substr $test, 5), (substr $_, 2));
3691
3692 # Loop for each of the subtests within the script. The variable $server_pid
3693 # is used to remember the pid of a "server" process, for which we do not
3694 # wait until we have waited for a subsequent command.
3695
3696 local($server_pid) = 0;
3697 for ($commandno = 1; !eof SCRIPT; $commandno++)
3698 {
3699 # Skip further leading comments and blank lines, handle the flag setting
3700 # commands, and deal with tests for IP support.
3701
3702 while (<SCRIPT>)
3703 {
3704 $lineno++;
3705 # Could remove these variable settings because they are already
3706 # set above, but doesn't hurt to leave them here.
3707 if (/^no_message_check/) { $message_skip = 1; next; }
3708 if (/^no_msglog_check/) { $msglog_skip = 1; next; }
3709 if (/^no_stderr_check/) { $stderr_skip = 1; next; }
3710 if (/^no_stdout_check/) { $stdout_skip = 1; next; }
3711 if (/^rmfiltertest/) { $rmfiltertest = 1; next; }
3712 if (/^sortlog/) { $sortlog = 1; next; }
3713
3714 if (/^need_largefiles/)
3715 {
3716 next if $have_largefiles;
3717 print ">>> Large file support is needed for test $testno, but is not available: skipping\n";
3718 $docheck = 0; # don't check output
3719 undef $_; # pretend EOF
3720 last;
3721 }
3722
3723 if (/^need_ipv4/)
3724 {
3725 next if $have_ipv4;
3726 print ">>> IPv4 is needed for test $testno, but is not available: skipping\n";
3727 $docheck = 0; # don't check output
3728 undef $_; # pretend EOF
3729 last;
3730 }
3731
3732 if (/^need_ipv6/)
3733 {
3734 if ($have_ipv6)
3735 {
3736 $is_ipv6test = 1;
3737 next;
3738 }
3739 print ">>> IPv6 is needed for test $testno, but is not available: skipping\n";
3740 $docheck = 0; # don't check output
3741 undef $_; # pretend EOF
3742 last;
3743 }
3744
3745 if (/^need_move_frozen_messages/)
3746 {
3747 next if defined $parm_support{"move_frozen_messages"};
3748 print ">>> move frozen message support is needed for test $testno, " .
3749 "but is not\n>>> available: skipping\n";
3750 $docheck = 0; # don't check output
3751 undef $_; # pretend EOF
3752 last;
3753 }
3754
3755 last unless /^(#|\s*$)/;
3756 }
3757 last if !defined $_; # Hit EOF
3758
3759 my($subtest_startline) = $lineno;
3760
3761 # Now run the command. The function returns 0 for an inline command,
3762 # 1 if a non-exim command was run and waited for, 2 if an exim
3763 # command was run and waited for, and 3 if a command
3764 # was run and not waited for (usually a daemon or server startup).
3765
3766 my($commandname) = "";
3767 my($expectrc) = 0;
3768 my($rc, $run_extra) = run_command($testno, \$subtestno, \$expectrc, \$commandname, $TEST_STATE);
3769 my($cmdrc) = $?;
3770
3771$0 = "[runtest $testno]";
3772
3773 if ($debug) {
3774 print ">> rc=$rc cmdrc=$cmdrc\n";
3775 if (defined $run_extra) {
3776 foreach my $k (keys %$run_extra) {
3777 my $v = defined $run_extra->{$k} ? qq!"$run_extra->{$k}"! : '<undef>';
3778 print ">> $k -> $v\n";
3779 }
3780 }
3781 }
3782 $run_extra = {} unless defined $run_extra;
3783 foreach my $k (keys %$run_extra) {
3784 if (exists $TEST_STATE->{$k}) {
3785 my $nv = defined $run_extra->{$k} ? qq!"$run_extra->{$k}"! : 'removed';
3786 print ">> override of $k; was $TEST_STATE->{$k}, now $nv\n" if $debug;
3787 }
3788 if (defined $run_extra->{$k}) {
3789 $TEST_STATE->{$k} = $run_extra->{$k};
3790 } elsif (exists $TEST_STATE->{$k}) {
3791 delete $TEST_STATE->{$k};
3792 }
3793 }
3794
3795 # Hit EOF after an initial return code number
3796
3797 tests_exit(-1, "Unexpected EOF in script") if ($rc == 4);
3798
3799 # Carry on with the next command if we did not wait for this one. $rc == 0
3800 # if no subprocess was run; $rc == 3 if we started a process but did not
3801 # wait for it.
3802
3803 next if ($rc == 0 || $rc == 3);
3804
3805 # We ran and waited for a command. Check for the expected result unless
3806 # it died.
3807
3808 if ($cmdrc != $expectrc && !$sigpipehappened)
3809 {
3810 printf("** Command $commandno (\"$commandname\", starting at line $subtest_startline)\n");
3811 if (($cmdrc & 0xff) == 0)
3812 {
3813 printf("** Return code %d (expected %d)", $cmdrc/256, $expectrc/256);
3814 }
3815 elsif (($cmdrc & 0xff00) == 0)
3816 { printf("** Killed by signal %d", $cmdrc & 255); }
3817 else
3818 { printf("** Status %x", $cmdrc); }
3819
3820 for (;;)
3821 {
3822 print "\nshow stdErr, show stdOut, Retry, Continue (without file comparison), or Quit? [Q] ";
3823 $_ = $force_continue ? "c" : <T>;
3824 tests_exit(1) if /^q?$/i;
3825 log_failure($log_failed_filename, $testno, "exit code unexpected") if (/^c$/i && $force_continue);
3826 if ($force_continue)
3827 {
3828 print "\nstderr tail:\n";
3829 print "===================\n";
3830 system("tail -20 test-stderr");
3831 print "===================\n";
3832 print "... continue forced\n";
3833 }
3834
3835 last if /^[rc]$/i;
3836 if (/^e$/i)
3837 {
3838 system("$more test-stderr");
3839 }
3840 elsif (/^o$/i)
3841 {
3842 system("$more test-stdout");
3843 }
3844 }
3845
3846 $retry = 1 if /^r$/i;
3847 $docheck = 0;
3848 }
3849
3850 # If the command was exim, and a listening server is running, we can now
3851 # close its input, which causes us to wait for it to finish, which is why
3852 # we didn't close it earlier.
3853
3854 if ($rc == 2 && $server_pid != 0)
3855 {
3856 close SERVERCMD;
3857 $server_pid = 0;
3858 if ($? != 0)
3859 {
3860 if (($? & 0xff) == 0)
3861 { printf("Server return code %d", $?/256); }
3862 elsif (($? & 0xff00) == 0)
3863 { printf("Server killed by signal %d", $? & 255); }
3864 else
3865 { printf("Server status %x", $?); }
3866
3867 for (;;)
3868 {
3869 print "\nShow server stdout, Retry, Continue, or Quit? [Q] ";
3870 $_ = $force_continue ? "c" : <T>;
3871 tests_exit(1) if /^q?$/i;
3872 log_failure($log_failed_filename, $testno, "exit code unexpected") if (/^c$/i && $force_continue);
3873 print "... continue forced\n" if $force_continue;
3874 last if /^[rc]$/i;
3875
3876 if (/^s$/i)
3877 {
3878 open(S, "test-stdout-server") ||
3879 tests_exit(-1, "Failed to open test-stdout-server: $!");
3880 print while <S>;
3881 close(S);
3882 }
3883 }
3884 $retry = 1 if /^r$/i;
3885 }
3886 }
3887 }
3888
3889 close SCRIPT;
3890
3891 # The script has finished. Check the all the output that was generated. The
3892 # function returns 0 if all is well, 1 if we should rerun the test (the files
3893 # function returns 0 if all is well, 1 if we should rerun the test (the files
3894 # have been updated). It does not return if the user responds Q to a prompt.
3895
3896 if ($retry)
3897 {
3898 $retry = '0';
3899 print (("#" x 79) . "\n");
3900 redo;
3901 }
3902
3903 if ($docheck)
3904 {
3905 if (check_output($TEST_STATE->{munge}) != 0)
3906 {
3907 print (("#" x 79) . "\n");
3908 redo;
3909 }
3910 else
3911 {
3912 print (" Script completed\n");
3913 }
3914 }
3915 }
3916
3917
3918##################################################
3919# Exit from the test script #
3920##################################################
3921
3922tests_exit(-1, "No runnable tests selected") if @test_list == 0;
3923tests_exit(0);
3924
3925# End of runtest script