From c7e20df7328613012be741d504cd31abba7038e1 2012-05-08 12:46:03 From: Jani Honkonen Date: 2012-05-08 12:46:03 Subject: [PATCH] Add a script for running tests --- diff --git a/test/scripts/Jobs.pm b/test/scripts/Jobs.pm new file mode 100644 index 0000000..d72cd22 --- /dev/null +++ b/test/scripts/Jobs.pm @@ -0,0 +1,33 @@ +package Jobs; +use File::Basename; +use IniFiles; + +sub get { + my $inifile = shift; + my $jobname = shift; + + # Strip the prefix from job name when using ${bamboo.buildPlanName} + my $prefix = "Digia Qt Commercial - Chart component - "; + $jobname =~ s/$prefix//; + + # read ini file + my %cfg; + tie %cfg, 'Config::IniFiles', ( -file => $inifile ); + + # get section from ini by jobname + my %job = %{$cfg{$jobname}}; + if (!%job) { + die ("Unknown jobname! Check $inifile and bamboo job name."); + } + + # print out the ini settings + print "\n\n$jobname\n"; + print "**********\n"; + foreach (keys %job) { + print $_ . " : " . $job{$_} . "\n"; + } + + return %job; +} + +1; \ No newline at end of file diff --git a/test/scripts/build.pl b/test/scripts/build.pl index 4e4a4fe..53a5c13 100644 --- a/test/scripts/build.pl +++ b/test/scripts/build.pl @@ -1,55 +1,39 @@ -use lib 'test/scripts'; # for IniFiles use File::Basename; -use IniFiles; use feature "switch"; +use lib 'test/scripts'; +use Jobs; # read command line params my $jobname = shift; -# Strip the prefix from job name when using ${bamboo.buildPlanName} -my $prefix = "Digia Qt Commercial - Chart component - "; -$jobname =~ s/$prefix//; +# get script directory +my $scriptdir = File::Basename::dirname($0); # read ini file -my $scriptdir = File::Basename::dirname($0); my $inifile = $scriptdir . "/jobs.ini"; -my %cfg; -tie %cfg, 'Config::IniFiles', ( -file => $inifile ); - -# get section from ini by jobname -my %build = %{$cfg{$jobname}}; -if (!%build) { - die ("Unknown jobname! Check $inifile and bamboo job name."); -} - -# print out the ini settings -print "\n\n$jobname\n"; -print "**********\n"; -foreach (keys %build) { - print $_ . " : " . $build{$_} . "\n"; -} +my %job = Jobs::get($inifile, $jobname); # examine the platform -given ($build{'Platform'}) { +given ($job{'Platform'}) { when ("Win7") { # construct a build command my @cmd; - if ($build{'ToolChain'} eq "mingw") { - @cmd = ($scriptdir . "\\build_win_mingw.bat", $build{'QtDir'}, $build{'Config'}, $build{'MinGWDir'}); + if ($job{'ToolChain'} eq "mingw") { + @cmd = ($scriptdir . "\\build_win_mingw.bat", $job{'QtDir'}, $job{'Config'}, $job{'MinGWDir'}); } - if ($build{'ToolChain'} eq "vs2005") { - @cmd = ($scriptdir . "\\build_win_vs2005.bat", $build{'QtDir'}, $build{'Config'}); + if ($job{'ToolChain'} eq "vs2005") { + @cmd = ($scriptdir . "\\build_win_vs2005.bat", $job{'QtDir'}, $job{'Config'}); } - if ($build{'ToolChain'} eq "vs2008") { - @cmd = ($scriptdir . "\\build_win_vs2008.bat", $build{'QtDir'}, $build{'Config'}); + if ($job{'ToolChain'} eq "vs2008") { + @cmd = ($scriptdir . "\\build_win_vs2008.bat", $job{'QtDir'}, $job{'Config'}); } - if ($build{'ToolChain'} eq "vs2010") { - @cmd = ($scriptdir . "\\build_win_vs2010.bat", $build{'QtDir'}, $build{'Config'}); + if ($job{'ToolChain'} eq "vs2010") { + @cmd = ($scriptdir . "\\build_win_vs2010.bat", $job{'QtDir'}, $job{'Config'}); } # run the build command system (@cmd) == 0 or die "system @cmd failed: $?"; } default { - die "Unknown platform " . $build{'Platform'}; + die "Unknown platform " . $job{'Platform'}; } } \ No newline at end of file diff --git a/test/scripts/run_tests.pl b/test/scripts/run_tests.pl new file mode 100644 index 0000000..1800a66 --- /dev/null +++ b/test/scripts/run_tests.pl @@ -0,0 +1,57 @@ +use Cwd; +use Cwd 'abs_path'; +use File::Basename; +use File::Copy; +use lib 'test/scripts'; +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); + +# Windows specific magic +if ($job{'Platform'} eq "Win7") { + $ENV{'PATH'} .= ";" . $job{'QtDir'} . "\\bin"; # Add qtdir to path +} + +# Go through all the files in the test folder +my $root_path = abs_path(); +my $test_path = "$root_path/bin/test/"; +opendir (TESTAPPDIR, "$test_path") or die "Couldn't open test app dir"; +@files = ; +while ($testapp = readdir TESTAPPDIR) { + # autotest is an executable beginning with "tst_" + if (index($testapp, "tst_") == 0) { + if (-x "$test_path$testapp") { + my $cmd_postfix = ""; + if ($^O eq "darwin") { + # On OSX the actual test binary is in a sub folder + $cmd_postfix = "/Contents/MacOS/$testapp"; + $cmd_postfix = substr($cmd_postfix, 0, rindex($cmd_postfix, ".app")); + } + # Generate path for test results + my $test_result_path = "test-reports/$testapp.xml"; + mkdir dirname($test_result_path); + # Execute the actual auto test + executeTestApp("$test_path$testapp$cmd_postfix", "-xunitxml -o $test_result_path"); + } else { + #print "file $testapp not executable\n"; + } + } +} +closedir TESTAPPDIR; + +sub executeTestApp($) { + my $test_app_path = $_[0]; + my $parameters = $_[1]; + + print "executing: $cmd_prefix$test_app_path $parameters\n"; + my $file_handle = system("$test_app_path $parameters"); + + my $exit_status = $? >> 8; +# print "exit: $exit_status \n"; +# print "handle: $file_handle\n"; +}