2005-04-16 17:47:59 +02:00
|
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
use Cwd 'abs_path';
|
|
|
|
|
|
|
|
|
|
my $root_path = $0;
|
|
|
|
|
$root_path =~ s/regression.pl/../;
|
|
|
|
|
$root_path = abs_path($root_path);
|
|
|
|
|
|
2012-05-09 21:32:36 +02:00
|
|
|
|
### Configuration
|
|
|
|
|
# Places where to search for the dictionary
|
|
|
|
|
my @ods_array = (
|
|
|
|
|
"$ENV{HOME}/ods5.dawg",
|
|
|
|
|
"$ENV{HOME}/dev/data/ods5.dawg",
|
|
|
|
|
"$ENV{HOME}/Travail/eliot/data/ods5.dawg"
|
|
|
|
|
);
|
|
|
|
|
# Places where to search for eliottxt executable
|
|
|
|
|
my @eliottxt_array = (
|
|
|
|
|
"$root_path/utils/eliottxt",
|
|
|
|
|
"$root_path/build/utils/eliottxt",
|
|
|
|
|
"$root_path/linux/utils/eliottxt",
|
|
|
|
|
"$root_path/win32/utils/eliottxt.exe"
|
|
|
|
|
);
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
# Change to the test/ directory, because some scenarii expect
|
|
|
|
|
# to find saved games in there
|
|
|
|
|
chdir("$root_path/test");
|
|
|
|
|
|
2005-04-16 17:47:59 +02:00
|
|
|
|
my $driver_file = "driver";
|
2012-05-09 21:32:36 +02:00
|
|
|
|
|
|
|
|
|
|
2012-10-05 20:23:12 +02:00
|
|
|
|
# Temporary directory
|
2012-10-06 01:40:18 +02:00
|
|
|
|
my $tmp_dir = "/tmp/eliot";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
|
|
|
|
|
# File extensions
|
|
|
|
|
my $input_ext = ".input";
|
|
|
|
|
my $ref_ext = ".ref";
|
|
|
|
|
my $run_ext = ".run";
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 21:32:36 +02:00
|
|
|
|
# Look for ods5.dawg
|
|
|
|
|
my $ods = "";
|
|
|
|
|
foreach my $ods_file (@ods_array)
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if (-f $ods_file)
|
|
|
|
|
{
|
|
|
|
|
$ods = $ods_file;
|
|
|
|
|
last;
|
|
|
|
|
}
|
2005-04-16 17:47:59 +02:00
|
|
|
|
}
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if (not -f $ods)
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
2012-05-09 21:32:36 +02:00
|
|
|
|
die "Cannot find dictionary $ods, check files : [".join(", ", @ods_array)."]";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
}
|
2012-05-09 21:32:36 +02:00
|
|
|
|
|
|
|
|
|
# Find eliottxt
|
|
|
|
|
my $eliottxt = "";
|
|
|
|
|
foreach my $eliottxt_file (@eliottxt_array)
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if (-f $eliottxt_file)
|
|
|
|
|
{
|
|
|
|
|
$eliottxt = $eliottxt_file;
|
|
|
|
|
last;
|
|
|
|
|
}
|
2005-04-16 17:47:59 +02:00
|
|
|
|
}
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if (not -x $eliottxt)
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
2012-05-09 21:32:36 +02:00
|
|
|
|
die "Cannot find the text interface executable in [".join(", ", @eliottxt_array)."]";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fill a map of (scenario --> randseed) from the driver file.
|
|
|
|
|
# Also fill the list of scenarios in the order of the driver file.
|
|
|
|
|
my %scenario_map;
|
|
|
|
|
my @all_scenarios;
|
|
|
|
|
open(DRIVER, $driver_file) or die "Cannot open the scenario list: $!";
|
|
|
|
|
while(<DRIVER>)
|
|
|
|
|
{
|
|
|
|
|
chomp;
|
|
|
|
|
my $line = $_;
|
|
|
|
|
$line =~ s/#.*//;
|
2012-10-06 01:40:18 +02:00
|
|
|
|
if ($line =~ /^\s*(\w+\/\w+)\s+(\d+)\s*$/)
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
$scenario_map{$1} = $2;
|
|
|
|
|
push(@all_scenarios, $1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
close(DRIVER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Select the scenarios to play: if there was no argument in the commandline
|
|
|
|
|
# we play all the scenarios, otherwise we play only the specified ones
|
|
|
|
|
my @scenarios_to_play;
|
|
|
|
|
if (@ARGV == 0)
|
|
|
|
|
{
|
|
|
|
|
@scenarios_to_play = @all_scenarios;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
# Remove known file extensions in case they are present
|
|
|
|
|
foreach my $item (@ARGV)
|
|
|
|
|
{
|
|
|
|
|
$item =~ s/$input_ext$|$ref_ext$|$run_ext$//;
|
|
|
|
|
push(@scenarios_to_play, $item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Actually play the selected scenarios
|
|
|
|
|
my @errors;
|
|
|
|
|
foreach my $scenario (@scenarios_to_play)
|
|
|
|
|
{
|
|
|
|
|
print "Scenario: $scenario\n";
|
|
|
|
|
my $input_file = $scenario . $input_ext;
|
|
|
|
|
my $ref_file = $scenario . $ref_ext;
|
|
|
|
|
my $run_file = $scenario . $run_ext;
|
2012-05-09 21:32:36 +02:00
|
|
|
|
my $randseed = $scenario_map{$scenario};
|
2005-04-16 17:47:59 +02:00
|
|
|
|
|
|
|
|
|
# Check that the needed files exist
|
|
|
|
|
if (not -f $input_file)
|
|
|
|
|
{
|
2012-10-05 17:55:41 +02:00
|
|
|
|
print "--> Error: missing file: $input_file\n";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
push(@errors, $scenario);
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
if (not -f $ref_file)
|
|
|
|
|
{
|
2012-10-05 17:55:41 +02:00
|
|
|
|
print "--> Error: missing file: $ref_file\n";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
push(@errors, $scenario);
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# OK, let's do the actual stuff
|
|
|
|
|
unlink $run_file;
|
|
|
|
|
my $rc = `$eliottxt $ods $randseed < $input_file > $run_file 2>&1`;
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if ($rc ne "")
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
2012-10-05 17:55:41 +02:00
|
|
|
|
print "--> Error: execution of scenario failed (return value: $rc)\n";
|
2005-04-16 17:47:59 +02:00
|
|
|
|
push(@errors, $scenario);
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 20:23:12 +02:00
|
|
|
|
# Create temporary copies of the files, without comments
|
2012-10-06 01:40:18 +02:00
|
|
|
|
my $tmp_ref_file = "$tmp_dir/$ref_file";
|
|
|
|
|
my $tmp_run_file = "$tmp_dir/$run_file";
|
|
|
|
|
system("mkdir -p `dirname $tmp_ref_file`");
|
2012-10-05 20:23:12 +02:00
|
|
|
|
system("cat $ref_file | egrep -v '^#' | egrep -v '^\\w+> #' > $tmp_ref_file");
|
|
|
|
|
system("cat $run_file | egrep -v '^#' | egrep -v '^\\w+> #' > $tmp_run_file");
|
|
|
|
|
|
2005-04-16 17:47:59 +02:00
|
|
|
|
# Is the output file different from the reference file?
|
2012-10-05 20:23:12 +02:00
|
|
|
|
my $diff = `diff $tmp_ref_file $tmp_run_file`;
|
2012-05-09 21:32:36 +02:00
|
|
|
|
if ($diff ne "")
|
2005-04-16 17:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
print "--> Error: found differences:\n";
|
|
|
|
|
print $diff;
|
|
|
|
|
push(@errors, $scenario);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Display the results
|
|
|
|
|
print "\nSummary: ";
|
|
|
|
|
if (@errors == 0)
|
|
|
|
|
{
|
|
|
|
|
print "Everything was OK.\n";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
my $errorsCount = @errors;
|
|
|
|
|
print "$errorsCount error(s). The following scenario(s) have failed:\n";
|
|
|
|
|
print "@errors\n"
|
|
|
|
|
}
|