2016-01-18 09:32:32 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use threads;
|
2016-01-18 19:20:57 +00:00
|
|
|
use threads::shared;
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-24 17:53:46 +00:00
|
|
|
use Cwd;
|
2016-01-18 09:32:32 +00:00
|
|
|
use Getopt::Long;
|
2016-01-20 18:37:45 +00:00
|
|
|
use File::Basename;
|
2016-01-18 09:32:32 +00:00
|
|
|
use File::Find;
|
2016-01-18 17:18:39 +00:00
|
|
|
use File::Spec;
|
2016-01-19 21:58:29 +00:00
|
|
|
use File::Copy::Recursive qw(fcopy rcopy dircopy);
|
|
|
|
use Tie::File;
|
2016-01-18 17:18:39 +00:00
|
|
|
use Cwd;
|
|
|
|
use Cwd 'abs_path';
|
2016-01-18 17:54:43 +00:00
|
|
|
use Term::ANSIColor;
|
2016-01-20 18:37:45 +00:00
|
|
|
use Data::Dumper;
|
2016-01-18 09:32:32 +00:00
|
|
|
|
|
|
|
sub help {
|
2016-01-18 20:41:16 +00:00
|
|
|
my $msg = << 'EOS';
|
|
|
|
|
|
|
|
The script run_test.pl is a test runner that work in conjunction with ps2autotests (https://github.com/unknownbrackets/ps2autotests)
|
|
|
|
|
|
|
|
Mandatory Option
|
2016-01-20 19:31:55 +00:00
|
|
|
--exe <STRING> : the PCSX2 binary that you want to test
|
|
|
|
--cfg <STRING> : a path to the a default ini configuration of PCSX2
|
|
|
|
--suite <STRING> : a path to ps2autotests test (root directory)
|
2016-01-18 20:41:16 +00:00
|
|
|
|
|
|
|
Optional Option
|
2016-01-20 19:31:55 +00:00
|
|
|
--cpu=1 : the number of parallel tests launched. Might create additional issue
|
|
|
|
--timeout=20 : a global timeout for hang tests
|
|
|
|
--show_diff : show debug information
|
2016-01-18 20:41:16 +00:00
|
|
|
|
2016-01-20 19:31:55 +00:00
|
|
|
--test=<REGEXP> : filter test based on their names
|
2016-01-24 19:11:25 +00:00
|
|
|
--bad : only run blacklisted tests
|
2016-01-20 19:31:55 +00:00
|
|
|
--regression : blacklist test that are known to be broken
|
2016-01-24 19:11:25 +00:00
|
|
|
|
2016-01-20 19:31:55 +00:00
|
|
|
--option <KEY>=<VAL> : overload PCSX2 configuration option
|
2016-01-18 22:53:28 +00:00
|
|
|
|
2016-01-20 19:31:55 +00:00
|
|
|
--debug_me : print script info
|
|
|
|
--dry_run : don't launch PCSX2
|
|
|
|
|
|
|
|
PCSX2 option
|
|
|
|
EnableEE=disabled : Use EE interpreter
|
|
|
|
EnableIOP=disabled : Use IOP interpreter
|
|
|
|
EnableVU0=disabled : Use VU0 interpreter
|
|
|
|
EnableVU1=disabled : Use VU1 interpreter
|
|
|
|
FPU.Roundmode=3 : EE FPU round mode
|
|
|
|
VU.Roundmode=3 : VU round mode
|
2016-01-20 18:37:45 +00:00
|
|
|
|
2016-01-18 20:41:16 +00:00
|
|
|
EOS
|
|
|
|
print $msg;
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:20:57 +00:00
|
|
|
my $mt_timeout :shared;
|
2016-01-24 19:11:25 +00:00
|
|
|
my ($o_suite, $o_help, $o_exe, $o_cfg, $o_max_cpu, $o_timeout, $o_show_diff, $o_debug_me, $o_test_name, $o_regression, $o_dry_run, %o_pcsx2_opt, $o_cygwin, $o_bad);
|
2016-01-18 19:20:57 +00:00
|
|
|
|
2016-01-20 06:56:32 +00:00
|
|
|
# default value
|
2016-01-24 19:11:25 +00:00
|
|
|
$o_bad = 0;
|
|
|
|
$o_regression = 0;
|
2016-01-23 17:35:34 +00:00
|
|
|
$o_cygwin = 0;
|
2016-01-18 17:18:39 +00:00
|
|
|
$o_max_cpu = 1;
|
2016-01-24 21:32:00 +00:00
|
|
|
$o_timeout = 30;
|
2016-01-18 20:41:16 +00:00
|
|
|
$o_help = 0;
|
|
|
|
$o_debug_me = 0;
|
2016-01-20 18:37:45 +00:00
|
|
|
$o_dry_run = 0;
|
2016-01-18 22:53:28 +00:00
|
|
|
$o_test_name = ".*";
|
2016-01-20 06:56:32 +00:00
|
|
|
$o_exe = File::Spec->catfile("bin", "PCSX2");
|
|
|
|
if (exists $ENV{"PS2_AUTOTESTS_ROOT"}) {
|
|
|
|
$o_suite = $ENV{"PS2_AUTOTESTS_ROOT"};
|
|
|
|
}
|
|
|
|
if (exists $ENV{"PS2_AUTOTESTS_CFG"}) {
|
|
|
|
$o_cfg = $ENV{"PS2_AUTOTESTS_CFG"};
|
|
|
|
}
|
2016-01-18 19:20:57 +00:00
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
my $status = Getopt::Long::GetOptions(
|
2016-01-24 19:11:25 +00:00
|
|
|
'bad' => \$o_bad,
|
2016-01-18 19:20:57 +00:00
|
|
|
'cfg=s' => \$o_cfg,
|
|
|
|
'cpu=i' => \$o_max_cpu,
|
2016-01-23 17:42:17 +00:00
|
|
|
'cygwin' => \$o_cygwin,
|
2016-01-18 20:41:16 +00:00
|
|
|
'debug_me' => \$o_debug_me,
|
2016-01-20 18:37:45 +00:00
|
|
|
'dry_run' => \$o_dry_run,
|
2016-01-18 19:20:57 +00:00
|
|
|
'exe=s' => \$o_exe,
|
|
|
|
'help' => \$o_help,
|
2016-01-20 19:31:55 +00:00
|
|
|
'option=s' => \%o_pcsx2_opt,
|
2016-01-20 18:37:45 +00:00
|
|
|
'regression' => \$o_regression,
|
2016-01-18 22:53:28 +00:00
|
|
|
'testname=s' => \$o_test_name,
|
2016-01-18 19:20:57 +00:00
|
|
|
'timeout=i' => \$o_timeout,
|
2016-01-18 19:26:36 +00:00
|
|
|
'show_diff' => \$o_show_diff,
|
2016-01-18 19:20:57 +00:00
|
|
|
'suite=s' => \$o_suite,
|
2016-01-18 09:32:32 +00:00
|
|
|
);
|
|
|
|
|
2016-01-24 17:18:13 +00:00
|
|
|
# Auto detect cygwin mess
|
2016-01-24 17:28:38 +00:00
|
|
|
if (-e "/cygdrive") {
|
2016-01-24 18:24:37 +00:00
|
|
|
print "INFO: CYGWIN OS detected. Update path accordingly\n";
|
2016-01-24 17:18:13 +00:00
|
|
|
$o_cygwin = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:20:57 +00:00
|
|
|
#####################################################
|
|
|
|
# Check option
|
|
|
|
#####################################################
|
2016-01-18 20:41:16 +00:00
|
|
|
if (not $status or $o_help) {
|
2016-01-18 09:32:32 +00:00
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (defined $o_suite) {
|
|
|
|
print "Error: require a test suite directory\n";
|
2016-01-20 06:56:32 +00:00
|
|
|
print "Note: you could use either use --suite or the env variable \$PS2_AUTOTESTS_ROOT\n";
|
2016-01-18 09:32:32 +00:00
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
2016-01-18 17:18:39 +00:00
|
|
|
unless (defined $o_cfg) {
|
2016-01-18 20:41:16 +00:00
|
|
|
print "Error: require a default cfg directory\n";
|
2016-01-20 06:56:32 +00:00
|
|
|
print "Note: you could use either use --cfg or the env variable \$PS2_AUTOTESTS_CFG\n";
|
2016-01-18 17:18:39 +00:00
|
|
|
help();
|
|
|
|
}
|
2016-01-18 19:20:57 +00:00
|
|
|
|
2016-01-18 20:41:16 +00:00
|
|
|
$o_exe = abs_path($o_exe);
|
2016-01-18 17:18:39 +00:00
|
|
|
$o_cfg = abs_path($o_cfg);
|
2016-01-19 21:58:29 +00:00
|
|
|
$o_suite = abs_path($o_suite);
|
2016-01-18 19:20:57 +00:00
|
|
|
$mt_timeout = $o_timeout;
|
|
|
|
|
2016-01-20 06:56:32 +00:00
|
|
|
unless (-d $o_suite) {
|
|
|
|
print "Error: --suite option requires a directory\n";
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (-x $o_exe) {
|
|
|
|
print "Error: --exe option requires an executable\n";
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (-d $o_cfg) {
|
|
|
|
print "Error: --cfg option requires a directory\n";
|
|
|
|
help();
|
|
|
|
}
|
2016-01-18 17:18:39 +00:00
|
|
|
|
2016-01-20 18:37:45 +00:00
|
|
|
my %blacklist;
|
2016-01-24 19:11:25 +00:00
|
|
|
if ($o_regression or $o_bad) {
|
2016-01-20 18:37:45 +00:00
|
|
|
# Blacklist bad test
|
2016-01-27 19:38:57 +00:00
|
|
|
|
|
|
|
# FULL FPU rounding to avoid EE FPU test issu
|
|
|
|
#$o_pcsx2_opt{"fpuExtraOverflow"} = "enabled";
|
|
|
|
#$o_pcsx2_opt{"fpuFullMode"} = "enabled";
|
|
|
|
|
2016-01-20 18:37:45 +00:00
|
|
|
$blacklist{"branchdelay"} = 1;
|
|
|
|
$blacklist{"arithmetic"} = 1;
|
|
|
|
$blacklist{"compare"} = 1;
|
|
|
|
$blacklist{"fcr"} = 1;
|
|
|
|
$blacklist{"muldiv"} = 1;
|
|
|
|
$blacklist{"sqrt"} = 1;
|
|
|
|
$blacklist{"normal"} = 1;
|
|
|
|
$blacklist{"mode"} = 1;
|
|
|
|
$blacklist{"stcycl"} = 1;
|
|
|
|
$blacklist{"triace"} = 1;
|
2016-01-24 19:11:25 +00:00
|
|
|
# IRX
|
2016-01-27 19:38:57 +00:00
|
|
|
$blacklist{"lsudelay"} = 1;
|
2016-01-24 19:11:25 +00:00
|
|
|
$blacklist{"register"} = 1;
|
2016-01-27 19:38:57 +00:00
|
|
|
$blacklist{"receive"} = 1;
|
2016-01-24 19:11:25 +00:00
|
|
|
$blacklist{"stat"} = 1;
|
2016-01-27 19:38:57 +00:00
|
|
|
$blacklist{"send"} = 1;
|
2016-01-20 18:37:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 19:20:57 +00:00
|
|
|
#####################################################
|
|
|
|
# Run
|
|
|
|
#####################################################
|
2016-01-18 09:32:32 +00:00
|
|
|
|
|
|
|
# Round 1: Collect the tests
|
2016-01-24 17:53:46 +00:00
|
|
|
my $cwd = getcwd();
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
my $g_test_db;
|
2016-01-18 17:54:43 +00:00
|
|
|
print "INFO: search tests in $o_suite and run them in $o_max_cpu CPU)\n";
|
2016-01-18 17:18:39 +00:00
|
|
|
find({ wanted => \&add_test_cmd_for_elf, no_chdir => 1 }, $o_suite);
|
2016-01-18 20:41:16 +00:00
|
|
|
print "\n";
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-24 17:53:46 +00:00
|
|
|
chdir($cwd); # Just to be sure
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
# Round 2: Run the tests (later in thread)
|
2016-01-18 17:54:43 +00:00
|
|
|
foreach my $test (keys(%$g_test_db)) {
|
2016-01-18 17:18:39 +00:00
|
|
|
# wait free CPU slot
|
|
|
|
while( scalar(threads->list() >= $o_max_cpu) ) {
|
|
|
|
if (close_joinnable_threads() == 0) {
|
2016-01-18 17:54:43 +00:00
|
|
|
sleep(1); # test are often fast so 1s is more than enough
|
2016-01-18 19:20:57 +00:00
|
|
|
$mt_timeout--;
|
2016-01-18 17:18:39 +00:00
|
|
|
}
|
2016-01-18 19:20:57 +00:00
|
|
|
kill_thread_if_timeout()
|
2016-01-18 17:18:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 17:54:43 +00:00
|
|
|
create_thread($test);
|
2016-01-18 09:32:32 +00:00
|
|
|
}
|
2016-01-18 17:18:39 +00:00
|
|
|
wait_all_threads();
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-18 17:54:43 +00:00
|
|
|
# Round 3: Collect the results (not thread safe)
|
|
|
|
collect_result();
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-18 17:54:43 +00:00
|
|
|
# Pretty print
|
2016-01-18 20:41:16 +00:00
|
|
|
print "\n\n Status | =========================== Test ================================\n";
|
2016-01-18 17:54:43 +00:00
|
|
|
foreach my $test (sort(keys(%$g_test_db))) {
|
|
|
|
my $info = $g_test_db->{$test};
|
2016-01-18 20:41:16 +00:00
|
|
|
my $cfg = $info->{"CFG_DIR"};
|
2016-01-18 19:26:36 +00:00
|
|
|
my $out = $info->{"OUT"};
|
|
|
|
my $exp = $info->{"EXPECTED"};
|
|
|
|
|
2016-01-19 21:58:29 +00:00
|
|
|
if ($info->{"STATUS"} eq "OK") {
|
2016-01-18 17:54:43 +00:00
|
|
|
print color('bold green');
|
|
|
|
print " OK | $test\n";
|
2016-01-18 19:20:57 +00:00
|
|
|
} else {
|
2016-01-19 21:58:29 +00:00
|
|
|
if ($info->{"STATUS"} eq "T") {
|
2016-01-18 22:40:04 +00:00
|
|
|
print color('bold blue');
|
|
|
|
print " Tout | $test\n";
|
|
|
|
} else {
|
|
|
|
print color('bold red');
|
|
|
|
print " KO | $test\n";
|
|
|
|
}
|
2016-01-18 19:26:36 +00:00
|
|
|
if ($o_show_diff) {
|
|
|
|
print color('bold magenta'); print "-----------------------------------------------------------------------\n"; print color('reset');
|
2016-01-26 06:58:06 +00:00
|
|
|
print test_cmd($test, $cfg) . "\n";
|
|
|
|
print "vi -d $exp $out\n";
|
|
|
|
print "\n";
|
2016-01-19 21:58:29 +00:00
|
|
|
diff($exp, $out, 0);
|
2016-01-18 19:26:36 +00:00
|
|
|
print color('bold magenta'); print "-----------------------------------------------------------------------\n"; print color('reset');
|
|
|
|
}
|
2016-01-18 17:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
print color('reset');
|
|
|
|
print "\n";
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-18 17:54:43 +00:00
|
|
|
#####################################################
|
2016-01-18 19:20:57 +00:00
|
|
|
# Sub helper
|
|
|
|
#####################################################
|
2016-01-24 14:21:47 +00:00
|
|
|
sub cyg_abs_path {
|
|
|
|
my $p = shift;
|
|
|
|
if ($o_cygwin) {
|
2016-01-24 18:24:37 +00:00
|
|
|
$p =~ s/\/cygdrive\/(\w)/$1:/;
|
2016-01-24 14:21:47 +00:00
|
|
|
}
|
2016-01-24 18:24:37 +00:00
|
|
|
return $p;
|
2016-01-24 14:21:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
sub collect_result {
|
2016-01-18 17:54:43 +00:00
|
|
|
foreach my $test (keys(%$g_test_db)) {
|
|
|
|
my $info = $g_test_db->{$test};
|
2016-01-26 06:58:06 +00:00
|
|
|
my $cfg = $info->{"CFG_DIR"};
|
2016-01-18 17:54:43 +00:00
|
|
|
my $out = $info->{"OUT"};
|
|
|
|
my $exp = $info->{"EXPECTED"};
|
|
|
|
|
2016-01-26 06:58:06 +00:00
|
|
|
extract_test_log(File::Spec->catfile($cfg, "emuLog.txt"), $out);
|
2016-01-19 21:58:29 +00:00
|
|
|
$info->{"STATUS"} = diff($exp, $out, 1); # potentially not thread safe
|
2016-01-18 17:54:43 +00:00
|
|
|
}
|
2016-01-18 09:32:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 06:58:06 +00:00
|
|
|
sub extract_test_log {
|
|
|
|
my $in = shift;
|
|
|
|
my $out = shift;
|
|
|
|
|
|
|
|
return unless (-e $in);
|
|
|
|
|
|
|
|
open(my $emulog, "<$in");
|
|
|
|
my @all_data = <$emulog>;
|
|
|
|
|
|
|
|
open(my $short_log, ">$out") or die "Impossible to open $!";
|
|
|
|
|
|
|
|
my $dump = 0;
|
|
|
|
foreach my $line (@all_data) {
|
|
|
|
# Remove color
|
|
|
|
$line =~ s/\e\[\d+(?>(;\d+)*)m//g;
|
|
|
|
|
|
|
|
if ($line =~ /-- TEST BEGIN/) {
|
|
|
|
$dump = 1;
|
|
|
|
}
|
|
|
|
if ($dump == 1) {
|
|
|
|
chomp($line);
|
|
|
|
$line =~ s/\r$//g;
|
|
|
|
|
|
|
|
print $short_log "$line\n";
|
|
|
|
}
|
|
|
|
if ($line =~ /-- TEST END/) {
|
|
|
|
$dump = 0;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
sub add_test_cmd_for_elf {
|
|
|
|
my $file = $_;
|
2016-01-23 12:45:12 +00:00
|
|
|
my $ext = "\\.(elf|irx)";
|
2016-01-23 12:37:39 +00:00
|
|
|
|
|
|
|
return 0 unless ($file =~ /$ext/);
|
2016-01-18 22:53:28 +00:00
|
|
|
return 0 unless ($file =~ /$o_test_name/i);
|
2016-01-20 18:37:45 +00:00
|
|
|
|
2016-01-23 12:37:39 +00:00
|
|
|
my($test, $dir_, $suffix) = fileparse($file, qw/.elf .irx/);
|
2016-01-24 19:11:25 +00:00
|
|
|
return 0 if ($o_regression and exists $blacklist{$test});
|
|
|
|
return 0 if ($o_bad and not exists $blacklist{$test});
|
2016-01-18 17:18:39 +00:00
|
|
|
# Fast test
|
|
|
|
#return 0 unless ($file =~ /branchdelay/);
|
2016-01-18 09:32:32 +00:00
|
|
|
|
|
|
|
my $dir = $File::Find::dir;
|
2016-01-20 18:37:45 +00:00
|
|
|
print "INFO: found test $test in $dir\n" if $o_debug_me or $o_dry_run;
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-24 18:24:37 +00:00
|
|
|
$g_test_db->{$file}->{"CFG_DIR"} = $file =~ s/$ext/_cfg/r;
|
|
|
|
$g_test_db->{$file}->{"EXPECTED"} = $file =~ s/$ext/.expected/r;
|
|
|
|
$g_test_db->{$file}->{"OUT"} = $file =~ s/$ext/.PCSX2.out/r;
|
|
|
|
$g_test_db->{$file}->{"STATUS"} = "T";
|
2016-01-18 09:32:32 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-18 17:18:39 +00:00
|
|
|
sub run_thread {
|
|
|
|
my $test = shift;
|
|
|
|
my $info = $g_test_db->{$test};
|
|
|
|
|
|
|
|
generate_cfg($info->{"CFG_DIR"});
|
|
|
|
|
|
|
|
run_elf($test, $info->{"CFG_DIR"}, $info->{"OUT"});
|
|
|
|
}
|
|
|
|
|
|
|
|
sub generate_cfg {
|
|
|
|
my $out_dir = shift;
|
|
|
|
|
2016-01-24 18:24:37 +00:00
|
|
|
print "INFO: Copy dir $o_cfg to $out_dir\n" if $o_debug_me;
|
2016-01-19 21:58:29 +00:00
|
|
|
local $File::Copy::Recursive::RMTrgDir = 2;
|
2016-01-24 14:21:47 +00:00
|
|
|
dircopy($o_cfg, $out_dir) or die "Failed to copy directory: $!\n";
|
2016-01-18 17:18:39 +00:00
|
|
|
|
|
|
|
my %sed;
|
|
|
|
# Enable logging for test
|
2016-01-26 06:58:06 +00:00
|
|
|
$sed{".EEout"} = "enabled";
|
2016-01-18 17:18:39 +00:00
|
|
|
$sed{".IOPout"} = "enabled";
|
2016-01-26 06:58:06 +00:00
|
|
|
# Redirect log file in the unique cfg dir
|
|
|
|
#$sed{"ConsoleToStdio"} = "enabled"; # was to redirect stdio (but windows...) # Still requires to force the flush
|
|
|
|
$sed{"Logs"} = cyg_abs_path($out_dir);
|
|
|
|
$sed{"UseDefaultLogs"} = "disabled";
|
|
|
|
|
2016-01-18 17:18:39 +00:00
|
|
|
# FIXME add interpreter vs recompiler
|
|
|
|
# FIXME add clamping / rounding option
|
|
|
|
# FIXME need separate cfg dir !
|
2016-01-20 19:31:55 +00:00
|
|
|
foreach my $k (keys(%o_pcsx2_opt)) {
|
|
|
|
my $v = $o_pcsx2_opt{$k};
|
|
|
|
$sed{$k} = $v;
|
|
|
|
}
|
2016-01-18 17:18:39 +00:00
|
|
|
|
2016-01-19 21:58:29 +00:00
|
|
|
tie my @ui, 'Tie::File', File::Spec->catfile($out_dir, "PCSX2_ui.ini") or die "Fail to tie PCSX2_ui.ini $!\n";
|
|
|
|
tie my @vm, 'Tie::File', File::Spec->catfile($out_dir, "PCSX2_vm.ini") or die "Fail to tie PCSX2_vm.ini $!\n";
|
|
|
|
|
|
|
|
for (@ui) {
|
|
|
|
foreach my $option (keys(%sed)) {
|
|
|
|
my $v = $sed{$option};
|
|
|
|
s/$option=.*/$option=$v/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (@vm) {
|
|
|
|
foreach my $option (keys(%sed)) {
|
|
|
|
my $v = $sed{$option};
|
|
|
|
s/$option=.*/$option=$v/;
|
|
|
|
}
|
2016-01-18 17:18:39 +00:00
|
|
|
}
|
2016-01-19 21:58:29 +00:00
|
|
|
|
|
|
|
untie @ui;
|
|
|
|
untie @vm;
|
2016-01-18 17:18:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:32:32 +00:00
|
|
|
sub run_elf {
|
|
|
|
my $elf = shift;
|
|
|
|
my $cfg = shift;
|
|
|
|
my $out = shift;
|
|
|
|
|
2016-01-26 06:58:06 +00:00
|
|
|
######################################################################
|
|
|
|
# FORK test
|
|
|
|
######################################################################
|
2016-01-18 20:41:16 +00:00
|
|
|
my $command = test_cmd($elf, $cfg);
|
2016-01-26 06:58:06 +00:00
|
|
|
print "FORK $command\n" if $o_debug_me;
|
2016-01-24 18:24:37 +00:00
|
|
|
return unless ($command ne "");
|
|
|
|
|
2016-01-26 06:58:06 +00:00
|
|
|
my $pid = 0;
|
|
|
|
my $log_file = File::Spec->catfile($cfg, "emuLog.txt");
|
|
|
|
|
|
|
|
if ($o_dry_run) {
|
|
|
|
print "INFO-DRY: fork process $pid\n";
|
|
|
|
# Delete old log
|
|
|
|
unlink($out) or die "Impossible to open $!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$pid = open(my $fork, "|$command ") or die "Impossible to fork $!";
|
|
|
|
print "INFO: fork process $pid\n";
|
2016-01-18 09:32:32 +00:00
|
|
|
|
2016-01-18 19:20:57 +00:00
|
|
|
# Kill me
|
|
|
|
$SIG{'KILL'} = sub {
|
|
|
|
print "ERROR: timeout detected on pid $pid.\n";
|
2016-01-26 06:58:06 +00:00
|
|
|
unless ($o_dry_run) {
|
|
|
|
kill 'KILL', $pid;
|
|
|
|
}
|
2016-01-18 19:20:57 +00:00
|
|
|
threads->exit();
|
|
|
|
};
|
|
|
|
|
2016-01-26 06:58:06 +00:00
|
|
|
######################################################################
|
|
|
|
# Parse test log
|
|
|
|
######################################################################
|
|
|
|
my $try = ($o_timeout > 3) ? $o_timeout - 3 : 1;
|
|
|
|
while ($try > 0) {
|
|
|
|
sleep(1);
|
|
|
|
$try--;
|
|
|
|
|
|
|
|
open(my $emulog, "<$log_file") or next;
|
|
|
|
my @all_data = <$emulog>;
|
|
|
|
close($emulog);
|
|
|
|
|
|
|
|
foreach my $line (@all_data) {
|
|
|
|
if ($line =~ /-- TEST END/) {
|
|
|
|
$try = 0;
|
|
|
|
}
|
2016-01-18 09:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-26 06:58:06 +00:00
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Test done
|
|
|
|
######################################################################
|
|
|
|
# Kill the process
|
|
|
|
print "INFO: kill process $pid\n" if $o_debug_me;
|
|
|
|
kill 'TERM', $pid;
|
|
|
|
|
|
|
|
threads->exit();
|
2016-01-18 09:32:32 +00:00
|
|
|
}
|
2016-01-18 17:18:39 +00:00
|
|
|
|
2016-01-18 20:41:16 +00:00
|
|
|
sub test_cmd {
|
|
|
|
my $elf = shift;
|
|
|
|
my $cfg = shift;
|
2016-01-23 17:35:34 +00:00
|
|
|
|
2016-01-24 14:21:47 +00:00
|
|
|
$elf = cyg_abs_path($elf);
|
|
|
|
$cfg = cyg_abs_path($cfg);
|
2016-01-23 17:35:34 +00:00
|
|
|
|
2016-01-23 12:37:39 +00:00
|
|
|
if ($elf =~ /\.elf/) {
|
|
|
|
return "$o_exe --elf $elf --cfgpath=$cfg"
|
2016-01-24 18:24:37 +00:00
|
|
|
} elsif ($elf =~ /\.irx/) {
|
2016-01-23 12:37:39 +00:00
|
|
|
return "$o_exe --irx $elf --cfgpath=$cfg"
|
2016-01-24 18:24:37 +00:00
|
|
|
} else {
|
|
|
|
print "ERROR: bad command parameters $elf $cfg\n";
|
|
|
|
return "";
|
2016-01-23 12:37:39 +00:00
|
|
|
}
|
2016-01-18 20:41:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:58:29 +00:00
|
|
|
sub diff {
|
|
|
|
my $ref_ = shift;
|
|
|
|
my $out_ = shift;
|
|
|
|
my $quiet = shift;
|
|
|
|
|
|
|
|
open (my $ref_h, "<$ref_");
|
|
|
|
my @ref = <$ref_h>;
|
2016-01-26 06:58:06 +00:00
|
|
|
chomp(@ref);
|
2016-01-19 21:58:29 +00:00
|
|
|
|
2016-01-20 18:37:45 +00:00
|
|
|
open (my $out_h, "<$out_") or return "T";
|
2016-01-19 21:58:29 +00:00
|
|
|
my @out = <$out_h>;
|
2016-01-26 06:58:06 +00:00
|
|
|
chomp(@out);
|
2016-01-19 21:58:29 +00:00
|
|
|
|
|
|
|
return "T" if (scalar(@out) < 2);
|
|
|
|
return "T" if ($out[-1] !~ /-- TEST END/);
|
2016-01-20 06:56:32 +00:00
|
|
|
return "KO" if ((scalar(@out) != scalar(@ref)) and $quiet);
|
2016-01-19 21:58:29 +00:00
|
|
|
|
|
|
|
my $status = "OK";
|
2016-01-26 06:58:06 +00:00
|
|
|
my $show = 10;
|
2016-01-19 21:58:29 +00:00
|
|
|
for (my $l = 0; $l < scalar(@ref); $l++) {
|
2016-01-26 17:15:47 +00:00
|
|
|
$ref[$l] =~ s/\r//g;
|
|
|
|
$out[$l] =~ s/\r//g;
|
2016-01-26 06:58:06 +00:00
|
|
|
|
|
|
|
if ($ref[$l] ne $out[$l]) {
|
2016-01-19 21:58:29 +00:00
|
|
|
$status = "KO";
|
2016-01-26 06:58:06 +00:00
|
|
|
if ($o_show_diff and not $quiet and $show > 0) {
|
|
|
|
print "EXPECTED: \"$ref[$l]\"\n";
|
|
|
|
print "BUT GOT : \"$out[$l]\"\n";
|
|
|
|
$show--;
|
2016-01-19 21:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
2016-01-18 17:18:39 +00:00
|
|
|
#####################################################
|
|
|
|
# Thread management
|
|
|
|
#####################################################
|
|
|
|
my $g_counter = 0;
|
|
|
|
sub create_thread {
|
|
|
|
my $cmd = shift;
|
|
|
|
|
|
|
|
my $thr = threads->create(\&run_thread, $cmd );
|
|
|
|
|
|
|
|
$g_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub close_joinnable_threads {
|
|
|
|
my $closed = 0;
|
|
|
|
foreach my $thr (threads->list(threads::joinable)) {
|
|
|
|
$thr->join();
|
|
|
|
$closed = 1;
|
|
|
|
$g_counter--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub wait_all_threads {
|
2016-01-18 19:20:57 +00:00
|
|
|
# wait free CPU slot
|
|
|
|
while( scalar(threads->list() > 0) and $mt_timeout > 0) {
|
|
|
|
if (close_joinnable_threads() == 0) {
|
|
|
|
sleep(1); # test are often fast so 1s is more than enough
|
|
|
|
$mt_timeout--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kill_thread_if_timeout()
|
|
|
|
}
|
|
|
|
|
|
|
|
sub kill_thread_if_timeout {
|
|
|
|
if ($mt_timeout <= 0) {
|
|
|
|
foreach my $thr (threads->list()) {
|
|
|
|
# Farewell my friend
|
|
|
|
print "ERROR: send kill on timeout process\n";
|
2016-01-24 21:32:00 +00:00
|
|
|
$thr->kill('KILL')->join();
|
2016-01-18 19:20:57 +00:00
|
|
|
}
|
|
|
|
$mt_timeout = 100;
|
2016-01-18 17:18:39 +00:00
|
|
|
}
|
|
|
|
}
|