| 1 |
#!/usr/bin/env perl |
| 2 |
############################################################################# |
| 3 |
## |
| 4 |
## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 5 |
## All rights reserved. |
| 6 |
## Contact: Nokia Corporation (qt-info@nokia.com) |
| 7 |
## |
| 8 |
## This file is part of the test suite of the Qt Toolkit. |
| 9 |
## |
| 10 |
## $QT_BEGIN_LICENSE:LGPL$ |
| 11 |
## GNU Lesser General Public License Usage |
| 12 |
## This file may be used under the terms of the GNU Lesser General Public |
| 13 |
## License version 2.1 as published by the Free Software Foundation and |
| 14 |
## appearing in the file LICENSE.LGPL included in the packaging of this |
| 15 |
## file. Please review the following information to ensure the GNU Lesser |
| 16 |
## General Public License version 2.1 requirements will be met: |
| 17 |
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 18 |
## |
| 19 |
## In addition, as a special exception, Nokia gives you certain additional |
| 20 |
## rights. These rights are described in the Nokia Qt LGPL Exception |
| 21 |
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 22 |
## |
| 23 |
## GNU General Public License Usage |
| 24 |
## Alternatively, this file may be used under the terms of the GNU General |
| 25 |
## Public License version 3.0 as published by the Free Software Foundation |
| 26 |
## and appearing in the file LICENSE.GPL included in the packaging of this |
| 27 |
## file. Please review the following information to ensure the GNU General |
| 28 |
## Public License version 3.0 requirements will be met: |
| 29 |
## http://www.gnu.org/copyleft/gpl.html. |
| 30 |
## |
| 31 |
## Other Usage |
| 32 |
## Alternatively, this file may be used in accordance with the terms and |
| 33 |
## conditions contained in a signed written agreement between you and Nokia. |
| 34 |
## |
| 35 |
## |
| 36 |
## |
| 37 |
## |
| 38 |
## |
| 39 |
## $QT_END_LICENSE$ |
| 40 |
## |
| 41 |
############################################################################# |
| 42 |
|
| 43 |
use strict; |
| 44 |
use Cwd; |
| 45 |
|
| 46 |
# Usage: test.pl <SearchPath> <ExecutionMode> <TestResults> <Timeout [Default 300 seconds]> |
| 47 |
# Variable declarations to keep strict happy |
| 48 |
our $SEARCH_PATH; |
| 49 |
our $EXEC_MODE; |
| 50 |
our $EXE_PREFIX; |
| 51 |
our $EXE_SUFFIX; |
| 52 |
our $TIMEOUT; |
| 53 |
our $REPORTDIR; |
| 54 |
our $buryChildren; |
| 55 |
our $timeoutChildren; |
| 56 |
our $totalExecuted; |
| 57 |
our $totalStarted; |
| 58 |
our $totalTimedOut; |
| 59 |
our $next; |
| 60 |
our $currentDirectory; |
| 61 |
|
| 62 |
# Where do we run this script? What directory? |
| 63 |
$SEARCH_PATH=$ARGV[0]; |
| 64 |
if(!$SEARCH_PATH) |
| 65 |
{ |
| 66 |
print "Please specify the search directory! \n"; |
| 67 |
exit(0); |
| 68 |
} |
| 69 |
|
| 70 |
# We have four options: |
| 71 |
# 'U': Unix |
| 72 |
# 'W': Windows |
| 73 |
# 'M': Mac |
| 74 |
# 'E': Embedded |
| 75 |
$EXEC_MODE=$ARGV[1]; |
| 76 |
if($EXEC_MODE =~ /^U$/) |
| 77 |
{ |
| 78 |
print "Using Unix execution mode\n"; |
| 79 |
$EXE_PREFIX="./"; |
| 80 |
$EXE_SUFFIX=""; |
| 81 |
} elsif($EXEC_MODE =~ /^W$/) |
| 82 |
{ |
| 83 |
print "Using Windows execution mode\n"; |
| 84 |
$EXE_PREFIX=""; |
| 85 |
$EXE_SUFFIX=".exe"; |
| 86 |
} elsif($EXEC_MODE =~ /^M$/) |
| 87 |
{ |
| 88 |
print "Using OSX execution mode\n"; |
| 89 |
$EXE_PREFIX="/Content/MacOS/"; |
| 90 |
$EXE_SUFFIX=""; |
| 91 |
} elsif($EXEC_MODE =~ /^E$/) |
| 92 |
{ |
| 93 |
print "Using embedded execution mode\n"; |
| 94 |
$EXE_PREFIX="./"; |
| 95 |
$EXE_SUFFIX=""; |
| 96 |
} else { |
| 97 |
print "Unknown execution mode: $EXEC_MODE \n"; |
| 98 |
print "Use: 'U' (Unix), 'W' (Windows), 'M' (MacOSX)\n"; |
| 99 |
exit(0); |
| 100 |
} |
| 101 |
# We get the current directory, we 'll need it afterwards |
| 102 |
$currentDirectory = getcwd(); |
| 103 |
|
| 104 |
# We assume that by default goes to "reports" unless the user specifies it. |
| 105 |
$REPORTDIR = $ARGV[2]; |
| 106 |
if(!$REPORTDIR) |
| 107 |
{ |
| 108 |
if($SEARCH_PATH =~ /^\.$/) |
| 109 |
{ |
| 110 |
# '.' ie current directory |
| 111 |
$REPORTDIR = $currentDirectory."/reports"; |
| 112 |
} elsif($SEARCH_PATH =~ /^\//) { |
| 113 |
# Absolute path |
| 114 |
$REPORTDIR = $SEARCH_PATH."/reports"; |
| 115 |
} else { |
| 116 |
# Relative path |
| 117 |
$REPORTDIR = $currentDirectory.$SEARCH_PATH."/reports"; |
| 118 |
} |
| 119 |
} |
| 120 |
# Let's create the directory |
| 121 |
mkdir $REPORTDIR; |
| 122 |
|
| 123 |
# If given we use it, otherwise we default to 300 seconds. |
| 124 |
$TIMEOUT = $ARGV[3]; |
| 125 |
if(!$TIMEOUT) |
| 126 |
{ |
| 127 |
$TIMEOUT=300; |
| 128 |
} |
| 129 |
print "Timeout value: $TIMEOUT\n"; |
| 130 |
|
| 131 |
# Initialize 'global' variables |
| 132 |
$buryChildren = 0; |
| 133 |
$timeoutChildren = 0; |
| 134 |
$totalExecuted = 0; |
| 135 |
$totalStarted = 0; |
| 136 |
$totalTimedOut = 0; |
| 137 |
|
| 138 |
# Install signal handlers and pray for the best |
| 139 |
$SIG{'CHLD'} = 'handleDeath'; |
| 140 |
$SIG{'ALRM'} = 'handleTimeout'; |
| 141 |
|
| 142 |
while ($next = <$SEARCH_PATH/*>) |
| 143 |
{ |
| 144 |
if( -d $next ) |
| 145 |
{ |
| 146 |
print "Examining $next \n"; |
| 147 |
chdir($next) || die("Could not chdir to $next"); |
| 148 |
my @components; |
| 149 |
my $command; |
| 150 |
@components = split(/\//, $next); |
| 151 |
if($EXEC_MODE =~ /^M$/) |
| 152 |
{ |
| 153 |
$command = "tst_".$components[1].".app"; |
| 154 |
} else { |
| 155 |
$command = "tst_".$components[1]; |
| 156 |
} |
| 157 |
if( -e $command) |
| 158 |
{ |
| 159 |
print "Executing $command \n"; |
| 160 |
my $myPid; |
| 161 |
$myPid = fork(); |
| 162 |
if($myPid == 0) |
| 163 |
{ |
| 164 |
my $realCommand; |
| 165 |
if($EXEC_MODE =~/^M$/) |
| 166 |
{ |
| 167 |
$realCommand = "./".$command.".app".$EXE_PREFIX.$command; |
| 168 |
} else { |
| 169 |
$realCommand = $EXE_PREFIX.$command.$EXE_SUFFIX; |
| 170 |
} |
| 171 |
my $outputRedirection = $REPORTDIR."/".$command.".xml"; |
| 172 |
if($EXEC_MODE =~ /^E$/) |
| 173 |
{ |
| 174 |
exec($realCommand, "-qws", "-xml", "-o", $outputRedirection); |
| 175 |
} else { |
| 176 |
exec($realCommand, "-xml", "-o", $outputRedirection); |
| 177 |
} |
| 178 |
exit(0); |
| 179 |
} elsif($myPid > 0 ) |
| 180 |
{ |
| 181 |
$totalStarted++; |
| 182 |
alarm($TIMEOUT); |
| 183 |
while(!$buryChildren && !$timeoutChildren) |
| 184 |
{ |
| 185 |
sleep 10; |
| 186 |
} |
| 187 |
if($buryChildren) |
| 188 |
{ |
| 189 |
my $value; |
| 190 |
$value = waitpid($myPid , 0); |
| 191 |
$buryChildren = 0; |
| 192 |
$totalExecuted++; |
| 193 |
} elsif($timeoutChildren) |
| 194 |
{ |
| 195 |
kill 'INT', $myPid; |
| 196 |
$timeoutChildren = 0; |
| 197 |
$totalTimedOut++; |
| 198 |
} else { |
| 199 |
# What?? If we get here we need to abort, this is totally unexpected |
| 200 |
print "Wrong condition evaluated, aborting to avoid damages\n"; |
| 201 |
exit(0); |
| 202 |
} |
| 203 |
# We need to handle children killed because of timeout |
| 204 |
if($buryChildren) |
| 205 |
{ |
| 206 |
my $value; |
| 207 |
$value = waitpid($myPid , 0); |
| 208 |
$buryChildren = 0; |
| 209 |
} |
| 210 |
} else { |
| 211 |
print "Problems trying to execute $command"; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
chdir($currentDirectory); |
| 216 |
|
| 217 |
} |
| 218 |
print " ** Statistics ** \n"; |
| 219 |
print " Tests started: $totalStarted \n"; |
| 220 |
print " Tests executed: $totalExecuted \n"; |
| 221 |
print " Tests timed out: $totalTimedOut \n"; |
| 222 |
|
| 223 |
# This procedure takes care of handling dead children on due time |
| 224 |
sub handleDeath { |
| 225 |
$buryChildren = 1; |
| 226 |
} |
| 227 |
|
| 228 |
# This takes care of timeouts |
| 229 |
sub handleTimeout { |
| 230 |
$timeoutChildren = 1; |
| 231 |
} |