empserver/tests/normalize.pl
Markus Armbruster 49b2b13a90 New make target check
Just a smoke test so far, extracted from src/scripts/nightly/.  This
makes the existing smoke test more easily accessible.  Noteworthy
differences:

* Instead of patching the code to make output more stable, postprocess
  the output to normalize it.

* Compare actual results to expected results instead of the previous
  test run's results.

* Much faster.  The old test harness used sleep liberally to "ensure"
  things always happen in the same order.

Known shortcomings:

* The smoke test hangs when the server fails to complete startup, or
  fails to terminate.

* Normalization of xdump hardcodes columns instead of getting them
  from xdump meta.

* Normalization of time values in xdump is an ugly hack.

* xdump meta column type isn't normalized.  Actual values can vary
  between systems, because the width of enumeration types is
  implementation-defined.  The smoke test works only when they're
  represented as int, which is the case on common systems.

* Currently expected to work only with thread package LWP and a
  random() that behaves exactly like the one on my development system,
  because:

  - Thread scheduling is reliably deterministic only with LWP

  - The PRN sequence produced by random() isn't portable

  - Shell builtin kill appears not to do the job in MinGW

  - The Windows server tries to run as service when -d isn't
    specified

Further work is needed to address these shortcomings.

Getting C programs behave exactly the same on all systems is hard.
We'll likely run into system-dependent differences that upset the
smoke test.  Floating-point computation seems particularly vulnerable.

Instead of updating src/scripts/nightly/ to use "make check", retire
it.  It hasn't been used in quite a while.  Investing more into our
homegrown auto-builder doesn't make sense, as canned auto-builders
such as Travis CI and Jenkins are readily available.

The shell scripts src/scripts/nightly/tests/?? become Empire batch
files tests/smoke/.  The shell scripts are actually shell boilerplate
around Empire batch files.  To make sure git recognizes the move, this
commit moves them unchanged.  tests/smoke-test strips the boilerplate
before it feeds the batch files to the client.  The next commit will
get rid fo that.
2013-05-08 06:55:11 +02:00

129 lines
3.6 KiB
Perl
Executable file

#!/usr/bin/perl
# TODO Don't hardcode xdump columns, get them from xdump meta
use warnings;
use strict;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
our ($opt_j, $opt_s);
getopts('js')
or die "$0: invalid options\n";
die "$0: either -j or -s, not both\n"
if $opt_j && $opt_s;
my $ctime_re = qr/(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 123][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9] [0-9][0-9][0-9][0-9]/;
my $xdfld_re = qr/\([^)]*\)|[^ (][^ ]*/;
# Current dump, if any
# Either zero or the name of the dump we're currently processing.
# Legacy dump names start with an uppercase letter, and xdump names
# start with a lowercase letter.
my $dump = "";
sub norm_ctime {
my ($s) = @_;
$s =~ s/$ctime_re/Thu Jan 1 00:00:00 1970/g;
return $s;
}
while (<>) {
chomp;
my $pfx = '';
if ($opt_j || $opt_s) {
die "$0: malformed line" unless substr($_, 24, 1) eq ' ';
$pfx .= norm_ctime(substr($_, 0, 25));
$_ = substr($_, 25);
}
if ($opt_j) {
die "$0: malformed line" unless substr($_, 10, 1) eq ' ';
$pfx .= substr($_, 0, 11);
$_ = substr($_, 11);
if (/(^output [^ ]* 1 )(.*)/) {
$pfx .= $1;
$_ = $2;
} else {
$pfx .= $_;
$_ = '';
}
}
if ($opt_s) {
$_ = norm_ctime($_);
### Host environment in logs
# getrusage() results in server.log
s/(End update|done assembling paths) .* user .* system/$1 0.0 user 0.0 system/g;
# PID in server.log
s/(Empire server \(pid) [0-9]+(\) started)/$1 42$2/g;
### Harmless races
# shutdown wins race with logout
next if /Waiting for player threads to terminate/;
print "$pfx$_\n";
next;
}
$dump = ""
if ($dump =~ /^[a-z]/
and /^\//)
or ($dump =~ /^[A-Z]/
and (/\: No (sector|ship|plane|unit|nuke)\(s\)|\: Nothing lost/
or /^[0-9]+ (sector|ship|plane|unit|nuke|lost item)/));
### Formatted time
# nat_timeused in prompt
s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/g;
# TODO command play column time
# result of ctime() in many commands
$_ = norm_ctime($_)
unless $dump;
### Time values in legacy dumps
s/(DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS)) [0-9]+$/$1 0/g;
s/ [0-9]+$/ 0/
if $dump eq 'LOST ITEMS';
### Time values in xdump
s/(XDUMP (meta )?[-a-z0-9]+) [0-9]+$/$1 0/
unless $dump;
# HACK: assume any integer with more than 10 digits is time
# TODO don't do that, use xdump meta instead
s/(^| )[0-9]{10,}/${1}0/g
if $dump =~ /^[a-z]/;
# timeused in xdump country (column 9)
s/^(($xdfld_re ){9})([0-9]+) /${1}255 /
if $dump eq 'country';
# timeused in xdump nat (column 14)
s/^(($xdfld_re ){14})([0-9]+) /${1}255 /
if $dump eq 'nat';
# duration in xdump news (column 4)
s/^(($xdfld_re ){4})([0-9]+) /${1}0 /
if $dump eq 'news';
### nsc_type values in xdump
# Can vary between systems, because the width of enumeration types
# is implementation-defined.
# TODO type in xdump meta
### nrndx values in xdump
# Encoding depends on the host, see resources[]. Too clever by half;
# perhaps we should change it.
# nrndx in xdump product (column 12)
s/^(($xdfld_re ){12})([0-9]+) /${1}0 /
if $dump eq 'product';
# value in xdump resources (column 0)
s/^[0-9]+ /0 /
if $dump eq 'resources';
### Floating-point zero in xdump
# Windows %#g prints it with seven significant digits instead of six
s/ 0\.000000/ 0.00000/g
if $dump =~ /^[a-z]/;
print "$pfx$_\n";
if (/XDUMP (meta )?([-a-z0-9]+)/) {
$dump = $2;
die unless $dump =~ /^[a-z]/;
} elsif (/DUMP (SECTOR|SHIPS|PLANES|LAND UNITS|NUKES|LOST ITEMS) /) {
$dump = $1;
}
}