author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/env perl |
2 |
############################################################################# |
|
3 |
## |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4 |
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
## No Commercial Usage |
|
12 |
## This file contains pre-release code and may not be distributed. |
|
13 |
## You may use this file in accordance with the terms and conditions |
|
14 |
## contained in the Technology Preview License Agreement accompanying |
|
15 |
## this package. |
|
16 |
## |
|
17 |
## GNU Lesser General Public License Usage |
|
18 |
## Alternatively, this file may be used under the terms of the GNU Lesser |
|
19 |
## General Public License version 2.1 as published by the Free Software |
|
20 |
## Foundation and appearing in the file LICENSE.LGPL included in the |
|
21 |
## packaging of this file. Please review the following information to |
|
22 |
## ensure the GNU Lesser General Public License version 2.1 requirements |
|
23 |
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
24 |
## |
|
25 |
## In addition, as a special exception, Nokia gives you certain additional |
|
26 |
## rights. These rights are described in the Nokia Qt LGPL Exception |
|
27 |
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
28 |
## |
|
29 |
## If you have questions regarding the use of this file, please contact |
|
30 |
## Nokia at qt-info@nokia.com. |
|
31 |
## |
|
32 |
## |
|
33 |
## |
|
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 |
} |
|
232 |