PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/test/runtest

https://gitlab.com/Exim/exim
Perl | 3765 lines | 2335 code | 678 blank | 752 comment | 556 complexity | 6171e73b04c453c5118d89556a6bb5a7 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. #! /usr/bin/perl -w
  2. ###############################################################################
  3. # This is the controlling script for the "new" test suite for Exim. It should #
  4. # be possible to export this suite for running on a wide variety of hosts, in #
  5. # contrast to the old suite, which was very dependent on the environment of #
  6. # Philip Hazel's desktop computer. This implementation inspects the version #
  7. # of Exim that it finds, and tests only those features that are included. The #
  8. # surrounding environment is also tested to discover what is available. See #
  9. # the README file for details of how it all works. #
  10. # #
  11. # Implementation started: 03 August 2005 by Philip Hazel #
  12. # Placed in the Exim CVS: 06 February 2006 #
  13. ###############################################################################
  14. #use strict;
  15. use Errno;
  16. use FileHandle;
  17. use Socket;
  18. use Time::Local;
  19. use Cwd;
  20. use File::Basename;
  21. use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
  22. # Start by initializing some global variables
  23. $testversion = "4.80 (08-May-12)";
  24. # This gets embedded in the D-H params filename, and the value comes
  25. # from asking GnuTLS for "normal", but there appears to be no way to
  26. # use certtool/... to ask what that value currently is. *sigh*
  27. # We also clamp it because of NSS interop, see addition of tls_dh_max_bits.
  28. # This value is correct as of GnuTLS 2.12.18 as clamped by tls_dh_max_bits.
  29. # normal = 2432 tls_dh_max_bits = 2236
  30. $gnutls_dh_bits_normal = 2236;
  31. $cf = "bin/cf -exact";
  32. $cr = "\r";
  33. $debug = 0;
  34. $force_continue = 0;
  35. $force_update = 0;
  36. $log_failed_filename = "failed-summary.log";
  37. $more = "less -XF";
  38. $optargs = "";
  39. $save_output = 0;
  40. $server_opts = "";
  41. $flavour = 'FOO';
  42. $have_ipv4 = 1;
  43. $have_ipv6 = 1;
  44. $have_largefiles = 0;
  45. $test_start = 1;
  46. $test_end = $test_top = 8999;
  47. $test_special_top = 9999;
  48. @test_list = ();
  49. @test_dirs = ();
  50. # Networks to use for DNS tests. We need to choose some networks that will
  51. # never be used so that there is no chance that the host on which we are
  52. # running is actually in one of the test networks. Private networks such as
  53. # the IPv4 10.0.0.0/8 network are no good because hosts may well use them.
  54. # Rather than use some unassigned numbers (that might become assigned later),
  55. # I have chosen some multicast networks, in the belief that such addresses
  56. # won't ever be assigned to hosts. This is the only place where these numbers
  57. # are defined, so it is trivially possible to change them should that ever
  58. # become necessary.
  59. $parm_ipv4_test_net = "224";
  60. $parm_ipv6_test_net = "ff00";
  61. # Port numbers are currently hard-wired
  62. $parm_port_n = 1223; # Nothing listening on this port
  63. $parm_port_s = 1224; # Used for the "server" command
  64. $parm_port_d = 1225; # Used for the Exim daemon
  65. $parm_port_d2 = 1226; # Additional for daemon
  66. $parm_port_d3 = 1227; # Additional for daemon
  67. $parm_port_d4 = 1228; # Additional for daemon
  68. # Manually set locale
  69. $ENV{'LC_ALL'} = 'C';
  70. # In some environments USER does not exists, but we
  71. # need it for some test(s)
  72. $ENV{USER} = getpwuid($>)
  73. if not exists $ENV{USER};
  74. ###############################################################################
  75. ###############################################################################
  76. # Define a number of subroutines
  77. ###############################################################################
  78. ###############################################################################
  79. ##################################################
  80. # Handle signals #
  81. ##################################################
  82. sub pipehandler { $sigpipehappened = 1; }
  83. sub inthandler { print "\n"; tests_exit(-1, "Caught SIGINT"); }
  84. ##################################################
  85. # Do global macro substitutions #
  86. ##################################################
  87. # This function is applied to configurations, command lines and data lines in
  88. # scripts, and to lines in the files of the aux-var-src and the dnszones-src
  89. # directory. It takes one argument: the current test number, or zero when
  90. # setting up files before running any tests.
  91. sub do_substitute{
  92. s?\bCALLER\b?$parm_caller?g;
  93. s?\bCALLERGROUP\b?$parm_caller_group?g;
  94. s?\bCALLER_UID\b?$parm_caller_uid?g;
  95. s?\bCALLER_GID\b?$parm_caller_gid?g;
  96. s?\bCLAMSOCKET\b?$parm_clamsocket?g;
  97. s?\bDIR/?$parm_cwd/?g;
  98. s?\bEXIMGROUP\b?$parm_eximgroup?g;
  99. s?\bEXIMUSER\b?$parm_eximuser?g;
  100. s?\bHOSTIPV4\b?$parm_ipv4?g;
  101. s?\bHOSTIPV6\b?$parm_ipv6?g;
  102. s?\bHOSTNAME\b?$parm_hostname?g;
  103. s?\bPORT_D\b?$parm_port_d?g;
  104. s?\bPORT_D2\b?$parm_port_d2?g;
  105. s?\bPORT_D3\b?$parm_port_d3?g;
  106. s?\bPORT_D4\b?$parm_port_d4?g;
  107. s?\bPORT_N\b?$parm_port_n?g;
  108. s?\bPORT_S\b?$parm_port_s?g;
  109. s?\bTESTNUM\b?$_[0]?g;
  110. s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
  111. s?\bV6NET:?$parm_ipv6_test_net:?g;
  112. }
  113. ##################################################
  114. # Any state to be preserved across tests #
  115. ##################################################
  116. my $TEST_STATE = {};
  117. ##################################################
  118. # Subroutine to tidy up and exit #
  119. ##################################################
  120. # In all cases, we check for any Exim daemons that have been left running, and
  121. # kill them. Then remove all the spool data, test output, and the modified Exim
  122. # binary if we are ending normally.
  123. # Arguments:
  124. # $_[0] = 0 for a normal exit; full cleanup done
  125. # $_[0] > 0 for an error exit; no files cleaned up
  126. # $_[0] < 0 for a "die" exit; $_[1] contains a message
  127. sub tests_exit{
  128. my($rc) = $_[0];
  129. my($spool);
  130. # Search for daemon pid files and kill the daemons. We kill with SIGINT rather
  131. # than SIGTERM to stop it outputting "Terminated" to the terminal when not in
  132. # the background.
  133. if (exists $TEST_STATE->{exim_pid})
  134. {
  135. $pid = $TEST_STATE->{exim_pid};
  136. print "Tidyup: killing wait-mode daemon pid=$pid\n";
  137. system("sudo kill -INT $pid");
  138. }
  139. if (opendir(DIR, "spool"))
  140. {
  141. my(@spools) = sort readdir(DIR);
  142. closedir(DIR);
  143. foreach $spool (@spools)
  144. {
  145. next if $spool !~ /^exim-daemon./;
  146. open(PID, "spool/$spool") || die "** Failed to open \"spool/$spool\": $!\n";
  147. chomp($pid = <PID>);
  148. close(PID);
  149. print "Tidyup: killing daemon pid=$pid\n";
  150. system("sudo rm -f spool/$spool; sudo kill -INT $pid");
  151. }
  152. }
  153. else
  154. { die "** Failed to opendir(\"spool\"): $!\n" unless $!{ENOENT}; }
  155. # Close the terminal input and remove the test files if all went well, unless
  156. # the option to save them is set. Always remove the patched Exim binary. Then
  157. # exit normally, or die.
  158. close(T);
  159. system("sudo /bin/rm -rf ./spool test-* ./dnszones/*")
  160. if ($rc == 0 && !$save_output);
  161. system("sudo /bin/rm -rf ./eximdir/*")
  162. if (!$save_output);
  163. print "\nYou were in test $test at the end there.\n\n" if defined $test;
  164. exit $rc if ($rc >= 0);
  165. die "** runtest error: $_[1]\n";
  166. }
  167. ##################################################
  168. # Subroutines used by the munging subroutine #
  169. ##################################################
  170. # This function is used for things like message ids, where we want to generate
  171. # more than one value, but keep a consistent mapping throughout.
  172. #
  173. # Arguments:
  174. # $oldid the value from the file
  175. # $base a base string into which we insert a sequence
  176. # $sequence the address of the current sequence counter
  177. sub new_value {
  178. my($oldid, $base, $sequence) = @_;
  179. my($newid) = $cache{$oldid};
  180. if (! defined $newid)
  181. {
  182. $newid = sprintf($base, $$sequence++);
  183. $cache{$oldid} = $newid;
  184. }
  185. return $newid;
  186. }
  187. # This is used while munging the output from exim_dumpdb.
  188. # May go wrong across DST changes.
  189. sub date_seconds {
  190. my($day,$month,$year,$hour,$min,$sec) =
  191. $_[0] =~ /^(\d\d)-(\w\w\w)-(\d{4})\s(\d\d):(\d\d):(\d\d)/;
  192. my($mon);
  193. if ($month =~ /Jan/) {$mon = 0;}
  194. elsif($month =~ /Feb/) {$mon = 1;}
  195. elsif($month =~ /Mar/) {$mon = 2;}
  196. elsif($month =~ /Apr/) {$mon = 3;}
  197. elsif($month =~ /May/) {$mon = 4;}
  198. elsif($month =~ /Jun/) {$mon = 5;}
  199. elsif($month =~ /Jul/) {$mon = 6;}
  200. elsif($month =~ /Aug/) {$mon = 7;}
  201. elsif($month =~ /Sep/) {$mon = 8;}
  202. elsif($month =~ /Oct/) {$mon = 9;}
  203. elsif($month =~ /Nov/) {$mon = 10;}
  204. elsif($month =~ /Dec/) {$mon = 11;}
  205. return timelocal($sec,$min,$hour,$day,$mon,$year);
  206. }
  207. # This is a subroutine to sort maildir files into time-order. The second field
  208. # is the microsecond field, and may vary in length, so must be compared
  209. # numerically.
  210. sub maildirsort {
  211. return $a cmp $b if ($a !~ /^\d+\.H\d/ || $b !~ /^\d+\.H\d/);
  212. my($x1,$y1) = $a =~ /^(\d+)\.H(\d+)/;
  213. my($x2,$y2) = $b =~ /^(\d+)\.H(\d+)/;
  214. return ($x1 != $x2)? ($x1 <=> $x2) : ($y1 <=> $y2);
  215. }
  216. ##################################################
  217. # Subroutine list files below a directory #
  218. ##################################################
  219. # This is used to build up a list of expected mail files below a certain path
  220. # in the directory tree. It has to be recursive in order to deal with multiple
  221. # maildir mailboxes.
  222. sub list_files_below {
  223. my($dir) = $_[0];
  224. my(@yield) = ();
  225. my(@sublist, $file);
  226. opendir(DIR, $dir) || tests_exit(-1, "Failed to open $dir: $!");
  227. @sublist = sort maildirsort readdir(DIR);
  228. closedir(DIR);
  229. foreach $file (@sublist)
  230. {
  231. next if $file eq "." || $file eq ".." || $file eq "CVS";
  232. if (-d "$dir/$file")
  233. { @yield = (@yield, list_files_below("$dir/$file")); }
  234. else
  235. { push @yield, "$dir/$file"; }
  236. }
  237. return @yield;
  238. }
  239. ##################################################
  240. # Munge a file before comparing #
  241. ##################################################
  242. # The pre-processing turns all dates, times, Exim versions, message ids, and so
  243. # on into standard values, so that the compare works. Perl's substitution with
  244. # an expression provides a neat way to do some of these changes.
  245. # We keep a global associative array for repeatedly turning the same values
  246. # into the same standard values throughout the data from a single test.
  247. # Message ids get this treatment (can't be made reliable for times), and
  248. # times in dumped retry databases are also handled in a special way, as are
  249. # incoming port numbers.
  250. # On entry to the subroutine, the file to write to is already opened with the
  251. # name MUNGED. The input file name is the only argument to the subroutine.
  252. # Certain actions are taken only when the name contains "stderr", "stdout",
  253. # or "log". The yield of the function is 1 if a line matching "*** truncated
  254. # ***" is encountered; otherwise it is 0.
  255. sub munge {
  256. my($file) = $_[0];
  257. my($extra) = $_[1];
  258. my($yield) = 0;
  259. my(@saved) = ();
  260. local $_;
  261. open(IN, "$file") || tests_exit(-1, "Failed to open $file: $!");
  262. my($is_log) = $file =~ /log/;
  263. my($is_stdout) = $file =~ /stdout/;
  264. my($is_stderr) = $file =~ /stderr/;
  265. # Date pattern
  266. $date = "\\d{2}-\\w{3}-\\d{4}\\s\\d{2}:\\d{2}:\\d{2}";
  267. # Pattern for matching pids at start of stderr lines; initially something
  268. # that won't match.
  269. $spid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  270. # Scan the file and make the changes. Near the bottom there are some changes
  271. # that are specific to certain file types, though there are also some of those
  272. # inline too.
  273. while(<IN>)
  274. {
  275. RESET_AFTER_EXTRA_LINE_READ:
  276. # Custom munges
  277. if ($extra)
  278. {
  279. next if $extra =~ m%^/% && eval $extra;
  280. eval $extra if $extra =~ m/^s/;
  281. }
  282. # Check for "*** truncated ***"
  283. $yield = 1 if /\*\*\* truncated \*\*\*/;
  284. # Replace the name of this host
  285. s/\Q$parm_hostname\E/the.local.host.name/g;
  286. # But convert "name=the.local.host address=127.0.0.1" to use "localhost"
  287. s/name=the\.local\.host address=127\.0\.0\.1/name=localhost address=127.0.0.1/g;
  288. # The name of the shell may vary
  289. s/\s\Q$parm_shell\E\b/ ENV_SHELL/;
  290. # Replace the path to the testsuite directory
  291. s?\Q$parm_cwd\E?TESTSUITE?g;
  292. # Replace the Exim version number (may appear in various places)
  293. # patchexim should have fixed this for us
  294. #s/(Exim) \d+\.\d+[\w_-]*/$1 x.yz/i;
  295. # Replace Exim message ids by a unique series
  296. s/((?:[^\W_]{6}-){2}[^\W_]{2})
  297. /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
  298. # The names of lock files appear in some error and debug messages
  299. s/\.lock(\.[-\w]+)+(\.[\da-f]+){2}/.lock.test.ex.dddddddd.pppppppp/;
  300. # Unless we are in an IPv6 test, replace IPv4 and/or IPv6 in "listening on
  301. # port" message, because it is not always the same.
  302. s/port (\d+) \([^)]+\)/port $1/g
  303. if !$is_ipv6test && m/listening for SMTP(S?) on port/;
  304. # Challenges in SPA authentication
  305. s/TlRMTVNTUAACAAAAAAAAAAAoAAABgg[\w+\/]+/TlRMTVNTUAACAAAAAAAAAAAoAAABggAAAEbBRwqFwwIAAAAAAAAAAAAt1sgAAAAA/;
  306. # PRVS values
  307. s?prvs=([^/]+)/[\da-f]{10}@?prvs=$1/xxxxxxxxxx@?g; # Old form
  308. s?prvs=[\da-f]{10}=([^@]+)@?prvs=xxxxxxxxxx=$1@?g; # New form
  309. # Error lines on stdout from SSL contain process id values and file names.
  310. # They also contain a source file name and line number, which may vary from
  311. # release to release.
  312. s/^\d+:error:/pppp:error:/;
  313. s/:(?:\/[^\s:]+\/)?([^\/\s]+\.c):\d+:/:$1:dddd:/;
  314. # There are differences in error messages between OpenSSL versions
  315. s/SSL_CTX_set_cipher_list/SSL_connect/;
  316. # One error test in expansions mentions base 62 or 36
  317. s/is not a base (36|62) number/is not a base 36\/62 number/;
  318. # This message sometimes has a different number of seconds
  319. s/forced fail after \d seconds/forced fail after d seconds/;
  320. # This message may contain a different DBM library name
  321. s/Failed to open \S+( \([^\)]+\))? file/Failed to open DBM file/;
  322. # The message for a non-listening FIFO varies
  323. s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;
  324. # Debugging output of lists of hosts may have different sort keys
  325. s/sort=\S+/sort=xx/ if /^\S+ (?:\d+\.){3}\d+ mx=\S+ sort=\S+/;
  326. # Random local part in callout cache testing
  327. s/myhost.test.ex-\d+-testing/myhost.test.ex-dddddddd-testing/;
  328. s/the.local.host.name-\d+-testing/the.local.host.name-dddddddd-testing/;
  329. # File descriptor numbers may vary
  330. s/^writing data block fd=\d+/writing data block fd=dddd/;
  331. s/running as transport filter: write=\d+ read=\d+/running as transport filter: write=dddd read=dddd/;
  332. # ======== Dumpdb output ========
  333. # This must be before the general date/date munging.
  334. # Time data lines, which look like this:
  335. # 25-Aug-2000 12:11:37 25-Aug-2000 12:11:37 26-Aug-2000 12:11:37
  336. if (/^($date)\s+($date)\s+($date)(\s+\*)?\s*$/)
  337. {
  338. my($date1,$date2,$date3,$expired) = ($1,$2,$3,$4);
  339. $expired = "" if !defined $expired;
  340. my($increment) = date_seconds($date3) - date_seconds($date2);
  341. # We used to use globally unique replacement values, but timing
  342. # differences make this impossible. Just show the increment on the
  343. # last one.
  344. printf MUNGED ("first failed = time last try = time2 next try = time2 + %s%s\n",
  345. $increment, $expired);
  346. next;
  347. }
  348. # more_errno values in exim_dumpdb output which are times
  349. s/T:(\S+)\s-22\s(\S+)\s/T:$1 -22 xxxx /;
  350. # ======== Dates and times ========
  351. # Dates and times are all turned into the same value - trying to turn
  352. # them into different ones cannot be done repeatedly because they are
  353. # real time stamps generated while running the test. The actual date and
  354. # time used was fixed when I first started running automatic Exim tests.
  355. # Date/time in header lines and SMTP responses
  356. 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}
  357. /Tue, 2 Mar 1999 09:44:33 +0000/gx;
  358. # Date/time in logs and in one instance of a filter test
  359. 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;
  360. s/^Logwrite\s"\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Logwrite "1999-03-02 09:44:33/gx;
  361. # Date/time in message separators
  362. s/(?:[A-Z][a-z]{2}\s){2}\d\d\s\d\d:\d\d:\d\d\s\d\d\d\d
  363. /Tue Mar 02 09:44:33 1999/gx;
  364. # Date of message arrival in spool file as shown by -Mvh
  365. s/^\d{9,10}\s0$/ddddddddd 0/;
  366. # Date/time in mbx mailbox files
  367. 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;
  368. # Dates/times in debugging output for writing retry records
  369. if (/^ first failed=(\d+) last try=(\d+) next try=(\d+) (.*)$/)
  370. {
  371. my($next) = $3 - $2;
  372. $_ = " first failed=dddd last try=dddd next try=+$next $4\n";
  373. }
  374. s/^(\s*)now=\d+ first_failed=\d+ next_try=\d+ expired=(\d)/$1now=tttt first_failed=tttt next_try=tttt expired=$2/;
  375. s/^(\s*)received_time=\d+ diff=\d+ timeout=(\d+)/$1received_time=tttt diff=tttt timeout=$2/;
  376. # Time to retry may vary
  377. s/time to retry = \S+/time to retry = tttt/;
  378. s/retry record exists: age=\S+/retry record exists: age=ttt/;
  379. s/failing_interval=\S+ message_age=\S+/failing_interval=ttt message_age=ttt/;
  380. # Date/time in exim -bV output
  381. s/\d\d-[A-Z][a-z]{2}-\d{4}\s\d\d:\d\d:\d\d/07-Mar-2000 12:21:52/g;
  382. # Time on queue tolerance
  383. s/(QT|D)=1s/$1=0s/;
  384. # Eximstats heading
  385. s/Exim\sstatistics\sfrom\s\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\sto\s
  386. \d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Exim statistics from <time> to <time>/x;
  387. # Treat ECONNRESET the same as ECONNREFUSED. At least some systems give
  388. # us the former on a new connection.
  389. s/(could not connect to .*: Connection) reset by peer$/$1 refused/;
  390. # ======== TLS certificate algorithms ========
  391. # Test machines might have various different TLS library versions supporting
  392. # different protocols; can't rely upon TLS 1.2's AES256-GCM-SHA384, so we
  393. # treat the standard algorithms the same.
  394. # So far, have seen:
  395. # TLSv1:AES128-GCM-SHA256:128
  396. # TLSv1:AES256-SHA:256
  397. # TLSv1.1:AES256-SHA:256
  398. # TLSv1.2:AES256-GCM-SHA384:256
  399. # TLSv1.2:DHE-RSA-AES256-SHA:256
  400. # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
  401. # We also need to handle the ciphersuite without the TLS part present, for
  402. # client-ssl's output. We also see some older forced ciphersuites, but
  403. # negotiating TLS 1.2 instead of 1.0.
  404. # Mail headers (...), log-lines X=..., client-ssl output ...
  405. # (and \b doesn't match between ' ' and '(' )
  406. s/( (?: (?:\b|\s) [\(=] ) | \s )TLSv1\.[12]:/$1TLSv1:/xg;
  407. s/\bAES128-GCM-SHA256:128\b/AES256-SHA:256/g;
  408. s/\bAES128-GCM-SHA256\b/AES256-SHA/g;
  409. s/\bAES256-GCM-SHA384\b/AES256-SHA/g;
  410. s/\bDHE-RSA-AES256-SHA\b/AES256-SHA/g;
  411. # GnuTLS have seen:
  412. # TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256
  413. # TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128
  414. # TLS1.2:RSA_AES_256_CBC_SHA1:256 (canonical)
  415. # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
  416. #
  417. # X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256
  418. # X=TLS1.2:RSA_AES_256_CBC_SHA1:256
  419. # X=TLS1.1:RSA_AES_256_CBC_SHA1:256
  420. # X=TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256
  421. # and as stand-alone cipher:
  422. # ECDHE-RSA-AES256-SHA
  423. # DHE-RSA-AES256-SHA256
  424. # DHE-RSA-AES256-SHA
  425. # picking latter as canonical simply because regex easier that way.
  426. s/\bDHE_RSA_AES_128_CBC_SHA1:128/RSA_AES_256_CBC_SHA1:256/g;
  427. 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;
  428. s/\b(ECDHE-RSA-AES256-SHA|DHE-RSA-AES256-SHA256)\b/AES256-SHA/g;
  429. # GnuTLS library error message changes
  430. s/No certificate was found/The peer did not send any certificate/g;
  431. #(dodgy test?) s/\(certificate verification failed\): invalid/\(gnutls_handshake\): The peer did not send any certificate./g;
  432. s/\(gnutls_priority_set\): No or insufficient priorities were set/\(gnutls_handshake\): Could not negotiate a supported cipher suite/g;
  433. # (this new one is a generic channel-read error, but the testsuite
  434. # only hits it in one place)
  435. 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;
  436. # (replace old with new, hoping that old only happens in one situation)
  437. 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;
  438. 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;
  439. # signature algorithm names
  440. s/RSA-SHA1/RSA-SHA/;
  441. # ======== Caller's login, uid, gid, home, gecos ========
  442. s/\Q$parm_caller_home\E/CALLER_HOME/g; # NOTE: these must be done
  443. s/\b\Q$parm_caller\E\b/CALLER/g; # in this order!
  444. s/\b\Q$parm_caller_group\E\b/CALLER/g; # In case group name different
  445. s/\beuid=$parm_caller_uid\b/euid=CALLER_UID/g;
  446. s/\begid=$parm_caller_gid\b/egid=CALLER_GID/g;
  447. s/\buid=$parm_caller_uid\b/uid=CALLER_UID/g;
  448. s/\bgid=$parm_caller_gid\b/gid=CALLER_GID/g;
  449. s/\bname="?$parm_caller_gecos"?/name=CALLER_GECOS/g;
  450. # When looking at spool files with -Mvh, we will find not only the caller
  451. # login, but also the uid and gid. It seems that $) in some Perls gives all
  452. # the auxiliary gids as well, so don't bother checking for that.
  453. s/^CALLER $> \d+$/CALLER UID GID/;
  454. # There is one case where the caller's login is forced to something else,
  455. # in order to test the processing of logins that contain spaces. Weird what
  456. # some people do, isn't it?
  457. s/^spaced user $> \d+$/CALLER UID GID/;
  458. # ======== Exim's login ========
  459. # For messages received by the daemon, this is in the -H file, which some
  460. # tests inspect. For bounce messages, this will appear on the U= lines in
  461. # logs and also after Received: and in addresses. In one pipe test it appears
  462. # after "Running as:". It also appears in addresses, and in the names of lock
  463. # files.
  464. s/U=$parm_eximuser/U=EXIMUSER/;
  465. s/user=$parm_eximuser/user=EXIMUSER/;
  466. s/login=$parm_eximuser/login=EXIMUSER/;
  467. s/Received: from $parm_eximuser /Received: from EXIMUSER /;
  468. s/Running as: $parm_eximuser/Running as: EXIMUSER/;
  469. s/\b$parm_eximuser@/EXIMUSER@/;
  470. s/\b$parm_eximuser\.lock\./EXIMUSER.lock./;
  471. s/\beuid=$parm_exim_uid\b/euid=EXIM_UID/g;
  472. s/\begid=$parm_exim_gid\b/egid=EXIM_GID/g;
  473. s/\buid=$parm_exim_uid\b/uid=EXIM_UID/g;
  474. s/\bgid=$parm_exim_gid\b/gid=EXIM_GID/g;
  475. s/^$parm_eximuser $parm_exim_uid $parm_exim_gid/EXIMUSER EXIM_UID EXIM_GID/;
  476. # ======== General uids, gids, and pids ========
  477. # Note: this must come after munges for caller's and exim's uid/gid
  478. # These are for systems where long int is 64
  479. s/\buid=4294967295/uid=-1/;
  480. s/\beuid=4294967295/euid=-1/;
  481. s/\bgid=4294967295/gid=-1/;
  482. s/\begid=4294967295/egid=-1/;
  483. s/\bgid=\d+/gid=gggg/;
  484. s/\begid=\d+/egid=gggg/;
  485. s/\bpid=\d+/pid=pppp/;
  486. s/\buid=\d+/uid=uuuu/;
  487. s/\beuid=\d+/euid=uuuu/;
  488. s/set_process_info:\s+\d+/set_process_info: pppp/;
  489. s/queue run pid \d+/queue run pid ppppp/;
  490. s/process \d+ running as transport filter/process pppp running as transport filter/;
  491. s/process \d+ writing to transport filter/process pppp writing to transport filter/;
  492. s/reading pipe for subprocess \d+/reading pipe for subprocess pppp/;
  493. s/remote delivery process \d+ ended/remote delivery process pppp ended/;
  494. # Pid in temp file in appendfile transport
  495. s"test-mail/temp\.\d+\."test-mail/temp.pppp.";
  496. # Optional pid in log lines
  497. s/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)(\s[+-]\d\d\d\d|)(\s\[\d+\])/
  498. "$1$2 [" . new_value($3, "%s", \$next_pid) . "]"/gxe;
  499. # Detect a daemon stderr line with a pid and save the pid for subsequent
  500. # removal from following lines.
  501. $spid = $1 if /^(\s*\d+) (?:listening|LOG: MAIN|(?:daemon_smtp_port|local_interfaces) overridden by)/;
  502. s/^$spid //;
  503. # Queue runner waiting messages
  504. s/waiting for children of \d+/waiting for children of pppp/;
  505. s/waiting for (\S+) \(\d+\)/waiting for $1 (pppp)/;
  506. # ======== Port numbers ========
  507. # Incoming port numbers may vary, but not in daemon startup line.
  508. s/^Port: (\d+)/"Port: " . new_value($1, "%s", \$next_port)/e;
  509. s/\(port=(\d+)/"(port=" . new_value($1, "%s", \$next_port)/e;
  510. # This handles "connection from" and the like, when the port is given
  511. if (!/listening for SMTP on/ && !/Connecting to/ && !/=>/ && !/->/
  512. && !/\*>/ && !/Connection refused/)
  513. {
  514. s/\[([a-z\d:]+|\d+(?:\.\d+){3})\]:(\d+)/"[".$1."]:".new_value($2,"%s",\$next_port)/ie;
  515. }
  516. # Port in host address in spool file output from -Mvh
  517. s/^-host_address (.*)\.\d+/-host_address $1.9999/;
  518. # ======== Local IP addresses ========
  519. # The amount of space between "host" and the address in verification output
  520. # depends on the length of the host name. We therefore reduce it to one space
  521. # for all of them.
  522. # Also, the length of space at the end of the host line is dependent
  523. # on the length of the longest line, so strip it also on otherwise
  524. # un-rewritten lines like localhost
  525. s/^\s+host\s(\S+)\s+(\S+)/ host $1 $2/;
  526. s/^\s+(host\s\S+\s\S+)\s+(port=.*)/ host $1 $2/;
  527. s/^\s+(host\s\S+\s\S+)\s+(?=MX=)/ $1 /;
  528. s/^\s+host\s.*?\K\s+(ad=\S+)/ $1/;
  529. s/host\s\Q$parm_ipv4\E\s\[\Q$parm_ipv4\E\]/host ipv4.ipv4.ipv4.ipv4 [ipv4.ipv4.ipv4.ipv4]/;
  530. 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]/;
  531. s/\b\Q$parm_ipv4\E\b/ip4.ip4.ip4.ip4/g;
  532. s/(^|\W)\K\Q$parm_ipv6\E/ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6/g;
  533. s/\b\Q$parm_ipv4r\E\b/ip4-reverse/g;
  534. s/(^|\W)\K\Q$parm_ipv6r\E/ip6-reverse/g;
  535. s/^(\s+host\s\S+\s+\[\S+\]) +$/$1 /;
  536. # ======== Test network IP addresses ========
  537. s/(\b|_)\Q$parm_ipv4_test_net\E(?=\.\d+\.\d+\.\d+\b|_|\.rbl|\.in-addr|\.test\.again\.dns)/$1V4NET/g;
  538. s/\b\Q$parm_ipv6_test_net\E(?=:[\da-f]+:[\da-f]+:[\da-f]+)/V6NET/gi;
  539. # ======== IP error numbers and messages ========
  540. # These vary between operating systems
  541. s/Can't assign requested address/Network Error/;
  542. s/Cannot assign requested address/Network Error/;
  543. s/Operation timed out/Connection timed out/;
  544. s/Address family not supported by protocol family/Network Error/;
  545. s/Network is unreachable/Network Error/;
  546. s/Invalid argument/Network Error/;
  547. s/\(\d+\): Network/(dd): Network/;
  548. s/\(\d+\): Connection refused/(dd): Connection refused/;
  549. s/\(\d+\): Connection timed out/(dd): Connection timed out/;
  550. s/\d+ 65 Connection refused/dd 65 Connection refused/;
  551. s/\d+ 321 Connection timed out/dd 321 Connection timed out/;
  552. # ======== Other error numbers ========
  553. s/errno=\d+/errno=dd/g;
  554. # ======== System Error Messages ======
  555. # depending on the underlaying file system the error message seems to differ
  556. s/(?: is not a regular file)|(?: has too many links \(\d+\))/ not a regular file or too many links/;
  557. # ======== Output from ls ========
  558. # Different operating systems use different spacing on long output
  559. #s/ +/ /g if /^[-rwd]{10} /;
  560. # (Bug 1226) SUSv3 allows a trailing printable char for modified access method control.
  561. # Handle only the Gnu and MacOS space, dot, plus and at-sign. A full [[:graph:]]
  562. # unfortunately matches a non-ls linefull of dashes.
  563. # Allow the case where we've already picked out the file protection bits.
  564. if (s/^([-d](?:[-r][-w][-SsTtx]){3})[.+@]?( +|$)/$1$2/) {
  565. s/ +/ /g;
  566. }
  567. # ======== Message sizes =========
  568. # Message sizes vary, owing to different logins and host names that get
  569. # automatically inserted. I can't think of any way of even approximately
  570. # comparing these.
  571. s/([\s,])S=\d+\b/$1S=sss/;
  572. s/:S\d+\b/:Ssss/;
  573. s/^(\s*\d+m\s+)\d+(\s+[a-z0-9-]{16} <)/$1sss$2/i if $is_stdout;
  574. s/\sSIZE=\d+\b/ SIZE=ssss/;
  575. s/\ssize=\d+\b/ size=sss/ if $is_stderr;
  576. s/old size = \d+\b/old size = sssss/;
  577. s/message size = \d+\b/message size = sss/;
  578. s/this message = \d+\b/this message = sss/;
  579. s/Size of headers = \d+/Size of headers = sss/;
  580. s/sum=(?!0)\d+/sum=dddd/;
  581. s/(?<=sum=dddd )count=\d+\b/count=dd/;
  582. s/(?<=sum=0 )count=\d+\b/count=dd/;
  583. s/,S is \d+\b/,S is ddddd/;
  584. s/\+0100,\d+;/+0100,ddd;/;
  585. s/\(\d+ bytes written\)/(ddd bytes written)/;
  586. s/added '\d+ 1'/added 'ddd 1'/;
  587. s/Received\s+\d+/Received nnn/;
  588. s/Delivered\s+\d+/Delivered nnn/;
  589. # ======== Values in spool space failure message ========
  590. s/space=\d+ inodes=[+-]?\d+/space=xxxxx inodes=xxxxx/;
  591. # ======== Filter sizes ========
  592. # The sizes of filter files may vary because of the substitution of local
  593. # filenames, logins, etc.
  594. s/^\d+(?= bytes read from )/ssss/;
  595. # ======== OpenSSL error messages ========
  596. # Different releases of the OpenSSL libraries seem to give different error
  597. # numbers, or handle specific bad conditions in different ways, leading to
  598. # different wording in the error messages, so we cannot compare them.
  599. s/(TLS error on connection (?:from .* )?\(SSL_\w+\): error:)(.*)/$1 <<detail omitted>>/;
  600. # ======== Maildir things ========
  601. # timestamp output in maildir processing
  602. s/(timestamp=|\(timestamp_only\): )\d+/$1ddddddd/g;
  603. # maildir delivery files appearing in log lines (in cases of error)
  604. s/writing to(?: file)? tmp\/\d+\.[^.]+\.(\S+)/writing to tmp\/MAILDIR.$1/;
  605. s/renamed tmp\/\d+\.[^.]+\.(\S+) as new\/\d+\.[^.]+\.(\S+)/renamed tmp\/MAILDIR.$1 as new\/MAILDIR.$1/;
  606. # Maildir file names in general
  607. s/\b\d+\.H\d+P\d+\b/dddddddddd.HddddddPddddd/;
  608. # Maildirsize data
  609. while (/^\d+S,\d+C\s*$/)
  610. {
  611. print MUNGED;
  612. while (<IN>)
  613. {
  614. last if !/^\d+ \d+\s*$/;
  615. print MUNGED "ddd d\n";
  616. }
  617. last if !defined $_;
  618. }
  619. last if !defined $_;
  620. # ======== Output from the "fd" program about open descriptors ========
  621. # The statuses seem to be different on different operating systems, but
  622. # at least we'll still be checking the number of open fd's.
  623. s/max fd = \d+/max fd = dddd/;
  624. s/status=0 RDONLY/STATUS/g;
  625. s/status=1 WRONLY/STATUS/g;
  626. s/status=2 RDWR/STATUS/g;
  627. # ======== Contents of spool files ========
  628. # A couple of tests dump the contents of the -H file. The length fields
  629. # will be wrong because of different user names, etc.
  630. s/^\d\d\d(?=[PFS*])/ddd/;
  631. # ========= Exim lookups ==================
  632. # Lookups have a char which depends on the number of lookup types compiled in,
  633. # in stderr output. Replace with a "0". Recognising this while avoiding
  634. # other output is fragile; perhaps the debug output should be revised instead.
  635. s%(?<!sqlite)(?<!lsearch\*@)(?<!lsearch\*)(?<!lsearch)[0-?]TESTSUITE/aux-fixed/%0TESTSUITE/aux-fixed/%g;
  636. # ==========================================================
  637. # MIME boundaries in RFC3461 DSN messages
  638. s/\d{8,10}-eximdsn-\d+/NNNNNNNNNN-eximdsn-MMMMMMMMMM/;
  639. # ==========================================================
  640. # Some munging is specific to the specific file types
  641. # ======== stdout ========
  642. if ($is_stdout)
  643. {
  644. # Skip translate_ip_address and use_classresources in -bP output because
  645. # they aren't always there.
  646. next if /translate_ip_address =/;
  647. next if /use_classresources/;
  648. # In certain filter tests, remove initial filter lines because they just
  649. # clog up by repetition.
  650. if ($rmfiltertest)
  651. {
  652. next if /^(Sender\staken\sfrom|
  653. Return-path\scopied\sfrom|
  654. Sender\s+=|
  655. Recipient\s+=)/x;
  656. if (/^Testing \S+ filter/)
  657. {
  658. $_ = <IN>; # remove blank line
  659. next;
  660. }
  661. }
  662. # openssl version variances
  663. next if /^SSL info: unknown state/;
  664. next if /^SSL info: SSLv2\/v3 write client hello A/;
  665. next if /^SSL info: SSLv3 read server key exchange A/;
  666. }
  667. # ======== stderr ========
  668. elsif ($is_stderr)
  669. {
  670. # The very first line of debugging output will vary
  671. s/^Exim version .*/Exim version x.yz ..../;
  672. # Debugging lines for Exim terminations
  673. s/(?<=^>>>>>>>>>>>>>>>> Exim pid=)\d+(?= terminating)/pppp/;
  674. # IP address lookups use gethostbyname() when IPv6 is not supported,
  675. # and gethostbyname2() or getipnodebyname() when it is.
  676. s/\bgethostbyname2?|\bgetipnodebyname/get[host|ipnode]byname[2]/;
  677. # drop gnutls version strings
  678. next if /GnuTLS compile-time version: \d+[\.\d]+$/;
  679. next if /GnuTLS runtime version: \d+[\.\d]+$/;
  680. # drop openssl version strings
  681. next if /OpenSSL compile-time version: OpenSSL \d+[\.\da-z]+/;
  682. next if /OpenSSL runtime version: OpenSSL \d+[\.\da-z]+/;
  683. # drop lookups
  684. next if /^Lookups \(built-in\):/;
  685. next if /^Loading lookup modules from/;
  686. next if /^Loaded \d+ lookup modules/;
  687. next if /^Total \d+ lookups/;
  688. # drop compiler information
  689. next if /^Compiler:/;
  690. # and the ugly bit
  691. # different libraries will have different numbers (possibly 0) of follow-up
  692. # lines, indenting with more data
  693. if (/^Library version:/) {
  694. while (1) {
  695. $_ = <IN>;
  696. next if /^\s/;
  697. goto RESET_AFTER_EXTRA_LINE_READ;
  698. }
  699. }
  700. # drop other build-time controls emitted for debugging
  701. next if /^WHITELIST_D_MACROS:/;
  702. next if /^TRUSTED_CONFIG_LIST:/;
  703. # As of Exim 4.74, we log when a setgid fails; because we invoke Exim
  704. # with -be, privileges will have been dropped, so this will always
  705. # be the case
  706. next if /^changing group to \d+ failed: (Operation not permitted|Not owner)/;
  707. # We might not keep this check; rather than change all the tests, just
  708. # ignore it as long as it succeeds; then we only need to change the
  709. # TLS tests where tls_require_ciphers has been set.
  710. if (m{^changed uid/gid: calling tls_validate_require_cipher}) {
  711. my $discard = <IN>;
  712. next;
  713. }
  714. next if /^tls_validate_require_cipher child \d+ ended: status=0x0/;
  715. # We invoke Exim with -D, so we hit this new messag as of Exim 4.73:
  716. next if /^macros_trusted overridden to true by whitelisting/;
  717. # We have to omit the localhost ::1 address so that all is well in
  718. # the IPv4-only case.
  719. print MUNGED "MUNGED: ::1 will be omitted in what follows\n"
  720. if (/looked up these IP addresses/);
  721. next if /name=localhost address=::1/;
  722. # drop pdkim debugging header
  723. next if /^PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+$/;
  724. # Various other IPv6 lines must be omitted too
  725. next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
  726. next if /get\[host\|ipnode\]byname\[2\]\(af=inet6\)/;
  727. next if /DNS lookup of \S+ \(AAAA\) using fakens/;
  728. next if / in dns_ipv4_lookup?/;
  729. if (/DNS lookup of \S+ \(AAAA\) gave NO_DATA/)
  730. {
  731. $_= <IN>; # Gets "returning DNS_NODATA"
  732. next;
  733. }
  734. # Skip tls_advertise_hosts and hosts_require_tls checks when the options
  735. # are unset, because tls ain't always there.
  736. next if /in\s(?:tls_advertise_hosts\?|hosts_require_tls\?)
  737. \sno\s\(option\sunset\)/x;
  738. # Skip auxiliary group lists because they will vary.
  739. next if /auxiliary group list:/;
  740. # Skip "extracted from gecos field" because the gecos field varies
  741. next if /extracted from gecos field/;
  742. # Skip "waiting for data on socket" and "read response data: size=" lines
  743. # because some systems pack more stuff into packets than others.
  744. next if /waiting for data on socket/;
  745. next if /read response data: size=/;
  746. # If Exim is compiled with readline support but it can't find the library
  747. # to load, there will be an extra debug line. Omit it.
  748. next if /failed to load readline:/;
  749. # Some DBM libraries seem to make DBM files on opening with O_RDWR without
  750. # O_CREAT; other's don't. In the latter case there is some debugging output
  751. # which is not present in the former. Skip the relevant lines (there are
  752. # two of them).
  753. if (/TESTSUITE\/spool\/db\/\S+ appears not to exist: trying to create/)
  754. {
  755. $_ = <IN>;
  756. next;
  757. }
  758. # Some tests turn on +expand debugging to check on expansions.
  759. # Unfortunately, the Received: expansion varies, depending on whether TLS
  760. # is compiled or not. So we must remove the relevant debugging if it is.
  761. if (/^condition: def:tls_cipher/)
  762. {
  763. while (<IN>) { last if /^condition: def:sender_address/; }
  764. }
  765. elsif (/^expanding: Received: /)
  766. {
  767. while (<IN>) { last if !/^\s/; }
  768. }
  769. # When Exim is checking the size of directories for maildir, it uses
  770. # the check_dir_size() function to scan directories. Of course, the order
  771. # of the files that are obtained using readdir() varies from system to
  772. # system. We therefore buffer up debugging lines from check_dir_size()
  773. # and sort them before outputting them.
  774. if (/^check_dir_size:/ || /^skipping TESTSUITE\/test-mail\//)
  775. {
  776. push @saved, $_;
  777. }
  778. else
  779. {
  780. if (@saved > 0)
  781. {
  782. print MUNGED "MUNGED: the check_dir_size lines have been sorted " .
  783. "to ensure consistency\n";
  784. @saved = sort(@saved);
  785. print MUNGED @saved;
  786. @saved = ();
  787. }
  788. # Skip hosts_require_dane checks when the options
  789. # are unset, because dane ain't always there.
  790. next if /in\shosts_require_dane\?\sno\s\(option\sunset\)/x;
  791. # Experimental_International
  792. next if / in smtputf8_advertise_hosts\? no \(option unset\)/;
  793. # Skip some lines that Exim puts out at the start of debugging output
  794. # because they will be different in different binaries.
  795. print MUNGED
  796. unless (/^Berkeley DB: / ||
  797. /^Probably (?:Berkeley DB|ndbm|GDBM)/ ||
  798. /^Authenticators:/ ||
  799. /^Lookups:/ ||
  800. /^Support for:/ ||
  801. /^Routers:/ ||
  802. /^Transports:/ ||
  803. /^log selectors =/ ||
  804. /^cwd=/ ||
  805. /^Fixed never_users:/ ||
  806. /^Size of off_t:/
  807. );
  808. }
  809. next;
  810. }
  811. # ======== log ========
  812. elsif ($is_log)
  813. {
  814. # Berkeley DB version differences
  815. next if / Berkeley DB error: /;
  816. }
  817. # ======== All files other than stderr ========
  818. print MUNGED;
  819. }
  820. close(IN);
  821. return $yield;
  822. }
  823. ##################################################
  824. # Subroutine to interact with caller #
  825. ##################################################
  826. # Arguments: [0] the prompt string
  827. # [1] if there is a U in the prompt and $force_update is true
  828. # [2] if there is a C in the prompt and $force_continue is true
  829. # Returns: returns the answer
  830. sub interact{
  831. print $_[0];
  832. if ($_[1]) { $_ = "u"; print "... update forced\n"; }
  833. elsif ($_[2]) { $_ = "c"; print "... continue forced\n"; }
  834. else { $_ = <T>; }
  835. }
  836. ##################################################
  837. # Subroutine to log in force_continue mode #
  838. ##################################################
  839. # In force_continue mode, we just want a terse output to a statically
  840. # named logfile. If multiple files in same batch (stdout, stderr, etc)
  841. # all have mismatches, it will log multiple times.
  842. #
  843. # Arguments: [0] the logfile to append to
  844. # [1] the testno that failed
  845. # Returns: nothing
  846. sub log_failure {
  847. my $logfile = shift();
  848. my $testno = shift();
  849. my $detail = shift() || '';
  850. if ( open(my $fh, ">>", $logfile) ) {
  851. print $fh "Test $testno $detail failed\n";
  852. close $fh;
  853. }
  854. }
  855. ##################################################
  856. # Subroutine to compare one output file #
  857. ##################################################
  858. # When an Exim server is part of the test, its output is in separate files from
  859. # an Exim client. The server data is concatenated with the client data as part
  860. # of the munging operation.
  861. #
  862. # Arguments: [0] the name of the main raw output file
  863. # [1] the name of the server raw output file or undef
  864. # [2] where to put the munged copy
  865. # [3] the name of the saved file
  866. # [4] TRUE if this is a log file whose deliveries must be sorted
  867. # [5] optionally, a custom munge command
  868. #
  869. # Returns: 0 comparison succeeded or differences to be ignored
  870. # 1 comparison failed; files may have been updated (=> re-compare)
  871. #
  872. # Does not return if the user replies "Q" to a prompt.
  873. sub check_file{
  874. my($rf,$rsf,$mf,$sf,$sortfile,$extra) = @_;
  875. # If there is no saved file, the raw files must either not exist, or be
  876. # empty. The test ! -s is TRUE if the file does not exist or is empty.
  877. # we check if there is a flavour specific file, but we remember
  878. # the original file name as "generic"
  879. $sf_generic = $sf;
  880. $sf_flavour = "$sf_generic.$flavour";
  881. $sf_current = -e $sf_flavour ? $sf_flavour : $sf_generic;
  882. if (! -e $sf_current)
  883. {
  884. return 0 if (! -s $rf && (! defined $rsf || ! -s $rsf));
  885. print "\n";
  886. print "** $rf is not empty\n" if (-s $rf);
  887. print "** $rsf is not empty\n" if (defined $rsf && -s $rsf);
  888. for (;;)
  889. {
  890. print "Continue, Show, or Quit? [Q] ";
  891. $_ = $force_continue ? "c" : <T>;
  892. tests_exit(1) if /^q?$/i;
  893. log_failure($log_failed_filename, $testno, $rf) if (/^c$/i && $force_continue);
  894. return 0 if /^c$/i;
  895. last if (/^s$/);
  896. }
  897. foreach $f ($rf, $rsf)
  898. {
  899. if (defined $f && -s $f)
  900. {
  901. print "\n";
  902. print "------------ $f -----------\n"
  903. if (defined $rf && -s $rf && defined $rsf && -s $rsf);
  904. system("$more '$f'");
  905. }
  906. }
  907. print "\n";
  908. for (;;)
  909. {
  910. interact("Continue, Update & retry, Quit? [Q] ", $force_update, $force_continue);
  911. tests_exit(1) if /^q?$/i;
  912. log_failure($log_failed_filename, $testno, $rsf) if (/^c$/i && $force_continue);
  913. return 0 if /^c$/i;
  914. last if (/^u$/i);
  915. }
  916. }
  917. #### $_
  918. # Control reaches here if either (a) there is a saved file ($sf), or (b) there
  919. # was a request to create a saved file. First, create the munged file from any
  920. # data that does exist.
  921. open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
  922. my($truncated) = munge($rf, $extra) if -e $rf;
  923. if (defined $rsf && -e $rsf)
  924. {
  925. print MUNGED "\n******** SERVER ********\n";
  926. $truncated |= munge($rsf, $extra);
  927. }
  928. close(MUNGED);
  929. # If a saved file exists, do the comparison. There are two awkward cases:
  930. #
  931. # If "*** truncated ***" was found in the new file, it means that a log line
  932. # was overlong, and truncated. The problem is that it may be truncated at
  933. # different points on different systems, because of different user name
  934. # lengths. We reload the file and the saved file, and remove lines from the new
  935. # file that precede "*** truncated ***" until we reach one that matches the
  936. # line that precedes it in the saved file.
  937. #
  938. # If $sortfile is set, we are dealing with a mainlog file where the deliveries
  939. # for an individual message might vary in their order from system to system, as
  940. # a result of parallel deliveries. We load the munged file and sort sequences
  941. # of delivery lines.
  942. if (-e $sf_current)
  943. {
  944. # Deal with truncated text items
  945. if ($truncated)
  946. {
  947. my(@munged, @saved, $i, $j, $k);
  948. open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
  949. @munged = <MUNGED>;
  950. close(MUNGED);
  951. open(SAVED, $sf_current) || tests_exit(-1, "Failed to open $sf_current: $!");
  952. @saved = <SAVED>;
  953. close(SAVED);
  954. $j = 0;
  955. for ($i = 0; $i < @munged; $i++)
  956. {
  957. if ($munged[$i] =~ /\*\*\* truncated \*\*\*/)
  958. {
  959. for (; $j < @saved; $j++)
  960. { last if $saved[$j] =~ /\*\*\* truncated \*\*\*/; }
  961. last if $j >= @saved; # not found in saved
  962. for ($k = $i - 1; $k >= 0; $k--)
  963. { last if $munged[$k] eq $saved[$j - 1]; }
  964. last if $k <= 0; # failed to find previous match
  965. splice @munged, $k + 1, $i - $k - 1;
  966. $i = $k + 1;
  967. }
  968. }
  969. open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
  970. for ($i = 0; $i < @munged; $i++)
  971. { print MUNGED $munged[$i]; }
  972. close(MUNGED);
  973. }
  974. # Deal with log sorting
  975. if ($sortfile)
  976. {
  977. my(@munged, $i, $j);
  978. open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
  979. @munged = <MUNGED>;
  980. close(MUNGED);
  981. for ($i = 0; $i < @munged; $i++)
  982. {
  983. if ($munged[$i] =~ /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/)
  984. {
  985. for ($j = $i + 1; $j < @munged; $j++)
  986. {
  987. last if $munged[$j] !~
  988. /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/;
  989. }
  990. @temp = splice(@munged, $i, $j - $i);
  991. @temp = sort(@temp);
  992. splice(@munged, $i, 0, @temp);
  993. }
  994. }
  995. open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
  996. print MUNGED "**NOTE: The delivery lines in this file have been sorted.\n";
  997. for ($i = 0; $i < @munged; $i++)
  998. { print MUNGED $munged[$i]; }
  999. close(MUNGED);
  1000. }
  1001. # Do the comparison
  1002. return 0 if (system("$cf '$mf' '$sf_current' >test-cf") == 0);
  1003. # Handle comparison failure
  1004. print "** Comparison of $mf with $sf_current failed";
  1005. system("$more test-cf");
  1006. print "\n";
  1007. for (;;)
  1008. {
  1009. interact("Continue, Retry, Update current"
  1010. . ($sf_current ne $sf_flavour ? "/Save for flavour '$flavour'" : "")
  1011. . " & retry, Quit? [Q] ", $force_update, $force_continue);
  1012. tests_exit(1) if /^q?$/i;
  1013. log_failure($log_failed_filename, $testno, $sf_current) if (/^c$/i && $force_continue);
  1014. return 0 if /^c$/i;
  1015. return 1 if /^r$/i;
  1016. last if (/^[us]$/i);
  1017. }
  1018. }
  1019. # Update or delete the saved file, and give the appropriate return code.
  1020. if (-s $mf)
  1021. {
  1022. my $sf = /^u/i ? $sf_current : $sf_flavour;
  1023. tests_exit(-1, "Failed to cp $mf $sf") if system("cp '$mf' '$sf'") != 0;
  1024. }
  1025. else
  1026. {
  1027. # if we deal with a flavour file, we can't delete it, because next time the generic
  1028. # file would be used again
  1029. if ($sf_current eq $sf_flavour) {
  1030. open(FOO, ">$sf_current");
  1031. close(FOO);
  1032. }
  1033. else {
  1034. tests_exit(-1, "Failed to unlink $sf_current") if !unlink($sf_current);
  1035. }
  1036. }
  1037. return 1;
  1038. }
  1039. ##################################################
  1040. # Custom munges
  1041. # keyed by name of munge; value is a ref to a hash
  1042. # which is keyed by file, value a string to look for.
  1043. # Usable files are:
  1044. # paniclog, rejectlog, mainlog, stdout, stderr, msglog, mail
  1045. # Search strings starting with 's' do substitutions;
  1046. # with '/' do line-skips.
  1047. # Triggered by a scriptfile line "munge <name>"
  1048. ##################################################
  1049. $munges =
  1050. { 'dnssec' =>
  1051. { 'stderr' => '/^Reverse DNS security status: unverified\n/' },
  1052. 'gnutls_unexpected' =>
  1053. { 'mainlog' => '/\(recv\): A TLS packet with unexpected length was received./' },
  1054. 'gnutls_handshake' =>
  1055. { 'mainlog' => 's/\(gnutls_handshake\): Error in the push function/\(gnutls_handshake\): A TLS packet with unexpected length was received/' },
  1056. 'optional_events' =>
  1057. { 'stdout' => '/event_action =/' },
  1058. 'optional_ocsp' =>
  1059. { 'stderr' => '/127.0.0.1 in hosts_requ(ire|est)_ocsp/' },
  1060. 'no_tpt_filter_epipe' =>
  1061. { 'stderr' => '/^writing error 32: Broken pipe$/' },
  1062. 'optional_cert_hostnames' =>
  1063. { 'stderr' => '/in tls_verify_cert_hostnames\? no/' },
  1064. 'loopback' =>
  1065. { 'stdout' => 's/[[](127\.0\.0\.1|::1)]/[IP_LOOPBACK_ADDR]/' },
  1066. 'scanfile_size' =>
  1067. { 'stdout' => 's/(Content-length:) \d\d\d/$1 ddd/' },
  1068. 'delay_1500' =>
  1069. { 'stderr' => 's/(1[5-9]|23\d)\d\d msec/ssss msec/' },
  1070. };
  1071. ##################################################
  1072. # Subroutine to check the output of a test #
  1073. ##################################################
  1074. # This function is called when the series of subtests is complete. It makes
  1075. # use of check_file(), whose arguments are:
  1076. #
  1077. # [0] the name of the main raw output file
  1078. # [1] the name of the server raw output file or undef
  1079. # [2] where to put the munged copy
  1080. # [3] the name of the saved file
  1081. # [4] TRUE if this is a log file whose deliveries must be sorted
  1082. # [5] an optional custom munge command
  1083. #
  1084. # Arguments: Optionally, name of a single custom munge to run.
  1085. # Returns: 0 if the output compared equal
  1086. # 1 if re-run needed (files may have been updated)
  1087. sub check_output{
  1088. my($mungename) = $_[0];
  1089. my($yield) = 0;
  1090. my($munge) = $munges->{$mungename} if defined $mungename;
  1091. $yield = 1 if check_file("spool/log/paniclog",
  1092. "spool/log/serverpaniclog",
  1093. "test-paniclog-munged",
  1094. "paniclog/$testno", 0,
  1095. $munge->{'paniclog'});
  1096. $yield = 1 if check_file("spool/log/rejectlog",
  1097. "spool/log/serverrejectlog",
  1098. "test-rejectlog-munged",
  1099. "rejectlog/$testno", 0,
  1100. $munge->{'rejectlog'});
  1101. $yield = 1 if check_file("spool/log/mainlog",
  1102. "spool/log/servermainlog",
  1103. "test-mainlog-munged",
  1104. "log/$testno", $sortlog,
  1105. $munge->{'mainlog'});
  1106. if (!$stdout_skip)
  1107. {
  1108. $yield = 1 if check_file("test-stdout",
  1109. "test-stdout-server",
  1110. "test-stdout-munged",
  1111. "stdout/$testno", 0,
  1112. $munge->{'stdout'});
  1113. }
  1114. if (!$stderr_skip)
  1115. {
  1116. $yield = 1 if check_file("test-stderr",
  1117. "test-stderr-server",
  1118. "test-stderr-munged",
  1119. "stderr/$testno", 0,
  1120. $munge->{'stderr'});
  1121. }
  1122. # Compare any delivered messages, unless this test is skipped.
  1123. if (! $message_skip)
  1124. {
  1125. my($msgno) = 0;
  1126. # Get a list of expected mailbox files for this script. We don't bother with
  1127. # directories, just the files within them.
  1128. foreach $oldmail (@oldmails)
  1129. {
  1130. next unless $oldmail =~ /^mail\/$testno\./;
  1131. print ">> EXPECT $oldmail\n" if $debug;
  1132. $expected_mails{$oldmail} = 1;
  1133. }
  1134. # If there are any files in test-mail, compare them. Note that "." and
  1135. # ".." are automatically omitted by list_files_below().
  1136. @mails = list_files_below("test-mail");
  1137. foreach $mail (@mails)
  1138. {
  1139. next if $mail eq "test-mail/oncelog";
  1140. $saved_mail = substr($mail, 10); # Remove "test-mail/"
  1141. $saved_mail =~ s/^$parm_caller(\/|$)/CALLER/; # Convert caller name
  1142. if ($saved_mail =~ /(\d+\.[^.]+\.)/)
  1143. {
  1144. $msgno++;
  1145. $saved_mail =~ s/(\d+\.[^.]+\.)/$msgno./gx;
  1146. }

Large files files are truncated, but you can click here to view the full file