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