run_tests.pl
90 lines
| 2.3 KiB
| text/plain
|
PerlLexer
/ tools / run_tests.pl
|
r1134 | use Cwd; | ||
use Cwd 'abs_path'; | ||||
use File::Basename; | ||||
use File::Copy; | ||||
|
r1151 | use feature "switch"; | ||
|
r1203 | use lib 'tools'; | ||
|
r1134 | use Jobs; | ||
# read command line params | ||||
my $jobname = shift; | ||||
# read ini file | ||||
my $inifile = File::Basename::dirname($0) . "/jobs.ini"; | ||||
my %job = Jobs::get($inifile, $jobname); | ||||
|
r1136 | # set/get paths | ||
|
r1135 | my $root_path = abs_path(); | ||
|
r1137 | my $bin_path = "$root_path/bin/"; | ||
|
r1136 | my $reports_path = "test-reports"; | ||
# create reports path | ||||
|
r1137 | mkdir $reports_path; | ||
|
r1135 | |||
|
r1151 | # setup environment for running tests | ||
given ($job{'Platform'}) { | ||||
when ("Win7") { | ||||
|
r1152 | # Add qtdir to path | ||
$ENV{'PATH'} .= ";" . $job{'QtDir'} . "\\bin"; | ||||
# replace / -> \ | ||||
$ENV{'PATH'} =~ s/\//\\/g; | ||||
|
r1151 | } | ||
|
r1134 | |||
|
r1151 | when ("Linux") { | ||
|
r1152 | # Add qtdir to path | ||
|
r1151 | $ENV{'PATH'} = $job{'QtDir'} . "/bin:" . $ENV{'PATH'}; | ||
|
r1152 | |||
# If this is not set we get "cannot connect to X server" errors | ||||
|
r1151 | $ENV{'DISPLAY'} = ":0.0"; | ||
} | ||||
} | ||||
|
r1136 | |||
|
r1134 | # Go through all the files in the test folder | ||
|
r1136 | # autotest is an executable beginning with "tst_" | ||
|
r1151 | my $script_exit_status = 0; | ||
|
r1137 | opendir (TESTAPPDIR, "$bin_path") or die "Couldn't open test app dir"; | ||
|
r1134 | @files = <TESTAPPDIR>; | ||
while ($testapp = readdir TESTAPPDIR) { | ||||
if (index($testapp, "tst_") == 0) { | ||||
|
r1137 | if (-x "$bin_path$testapp") { | ||
|
r1136 | my $status = executeTestApp($testapp); | ||
if ($status != 0) { | ||||
$script_exit_status = $status; | ||||
} | ||||
|
r1134 | } else { | ||
#print "file $testapp not executable\n"; | ||||
} | ||||
} | ||||
} | ||||
closedir TESTAPPDIR; | ||||
|
r1137 | print "\n*** script exit status : $script_exit_status ***\n\n"; | ||
|
r1136 | exit($script_exit_status); | ||
|
r1134 | |||
|
r1151 | |||
|
r1136 | sub executeTestApp($) { | ||
my $testapp = $_[0]; | ||||
# On OSX the actual test binary is in a sub folder | ||||
my $cmd_postfix = ""; | ||||
if ($^O eq "darwin") { | ||||
$cmd_postfix = "/Contents/MacOS/$testapp"; | ||||
$cmd_postfix = substr($cmd_postfix, 0, rindex($cmd_postfix, ".app")); | ||||
} | ||||
|
r1137 | my $cmd = "$bin_path$testapp$cmd_postfix -xunitxml -o $reports_path/$testapp.xml"; | ||
|
r1136 | print "executing: $cmd\n"; | ||
|
r1137 | system($cmd); | ||
# From http://perldoc.perl.org/perlvar.html about $?: | ||||
# The upper eight bits reflect specific error conditions encountered by the | ||||
# program (the program's exit() value). The lower eight bits reflect | ||||
# mode of failure, like signal death and core dump information. | ||||
# See wait(2) for details. | ||||
|
r1134 | my $exit_status = $? >> 8; | ||
|
r1137 | print "\texit status: $exit_status\n"; | ||
|
r1136 | |||
return $exit_status; | ||||
|
r1134 | } | ||